main
 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"
 9#import "KWValue.h"
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 @[@"equal:"];
40}
41
42#pragma mark -
43#pragma mark Matching
44
45- (BOOL)evaluate {
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    }
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
67- (NSString *)description
68{
69  return [NSString stringWithFormat:@"equal %@", [KWFormatter formatObject:self.otherSubject]];
70}
71
72#pragma mark -
73#pragma mark Configuring Matchers
74
75- (void)equal:(id)anObject {
76    self.otherSubject = anObject;
77}
78
79@end