forked from kiwi-bdd/Kiwi
/
KWEqualMatcher.m
79 lines (58 loc) · 1.79 KB
/
KWEqualMatcher.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
//
// Licensed under the terms in License.txt
//
// Copyright 2010 Allen Ding. All rights reserved.
//
#import "KWEqualMatcher.h"
#import "KWFormatter.h"
#import "KWValue.h"
@interface KWEqualMatcher()
#pragma mark -
#pragma mark Properties
@property (nonatomic, readwrite, retain) id otherSubject;
@end
@implementation KWEqualMatcher
#pragma mark -
#pragma mark Initializing
- (void)dealloc {
[otherSubject release];
[super dealloc];
}
#pragma mark -
#pragma mark Properties
@synthesize otherSubject;
#pragma mark -
#pragma mark Getting Matcher Strings
+ (NSArray *)matcherStrings {
return [NSArray arrayWithObjects:@"equal:", nil];
}
#pragma mark -
#pragma mark Matching
- (BOOL)evaluate {
/** handle this as a special case; KWValue supports NSNumber equality but not vice-versa **/
if ([self.subject isKindOfClass:[NSNumber class]] && [self.otherSubject isKindOfClass:[KWValue class]]) {
return [self.otherSubject isEqual:self.subject];
}
return [self.subject isEqual:self.otherSubject];
}
#pragma mark -
#pragma mark Getting Failure Messages
- (NSString *)failureMessageForShould {
return [NSString stringWithFormat:@"expected subject to equal %@, got %@",
[KWFormatter formatObject:self.otherSubject],
[KWFormatter formatObject:self.subject]];
}
- (NSString *)failureMessageForShouldNot {
return [NSString stringWithFormat:@"expected subject not to equal %@",
[KWFormatter formatObject:self.otherSubject]];
}
- (NSString *)description
{
return [NSString stringWithFormat:@"equal %@", [KWFormatter formatObject:self.otherSubject]];
}
#pragma mark -
#pragma mark Configuring Matchers
- (void)equal:(id)anObject {
self.otherSubject = anObject;
}
@end