Skip to content

Commit f111a57

Browse files
committed
Add some tests for CharacterClass.anyGraphemeCluster
1 parent 210bfa3 commit f111a57

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
@@ -259,6 +259,34 @@ class RegexDSLTests: XCTestCase {
259259
}.dotMatchesNewlines(dotMatchesNewline)
260260
}
261261
}
262+
263+
// `.anyGraphemeCluster` is the same as `.any` in grapheme mode.
264+
for mode in [RegexSemanticLevel.graphemeCluster, .unicodeScalar] {
265+
try _testDSLCaptures(
266+
("a", "a"),
267+
("\r\n", "\r\n"),
268+
("e\u{301}", "e\u{301}"),
269+
("e\u{301}f", nil),
270+
("e\u{303}\u{301}\u{302}", "e\u{303}\u{301}\u{302}"),
271+
matchType: Substring.self, ==)
272+
{
273+
Regex {
274+
One(.anyGraphemeCluster)
275+
}.matchingSemantics(mode)
276+
}
277+
278+
// Like `.any` it also always matches newlines.
279+
for dotMatchesNewline in [true, false] {
280+
try _testDSLCaptures(
281+
("abc\(allNewlines)def", "abc\(allNewlines)def"),
282+
matchType: Substring.self, ==)
283+
{
284+
Regex {
285+
OneOrMore(.anyGraphemeCluster)
286+
}.matchingSemantics(mode).dotMatchesNewlines(dotMatchesNewline)
287+
}
288+
}
289+
}
262290
}
263291

264292
func testMatchResultDotZeroWithoutCapture() throws {

0 commit comments

Comments
 (0)