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

59 lines
2.1 KiB
Objective-C

// OCHamcrest by Jon Reid, https://qualitycoding.org/
// Copyright 2019 hamcrest.org. See LICENSE.txt
#import "HCAssertThat.h"
#import "HCRunloopRunner.h"
#import "HCStringDescription.h"
#import "HCMatcher.h"
#import "HCTestFailure.h"
#import "HCTestFailureReporter.h"
#import "HCTestFailureReporterChain.h"
static void reportMismatch(id testCase, id actual, id <HCMatcher> matcher,
char const *fileName, int lineNumber)
{
HCTestFailure *failure = [[HCTestFailure alloc] initWithTestCase:testCase
fileName:[NSString stringWithUTF8String:fileName]
lineNumber:(NSUInteger)lineNumber
reason:HCDescribeMismatch(matcher, actual)];
HCTestFailureReporter *chain = [HCTestFailureReporterChain reporterChain];
[chain handleFailure:failure];
}
void HC_assertThatWithLocation(id testCase, _Nullable id actual, id <HCMatcher> matcher,
const char *fileName, int lineNumber)
{
if (![matcher matches:actual])
reportMismatch(testCase, actual, matcher, fileName, lineNumber);
}
void HC_assertWithTimeoutAndLocation(id testCase, NSTimeInterval timeout,
HCFutureValue actualBlock, id <HCMatcher> matcher,
const char *fileName, int lineNumber)
{
__block BOOL match = [matcher matches:actualBlock()];
if (!match)
{
HCRunloopRunner *runner = [[HCRunloopRunner alloc] initWithFulfillmentBlock:^{
match = [matcher matches:actualBlock()];
return match;
}];
[runner runUntilFulfilledOrTimeout:timeout];
}
if (!match)
reportMismatch(testCase, actualBlock(), matcher, fileName, lineNumber);
}
NSString *HCDescribeMismatch(id <HCMatcher> matcher, id actual)
{
HCStringDescription *description = [HCStringDescription stringDescription];
[[[description appendText:@"Expected "]
appendDescriptionOf:matcher]
appendText:@", but "];
[matcher describeMismatchOf:actual to:description];
return description.description;
}