Skip to content

Commit fcdf5ee

Browse files
committed
Adjust OmitReturnsTests to use the most recent APIs
1 parent a13a52f commit fcdf5ee

File tree

1 file changed

+61
-55
lines changed

1 file changed

+61
-55
lines changed
Lines changed: 61 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,105 +1,107 @@
1+
import _SwiftFormatTestSupport
2+
13
@_spi(Rules) import SwiftFormat
24

35
final class OmitReturnsTests: LintOrFormatRuleTestCase {
46
func testOmitReturnInFunction() {
5-
XCTAssertFormatting(
7+
assertFormatting(
68
OmitReturns.self,
79
input: """
810
func test() -> Bool {
9-
return false
11+
1️⃣return false
1012
}
11-
""",
13+
""",
1214
expected: """
1315
func test() -> Bool {
1416
false
1517
}
16-
""")
18+
""",
19+
findings: [
20+
FindingSpec("1️⃣", message: "`return` can be omitted because body consists of a single expression")
21+
])
1722
}
1823

1924
func testOmitReturnInClosure() {
20-
XCTAssertFormatting(
25+
assertFormatting(
2126
OmitReturns.self,
2227
input: """
2328
vals.filter {
24-
return $0.count == 1
29+
1️⃣return $0.count == 1
2530
}
26-
""",
31+
""",
2732
expected: """
2833
vals.filter {
2934
$0.count == 1
3035
}
31-
""")
36+
""",
37+
findings: [
38+
FindingSpec("1️⃣", message: "`return` can be omitted because body consists of a single expression")
39+
])
3240
}
3341

3442
func testOmitReturnInSubscript() {
35-
XCTAssertFormatting(
36-
OmitReturns.self,
37-
input: """
38-
struct Test {
39-
subscript(x: Int) -> Bool {
40-
return false
41-
}
42-
}
43-
""",
44-
expected: """
45-
struct Test {
46-
subscript(x: Int) -> Bool {
47-
false
48-
}
43+
assertFormatting(
44+
OmitReturns.self,
45+
input: """
46+
struct Test {
47+
subscript(x: Int) -> Bool {
48+
1️⃣return false
4949
}
50-
""")
50+
}
5151
52-
XCTAssertFormatting(
53-
OmitReturns.self,
54-
input: """
55-
struct Test {
56-
subscript(x: Int) -> Bool {
57-
get {
58-
return false
59-
}
60-
set { }
52+
struct Test {
53+
subscript(x: Int) -> Bool {
54+
get {
55+
2️⃣return false
6156
}
57+
set { }
58+
}
59+
}
60+
""",
61+
expected: """
62+
struct Test {
63+
subscript(x: Int) -> Bool {
64+
false
6265
}
63-
""",
64-
expected: """
65-
struct Test {
66-
subscript(x: Int) -> Bool {
67-
get {
68-
false
69-
}
70-
set { }
66+
}
67+
68+
struct Test {
69+
subscript(x: Int) -> Bool {
70+
get {
71+
false
7172
}
73+
set { }
7274
}
73-
""")
75+
}
76+
""",
77+
findings: [
78+
FindingSpec("1️⃣", message: "`return` can be omitted because body consists of a single expression"),
79+
FindingSpec("2️⃣", message: "`return` can be omitted because body consists of a single expression")
80+
])
7481
}
7582

7683
func testOmitReturnInComputedVars() {
77-
XCTAssertFormatting(
84+
assertFormatting(
7885
OmitReturns.self,
7986
input: """
8087
var x: Int {
81-
return 42
82-
}
83-
""",
84-
expected: """
85-
var x: Int {
86-
42
88+
1️⃣return 42
8789
}
88-
""")
8990
90-
XCTAssertFormatting(
91-
OmitReturns.self,
92-
input: """
9391
struct Test {
9492
var x: Int {
9593
get {
96-
return 42
94+
2️⃣return 42
9795
}
9896
set { }
9997
}
10098
}
101-
""",
99+
""",
102100
expected: """
101+
var x: Int {
102+
42
103+
}
104+
103105
struct Test {
104106
var x: Int {
105107
get {
@@ -108,6 +110,10 @@ final class OmitReturnsTests: LintOrFormatRuleTestCase {
108110
set { }
109111
}
110112
}
111-
""")
113+
""",
114+
findings: [
115+
FindingSpec("1️⃣", message: "`return` can be omitted because body consists of a single expression"),
116+
FindingSpec("2️⃣", message: "`return` can be omitted because body consists of a single expression")
117+
])
112118
}
113119
}

0 commit comments

Comments
 (0)