-
Notifications
You must be signed in to change notification settings - Fork 248
Add fix and tests for postfix pound ifs #383
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -230,4 +230,164 @@ final class IfConfigTests: PrettyPrintTestCase { | |
|
||
assertPrettyPrintEqual(input: input, expected: expected, linelength: 40) | ||
} | ||
|
||
func testPostfixPoundIfAfterParentheses() { | ||
let input = | ||
""" | ||
VStack { | ||
Text("something") | ||
#if os(iOS) | ||
.iOSSpecificModifier() | ||
#endif | ||
.commonModifier() | ||
} | ||
""" | ||
|
||
let expected = | ||
""" | ||
VStack { | ||
Text("something") | ||
#if os(iOS) | ||
.iOSSpecificModifier() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you add a test for a situation where you would have multiple members accesses inside the
We want to make sure the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
#endif | ||
.commonModifier() | ||
} | ||
|
||
""" | ||
|
||
assertPrettyPrintEqual(input: input, expected: expected, linelength: 45) | ||
} | ||
|
||
func testPostfixPoundIfAfterParenthesesMultipleMembers() { | ||
let input = | ||
""" | ||
VStack { | ||
Text("something") | ||
#if os(iOS) | ||
.iOSSpecificModifier() | ||
.anotherModifier() | ||
.anotherAnotherModifier() | ||
#endif | ||
.commonModifier() | ||
.anotherCommonModifier() | ||
} | ||
""" | ||
|
||
let expected = | ||
""" | ||
VStack { | ||
Text("something") | ||
#if os(iOS) | ||
.iOSSpecificModifier() | ||
.anotherModifier() | ||
.anotherAnotherModifier() | ||
#endif | ||
.commonModifier() | ||
.anotherCommonModifier() | ||
} | ||
|
||
""" | ||
|
||
assertPrettyPrintEqual(input: input, expected: expected, linelength: 45) | ||
} | ||
|
||
func testPostfixPoundIfNested() { | ||
let input = | ||
""" | ||
VStack { | ||
Text("something") | ||
#if os(iOS) || os(watchOS) | ||
#if os(iOS) | ||
.iOSModifier() | ||
#else | ||
.watchOSModifier() | ||
#endif | ||
.iOSAndWatchOSModifier() | ||
#endif | ||
} | ||
""" | ||
|
||
let expected = | ||
""" | ||
VStack { | ||
Text("something") | ||
#if os(iOS) || os(watchOS) | ||
#if os(iOS) | ||
.iOSModifier() | ||
#else | ||
.watchOSModifier() | ||
#endif | ||
.iOSAndWatchOSModifier() | ||
#endif | ||
} | ||
|
||
""" | ||
|
||
assertPrettyPrintEqual(input: input, expected: expected, linelength: 45) | ||
} | ||
|
||
|
||
func testPostfixPoundIfAfterVariables() { | ||
let input = | ||
""" | ||
VStack { | ||
textView | ||
#if os(iOS) | ||
.iOSSpecificModifier() | ||
#endif | ||
.commonModifier() | ||
} | ||
""" | ||
|
||
let expected = | ||
""" | ||
VStack { | ||
textView | ||
#if os(iOS) | ||
.iOSSpecificModifier() | ||
#endif | ||
.commonModifier() | ||
} | ||
|
||
""" | ||
|
||
assertPrettyPrintEqual(input: input, expected: expected, linelength: 45) | ||
} | ||
|
||
func testPostfixPoundIfAfterClosingBrace() { | ||
let input = | ||
""" | ||
HStack { | ||
Toggle(isOn: binding) { | ||
Text("Some text") | ||
} | ||
#if !os(tvOS) | ||
.toggleStyle(SwitchToggleStyle(tint: Color.blue)) | ||
#endif | ||
.accessibilityValue( | ||
binding.wrappedValue == true ? "On" : "Off" | ||
) | ||
} | ||
""" | ||
|
||
let expected = | ||
""" | ||
HStack { | ||
Toggle(isOn: binding) { | ||
Text("Some text") | ||
} | ||
#if !os(tvOS) | ||
.toggleStyle( | ||
SwitchToggleStyle(tint: Color.blue)) | ||
#endif | ||
.accessibilityValue( | ||
binding.wrappedValue == true | ||
? "On" : "Off" | ||
) | ||
} | ||
|
||
""" | ||
|
||
assertPrettyPrintEqual(input: input, expected: expected, linelength: 45) | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A test that uses nested
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need to check all the ancestors, not just the immediate parent? Is this required to make nested clauses have the right indentation? (If it is, that's fine, I just wanted to verify the reason.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From what I was seeing, yes we need to check all the ancestors. In the code to handle the break before the
#if
the ancestor was consistent but it was a great-grandparent, not the immediate parent.But in the code to ensure that the indentation is correct the ancestor that was
PostfixIfConfigExprSyntax
changed based upon how many modifiers were chained together.