Make `Defaults.AnyKey` conform to `Equatable` and `Hashable` (#104)
This commit is contained in:
parent
d1e2109fc9
commit
001adc694b
|
@ -90,3 +90,17 @@ extension Defaults.Key {
|
||||||
self.init(key, default: nil, suite: suite)
|
self.init(key, default: nil, suite: suite)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
extension Defaults.AnyKey: Equatable {
|
||||||
|
public static func == (lhs: Defaults.AnyKey, rhs: Defaults.AnyKey) -> Bool {
|
||||||
|
lhs.name == rhs.name
|
||||||
|
&& lhs.suite == rhs.suite
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
extension Defaults.AnyKey: Hashable {
|
||||||
|
public func hash(into hasher: inout Hasher) {
|
||||||
|
hasher.combine(name)
|
||||||
|
hasher.combine(suite)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -639,4 +639,12 @@ final class DefaultsTests: XCTestCase {
|
||||||
cancellable.cancel()
|
cancellable.cancel()
|
||||||
waitForExpectations(timeout: 10)
|
waitForExpectations(timeout: 10)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func testKeyEquatable() {
|
||||||
|
XCTAssertEqual(Defaults.Key<Bool>("equatableKeyTest", default: false), Defaults.Key<Bool>("equatableKeyTest", default: false))
|
||||||
|
}
|
||||||
|
|
||||||
|
func testKeyHashable() {
|
||||||
|
_ = Set([Defaults.Key<Bool>("hashableKeyTest", default: false)])
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue