Skip to content

Commit dd1ee7b

Browse files
committed
Improve testing around reverse string
1 parent bc68e9c commit dd1ee7b

File tree

1 file changed

+89
-3
lines changed

1 file changed

+89
-3
lines changed

Tests/MutationKitTests/ReverseStringTests.swift

Lines changed: 89 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,13 @@ import Testing
66
@Suite("ReverseString")
77
struct ReverseStringTests {
88

9+
@Test("empty")
10+
func empty() {
11+
let file = Source.File(name: "name", path: "path", code: "")
12+
let mutants = Mutation.reverseString.mutants(for: file)
13+
#expect(mutants.isEmpty)
14+
}
15+
916
@Test("none")
1017
func none() {
1118

@@ -19,8 +26,8 @@ struct ReverseStringTests {
1926
#expect(mutants.isEmpty)
2027
}
2128

22-
@Test("mutation")
23-
func mutation() throws {
29+
@Test("single")
30+
func single() throws {
2431

2532
let file = Source.File(name: "name", path: "path", code: """
2633
func hello() {
@@ -44,5 +51,84 @@ struct ReverseStringTests {
4451
}
4552
""")
4653
}
47-
}
4854

55+
@Test("multiple")
56+
func multiple() throws {
57+
58+
let file = Source.File(name: "name", path: "path", code: """
59+
func foo() {
60+
print("hello!")
61+
}
62+
63+
var bar: String { "baz" }
64+
""")
65+
66+
let mutants = Mutation.reverseString.mutants(for: file)
67+
68+
try #require(mutants.count == 2)
69+
#expect(mutants[0].original == file.code)
70+
#expect(mutants[0].mutation == "Reverse String")
71+
#expect(mutants[0].location.name == file.name)
72+
#expect(mutants[0].location.path == file.path)
73+
#expect(mutants[0].location.start == Source.Position(line: 2, column: 10, offset: 22))
74+
#expect(mutants[0].location.end == Source.Position(line: 2, column: 16, offset: 28))
75+
#expect(mutants[0].replacement == """
76+
func foo() {
77+
print("!olleh")
78+
}
79+
80+
var bar: String { "baz" }
81+
""")
82+
83+
#expect(mutants[1].original == file.code)
84+
#expect(mutants[1].mutation == "Reverse String")
85+
#expect(mutants[1].location.name == file.name)
86+
#expect(mutants[1].location.path == file.path)
87+
#expect(mutants[1].location.start == Source.Position(line: 5, column: 20, offset: 53))
88+
#expect(mutants[1].location.end == Source.Position(line: 5, column: 23, offset: 56))
89+
#expect(mutants[1].replacement == """
90+
func foo() {
91+
print("hello!")
92+
}
93+
94+
var bar: String { "zab" }
95+
""")
96+
}
97+
98+
@Test("interpolated expressions")
99+
func interpolatedExpressions() throws {
100+
101+
let file = Source.File(name: "name", path: "path", code: #"""
102+
func hello(name: String) {
103+
print("hello \(name) and welcome!")
104+
}
105+
"""#)
106+
107+
let mutants = Mutation.reverseString.mutants(for: file)
108+
109+
try #require(mutants.count == 2)
110+
#expect(mutants[0].original == file.code)
111+
#expect(mutants[0].mutation == "Reverse String")
112+
#expect(mutants[0].location.name == file.name)
113+
#expect(mutants[0].location.path == file.path)
114+
#expect(mutants[0].location.start == Source.Position(line: 2, column: 10, offset: 36))
115+
#expect(mutants[0].location.end == Source.Position(line: 2, column: 16, offset: 42))
116+
#expect(mutants[0].replacement == #"""
117+
func hello(name: String) {
118+
print(" olleh\(name) and welcome!")
119+
}
120+
"""#)
121+
122+
#expect(mutants[1].original == file.code)
123+
#expect(mutants[1].mutation == "Reverse String")
124+
#expect(mutants[1].location.name == file.name)
125+
#expect(mutants[1].location.path == file.path)
126+
#expect(mutants[1].location.start == Source.Position(line: 2, column: 23, offset: 49))
127+
#expect(mutants[1].location.end == Source.Position(line: 2, column: 36, offset: 62))
128+
#expect(mutants[1].replacement == #"""
129+
func hello(name: String) {
130+
print("hello \(name)!emoclew dna ")
131+
}
132+
"""#)
133+
}
134+
}

0 commit comments

Comments
 (0)