This repository has been archived by the owner on Jan 19, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
CRLTestUtils.m
51 lines (39 loc) · 1.63 KB
/
CRLTestUtils.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
//
// CRLTestUtils.m
// Sidecar
//
// Created by Timothy Clem on 8/23/15.
// Copyright © 2015 Crush & Lovely. All rights reserved.
//
#import "CRLTestUtils.h"
EXPMatcherImplementationBegin(haveElementsEqualTo, (NSArray *expected)) {
NSArray *actualArray = (NSArray *)actual;
__block NSUInteger indexOfMismatch;
__block id expectedElement, actualElement;
prerequisite(^BOOL {
return expected && [actual isKindOfClass:[NSArray class]];
});
match(^BOOL {
if(actualArray.count != expected.count) return NO;
for(NSUInteger i = 0; i < actualArray.count; i++) {
if(![actualArray[i] isEqual:expected[i]]) {
indexOfMismatch = i;
expectedElement = expected[i];
actualElement = actualArray[i];
return NO;
}
}
return YES;
});
failureMessageForTo(^NSString * {
if(!expected) return @"the expected value is nil/null";
if(!actual)
return @"the actual value is nil/null";
if(![actual isKindOfClass:[NSArray class]])
return [NSString stringWithFormat:@"the actual value is an instance of %@, which is not an NSArray", [actual class]];
if(actualArray.count != expected.count)
return [NSString stringWithFormat:@"expected: an array of count %lu, got: an array of count %lu", (unsigned long)expected.count, (unsigned long)actualArray.count];
return [NSString stringWithFormat:@"expected: element at index %lu to equal %@, got: %@", (unsigned long)indexOfMismatch, expectedElement, actualElement];
});
}
EXPMatcherImplementationEnd