Skip to content

Commit ba33c0d

Browse files
authored
Merge pull request #421 from natecook1000/fix_wholematch_substring
Keep substring bounds when searching in Regex.wholeMatch
2 parents c000596 + 812c394 commit ba33c0d

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

Sources/_StringProcessing/Regex/Match.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ extension BidirectionalCollection where SubSequence == Substring {
177177
public func wholeMatch<R: RegexComponent>(
178178
of r: R
179179
) -> Regex<R.RegexOutput>.Match? {
180-
try? r.regex.wholeMatch(in: self[...].base)
180+
try? r.regex.wholeMatch(in: self[...])
181181
}
182182

183183
/// Checks for a match against the string, starting at its beginning.

Tests/RegexBuilderTests/AlgorithmsTests.swift

+10
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,16 @@ class AlgorithmsResultBuilderTests: XCTestCase {
229229
}
230230

231231
func testMatches() throws {
232+
do {
233+
let regex = Regex { OneOrMore(.any) }
234+
XCTAssertEqual("abc".wholeMatch(of: regex)!.0, "abc")
235+
XCTAssertEqual("abc".prefixMatch(of: regex)!.0, "abc")
236+
XCTAssertEqual("abc".firstMatch(of: regex)!.0, "abc")
237+
XCTAssertEqual("abc".suffix(1).wholeMatch(of: regex)!.0, "c")
238+
XCTAssertEqual("abc".suffix(1).prefixMatch(of: regex)!.0, "c")
239+
XCTAssertEqual("abc".suffix(1).firstMatch(of: regex)!.0, "c")
240+
}
241+
232242
let int = Capture(OneOrMore(.digit)) { Int($0)! }
233243

234244
// Test syntax

0 commit comments

Comments
 (0)