Skip to content

Commit 5dff33a

Browse files
committed
Test matches/ranges/replace w/ scalar semantics
1 parent a94c72c commit 5dff33a

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

Tests/RegexTests/AlgorithmsTests.swift

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -498,6 +498,25 @@ class AlgorithmTests: XCTestCase {
498498
s2.ranges(of: try Regex("a*?")).map(s2.offsets(of:)), [0..<0, 1..<1, 2..<2])
499499
}
500500

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+
501520
func testSwitches() {
502521
switch "abcde" {
503522
case try! Regex("a.*f"):

0 commit comments

Comments
 (0)