Skip to content

Commit d9e26bb

Browse files
committed
Add some extra character class newline matching tests
1 parent 6501cf5 commit d9e26bb

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(
@@ -1464,6 +1462,74 @@ extension RegexTests {
14641462
firstMatchTest(#".+"#, input: "a\nb", match: "a")
14651463
firstMatchTest(#"(?s:.+)"#, input: "a\nb", match: "a\nb")
14661464
}
1465+
1466+
func testMatchNewlines() {
1467+
// Must have new stdlib for character class ranges and word boundaries.
1468+
guard ensureNewStdlib() else { return }
1469+
1470+
for semantics in [RegexSemanticLevel.unicodeScalar, .graphemeCluster] {
1471+
firstMatchTest(
1472+
#"\r\n"#, input: "\r\n", match: "\r\n",
1473+
semanticLevel: semantics
1474+
)
1475+
firstMatchTest(
1476+
#"\r\n"#, input: "\n", match: nil, semanticLevel: semantics)
1477+
firstMatchTest(
1478+
#"\r\n"#, input: "\r", match: nil, semanticLevel: semantics)
1479+
1480+
// \r\n is not treated as ASCII.
1481+
firstMatchTest(
1482+
#"^\p{ASCII}$"#, input: "\r\n", match: nil,
1483+
semanticLevel: semantics
1484+
)
1485+
firstMatchTest(
1486+
#"^\r$"#, input: "\r\n", match: nil,
1487+
semanticLevel: semantics
1488+
)
1489+
firstMatchTest(
1490+
#"^[\r]$"#, input: "\r\n", match: nil,
1491+
semanticLevel: semantics
1492+
)
1493+
firstMatchTest(
1494+
#"^\n$"#, input: "\r\n", match: nil,
1495+
semanticLevel: semantics
1496+
)
1497+
firstMatchTest(
1498+
#"^[\n]$"#, input: "\r\n", match: nil,
1499+
semanticLevel: semantics
1500+
)
1501+
firstMatchTest(
1502+
#"^[\u{0}-\u{7F}]$"#, input: "\r\n", match: nil,
1503+
semanticLevel: semantics
1504+
)
1505+
1506+
let scalarSemantics = semantics == .unicodeScalar
1507+
firstMatchTest(
1508+
#"\p{ASCII}"#, input: "\r\n", match: scalarSemantics ? "\r" : nil,
1509+
semanticLevel: semantics
1510+
)
1511+
firstMatchTest(
1512+
#"\r"#, input: "\r\n", match: scalarSemantics ? "\r" : nil,
1513+
semanticLevel: semantics
1514+
)
1515+
firstMatchTest(
1516+
#"[\r]"#, input: "\r\n", match: scalarSemantics ? "\r" : nil,
1517+
semanticLevel: semantics
1518+
)
1519+
firstMatchTest(
1520+
#"\n"#, input: "\r\n", match: scalarSemantics ? "\n" : nil,
1521+
semanticLevel: semantics
1522+
)
1523+
firstMatchTest(
1524+
#"[\n]"#, input: "\r\n", match: scalarSemantics ? "\n" : nil,
1525+
semanticLevel: semantics
1526+
)
1527+
firstMatchTest(
1528+
#"[\u{0}-\u{7F}]"#, input: "\r\n", match: scalarSemantics ? "\r" : nil,
1529+
semanticLevel: semantics
1530+
)
1531+
}
1532+
}
14671533

14681534
func testCaseSensitivity() {
14691535
matchTest(

0 commit comments

Comments
 (0)