Skip to content

Commit 17d8362

Browse files
committed
Add additional capture transform tests.
- Add a test where the capture transform produecs a `Substring` from a `Substring`. - Add a test where the capture transform wraps a `Substring` in an `Optional`.
1 parent a7001b1 commit 17d8362

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

Tests/RegexBuilderTests/RegexDSLTests.swift

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -525,6 +525,29 @@ class RegexDSLTests: XCTestCase {
525525
*/
526526
}
527527

528+
func testCaptureTransform() throws {
529+
try _testDSLCaptures(
530+
("aaaa1", ("aaaa1", "aaa")),
531+
matchType: (Substring, Substring).self, ==)
532+
{
533+
Capture {
534+
OneOrMore("a")
535+
} transform: {
536+
$0.dropFirst()
537+
}
538+
One(.digit)
539+
}
540+
try _testDSLCaptures(
541+
("aaaa1", ("aaaa1", "a")),
542+
matchType: (Substring, Substring??).self, ==)
543+
{
544+
ZeroOrMore {
545+
Capture("a", transform: { Optional.some($0) })
546+
}
547+
One(.digit)
548+
}
549+
}
550+
528551
func testCapturelessQuantification() throws {
529552
// This test is to make sure that a captureless quantification, when used
530553
// straight out of the quantifier (without being wrapped in a builder), is

0 commit comments

Comments
 (0)