From 1c306a8c60437a7d4ae34ae17170678a0da9fa97 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 | 44 ++++++++++++--------- 1 file changed, 25 insertions(+), 19 deletions(-) diff --git a/Tests/RegexBuilderTests/RegexDSLTests.swift b/Tests/RegexBuilderTests/RegexDSLTests.swift index 09f7999f9..e43cc350c 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) } }