diff --git a/Sources/CasePaths/CasePathable.swift b/Sources/CasePaths/CasePathable.swift index 5c1f17f..d51e624 100644 --- a/Sources/CasePaths/CasePathable.swift +++ b/Sources/CasePaths/CasePathable.swift @@ -410,10 +410,15 @@ extension CasePathable { /// userActions.filter { $0.is(\.home) } // [UserAction.home(.onAppear)] /// userActions.filter { $0.is(\.settings) } // [UserAction.settings(.subscribeButtonTapped)] /// ``` + @_disfavoredOverload public func `is`(_ keyPath: PartialCaseKeyPath) -> Bool { self[case: keyPath] != nil } + public func `is`(_ keyPath: CaseKeyPath) -> Bool { + self[case: keyPath] != nil + } + /// Unwraps and yields a mutable associated value to a closure. /// /// > Warning: If the enum's case does not match the given case key path, the mutation will not be diff --git a/Tests/CasePathsTests/CasePathsTests.swift b/Tests/CasePathsTests/CasePathsTests.swift index 3d6a381..74c5634 100644 --- a/Tests/CasePathsTests/CasePathsTests.swift +++ b/Tests/CasePathsTests/CasePathsTests.swift @@ -132,14 +132,14 @@ final class CasePathsTests: XCTestCase { func testMatch() { switch Foo.bar(.int(42)) { case \.bar.int: - return + break default: XCTFail() } switch Foo.bar(.int(42)) { case \.bar: - return + break default: XCTFail() } @@ -150,6 +150,10 @@ final class CasePathsTests: XCTestCase { XCTAssertFalse(Foo.bar(.int(42)).is(\.baz.string)) XCTAssertFalse(Foo.bar(.int(42)).is(\.blob)) XCTAssertFalse(Foo.bar(.int(42)).is(\.fizzBuzz)) + XCTAssertTrue(Foo.foo(nil).is(\.foo)) + XCTAssertTrue(Foo.foo(nil).is(\.foo.none)) + XCTAssertTrue(Foo.foo("").is(\.foo)) + XCTAssertFalse(Foo.foo(nil).is(\.bar)) } func testPartialCaseKeyPath() { @@ -169,6 +173,7 @@ final class CasePathsTests: XCTestCase { case baz(Baz) case fizzBuzz case blob(Blob) + case foo(String?) } @CasePathable @dynamicMemberLookup enum Bar: Equatable { case int(Int)