Skip to content

Commit

Permalink
Add new void rule example and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nicklockwood committed Aug 15, 2020
1 parent 3ae5d97 commit 628ff49
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
5 changes: 5 additions & 0 deletions Sources/Examples.swift
Original file line number Diff line number Diff line change
Expand Up @@ -953,6 +953,11 @@ private struct Examples {
- func quux() -> (Void)
+ func quux() -> Void
```
```diff
- callback = { _ in Void() }
+ callback = { _ in () }
```
"""

let wrapArguments = """
Expand Down
20 changes: 20 additions & 0 deletions Tests/RulesTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4876,6 +4876,26 @@ class RulesTests: XCTestCase {
testFormatting(for: input, output, rule: FormatRules.void)
}

func testVoidLiteralReturnValueConvertedToParens() {
let input = """
func foo() {
return Void()
}
"""
let output = """
func foo() {
return ()
}
"""
testFormatting(for: input, output, rule: FormatRules.void)
}

func testVoidLiteralReturnValueConvertedToParens2() {
let input = "{ _ in Void() }"
let output = "{ _ in () }"
testFormatting(for: input, output, rule: FormatRules.void)
}

func testNamespacedVoidLiteralNotConverted() {
let input = "let foo = Swift.Void()"
testFormatting(for: input, rule: FormatRules.void)
Expand Down
2 changes: 2 additions & 0 deletions Tests/XCTestManifests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1843,6 +1843,8 @@ extension RulesTests {
("testVoidClosureReturnValueConvertedToEmptyTuple", testVoidClosureReturnValueConvertedToEmptyTuple),
("testVoidLiteralConvertedToParens", testVoidLiteralConvertedToParens),
("testVoidLiteralConvertedToParens2", testVoidLiteralConvertedToParens2),
("testVoidLiteralReturnValueConvertedToParens", testVoidLiteralReturnValueConvertedToParens),
("testVoidLiteralReturnValueConvertedToParens2", testVoidLiteralReturnValueConvertedToParens2),
("testVoidThrowsIsNotMangled", testVoidThrowsIsNotMangled),
("testWhileAndReplaced", testWhileAndReplaced),
("testWhileNotAffectedByElseOnSameLineIfNotRepeatWhile", testWhileNotAffectedByElseOnSameLineIfNotRepeatWhile),
Expand Down

0 comments on commit 628ff49

Please sign in to comment.