// OCHamcrest by Jon Reid, https://qualitycoding.org/ // Copyright 2019 hamcrest.org. See LICENSE.txt #import NS_ASSUME_NONNULL_BEGIN /*! * @abstract Matches if dictionary contains entries that satisfy the list of keys and value * matchers. */ @interface HCIsDictionaryContainingEntries : HCDiagnosingMatcher - (instancetype)initWithKeys:(NSArray *)keys valueMatchers:(NSArray> *)valueMatchers NS_DESIGNATED_INITIALIZER; - (instancetype)init NS_UNAVAILABLE; @end FOUNDATION_EXPORT id HC_hasEntriesIn(NSDictionary *valueMatchersForKeys); #ifndef HC_DISABLE_SHORT_SYNTAX /*! * @abstract Creates a matcher for NSDictionaries that matches when the examined dictionary contains * entries satisfying a dictionary of keys and their value matchers. * @param valueMatchersForKeys A dictionary of keys (not matchers) and their value matchers. Any * value argument that is not a matcher is implicitly wrapped in an equalTo matcher to * check for equality. * @discussion * Examples
*
assertThat(personDict, hasEntriesIn(\@{\@"firstName": equalTo(\@"Jon"), \@"lastName": equalTo(\@"Reid")}))
*
assertThat(personDict, hasEntriesIn(\@{\@"firstName": \@"Jon", \@"lastName": \@"Reid"}))
* * Name Clash
* In the event of a name clash, #define HC_DISABLE_SHORT_SYNTAX and use the synonym * HC_hasEntryIn instead. */ static inline id hasEntriesIn(NSDictionary *valueMatchersForKeys) { return HC_hasEntriesIn(valueMatchersForKeys); } #endif FOUNDATION_EXPORT id HC_hasEntries(id keysAndValueMatchers, ...) NS_REQUIRES_NIL_TERMINATION; #ifndef HC_DISABLE_SHORT_SYNTAX /*! * @abstract Creates a matcher for NSDictionaries that matches when the examined dictionary contains * entries satisfying a list of alternating keys and their value matchers. * @param keysAndValueMatchers... A key (not a matcher) to look up, followed by a value matcher or * an expected value for equalTo matching, in a comma-separated list ending * with nil * @discussion Note that the keys must be actual keys, not matchers. Any value argument that is not * a matcher is implicitly wrapped in an equalTo matcher to check for equality. * * Examples
*
assertThat(personDict, hasEntries(\@"firstName", equalTo(\@"Jon"), \@"lastName", equalTo(\@"Reid"), nil))
*
assertThat(personDict, hasEntries(\@"firstName", \@"Jon", \@"lastName", \@"Reid", nil))
* * Name Clash
* In the event of a name clash, #define HC_DISABLE_SHORT_SYNTAX and use the synonym * HC_hasEntry instead. */ #define hasEntries(keysAndValueMatchers...) HC_hasEntries(keysAndValueMatchers) #endif NS_ASSUME_NONNULL_END