Skip to content

Commit 87dc7fb

Browse files
committed
word breaking test case
1 parent 45fd8ec commit 87dc7fb

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

Tests/RegexTests/MatchTests.swift

+42
Original file line numberDiff line numberDiff line change
@@ -1683,6 +1683,38 @@ extension RegexTests {
16831683
firstMatchTest(#"\b÷\b"#, input: "3 ÷ 3 = 1", match: "÷")
16841684
}
16851685

1686+
func testLevel2WordBoundaries_2() throws {
1687+
let re = try! Regex(#"\bA\b"#)
1688+
1689+
// OK: Space after colon works (note "NO ENTRY" emoji has U+FE0F after it)
1690+
try print(re.firstMatch(in: "⛔️: X ") == nil) // => true
1691+
try print(re.firstMatch(in: "\u{FE0F}: X ") == nil) // => true
1692+
try print(re.firstMatch(in: "👨‍👨‍👧‍👦\u{FE0F}: X ") == nil) // => true
1693+
1694+
// OK: No U+FE0F to left of colon, no space after colon
1695+
try print(re.firstMatch(in: "Z:X ") == nil) // => true
1696+
1697+
// OK: Alphabetic followed by U+FE0F to left of colon
1698+
try print(re.firstMatch(in: "Z\u{FE0F}:X ") == nil) // => true
1699+
try print(re.firstMatch(in: "è\u{FE0F}:X ") == nil) // => true
1700+
1701+
// OK: Non-alphabetic without U+FE0F
1702+
try print(re.firstMatch(in: "日:X ") == nil) // => true
1703+
try print(re.firstMatch(in: "👨‍👨‍👧‍👦:X ") == nil) // => true
1704+
1705+
print("all the rest hang...")
1706+
1707+
// HANGS: Non-alphabetic followed by U+FE0F to left of colon (note "NO ENTRY" emoji has U+FE0F)
1708+
try print(re.firstMatch(in: "\u{FE0F}:X ") == nil) // => HANGS!
1709+
try print(re.firstMatch(in: "👨‍👨‍👧‍👦\u{FE0F}:X ") == nil) // => HANGS!
1710+
try print(re.firstMatch(in: "⛔️:X ") == nil) // => HANGS!
1711+
1712+
// HANGS: Other MidLetters as well, not just colon (note "NO ENTRY" emoji has U+FE0F)
1713+
try print(re.firstMatch(in: "⛔️·X ") == nil) // => HANGS!
1714+
try print(re.firstMatch(in: "⛔️:X ") == nil) // => HANGS!
1715+
1716+
}
1717+
16861718
func testMatchGroups() {
16871719
// Must have new stdlib for character class ranges and word boundaries.
16881720
guard ensureNewStdlib() else { return }
@@ -2717,4 +2749,14 @@ extension RegexTests {
27172749
XCTAssertNotNil(str.wholeMatch(of: possessiveRegex))
27182750
}
27192751
}
2752+
2753+
func testFoo() throws {
2754+
let re = try Regex(#"^[\u{0000}-\u{024F}]+$"#)
2755+
2756+
XCTAssertNotNil("aaa".wholeMatch(of: re))
2757+
XCTAssertNotNil("aa\u{301}a".wholeMatch(of: re))
2758+
XCTAssertNil("aa\u{301}\u{302}a".wholeMatch(of: re))
2759+
}
27202760
}
2761+
2762+

0 commit comments

Comments
 (0)