|
| 1 | +import SwiftFormatConfiguration |
| 2 | + |
| 3 | +final class DeclNameArgumentTests: PrettyPrintTestCase { |
| 4 | + func testSelectors_noPackArguments() { |
| 5 | + let input = |
| 6 | + """ |
| 7 | + let selector = #selector(FooClass.method(firstArg:secondArg:thirdArg:fourthArg:fifthArg:)) |
| 8 | + let selector = #selector(FooClass.method(firstArg:secondArg:)) |
| 9 | + let selector = #selector(FooClass.VeryDeeply.NestedInner.Member.foo(firstArg:secondArg:)) |
| 10 | + let selector = #selector(FooClass.VeryDeeply.NestedInner.Member.foo(firstArg:secondArg:thirdArg:fourthArg:fifthArg:)) |
| 11 | + """ |
| 12 | + |
| 13 | + let expected = |
| 14 | + """ |
| 15 | + let selector = #selector( |
| 16 | + FooClass.method( |
| 17 | + firstArg: |
| 18 | + secondArg: |
| 19 | + thirdArg: |
| 20 | + fourthArg: |
| 21 | + fifthArg: |
| 22 | + )) |
| 23 | + let selector = #selector( |
| 24 | + FooClass.method(firstArg:secondArg:)) |
| 25 | + let selector = #selector( |
| 26 | + FooClass.VeryDeeply.NestedInner.Member |
| 27 | + .foo(firstArg:secondArg:)) |
| 28 | + let selector = #selector( |
| 29 | + FooClass.VeryDeeply.NestedInner.Member |
| 30 | + .foo( |
| 31 | + firstArg: |
| 32 | + secondArg: |
| 33 | + thirdArg: |
| 34 | + fourthArg: |
| 35 | + fifthArg: |
| 36 | + )) |
| 37 | +
|
| 38 | + """ |
| 39 | + |
| 40 | + var config = Configuration() |
| 41 | + config.lineBreakBeforeEachArgument = true |
| 42 | + assertPrettyPrintEqual(input: input, expected: expected, linelength: 40, configuration: config) |
| 43 | + } |
| 44 | + |
| 45 | + func testSelectors_packArguments() { |
| 46 | + let input = |
| 47 | + """ |
| 48 | + let selector = #selector(FooClass.method(firstArg:secondArg:thirdArg:fourthArg:fifthArg:)) |
| 49 | + let selector = #selector(FooClass.method(firstArg:secondArg:)) |
| 50 | + let selector = #selector(FooClass.VeryDeeply.NestedInner.Member.foo(firstArg:secondArg:)) |
| 51 | + let selector = #selector(FooClass.VeryDeeply.NestedInner.Member.foo(firstArg:secondArg:thirdArg:fourthArg:fifthArg:)) |
| 52 | + """ |
| 53 | + |
| 54 | + let expected = |
| 55 | + """ |
| 56 | + let selector = #selector( |
| 57 | + FooClass.method( |
| 58 | + firstArg:secondArg:thirdArg: |
| 59 | + fourthArg:fifthArg:)) |
| 60 | + let selector = #selector( |
| 61 | + FooClass.method(firstArg:secondArg:)) |
| 62 | + let selector = #selector( |
| 63 | + FooClass.VeryDeeply.NestedInner.Member |
| 64 | + .foo(firstArg:secondArg:)) |
| 65 | + let selector = #selector( |
| 66 | + FooClass.VeryDeeply.NestedInner.Member |
| 67 | + .foo( |
| 68 | + firstArg:secondArg:thirdArg: |
| 69 | + fourthArg:fifthArg:)) |
| 70 | +
|
| 71 | + """ |
| 72 | + |
| 73 | + assertPrettyPrintEqual(input: input, expected: expected, linelength: 40) |
| 74 | + } |
| 75 | + |
| 76 | + func testFunctions_noPackArguments() { |
| 77 | + let input = |
| 78 | + """ |
| 79 | + someArray.map(foo(firstArg:secondArg:)) |
| 80 | + someArray.map(foo(firstArg:secondArg:thirdArg:)) |
| 81 | + someArray.map(globalFuncFoo(firstArg:secondArg:thirdArg:fourthArg:fifthArg:)) |
| 82 | + someArray.map(obj.DeeplyNested.Inner.MemberWith.funcFoo(firstArg:secondArg:thirdArg:fourthArg:fifthArg:)) |
| 83 | + """ |
| 84 | + |
| 85 | + let expected = |
| 86 | + """ |
| 87 | + someArray.map(foo(firstArg:secondArg:)) |
| 88 | + someArray.map( |
| 89 | + foo(firstArg:secondArg:thirdArg:) |
| 90 | + ) |
| 91 | + someArray.map( |
| 92 | + globalFuncFoo( |
| 93 | + firstArg: |
| 94 | + secondArg: |
| 95 | + thirdArg: |
| 96 | + fourthArg: |
| 97 | + fifthArg: |
| 98 | + ) |
| 99 | + ) |
| 100 | + someArray.map( |
| 101 | + obj.DeeplyNested.Inner.MemberWith |
| 102 | + .funcFoo( |
| 103 | + firstArg: |
| 104 | + secondArg: |
| 105 | + thirdArg: |
| 106 | + fourthArg: |
| 107 | + fifthArg: |
| 108 | + ) |
| 109 | + ) |
| 110 | +
|
| 111 | + """ |
| 112 | + |
| 113 | + var config = Configuration() |
| 114 | + config.lineBreakBeforeEachArgument = true |
| 115 | + assertPrettyPrintEqual(input: input, expected: expected, linelength: 40, configuration: config) |
| 116 | + } |
| 117 | + |
| 118 | + func testFunctions_packArguments() { |
| 119 | + let input = |
| 120 | + """ |
| 121 | + someArray.map(foo(firstArg:secondArg:)) |
| 122 | + someArray.map(foo(firstArg:secondArg:thirdArg:)) |
| 123 | + someArray.map(globalFuncFoo(firstArg:secondArg:thirdArg:fourthArg:fifthArg:)) |
| 124 | + someArray.map(obj.DeeplyNested.Inner.MemberWith.funcFoo(firstArg:secondArg:thirdArg:fourthArg:fifthArg:)) |
| 125 | + """ |
| 126 | + |
| 127 | + let expected = |
| 128 | + """ |
| 129 | + someArray.map(foo(firstArg:secondArg:)) |
| 130 | + someArray.map( |
| 131 | + foo(firstArg:secondArg:thirdArg:)) |
| 132 | + someArray.map( |
| 133 | + globalFuncFoo( |
| 134 | + firstArg:secondArg:thirdArg: |
| 135 | + fourthArg:fifthArg:)) |
| 136 | + someArray.map( |
| 137 | + obj.DeeplyNested.Inner.MemberWith |
| 138 | + .funcFoo( |
| 139 | + firstArg:secondArg:thirdArg: |
| 140 | + fourthArg:fifthArg:)) |
| 141 | +
|
| 142 | + """ |
| 143 | + |
| 144 | + assertPrettyPrintEqual(input: input, expected: expected, linelength: 40) |
| 145 | + } |
| 146 | +} |
| 147 | + |
0 commit comments