1
1
import SwiftFormat
2
2
3
3
final class CommaTests : PrettyPrintTestCase {
4
- func testCommasAbsentEnabled ( ) {
4
+ func testArrayCommasAbsentEnabled ( ) {
5
5
let input =
6
6
"""
7
- let MyList = [
7
+ let MyCollection = [
8
8
1,
9
9
2,
10
10
3
@@ -14,7 +14,7 @@ final class CommaTests: PrettyPrintTestCase {
14
14
15
15
let expected =
16
16
"""
17
- let MyList = [
17
+ let MyCollection = [
18
18
1,
19
19
2,
20
20
3,
@@ -27,10 +27,10 @@ final class CommaTests: PrettyPrintTestCase {
27
27
assertPrettyPrintEqual ( input: input, expected: expected, linelength: 20 , configuration: configuration)
28
28
}
29
29
30
- func testCommasAbsentDisabled ( ) {
30
+ func testArrayCommasAbsentDisabled ( ) {
31
31
let input =
32
32
"""
33
- let MyList = [
33
+ let MyCollection = [
34
34
1,
35
35
2,
36
36
3
@@ -40,7 +40,7 @@ final class CommaTests: PrettyPrintTestCase {
40
40
41
41
let expected =
42
42
"""
43
- let MyList = [
43
+ let MyCollection = [
44
44
1,
45
45
2,
46
46
3
@@ -53,10 +53,10 @@ final class CommaTests: PrettyPrintTestCase {
53
53
assertPrettyPrintEqual ( input: input, expected: expected, linelength: 20 , configuration: configuration)
54
54
}
55
55
56
- func testCommasPresentEnabled ( ) {
56
+ func testArrayCommasPresentEnabled ( ) {
57
57
let input =
58
58
"""
59
- let MyList = [
59
+ let MyCollection = [
60
60
1,
61
61
2,
62
62
3,
@@ -66,7 +66,7 @@ final class CommaTests: PrettyPrintTestCase {
66
66
67
67
let expected =
68
68
"""
69
- let MyList = [
69
+ let MyCollection = [
70
70
1,
71
71
2,
72
72
3,
@@ -79,10 +79,10 @@ final class CommaTests: PrettyPrintTestCase {
79
79
assertPrettyPrintEqual ( input: input, expected: expected, linelength: 20 , configuration: configuration)
80
80
}
81
81
82
- func testCommasPresentDisabled ( ) {
82
+ func testArrayCommasPresentDisabled ( ) {
83
83
let input =
84
84
"""
85
- let MyList = [
85
+ let MyCollection = [
86
86
1,
87
87
2,
88
88
3,
@@ -92,7 +92,7 @@ final class CommaTests: PrettyPrintTestCase {
92
92
93
93
let expected =
94
94
"""
95
- let MyList = [
95
+ let MyCollection = [
96
96
1,
97
97
2,
98
98
3
@@ -105,17 +105,17 @@ final class CommaTests: PrettyPrintTestCase {
105
105
assertPrettyPrintEqual ( input: input, expected: expected, linelength: 20 , configuration: configuration)
106
106
}
107
107
108
- func testCommasPresentSingleLineDisabled ( ) {
108
+ func testArraySingleLineCommasPresentDisabled ( ) {
109
109
let input =
110
110
"""
111
- let MyList = [1, 2, 3,]
111
+ let MyCollection = [1, 2, 3,]
112
112
113
113
"""
114
114
115
115
// no effect expected
116
116
let expected =
117
117
"""
118
- let MyList = [1, 2, 3]
118
+ let MyCollection = [1, 2, 3]
119
119
120
120
"""
121
121
@@ -124,17 +124,161 @@ final class CommaTests: PrettyPrintTestCase {
124
124
assertPrettyPrintEqual ( input: input, expected: expected, linelength: 40 , configuration: configuration)
125
125
}
126
126
127
- func testCommasPresentSingleLineEnabled ( ) {
127
+ func testArraySingleLineCommasPresentEnabled ( ) {
128
128
let input =
129
129
"""
130
- let MyList = [1, 2, 3,]
130
+ let MyCollection = [1, 2, 3,]
131
131
132
132
"""
133
133
134
134
// no effect expected
135
135
let expected =
136
136
"""
137
- let MyList = [1, 2, 3]
137
+ let MyCollection = [1, 2, 3]
138
+
139
+ """
140
+
141
+ var configuration = Configuration . forTesting
142
+ configuration. multilineCollectionTrailingCommas = false
143
+ assertPrettyPrintEqual ( input: input, expected: expected, linelength: 40 , configuration: configuration)
144
+ }
145
+
146
+ func testDictionaryCommasAbsentEnabled( ) {
147
+ let input =
148
+ """
149
+ let MyCollection = [
150
+ " a " : 1,
151
+ " b " : 2,
152
+ " c " : 3
153
+ ]
154
+
155
+ """
156
+
157
+ let expected =
158
+ """
159
+ let MyCollection = [
160
+ " a " : 1,
161
+ " b " : 2,
162
+ " c " : 3,
163
+ ]
164
+
165
+ """
166
+
167
+ var configuration = Configuration . forTesting
168
+ configuration. multilineCollectionTrailingCommas = true
169
+ assertPrettyPrintEqual ( input: input, expected: expected, linelength: 20 , configuration: configuration)
170
+ }
171
+
172
+ func testDictionaryCommasAbsentDisabled( ) {
173
+ let input =
174
+ """
175
+ let MyCollection = [
176
+ " a " : 1,
177
+ " b " : 2,
178
+ " c " : 3
179
+ ]
180
+
181
+ """
182
+
183
+ let expected =
184
+ """
185
+ let MyCollection = [
186
+ " a " : 1,
187
+ " b " : 2,
188
+ " c " : 3
189
+ ]
190
+
191
+ """
192
+
193
+ var configuration = Configuration . forTesting
194
+ configuration. multilineCollectionTrailingCommas = false
195
+ assertPrettyPrintEqual ( input: input, expected: expected, linelength: 20 , configuration: configuration)
196
+ }
197
+
198
+ func testDictionaryCommasPresentEnabled( ) {
199
+ let input =
200
+ """
201
+ let MyCollection = [
202
+ " a " : 1,
203
+ " b " : 2,
204
+ " c " : 3,
205
+ ]
206
+
207
+ """
208
+
209
+ let expected =
210
+ """
211
+ let MyCollection = [
212
+ " a " : 1,
213
+ " b " : 2,
214
+ " c " : 3,
215
+ ]
216
+
217
+ """
218
+
219
+ var configuration = Configuration . forTesting
220
+ configuration. multilineCollectionTrailingCommas = true
221
+ assertPrettyPrintEqual ( input: input, expected: expected, linelength: 20 , configuration: configuration)
222
+ }
223
+
224
+ func testDictionaryCommasPresentDisabled( ) {
225
+ let input =
226
+ """
227
+ let MyCollection = [
228
+ " a " : 1,
229
+ " b " : 2,
230
+ " c " : 3,
231
+ ]
232
+
233
+ """
234
+
235
+ let expected =
236
+ """
237
+ let MyCollection = [
238
+ " a " : 1,
239
+ " b " : 2,
240
+ " c " : 3
241
+ ]
242
+
243
+ """
244
+
245
+ var configuration = Configuration . forTesting
246
+ configuration. multilineCollectionTrailingCommas = false
247
+ assertPrettyPrintEqual ( input: input, expected: expected, linelength: 20 , configuration: configuration)
248
+ }
249
+
250
+ func testDictionarySingleLineCommasPresentDisabled( ) {
251
+ let input =
252
+ """
253
+ let MyCollection = [ " a " : 1, " b " : 2, " c " : 3,]
254
+
255
+ """
256
+
257
+ let expected =
258
+ """
259
+ let MyCollection = [
260
+ " a " : 1, " b " : 2, " c " : 3,
261
+ ]
262
+
263
+ """
264
+
265
+ var configuration = Configuration . forTesting
266
+ configuration. multilineCollectionTrailingCommas = true
267
+ assertPrettyPrintEqual ( input: input, expected: expected, linelength: 40 , configuration: configuration)
268
+ }
269
+
270
+ func testDictionarySingleLineCommasPresentEnabled( ) {
271
+ let input =
272
+ """
273
+ let MyCollection = [ " a " : 1, " b " : 2, " c " : 3,]
274
+
275
+ """
276
+
277
+ let expected =
278
+ """
279
+ let MyCollection = [
280
+ " a " : 1, " b " : 2, " c " : 3
281
+ ]
138
282
139
283
"""
140
284
0 commit comments