-
Notifications
You must be signed in to change notification settings - Fork 36
/
Copy pathDictionaryMatchers.swift
30 lines (25 loc) · 1.2 KB
/
DictionaryMatchers.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
public func hasEntry<K, V>(_ keyMatcher: Matcher<K>, _ valueMatcher: Matcher<V>) -> Matcher<Dictionary<K, V>> {
return Matcher("a dictionary containing [\(keyMatcher.description) -> \(valueMatcher.description)]") { (dictionary: Dictionary<K, V>) -> Bool in
for (key, value) in dictionary {
if keyMatcher.matches(key).boolValue && valueMatcher.matches(value).boolValue {
return true
}
}
return false
}
}
public func hasEntry<K, V: Equatable>(_ expectedKey: K, _ expectedValue: V) -> Matcher<Dictionary<K, V>> {
return hasEntry(equalToWithoutDescription(expectedKey), equalToWithoutDescription(expectedValue))
}
public func hasKey<K, V>(_ matcher: Matcher<K>) -> Matcher<Dictionary<K, V>> {
return hasEntry(matcher, anything())
}
public func hasKey<K, V>(_ expectedKey: K) -> Matcher<Dictionary<K, V>> {
return hasKey(equalToWithoutDescription(expectedKey))
}
public func hasValue<K, V>(_ matcher: Matcher<V>) -> Matcher<Dictionary<K, V>> {
return hasEntry(anything(), matcher)
}
public func hasValue<K, V: Equatable>(_ expectedValue: V) -> Matcher<Dictionary<K, V>> {
return hasValue(equalToWithoutDescription(expectedValue))
}