Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 80 lines (58 sloc) 1.838 kB
4f0c627 @allending First release.
authored
1 //
2 // Licensed under the terms in License.txt
3 //
4 // Copyright 2010 Allen Ding. All rights reserved.
5 //
6
7 #import "KWEqualMatcher.h"
8 #import "KWFormatter.h"
e443475 @lukeredpath Make it easier to compare Kiwi-boxed values with numbers.
lukeredpath authored
9 #import "KWValue.h"
4f0c627 @allending First release.
authored
10
11 @interface KWEqualMatcher()
12
13 #pragma mark -
14 #pragma mark Properties
15
16 @property (nonatomic, readwrite, retain) id otherSubject;
17
18 @end
19
20 @implementation KWEqualMatcher
21
22 #pragma mark -
23 #pragma mark Initializing
24
25 - (void)dealloc {
26 [otherSubject release];
27 [super dealloc];
28 }
29
30 #pragma mark -
31 #pragma mark Properties
32
33 @synthesize otherSubject;
34
35 #pragma mark -
36 #pragma mark Getting Matcher Strings
37
38 + (NSArray *)matcherStrings {
39 return [NSArray arrayWithObjects:@"equal:", nil];
40 }
41
42 #pragma mark -
43 #pragma mark Matching
44
45 - (BOOL)evaluate {
e443475 @lukeredpath Make it easier to compare Kiwi-boxed values with numbers.
lukeredpath authored
46 /** handle this as a special case; KWValue supports NSNumber equality but not vice-versa **/
47 if ([self.subject isKindOfClass:[NSNumber class]] && [self.otherSubject isKindOfClass:[KWValue class]]) {
48 return [self.otherSubject isEqual:self.subject];
49 }
4f0c627 @allending First release.
authored
50 return [self.subject isEqual:self.otherSubject];
51 }
52
53 #pragma mark -
54 #pragma mark Getting Failure Messages
55
56 - (NSString *)failureMessageForShould {
57 return [NSString stringWithFormat:@"expected subject to equal %@, got %@",
58 [KWFormatter formatObject:self.otherSubject],
59 [KWFormatter formatObject:self.subject]];
60 }
61
62 - (NSString *)failureMessageForShouldNot {
63 return [NSString stringWithFormat:@"expected subject not to equal %@",
64 [KWFormatter formatObject:self.otherSubject]];
65 }
66
24de39e @lukeredpath Add descriptions to matchers so we can generate nice names for anonym…
lukeredpath authored
67 - (NSString *)description
68 {
69 return [NSString stringWithFormat:@"equal %@", [KWFormatter formatObject:self.otherSubject]];
70 }
71
4f0c627 @allending First release.
authored
72 #pragma mark -
73 #pragma mark Configuring Matchers
74
75 - (void)equal:(id)anObject {
76 self.otherSubject = anObject;
77 }
78
79 @end
Something went wrong with that request. Please try again.