File tree Expand file tree Collapse file tree 1 file changed +16
-7
lines changed Expand file tree Collapse file tree 1 file changed +16
-7
lines changed Original file line number Diff line number Diff line change @@ -13,6 +13,13 @@ import XCTest
13
13
@testable import _MatchingEngine
14
14
@testable import _StringProcessing
15
15
16
+ struct MatchError : Error {
17
+ var message : String
18
+ init ( _ message: String ) {
19
+ self . message = message
20
+ }
21
+ }
22
+
16
23
extension Executor {
17
24
func _firstMatch(
18
25
_ regex: String , input: String ,
@@ -31,7 +38,7 @@ extension Executor {
31
38
let caps = result. rawCaptures. slices ( from: input)
32
39
return ( input [ result. range] , caps)
33
40
} else if start == input. endIndex {
34
- throw " match not found for \( regex) in \( input) "
41
+ throw MatchError ( " match not found for \( regex) in \( input) " )
35
42
} else {
36
43
input. formIndex ( after: & start)
37
44
}
@@ -76,27 +83,29 @@ func flatCaptureTest(
76
83
if expect == nil {
77
84
continue
78
85
} else {
79
- throw " Match failed "
86
+ throw MatchError ( " Match failed " )
80
87
}
81
88
}
82
89
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
+ """ )
84
93
}
85
94
let capStrs = caps. map { $0 == nil ? nil : String ( $0!) }
86
95
guard expect. count == capStrs. count else {
87
- throw """
96
+ throw MatchError ( """
88
97
Capture count mismatch:
89
98
\( expect)
90
99
\( capStrs)
91
- """
100
+ """ )
92
101
}
93
102
94
103
guard expect. elementsEqual ( capStrs) else {
95
- throw """
104
+ throw MatchError ( """
96
105
Capture mismatch:
97
106
\( expect)
98
107
\( capStrs)
99
- """
108
+ """ )
100
109
}
101
110
} catch {
102
111
if !xfail {
You can’t perform that action at this time.
0 commit comments