OCHamcrest
|
Matchers of collections.
Defines | |
#define | hasCount HC_hasCount |
hasCount(aMatcher) - Matches if object's -count satisfies a given matcher. | |
#define | hasCountOf HC_hasCountOf |
hasCountOf(value) - Matches if object's -count equals a given value. | |
#define | hasItem HC_hasItem |
hasItem(aMatcher) - Matches if any element of collection satisfies a given matcher. | |
#define | hasItems HC_hasItems |
hasItems(firstMatcher, ...) - Matches if all of the given matchers are satisfied by any elements of the collection. | |
#define | containsInAnyOrder HC_containsInAnyOrder |
containsInAnyOrder(firstMatcher, ...) - Matches if collection's elements, in any order, satisfy a given list of matchers. | |
#define | contains HC_contains |
contains(firstMatcher, ...) - Matches if collection's elements satisfy a given list of matchers, in order. | |
#define | onlyContains HC_onlyContains |
onlyContains(firstMatcher, ...) - Matches if each element of collection satisfies any of the given matchers. | |
#define | hasEntry HC_hasEntry |
hasEntry(keyMatcher, valueMatcher) - Matches if dictionary contains key-value entry satisfying a given pair of matchers. | |
#define | hasEntries HC_hasEntries |
hasEntries(firstKey, valueMatcher, ...) - Matches if dictionary contains entries satisfying a list of alternating keys and their value matchers. | |
#define | hasKey HC_hasKey |
hasKey(keyMatcher) - Matches if dictionary contains an entry whose key satisfies a given matcher. | |
#define | hasValue HC_hasValue |
hasValue(valueMatcher) - Matches if dictionary contains an entry whose value satisfies a given matcher. | |
#define | isEmpty() HC_isEmpty() |
Matches empty collection. | |
#define | isIn HC_isIn |
isIn(aCollection) - Matches if evaluated object is present in a given collection. |
Matchers of collections.
#define contains HC_contains |
contains(firstMatcher, ...) - Matches if collection's elements satisfy a given list of matchers, in order.
firstMatcher,... | A comma-separated list of matchers ending with nil . |
This matcher iterates the evaluated collection and a given list of matchers, seeing if each element satisfies its corresponding matcher.
Any argument that is not a matcher is implicitly wrapped in an equalTo matcher to check for equality.
(In the event of a name clash, don't #define HC_SHORTHAND
and use the synonym HC_contains
instead.)
containsInAnyOrder(firstMatcher, ...) - Matches if collection's elements, in any order, satisfy a given list of matchers.
firstMatcher,... | A comma-separated list of matchers ending with nil . |
This matcher iterates the evaluated collection, seeing if each element satisfies any of the given matchers. The matchers are tried from left to right, and when a satisfied matcher is found, it is no longer a candidate for the remaining elements. If a one-to-one correspondence is established between elements and matchers, containsInAnyOrder
is satisfied.
Any argument that is not a matcher is implicitly wrapped in an equalTo matcher to check for equality.
(In the event of a name clash, don't #define HC_SHORTHAND
and use the synonym HC_containsInAnyOrder
instead.)
#define hasCount HC_hasCount |
hasCount(aMatcher) - Matches if object's -count
satisfies a given matcher.
aMatcher | The matcher to satisfy. |
This matcher invokes -count
on the evaluated object to get the number of elements it contains, passing the result to aMatcher for evaluation.
(In the event of a name clash, don't #define HC_SHORTHAND
and use the synonym HC_hasCount
instead.)
#define hasCountOf HC_hasCountOf |
hasCountOf(value) - Matches if object's -count
equals a given value.
value | NSUInteger value to compare against as the expected value. |
This matcher invokes -count
on the evaluated object to get the number of elements it contains, comparing the result to value for equality.
(In the event of a name clash, don't #define HC_SHORTHAND
and use the synonym HC_hasCountOf
instead.)
#define hasEntries HC_hasEntries |
hasEntries(firstKey, valueMatcher, ...) - Matches if dictionary contains entries satisfying a list of alternating keys and their value matchers.
firstKey | A key (not a matcher) to look up. |
valueMatcher,... | The matcher to satisfy for the value, or an expected value for equalTo matching. |
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. The list must end with nil
.
Examples:
(In the event of a name clash, don't #define HC_SHORTHAND
and use the synonym HC_hasEntry
instead.)
#define hasEntry HC_hasEntry |
hasEntry(keyMatcher, valueMatcher) - Matches if dictionary contains key-value entry satisfying a given pair of matchers.
keyMatcher | The matcher to satisfy for the key, or an expected value for equalTo matching. |
valueMatcher | The matcher to satisfy for the value, or an expected value for equalTo matching. |
This matcher iterates the evaluated dictionary, searching for any key-value entry that satisfies keyMatcher and valueMatcher. If a matching entry is found, hasEntry
is satisfied.
Any argument that is not a matcher is implicitly wrapped in an equalTo matcher to check for equality.
Examples:
(In the event of a name clash, don't #define HC_SHORTHAND
and use the synonym HC_hasEntry
instead.)
#define hasItem HC_hasItem |
hasItem(aMatcher) - Matches if any element of collection satisfies a given matcher.
aMatcher | The matcher to satisfy, or an expected value for equalTo matching. |
This matcher iterates the evaluated collection, searching for any element that satisfies a given matcher. If a matching element is found, hasItem
is satisfied.
If the aMatcher argument is not a matcher, it is implicitly wrapped in an equalTo matcher to check for equality.
(In the event of a name clash, don't #define HC_SHORTHAND
and use the synonym HC_hasItem
instead.)
#define hasItems HC_hasItems |
hasItems(firstMatcher, ...) - Matches if all of the given matchers are satisfied by any elements of the collection.
firstMatcher,... | A comma-separated list of matchers ending with nil . |
This matcher iterates the given matchers, searching for any elements in the evaluated collection that satisfy them. If each matcher is satisfied, then hasItems
is satisfied.
Any argument that is not a matcher is implicitly wrapped in an equalTo matcher to check for equality.
(In the event of a name clash, don't #define HC_SHORTHAND
and use the synonym hasItems
instead.)
hasKey(keyMatcher) - Matches if dictionary contains an entry whose key satisfies a given matcher.
keyMatcher | The matcher to satisfy for the key, or an expected value for equalTo matching. |
This matcher iterates the evaluated dictionary, searching for any key-value entry whose key satisfies the given matcher. If a matching entry is found, hasKey
is satisfied.
Any argument that is not a matcher is implicitly wrapped in an equalTo matcher to check for equality.
(In the event of a name clash, don't #define HC_SHORTHAND
and use the synonym HC_hasKey
instead.)
Examples:
#define hasValue HC_hasValue |
hasValue(valueMatcher) - Matches if dictionary contains an entry whose value satisfies a given matcher.
valueMatcher | The matcher to satisfy for the value, or an expected value for equalTo matching. |
This matcher iterates the evaluated dictionary, searching for any key-value entry whose value satisfies the given matcher. If a matching entry is found, hasValue
is satisfied.
Any argument that is not a matcher is implicitly wrapped in an equalTo matcher to check for equality.
Examples:
(In the event of a name clash, don't #define HC_SHORTHAND
and use the synonym HC_hasValue
instead.)
#define isEmpty | ( | ) | HC_isEmpty() |
Matches empty collection.
This matcher invokes -count
on the evaluated object to determine if the number of elements it contains is zero.
(In the event of a name clash, don't #define HC_SHORTHAND
and use the synonym HC_isEmpty
instead.)
isIn(aCollection) - Matches if evaluated object is present in a given collection.
aCollection | The collection to search. |
This matcher invokes -containsObject
: on aCollection to determine if the evaluated object is an element of the collection.
(In the event of a name clash, don't #define HC_SHORTHAND
and use the synonym HC_isIn
instead.)
#define onlyContains HC_onlyContains |
onlyContains(firstMatcher, ...) - Matches if each element of collection satisfies any of the given matchers.
firstMatcher,... | A comma-separated list of matchers ending with nil . |
This matcher iterates the evaluated collection, confirming whether each element satisfies any of the given matchers.
Any argument that is not a matcher is implicitly wrapped in an equalTo matcher to check for equality.
Example:
will match a collection ["Jon", @"John", @"Johann"].
(In the event of a name clash, don't #define HC_SHORTHAND
and use the synonym HC_onlyContains
instead.)