From 17d8362493fb40643df04ec68ca64257ba091b0c Mon Sep 17 00:00:00 2001 From: Richard Wei Date: Tue, 7 Jun 2022 13:20:58 -0700 Subject: [PATCH] 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`. --- Tests/RegexBuilderTests/RegexDSLTests.swift | 23 +++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/Tests/RegexBuilderTests/RegexDSLTests.swift b/Tests/RegexBuilderTests/RegexDSLTests.swift index 5a88adf6b..041556eec 100644 --- a/Tests/RegexBuilderTests/RegexDSLTests.swift +++ b/Tests/RegexBuilderTests/RegexDSLTests.swift @@ -525,6 +525,29 @@ class RegexDSLTests: XCTestCase { */ } + func testCaptureTransform() throws { + try _testDSLCaptures( + ("aaaa1", ("aaaa1", "aaa")), + matchType: (Substring, Substring).self, ==) + { + Capture { + OneOrMore("a") + } transform: { + $0.dropFirst() + } + One(.digit) + } + try _testDSLCaptures( + ("aaaa1", ("aaaa1", "a")), + matchType: (Substring, Substring??).self, ==) + { + ZeroOrMore { + Capture("a", transform: { Optional.some($0) }) + } + One(.digit) + } + } + func testCapturelessQuantification() throws { // This test is to make sure that a captureless quantification, when used // straight out of the quantifier (without being wrapped in a builder), is