Skip to content

Commit 9041b9b

Browse files
committed
Add tests for individual scalar matching
1 parent a8aa433 commit 9041b9b

File tree

1 file changed

+28
-5
lines changed

1 file changed

+28
-5
lines changed

Tests/RegexTests/MatchTests.swift

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -837,6 +837,30 @@ extension RegexTests {
837837
var eComposed: String { "é" }
838838
var eDecomposed: String { "e\u{301}" }
839839

840+
func testIndividualScalars() {
841+
// Expectation: A standalone Unicode scalar value in a regex literal
842+
// can match either that specific scalar value or participate in matching
843+
// as a character.
844+
845+
matchTest(#"\u{65}\u{301}$"#, input: eDecomposed, match: eDecomposed)
846+
// FIXME: Decomposed character in regex literal doesn't match an equivalent character
847+
matchTest(#"\u{65}\u{301}$"#, input: eComposed, match: eComposed,
848+
xfail: true)
849+
850+
matchTest(#"\u{65}"#, input: eDecomposed, match: "e")
851+
matchTest(#"\u{65}$"#, input: eDecomposed, match: nil)
852+
// FIXME: \y is unsupported
853+
matchTest(#"\u{65}\y"#, input: eDecomposed, match: nil,
854+
xfail: true)
855+
856+
// FIXME: Unicode scalars are only matched at the start of a grapheme cluster
857+
matchTest(#"\u{301}"#, input: eDecomposed, match: "\u{301}",
858+
xfail: true)
859+
// FIXME: \y is unsupported
860+
matchTest(#"\y\u{301}"#, input: eDecomposed, match: nil,
861+
xfail: true)
862+
}
863+
840864
func testCanonicalEquivalence() throws {
841865
// Expectation: Matching should use canonical equivalence whenever comparing
842866
// characters, so a user can write characters using any equivalent spelling
@@ -846,20 +870,20 @@ extension RegexTests {
846870
#"é$"#,
847871
(eComposed, eComposed),
848872
(eDecomposed, eDecomposed))
849-
873+
850874
// FIXME: Decomposed character in regex literal doesn't match an equivalent character
851875
matchTests(
852876
#"e\u{301}$"#,
853877
(eComposed, eComposed),
854878
(eDecomposed, eDecomposed),
855879
xfail: true)
856-
880+
857881
matchTests(
858882
#"e$"#,
859883
(eComposed, nil),
860884
(eDecomposed, nil))
861885
}
862-
886+
863887
func testCanonicalEquivalenceCharacterClass() throws {
864888
// Expectation: Character classes should match equivalent characters to the
865889
// same degree, regardless of how they are spelled. Unicode "property
@@ -980,8 +1004,7 @@ extension RegexTests {
9801004
xfail: true)
9811005
matchTest(#"e\O"#, input: eDecomposed, match: eDecomposed,
9821006
xfail: true)
983-
// TODO: Should these two match or not?
984-
matchTest(#"\O\u{301}"#, input: eComposed, match: eComposed,
1007+
matchTest(#"\O\u{301}"#, input: eComposed, match: nil,
9851008
xfail: true)
9861009
matchTest(#"e\O"#, input: eComposed, match: nil,
9871010
xfail: true)

0 commit comments

Comments
 (0)