Skip to content

Commit 2d13a10

Browse files
committed
Add some extra character class newline matching tests
1 parent 9061836 commit 2d13a10

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(
@@ -1430,6 +1428,74 @@ extension RegexTests {
14301428
firstMatchTest(#".+"#, input: "a\nb", match: "a")
14311429
firstMatchTest(#"(?s:.+)"#, input: "a\nb", match: "a\nb")
14321430
}
1431+
1432+
func testMatchNewlines() {
1433+
// Must have new stdlib for character class ranges and word boundaries.
1434+
guard ensureNewStdlib() else { return }
1435+
1436+
for semantics in [RegexSemanticLevel.unicodeScalar, .graphemeCluster] {
1437+
firstMatchTest(
1438+
#"\r\n"#, input: "\r\n", match: "\r\n",
1439+
semanticLevel: semantics
1440+
)
1441+
firstMatchTest(
1442+
#"\r\n"#, input: "\n", match: nil, semanticLevel: semantics)
1443+
firstMatchTest(
1444+
#"\r\n"#, input: "\r", match: nil, semanticLevel: semantics)
1445+
1446+
// \r\n is not treated as ASCII.
1447+
firstMatchTest(
1448+
#"^\p{ASCII}$"#, input: "\r\n", match: nil,
1449+
semanticLevel: semantics
1450+
)
1451+
firstMatchTest(
1452+
#"^\r$"#, input: "\r\n", match: nil,
1453+
semanticLevel: semantics
1454+
)
1455+
firstMatchTest(
1456+
#"^[\r]$"#, input: "\r\n", match: nil,
1457+
semanticLevel: semantics
1458+
)
1459+
firstMatchTest(
1460+
#"^\n$"#, input: "\r\n", match: nil,
1461+
semanticLevel: semantics
1462+
)
1463+
firstMatchTest(
1464+
#"^[\n]$"#, input: "\r\n", match: nil,
1465+
semanticLevel: semantics
1466+
)
1467+
firstMatchTest(
1468+
#"^[\u{0}-\u{7F}]$"#, input: "\r\n", match: nil,
1469+
semanticLevel: semantics
1470+
)
1471+
1472+
let scalarSemantics = semantics == .unicodeScalar
1473+
firstMatchTest(
1474+
#"\p{ASCII}"#, input: "\r\n", match: scalarSemantics ? "\r" : nil,
1475+
semanticLevel: semantics
1476+
)
1477+
firstMatchTest(
1478+
#"\r"#, input: "\r\n", match: scalarSemantics ? "\r" : nil,
1479+
semanticLevel: semantics
1480+
)
1481+
firstMatchTest(
1482+
#"[\r]"#, input: "\r\n", match: scalarSemantics ? "\r" : nil,
1483+
semanticLevel: semantics
1484+
)
1485+
firstMatchTest(
1486+
#"\n"#, input: "\r\n", match: scalarSemantics ? "\n" : nil,
1487+
semanticLevel: semantics
1488+
)
1489+
firstMatchTest(
1490+
#"[\n]"#, input: "\r\n", match: scalarSemantics ? "\n" : nil,
1491+
semanticLevel: semantics
1492+
)
1493+
firstMatchTest(
1494+
#"[\u{0}-\u{7F}]"#, input: "\r\n", match: scalarSemantics ? "\r" : nil,
1495+
semanticLevel: semantics
1496+
)
1497+
}
1498+
}
14331499

14341500
func testCaseSensitivity() {
14351501
matchTest(

0 commit comments

Comments
 (0)