@@ -498,6 +498,25 @@ class AlgorithmTests: XCTestCase {
498
498
s2. ranges ( of: try Regex ( " a*? " ) ) . map ( s2. offsets ( of: ) ) , [ 0 ..< 0 , 1 ..< 1 , 2 ..< 2 ] )
499
499
}
500
500
501
+ func testUnicodeScalarSemantics( ) throws {
502
+ let regex = try Regex ( #"(?u)."# , as: Substring . self)
503
+ let emptyRegex = try Regex ( #"(?u)z?"# , as: Substring . self)
504
+
505
+ XCTAssertEqual ( " " . matches ( of: regex) . map ( \. output) , [ ] )
506
+ XCTAssertEqual ( " Café " . matches ( of: regex) . map ( \. output) , [ " C " , " a " , " f " , " é " ] )
507
+ XCTAssertEqual ( " Cafe \u{301} " . matches ( of: regex) . map ( \. output) , [ " C " , " a " , " f " , " e " , " \u{301} " ] )
508
+ XCTAssertEqual ( " Cafe \u{301} " . matches ( of: emptyRegex) . count, 6 )
509
+
510
+ XCTAssertEqual ( " Café " . ranges ( of: regex) . count, 4 )
511
+ XCTAssertEqual ( " Cafe \u{301} " . ranges ( of: regex) . count, 5 )
512
+ XCTAssertEqual ( " Cafe \u{301} " . ranges ( of: emptyRegex) . count, 6 )
513
+
514
+ XCTAssertEqual ( " Café " . replacing ( regex, with: " - " ) , " ---- " )
515
+ XCTAssertEqual ( " Cafe \u{301} " . replacing ( regex, with: " - " ) , " ----- " )
516
+ XCTAssertEqual ( " Café " . replacing ( emptyRegex, with: " - " ) , " -C-a-f-é- " )
517
+ XCTAssertEqual ( " Cafe \u{301} " . replacing ( emptyRegex, with: " - " ) , " -C-a-f-e- \u{301} - " )
518
+ }
519
+
501
520
func testSwitches( ) {
502
521
switch " abcde " {
503
522
case try ! Regex ( " a.*f " ) :
0 commit comments