Skip to content
Newer
Older
100644 80 lines (58 sloc) 1.54 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 "KWBeEmptyMatcher.h"
8 #import "KWFormatter.h"
9
10 @interface KWBeEmptyMatcher()
11
12 #pragma mark -
13 #pragma mark Properties
14
15 @property (nonatomic, readwrite) NSUInteger count;
16
17 @end
18
19 @implementation KWBeEmptyMatcher
20
21 #pragma mark -
22 #pragma mark Properties
23
24 @synthesize count;
25
26 #pragma mark -
27 #pragma mark Getting Matcher Strings
28
29 + (NSArray *)matcherStrings {
30 return [NSArray arrayWithObject:@"beEmpty"];
31 }
32
33 #pragma mark -
34 #pragma mark Matching
35
36 - (BOOL)evaluate {
37 if ([self.subject respondsToSelector:@selector(count)]) {
38 self.count = [self.subject count];
39 return self.count == 0;
40 }
41 else if ([self.subject respondsToSelector:@selector(length)]) {
42 self.count = [self.subject length];
43 return self.count == 0;
44 }
45
46 [NSException raise:@"KWMatcherException" format:@"subject does not respond to -count or -length"];
47 return NO;
48 }
49
50 #pragma mark -
51 #pragma mark Getting Failure Messages
52
53 - (NSString *)countPhrase {
54 if (self.count == 1)
55 return @"1 item";
56 else
12bb85f @shpakovski Adds compatibility with Xcode 4.4.
shpakovski authored
57 return [NSString stringWithFormat:@"%u items", (unsigned)self.count];
4f0c627 @allending First release.
authored
58 }
59
60 - (NSString *)failureMessageForShould {
61 return [NSString stringWithFormat:@"expected subject to be empty, got %@", [self countPhrase]];
62 }
63
64 - (NSString *)failureMessageForShouldNot {
65 return @"expected subject not to be empty";
66 }
67
24de39e @lukeredpath Add descriptions to matchers so we can generate nice names for anonym…
lukeredpath authored
68 - (NSString *)description
69 {
70 return @"be empty";
71 }
72
4f0c627 @allending First release.
authored
73 #pragma mark -
74 #pragma mark Configuring Matchers
75
76 - (void)beEmpty {
77 }
78
79 @end
Something went wrong with that request. Please try again.