// OCHamcrest by Jon Reid, https://qualitycoding.org/ // Copyright 2019 hamcrest.org. See LICENSE.txt #import "HCIsDictionaryContaining.h" #import "HCRequireNonNilObject.h" #import "HCWrapInMatcher.h" @interface HCIsDictionaryContaining () @property (nonatomic, strong, readonly) id keyMatcher; @property (nonatomic, strong, readonly) id valueMatcher; @end @implementation HCIsDictionaryContaining - (instancetype)initWithKeyMatcher:(id )keyMatcher valueMatcher:(id )valueMatcher { self = [super init]; if (self) { _keyMatcher = keyMatcher; _valueMatcher = valueMatcher; } return self; } - (BOOL)matches:(id)dict { if ([dict isKindOfClass:[NSDictionary class]]) for (id oneKey in dict) if ([self.keyMatcher matches:oneKey] && [self.valueMatcher matches:dict[oneKey]]) return YES; return NO; } - (void)describeTo:(id )description { [[[[[description appendText:@"a dictionary containing { "] appendDescriptionOf:self.keyMatcher] appendText:@" = "] appendDescriptionOf:self.valueMatcher] appendText:@"; }"]; } @end id HC_hasEntry(id keyMatcher, id valueMatcher) { HCRequireNonNilObject(keyMatcher); HCRequireNonNilObject(valueMatcher); return [[HCIsDictionaryContaining alloc] initWithKeyMatcher:HCWrapInMatcher(keyMatcher) valueMatcher:HCWrapInMatcher(valueMatcher)]; }