forked from swiftlang/swift-format
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request swiftlang#544 from kimberninger/macro_expression_w…
…hite_space Insert white space before trailing closure of a macro expression
- Loading branch information
Showing
2 changed files
with
131 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
import SwiftFormatConfiguration | ||
|
||
final class MacroCallTests: PrettyPrintTestCase { | ||
func testNoWhiteSpaceAfterMacroWithoutTrailingClosure() { | ||
let input = | ||
""" | ||
func myFunction() { | ||
print("Currently running \\(#function)") | ||
} | ||
""" | ||
|
||
let expected = | ||
""" | ||
func myFunction() { | ||
print("Currently running \\(#function)") | ||
} | ||
""" | ||
|
||
assertPrettyPrintEqual(input: input, expected: expected, linelength: 50) | ||
} | ||
|
||
func testKeepWhiteSpaceBeforeTrailingClosure() { | ||
let input = | ||
""" | ||
#Preview {} | ||
#Preview("MyPreview") { | ||
MyView() | ||
} | ||
let p = #Predicate<Int> { $0 == 0 } | ||
""" | ||
|
||
let expected = | ||
""" | ||
#Preview {} | ||
#Preview("MyPreview") { | ||
MyView() | ||
} | ||
let p = #Predicate<Int> { $0 == 0 } | ||
""" | ||
|
||
assertPrettyPrintEqual(input: input, expected: expected, linelength: 40) | ||
} | ||
|
||
func testInsertWhiteSpaceBeforeTrailingClosure() { | ||
let input = | ||
""" | ||
#Preview{} | ||
#Preview("MyPreview"){ | ||
MyView() | ||
} | ||
let p = #Predicate<Int>{ $0 == 0 } | ||
""" | ||
|
||
let expected = | ||
""" | ||
#Preview {} | ||
#Preview("MyPreview") { | ||
MyView() | ||
} | ||
let p = #Predicate<Int> { $0 == 0 } | ||
""" | ||
|
||
assertPrettyPrintEqual(input: input, expected: expected, linelength: 40) | ||
} | ||
|
||
func testDiscretionaryLineBreakBeforeTrailingClosure() { | ||
let input = | ||
""" | ||
#Preview("MyPreview") | ||
{ | ||
MyView() | ||
} | ||
#Preview( | ||
"MyPreview", traits: .landscapeLeft | ||
) | ||
{ | ||
MyView() | ||
} | ||
#Preview("MyPreview", traits: .landscapeLeft, .sizeThatFitsLayout) | ||
{ | ||
MyView() | ||
} | ||
#Preview("MyPreview", traits: .landscapeLeft) { | ||
MyView() | ||
} | ||
""" | ||
|
||
let expected = | ||
""" | ||
#Preview("MyPreview") { | ||
MyView() | ||
} | ||
#Preview( | ||
"MyPreview", traits: .landscapeLeft | ||
) { | ||
MyView() | ||
} | ||
#Preview( | ||
"MyPreview", traits: .landscapeLeft, | ||
.sizeThatFitsLayout | ||
) { | ||
MyView() | ||
} | ||
#Preview("MyPreview", traits: .landscapeLeft) | ||
{ | ||
MyView() | ||
} | ||
""" | ||
|
||
assertPrettyPrintEqual(input: input, expected: expected, linelength: 45) | ||
} | ||
} |