@@ -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 (
@@ -1430,6 +1428,74 @@ extension RegexTests {
1430
1428
firstMatchTest ( #".+"# , input: " a \n b " , match: " a " )
1431
1429
firstMatchTest ( #"(?s:.+)"# , input: " a \n b " , match: " a \n b " )
1432
1430
}
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
+ }
1433
1499
1434
1500
func testCaseSensitivity( ) {
1435
1501
matchTest (
0 commit comments