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#619 from mlavergn/trailingCommas
Add option to disable trailing commas on multi-line collections
- Loading branch information
Showing
6 changed files
with
324 additions
and
1 deletion.
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
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
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,289 @@ | ||
import SwiftFormat | ||
|
||
final class CommaTests: PrettyPrintTestCase { | ||
func testArrayCommasAbsentEnabled() { | ||
let input = | ||
""" | ||
let MyCollection = [ | ||
1, | ||
2, | ||
3 | ||
] | ||
""" | ||
|
||
let expected = | ||
""" | ||
let MyCollection = [ | ||
1, | ||
2, | ||
3, | ||
] | ||
""" | ||
|
||
var configuration = Configuration.forTesting | ||
configuration.multiElementCollectionTrailingCommas = true | ||
assertPrettyPrintEqual(input: input, expected: expected, linelength: 20, configuration: configuration) | ||
} | ||
|
||
func testArrayCommasAbsentDisabled() { | ||
let input = | ||
""" | ||
let MyCollection = [ | ||
1, | ||
2, | ||
3 | ||
] | ||
""" | ||
|
||
let expected = | ||
""" | ||
let MyCollection = [ | ||
1, | ||
2, | ||
3 | ||
] | ||
""" | ||
|
||
var configuration = Configuration.forTesting | ||
configuration.multiElementCollectionTrailingCommas = false | ||
assertPrettyPrintEqual(input: input, expected: expected, linelength: 20, configuration: configuration) | ||
} | ||
|
||
func testArrayCommasPresentEnabled() { | ||
let input = | ||
""" | ||
let MyCollection = [ | ||
1, | ||
2, | ||
3, | ||
] | ||
""" | ||
|
||
let expected = | ||
""" | ||
let MyCollection = [ | ||
1, | ||
2, | ||
3, | ||
] | ||
""" | ||
|
||
var configuration = Configuration.forTesting | ||
configuration.multiElementCollectionTrailingCommas = true | ||
assertPrettyPrintEqual(input: input, expected: expected, linelength: 20, configuration: configuration) | ||
} | ||
|
||
func testArrayCommasPresentDisabled() { | ||
let input = | ||
""" | ||
let MyCollection = [ | ||
1, | ||
2, | ||
3, | ||
] | ||
""" | ||
|
||
let expected = | ||
""" | ||
let MyCollection = [ | ||
1, | ||
2, | ||
3 | ||
] | ||
""" | ||
|
||
var configuration = Configuration.forTesting | ||
configuration.multiElementCollectionTrailingCommas = false | ||
assertPrettyPrintEqual(input: input, expected: expected, linelength: 20, configuration: configuration) | ||
} | ||
|
||
func testArraySingleLineCommasPresentDisabled() { | ||
let input = | ||
""" | ||
let MyCollection = [1, 2, 3,] | ||
""" | ||
|
||
// no effect expected | ||
let expected = | ||
""" | ||
let MyCollection = [1, 2, 3] | ||
""" | ||
|
||
var configuration = Configuration.forTesting | ||
configuration.multiElementCollectionTrailingCommas = true | ||
assertPrettyPrintEqual(input: input, expected: expected, linelength: 40, configuration: configuration) | ||
} | ||
|
||
func testArraySingleLineCommasPresentEnabled() { | ||
let input = | ||
""" | ||
let MyCollection = [1, 2, 3,] | ||
""" | ||
|
||
// no effect expected | ||
let expected = | ||
""" | ||
let MyCollection = [1, 2, 3] | ||
""" | ||
|
||
var configuration = Configuration.forTesting | ||
configuration.multiElementCollectionTrailingCommas = false | ||
assertPrettyPrintEqual(input: input, expected: expected, linelength: 40, configuration: configuration) | ||
} | ||
|
||
func testDictionaryCommasAbsentEnabled() { | ||
let input = | ||
""" | ||
let MyCollection = [ | ||
"a": 1, | ||
"b": 2, | ||
"c": 3 | ||
] | ||
""" | ||
|
||
let expected = | ||
""" | ||
let MyCollection = [ | ||
"a": 1, | ||
"b": 2, | ||
"c": 3, | ||
] | ||
""" | ||
|
||
var configuration = Configuration.forTesting | ||
configuration.multiElementCollectionTrailingCommas = true | ||
assertPrettyPrintEqual(input: input, expected: expected, linelength: 20, configuration: configuration) | ||
} | ||
|
||
func testDictionaryCommasAbsentDisabled() { | ||
let input = | ||
""" | ||
let MyCollection = [ | ||
"a": 1, | ||
"b": 2, | ||
"c": 3 | ||
] | ||
""" | ||
|
||
let expected = | ||
""" | ||
let MyCollection = [ | ||
"a": 1, | ||
"b": 2, | ||
"c": 3 | ||
] | ||
""" | ||
|
||
var configuration = Configuration.forTesting | ||
configuration.multiElementCollectionTrailingCommas = false | ||
assertPrettyPrintEqual(input: input, expected: expected, linelength: 20, configuration: configuration) | ||
} | ||
|
||
func testDictionaryCommasPresentEnabled() { | ||
let input = | ||
""" | ||
let MyCollection = [ | ||
"a": 1, | ||
"b": 2, | ||
"c": 3, | ||
] | ||
""" | ||
|
||
let expected = | ||
""" | ||
let MyCollection = [ | ||
"a": 1, | ||
"b": 2, | ||
"c": 3, | ||
] | ||
""" | ||
|
||
var configuration = Configuration.forTesting | ||
configuration.multiElementCollectionTrailingCommas = true | ||
assertPrettyPrintEqual(input: input, expected: expected, linelength: 20, configuration: configuration) | ||
} | ||
|
||
func testDictionaryCommasPresentDisabled() { | ||
let input = | ||
""" | ||
let MyCollection = [ | ||
"a": 1, | ||
"b": 2, | ||
"c": 3, | ||
] | ||
""" | ||
|
||
let expected = | ||
""" | ||
let MyCollection = [ | ||
"a": 1, | ||
"b": 2, | ||
"c": 3 | ||
] | ||
""" | ||
|
||
var configuration = Configuration.forTesting | ||
configuration.multiElementCollectionTrailingCommas = false | ||
assertPrettyPrintEqual(input: input, expected: expected, linelength: 20, configuration: configuration) | ||
} | ||
|
||
func testDictionarySingleLineCommasPresentDisabled() { | ||
let input = | ||
""" | ||
let MyCollection = ["a": 1, "b": 2, "c": 3,] | ||
""" | ||
|
||
let expected = | ||
""" | ||
let MyCollection = [ | ||
"a": 1, "b": 2, "c": 3, | ||
] | ||
""" | ||
|
||
var configuration = Configuration.forTesting | ||
configuration.multiElementCollectionTrailingCommas = true | ||
assertPrettyPrintEqual(input: input, expected: expected, linelength: 40, configuration: configuration) | ||
} | ||
|
||
func testDictionarySingleLineCommasPresentEnabled() { | ||
let input = | ||
""" | ||
let MyCollection = ["a": 1, "b": 2, "c": 3,] | ||
""" | ||
|
||
let expected = | ||
""" | ||
let MyCollection = [ | ||
"a": 1, "b": 2, "c": 3 | ||
] | ||
""" | ||
|
||
var configuration = Configuration.forTesting | ||
configuration.multiElementCollectionTrailingCommas = false | ||
assertPrettyPrintEqual(input: input, expected: expected, linelength: 40, configuration: configuration) | ||
} | ||
} |