From 00ac97ce415f78734feab315d0e5139a4e9e59e0 Mon Sep 17 00:00:00 2001 From: Stephen Canon Date: Wed, 29 Jun 2022 21:13:25 -0400 Subject: [PATCH 1/2] Retract ~= for Regex. We'd like to provide this, but we haven't been able to reach agreement on what the semantics actually ought to be. The original version used wholeMatch; contains is arguably more flexible, but feels less natural when compared to how ~= is used for other types in the language. Additionally, we'd like to investigate the possibility of using named captures to effect bindings in case statements in the future, and we don't want to wall ourselves off from that until we've had time to think about it some more. --- Sources/_StringProcessing/Regex/Match.swift | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/Sources/_StringProcessing/Regex/Match.swift b/Sources/_StringProcessing/Regex/Match.swift index 8020d2e9b..762f744a7 100644 --- a/Sources/_StringProcessing/Regex/Match.swift +++ b/Sources/_StringProcessing/Regex/Match.swift @@ -166,14 +166,3 @@ extension BidirectionalCollection where SubSequence == Substring { try? r.regex.prefixMatch(in: self[...]) } } - -@available(SwiftStdlib 5.7, *) -extension RegexComponent { - public static func ~=(regex: Self, input: String) -> Bool { - input.wholeMatch(of: regex) != nil - } - - public static func ~=(regex: Self, input: Substring) -> Bool { - input.wholeMatch(of: regex) != nil - } -} From acb5b240a4b67f1f5f6645d7727658ecffe3103a Mon Sep 17 00:00:00 2001 From: Stephen Canon Date: Wed, 29 Jun 2022 21:28:41 -0400 Subject: [PATCH 2/2] Forgot to remove ~= tests as well. --- Tests/RegexBuilderTests/AlgorithmsTests.swift | 60 ------------------- Tests/RegexTests/AlgorithmsTests.swift | 15 ----- 2 files changed, 75 deletions(-) diff --git a/Tests/RegexBuilderTests/AlgorithmsTests.swift b/Tests/RegexBuilderTests/AlgorithmsTests.swift index 173d41598..0a2e6bc21 100644 --- a/Tests/RegexBuilderTests/AlgorithmsTests.swift +++ b/Tests/RegexBuilderTests/AlgorithmsTests.swift @@ -104,66 +104,6 @@ class RegexConsumerTests: XCTestCase { result: "9+16, 3, 10, 99+1") ) } - - func testSwitches() { - // Failure cases - do { - switch "abcde" { - case Regex { - "a" - ZeroOrMore(.any) - "f" - }: - XCTFail() - - case OneOrMore { CharacterClass.whitespace }: - XCTFail() - - case "abc": - XCTFail() - - case Regex { - "a" - "b" - "c" - }: - XCTFail() - - default: - break - } - } - // Success cases - do { - let input = "abcde" - - switch input { - case Regex { - "a" - ZeroOrMore(.any) - "e" - }: - break - - default: - XCTFail() - } - - guard case Regex({ - "a" - ZeroOrMore(.any) - "e" - }) = input else { - XCTFail() - return - } - - guard case OneOrMore(.word) = input else { - XCTFail() - return - } - } - } } class AlgorithmsResultBuilderTests: XCTestCase { diff --git a/Tests/RegexTests/AlgorithmsTests.swift b/Tests/RegexTests/AlgorithmsTests.swift index 1a5bc34df..23c155f4b 100644 --- a/Tests/RegexTests/AlgorithmsTests.swift +++ b/Tests/RegexTests/AlgorithmsTests.swift @@ -497,19 +497,4 @@ class AlgorithmTests: XCTestCase { XCTAssertEqual( s2.ranges(of: try Regex("a*?")).map(s2.offsets(of:)), [0..<0, 1..<1, 2..<2]) } - - func testSwitches() { - switch "abcde" { - case try! Regex("a.*f"): - XCTFail() - case try! Regex("abc"): - XCTFail() - - case try! Regex("a.*e"): - break // success - - default: - XCTFail() - } - } }