File tree Expand file tree Collapse file tree 2 files changed +40
-4
lines changed
Sources/_StringProcessing/Regex Expand file tree Collapse file tree 2 files changed +40
-4
lines changed Original file line number Diff line number Diff line change @@ -187,13 +187,15 @@ extension Regex {
187
187
}
188
188
189
189
@available ( SwiftStdlib 5 . 7 , * )
190
- public func ~= < Output> ( regex: Regex < Output > , input: String ) -> Bool {
191
- guard let _ = try ? regex. wholeMatch ( in: input) else { return false }
190
+ @_disfavoredOverload // disambiguate from equatable patterns
191
+ public func ~= < R: RegexComponent > ( regex: R , input: String ) -> Bool {
192
+ guard let _ = input. wholeMatch ( of: regex) else { return false }
192
193
return true
193
194
}
194
195
195
196
@available ( SwiftStdlib 5 . 7 , * )
196
- public func ~= < Output> ( regex: Regex < Output > , input: Substring ) -> Bool {
197
- guard let _ = try ? regex. wholeMatch ( in: input) else { return false }
197
+ @_disfavoredOverload // disambiguate from equatable patterns
198
+ public func ~= < R: RegexComponent > ( regex: R , input: Substring ) -> Bool {
199
+ guard let _ = input. wholeMatch ( of: regex) else { return false }
198
200
return true
199
201
}
Original file line number Diff line number Diff line change @@ -104,4 +104,38 @@ class RegexConsumerTests: XCTestCase {
104
104
result: " 9+16, 3, 10, 99+1 " )
105
105
)
106
106
}
107
+
108
+ func testSwitches( ) {
109
+ switch " abcde " {
110
+ case Regex {
111
+ " a "
112
+ ZeroOrMore ( . any)
113
+ " f "
114
+ } :
115
+ XCTFail ( )
116
+
117
+ case " abc " :
118
+ XCTFail ( )
119
+
120
+ case Regex {
121
+ " a "
122
+ " b "
123
+ " c "
124
+ } :
125
+ XCTFail ( )
126
+
127
+ case Regex {
128
+ " a "
129
+ ZeroOrMore ( . any)
130
+ " e "
131
+ } :
132
+ break // success
133
+
134
+ case OneOrMore ( . word) :
135
+ break // success
136
+
137
+ default :
138
+ XCTFail ( )
139
+ }
140
+ }
107
141
}
You can’t perform that action at this time.
0 commit comments