@@ -320,8 +320,6 @@ extension RegexTests {
320
320
input: " \u{7} \u{8} \u{1B} \u{C} \n \r \t " ,
321
321
match: " \u{7} \u{8} \u{1B} \u{C} \n \r \t " )
322
322
323
- firstMatchTest ( #"\r\n"# , input: " \r \n " , match: " \r \n " )
324
-
325
323
// MARK: Quotes
326
324
327
325
firstMatchTest (
@@ -1473,6 +1471,74 @@ extension RegexTests {
1473
1471
firstMatchTest ( #".+"# , input: " a \n b " , match: " a " )
1474
1472
firstMatchTest ( #"(?s:.+)"# , input: " a \n b " , match: " a \n b " )
1475
1473
}
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
+ }
1476
1542
1477
1543
func testCaseSensitivity( ) {
1478
1544
matchTest (
0 commit comments