Files
MonsterCards/iOS/Pods/OCHamcrest/Source/Library/Logical/HCAllOf.m
Tom Hicks c3031fbc39 Adds cocoapods for libraries.
Adds OCMockito and OCHamcrest libs.
2020-09-05 22:06:51 -07:00

61 lines
1.4 KiB
Objective-C

// OCHamcrest by Jon Reid, https://qualitycoding.org/
// Copyright 2019 hamcrest.org. See LICENSE.txt
#import "HCAllOf.h"
#import "HCCollect.h"
@interface HCAllOf ()
@property (nonatomic, copy, readonly) NSArray<id <HCMatcher>> *matchers;
@end
@implementation HCAllOf
- (instancetype)initWithMatchers:(NSArray<id <HCMatcher>> *)matchers
{
self = [super init];
if (self)
_matchers = [matchers copy];
return self;
}
- (BOOL)matches:(nullable id)item describingMismatchTo:(id <HCDescription>)mismatchDescription
{
for (id <HCMatcher> oneMatcher in self.matchers)
{
if (![oneMatcher matches:item])
{
[[[mismatchDescription appendText:@"instead of "]
appendDescriptionOf:oneMatcher]
appendText:@", "];
[oneMatcher describeMismatchOf:item to:mismatchDescription];
return NO;
}
}
return YES;
}
- (void)describeTo:(id <HCDescription>)description
{
[description appendList:self.matchers start:@"(" separator:@" and " end:@")"];
}
@end
id HC_allOfIn(NSArray *matchers)
{
return [[HCAllOf alloc] initWithMatchers:HCWrapIntoMatchers(matchers)];
}
id HC_allOf(id matchers, ...)
{
va_list args;
va_start(args, matchers);
NSArray *array = HCCollectItems(matchers, args);
va_end(args);
return HC_allOfIn(array);
}