Permalink
Browse files

fix bug when first Hamcrest argument match caused invocation match

add ability to use numeric Hamcrest matchers, e.g. closeTo(value,delta)
  • Loading branch information...
1 parent 4d9d974 commit 9215fd3e8d3f3389d9c32870e59f3ad5db1eaacb @paulz paulz committed with Paul Zabelin Mar 11, 2012
Showing with 15 additions and 18 deletions.
  1. +15 −18 Kiwi/KWMessagePattern.m
View
33 Kiwi/KWMessagePattern.m
@@ -135,28 +135,25 @@ - (BOOL)argumentFiltersMatchInvocationArguments:(NSInvocation *)anInvocation {
continue;
}
- if (KWObjCTypeIsObject(objCType)) {
- if ([argumentFilter isEqual:[KWNull null]]) {
- if (object != nil)
+ if ([argumentFilter conformsToProtocol:@protocol(HCMatcher)]) {
+ id<HCMatcher> matcher = (id<HCMatcher>)argumentFilter;
+ if ([object isKindOfClass:[KWValue class]] && [object isNumeric]) {
+ NSNumber *number = [object numberValue];
+ if (![matcher matches:number]) {
return NO;
- } else if ([argumentFilter respondsToSelector:@selector(matches:)]) {
- return [(id<HCMatcher>)argumentFilter matches:object];
- } else if (![argumentFilter isEqual:object]) {
+ }
+ } else if (![matcher matches:object]) {
return NO;
}
- } else {
- if ([argumentFilter isEqual:[KWNull null]]) {
- if (!KWObjCTypeIsPointerLike(objCType))
- [NSException raise:@"KWMessagePatternException" format:@"nil was specified as an argument filter, but argument is not a pointer"];
-
- void *p = nil;
- [anInvocation getMessageArgument:&p atIndex:i];
-
- if (p != nil)
- return NO;
- } else if (![argumentFilter isEqual:object]) {
+ } else if ([argumentFilter isEqual:[KWNull null]]) {
+ if (!KWObjCTypeIsPointerLike(objCType))
+ [NSException raise:@"KWMessagePatternException" format:@"nil was specified as an argument filter, but argument is not a pointer"];
+ void *p = nil;
+ [anInvocation getMessageArgument:&p atIndex:i];
+ if (p != nil)
return NO;
- }
+ } else if (![argumentFilter isEqual:object]) {
+ return NO;
}
}

0 comments on commit 9215fd3

Please sign in to comment.