Skip to content

Commit bf8c1a9

Browse files
committed
Update tests as well
1 parent bf7710d commit bf8c1a9

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

Tests/RegexTests/MatchTests.swift

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,13 @@ import XCTest
1313
@testable import _MatchingEngine
1414
@testable import _StringProcessing
1515

16+
struct MatchError: Error {
17+
var message: String
18+
init(_ message: String) {
19+
self.message = message
20+
}
21+
}
22+
1623
extension Executor {
1724
func _firstMatch(
1825
_ regex: String, input: String,
@@ -31,7 +38,7 @@ extension Executor {
3138
let caps = result.rawCaptures.slices(from: input)
3239
return (input[result.range], caps)
3340
} else if start == input.endIndex {
34-
throw "match not found for \(regex) in \(input)"
41+
throw MatchError("match not found for \(regex) in \(input)")
3542
} else {
3643
input.formIndex(after: &start)
3744
}
@@ -76,27 +83,29 @@ func flatCaptureTest(
7683
if expect == nil {
7784
continue
7885
} else {
79-
throw "Match failed"
86+
throw MatchError("Match failed")
8087
}
8188
}
8289
guard let expect = expect else {
83-
throw "Match of \(test) succeeded where failure expected in \(regex)"
90+
throw MatchError("""
91+
Match of \(test) succeeded where failure expected in \(regex)
92+
""")
8493
}
8594
let capStrs = caps.map { $0 == nil ? nil : String($0!) }
8695
guard expect.count == capStrs.count else {
87-
throw """
96+
throw MatchError("""
8897
Capture count mismatch:
8998
\(expect)
9099
\(capStrs)
91-
"""
100+
""")
92101
}
93102

94103
guard expect.elementsEqual(capStrs) else {
95-
throw """
104+
throw MatchError("""
96105
Capture mismatch:
97106
\(expect)
98107
\(capStrs)
99-
"""
108+
""")
100109
}
101110
} catch {
102111
if !xfail {

0 commit comments

Comments
 (0)