|
| 1 | +import SwiftFormatConfiguration |
| 2 | + |
| 3 | +final class MacroCallTests: PrettyPrintTestCase { |
| 4 | + func testNoWhiteSpaceAfterMacroWithoutTrailingClosure() { |
| 5 | + let input = |
| 6 | + """ |
| 7 | + func myFunction() { |
| 8 | + print("Currently running \\(#function)") |
| 9 | + } |
| 10 | +
|
| 11 | + """ |
| 12 | + |
| 13 | + let expected = |
| 14 | + """ |
| 15 | + func myFunction() { |
| 16 | + print("Currently running \\(#function)") |
| 17 | + } |
| 18 | +
|
| 19 | + """ |
| 20 | + |
| 21 | + assertPrettyPrintEqual(input: input, expected: expected, linelength: 50) |
| 22 | + } |
| 23 | + |
| 24 | + func testKeepWhiteSpaceBeforeTrailingClosure() { |
| 25 | + let input = |
| 26 | + """ |
| 27 | + #Preview {} |
| 28 | + #Preview("MyPreview") { |
| 29 | + MyView() |
| 30 | + } |
| 31 | + let p = #Predicate<Int> { $0 == 0 } |
| 32 | + """ |
| 33 | + |
| 34 | + let expected = |
| 35 | + """ |
| 36 | + #Preview {} |
| 37 | + #Preview("MyPreview") { |
| 38 | + MyView() |
| 39 | + } |
| 40 | + let p = #Predicate<Int> { $0 == 0 } |
| 41 | +
|
| 42 | + """ |
| 43 | + |
| 44 | + assertPrettyPrintEqual(input: input, expected: expected, linelength: 40) |
| 45 | + } |
| 46 | + |
| 47 | + func testInsertWhiteSpaceBeforeTrailingClosure() { |
| 48 | + let input = |
| 49 | + """ |
| 50 | + #Preview{} |
| 51 | + #Preview("MyPreview"){ |
| 52 | + MyView() |
| 53 | + } |
| 54 | + let p = #Predicate<Int>{ $0 == 0 } |
| 55 | + """ |
| 56 | + |
| 57 | + let expected = |
| 58 | + """ |
| 59 | + #Preview {} |
| 60 | + #Preview("MyPreview") { |
| 61 | + MyView() |
| 62 | + } |
| 63 | + let p = #Predicate<Int> { $0 == 0 } |
| 64 | +
|
| 65 | + """ |
| 66 | + |
| 67 | + assertPrettyPrintEqual(input: input, expected: expected, linelength: 40) |
| 68 | + } |
| 69 | + |
| 70 | + func testDiscretionaryLineBreakBeforeTrailingClosure() { |
| 71 | + let input = |
| 72 | + """ |
| 73 | + #Preview("MyPreview") |
| 74 | + { |
| 75 | + MyView() |
| 76 | + } |
| 77 | + #Preview( |
| 78 | + "MyPreview", traits: .landscapeLeft |
| 79 | + ) |
| 80 | + { |
| 81 | + MyView() |
| 82 | + } |
| 83 | + #Preview("MyPreview", traits: .landscapeLeft, .sizeThatFitsLayout) |
| 84 | + { |
| 85 | + MyView() |
| 86 | + } |
| 87 | + #Preview("MyPreview", traits: .landscapeLeft) { |
| 88 | + MyView() |
| 89 | + } |
| 90 | + """ |
| 91 | + |
| 92 | + let expected = |
| 93 | + """ |
| 94 | + #Preview("MyPreview") { |
| 95 | + MyView() |
| 96 | + } |
| 97 | + #Preview( |
| 98 | + "MyPreview", traits: .landscapeLeft |
| 99 | + ) { |
| 100 | + MyView() |
| 101 | + } |
| 102 | + #Preview( |
| 103 | + "MyPreview", traits: .landscapeLeft, |
| 104 | + .sizeThatFitsLayout |
| 105 | + ) { |
| 106 | + MyView() |
| 107 | + } |
| 108 | + #Preview("MyPreview", traits: .landscapeLeft) |
| 109 | + { |
| 110 | + MyView() |
| 111 | + } |
| 112 | +
|
| 113 | + """ |
| 114 | + |
| 115 | + assertPrettyPrintEqual(input: input, expected: expected, linelength: 45) |
| 116 | + } |
| 117 | +} |
0 commit comments