@@ -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 (
@@ -1464,6 +1462,74 @@ extension RegexTests {
1464
1462
firstMatchTest ( #".+"# , input: " a \n b " , match: " a " )
1465
1463
firstMatchTest ( #"(?s:.+)"# , input: " a \n b " , match: " a \n b " )
1466
1464
}
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
+ }
1467
1533
1468
1534
func testCaseSensitivity( ) {
1469
1535
matchTest (
0 commit comments