Skip to content

Commit f1026b3

Browse files
committed
Add some tests for CharacterClass.anyGraphemeCluster
1 parent 540ab8c commit f1026b3

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

Tests/RegexBuilderTests/RegexDSLTests.swift

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,34 @@ class RegexDSLTests: XCTestCase {
255255
}.dotMatchesNewlines(dotMatchesNewline)
256256
}
257257
}
258+
259+
// `.anyGraphemeCluster` is the same as `.any` in grapheme mode.
260+
for mode in [RegexSemanticLevel.graphemeCluster, .unicodeScalar] {
261+
try _testDSLCaptures(
262+
("a", "a"),
263+
("\r\n", "\r\n"),
264+
("e\u{301}", "e\u{301}"),
265+
("e\u{301}f", nil),
266+
("e\u{303}\u{301}\u{302}", "e\u{303}\u{301}\u{302}"),
267+
matchType: Substring.self, ==)
268+
{
269+
Regex {
270+
One(.anyGraphemeCluster)
271+
}.matchingSemantics(mode)
272+
}
273+
274+
// Like `.any` it also always matches newlines.
275+
for dotMatchesNewline in [true, false] {
276+
try _testDSLCaptures(
277+
("abc\(allNewlines)def", "abc\(allNewlines)def"),
278+
matchType: Substring.self, ==)
279+
{
280+
Regex {
281+
OneOrMore(.anyGraphemeCluster)
282+
}.matchingSemantics(mode).dotMatchesNewlines(dotMatchesNewline)
283+
}
284+
}
285+
}
258286
}
259287

260288
func testMatchResultDotZeroWithoutCapture() throws {

0 commit comments

Comments
 (0)