Skip to content

Commit 1acb82a

Browse files
committed
Add some extra character class newline matching tests
1 parent e343554 commit 1acb82a

File tree

1 file changed

+68
-2
lines changed

1 file changed

+68
-2
lines changed

Tests/RegexTests/MatchTests.swift

Lines changed: 68 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -320,8 +320,6 @@ extension RegexTests {
320320
input: "\u{7}\u{8}\u{1B}\u{C}\n\r\t",
321321
match: "\u{7}\u{8}\u{1B}\u{C}\n\r\t")
322322

323-
firstMatchTest(#"\r\n"#, input: "\r\n", match: "\r\n")
324-
325323
// MARK: Quotes
326324

327325
firstMatchTest(
@@ -1473,6 +1471,74 @@ extension RegexTests {
14731471
firstMatchTest(#".+"#, input: "a\nb", match: "a")
14741472
firstMatchTest(#"(?s:.+)"#, input: "a\nb", match: "a\nb")
14751473
}
1474+
1475+
func testMatchNewlines() {
1476+
// Must have new stdlib for character class ranges and word boundaries.
1477+
guard ensureNewStdlib() else { return }
1478+
1479+
for semantics in [RegexSemanticLevel.unicodeScalar, .graphemeCluster] {
1480+
firstMatchTest(
1481+
#"\r\n"#, input: "\r\n", match: "\r\n",
1482+
semanticLevel: semantics
1483+
)
1484+
firstMatchTest(
1485+
#"\r\n"#, input: "\n", match: nil, semanticLevel: semantics)
1486+
firstMatchTest(
1487+
#"\r\n"#, input: "\r", match: nil, semanticLevel: semantics)
1488+
1489+
// \r\n is not treated as ASCII.
1490+
firstMatchTest(
1491+
#"^\p{ASCII}$"#, input: "\r\n", match: nil,
1492+
semanticLevel: semantics
1493+
)
1494+
firstMatchTest(
1495+
#"^\r$"#, input: "\r\n", match: nil,
1496+
semanticLevel: semantics
1497+
)
1498+
firstMatchTest(
1499+
#"^[\r]$"#, input: "\r\n", match: nil,
1500+
semanticLevel: semantics
1501+
)
1502+
firstMatchTest(
1503+
#"^\n$"#, input: "\r\n", match: nil,
1504+
semanticLevel: semantics
1505+
)
1506+
firstMatchTest(
1507+
#"^[\n]$"#, input: "\r\n", match: nil,
1508+
semanticLevel: semantics
1509+
)
1510+
firstMatchTest(
1511+
#"^[\u{0}-\u{7F}]$"#, input: "\r\n", match: nil,
1512+
semanticLevel: semantics
1513+
)
1514+
1515+
let scalarSemantics = semantics == .unicodeScalar
1516+
firstMatchTest(
1517+
#"\p{ASCII}"#, input: "\r\n", match: scalarSemantics ? "\r" : nil,
1518+
semanticLevel: semantics
1519+
)
1520+
firstMatchTest(
1521+
#"\r"#, input: "\r\n", match: scalarSemantics ? "\r" : nil,
1522+
semanticLevel: semantics
1523+
)
1524+
firstMatchTest(
1525+
#"[\r]"#, input: "\r\n", match: scalarSemantics ? "\r" : nil,
1526+
semanticLevel: semantics
1527+
)
1528+
firstMatchTest(
1529+
#"\n"#, input: "\r\n", match: scalarSemantics ? "\n" : nil,
1530+
semanticLevel: semantics
1531+
)
1532+
firstMatchTest(
1533+
#"[\n]"#, input: "\r\n", match: scalarSemantics ? "\n" : nil,
1534+
semanticLevel: semantics
1535+
)
1536+
firstMatchTest(
1537+
#"[\u{0}-\u{7F}]"#, input: "\r\n", match: scalarSemantics ? "\r" : nil,
1538+
semanticLevel: semantics
1539+
)
1540+
}
1541+
}
14761542

14771543
func testCaseSensitivity() {
14781544
matchTest(

0 commit comments

Comments
 (0)