Skip to content

Add tests for line start/end word boundary diffs #616

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 2, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions Tests/RegexTests/MatchTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1517,6 +1517,19 @@ extension RegexTests {
(" 123", "23"),
("123 456", "23"))

let defaultBoundaryRegex = try Regex(#"\b.{3}X.{3}\b"#)
// Default word boundaries match at the start/end of a string/line.
XCTAssertNotNil(try defaultBoundaryRegex.firstMatch(in: "---X---"))
XCTAssertNotNil(try defaultBoundaryRegex.firstMatch(in: "abc\n---X---\ndef"))

let simpleBoundaryRegex = defaultBoundaryRegex.wordBoundaryKind(.simple)
// Simple word boundaries match only when the adjacent position matches \w.
XCTAssertNil(try simpleBoundaryRegex.firstMatch(in: "---X---"))
XCTAssertNil(try simpleBoundaryRegex.firstMatch(in: "abc\n---X---\ndef"))

XCTAssertNotNil(try simpleBoundaryRegex.firstMatch(in: "x--X--x"))
XCTAssertNotNil(try simpleBoundaryRegex.firstMatch(in: "abc\nx--X--x\ndef"))

// \G and \K
let regex = try Regex(#"\Gab"#, as: Substring.self)
XCTAssertEqual("abab".matches(of: regex).map(\.output), ["ab", "ab"])
Expand Down