Skip to content
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