From 99002fa611209f2a2972ce6fb61ff4a4a073d19b Mon Sep 17 00:00:00 2001 From: Hamish Knight Date: Wed, 6 Jul 2022 13:40:14 +0100 Subject: [PATCH] Fix `_testDSLCaptures` Previously we would ignore the case where the match fails, but the test expects the match to succeed. --- Tests/RegexBuilderTests/RegexDSLTests.swift | 54 ++++++++++++--------- 1 file changed, 31 insertions(+), 23 deletions(-) diff --git a/Tests/RegexBuilderTests/RegexDSLTests.swift b/Tests/RegexBuilderTests/RegexDSLTests.swift index e3541345d..f7dcc5366 100644 --- a/Tests/RegexBuilderTests/RegexDSLTests.swift +++ b/Tests/RegexBuilderTests/RegexDSLTests.swift @@ -26,29 +26,35 @@ class RegexDSLTests: XCTestCase { let regex = content() for (input, maybeExpectedCaptures) in tests { let maybeMatch = input.wholeMatch(of: regex) - if let expectedCaptures = maybeExpectedCaptures, - let match = maybeMatch - { - if xfail { - XCTFail("Unexpectedly matched", file: file, line: line) - continue + guard let match = maybeMatch else { + if !xfail, maybeExpectedCaptures != nil { + XCTFail("Failed to match '\(input)'", file: file, line: line) } - XCTAssertTrue( - type(of: regex).RegexOutput.self == MatchType.self, - """ - Expected match type: \(MatchType.self) - Actual match type: \(type(of: regex).RegexOutput.self) - """) - let captures = try XCTUnwrap(match.output as? MatchType, file: file, line: line) - XCTAssertTrue( - equivalence(captures, expectedCaptures), - "'\(captures)' is not equal to the expected '\(expectedCaptures)'.", - file: file, line: line) - } else { + continue + } + guard let expectedCaptures = maybeExpectedCaptures else { if !xfail { - XCTAssertNil(maybeMatch, file: file, line: line) + XCTFail( + "Unexpectedly matched '\(match)' for '\(input)'", + file: file, line: line) } + continue + } + if xfail { + XCTFail("Unexpectedly matched", file: file, line: line) + continue } + XCTAssertTrue( + type(of: regex).RegexOutput.self == MatchType.self, + """ + Expected match type: \(MatchType.self) + Actual match type: \(type(of: regex).RegexOutput.self) + """) + let captures = try XCTUnwrap(match.output as? MatchType, file: file, line: line) + XCTAssertTrue( + equivalence(captures, expectedCaptures), + "'\(captures)' is not equal to the expected '\(expectedCaptures)'.", + file: file, line: line) } } @@ -270,10 +276,11 @@ class RegexDSLTests: XCTestCase { } .ignoresCase(false) } - + + // FIXME: Re-enable this test try _testDSLCaptures( ("can't stop won't stop", ("can't stop won't stop", "can't", "won't")), - matchType: (Substring, Substring, Substring).self, ==) { + matchType: (Substring, Substring, Substring).self, ==, xfail: true) { Capture { OneOrMore(.word) Anchor.wordBoundary @@ -289,10 +296,11 @@ class RegexDSLTests: XCTestCase { OneOrMore(.any, .reluctant) "stop" } - + + // FIXME: Re-enable this test try _testDSLCaptures( ("can't stop won't stop", ("can't stop won't stop", "can", "won")), - matchType: (Substring, Substring, Substring).self, ==) { + matchType: (Substring, Substring, Substring).self, ==, xfail: true) { Capture { OneOrMore(.word) Anchor.wordBoundary