- Update
This commit is contained in:
1 parent
d281d765ea
commit
5b074a5176
1261 files changed
+199158
-7303
No files matched your search
+63
@@ -0,0 +1,63 @@
|
||||
//
|
||||
// OCHamcrest - HCHasCount.h
|
||||
// Copyright 2012 hamcrest.org. See LICENSE.txt
|
||||
//
|
||||
// Created by: Jon Reid, http://qualitycoding.org/
|
||||
// Docs: http://hamcrest.github.com/OCHamcrest/
|
||||
// Source: https://github.com/hamcrest/OCHamcrest
|
||||
//
|
||||
|
||||
#import <OCHamcrest/HCBaseMatcher.h>
|
||||
|
||||
|
||||
@interface HCHasCount : HCBaseMatcher
|
||||
{
|
||||
id<HCMatcher> countMatcher;
|
||||
}
|
||||
|
||||
+ (id)hasCount:(id<HCMatcher>)matcher;
|
||||
- (id)initWithCount:(id<HCMatcher>)matcher;
|
||||
|
||||
@end
|
||||
|
||||
|
||||
OBJC_EXPORT id<HCMatcher> HC_hasCount(id<HCMatcher> matcher);
|
||||
|
||||
/**
|
||||
hasCount(aMatcher) -
|
||||
Matches if object's @c -count satisfies a given matcher.
|
||||
|
||||
@param aMatcher The matcher to satisfy.
|
||||
|
||||
This matcher invokes @c -count on the evaluated object to get the number of elements it
|
||||
contains, passing the result to @a aMatcher for evaluation.
|
||||
|
||||
(In the event of a name clash, don't \#define @c HC_SHORTHAND and use the synonym
|
||||
@c HC_hasCount instead.)
|
||||
|
||||
@ingroup collection_matchers
|
||||
*/
|
||||
#ifdef HC_SHORTHAND
|
||||
#define hasCount HC_hasCount
|
||||
#endif
|
||||
|
||||
|
||||
OBJC_EXPORT id<HCMatcher> HC_hasCountOf(NSUInteger count);
|
||||
|
||||
/**
|
||||
hasCountOf(value) -
|
||||
Matches if object's @c -count equals a given value.
|
||||
|
||||
@param value @c NSUInteger value to compare against as the expected value.
|
||||
|
||||
This matcher invokes @c -count on the evaluated object to get the number of elements it
|
||||
contains, comparing the result to @a value for equality.
|
||||
|
||||
(In the event of a name clash, don't \#define @c HC_SHORTHAND and use the synonym
|
||||
@c HC_hasCountOf instead.)
|
||||
|
||||
@ingroup collection_matchers
|
||||
*/
|
||||
#ifdef HC_SHORTHAND
|
||||
#define hasCountOf HC_hasCountOf
|
||||
#endif
|
||||
+70
@@ -0,0 +1,70 @@
|
||||
//
|
||||
// OCHamcrest - HCHasCount.m
|
||||
// Copyright 2012 hamcrest.org. See LICENSE.txt
|
||||
//
|
||||
// Created by: Jon Reid, http://qualitycoding.org/
|
||||
// Docs: http://hamcrest.github.com/OCHamcrest/
|
||||
// Source: https://github.com/hamcrest/OCHamcrest
|
||||
//
|
||||
|
||||
#import "HCHasCount.h"
|
||||
|
||||
#import "HCDescription.h"
|
||||
#import "HCIsEqualToNumber.h"
|
||||
|
||||
|
||||
@implementation HCHasCount
|
||||
|
||||
+ (id)hasCount:(id<HCMatcher>)matcher
|
||||
{
|
||||
return [[self alloc] initWithCount:matcher];
|
||||
}
|
||||
|
||||
- (id)initWithCount:(id<HCMatcher>)matcher
|
||||
{
|
||||
self = [super init];
|
||||
if (self)
|
||||
countMatcher = matcher;
|
||||
return self;
|
||||
}
|
||||
|
||||
- (BOOL)matches:(id)item
|
||||
{
|
||||
if (![item respondsToSelector:@selector(count)])
|
||||
return NO;
|
||||
|
||||
NSNumber *count = @([item count]);
|
||||
return [countMatcher matches:count];
|
||||
}
|
||||
|
||||
- (void)describeMismatchOf:(id)item to:(id<HCDescription>)mismatchDescription
|
||||
{
|
||||
[mismatchDescription appendText:@"was "];
|
||||
if ([item respondsToSelector:@selector(count)])
|
||||
{
|
||||
[[[mismatchDescription appendText:@"count of "]
|
||||
appendDescriptionOf:@([item count])]
|
||||
appendText:@" with "];
|
||||
}
|
||||
[mismatchDescription appendDescriptionOf:item];
|
||||
}
|
||||
|
||||
- (void)describeTo:(id<HCDescription>)description
|
||||
{
|
||||
[[description appendText:@"a collection with count of "] appendDescriptionOf:countMatcher];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
|
||||
#pragma mark -
|
||||
|
||||
id<HCMatcher> HC_hasCount(id<HCMatcher> matcher)
|
||||
{
|
||||
return [HCHasCount hasCount:matcher];
|
||||
}
|
||||
|
||||
id<HCMatcher> HC_hasCountOf(NSUInteger value)
|
||||
{
|
||||
return HC_hasCount(HC_equalToUnsignedInteger(value));
|
||||
}
|
||||
Vendored
+69
@@ -0,0 +1,69 @@
|
||||
//
|
||||
// OCHamcrest - HCIsCollectionContaining.h
|
||||
// Copyright 2012 hamcrest.org. See LICENSE.txt
|
||||
//
|
||||
// Created by: Jon Reid, http://qualitycoding.org/
|
||||
// Docs: http://hamcrest.github.com/OCHamcrest/
|
||||
// Source: https://github.com/hamcrest/OCHamcrest
|
||||
//
|
||||
|
||||
#import <OCHamcrest/HCBaseMatcher.h>
|
||||
|
||||
|
||||
@interface HCIsCollectionContaining : HCBaseMatcher
|
||||
{
|
||||
id<HCMatcher> elementMatcher;
|
||||
}
|
||||
|
||||
+ (id)isCollectionContaining:(id<HCMatcher>)anElementMatcher;
|
||||
- (id)initWithMatcher:(id<HCMatcher>)anElementMatcher;
|
||||
|
||||
@end
|
||||
|
||||
|
||||
OBJC_EXPORT id<HCMatcher> HC_hasItem(id itemMatch);
|
||||
|
||||
/**
|
||||
hasItem(aMatcher) -
|
||||
Matches if any element of collection satisfies a given matcher.
|
||||
|
||||
@param aMatcher The matcher to satisfy, or an expected value for @ref equalTo matching.
|
||||
|
||||
This matcher iterates the evaluated collection, searching for any element that satisfies a
|
||||
given matcher. If a matching element is found, @c hasItem is satisfied.
|
||||
|
||||
If the @a aMatcher argument is not a matcher, it is implicitly wrapped in an @ref equalTo
|
||||
matcher to check for equality.
|
||||
|
||||
(In the event of a name clash, don't \#define @c HC_SHORTHAND and use the synonym
|
||||
@c HC_hasItem instead.)
|
||||
|
||||
@ingroup collection_matchers
|
||||
*/
|
||||
#ifdef HC_SHORTHAND
|
||||
#define hasItem HC_hasItem
|
||||
#endif
|
||||
|
||||
|
||||
OBJC_EXPORT id<HCMatcher> HC_hasItems(id itemMatch, ...) NS_REQUIRES_NIL_TERMINATION;
|
||||
|
||||
/**
|
||||
hasItems(firstMatcher, ...) -
|
||||
Matches if all of the given matchers are satisfied by any elements of the collection.
|
||||
|
||||
@param firstMatcher,... A comma-separated list of matchers ending with @c nil.
|
||||
|
||||
This matcher iterates the given matchers, searching for any elements in the evaluated collection
|
||||
that satisfy them. If each matcher is satisfied, then @c hasItems is satisfied.
|
||||
|
||||
Any argument that is not a matcher is implicitly wrapped in an @ref equalTo matcher to check for
|
||||
equality.
|
||||
|
||||
(In the event of a name clash, don't \#define @c HC_SHORTHAND and use the synonym
|
||||
@c hasItems instead.)
|
||||
|
||||
@ingroup collection_matchers
|
||||
*/
|
||||
#ifdef HC_SHORTHAND
|
||||
#define hasItems HC_hasItems
|
||||
#endif
|
||||
Vendored
+76
@@ -0,0 +1,76 @@
|
||||
//
|
||||
// OCHamcrest - HCIsCollectionContaining.m
|
||||
// Copyright 2012 hamcrest.org. See LICENSE.txt
|
||||
//
|
||||
// Created by: Jon Reid, http://qualitycoding.org/
|
||||
// Docs: http://hamcrest.github.com/OCHamcrest/
|
||||
// Source: https://github.com/hamcrest/OCHamcrest
|
||||
//
|
||||
|
||||
#import "HCIsCollectionContaining.h"
|
||||
|
||||
#import "HCAllOf.h"
|
||||
#import "HCDescription.h"
|
||||
#import "HCRequireNonNilObject.h"
|
||||
#import "HCWrapInMatcher.h"
|
||||
|
||||
|
||||
@implementation HCIsCollectionContaining
|
||||
|
||||
+ (id)isCollectionContaining:(id<HCMatcher>)anElementMatcher
|
||||
{
|
||||
return [[self alloc] initWithMatcher:anElementMatcher];
|
||||
}
|
||||
|
||||
- (id)initWithMatcher:(id<HCMatcher>)anElementMatcher
|
||||
{
|
||||
self = [super init];
|
||||
if (self)
|
||||
elementMatcher = anElementMatcher;
|
||||
return self;
|
||||
}
|
||||
|
||||
- (BOOL)matches:(id)collection
|
||||
{
|
||||
if (![collection conformsToProtocol:@protocol(NSFastEnumeration)])
|
||||
return NO;
|
||||
|
||||
for (id item in collection)
|
||||
if ([elementMatcher matches:item])
|
||||
return YES;
|
||||
return NO;
|
||||
}
|
||||
|
||||
- (void)describeTo:(id<HCDescription>)description
|
||||
{
|
||||
[[description appendText:@"a collection containing "]
|
||||
appendDescriptionOf:elementMatcher];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
|
||||
#pragma mark -
|
||||
|
||||
id<HCMatcher> HC_hasItem(id itemMatch)
|
||||
{
|
||||
HCRequireNonNilObject(itemMatch);
|
||||
return [HCIsCollectionContaining isCollectionContaining:HCWrapInMatcher(itemMatch)];
|
||||
}
|
||||
|
||||
id<HCMatcher> HC_hasItems(id itemMatch, ...)
|
||||
{
|
||||
NSMutableArray *matchers = [NSMutableArray arrayWithObject:HC_hasItem(itemMatch)];
|
||||
|
||||
va_list args;
|
||||
va_start(args, itemMatch);
|
||||
itemMatch = va_arg(args, id);
|
||||
while (itemMatch != nil)
|
||||
{
|
||||
[matchers addObject:HC_hasItem(itemMatch)];
|
||||
itemMatch = va_arg(args, id);
|
||||
}
|
||||
va_end(args);
|
||||
|
||||
return [HCAllOf allOf:matchers];
|
||||
}
|
||||
+47
@@ -0,0 +1,47 @@
|
||||
//
|
||||
// OCHamcrest - HCIsCollectionContainingInAnyOrder.h
|
||||
// Copyright 2012 hamcrest.org. See LICENSE.txt
|
||||
//
|
||||
// Created by: Jon Reid, http://qualitycoding.org/
|
||||
// Docs: http://hamcrest.github.com/OCHamcrest/
|
||||
// Source: https://github.com/hamcrest/OCHamcrest
|
||||
//
|
||||
|
||||
#import <OCHamcrest/HCBaseMatcher.h>
|
||||
|
||||
|
||||
@interface HCIsCollectionContainingInAnyOrder : HCBaseMatcher
|
||||
{
|
||||
NSMutableArray *matchers;
|
||||
}
|
||||
|
||||
+ (id)isCollectionContainingInAnyOrder:(NSMutableArray *)itemMatchers;
|
||||
- (id)initWithMatchers:(NSMutableArray *)itemMatchers;
|
||||
|
||||
@end
|
||||
|
||||
|
||||
OBJC_EXPORT id<HCMatcher> HC_containsInAnyOrder(id itemMatch, ...) NS_REQUIRES_NIL_TERMINATION;
|
||||
|
||||
/**
|
||||
containsInAnyOrder(firstMatcher, ...) -
|
||||
Matches if collection's elements, in any order, satisfy a given list of matchers.
|
||||
|
||||
@param firstMatcher,... A comma-separated list of matchers ending with @c nil.
|
||||
|
||||
This matcher iterates the evaluated collection, seeing if each element satisfies any of the
|
||||
given matchers. The matchers are tried from left to right, and when a satisfied matcher is
|
||||
found, it is no longer a candidate for the remaining elements. If a one-to-one correspondence is
|
||||
established between elements and matchers, @c containsInAnyOrder is satisfied.
|
||||
|
||||
Any argument that is not a matcher is implicitly wrapped in an @ref equalTo matcher to check for
|
||||
equality.
|
||||
|
||||
(In the event of a name clash, don't \#define @c HC_SHORTHAND and use the synonym
|
||||
@c HC_containsInAnyOrder instead.)
|
||||
|
||||
@ingroup collection_matchers
|
||||
*/
|
||||
#ifdef HC_SHORTHAND
|
||||
#define containsInAnyOrder HC_containsInAnyOrder
|
||||
#endif
|
||||
+142
@@ -0,0 +1,142 @@
|
||||
//
|
||||
// OCHamcrest - HCIsCollectionContainingInAnyOrder.m
|
||||
// Copyright 2012 hamcrest.org. See LICENSE.txt
|
||||
//
|
||||
// Created by: Jon Reid, http://qualitycoding.org/
|
||||
// Docs: http://hamcrest.github.com/OCHamcrest/
|
||||
// Source: https://github.com/hamcrest/OCHamcrest
|
||||
//
|
||||
|
||||
#import "HCIsCollectionContainingInAnyOrder.h"
|
||||
|
||||
#import "HCAllOf.h"
|
||||
#import "HCDescription.h"
|
||||
#import "HCWrapInMatcher.h"
|
||||
|
||||
|
||||
@interface HCMatchingInAnyOrder : NSObject
|
||||
{
|
||||
NSMutableArray *matchers;
|
||||
id<HCDescription, NSObject> mismatchDescription;
|
||||
}
|
||||
@end
|
||||
|
||||
|
||||
@implementation HCMatchingInAnyOrder
|
||||
|
||||
- (id)initWithMatchers:(NSMutableArray *)itemMatchers
|
||||
mismatchDescription:(id<HCDescription, NSObject>)description
|
||||
{
|
||||
self = [super init];
|
||||
if (self)
|
||||
{
|
||||
matchers = itemMatchers;
|
||||
mismatchDescription = description;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (BOOL)matches:(id)item
|
||||
{
|
||||
NSUInteger index = 0;
|
||||
for (id<HCMatcher> matcher in matchers)
|
||||
{
|
||||
if ([matcher matches:item])
|
||||
{
|
||||
[matchers removeObjectAtIndex:index];
|
||||
return YES;
|
||||
}
|
||||
++index;
|
||||
}
|
||||
[[mismatchDescription appendText:@"not matched: "] appendDescriptionOf:item];
|
||||
return NO;
|
||||
}
|
||||
|
||||
- (BOOL)isFinishedWith:(NSArray *)collection
|
||||
{
|
||||
if ([matchers count] == 0)
|
||||
return YES;
|
||||
|
||||
[[[[mismatchDescription appendText:@"no item matches: "]
|
||||
appendList:matchers start:@"" separator:@", " end:@""]
|
||||
appendText:@" in "]
|
||||
appendList:collection start:@"[" separator:@", " end:@"]"];
|
||||
return NO;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
|
||||
#pragma mark -
|
||||
|
||||
@implementation HCIsCollectionContainingInAnyOrder
|
||||
|
||||
+ (id)isCollectionContainingInAnyOrder:(NSMutableArray *)itemMatchers
|
||||
{
|
||||
return [[self alloc] initWithMatchers:itemMatchers];
|
||||
}
|
||||
|
||||
- (id)initWithMatchers:(NSMutableArray *)itemMatchers
|
||||
{
|
||||
self = [super init];
|
||||
if (self)
|
||||
matchers = itemMatchers;
|
||||
return self;
|
||||
}
|
||||
|
||||
- (BOOL)matches:(id)collection
|
||||
{
|
||||
return [self matches:collection describingMismatchTo:nil];
|
||||
}
|
||||
|
||||
- (BOOL)matches:(id)collection describingMismatchTo:(id<HCDescription>)mismatchDescription
|
||||
{
|
||||
if (![collection conformsToProtocol:@protocol(NSFastEnumeration)])
|
||||
{
|
||||
[super describeMismatchOf:collection to:mismatchDescription];
|
||||
return NO;
|
||||
}
|
||||
|
||||
HCMatchingInAnyOrder *matchSequence =
|
||||
[[HCMatchingInAnyOrder alloc] initWithMatchers:matchers
|
||||
mismatchDescription:mismatchDescription];
|
||||
for (id item in collection)
|
||||
if (![matchSequence matches:item])
|
||||
return NO;
|
||||
|
||||
return [matchSequence isFinishedWith:collection];
|
||||
}
|
||||
|
||||
- (void)describeMismatchOf:(id)item to:(id<HCDescription>)mismatchDescription
|
||||
{
|
||||
[self matches:item describingMismatchTo:mismatchDescription];
|
||||
}
|
||||
|
||||
- (void)describeTo:(id<HCDescription>)description
|
||||
{
|
||||
[[[description appendText:@"a collection over "]
|
||||
appendList:matchers start:@"[" separator:@", " end:@"]"]
|
||||
appendText:@" in any order"];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
|
||||
#pragma mark -
|
||||
|
||||
id<HCMatcher> HC_containsInAnyOrder(id itemMatch, ...)
|
||||
{
|
||||
NSMutableArray *matchers = [NSMutableArray arrayWithObject:HCWrapInMatcher(itemMatch)];
|
||||
|
||||
va_list args;
|
||||
va_start(args, itemMatch);
|
||||
itemMatch = va_arg(args, id);
|
||||
while (itemMatch != nil)
|
||||
{
|
||||
[matchers addObject:HCWrapInMatcher(itemMatch)];
|
||||
itemMatch = va_arg(args, id);
|
||||
}
|
||||
va_end(args);
|
||||
|
||||
return [HCIsCollectionContainingInAnyOrder isCollectionContainingInAnyOrder:matchers];
|
||||
}
|
||||
+45
@@ -0,0 +1,45 @@
|
||||
//
|
||||
// OCHamcrest - HCIsCollectionContainingInOrder.h
|
||||
// Copyright 2012 hamcrest.org. See LICENSE.txt
|
||||
//
|
||||
// Created by: Jon Reid, http://qualitycoding.org/
|
||||
// Docs: http://hamcrest.github.com/OCHamcrest/
|
||||
// Source: https://github.com/hamcrest/OCHamcrest
|
||||
//
|
||||
|
||||
#import <OCHamcrest/HCBaseMatcher.h>
|
||||
|
||||
|
||||
@interface HCIsCollectionContainingInOrder : HCBaseMatcher
|
||||
{
|
||||
NSArray *matchers;
|
||||
}
|
||||
|
||||
+ (id)isCollectionContainingInOrder:(NSArray *)itemMatchers;
|
||||
- (id)initWithMatchers:(NSArray *)itemMatchers;
|
||||
|
||||
@end
|
||||
|
||||
|
||||
OBJC_EXPORT id<HCMatcher> HC_contains(id itemMatch, ...) NS_REQUIRES_NIL_TERMINATION;
|
||||
|
||||
/**
|
||||
contains(firstMatcher, ...) -
|
||||
Matches if collection's elements satisfy a given list of matchers, in order.
|
||||
|
||||
@param firstMatcher,... A comma-separated list of matchers ending with @c nil.
|
||||
|
||||
This matcher iterates the evaluated collection and a given list of matchers, seeing if each
|
||||
element satisfies its corresponding matcher.
|
||||
|
||||
Any argument that is not a matcher is implicitly wrapped in an @ref equalTo matcher to check for
|
||||
equality.
|
||||
|
||||
(In the event of a name clash, don't \#define @c HC_SHORTHAND and use the synonym
|
||||
@c HC_contains instead.)
|
||||
|
||||
@ingroup collection_matchers
|
||||
*/
|
||||
#ifdef HC_SHORTHAND
|
||||
#define contains HC_contains
|
||||
#endif
|
||||
+161
@@ -0,0 +1,161 @@
|
||||
//
|
||||
// OCHamcrest - HCIsCollectionContainingInOrder.m
|
||||
// Copyright 2012 hamcrest.org. See LICENSE.txt
|
||||
//
|
||||
// Created by: Jon Reid, http://qualitycoding.org/
|
||||
// Docs: http://hamcrest.github.com/OCHamcrest/
|
||||
// Source: https://github.com/hamcrest/OCHamcrest
|
||||
//
|
||||
|
||||
#import "HCIsCollectionContainingInOrder.h"
|
||||
|
||||
#import "HCAllOf.h"
|
||||
#import "HCDescription.h"
|
||||
#import "HCWrapInMatcher.h"
|
||||
|
||||
|
||||
@interface HCMatchSequence : NSObject
|
||||
{
|
||||
NSArray *matchers;
|
||||
id<HCDescription, NSObject> mismatchDescription;
|
||||
NSUInteger nextMatchIndex;
|
||||
}
|
||||
|
||||
- (BOOL)isMatched:(id)item;
|
||||
- (BOOL)isNotSurplus:(id)item;
|
||||
- (void)describeMismatchOfMatcher:(id<HCMatcher>)matcher item:(id)item;
|
||||
|
||||
@end
|
||||
|
||||
@implementation HCMatchSequence
|
||||
|
||||
- (id)initWithMatchers:(NSArray *)itemMatchers mismatchDescription:(id<HCDescription, NSObject>)description
|
||||
{
|
||||
self = [super init];
|
||||
if (self)
|
||||
{
|
||||
matchers = itemMatchers;
|
||||
mismatchDescription = description;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (BOOL)matches:(id)item
|
||||
{
|
||||
return [self isNotSurplus:item] && [self isMatched:item];
|
||||
}
|
||||
|
||||
- (BOOL)isFinished
|
||||
{
|
||||
if (nextMatchIndex < [matchers count])
|
||||
{
|
||||
[[mismatchDescription appendText:@"no item matched: "]
|
||||
appendDescriptionOf:matchers[nextMatchIndex]];
|
||||
return NO;
|
||||
}
|
||||
return YES;
|
||||
}
|
||||
|
||||
- (BOOL)isMatched:(id)item
|
||||
{
|
||||
id<HCMatcher> matcher = matchers[nextMatchIndex];
|
||||
if (![matcher matches:item])
|
||||
{
|
||||
[self describeMismatchOfMatcher:matcher item:item];
|
||||
return NO;
|
||||
}
|
||||
++nextMatchIndex;
|
||||
return YES;
|
||||
}
|
||||
|
||||
- (BOOL)isNotSurplus:(id)item
|
||||
{
|
||||
if ([matchers count] <= nextMatchIndex)
|
||||
{
|
||||
[[mismatchDescription appendText:@"not matched: "] appendDescriptionOf:item];
|
||||
return NO;
|
||||
}
|
||||
return YES;
|
||||
}
|
||||
|
||||
- (void)describeMismatchOfMatcher:(id<HCMatcher>)matcher item:(id)item
|
||||
{
|
||||
[mismatchDescription appendText:[NSString stringWithFormat:@"item %zi: ", nextMatchIndex]];
|
||||
[matcher describeMismatchOf:item to:mismatchDescription];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
|
||||
#pragma mark -
|
||||
|
||||
@implementation HCIsCollectionContainingInOrder
|
||||
|
||||
+ (id)isCollectionContainingInOrder:(NSArray *)itemMatchers
|
||||
{
|
||||
return [[self alloc] initWithMatchers:itemMatchers];
|
||||
}
|
||||
|
||||
- (id)initWithMatchers:(NSArray *)itemMatchers
|
||||
{
|
||||
self = [super init];
|
||||
if (self)
|
||||
matchers = itemMatchers;
|
||||
return self;
|
||||
}
|
||||
|
||||
- (BOOL)matches:(id)collection
|
||||
{
|
||||
return [self matches:collection describingMismatchTo:nil];
|
||||
}
|
||||
|
||||
- (BOOL)matches:(id)collection describingMismatchTo:(id<HCDescription, NSObject>)mismatchDescription
|
||||
{
|
||||
if (![collection conformsToProtocol:@protocol(NSFastEnumeration)])
|
||||
{
|
||||
[super describeMismatchOf:collection to:mismatchDescription];
|
||||
return NO;
|
||||
}
|
||||
|
||||
HCMatchSequence *matchSequence =
|
||||
[[HCMatchSequence alloc] initWithMatchers:matchers
|
||||
mismatchDescription:mismatchDescription];
|
||||
for (id item in collection)
|
||||
if (![matchSequence matches:item])
|
||||
return NO;
|
||||
|
||||
return [matchSequence isFinished];
|
||||
}
|
||||
|
||||
- (void)describeMismatchOf:(id)item to:(id<HCDescription>)mismatchDescription
|
||||
{
|
||||
[self matches:item describingMismatchTo:mismatchDescription];
|
||||
}
|
||||
|
||||
- (void)describeTo:(id<HCDescription>)description
|
||||
{
|
||||
[[description appendText:@"a collection containing "]
|
||||
appendList:matchers start:@"[" separator:@", " end:@"]"];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
|
||||
#pragma mark -
|
||||
|
||||
id<HCMatcher> HC_contains(id itemMatch, ...)
|
||||
{
|
||||
NSMutableArray *matchers = [NSMutableArray arrayWithObject:HCWrapInMatcher(itemMatch)];
|
||||
|
||||
va_list args;
|
||||
va_start(args, itemMatch);
|
||||
itemMatch = va_arg(args, id);
|
||||
while (itemMatch != nil)
|
||||
{
|
||||
[matchers addObject:HCWrapInMatcher(itemMatch)];
|
||||
itemMatch = va_arg(args, id);
|
||||
}
|
||||
va_end(args);
|
||||
|
||||
return [HCIsCollectionContainingInOrder isCollectionContainingInOrder:matchers];
|
||||
}
|
||||
Vendored
+52
@@ -0,0 +1,52 @@
|
||||
//
|
||||
// OCHamcrest - HCIsCollectionOnlyContaining.h
|
||||
// Copyright 2012 hamcrest.org. See LICENSE.txt
|
||||
//
|
||||
// Created by: Jon Reid, http://qualitycoding.org/
|
||||
// Docs: http://hamcrest.github.com/OCHamcrest/
|
||||
// Source: https://github.com/hamcrest/OCHamcrest
|
||||
//
|
||||
|
||||
#import <OCHamcrest/HCBaseMatcher.h>
|
||||
|
||||
|
||||
@interface HCIsCollectionOnlyContaining : HCBaseMatcher
|
||||
{
|
||||
id<HCMatcher> matcher;
|
||||
}
|
||||
|
||||
+ (id)isCollectionOnlyContaining:(id<HCMatcher>)aMatcher;
|
||||
- (id)initWithMatcher:(id<HCMatcher>)aMatcher;
|
||||
|
||||
@end
|
||||
|
||||
|
||||
OBJC_EXPORT id<HCMatcher> HC_onlyContains(id itemMatch, ...) NS_REQUIRES_NIL_TERMINATION;
|
||||
|
||||
/**
|
||||
onlyContains(firstMatcher, ...) -
|
||||
Matches if each element of collection satisfies any of the given matchers.
|
||||
|
||||
@param firstMatcher,... A comma-separated list of matchers ending with @c nil.
|
||||
|
||||
This matcher iterates the evaluated collection, confirming whether each element satisfies any of
|
||||
the given matchers.
|
||||
|
||||
Any argument that is not a matcher is implicitly wrapped in an @ref equalTo matcher to check for
|
||||
equality.
|
||||
|
||||
Example:
|
||||
|
||||
@par
|
||||
@ref onlyContains(startsWith(@"Jo"), nil)
|
||||
|
||||
will match a collection [@"Jon", @"John", @"Johann"].
|
||||
|
||||
(In the event of a name clash, don't \#define @c HC_SHORTHAND and use the synonym
|
||||
@c HC_onlyContains instead.)
|
||||
|
||||
@ingroup collection_matchers
|
||||
*/
|
||||
#ifdef HC_SHORTHAND
|
||||
#define onlyContains HC_onlyContains
|
||||
#endif
|
||||
Vendored
+72
@@ -0,0 +1,72 @@
|
||||
//
|
||||
// OCHamcrest - HCIsCollectionOnlyContaining.m
|
||||
// Copyright 2012 hamcrest.org. See LICENSE.txt
|
||||
//
|
||||
// Created by: Jon Reid, http://qualitycoding.org/
|
||||
// Docs: http://hamcrest.github.com/OCHamcrest/
|
||||
// Source: https://github.com/hamcrest/OCHamcrest
|
||||
//
|
||||
|
||||
#import "HCIsCollectionOnlyContaining.h"
|
||||
|
||||
#import "HCAnyOf.h"
|
||||
#import "HCDescription.h"
|
||||
#import "HCWrapInMatcher.h"
|
||||
|
||||
|
||||
@implementation HCIsCollectionOnlyContaining
|
||||
|
||||
+ (id)isCollectionOnlyContaining:(id<HCMatcher>)aMatcher
|
||||
{
|
||||
return [[self alloc] initWithMatcher:aMatcher];
|
||||
}
|
||||
|
||||
- (id)initWithMatcher:(id<HCMatcher>)aMatcher
|
||||
{
|
||||
self = [super init];
|
||||
if (self)
|
||||
matcher = aMatcher;
|
||||
return self;
|
||||
}
|
||||
|
||||
- (BOOL)matches:(id)collection
|
||||
{
|
||||
if (![collection conformsToProtocol:@protocol(NSFastEnumeration)])
|
||||
return NO;
|
||||
|
||||
if ([collection count] == 0)
|
||||
return NO;
|
||||
|
||||
for (id item in collection)
|
||||
if (![matcher matches:item])
|
||||
return NO;
|
||||
return YES;
|
||||
}
|
||||
|
||||
- (void)describeTo:(id<HCDescription>)description
|
||||
{
|
||||
[[description appendText:@"a collection containing items matching "]
|
||||
appendDescriptionOf:matcher];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
|
||||
#pragma mark -
|
||||
|
||||
id<HCMatcher> HC_onlyContains(id itemMatch, ...)
|
||||
{
|
||||
NSMutableArray *matchers = [NSMutableArray arrayWithObject:HCWrapInMatcher(itemMatch)];
|
||||
|
||||
va_list args;
|
||||
va_start(args, itemMatch);
|
||||
itemMatch = va_arg(args, id);
|
||||
while (itemMatch != nil)
|
||||
{
|
||||
[matchers addObject:HCWrapInMatcher(itemMatch)];
|
||||
itemMatch = va_arg(args, id);
|
||||
}
|
||||
va_end(args);
|
||||
|
||||
return [HCIsCollectionOnlyContaining isCollectionOnlyContaining:[HCAnyOf anyOf:matchers]];
|
||||
}
|
||||
Vendored
+54
@@ -0,0 +1,54 @@
|
||||
//
|
||||
// OCHamcrest - HCIsDictionaryContaining.h
|
||||
// Copyright 2012 hamcrest.org. See LICENSE.txt
|
||||
//
|
||||
// Created by: Jon Reid, http://qualitycoding.org/
|
||||
// Docs: http://hamcrest.github.com/OCHamcrest/
|
||||
// Source: https://github.com/hamcrest/OCHamcrest
|
||||
//
|
||||
|
||||
#import <OCHamcrest/HCBaseMatcher.h>
|
||||
|
||||
|
||||
@interface HCIsDictionaryContaining : HCBaseMatcher
|
||||
{
|
||||
id<HCMatcher> keyMatcher;
|
||||
id<HCMatcher> valueMatcher;
|
||||
}
|
||||
|
||||
+ (id)isDictionaryContainingKey:(id<HCMatcher>)aKeyMatcher
|
||||
value:(id<HCMatcher>)aValueMatcher;
|
||||
|
||||
- (id)initWithKeyMatcher:(id<HCMatcher>)aKeyMatcher
|
||||
valueMatcher:(id<HCMatcher>)aValueMatcher;
|
||||
|
||||
@end
|
||||
|
||||
|
||||
OBJC_EXPORT id<HCMatcher> HC_hasEntry(id keyMatch, id valueMatch);
|
||||
|
||||
/**
|
||||
hasEntry(keyMatcher, valueMatcher) -
|
||||
Matches if dictionary contains key-value entry satisfying a given pair of matchers.
|
||||
|
||||
@param keyMatcher The matcher to satisfy for the key, or an expected value for @ref equalTo matching.
|
||||
@param valueMatcher The matcher to satisfy for the value, or an expected value for @ref equalTo matching.
|
||||
|
||||
This matcher iterates the evaluated dictionary, searching for any key-value entry that satisfies
|
||||
@a keyMatcher and @a valueMatcher. If a matching entry is found, @c hasEntry is satisfied.
|
||||
|
||||
Any argument that is not a matcher is implicitly wrapped in an @ref equalTo matcher to check for
|
||||
equality.
|
||||
|
||||
Examples:
|
||||
@li @ref hasEntry(@ref equalTo(@"foo"), equalTo(@"bar"))
|
||||
@li @ref hasEntry(@"foo", @"bar")
|
||||
|
||||
(In the event of a name clash, don't \#define @c HC_SHORTHAND and use the synonym
|
||||
@c HC_hasEntry instead.)
|
||||
|
||||
@ingroup collection_matchers
|
||||
*/
|
||||
#ifdef HC_SHORTHAND
|
||||
#define hasEntry HC_hasEntry
|
||||
#endif
|
||||
Vendored
+66
@@ -0,0 +1,66 @@
|
||||
//
|
||||
// OCHamcrest - HCIsDictionaryContaining.m
|
||||
// Copyright 2012 hamcrest.org. See LICENSE.txt
|
||||
//
|
||||
// Created by: Jon Reid, http://qualitycoding.org/
|
||||
// Docs: http://hamcrest.github.com/OCHamcrest/
|
||||
// Source: https://github.com/hamcrest/OCHamcrest
|
||||
//
|
||||
|
||||
#import "HCIsDictionaryContaining.h"
|
||||
|
||||
#import "HCDescription.h"
|
||||
#import "HCRequireNonNilObject.h"
|
||||
#import "HCWrapInMatcher.h"
|
||||
|
||||
|
||||
@implementation HCIsDictionaryContaining
|
||||
|
||||
+ (id)isDictionaryContainingKey:(id<HCMatcher>)aKeyMatcher
|
||||
value:(id<HCMatcher>)aValueMatcher
|
||||
{
|
||||
return [[self alloc] initWithKeyMatcher:aKeyMatcher valueMatcher:aValueMatcher];
|
||||
}
|
||||
|
||||
- (id)initWithKeyMatcher:(id<HCMatcher>)aKeyMatcher
|
||||
valueMatcher:(id<HCMatcher>)aValueMatcher
|
||||
{
|
||||
self = [super init];
|
||||
if (self)
|
||||
{
|
||||
keyMatcher = aKeyMatcher;
|
||||
valueMatcher = aValueMatcher;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (BOOL)matches:(id)dict
|
||||
{
|
||||
if ([dict isKindOfClass:[NSDictionary class]])
|
||||
for (id oneKey in dict)
|
||||
if ([keyMatcher matches:oneKey] && [valueMatcher matches:dict[oneKey]])
|
||||
return YES;
|
||||
return NO;
|
||||
}
|
||||
|
||||
- (void)describeTo:(id<HCDescription>)description
|
||||
{
|
||||
[[[[[description appendText:@"a dictionary containing { "]
|
||||
appendDescriptionOf:keyMatcher]
|
||||
appendText:@" = "]
|
||||
appendDescriptionOf:valueMatcher]
|
||||
appendText:@"; }"];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
|
||||
#pragma mark -
|
||||
|
||||
id<HCMatcher> HC_hasEntry(id keyMatch, id valueMatch)
|
||||
{
|
||||
HCRequireNonNilObject(keyMatch);
|
||||
HCRequireNonNilObject(valueMatch);
|
||||
return [HCIsDictionaryContaining isDictionaryContainingKey:HCWrapInMatcher(keyMatch)
|
||||
value:HCWrapInMatcher(valueMatch)];
|
||||
}
|
||||
+53
@@ -0,0 +1,53 @@
|
||||
//
|
||||
// OCHamcrest - HCIsDictionaryContainingEntries.h
|
||||
// Copyright 2012 hamcrest.org. See LICENSE.txt
|
||||
//
|
||||
// Created by: Jon Reid, http://qualitycoding.org/
|
||||
// Docs: http://hamcrest.github.com/OCHamcrest/
|
||||
// Source: https://github.com/hamcrest/OCHamcrest
|
||||
//
|
||||
|
||||
#import <OCHamcrest/HCBaseMatcher.h>
|
||||
|
||||
|
||||
@interface HCIsDictionaryContainingEntries : HCBaseMatcher
|
||||
{
|
||||
NSArray *keys;
|
||||
NSArray *valueMatchers;
|
||||
}
|
||||
|
||||
+ (id)isDictionaryContainingKeys:(NSArray *)theKeys
|
||||
valueMatchers:(NSArray *)theValueMatchers;
|
||||
|
||||
- (id)initWithKeys:(NSArray *)theKeys
|
||||
valueMatchers:(NSArray *)theValueMatchers;
|
||||
|
||||
@end
|
||||
|
||||
|
||||
OBJC_EXPORT id<HCMatcher> HC_hasEntries(id keysAndValueMatch, ...) NS_REQUIRES_NIL_TERMINATION;
|
||||
|
||||
/**
|
||||
hasEntries(firstKey, valueMatcher, ...) -
|
||||
Matches if dictionary contains entries satisfying a list of alternating keys and their value
|
||||
matchers.
|
||||
|
||||
@param firstKey A key (not a matcher) to look up.
|
||||
@param valueMatcher,... The matcher to satisfy for the value, or an expected value for @ref equalTo matching.
|
||||
|
||||
Note that the keys must be actual keys, not matchers. Any value argument that is not a matcher
|
||||
is implicitly wrapped in an @ref equalTo matcher to check for equality. The list must end with
|
||||
@c nil.
|
||||
|
||||
Examples:
|
||||
@li @ref hasEntries(@"first", equalTo(@"Jon"), @"last", equalTo(@"Reid"), nil)
|
||||
@li @ref hasEntries(@"first", @"Jon", @"last", @"Reid", nil)
|
||||
|
||||
(In the event of a name clash, don't \#define @c HC_SHORTHAND and use the synonym
|
||||
@c HC_hasEntry instead.)
|
||||
|
||||
@ingroup collection_matchers
|
||||
*/
|
||||
#ifdef HC_SHORTHAND
|
||||
#define hasEntries HC_hasEntries
|
||||
#endif
|
||||
+141
@@ -0,0 +1,141 @@
|
||||
//
|
||||
// OCHamcrest - HCIsDictionaryContainingEntries.m
|
||||
// Copyright 2012 hamcrest.org. See LICENSE.txt
|
||||
//
|
||||
// Created by: Jon Reid, http://qualitycoding.org/
|
||||
// Docs: http://hamcrest.github.com/OCHamcrest/
|
||||
// Source: https://github.com/hamcrest/OCHamcrest
|
||||
//
|
||||
|
||||
#import "HCIsDictionaryContainingEntries.h"
|
||||
|
||||
#import "HCDescription.h"
|
||||
#import "HCWrapInMatcher.h"
|
||||
|
||||
|
||||
@implementation HCIsDictionaryContainingEntries
|
||||
|
||||
+ (id)isDictionaryContainingKeys:(NSArray *)theKeys
|
||||
valueMatchers:(NSArray *)theValueMatchers
|
||||
{
|
||||
return [[self alloc] initWithKeys:theKeys valueMatchers:theValueMatchers];
|
||||
}
|
||||
|
||||
- (id)initWithKeys:(NSArray *)theKeys
|
||||
valueMatchers:(NSArray *)theValueMatchers
|
||||
{
|
||||
self = [super init];
|
||||
if (self)
|
||||
{
|
||||
keys = theKeys;
|
||||
valueMatchers = theValueMatchers;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (BOOL)matches:(id)item
|
||||
{
|
||||
return [self matches:item describingMismatchTo:nil];
|
||||
}
|
||||
|
||||
- (BOOL)matches:(id)dict describingMismatchTo:(id<HCDescription>)mismatchDescription
|
||||
{
|
||||
if (![dict isKindOfClass:[NSDictionary class]])
|
||||
{
|
||||
[super describeMismatchOf:dict to:mismatchDescription];
|
||||
return NO;
|
||||
}
|
||||
|
||||
NSUInteger count = [keys count];
|
||||
for (NSUInteger index = 0; index < count; ++index)
|
||||
{
|
||||
id key = keys[index];
|
||||
if (dict[key] == nil)
|
||||
{
|
||||
[[[[mismatchDescription appendText:@"no "]
|
||||
appendDescriptionOf:key]
|
||||
appendText:@" key in "]
|
||||
appendDescriptionOf:dict];
|
||||
return NO;
|
||||
}
|
||||
|
||||
id valueMatcher = valueMatchers[index];
|
||||
id actualValue = dict[key];
|
||||
|
||||
if (![valueMatcher matches:actualValue])
|
||||
{
|
||||
[[[[mismatchDescription appendText:@"value for "]
|
||||
appendDescriptionOf:key]
|
||||
appendText:@" was "]
|
||||
appendDescriptionOf:actualValue];
|
||||
return NO;
|
||||
}
|
||||
}
|
||||
|
||||
return YES;
|
||||
}
|
||||
|
||||
- (void)describeMismatchOf:(id)item to:(id<HCDescription>)mismatchDescription
|
||||
{
|
||||
[self matches:item describingMismatchTo:mismatchDescription];
|
||||
}
|
||||
|
||||
- (void)describeKeyValueAtIndex:(NSUInteger)index to:(id<HCDescription>)description
|
||||
{
|
||||
[[[[description appendDescriptionOf:keys[index]]
|
||||
appendText:@" = "]
|
||||
appendDescriptionOf:valueMatchers[index]]
|
||||
appendText:@"; "];
|
||||
}
|
||||
|
||||
- (void)describeTo:(id<HCDescription>)description
|
||||
{
|
||||
[description appendText:@"a dictionary containing { "];
|
||||
NSUInteger count = [keys count];
|
||||
NSUInteger index = 0;
|
||||
for (; index < count - 1; ++index)
|
||||
[self describeKeyValueAtIndex:index to:description];
|
||||
[self describeKeyValueAtIndex:index to:description];
|
||||
[description appendText:@"}"];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
|
||||
#pragma mark -
|
||||
|
||||
static void requirePairedObject(id obj)
|
||||
{
|
||||
if (obj == nil)
|
||||
{
|
||||
@throw [NSException exceptionWithName:@"NilObject"
|
||||
reason:@"HC_hasEntries keys and value matchers must be paired"
|
||||
userInfo:nil];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
id<HCMatcher> HC_hasEntries(id keysAndValueMatch, ...)
|
||||
{
|
||||
va_list args;
|
||||
va_start(args, keysAndValueMatch);
|
||||
|
||||
id key = keysAndValueMatch;
|
||||
id valueMatcher = va_arg(args, id);
|
||||
requirePairedObject(valueMatcher);
|
||||
NSMutableArray *keys = [NSMutableArray arrayWithObject:key];
|
||||
NSMutableArray *valueMatchers = [NSMutableArray arrayWithObject:HCWrapInMatcher(valueMatcher)];
|
||||
|
||||
key = va_arg(args, id);
|
||||
while (key != nil)
|
||||
{
|
||||
[keys addObject:key];
|
||||
valueMatcher = va_arg(args, id);
|
||||
requirePairedObject(valueMatcher);
|
||||
[valueMatchers addObject:HCWrapInMatcher(valueMatcher)];
|
||||
key = va_arg(args, id);
|
||||
}
|
||||
|
||||
return [HCIsDictionaryContainingEntries isDictionaryContainingKeys:keys
|
||||
valueMatchers:valueMatchers];
|
||||
}
|
||||
Vendored
+49
@@ -0,0 +1,49 @@
|
||||
//
|
||||
// OCHamcrest - HCIsDictionaryContainingKey.h
|
||||
// Copyright 2012 hamcrest.org. See LICENSE.txt
|
||||
//
|
||||
// Created by: Jon Reid, http://qualitycoding.org/
|
||||
// Docs: http://hamcrest.github.com/OCHamcrest/
|
||||
// Source: https://github.com/hamcrest/OCHamcrest
|
||||
//
|
||||
|
||||
#import <OCHamcrest/HCBaseMatcher.h>
|
||||
|
||||
|
||||
@interface HCIsDictionaryContainingKey : HCBaseMatcher
|
||||
{
|
||||
id<HCMatcher> keyMatcher;
|
||||
}
|
||||
|
||||
+ (id)isDictionaryContainingKey:(id<HCMatcher>)theKeyMatcher;
|
||||
- (id)initWithKeyMatcher:(id<HCMatcher>)theKeyMatcher;
|
||||
|
||||
@end
|
||||
|
||||
|
||||
OBJC_EXPORT id<HCMatcher> HC_hasKey(id keyMatch);
|
||||
|
||||
/**
|
||||
hasKey(keyMatcher) -
|
||||
Matches if dictionary contains an entry whose key satisfies a given matcher.
|
||||
|
||||
@param keyMatcher The matcher to satisfy for the key, or an expected value for @ref equalTo matching.
|
||||
|
||||
This matcher iterates the evaluated dictionary, searching for any key-value entry whose key
|
||||
satisfies the given matcher. If a matching entry is found, @c hasKey is satisfied.
|
||||
|
||||
Any argument that is not a matcher is implicitly wrapped in an @ref equalTo matcher to check for
|
||||
equality.
|
||||
|
||||
(In the event of a name clash, don't \#define @c HC_SHORTHAND and use the synonym
|
||||
@c HC_hasKey instead.)
|
||||
|
||||
Examples:
|
||||
@li @ref hasEntry(equalTo(@"foo"))
|
||||
@li @ref hasEntry(@"foo")
|
||||
|
||||
@ingroup collection_matchers
|
||||
*/
|
||||
#ifdef HC_SHORTHAND
|
||||
#define hasKey HC_hasKey
|
||||
#endif
|
||||
Vendored
+56
@@ -0,0 +1,56 @@
|
||||
//
|
||||
// OCHamcrest - HCIsDictionaryContainingKey.m
|
||||
// Copyright 2012 hamcrest.org. See LICENSE.txt
|
||||
//
|
||||
// Created by: Jon Reid, http://qualitycoding.org/
|
||||
// Docs: http://hamcrest.github.com/OCHamcrest/
|
||||
// Source: https://github.com/hamcrest/OCHamcrest
|
||||
//
|
||||
|
||||
#import "HCIsDictionaryContainingKey.h"
|
||||
|
||||
#import "HCDescription.h"
|
||||
#import "HCRequireNonNilObject.h"
|
||||
#import "HCWrapInMatcher.h"
|
||||
|
||||
|
||||
@implementation HCIsDictionaryContainingKey
|
||||
|
||||
+ (id)isDictionaryContainingKey:(id<HCMatcher>)theKeyMatcher
|
||||
{
|
||||
return [[self alloc] initWithKeyMatcher:theKeyMatcher];
|
||||
}
|
||||
|
||||
- (id)initWithKeyMatcher:(id<HCMatcher>)theKeyMatcher
|
||||
{
|
||||
self = [super init];
|
||||
if (self)
|
||||
keyMatcher = theKeyMatcher;
|
||||
return self;
|
||||
}
|
||||
|
||||
- (BOOL)matches:(id)dict
|
||||
{
|
||||
if ([dict isKindOfClass:[NSDictionary class]])
|
||||
for (id oneKey in dict)
|
||||
if ([keyMatcher matches:oneKey])
|
||||
return YES;
|
||||
return NO;
|
||||
}
|
||||
|
||||
- (void)describeTo:(id<HCDescription>)description
|
||||
{
|
||||
[[description appendText:@"a dictionary containing key "]
|
||||
appendDescriptionOf:keyMatcher];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
|
||||
#pragma mark -
|
||||
|
||||
id<HCMatcher> HC_hasKey(id keyMatch)
|
||||
{
|
||||
HCRequireNonNilObject(keyMatch);
|
||||
return [HCIsDictionaryContainingKey isDictionaryContainingKey:HCWrapInMatcher(keyMatch)];
|
||||
}
|
||||
Vendored
+49
@@ -0,0 +1,49 @@
|
||||
//
|
||||
// OCHamcrest - HCIsDictionaryContainingValue.h
|
||||
// Copyright 2012 hamcrest.org. See LICENSE.txt
|
||||
//
|
||||
// Created by: Jon Reid, http://qualitycoding.org/
|
||||
// Docs: http://hamcrest.github.com/OCHamcrest/
|
||||
// Source: https://github.com/hamcrest/OCHamcrest
|
||||
//
|
||||
|
||||
#import <OCHamcrest/HCBaseMatcher.h>
|
||||
|
||||
|
||||
@interface HCIsDictionaryContainingValue : HCBaseMatcher
|
||||
{
|
||||
id<HCMatcher> valueMatcher;
|
||||
}
|
||||
|
||||
+ (id)isDictionaryContainingValue:(id<HCMatcher>)theValueMatcher;
|
||||
- (id)initWithValueMatcher:(id<HCMatcher>)theValueMatcher;
|
||||
|
||||
@end
|
||||
|
||||
|
||||
OBJC_EXPORT id<HCMatcher> HC_hasValue(id valueMatch);
|
||||
|
||||
/**
|
||||
hasValue(valueMatcher) -
|
||||
Matches if dictionary contains an entry whose value satisfies a given matcher.
|
||||
|
||||
@param valueMatcher The matcher to satisfy for the value, or an expected value for @ref equalTo matching.
|
||||
|
||||
This matcher iterates the evaluated dictionary, searching for any key-value entry whose value
|
||||
satisfies the given matcher. If a matching entry is found, @c hasValue is satisfied.
|
||||
|
||||
Any argument that is not a matcher is implicitly wrapped in an @ref equalTo matcher to check for
|
||||
equality.
|
||||
|
||||
Examples:
|
||||
@li @ref hasValue(equalTo(@"bar"))
|
||||
@li @ref hasValue(@"bar")
|
||||
|
||||
(In the event of a name clash, don't \#define @c HC_SHORTHAND and use the synonym
|
||||
@c HC_hasValue instead.)
|
||||
|
||||
@ingroup collection_matchers
|
||||
*/
|
||||
#ifdef HC_SHORTHAND
|
||||
#define hasValue HC_hasValue
|
||||
#endif
|
||||
Vendored
+56
@@ -0,0 +1,56 @@
|
||||
//
|
||||
// OCHamcrest - HCIsDictionaryContainingValue.m
|
||||
// Copyright 2012 hamcrest.org. See LICENSE.txt
|
||||
//
|
||||
// Created by: Jon Reid, http://qualitycoding.org/
|
||||
// Docs: http://hamcrest.github.com/OCHamcrest/
|
||||
// Source: https://github.com/hamcrest/OCHamcrest
|
||||
//
|
||||
|
||||
#import "HCIsDictionaryContainingValue.h"
|
||||
|
||||
#import "HCDescription.h"
|
||||
#import "HCRequireNonNilObject.h"
|
||||
#import "HCWrapInMatcher.h"
|
||||
|
||||
|
||||
@implementation HCIsDictionaryContainingValue
|
||||
|
||||
+ (id)isDictionaryContainingValue:(id<HCMatcher>)theValueMatcher
|
||||
{
|
||||
return [[self alloc] initWithValueMatcher:theValueMatcher];
|
||||
}
|
||||
|
||||
- (id)initWithValueMatcher:(id<HCMatcher>)theValueMatcher
|
||||
{
|
||||
self = [super init];
|
||||
if (self)
|
||||
valueMatcher = theValueMatcher;
|
||||
return self;
|
||||
}
|
||||
|
||||
- (BOOL)matches:(id)dict
|
||||
{
|
||||
if ([dict respondsToSelector:@selector(allValues)])
|
||||
for (id oneValue in [dict allValues])
|
||||
if ([valueMatcher matches:oneValue])
|
||||
return YES;
|
||||
return NO;
|
||||
}
|
||||
|
||||
- (void)describeTo:(id<HCDescription>)description
|
||||
{
|
||||
[[description appendText:@"a dictionary containing value "]
|
||||
appendDescriptionOf:valueMatcher];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
|
||||
#pragma mark -
|
||||
|
||||
id<HCMatcher> HC_hasValue(id valueMatch)
|
||||
{
|
||||
HCRequireNonNilObject(valueMatch);
|
||||
return [HCIsDictionaryContainingValue isDictionaryContainingValue:HCWrapInMatcher(valueMatch)];
|
||||
}
|
||||
+36
@@ -0,0 +1,36 @@
|
||||
//
|
||||
// OCHamcrest - HCIsEmptyCollection.h
|
||||
// Copyright 2012 hamcrest.org. See LICENSE.txt
|
||||
//
|
||||
// Created by: Jon Reid, http://qualitycoding.org/
|
||||
// Docs: http://hamcrest.github.com/OCHamcrest/
|
||||
// Source: https://github.com/hamcrest/OCHamcrest
|
||||
//
|
||||
|
||||
#import <OCHamcrest/HCHasCount.h>
|
||||
|
||||
|
||||
@interface HCIsEmptyCollection : HCHasCount
|
||||
|
||||
+ (id)isEmptyCollection;
|
||||
- (id)init;
|
||||
|
||||
@end
|
||||
|
||||
|
||||
OBJC_EXPORT id<HCMatcher> HC_empty(void);
|
||||
|
||||
/**
|
||||
Matches empty collection.
|
||||
|
||||
This matcher invokes @c -count on the evaluated object to determine if the number of elements it
|
||||
contains is zero.
|
||||
|
||||
(In the event of a name clash, don't \#define @c HC_SHORTHAND and use the synonym
|
||||
@c HC_empty instead.)
|
||||
|
||||
@ingroup collection_matchers
|
||||
*/
|
||||
#ifdef HC_SHORTHAND
|
||||
#define empty() HC_empty()
|
||||
#endif
|
||||
+47
@@ -0,0 +1,47 @@
|
||||
//
|
||||
// OCHamcrest - HCIsEmptyCollection.m
|
||||
// Copyright 2012 hamcrest.org. See LICENSE.txt
|
||||
//
|
||||
// Created by: Jon Reid, http://qualitycoding.org/
|
||||
// Docs: http://hamcrest.github.com/OCHamcrest/
|
||||
// Source: https://github.com/hamcrest/OCHamcrest
|
||||
//
|
||||
|
||||
#import "HCIsEmptyCollection.h"
|
||||
|
||||
#import "HCDescription.h"
|
||||
#import "HCIsEqualToNumber.h"
|
||||
|
||||
|
||||
@implementation HCIsEmptyCollection
|
||||
|
||||
+ (id)isEmptyCollection
|
||||
{
|
||||
return [[self alloc] init];
|
||||
}
|
||||
|
||||
- (id)init
|
||||
{
|
||||
self = [super initWithCount:HC_equalToUnsignedInteger(0)];
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)describeMismatchOf:(id)item to:(id<HCDescription>)mismatchDescription
|
||||
{
|
||||
[[mismatchDescription appendText:@"was "] appendDescriptionOf:item];
|
||||
}
|
||||
|
||||
- (void)describeTo:(id<HCDescription>)description
|
||||
{
|
||||
[description appendText:@"empty collection"];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
|
||||
#pragma mark -
|
||||
|
||||
OBJC_EXPORT id<HCMatcher> HC_empty()
|
||||
{
|
||||
return [HCIsEmptyCollection isEmptyCollection];
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
//
|
||||
// OCHamcrest - HCIsIn.h
|
||||
// Copyright 2012 hamcrest.org. See LICENSE.txt
|
||||
//
|
||||
// Created by: Jon Reid, http://qualitycoding.org/
|
||||
// Docs: http://hamcrest.github.com/OCHamcrest/
|
||||
// Source: https://github.com/hamcrest/OCHamcrest
|
||||
//
|
||||
|
||||
#import <OCHamcrest/HCBaseMatcher.h>
|
||||
|
||||
|
||||
@interface HCIsIn : HCBaseMatcher
|
||||
{
|
||||
id collection;
|
||||
}
|
||||
|
||||
+ (id)isInCollection:(id)aCollection;
|
||||
- (id)initWithCollection:(id)aCollection;
|
||||
|
||||
@end
|
||||
|
||||
|
||||
OBJC_EXPORT id<HCMatcher> HC_isIn(id aCollection);
|
||||
|
||||
/**
|
||||
isIn(aCollection) -
|
||||
Matches if evaluated object is present in a given collection.
|
||||
|
||||
@param aCollection The collection to search.
|
||||
|
||||
This matcher invokes @c -containsObject: on @a aCollection to determine if the evaluated object
|
||||
is an element of the collection.
|
||||
|
||||
(In the event of a name clash, don't \#define @c HC_SHORTHAND and use the synonym
|
||||
@c HC_isIn instead.)
|
||||
|
||||
@ingroup collection_matchers
|
||||
*/
|
||||
#ifdef HC_SHORTHAND
|
||||
#define isIn HC_isIn
|
||||
#endif
|
||||
@@ -0,0 +1,56 @@
|
||||
//
|
||||
// OCHamcrest - HCIsIn.m
|
||||
// Copyright 2012 hamcrest.org. See LICENSE.txt
|
||||
//
|
||||
// Created by: Jon Reid, http://qualitycoding.org/
|
||||
// Docs: http://hamcrest.github.com/OCHamcrest/
|
||||
// Source: https://github.com/hamcrest/OCHamcrest
|
||||
//
|
||||
|
||||
#import "HCIsIn.h"
|
||||
|
||||
#import "HCDescription.h"
|
||||
|
||||
|
||||
@implementation HCIsIn
|
||||
|
||||
+ (id)isInCollection:(id)aCollection
|
||||
{
|
||||
return [[self alloc] initWithCollection:aCollection];
|
||||
}
|
||||
|
||||
- (id)initWithCollection:(id)aCollection
|
||||
{
|
||||
if (![aCollection respondsToSelector:@selector(containsObject:)])
|
||||
{
|
||||
@throw [NSException exceptionWithName:@"NotAContainer"
|
||||
reason:@"Object must respond to -containsObject:"
|
||||
userInfo:nil];
|
||||
}
|
||||
|
||||
self = [super init];
|
||||
if (self)
|
||||
collection = aCollection;
|
||||
return self;
|
||||
}
|
||||
|
||||
- (BOOL)matches:(id)item
|
||||
{
|
||||
return [collection containsObject:item];
|
||||
}
|
||||
|
||||
- (void)describeTo:(id<HCDescription>)description
|
||||
{
|
||||
[description appendText:@"one of "];
|
||||
[description appendList:collection start:@"{" separator:@", " end:@"}"];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
|
||||
#pragma mark -
|
||||
|
||||
id<HCMatcher> HC_isIn(id aCollection)
|
||||
{
|
||||
return [HCIsIn isInCollection:aCollection];
|
||||
}
|
||||
+50
@@ -0,0 +1,50 @@
|
||||
//
|
||||
// OCHamcrest - HCDescribedAs.h
|
||||
// Copyright 2012 hamcrest.org. See LICENSE.txt
|
||||
//
|
||||
// Created by: Jon Reid, http://qualitycoding.org/
|
||||
// Docs: http://hamcrest.github.com/OCHamcrest/
|
||||
// Source: https://github.com/hamcrest/OCHamcrest
|
||||
//
|
||||
|
||||
#import <OCHamcrest/HCBaseMatcher.h>
|
||||
|
||||
|
||||
@interface HCDescribedAs : HCBaseMatcher
|
||||
{
|
||||
NSString *descriptionTemplate;
|
||||
id<HCMatcher> matcher;
|
||||
NSArray *values;
|
||||
}
|
||||
|
||||
+ (id)describedAs:(NSString *)description
|
||||
forMatcher:(id<HCMatcher>)aMatcher
|
||||
overValues:(NSArray *)templateValues;
|
||||
|
||||
- (id)initWithDescription:(NSString *)description
|
||||
forMatcher:(id<HCMatcher>)aMatcher
|
||||
overValues:(NSArray *)templateValues;
|
||||
|
||||
@end
|
||||
|
||||
|
||||
OBJC_EXPORT id<HCMatcher> HC_describedAs(NSString *description, id<HCMatcher> matcher, ...) NS_REQUIRES_NIL_TERMINATION;
|
||||
|
||||
/**
|
||||
describedAs(description, matcher, ...) -
|
||||
Adds custom failure description to a given matcher.
|
||||
|
||||
@param description Overrides the matcher's description.
|
||||
@param matcher,... The matcher to satisfy, followed by a comma-separated list of substitution values ending with @c nil.
|
||||
|
||||
The description may contain substitution placeholders \%0, \%1, etc. These will be replaced by
|
||||
any values that follow the matcher.
|
||||
|
||||
(In the event of a name clash, don't \#define @c HC_SHORTHAND and use the synonym
|
||||
@c HC_describedAs instead.)
|
||||
|
||||
@ingroup decorator_matchers
|
||||
*/
|
||||
#ifdef HC_SHORTHAND
|
||||
#define describedAs HC_describedAs
|
||||
#endif
|
||||
+130
@@ -0,0 +1,130 @@
|
||||
//
|
||||
// OCHamcrest - HCDescribedAs.m
|
||||
// Copyright 2012 hamcrest.org. See LICENSE.txt
|
||||
//
|
||||
// Created by: Jon Reid, http://qualitycoding.org/
|
||||
// Docs: http://hamcrest.github.com/OCHamcrest/
|
||||
// Source: https://github.com/hamcrest/OCHamcrest
|
||||
//
|
||||
|
||||
#import "HCDescribedAs.h"
|
||||
|
||||
#import "HCDescription.h"
|
||||
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int first;
|
||||
__unsafe_unretained NSString *second;
|
||||
} HCPairIntNSString;
|
||||
|
||||
|
||||
/**
|
||||
Splits string into decimal number (-1 if not found) and remaining string.
|
||||
*/
|
||||
static HCPairIntNSString separate(NSString *component)
|
||||
{
|
||||
int index = 0;
|
||||
bool gotIndex = false;
|
||||
|
||||
NSUInteger length = [component length];
|
||||
NSUInteger charIndex;
|
||||
for (charIndex = 0; charIndex < length; ++charIndex)
|
||||
{
|
||||
unichar character = [component characterAtIndex:charIndex];
|
||||
if (!isdigit(character))
|
||||
break;
|
||||
index = index * 10 + character - '0';
|
||||
gotIndex = true;
|
||||
}
|
||||
|
||||
if (!gotIndex)
|
||||
return (HCPairIntNSString){ -1, component };
|
||||
else
|
||||
return (HCPairIntNSString){ index, [component substringFromIndex:charIndex] };
|
||||
}
|
||||
|
||||
|
||||
#pragma mark -
|
||||
|
||||
@implementation HCDescribedAs
|
||||
|
||||
+ (id)describedAs:(NSString *)description
|
||||
forMatcher:(id<HCMatcher>)aMatcher
|
||||
overValues:(NSArray *)templateValues
|
||||
{
|
||||
return [[self alloc] initWithDescription:description
|
||||
forMatcher:aMatcher
|
||||
overValues:templateValues];
|
||||
}
|
||||
|
||||
- (id)initWithDescription:(NSString *)description
|
||||
forMatcher:(id<HCMatcher>)aMatcher
|
||||
overValues:(NSArray *)templateValues
|
||||
{
|
||||
self = [super init];
|
||||
if (self)
|
||||
{
|
||||
descriptionTemplate = [description copy];
|
||||
matcher = aMatcher;
|
||||
values = templateValues;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (BOOL)matches:(id)item
|
||||
{
|
||||
return [matcher matches:item];
|
||||
}
|
||||
|
||||
- (void)describeMismatchOf:(id)item to:(id<HCDescription>)mismatchDescription
|
||||
{
|
||||
[matcher describeMismatchOf:item to:mismatchDescription];
|
||||
}
|
||||
|
||||
- (void)describeTo:(id<HCDescription>)description
|
||||
{
|
||||
NSArray *components = [descriptionTemplate componentsSeparatedByString:@"%"];
|
||||
bool firstTime = true;
|
||||
for (NSString *oneComponent in components)
|
||||
{
|
||||
if (firstTime)
|
||||
{
|
||||
firstTime = false;
|
||||
[description appendText:oneComponent];
|
||||
}
|
||||
else
|
||||
{
|
||||
HCPairIntNSString parseIndex = separate(oneComponent);
|
||||
if (parseIndex.first < 0)
|
||||
[[description appendText:@"%"] appendText:oneComponent];
|
||||
else
|
||||
{
|
||||
[description appendDescriptionOf:values[(NSUInteger)parseIndex.first]];
|
||||
[description appendText:parseIndex.second];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
|
||||
#pragma mark -
|
||||
|
||||
id<HCMatcher> HC_describedAs(NSString *description, id<HCMatcher> matcher, ...)
|
||||
{
|
||||
NSMutableArray *valueList = [NSMutableArray array];
|
||||
|
||||
va_list args;
|
||||
va_start(args, matcher);
|
||||
id value = va_arg(args, id);
|
||||
while (value != nil)
|
||||
{
|
||||
[valueList addObject:value];
|
||||
value = va_arg(args, id);
|
||||
}
|
||||
va_end(args);
|
||||
|
||||
return [HCDescribedAs describedAs:description forMatcher:matcher overValues:valueList];
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
//
|
||||
// OCHamcrest - HCIs.h
|
||||
// Copyright 2012 hamcrest.org. See LICENSE.txt
|
||||
//
|
||||
// Created by: Jon Reid, http://qualitycoding.org/
|
||||
// Docs: http://hamcrest.github.com/OCHamcrest/
|
||||
// Source: https://github.com/hamcrest/OCHamcrest
|
||||
//
|
||||
|
||||
#import <OCHamcrest/HCBaseMatcher.h>
|
||||
|
||||
|
||||
@interface HCIs : HCBaseMatcher
|
||||
{
|
||||
id<HCMatcher> matcher;
|
||||
}
|
||||
|
||||
+ (id)is:(id<HCMatcher>)aMatcher;
|
||||
- (id)initWithMatcher:(id<HCMatcher>)aMatcher;
|
||||
|
||||
@end
|
||||
|
||||
|
||||
OBJC_EXPORT id<HCMatcher> HC_is(id match);
|
||||
|
||||
/**
|
||||
is(aMatcher) -
|
||||
Decorates another matcher, or provides a shortcut to the frequently used @ref is(equalTo(x)).
|
||||
|
||||
@param aMatcher The matcher to satisfy, or an expected value for @ref equalTo matching.
|
||||
|
||||
This matcher compares the evaluated object to the given matcher.
|
||||
|
||||
If the @a aMatcher argument is a matcher, its behavior is retained, but the test may be more
|
||||
expressive. For example:
|
||||
@li <code>@ref assertThatInt(value, equalToInt(5))</code>
|
||||
@li <code>@ref assertThatInt(value, is(equalToInt(5)))</code>
|
||||
|
||||
If the @a aMatcher argument is not a matcher, it is wrapped in an @ref equalTo matcher. This
|
||||
makes the following statements equivalent:
|
||||
@li <code>@ref assertThat(cheese, equalTo(smelly))</code>
|
||||
@li <code>@ref assertThat(cheese, is(equalTo(smelly)))</code>
|
||||
@li <code>@ref assertThat(cheese, is(smelly))</code>
|
||||
|
||||
Choose the style that makes your expression most readable. This will vary depending on context.
|
||||
|
||||
(In the event of a name clash, don't \#define @c HC_SHORTHAND and use the synonym
|
||||
@c HC_is instead.)
|
||||
|
||||
@ingroup decorator_matchers
|
||||
*/
|
||||
#ifdef HC_SHORTHAND
|
||||
#define is HC_is
|
||||
#endif
|
||||
@@ -0,0 +1,54 @@
|
||||
//
|
||||
// OCHamcrest - HCIs.m
|
||||
// Copyright 2012 hamcrest.org. See LICENSE.txt
|
||||
//
|
||||
// Created by: Jon Reid, http://qualitycoding.org/
|
||||
// Docs: http://hamcrest.github.com/OCHamcrest/
|
||||
// Source: https://github.com/hamcrest/OCHamcrest
|
||||
//
|
||||
|
||||
#import "HCIs.h"
|
||||
|
||||
#import "HCDescription.h"
|
||||
#import "HCWrapInMatcher.h"
|
||||
|
||||
|
||||
@implementation HCIs
|
||||
|
||||
+ (id)is:(id<HCMatcher>)aMatcher
|
||||
{
|
||||
return [[self alloc] initWithMatcher:aMatcher];
|
||||
}
|
||||
|
||||
- (id)initWithMatcher:(id<HCMatcher>)aMatcher
|
||||
{
|
||||
self = [super init];
|
||||
if (self)
|
||||
matcher = aMatcher;
|
||||
return self;
|
||||
}
|
||||
|
||||
- (BOOL)matches:(id)item
|
||||
{
|
||||
return [matcher matches:item];
|
||||
}
|
||||
|
||||
- (void)describeMismatchOf:(id)item to:(id<HCDescription>)mismatchDescription
|
||||
{
|
||||
[matcher describeMismatchOf:item to:mismatchDescription];
|
||||
}
|
||||
|
||||
- (void)describeTo:(id<HCDescription>)description
|
||||
{
|
||||
[description appendDescriptionOf:matcher];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
|
||||
#pragma mark -
|
||||
|
||||
id<HCMatcher> HC_is(id match)
|
||||
{
|
||||
return [HCIs is:HCWrapInMatcher(match)];
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
//
|
||||
// OCHamcrest - HCAllOf.h
|
||||
// Copyright 2012 hamcrest.org. See LICENSE.txt
|
||||
//
|
||||
// Created by: Jon Reid, http://qualitycoding.org/
|
||||
// Docs: http://hamcrest.github.com/OCHamcrest/
|
||||
// Source: https://github.com/hamcrest/OCHamcrest
|
||||
//
|
||||
|
||||
#import <OCHamcrest/HCBaseMatcher.h>
|
||||
|
||||
|
||||
@interface HCAllOf : HCBaseMatcher
|
||||
{
|
||||
NSArray *matchers;
|
||||
}
|
||||
|
||||
+ (id)allOf:(NSArray *)theMatchers;
|
||||
- (id)initWithMatchers:(NSArray *)theMatchers;
|
||||
|
||||
@end
|
||||
|
||||
|
||||
OBJC_EXPORT id<HCMatcher> HC_allOf(id match, ...) NS_REQUIRES_NIL_TERMINATION;
|
||||
|
||||
/**
|
||||
allOf(firstMatcher, ...) -
|
||||
Matches if all of the given matchers evaluate to @c YES.
|
||||
|
||||
@param firstMatcher,... A comma-separated list of matchers ending with @c nil.
|
||||
|
||||
The matchers are evaluated from left to right using short-circuit evaluation, so evaluation
|
||||
stops as soon as a matcher returns @c NO.
|
||||
|
||||
Any argument that is not a matcher is implicitly wrapped in an @ref equalTo matcher to check for
|
||||
equality.
|
||||
|
||||
(In the event of a name clash, don't \#define @c HC_SHORTHAND and use the synonym
|
||||
@c HC_allOf instead.)
|
||||
|
||||
@ingroup logical_matchers
|
||||
*/
|
||||
#ifdef HC_SHORTHAND
|
||||
#define allOf HC_allOf
|
||||
#endif
|
||||
@@ -0,0 +1,73 @@
|
||||
//
|
||||
// OCHamcrest - HCAllOf.m
|
||||
// Copyright 2012 hamcrest.org. See LICENSE.txt
|
||||
//
|
||||
// Created by: Jon Reid, http://qualitycoding.org/
|
||||
// Docs: http://hamcrest.github.com/OCHamcrest/
|
||||
// Source: https://github.com/hamcrest/OCHamcrest
|
||||
//
|
||||
|
||||
#import "HCAllOf.h"
|
||||
|
||||
#import "HCCollectMatchers.h"
|
||||
#import "HCDescription.h"
|
||||
|
||||
|
||||
@implementation HCAllOf
|
||||
|
||||
+ (id)allOf:(NSArray *)theMatchers
|
||||
{
|
||||
return [[self alloc] initWithMatchers:theMatchers];
|
||||
}
|
||||
|
||||
- (id)initWithMatchers:(NSArray *)theMatchers
|
||||
{
|
||||
self = [super init];
|
||||
if (self)
|
||||
matchers = theMatchers;
|
||||
return self;
|
||||
}
|
||||
|
||||
- (BOOL)matches:(id)item
|
||||
{
|
||||
return [self matches:item describingMismatchTo:nil];
|
||||
}
|
||||
|
||||
- (BOOL)matches:(id)item describingMismatchTo:(id<HCDescription>)mismatchDescription
|
||||
{
|
||||
for (id<HCMatcher> oneMatcher in matchers)
|
||||
{
|
||||
if (![oneMatcher matches:item])
|
||||
{
|
||||
[[mismatchDescription appendDescriptionOf:oneMatcher] appendText:@" "];
|
||||
[oneMatcher describeMismatchOf:item to:mismatchDescription];
|
||||
return NO;
|
||||
}
|
||||
}
|
||||
return YES;
|
||||
}
|
||||
|
||||
- (void)describeMismatchOf:(id)item to:(id<HCDescription>)mismatchDescription
|
||||
{
|
||||
[self matches:item describingMismatchTo:mismatchDescription];
|
||||
}
|
||||
|
||||
- (void)describeTo:(id<HCDescription>)description
|
||||
{
|
||||
[description appendList:matchers start:@"(" separator:@" and " end:@")"];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
|
||||
#pragma mark -
|
||||
|
||||
id<HCMatcher> HC_allOf(id match, ...)
|
||||
{
|
||||
va_list args;
|
||||
va_start(args, match);
|
||||
NSArray *matcherList = HCCollectMatchers(match, args);
|
||||
va_end(args);
|
||||
|
||||
return [HCAllOf allOf:matcherList];
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
//
|
||||
// OCHamcrest - HCAnyOf.h
|
||||
// Copyright 2012 hamcrest.org. See LICENSE.txt
|
||||
//
|
||||
// Created by: Jon Reid, http://qualitycoding.org/
|
||||
// Docs: http://hamcrest.github.com/OCHamcrest/
|
||||
// Source: https://github.com/hamcrest/OCHamcrest
|
||||
//
|
||||
|
||||
#import <OCHamcrest/HCBaseMatcher.h>
|
||||
|
||||
|
||||
@interface HCAnyOf : HCBaseMatcher
|
||||
{
|
||||
NSArray *matchers;
|
||||
}
|
||||
|
||||
+ (id)anyOf:(NSArray *)theMatchers;
|
||||
- (id)initWithMatchers:(NSArray *)theMatchers;
|
||||
|
||||
@end
|
||||
|
||||
|
||||
OBJC_EXPORT id<HCMatcher> HC_anyOf(id match, ...) NS_REQUIRES_NIL_TERMINATION;
|
||||
|
||||
/**
|
||||
anyOf(firstMatcher, ...) -
|
||||
Matches if any of the given matchers evaluate to @c YES.
|
||||
|
||||
@param firstMatcher,... A comma-separated list of matchers ending with @c nil.
|
||||
|
||||
The matchers are evaluated from left to right using short-circuit evaluation, so evaluation
|
||||
stops as soon as a matcher returns @c YES.
|
||||
|
||||
Any argument that is not a matcher is implicitly wrapped in an @ref equalTo matcher to check for
|
||||
equality.
|
||||
|
||||
(In the event of a name clash, don't \#define @c HC_SHORTHAND and use the synonym
|
||||
@c HC_anyOf instead.)
|
||||
|
||||
@ingroup logical_matchers
|
||||
*/
|
||||
#ifdef HC_SHORTHAND
|
||||
#define anyOf HC_anyOf
|
||||
#endif
|
||||
@@ -0,0 +1,57 @@
|
||||
//
|
||||
// OCHamcrest - HCAnyOf.m
|
||||
// Copyright 2012 hamcrest.org. See LICENSE.txt
|
||||
//
|
||||
// Created by: Jon Reid, http://qualitycoding.org/
|
||||
// Docs: http://hamcrest.github.com/OCHamcrest/
|
||||
// Source: https://github.com/hamcrest/OCHamcrest
|
||||
//
|
||||
|
||||
#import "HCAnyOf.h"
|
||||
|
||||
#import "HCCollectMatchers.h"
|
||||
#import "HCDescription.h"
|
||||
|
||||
|
||||
@implementation HCAnyOf
|
||||
|
||||
+ (id)anyOf:(NSArray *)theMatchers
|
||||
{
|
||||
return [[self alloc] initWithMatchers:theMatchers];
|
||||
}
|
||||
|
||||
- (id)initWithMatchers:(NSArray *)theMatchers
|
||||
{
|
||||
self = [super init];
|
||||
if (self)
|
||||
matchers = theMatchers;
|
||||
return self;
|
||||
}
|
||||
|
||||
- (BOOL)matches:(id)item
|
||||
{
|
||||
for (id<HCMatcher> oneMatcher in matchers)
|
||||
if ([oneMatcher matches:item])
|
||||
return YES;
|
||||
return NO;
|
||||
}
|
||||
|
||||
- (void)describeTo:(id<HCDescription>)description
|
||||
{
|
||||
[description appendList:matchers start:@"(" separator:@" or " end:@")"];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
|
||||
#pragma mark -
|
||||
|
||||
id<HCMatcher> HC_anyOf(id match, ...)
|
||||
{
|
||||
va_list args;
|
||||
va_start(args, match);
|
||||
NSArray *matcherList = HCCollectMatchers(match, args);
|
||||
va_end(args);
|
||||
|
||||
return [HCAnyOf anyOf:matcherList];
|
||||
}
|
||||
+63
@@ -0,0 +1,63 @@
|
||||
//
|
||||
// OCHamcrest - HCIsAnything.h
|
||||
// Copyright 2012 hamcrest.org. See LICENSE.txt
|
||||
//
|
||||
// Created by: Jon Reid, http://qualitycoding.org/
|
||||
// Docs: http://hamcrest.github.com/OCHamcrest/
|
||||
// Source: https://github.com/hamcrest/OCHamcrest
|
||||
//
|
||||
|
||||
#import <OCHamcrest/HCBaseMatcher.h>
|
||||
|
||||
|
||||
@interface HCIsAnything : HCBaseMatcher
|
||||
{
|
||||
NSString *description;
|
||||
}
|
||||
|
||||
+ (id)isAnything;
|
||||
+ (id)isAnythingWithDescription:(NSString *)aDescription;
|
||||
|
||||
- (id)init;
|
||||
- (id)initWithDescription:(NSString *)aDescription;
|
||||
|
||||
@end
|
||||
|
||||
|
||||
OBJC_EXPORT id<HCMatcher> HC_anything(void);
|
||||
|
||||
/**
|
||||
Matches anything.
|
||||
|
||||
This matcher always evaluates to @c YES. Specify this in composite matchers when the value of a
|
||||
particular element is unimportant.
|
||||
|
||||
(In the event of a name clash, don't \#define @c HC_SHORTHAND and use the synonym
|
||||
@c HC_anything instead.)
|
||||
|
||||
@ingroup logical_matchers
|
||||
*/
|
||||
#ifdef HC_SHORTHAND
|
||||
#define anything() HC_anything()
|
||||
#endif
|
||||
|
||||
|
||||
OBJC_EXPORT id<HCMatcher> HC_anythingWithDescription(NSString *aDescription);
|
||||
|
||||
/**
|
||||
anythingWithDescription(description) -
|
||||
Matches anything.
|
||||
|
||||
@param description A string used to describe this matcher.
|
||||
|
||||
This matcher always evaluates to @c YES. Specify this in collection matchers when the value of a
|
||||
particular element in a collection is unimportant.
|
||||
|
||||
(In the event of a name clash, don't \#define @c HC_SHORTHAND and use the synonym
|
||||
@c HC_anything instead.)
|
||||
|
||||
@ingroup logical_matchers
|
||||
*/
|
||||
#ifdef HC_SHORTHAND
|
||||
#define anythingWithDescription HC_anythingWithDescription
|
||||
#endif
|
||||
+64
@@ -0,0 +1,64 @@
|
||||
//
|
||||
// OCHamcrest - HCIsAnything.m
|
||||
// Copyright 2012 hamcrest.org. See LICENSE.txt
|
||||
//
|
||||
// Created by: Jon Reid, http://qualitycoding.org/
|
||||
// Docs: http://hamcrest.github.com/OCHamcrest/
|
||||
// Source: https://github.com/hamcrest/OCHamcrest
|
||||
//
|
||||
|
||||
#import "HCIsAnything.h"
|
||||
|
||||
#import "HCDescription.h"
|
||||
|
||||
|
||||
@implementation HCIsAnything
|
||||
|
||||
+ (id)isAnything
|
||||
{
|
||||
return [[self alloc] init];
|
||||
}
|
||||
|
||||
+ (id)isAnythingWithDescription:(NSString *)aDescription
|
||||
{
|
||||
return [[self alloc] initWithDescription:aDescription];
|
||||
}
|
||||
|
||||
- (id)init
|
||||
{
|
||||
self = [self initWithDescription:@"ANYTHING"];
|
||||
return self;
|
||||
}
|
||||
|
||||
- (id)initWithDescription:(NSString *)aDescription
|
||||
{
|
||||
self = [super init];
|
||||
if (self)
|
||||
description = [aDescription copy];
|
||||
return self;
|
||||
}
|
||||
|
||||
- (BOOL)matches:(id)item
|
||||
{
|
||||
return YES;
|
||||
}
|
||||
|
||||
- (void)describeTo:(id<HCDescription>)aDescription
|
||||
{
|
||||
[aDescription appendText:description];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
|
||||
#pragma mark -
|
||||
|
||||
id<HCMatcher> HC_anything()
|
||||
{
|
||||
return [HCIsAnything isAnything];
|
||||
}
|
||||
|
||||
id<HCMatcher> HC_anythingWithDescription(NSString *description)
|
||||
{
|
||||
return [HCIsAnything isAnythingWithDescription:description];
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
//
|
||||
// OCHamcrest - HCIsNot.h
|
||||
// Copyright 2012 hamcrest.org. See LICENSE.txt
|
||||
//
|
||||
// Created by: Jon Reid, http://qualitycoding.org/
|
||||
// Docs: http://hamcrest.github.com/OCHamcrest/
|
||||
// Source: https://github.com/hamcrest/OCHamcrest
|
||||
//
|
||||
|
||||
#import <OCHamcrest/HCBaseMatcher.h>
|
||||
|
||||
|
||||
@interface HCIsNot : HCBaseMatcher
|
||||
{
|
||||
id<HCMatcher> matcher;
|
||||
}
|
||||
|
||||
+ (id)isNot:(id<HCMatcher>)aMatcher;
|
||||
- (id)initNot:(id<HCMatcher>)aMatcher;
|
||||
|
||||
@end
|
||||
|
||||
|
||||
OBJC_EXPORT id<HCMatcher> HC_isNot(id aMatcher);
|
||||
|
||||
/**
|
||||
isNot(aMatcher) -
|
||||
Inverts the given matcher to its logical negation.
|
||||
|
||||
@param aMatcher The matcher to negate.
|
||||
|
||||
This matcher compares the evaluated object to the negation of the given matcher. If the
|
||||
@a aMatcher argument is not a matcher, it is implicitly wrapped in an @ref equalTo matcher to
|
||||
check for equality, and thus matches for inequality.
|
||||
|
||||
Examples:
|
||||
@li <code>@ref assertThat(cheese, isNot(equalTo(smelly)))</code>
|
||||
@li <code>@ref assertThat(cheese, isNot(smelly))</code>
|
||||
|
||||
(In the event of a name clash, don't \#define @c HC_SHORTHAND and use the synonym
|
||||
@c HC_isNot instead.)
|
||||
|
||||
@ingroup logical_matchers
|
||||
*/
|
||||
#ifdef HC_SHORTHAND
|
||||
#define isNot HC_isNot
|
||||
#endif
|
||||
@@ -0,0 +1,49 @@
|
||||
//
|
||||
// OCHamcrest - HCIsNot.m
|
||||
// Copyright 2012 hamcrest.org. See LICENSE.txt
|
||||
//
|
||||
// Created by: Jon Reid, http://qualitycoding.org/
|
||||
// Docs: http://hamcrest.github.com/OCHamcrest/
|
||||
// Source: https://github.com/hamcrest/OCHamcrest
|
||||
//
|
||||
|
||||
#import "HCIsNot.h"
|
||||
|
||||
#import "HCDescription.h"
|
||||
#import "HCWrapInMatcher.h"
|
||||
|
||||
|
||||
@implementation HCIsNot
|
||||
|
||||
+ (id)isNot:(id<HCMatcher>)aMatcher
|
||||
{
|
||||
return [[self alloc] initNot:aMatcher];
|
||||
}
|
||||
|
||||
- (id)initNot:(id<HCMatcher>)aMatcher
|
||||
{
|
||||
self = [super init];
|
||||
if (self)
|
||||
matcher = aMatcher;
|
||||
return self;
|
||||
}
|
||||
|
||||
- (BOOL)matches:(id)item
|
||||
{
|
||||
return ![matcher matches:item];
|
||||
}
|
||||
|
||||
- (void)describeTo:(id<HCDescription>)description
|
||||
{
|
||||
[[description appendText:@"not "] appendDescriptionOf:matcher];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
|
||||
#pragma mark -
|
||||
|
||||
id<HCMatcher> HC_isNot(id aMatcher)
|
||||
{
|
||||
return [HCIsNot isNot:HCWrapInMatcher(aMatcher)];
|
||||
}
|
||||
+95
@@ -0,0 +1,95 @@
|
||||
//
|
||||
// OCHamcrest - HCBoxNumber.h
|
||||
// Copyright 2012 hamcrest.org. See LICENSE.txt
|
||||
//
|
||||
// Created by: Jon Reid, http://qualitycoding.org/
|
||||
// Docs: http://hamcrest.github.com/OCHamcrest/
|
||||
// Source: https://github.com/hamcrest/OCHamcrest
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
namespace hamcrest {
|
||||
|
||||
/**
|
||||
Boxes a scalar value in an NSNumber, specialized per type.
|
||||
|
||||
@b Deprecated
|
||||
|
||||
@ingroup number_matchers
|
||||
*/
|
||||
template <typename T>
|
||||
inline
|
||||
NSNumber *boxNumber(T value) __attribute__((deprecated));
|
||||
{ return nil; }
|
||||
|
||||
template <>
|
||||
inline
|
||||
NSNumber *boxNumber(BOOL value)
|
||||
{ return [NSNumber numberWithBool:value]; }
|
||||
|
||||
template <>
|
||||
inline
|
||||
NSNumber *boxNumber(char value)
|
||||
{ return [NSNumber numberWithChar:value]; }
|
||||
|
||||
template <>
|
||||
inline
|
||||
NSNumber *boxNumber(double value)
|
||||
{ return [NSNumber numberWithDouble:value]; }
|
||||
|
||||
template <>
|
||||
inline
|
||||
NSNumber *boxNumber(float value)
|
||||
{ return [NSNumber numberWithFloat:value]; }
|
||||
|
||||
template <>
|
||||
inline
|
||||
NSNumber *boxNumber(int value)
|
||||
{ return [NSNumber numberWithInt:value]; }
|
||||
|
||||
template <>
|
||||
inline
|
||||
NSNumber *boxNumber(long value)
|
||||
{ return [NSNumber numberWithLong:value]; }
|
||||
|
||||
template <>
|
||||
inline
|
||||
NSNumber *boxNumber(long long value)
|
||||
{ return [NSNumber numberWithLongLong:value]; }
|
||||
|
||||
template <>
|
||||
inline
|
||||
NSNumber *boxNumber(short value)
|
||||
{ return [NSNumber numberWithShort:value]; }
|
||||
|
||||
template <>
|
||||
inline
|
||||
NSNumber *boxNumber(unsigned char value)
|
||||
{ return [NSNumber numberWithUnsignedChar:value]; }
|
||||
|
||||
template <>
|
||||
inline
|
||||
NSNumber *boxNumber(unsigned int value)
|
||||
{ return [NSNumber numberWithUnsignedInt:value]; }
|
||||
|
||||
template <>
|
||||
inline
|
||||
NSNumber *boxNumber(unsigned long value)
|
||||
{ return [NSNumber numberWithUnsignedLong:value]; }
|
||||
|
||||
template <>
|
||||
inline
|
||||
NSNumber *boxNumber(unsigned long long value)
|
||||
{ return [NSNumber numberWithUnsignedLongLong:value]; }
|
||||
|
||||
template <>
|
||||
inline
|
||||
NSNumber *boxNumber(unsigned short value)
|
||||
{ return [NSNumber numberWithUnsignedShort:value]; }
|
||||
|
||||
} // namespace hamcrest
|
||||
|
||||
#endif // __cplusplus
|
||||
+47
@@ -0,0 +1,47 @@
|
||||
//
|
||||
// OCHamcrest - HCIsCloseTo.h
|
||||
// Copyright 2012 hamcrest.org. See LICENSE.txt
|
||||
//
|
||||
// Created by: Jon Reid, http://qualitycoding.org/
|
||||
// Docs: http://hamcrest.github.com/OCHamcrest/
|
||||
// Source: https://github.com/hamcrest/OCHamcrest
|
||||
//
|
||||
|
||||
#import <OCHamcrest/HCBaseMatcher.h>
|
||||
|
||||
|
||||
@interface HCIsCloseTo : HCBaseMatcher
|
||||
{
|
||||
double value;
|
||||
double delta;
|
||||
}
|
||||
|
||||
+ (id)isCloseTo:(double)aValue within:(double)aDelta;
|
||||
- (id)initWithValue:(double)aValue delta:(double)aDelta;
|
||||
|
||||
@end
|
||||
|
||||
|
||||
OBJC_EXPORT id<HCMatcher> HC_closeTo(double aValue, double aDelta);
|
||||
|
||||
/**
|
||||
closeTo(aValue, aDelta) -
|
||||
Matches if object is a number close to a given value, within a given delta.
|
||||
|
||||
@param aValue The @c double value to compare against as the expected value.
|
||||
@param aDelta The @c double maximum delta between the values for which the numbers are considered close.
|
||||
|
||||
This matcher invokes @c -doubleValue on the evaluated object to get its value as a @c double.
|
||||
The result is compared against @a aValue to see if the difference is within a positive @a aDelta.
|
||||
|
||||
Example:
|
||||
@li @ref closeTo(3.0, 0.25)
|
||||
|
||||
(In the event of a name clash, don't \#define @c HC_SHORTHAND and use the synonym
|
||||
@c HC_closeTo instead.)
|
||||
|
||||
@ingroup number_matchers
|
||||
*/
|
||||
#ifdef HC_SHORTHAND
|
||||
#define closeTo HC_closeTo
|
||||
#endif
|
||||
+70
@@ -0,0 +1,70 @@
|
||||
//
|
||||
// OCHamcrest - HCIsCloseTo.m
|
||||
// Copyright 2012 hamcrest.org. See LICENSE.txt
|
||||
//
|
||||
// Created by: Jon Reid, http://qualitycoding.org/
|
||||
// Docs: http://hamcrest.github.com/OCHamcrest/
|
||||
// Source: https://github.com/hamcrest/OCHamcrest
|
||||
//
|
||||
|
||||
#import "HCIsCloseTo.h"
|
||||
|
||||
#import "HCDescription.h"
|
||||
|
||||
|
||||
@implementation HCIsCloseTo
|
||||
|
||||
+ (id)isCloseTo:(double)aValue within:(double)aDelta
|
||||
{
|
||||
return [[self alloc] initWithValue:aValue delta:aDelta];
|
||||
}
|
||||
|
||||
- (id)initWithValue:(double)aValue delta:(double)aDelta
|
||||
{
|
||||
self = [super init];
|
||||
if (self)
|
||||
{
|
||||
value = aValue;
|
||||
delta = aDelta;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (BOOL)matches:(id)item
|
||||
{
|
||||
if (![item isKindOfClass:[NSNumber class]])
|
||||
return NO;
|
||||
|
||||
return fabs([item doubleValue] - value) <= delta;
|
||||
}
|
||||
|
||||
- (void)describeMismatchOf:(id)item to:(id<HCDescription>)mismatchDescription
|
||||
{
|
||||
if (![item isKindOfClass:[NSNumber class]])
|
||||
[super describeMismatchOf:item to:mismatchDescription];
|
||||
else
|
||||
{
|
||||
double actualDelta = fabs([item doubleValue] - value);
|
||||
[[[mismatchDescription appendDescriptionOf:item]
|
||||
appendText:@" differed by "]
|
||||
appendDescriptionOf:@(actualDelta)];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)describeTo:(id<HCDescription>)description
|
||||
{
|
||||
[[[[description appendText:@"a numeric value within "]
|
||||
appendDescriptionOf:@(delta)]
|
||||
appendText:@" of "]
|
||||
appendDescriptionOf:@(value)];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
|
||||
#pragma mark -
|
||||
|
||||
id<HCMatcher> HC_closeTo(double value, double delta)
|
||||
{
|
||||
return [HCIsCloseTo isCloseTo:value within:delta];
|
||||
}
|
||||
+325
@@ -0,0 +1,325 @@
|
||||
//
|
||||
// OCHamcrest - HCIsEqualToNumber.h
|
||||
// Copyright 2012 hamcrest.org. See LICENSE.txt
|
||||
//
|
||||
// Created by: Jon Reid, http://qualitycoding.org/
|
||||
// Docs: http://hamcrest.github.com/OCHamcrest/
|
||||
// Source: https://github.com/hamcrest/OCHamcrest
|
||||
//
|
||||
|
||||
#import <OCHamcrest/HCBaseMatcher.h>
|
||||
|
||||
|
||||
OBJC_EXPORT id<HCMatcher> HC_equalToBool(BOOL value);
|
||||
|
||||
/**
|
||||
equalToBool(value) -
|
||||
Matches if object is equal to @c NSNumber created from a @c BOOL.
|
||||
|
||||
@param value The @c BOOL value from which to create an @c NSNumber.
|
||||
|
||||
This matcher creates an @c NSNumber object from a @c BOOL @a value and compares the evaluated
|
||||
object to it for equality.
|
||||
|
||||
(In the event of a name clash, don't \#define @c HC_SHORTHAND and use the synonym
|
||||
@c HC_equalToBool instead.)
|
||||
|
||||
@ingroup primitive_number_matchers
|
||||
*/
|
||||
#ifdef HC_SHORTHAND
|
||||
#define equalToBool HC_equalToBool
|
||||
#endif
|
||||
|
||||
|
||||
OBJC_EXPORT id<HCMatcher> HC_equalToChar(char value);
|
||||
|
||||
/**
|
||||
equalToChar(value) -
|
||||
Matches if object is equal to @c NSNumber created from a @c char.
|
||||
|
||||
@param value The @c char value from which to create an @c NSNumber.
|
||||
|
||||
This matcher creates an @c NSNumber object from a @c char @a value and compares the evaluated
|
||||
object to it for equality.
|
||||
|
||||
(In the event of a name clash, don't \#define @c HC_SHORTHAND and use the synonym
|
||||
@c HC_equalToChar instead.)
|
||||
|
||||
@ingroup primitive_number_matchers
|
||||
*/
|
||||
#ifdef HC_SHORTHAND
|
||||
#define equalToChar HC_equalToChar
|
||||
#endif
|
||||
|
||||
|
||||
OBJC_EXPORT id<HCMatcher> HC_equalToDouble(double value);
|
||||
|
||||
/**
|
||||
equalToDouble(value) -
|
||||
Matches if object is equal to @c NSNumber created from a @c double.
|
||||
|
||||
@param value The @c double value from which to create an @c NSNumber.
|
||||
|
||||
This matcher creates an @c NSNumber object from a @c double @a value and compares the evaluated
|
||||
object to it for equality.
|
||||
|
||||
(In the event of a name clash, don't \#define @c HC_SHORTHAND and use the synonym
|
||||
@c HC_equalToDouble instead.)
|
||||
|
||||
@ingroup primitive_number_matchers
|
||||
*/
|
||||
#ifdef HC_SHORTHAND
|
||||
#define equalToDouble HC_equalToDouble
|
||||
#endif
|
||||
|
||||
|
||||
OBJC_EXPORT id<HCMatcher> HC_equalToFloat(float value);
|
||||
|
||||
/**
|
||||
equalToFloat(value) -
|
||||
Matches if object is equal to @c NSNumber created from a @c float.
|
||||
|
||||
@param value The @c float value from which to create an @c NSNumber.
|
||||
|
||||
This matcher creates an @c NSNumber object from a @c float @a value and compares the evaluated
|
||||
object to it for equality.
|
||||
|
||||
(In the event of a name clash, don't \#define @c HC_SHORTHAND and use the synonym
|
||||
@c HC_equalToFloat instead.)
|
||||
|
||||
@ingroup primitive_number_matchers
|
||||
*/
|
||||
#ifdef HC_SHORTHAND
|
||||
#define equalToFloat HC_equalToFloat
|
||||
#endif
|
||||
|
||||
|
||||
OBJC_EXPORT id<HCMatcher> HC_equalToInt(int value);
|
||||
|
||||
/**
|
||||
equalToInt(value) -
|
||||
Matches if object is equal to @c NSNumber created from an @c int.
|
||||
|
||||
@param value The @c int value from which to create an @c NSNumber.
|
||||
|
||||
This matcher creates an @c NSNumber object from a @c int @a value and compares the evaluated
|
||||
object to it for equality.
|
||||
|
||||
(In the event of a name clash, don't \#define @c HC_SHORTHAND and use the synonym
|
||||
@c HC_equalToInt instead.)
|
||||
|
||||
@ingroup primitive_number_matchers
|
||||
*/
|
||||
#ifdef HC_SHORTHAND
|
||||
#define equalToInt HC_equalToInt
|
||||
#endif
|
||||
|
||||
|
||||
OBJC_EXPORT id<HCMatcher> HC_equalToLong(long value);
|
||||
|
||||
/**
|
||||
equalToLong(value) -
|
||||
Matches if object is equal to @c NSNumber created from a @c long.
|
||||
|
||||
@param value The @c long value from which to create an @c NSNumber.
|
||||
|
||||
This matcher creates an @c NSNumber object from a @c long @a value and compares the evaluated
|
||||
object to it for equality.
|
||||
|
||||
(In the event of a name clash, don't \#define @c HC_SHORTHAND and use the synonym
|
||||
@c HC_equalToLong instead.)
|
||||
|
||||
@ingroup primitive_number_matchers
|
||||
*/
|
||||
#ifdef HC_SHORTHAND
|
||||
#define equalToLong HC_equalToLong
|
||||
#endif
|
||||
|
||||
|
||||
OBJC_EXPORT id<HCMatcher> HC_equalToLongLong(long long value);
|
||||
|
||||
/**
|
||||
equalToLongLong(value) -
|
||||
Matches if object is equal to @c NSNumber created from a <code>long long</code>.
|
||||
|
||||
@param value The <code>long long</code> value from which to create an @c NSNumber.
|
||||
|
||||
This matcher creates an @c NSNumber object from a <code>long long</code> @a value and compares
|
||||
the evaluated object to it for equality.
|
||||
|
||||
(In the event of a name clash, don't \#define @c HC_SHORTHAND and use the synonym
|
||||
@c HC_equalToLongLong instead.)
|
||||
|
||||
@ingroup primitive_number_matchers
|
||||
*/
|
||||
#ifdef HC_SHORTHAND
|
||||
#define equalToLongLong HC_equalToLongLong
|
||||
#endif
|
||||
|
||||
|
||||
OBJC_EXPORT id<HCMatcher> HC_equalToShort(short value);
|
||||
|
||||
/**
|
||||
equalToShort(value) -
|
||||
Matches if object is equal to @c NSNumber created from a @c short.
|
||||
|
||||
@param value The @c short value from which to create an @c NSNumber.
|
||||
|
||||
This matcher creates an @c NSNumber object from a @c short @a value and compares the evaluated
|
||||
object to it for equality.
|
||||
|
||||
(In the event of a name clash, don't \#define @c HC_SHORTHAND and use the synonym
|
||||
@c HC_equalToShort instead.)
|
||||
|
||||
@ingroup primitive_number_matchers
|
||||
*/
|
||||
#ifdef HC_SHORTHAND
|
||||
#define equalToShort HC_equalToShort
|
||||
#endif
|
||||
|
||||
|
||||
OBJC_EXPORT id<HCMatcher> HC_equalToUnsignedChar(unsigned char value);
|
||||
|
||||
/**
|
||||
equalToUnsignedChar(value) -
|
||||
Matches if object is equal to @c NSNumber created from an <code>unsigned char</code>.
|
||||
|
||||
@param value The <code>unsigned char</code> value from which to create an @c NSNumber.
|
||||
|
||||
This matcher creates an @c NSNumber object from an <code>unsigned char</code> @a value and
|
||||
compares the evaluated object to it for equality.
|
||||
|
||||
(In the event of a name clash, don't \#define @c HC_SHORTHAND and use the synonym
|
||||
@c HC_equalToUnsignedChar instead.)
|
||||
|
||||
@ingroup primitive_number_matchers
|
||||
*/
|
||||
#ifdef HC_SHORTHAND
|
||||
#define equalToUnsignedChar HC_equalToUnsignedChar
|
||||
#endif
|
||||
|
||||
|
||||
OBJC_EXPORT id<HCMatcher> HC_equalToUnsignedInt(unsigned int value);
|
||||
|
||||
/**
|
||||
equalToUnsignedInt(value) -
|
||||
Matches if object is equal to @c NSNumber created from an <code>unsigned int</code>.
|
||||
|
||||
@param value The <code>unsigned int</code> value from which to create an @c NSNumber.
|
||||
|
||||
This matcher creates an @c NSNumber object from an <code>unsigned int</code> @a value and
|
||||
compares the evaluated object to it for equality.
|
||||
|
||||
(In the event of a name clash, don't \#define @c HC_SHORTHAND and use the synonym
|
||||
@c HC_equalToUnsignedInt instead.)
|
||||
|
||||
@ingroup primitive_number_matchers
|
||||
*/
|
||||
#ifdef HC_SHORTHAND
|
||||
#define equalToUnsignedInt HC_equalToUnsignedInt
|
||||
#endif
|
||||
|
||||
|
||||
OBJC_EXPORT id<HCMatcher> HC_equalToUnsignedLong(unsigned long value);
|
||||
|
||||
/**
|
||||
equalToUnsignedLong(value) -
|
||||
Matches if object is equal to @c NSNumber created from an <code>unsigned long</code>.
|
||||
|
||||
@param value The <code>unsigned long</code> value from which to create an @c NSNumber.
|
||||
|
||||
This matcher creates an @c NSNumber object from an <code>unsigned long</code> @a value and
|
||||
compares the evaluated object to it for equality.
|
||||
|
||||
(In the event of a name clash, don't \#define @c HC_SHORTHAND and use the synonym
|
||||
@c HC_equalToUnsignedLong instead.)
|
||||
|
||||
@ingroup primitive_number_matchers
|
||||
*/
|
||||
#ifdef HC_SHORTHAND
|
||||
#define equalToUnsignedLong HC_equalToUnsignedLong
|
||||
#endif
|
||||
|
||||
|
||||
OBJC_EXPORT id<HCMatcher> HC_equalToUnsignedLongLong(unsigned long long value);
|
||||
|
||||
/**
|
||||
equalToUnsignedLongLong(value) -
|
||||
Matches if object is equal to @c NSNumber created from an <code>unsigned long long</code>.
|
||||
|
||||
@param value The <code>unsigned long long</code> value from which to create an @c NSNumber.
|
||||
|
||||
This matcher creates an @c NSNumber object from an <code>unsigned long long</code> @a value and
|
||||
compares the evaluated object to it for equality.
|
||||
|
||||
(In the event of a name clash, don't \#define @c HC_SHORTHAND and use the synonym
|
||||
@c HC_equalToUnsignedLongLong instead.)
|
||||
|
||||
@ingroup primitive_number_matchers
|
||||
*/
|
||||
#ifdef HC_SHORTHAND
|
||||
#define equalToUnsignedLongLong HC_equalToUnsignedLongLong
|
||||
#endif
|
||||
|
||||
|
||||
OBJC_EXPORT id<HCMatcher> HC_equalToUnsignedShort(unsigned short value);
|
||||
|
||||
/**
|
||||
equalToUnsignedShort(value) -
|
||||
Matches if object is equal to @c NSNumber created from an <code>unsigned short</code>.
|
||||
|
||||
@param value The <code>unsigned short</code> value from which to create an @c NSNumber.
|
||||
|
||||
This matcher creates an @c NSNumber object from an <code>unsigned short</code> @a value and
|
||||
compares the evaluated object to it for equality.
|
||||
|
||||
(In the event of a name clash, don't \#define @c HC_SHORTHAND and use the synonym
|
||||
@c HC_equalToUnsignedShort instead.)
|
||||
|
||||
@ingroup primitive_number_matchers
|
||||
*/
|
||||
#ifdef HC_SHORTHAND
|
||||
#define equalToUnsignedShort HC_equalToUnsignedShort
|
||||
#endif
|
||||
|
||||
|
||||
OBJC_EXPORT id<HCMatcher> HC_equalToInteger(NSInteger value);
|
||||
|
||||
/**
|
||||
equalToInteger(value) -
|
||||
Matches if object is equal to @c NSNumber created from an @c NSInteger.
|
||||
|
||||
@param value The @c NSInteger value from which to create an @c NSNumber.
|
||||
|
||||
This matcher creates an @c NSNumber object from an @c NSInteger @a value and compares the
|
||||
evaluated object to it for equality.
|
||||
|
||||
(In the event of a name clash, don't \#define @c HC_SHORTHAND and use the synonym
|
||||
@c HC_equalToInteger instead.)
|
||||
|
||||
@ingroup primitive_number_matchers
|
||||
*/
|
||||
#ifdef HC_SHORTHAND
|
||||
#define equalToInteger HC_equalToInteger
|
||||
#endif
|
||||
|
||||
|
||||
OBJC_EXPORT id<HCMatcher> HC_equalToUnsignedInteger(NSUInteger value);
|
||||
|
||||
/**
|
||||
equalToUnsignedInteger(value) -
|
||||
Matches if object is equal to @c NSNumber created from an @c NSUInteger.
|
||||
|
||||
@param value The @c NSUInteger value from which to create an @c NSNumber.
|
||||
|
||||
This matcher creates an @c NSNumber object from an @c NSUInteger @a value and compares the
|
||||
evaluated object to it for equality.
|
||||
|
||||
(In the event of a name clash, don't \#define @c HC_SHORTHAND and use the synonym
|
||||
@c HC_equalToUnsignedInteger instead.)
|
||||
|
||||
@ingroup primitive_number_matchers
|
||||
*/
|
||||
#ifdef HC_SHORTHAND
|
||||
#define equalToUnsignedInteger HC_equalToUnsignedInteger
|
||||
#endif
|
||||
+35
@@ -0,0 +1,35 @@
|
||||
//
|
||||
// OCHamcrest - HCIsEqualToNumber.m
|
||||
// Copyright 2012 hamcrest.org. See LICENSE.txt
|
||||
//
|
||||
// Created by: Jon Reid, http://qualitycoding.org/
|
||||
// Docs: http://hamcrest.github.com/OCHamcrest/
|
||||
// Source: https://github.com/hamcrest/OCHamcrest
|
||||
//
|
||||
|
||||
#import "HCIsEqualToNumber.h"
|
||||
|
||||
#import "HCIsEqual.h"
|
||||
|
||||
|
||||
#define DEFINE_EQUAL_TO_NUMBER(name, type) \
|
||||
OBJC_EXPORT id<HCMatcher> HC_equalTo ## name(type value) \
|
||||
{ \
|
||||
return [HCIsEqual isEqualTo:[NSNumber numberWith ## name :value]]; \
|
||||
}
|
||||
|
||||
DEFINE_EQUAL_TO_NUMBER(Bool, BOOL)
|
||||
DEFINE_EQUAL_TO_NUMBER(Char, char)
|
||||
DEFINE_EQUAL_TO_NUMBER(Double, double)
|
||||
DEFINE_EQUAL_TO_NUMBER(Float, float)
|
||||
DEFINE_EQUAL_TO_NUMBER(Int, int)
|
||||
DEFINE_EQUAL_TO_NUMBER(Long, long)
|
||||
DEFINE_EQUAL_TO_NUMBER(LongLong, long long)
|
||||
DEFINE_EQUAL_TO_NUMBER(Short, short)
|
||||
DEFINE_EQUAL_TO_NUMBER(UnsignedChar, unsigned char)
|
||||
DEFINE_EQUAL_TO_NUMBER(UnsignedInt, unsigned int)
|
||||
DEFINE_EQUAL_TO_NUMBER(UnsignedLong, unsigned long)
|
||||
DEFINE_EQUAL_TO_NUMBER(UnsignedLongLong, unsigned long long)
|
||||
DEFINE_EQUAL_TO_NUMBER(UnsignedShort, unsigned short)
|
||||
DEFINE_EQUAL_TO_NUMBER(Integer, NSInteger)
|
||||
DEFINE_EQUAL_TO_NUMBER(UnsignedInteger, NSUInteger)
|
||||
+387
@@ -0,0 +1,387 @@
|
||||
//
|
||||
// OCHamcrest - HCNumberAssert.h
|
||||
// Copyright 2012 hamcrest.org. See LICENSE.txt
|
||||
//
|
||||
// Created by: Jon Reid, http://qualitycoding.org/
|
||||
// Docs: http://hamcrest.github.com/OCHamcrest/
|
||||
// Source: https://github.com/hamcrest/OCHamcrest
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
@protocol HCMatcher;
|
||||
|
||||
|
||||
OBJC_EXPORT void HC_assertThatBoolWithLocation(id testCase, BOOL actual,
|
||||
id<HCMatcher> matcher, const char* fileName, int lineNumber);
|
||||
|
||||
#define HC_assertThatBool(actual, matcher) \
|
||||
HC_assertThatBoolWithLocation(self, actual, matcher, __FILE__, __LINE__)
|
||||
|
||||
/**
|
||||
assertThatBool(actual, matcher) -
|
||||
Asserts that @c BOOL actual value, converted to an @c NSNumber, satisfies matcher.
|
||||
|
||||
@param actual The @c BOOL value to convert to an @c NSNumber for evaluation.
|
||||
@param matcher The matcher to satisfy as the expected condition.
|
||||
|
||||
(In the event of a name clash, don't \#define @c HC_SHORTHAND and use the synonym
|
||||
@c HC_assertThatBool instead.)
|
||||
|
||||
@ingroup integration_numeric
|
||||
*/
|
||||
#ifdef HC_SHORTHAND
|
||||
#define assertThatBool HC_assertThatBool
|
||||
#endif
|
||||
|
||||
|
||||
#pragma mark -
|
||||
|
||||
OBJC_EXPORT void HC_assertThatCharWithLocation(id testCase, char actual,
|
||||
id<HCMatcher> matcher, const char* fileName, int lineNumber);
|
||||
|
||||
#define HC_assertThatChar(actual, matcher) \
|
||||
HC_assertThatCharWithLocation(self, actual, matcher, __FILE__, __LINE__)
|
||||
|
||||
/**
|
||||
assertThatChar(actual, matcher) -
|
||||
Asserts that @c char actual value, converted to an @c NSNumber, satisfies matcher.
|
||||
|
||||
@param actual The @c char value to convert to an @c NSNumber for evaluation.
|
||||
@param matcher The matcher to satisfy as the expected condition.
|
||||
|
||||
(In the event of a name clash, don't \#define @c HC_SHORTHAND and use the synonym
|
||||
@c HC_assertThatChar instead.)
|
||||
|
||||
@ingroup integration_numeric
|
||||
*/
|
||||
#ifdef HC_SHORTHAND
|
||||
#define assertThatChar HC_assertThatChar
|
||||
#endif
|
||||
|
||||
|
||||
#pragma mark -
|
||||
|
||||
OBJC_EXPORT void HC_assertThatDoubleWithLocation(id testCase, double actual,
|
||||
id<HCMatcher> matcher, const char* fileName, int lineNumber);
|
||||
|
||||
#define HC_assertThatDouble(actual, matcher) \
|
||||
HC_assertThatDoubleWithLocation(self, actual, matcher, __FILE__, __LINE__)
|
||||
|
||||
/**
|
||||
HC_assertThatDouble(actual, matcher) -
|
||||
Asserts that @c double actual value, converted to an @c NSNumber, satisfies matcher.
|
||||
|
||||
@param actual The @c double value to convert to an @c NSNumber for evaluation.
|
||||
@param matcher The matcher to satisfy as the expected condition.
|
||||
|
||||
(In the event of a name clash, don't \#define @c HC_SHORTHAND and use the synonym
|
||||
@c HC_assertThatDouble instead.)
|
||||
|
||||
@ingroup integration_numeric
|
||||
*/
|
||||
#ifdef HC_SHORTHAND
|
||||
#define assertThatDouble HC_assertThatDouble
|
||||
#endif
|
||||
|
||||
|
||||
#pragma mark -
|
||||
|
||||
OBJC_EXPORT void HC_assertThatFloatWithLocation(id testCase, float actual,
|
||||
id<HCMatcher> matcher, const char* fileName, int lineNumber);
|
||||
|
||||
#define HC_assertThatFloat(actual, matcher) \
|
||||
HC_assertThatFloatWithLocation(self, actual, matcher, __FILE__, __LINE__)
|
||||
|
||||
/**
|
||||
assertThatFloat(actual, matcher) -
|
||||
Asserts that @c float actual value, converted to an @c NSNumber, satisfies matcher.
|
||||
|
||||
@param actual The @c float value to convert to an @c NSNumber for evaluation.
|
||||
@param matcher The matcher to satisfy as the expected condition.
|
||||
|
||||
(In the event of a name clash, don't \#define @c HC_SHORTHAND and use the synonym
|
||||
@c HC_assertThatFloat instead.)
|
||||
|
||||
@ingroup integration_numeric
|
||||
*/
|
||||
#ifdef HC_SHORTHAND
|
||||
#define assertThatFloat HC_assertThatFloat
|
||||
#endif
|
||||
|
||||
|
||||
#pragma mark -
|
||||
|
||||
OBJC_EXPORT void HC_assertThatIntWithLocation(id testCase, int actual,
|
||||
id<HCMatcher> matcher, const char* fileName, int lineNumber);
|
||||
|
||||
#define HC_assertThatInt(actual, matcher) \
|
||||
HC_assertThatIntWithLocation(self, actual, matcher, __FILE__, __LINE__)
|
||||
|
||||
/**
|
||||
assertThatInt(actual, matcher) -
|
||||
Asserts that @c int actual value, converted to an @c NSNumber, satisfies matcher.
|
||||
|
||||
@param actual The @c int value to convert to an @c NSNumber for evaluation.
|
||||
@param matcher The matcher to satisfy as the expected condition.
|
||||
|
||||
(In the event of a name clash, don't \#define @c HC_SHORTHAND and use the synonym
|
||||
@c HC_assertThatInt instead.)
|
||||
|
||||
@ingroup integration_numeric
|
||||
*/
|
||||
#ifdef HC_SHORTHAND
|
||||
#define assertThatInt HC_assertThatInt
|
||||
#endif
|
||||
|
||||
|
||||
#pragma mark -
|
||||
|
||||
OBJC_EXPORT void HC_assertThatLongWithLocation(id testCase, long actual,
|
||||
id<HCMatcher> matcher, const char* fileName, int lineNumber);
|
||||
|
||||
#define HC_assertThatLong(actual, matcher) \
|
||||
HC_assertThatLongWithLocation(self, actual, matcher, __FILE__, __LINE__)
|
||||
|
||||
/**
|
||||
assertThatLong(actual, matcher) -
|
||||
Asserts that @c long actual value, converted to an @c NSNumber, satisfies matcher.
|
||||
|
||||
@param actual The @c long value to convert to an @c NSNumber for evaluation.
|
||||
@param matcher The matcher to satisfy as the expected condition.
|
||||
|
||||
(In the event of a name clash, don't \#define @c HC_SHORTHAND and use the synonym
|
||||
@c HC_assertThatLong instead.)
|
||||
|
||||
@ingroup integration_numeric
|
||||
*/
|
||||
#ifdef HC_SHORTHAND
|
||||
#define assertThatLong HC_assertThatLong
|
||||
#endif
|
||||
|
||||
|
||||
#pragma mark -
|
||||
|
||||
OBJC_EXPORT void HC_assertThatLongLongWithLocation(id testCase, long long actual,
|
||||
id<HCMatcher> matcher, const char* fileName, int lineNumber);
|
||||
|
||||
#define HC_assertThatLongLong(actual, matcher) \
|
||||
HC_assertThatLongLongWithLocation(self, actual, matcher, __FILE__, __LINE__)
|
||||
|
||||
/**
|
||||
assertThatLongLong(actual, matcher) -
|
||||
Asserts that <code>long long</code> actual value, converted to an @c NSNumber, satisfies
|
||||
matcher.
|
||||
|
||||
@param actual The <code>long long</code> value to convert to an @c NSNumber for evaluation.
|
||||
@param matcher The matcher to satisfy as the expected condition.
|
||||
|
||||
(In the event of a name clash, don't \#define @c HC_SHORTHAND and use the synonym
|
||||
@c HC_assertThatLongLong instead.)
|
||||
|
||||
@ingroup integration_numeric
|
||||
*/
|
||||
#ifdef HC_SHORTHAND
|
||||
#define assertThatLongLong HC_assertThatLongLong
|
||||
#endif
|
||||
|
||||
|
||||
#pragma mark -
|
||||
|
||||
OBJC_EXPORT void HC_assertThatShortWithLocation(id testCase, short actual,
|
||||
id<HCMatcher> matcher, const char* fileName, int lineNumber);
|
||||
|
||||
#define HC_assertThatShort(actual, matcher) \
|
||||
HC_assertThatShortWithLocation(self, actual, matcher, __FILE__, __LINE__)
|
||||
|
||||
/**
|
||||
assertThatShort(actual, matcher) -
|
||||
Asserts that @c short actual value, converted to an @c NSNumber, satisfies matcher.
|
||||
|
||||
@param actual The @c short value to convert to an @c NSNumber for evaluation.
|
||||
@param matcher The matcher to satisfy as the expected condition.
|
||||
|
||||
(In the event of a name clash, don't \#define @c HC_SHORTHAND and use the synonym
|
||||
@c HC_assertThatShort instead.)
|
||||
|
||||
@ingroup integration_numeric
|
||||
*/
|
||||
#ifdef HC_SHORTHAND
|
||||
#define assertThatShort HC_assertThatShort
|
||||
#endif
|
||||
|
||||
|
||||
#pragma mark -
|
||||
|
||||
OBJC_EXPORT void HC_assertThatUnsignedCharWithLocation(id testCase, unsigned char actual,
|
||||
id<HCMatcher> matcher, const char* fileName, int lineNumber);
|
||||
|
||||
#define HC_assertThatUnsignedChar(actual, matcher) \
|
||||
HC_assertThatUnsignedCharWithLocation(self, actual, matcher, __FILE__, __LINE__)
|
||||
|
||||
/**
|
||||
assertThatUnsignedChar(actual, matcher) -
|
||||
Asserts that <code>unsigned char</code> actual value, converted to an @c NSNumber, satisfies
|
||||
matcher.
|
||||
|
||||
@param actual The <code>unsigned char</code> value to convert to an @c NSNumber for evaluation.
|
||||
@param matcher The matcher to satisfy as the expected condition.
|
||||
|
||||
(In the event of a name clash, don't \#define @c HC_SHORTHAND and use the synonym
|
||||
@c HC_assertThatUnsignedChar instead.)
|
||||
|
||||
@ingroup integration_numeric
|
||||
*/
|
||||
#ifdef HC_SHORTHAND
|
||||
#define assertThatUnsignedChar HC_assertThatUnsignedChar
|
||||
#endif
|
||||
|
||||
|
||||
#pragma mark -
|
||||
|
||||
OBJC_EXPORT void HC_assertThatUnsignedIntWithLocation(id testCase, unsigned int actual,
|
||||
id<HCMatcher> matcher, const char* fileName, int lineNumber);
|
||||
|
||||
#define HC_assertThatUnsignedInt(actual, matcher) \
|
||||
HC_assertThatUnsignedIntWithLocation(self, actual, matcher, __FILE__, __LINE__)
|
||||
|
||||
/**
|
||||
assertThatUnsignedInt(actual, matcher) -
|
||||
Asserts that <code>unsigned int</code> actual value, converted to an @c NSNumber, satisfies
|
||||
matcher.
|
||||
|
||||
@param actual The <code>unsigned int</code> value to convert to an @c NSNumber for evaluation @param matcher The matcher to satisfy as the expected condition.
|
||||
|
||||
(In the event of a name clash, don't \#define @c HC_SHORTHAND and use the synonym
|
||||
@c HC_assertThatUnsignedInt instead.)
|
||||
|
||||
@ingroup integration_numeric
|
||||
*/
|
||||
#ifdef HC_SHORTHAND
|
||||
#define assertThatUnsignedInt HC_assertThatUnsignedInt
|
||||
#endif
|
||||
|
||||
|
||||
#pragma mark -
|
||||
|
||||
OBJC_EXPORT void HC_assertThatUnsignedLongWithLocation(id testCase, unsigned long actual,
|
||||
id<HCMatcher> matcher, const char* fileName, int lineNumber);
|
||||
|
||||
#define HC_assertThatUnsignedLong(actual, matcher) \
|
||||
HC_assertThatUnsignedLongWithLocation(self, actual, matcher, __FILE__, __LINE__)
|
||||
|
||||
/**
|
||||
assertThatUnsignedLong(actual, matcher) -
|
||||
Asserts that <code>unsigned long</code> actual value, converted to an @c NSNumber, satisfies
|
||||
matcher.
|
||||
|
||||
@param actual The <code>unsigned long</code> value to convert to an @c NSNumber for evaluation @param matcher The matcher to satisfy as the expected condition.
|
||||
|
||||
(In the event of a name clash, don't \#define @c HC_SHORTHAND and use the synonym
|
||||
@c HC_assertThatUnsignedLong instead.)
|
||||
|
||||
@ingroup integration_numeric
|
||||
*/
|
||||
#ifdef HC_SHORTHAND
|
||||
#define assertThatUnsignedLong HC_assertThatUnsignedLong
|
||||
#endif
|
||||
|
||||
|
||||
#pragma mark -
|
||||
|
||||
OBJC_EXPORT void HC_assertThatUnsignedLongLongWithLocation(id testCase, unsigned long long actual,
|
||||
id<HCMatcher> matcher, const char* fileName, int lineNumber);
|
||||
|
||||
#define HC_assertThatUnsignedLongLong(actual, matcher) \
|
||||
HC_assertThatUnsignedLongLongWithLocation(self, actual, matcher, __FILE__, __LINE__)
|
||||
|
||||
/**
|
||||
assertThatUnsignedLongLong(actual, matcher) -
|
||||
Asserts that <code>unsigned long long</code> actual value, converted to an @c NSNumber,
|
||||
satisfies matcher.
|
||||
|
||||
@param actual The <code>unsigned long long</code> value to convert to an @c NSNumber for evaluation @param matcher The matcher to satisfy as the expected condition.
|
||||
|
||||
(In the event of a name clash, don't \#define @c HC_SHORTHAND and use the synonym
|
||||
@c HC_assertThatUnsignedLongLong instead.)
|
||||
|
||||
@ingroup integration_numeric
|
||||
*/
|
||||
#ifdef HC_SHORTHAND
|
||||
#define assertThatUnsignedLongLong HC_assertThatUnsignedLongLong
|
||||
#endif
|
||||
|
||||
|
||||
#pragma mark -
|
||||
|
||||
OBJC_EXPORT void HC_assertThatUnsignedShortWithLocation(id testCase, unsigned short actual,
|
||||
id<HCMatcher> matcher, const char* fileName, int lineNumber);
|
||||
|
||||
#define HC_assertThatUnsignedShort(actual, matcher) \
|
||||
HC_assertThatUnsignedShortWithLocation(self, actual, matcher, __FILE__, __LINE__)
|
||||
|
||||
/**
|
||||
assertThatUnsignedShort(actual, matcher) -
|
||||
Asserts that <code>unsigned short</code> actual value, converted to an @c NSNumber, satisfies
|
||||
matcher.
|
||||
|
||||
@param actual The <code>unsigned short</code> value to convert to an @c NSNumber for evaluation @param matcher The matcher to satisfy as the expected condition.
|
||||
|
||||
(In the event of a name clash, don't \#define @c HC_SHORTHAND and use the synonym
|
||||
@c HC_assertThatUnsignedShort instead.)
|
||||
|
||||
@ingroup integration_numeric
|
||||
*/
|
||||
#ifdef HC_SHORTHAND
|
||||
#define assertThatUnsignedShort HC_assertThatUnsignedShort
|
||||
#endif
|
||||
|
||||
|
||||
#pragma mark -
|
||||
|
||||
OBJC_EXPORT void HC_assertThatIntegerWithLocation(id testCase, NSInteger actual,
|
||||
id<HCMatcher> matcher, const char* fileName, int lineNumber);
|
||||
|
||||
#define HC_assertThatInteger(actual, matcher) \
|
||||
HC_assertThatIntegerWithLocation(self, actual, matcher, __FILE__, __LINE__)
|
||||
|
||||
/**
|
||||
assertThatInteger(actual, matcher) -
|
||||
Asserts that @c NSInteger actual value, converted to an @c NSNumber, satisfies matcher.
|
||||
|
||||
@param actual The @c NSInteger value to convert to an @c NSNumber for evaluation.
|
||||
@param matcher The matcher to satisfy as the expected condition.
|
||||
|
||||
(In the event of a name clash, don't \#define @c HC_SHORTHAND and use the synonym
|
||||
@c HC_assertThatInteger instead.)
|
||||
|
||||
@ingroup integration_numeric
|
||||
*/
|
||||
#ifdef HC_SHORTHAND
|
||||
#define assertThatInteger HC_assertThatInteger
|
||||
#endif
|
||||
|
||||
|
||||
#pragma mark -
|
||||
|
||||
OBJC_EXPORT void HC_assertThatUnsignedIntegerWithLocation(id testCase, NSUInteger actual,
|
||||
id<HCMatcher> matcher, const char* fileName, int lineNumber);
|
||||
|
||||
#define HC_assertThatUnsignedInteger(actual, matcher) \
|
||||
HC_assertThatUnsignedIntegerWithLocation(self, actual, matcher, __FILE__, __LINE__)
|
||||
|
||||
/**
|
||||
assertThatUnsignedInteger(actual, matcher) -
|
||||
Asserts that @c NSUInteger actual value, converted to an @c NSNumber, satisfies matcher.
|
||||
|
||||
@param actual The @c NSUInteger value to convert to an @c NSNumber for evaluation.
|
||||
@param matcher The matcher to satisfy as the expected condition.
|
||||
|
||||
(In the event of a name clash, don't \#define @c HC_SHORTHAND and use the synonym
|
||||
@c HC_assertThatUnsignedInteger instead.)
|
||||
|
||||
@ingroup integration_numeric
|
||||
*/
|
||||
#ifdef HC_SHORTHAND
|
||||
#define assertThatUnsignedInteger HC_assertThatUnsignedInteger
|
||||
#endif
|
||||
+36
@@ -0,0 +1,36 @@
|
||||
//
|
||||
// OCHamcrest - HCNumberAssert.m
|
||||
// Copyright 2012 hamcrest.org. See LICENSE.txt
|
||||
//
|
||||
// Created by: Jon Reid, http://qualitycoding.org/
|
||||
// Docs: http://hamcrest.github.com/OCHamcrest/
|
||||
// Source: https://github.com/hamcrest/OCHamcrest
|
||||
//
|
||||
|
||||
#import "HCNumberAssert.h"
|
||||
|
||||
#import "HCAssertThat.h"
|
||||
|
||||
|
||||
#define DEFINE_NUMBER_ASSERT(name, type) \
|
||||
OBJC_EXPORT void HC_assertThat ## name ## WithLocation(id testCase, type actual, id<HCMatcher> matcher, \
|
||||
const char* fileName, int lineNumber) \
|
||||
{ \
|
||||
HC_assertThatWithLocation(testCase, [NSNumber numberWith ## name :actual], matcher, fileName, lineNumber); \
|
||||
}
|
||||
|
||||
DEFINE_NUMBER_ASSERT(Bool, BOOL)
|
||||
DEFINE_NUMBER_ASSERT(Char, char)
|
||||
DEFINE_NUMBER_ASSERT(Double, double)
|
||||
DEFINE_NUMBER_ASSERT(Float, float)
|
||||
DEFINE_NUMBER_ASSERT(Int, int)
|
||||
DEFINE_NUMBER_ASSERT(Long, long)
|
||||
DEFINE_NUMBER_ASSERT(LongLong, long long)
|
||||
DEFINE_NUMBER_ASSERT(Short, short)
|
||||
DEFINE_NUMBER_ASSERT(UnsignedChar, unsigned char)
|
||||
DEFINE_NUMBER_ASSERT(UnsignedInt, unsigned int)
|
||||
DEFINE_NUMBER_ASSERT(UnsignedLong, unsigned long)
|
||||
DEFINE_NUMBER_ASSERT(UnsignedLongLong, unsigned long long)
|
||||
DEFINE_NUMBER_ASSERT(UnsignedShort, unsigned short)
|
||||
DEFINE_NUMBER_ASSERT(Integer, NSInteger)
|
||||
DEFINE_NUMBER_ASSERT(UnsignedInteger, NSUInteger)
|
||||
+115
@@ -0,0 +1,115 @@
|
||||
//
|
||||
// OCHamcrest - HCOrderingComparison.h
|
||||
// Copyright 2012 hamcrest.org. See LICENSE.txt
|
||||
//
|
||||
// Created by: Jon Reid, http://qualitycoding.org/
|
||||
// Docs: http://hamcrest.github.com/OCHamcrest/
|
||||
// Source: https://github.com/hamcrest/OCHamcrest
|
||||
//
|
||||
|
||||
#import <OCHamcrest/HCBaseMatcher.h>
|
||||
|
||||
|
||||
@interface HCOrderingComparison : HCBaseMatcher
|
||||
{
|
||||
id expected;
|
||||
NSComparisonResult minCompare;
|
||||
NSComparisonResult maxCompare;
|
||||
NSString *comparisonDescription;
|
||||
}
|
||||
|
||||
+ (id)compare:(id)expectedValue
|
||||
minCompare:(NSComparisonResult)min
|
||||
maxCompare:(NSComparisonResult)max
|
||||
comparisonDescription:(NSString *)comparisonDescription;
|
||||
|
||||
- (id)initComparing:(id)expectedValue
|
||||
minCompare:(NSComparisonResult)min
|
||||
maxCompare:(NSComparisonResult)max
|
||||
comparisonDescription:(NSString *)comparisonDescription;
|
||||
|
||||
@end
|
||||
|
||||
|
||||
OBJC_EXPORT id<HCMatcher> HC_greaterThan(id expected);
|
||||
|
||||
/**
|
||||
greaterThan(aNumber) -
|
||||
Matches if object is greater than a given number.
|
||||
|
||||
@param aNumber The @c NSNumber to compare against.
|
||||
|
||||
Example:
|
||||
@li @ref greaterThan(\@5)
|
||||
|
||||
(In the event of a name clash, don't \#define @c HC_SHORTHAND and use the synonym
|
||||
@c HC_greaterThan instead.)
|
||||
|
||||
@ingroup number_matchers
|
||||
*/
|
||||
#ifdef HC_SHORTHAND
|
||||
#define greaterThan HC_greaterThan
|
||||
#endif
|
||||
|
||||
|
||||
OBJC_EXPORT id<HCMatcher> HC_greaterThanOrEqualTo(id expected);
|
||||
|
||||
/**
|
||||
greaterThanOrEqualTo(aNumber) -
|
||||
Matches if object is greater than or equal to a given number.
|
||||
|
||||
@param aNumber The @c NSNumber to compare against.
|
||||
|
||||
Example:
|
||||
@li @ref greaterThanOrEqualTo(\@5)
|
||||
|
||||
(In the event of a name clash, don't \#define @c HC_SHORTHAND and use the synonym
|
||||
@c HC_greaterThanOrEqualTo instead.)
|
||||
|
||||
@ingroup number_matchers
|
||||
*/
|
||||
#ifdef HC_SHORTHAND
|
||||
#define greaterThanOrEqualTo HC_greaterThanOrEqualTo
|
||||
#endif
|
||||
|
||||
|
||||
OBJC_EXPORT id<HCMatcher> HC_lessThan(id expected);
|
||||
|
||||
/**
|
||||
lessThan(aNumber) -
|
||||
Matches if object is less than a given number.
|
||||
|
||||
@param aNumber The @c NSNumber to compare against.
|
||||
|
||||
Example:
|
||||
@li @ref lessThan(\@5)
|
||||
|
||||
(In the event of a name clash, don't \#define @c HC_SHORTHAND and use the synonym
|
||||
@c HC_lessThan instead.)
|
||||
|
||||
@ingroup number_matchers
|
||||
*/
|
||||
#ifdef HC_SHORTHAND
|
||||
#define lessThan HC_lessThan
|
||||
#endif
|
||||
|
||||
|
||||
OBJC_EXPORT id<HCMatcher> HC_lessThanOrEqualTo(id expected);
|
||||
|
||||
/**
|
||||
lessThanOrEqualTo(aNumber) -
|
||||
Matches if object is less than or equal to a given number.
|
||||
|
||||
@param aNumber The @c NSNumber to compare against.
|
||||
|
||||
Example:
|
||||
@li @ref lessThanOrEqualTo(\@5)
|
||||
|
||||
(In the event of a name clash, don't \#define @c HC_SHORTHAND and use the synonym
|
||||
@c HC_lessThanOrEqualTo instead.)
|
||||
|
||||
@ingroup number_matchers
|
||||
*/
|
||||
#ifdef HC_SHORTHAND
|
||||
#define lessThanOrEqualTo HC_lessThanOrEqualTo
|
||||
#endif
|
||||
+103
@@ -0,0 +1,103 @@
|
||||
//
|
||||
// OCHamcrest - HCOrderingComparison.m
|
||||
// Copyright 2012 hamcrest.org. See LICENSE.txt
|
||||
//
|
||||
// Created by: Jon Reid, http://qualitycoding.org/
|
||||
// Docs: http://hamcrest.github.com/OCHamcrest/
|
||||
// Source: https://github.com/hamcrest/OCHamcrest
|
||||
//
|
||||
|
||||
#import "HCOrderingComparison.h"
|
||||
|
||||
#import "HCDescription.h"
|
||||
|
||||
|
||||
@implementation HCOrderingComparison
|
||||
|
||||
+ (id)compare:(id)expectedValue
|
||||
minCompare:(NSComparisonResult)min
|
||||
maxCompare:(NSComparisonResult)max
|
||||
comparisonDescription:(NSString *)description
|
||||
{
|
||||
return [[self alloc] initComparing:expectedValue
|
||||
minCompare:min
|
||||
maxCompare:max
|
||||
comparisonDescription:description];
|
||||
}
|
||||
|
||||
- (id)initComparing:(id)expectedValue
|
||||
minCompare:(NSComparisonResult)min
|
||||
maxCompare:(NSComparisonResult)max
|
||||
comparisonDescription:(NSString *)description
|
||||
{
|
||||
if (![expectedValue respondsToSelector:@selector(compare:)])
|
||||
{
|
||||
@throw [NSException exceptionWithName: @"UncomparableObject"
|
||||
reason: @"Object must respond to compare:"
|
||||
userInfo: nil];
|
||||
}
|
||||
|
||||
self = [super init];
|
||||
if (self)
|
||||
{
|
||||
expected = expectedValue;
|
||||
minCompare = min;
|
||||
maxCompare = max;
|
||||
comparisonDescription = [description copy];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (BOOL)matches:(id)item
|
||||
{
|
||||
if (item == nil)
|
||||
return NO;
|
||||
|
||||
NSComparisonResult compare = [expected compare:item];
|
||||
return minCompare <= compare && compare <= maxCompare;
|
||||
}
|
||||
|
||||
- (void)describeTo:(id<HCDescription>)description
|
||||
{
|
||||
[[[[description appendText:@"a value "]
|
||||
appendText:comparisonDescription]
|
||||
appendText:@" "]
|
||||
appendDescriptionOf:expected];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
|
||||
#pragma mark -
|
||||
|
||||
id<HCMatcher> HC_greaterThan(id aValue)
|
||||
{
|
||||
return [HCOrderingComparison compare:aValue
|
||||
minCompare:NSOrderedAscending
|
||||
maxCompare:NSOrderedAscending
|
||||
comparisonDescription:@"greater than"];
|
||||
}
|
||||
|
||||
id<HCMatcher> HC_greaterThanOrEqualTo(id aValue)
|
||||
{
|
||||
return [HCOrderingComparison compare:aValue
|
||||
minCompare:NSOrderedAscending
|
||||
maxCompare:NSOrderedSame
|
||||
comparisonDescription:@"greater than or equal to"];
|
||||
}
|
||||
|
||||
id<HCMatcher> HC_lessThan(id aValue)
|
||||
{
|
||||
return [HCOrderingComparison compare:aValue
|
||||
minCompare:NSOrderedDescending
|
||||
maxCompare:NSOrderedDescending
|
||||
comparisonDescription:@"less than"];
|
||||
}
|
||||
|
||||
id<HCMatcher> HC_lessThanOrEqualTo(id aValue)
|
||||
{
|
||||
return [HCOrderingComparison compare:aValue
|
||||
minCompare:NSOrderedSame
|
||||
maxCompare:NSOrderedDescending
|
||||
comparisonDescription:@"less than or equal to"];
|
||||
}
|
||||
+43
@@ -0,0 +1,43 @@
|
||||
//
|
||||
// OCHamcrest - HCConformsToProtocol.h
|
||||
// Copyright 2012 hamcrest.org. See LICENSE.txt
|
||||
//
|
||||
// Created by: Todd Farrell
|
||||
//
|
||||
|
||||
#import <OCHamcrest/HCBaseMatcher.h>
|
||||
|
||||
|
||||
@interface HCConformsToProtocol : HCBaseMatcher
|
||||
{
|
||||
Protocol *theProtocol;
|
||||
}
|
||||
|
||||
+ (id)conformsTo:(Protocol *)protocol;
|
||||
- (id)initWithProtocol:(Protocol *)protocol;
|
||||
|
||||
@end
|
||||
|
||||
|
||||
OBJC_EXPORT id<HCMatcher> HC_conformsTo(Protocol *aProtocol);
|
||||
OBJC_EXPORT id<HCMatcher> HC_conformsToProtocol(Protocol *aProtocol) __attribute__((deprecated));
|
||||
|
||||
/**
|
||||
conformsTo(aProtocol) -
|
||||
Matches if object conforms to a given protocol.
|
||||
|
||||
@param aProtocol The protocol to compare against as the expected protocol.
|
||||
|
||||
This matcher checks whether the evaluated object conforms to @a aProtocol.
|
||||
|
||||
Example:
|
||||
@li @ref conformsTo(\@protocol(NSObject))
|
||||
|
||||
(In the event of a name clash, don't \#define @c HC_SHORTHAND and use the synonym
|
||||
@c HC_conformsTo instead.)
|
||||
|
||||
@ingroup object_matchers
|
||||
*/
|
||||
#ifdef HC_SHORTHAND
|
||||
#define conformsTo HC_conformsTo
|
||||
#endif
|
||||
+55
@@ -0,0 +1,55 @@
|
||||
//
|
||||
// OCHamcrest - HCConformsToProtocol.m
|
||||
// Copyright 2012 hamcrest.org. See LICENSE.txt
|
||||
//
|
||||
// Created by: Todd Farrell
|
||||
//
|
||||
|
||||
#import "HCConformsToProtocol.h"
|
||||
|
||||
#import "HCDescription.h"
|
||||
#import "HCRequireNonNilObject.h"
|
||||
|
||||
|
||||
@implementation HCConformsToProtocol
|
||||
|
||||
+ (id)conformsTo:(Protocol *)protocol
|
||||
{
|
||||
return [[self alloc] initWithProtocol:protocol];
|
||||
}
|
||||
|
||||
- (id)initWithProtocol:(Protocol *)aProtocol
|
||||
{
|
||||
HCRequireNonNilObject(aProtocol);
|
||||
|
||||
self = [super init];
|
||||
if (self)
|
||||
theProtocol = aProtocol;
|
||||
return self;
|
||||
}
|
||||
|
||||
- (BOOL)matches:(id)item
|
||||
{
|
||||
return [item conformsToProtocol:theProtocol];
|
||||
}
|
||||
|
||||
- (void)describeTo:(id<HCDescription>)description
|
||||
{
|
||||
[[description appendText:@"an object that conforms to "]
|
||||
appendText:NSStringFromProtocol(theProtocol)];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
|
||||
#pragma mark -
|
||||
|
||||
id<HCMatcher> HC_conformsTo(Protocol *aProtocol)
|
||||
{
|
||||
return [HCConformsToProtocol conformsTo:aProtocol];
|
||||
}
|
||||
|
||||
id<HCMatcher> HC_conformsToProtocol(Protocol *aProtocol)
|
||||
{
|
||||
return HC_conformsTo(aProtocol);
|
||||
}
|
||||
+44
@@ -0,0 +1,44 @@
|
||||
//
|
||||
// OCHamcrest - HCHasDescription.h
|
||||
// Copyright 2012 hamcrest.org. See LICENSE.txt
|
||||
//
|
||||
// Created by: Jon Reid, http://qualitycoding.org/
|
||||
// Docs: http://hamcrest.github.com/OCHamcrest/
|
||||
// Source: https://github.com/hamcrest/OCHamcrest
|
||||
//
|
||||
|
||||
#import <OCHamcrest/HCInvocationMatcher.h>
|
||||
|
||||
|
||||
@interface HCHasDescription : HCInvocationMatcher
|
||||
|
||||
+ (id)hasDescription:(id<HCMatcher>)descriptionMatcher;
|
||||
- (id)initWithDescription:(id<HCMatcher>)descriptionMatcher;
|
||||
|
||||
@end
|
||||
|
||||
|
||||
OBJC_EXPORT id<HCMatcher> HC_hasDescription(id match);
|
||||
|
||||
/**
|
||||
hasDescription(aMatcher) -
|
||||
Matches if object's @c -description satisfies a given matcher.
|
||||
|
||||
@param aMatcher The matcher to satisfy, or an expected value for @ref equalTo matching.
|
||||
|
||||
This matcher invokes @c -description on the evaluated object to get its description, passing the
|
||||
result to a given matcher for evaluation. If the @a aMatcher argument is not a matcher, it is
|
||||
implicitly wrapped in an @ref equalTo matcher to check for equality.
|
||||
|
||||
Examples:
|
||||
@li @ref hasDescription(@ref startsWith(\@"foo"))
|
||||
@li @ref hasDescription(\@"bar")
|
||||
|
||||
(In the event of a name clash, don't \#define @c HC_SHORTHAND and use the synonym
|
||||
@c HC_hasDescription instead.)
|
||||
|
||||
@ingroup object_matchers
|
||||
*/
|
||||
#ifdef HC_SHORTHAND
|
||||
#define hasDescription HC_hasDescription
|
||||
#endif
|
||||
+39
@@ -0,0 +1,39 @@
|
||||
//
|
||||
// OCHamcrest - HCHasDescription.m
|
||||
// Copyright 2012 hamcrest.org. See LICENSE.txt
|
||||
//
|
||||
// Created by: Jon Reid, http://qualitycoding.org/
|
||||
// Docs: http://hamcrest.github.com/OCHamcrest/
|
||||
// Source: https://github.com/hamcrest/OCHamcrest
|
||||
//
|
||||
|
||||
#import "HCHasDescription.h"
|
||||
|
||||
#import "HCWrapInMatcher.h"
|
||||
|
||||
|
||||
@implementation HCHasDescription
|
||||
|
||||
+ (id)hasDescription:(id<HCMatcher>)descriptionMatcher
|
||||
{
|
||||
return [[self alloc] initWithDescription:descriptionMatcher];
|
||||
}
|
||||
|
||||
- (id)initWithDescription:(id<HCMatcher>)descriptionMatcher
|
||||
{
|
||||
NSInvocation *anInvocation = [HCInvocationMatcher invocationForSelector:@selector(description)
|
||||
onClass:[NSObject class]];
|
||||
self = [super initWithInvocation:anInvocation matching:descriptionMatcher];
|
||||
shortMismatchDescription = YES;
|
||||
return self;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
|
||||
#pragma mark -
|
||||
|
||||
id<HCMatcher> HC_hasDescription(id match)
|
||||
{
|
||||
return [HCHasDescription hasDescription:HCWrapInMatcher(match)];
|
||||
}
|
||||
+49
@@ -0,0 +1,49 @@
|
||||
//
|
||||
// OCHamcrest - HCHasProperty.h
|
||||
// Copyright 2012 hamcrest.org. See LICENSE.txt
|
||||
//
|
||||
// Created by: Justin Shacklette
|
||||
//
|
||||
|
||||
#import <OCHamcrest/HCBaseMatcher.h>
|
||||
|
||||
|
||||
@interface HCHasProperty : HCBaseMatcher
|
||||
{
|
||||
NSString *propertyName;
|
||||
id<HCMatcher> valueMatcher;
|
||||
}
|
||||
|
||||
+ (id)hasProperty:(NSString *)property value:(id<HCMatcher>)aValueMatcher;
|
||||
- (id)initWithProperty:(NSString *)property value:(id<HCMatcher>)aValueMatcher;
|
||||
|
||||
@end
|
||||
|
||||
|
||||
OBJC_EXPORT id<HCMatcher> HC_hasProperty(NSString *name, id valueMatch);
|
||||
|
||||
/**
|
||||
hasProperty(name, valueMatcher) -
|
||||
Matches if object has a method of a given name whose return value satisfies a given matcher.
|
||||
|
||||
@param name The name of a method without arguments that returns an object.
|
||||
@param valueMatcher The matcher to satisfy for the return value, or an expected value for @ref equalTo matching.
|
||||
|
||||
This matcher first checks if the evaluated object has a method with a name matching the given
|
||||
@c name. If so, it invokes the method and sees if the returned value satisfies @c valueMatcher.
|
||||
|
||||
While this matcher is called "hasProperty", it's useful for checking the results of any simple
|
||||
methods, not just properties.
|
||||
|
||||
Examples:
|
||||
@li @ref hasProperty(\@"firstName", \@"Joe")
|
||||
@li @ref hasProperty(\@"firstName", startsWith(\@"J"))
|
||||
|
||||
(In the event of a name clash, don't \#define @c HC_SHORTHAND and use the synonym
|
||||
@c HC_hasProperty instead.)
|
||||
|
||||
@ingroup object_matchers
|
||||
*/
|
||||
#ifdef HC_SHORTHAND
|
||||
#define hasProperty HC_hasProperty
|
||||
#endif
|
||||
+150
@@ -0,0 +1,150 @@
|
||||
//
|
||||
// OCHamcrest - HCHasProperty.m
|
||||
// Copyright 2012 hamcrest.org. See LICENSE.txt
|
||||
//
|
||||
// Created by: Justin Shacklette
|
||||
//
|
||||
|
||||
#import "HCHasProperty.h"
|
||||
|
||||
#import "HCDescription.h"
|
||||
#import "HCRequireNonNilObject.h"
|
||||
#import "HCWrapInMatcher.h"
|
||||
|
||||
|
||||
@implementation HCHasProperty
|
||||
|
||||
+ (id)hasProperty:(NSString *)property value:(id<HCMatcher>)aValueMatcher
|
||||
{
|
||||
return [[self alloc] initWithProperty:property value:aValueMatcher];
|
||||
}
|
||||
|
||||
- (id)initWithProperty:(NSString *)property value:(id<HCMatcher>)aValueMatcher
|
||||
{
|
||||
HCRequireNonNilObject(property);
|
||||
|
||||
self = [super init];
|
||||
if (self != nil)
|
||||
{
|
||||
propertyName = [property copy];
|
||||
valueMatcher = aValueMatcher;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (BOOL)matches:(id)item
|
||||
{
|
||||
SEL propertyGetter = NSSelectorFromString(propertyName);
|
||||
if (![item respondsToSelector:propertyGetter])
|
||||
return NO;
|
||||
|
||||
id propertyValue = [self objectFromInvokingSelector:propertyGetter onObject:item];
|
||||
return [valueMatcher matches:propertyValue];
|
||||
}
|
||||
|
||||
- (id)objectFromInvokingSelector:(SEL)selector onObject:(id)object
|
||||
{
|
||||
NSMethodSignature *getterSignature = [object methodSignatureForSelector:selector];
|
||||
NSInvocation *getterInvocation = [NSInvocation invocationWithMethodSignature:getterSignature];
|
||||
[getterInvocation setTarget:object];
|
||||
[getterInvocation setSelector:selector];
|
||||
[getterInvocation invoke];
|
||||
|
||||
__unsafe_unretained id result = nil;
|
||||
const char *argType = [getterSignature methodReturnType];
|
||||
if (strncmp(argType, @encode(char), 1) == 0)
|
||||
{
|
||||
char charValue;
|
||||
[getterInvocation getReturnValue:&charValue];
|
||||
result = @(charValue);
|
||||
}
|
||||
else if (strncmp(argType, @encode(int), 1) == 0)
|
||||
{
|
||||
int intValue;
|
||||
[getterInvocation getReturnValue:&intValue];
|
||||
result = @(intValue);
|
||||
}
|
||||
else if (strncmp(argType, @encode(short), 1) == 0)
|
||||
{
|
||||
short shortValue;
|
||||
[getterInvocation getReturnValue:&shortValue];
|
||||
result = @(shortValue);
|
||||
}
|
||||
else if (strncmp(argType, @encode(long), 1) == 0)
|
||||
{
|
||||
long longValue;
|
||||
[getterInvocation getReturnValue:&longValue];
|
||||
result = @(longValue);
|
||||
}
|
||||
else if (strncmp(argType, @encode(long long), 1) == 0)
|
||||
{
|
||||
long long longLongValue;
|
||||
[getterInvocation getReturnValue:&longLongValue];
|
||||
result = @(longLongValue);
|
||||
}
|
||||
else if (strncmp(argType, @encode(unsigned char), 1) == 0)
|
||||
{
|
||||
unsigned char unsignedCharValue;
|
||||
[getterInvocation getReturnValue:&unsignedCharValue];
|
||||
result = @(unsignedCharValue);
|
||||
}
|
||||
else if (strncmp(argType, @encode(unsigned int), 1) == 0)
|
||||
{
|
||||
unsigned int unsignedIntValue;
|
||||
[getterInvocation getReturnValue:&unsignedIntValue];
|
||||
result = @(unsignedIntValue);
|
||||
}
|
||||
else if (strncmp(argType, @encode(unsigned short), 1) == 0)
|
||||
{
|
||||
unsigned short unsignedShortValue;
|
||||
[getterInvocation getReturnValue:&unsignedShortValue];
|
||||
result = @(unsignedShortValue);
|
||||
}
|
||||
else if (strncmp(argType, @encode(unsigned long), 1) == 0)
|
||||
{
|
||||
unsigned long unsignedLongValue;
|
||||
[getterInvocation getReturnValue:&unsignedLongValue];
|
||||
result = @(unsignedLongValue);
|
||||
}
|
||||
else if (strncmp(argType, @encode(unsigned long long), 1) == 0)
|
||||
{
|
||||
unsigned long long unsignedLongLongValue;
|
||||
[getterInvocation getReturnValue:&unsignedLongLongValue];
|
||||
result = @(unsignedLongLongValue);
|
||||
}
|
||||
else if (strncmp(argType, @encode(float), 1) == 0)
|
||||
{
|
||||
float floatValue;
|
||||
[getterInvocation getReturnValue:&floatValue];
|
||||
result = @(floatValue);
|
||||
}
|
||||
else if (strncmp(argType, @encode(double), 1) == 0)
|
||||
{
|
||||
double doubleValue;
|
||||
[getterInvocation getReturnValue:&doubleValue];
|
||||
result = @(doubleValue);
|
||||
}
|
||||
else if (strncmp(argType, @encode(id), 1) == 0)
|
||||
{
|
||||
[getterInvocation getReturnValue:&result];
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
- (void)describeTo:(id<HCDescription>)description
|
||||
{
|
||||
[[[[description appendText:@"an object with "]
|
||||
appendText:propertyName]
|
||||
appendText:@" "]
|
||||
appendDescriptionOf:valueMatcher];
|
||||
}
|
||||
@end
|
||||
|
||||
|
||||
#pragma mark -
|
||||
|
||||
id<HCMatcher> HC_hasProperty(NSString *name, id valueMatch)
|
||||
{
|
||||
return [HCHasProperty hasProperty:name value:HCWrapInMatcher(valueMatch)];
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
//
|
||||
// OCHamcrest - HCIsEqual.h
|
||||
// Copyright 2012 hamcrest.org. See LICENSE.txt
|
||||
//
|
||||
// Created by: Jon Reid, http://qualitycoding.org/
|
||||
// Docs: http://hamcrest.github.com/OCHamcrest/
|
||||
// Source: https://github.com/hamcrest/OCHamcrest
|
||||
//
|
||||
|
||||
#import <OCHamcrest/HCBaseMatcher.h>
|
||||
|
||||
|
||||
@interface HCIsEqual : HCBaseMatcher
|
||||
{
|
||||
id object;
|
||||
}
|
||||
|
||||
+ (id)isEqualTo:(id)anObject;
|
||||
- (id)initEqualTo:(id)anObject;
|
||||
|
||||
@end
|
||||
|
||||
|
||||
OBJC_EXPORT id<HCMatcher> HC_equalTo(id object);
|
||||
|
||||
/**
|
||||
equalTo(anObject) -
|
||||
Matches if object is equal to a given object.
|
||||
|
||||
@param anObject The object to compare against as the expected value.
|
||||
|
||||
This matcher compares the evaluated object to @a anObject for equality, as determined by the
|
||||
@c -isEqual: method.
|
||||
|
||||
If @a anObject is @c nil, the matcher will successfully match @c nil.
|
||||
|
||||
(In the event of a name clash, don't \#define @c HC_SHORTHAND and use the synonym
|
||||
@c HC_equalTo instead.)
|
||||
|
||||
@ingroup object_matchers
|
||||
*/
|
||||
#ifdef HC_SHORTHAND
|
||||
#define equalTo HC_equalTo
|
||||
#endif
|
||||
@@ -0,0 +1,58 @@
|
||||
//
|
||||
// OCHamcrest - HCIsEqual.m
|
||||
// Copyright 2012 hamcrest.org. See LICENSE.txt
|
||||
//
|
||||
// Created by: Jon Reid, http://qualitycoding.org/
|
||||
// Docs: http://hamcrest.github.com/OCHamcrest/
|
||||
// Source: https://github.com/hamcrest/OCHamcrest
|
||||
//
|
||||
|
||||
#import "HCIsEqual.h"
|
||||
|
||||
#import "HCDescription.h"
|
||||
|
||||
|
||||
@implementation HCIsEqual
|
||||
|
||||
+ (id)isEqualTo:(id)anObject
|
||||
{
|
||||
return [[self alloc] initEqualTo:anObject];
|
||||
}
|
||||
|
||||
- (id)initEqualTo:(id)anObject
|
||||
{
|
||||
self = [super init];
|
||||
if (self)
|
||||
object = anObject;
|
||||
return self;
|
||||
}
|
||||
|
||||
- (BOOL)matches:(id)item
|
||||
{
|
||||
if (item == nil)
|
||||
return object == nil;
|
||||
else
|
||||
return [item isEqual:object];
|
||||
}
|
||||
|
||||
- (void)describeTo:(id<HCDescription>)description
|
||||
{
|
||||
if ([object conformsToProtocol:@protocol(HCMatcher)])
|
||||
{
|
||||
[[[description appendText:@"<"]
|
||||
appendDescriptionOf:object]
|
||||
appendText:@">"];
|
||||
}
|
||||
else
|
||||
[description appendDescriptionOf:object];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
|
||||
#pragma mark -
|
||||
|
||||
id<HCMatcher> HC_equalTo(id object)
|
||||
{
|
||||
return [HCIsEqual isEqualTo:object];
|
||||
}
|
||||
+45
@@ -0,0 +1,45 @@
|
||||
//
|
||||
// OCHamcrest - HCIsInstanceOf.h
|
||||
// Copyright 2012 hamcrest.org. See LICENSE.txt
|
||||
//
|
||||
// Created by: Jon Reid, http://qualitycoding.org/
|
||||
// Docs: http://hamcrest.github.com/OCHamcrest/
|
||||
// Source: https://github.com/hamcrest/OCHamcrest
|
||||
//
|
||||
|
||||
#import <OCHamcrest/HCBaseMatcher.h>
|
||||
|
||||
|
||||
@interface HCIsInstanceOf : HCBaseMatcher
|
||||
{
|
||||
Class theClass;
|
||||
}
|
||||
|
||||
+ (id)isInstanceOf:(Class)type;
|
||||
- (id)initWithType:(Class)type;
|
||||
|
||||
@end
|
||||
|
||||
|
||||
OBJC_EXPORT id<HCMatcher> HC_instanceOf(Class aClass);
|
||||
|
||||
/**
|
||||
instanceOf(aClass) -
|
||||
Matches if object is an instance of, or inherits from, a given class.
|
||||
|
||||
@param aClass The class to compare against as the expected class.
|
||||
|
||||
This matcher checks whether the evaluated object is an instance of @a aClass or an instance of
|
||||
any class that inherits from @a aClass.
|
||||
|
||||
Example:
|
||||
@li @ref instanceOf([NSString class])
|
||||
|
||||
(In the event of a name clash, don't \#define @c HC_SHORTHAND and use the synonym
|
||||
@c HC_instanceOf instead.)
|
||||
|
||||
@ingroup object_matchers
|
||||
*/
|
||||
#ifdef HC_SHORTHAND
|
||||
#define instanceOf HC_instanceOf
|
||||
#endif
|
||||
+52
@@ -0,0 +1,52 @@
|
||||
//
|
||||
// OCHamcrest - HCIsInstanceOf.m
|
||||
// Copyright 2012 hamcrest.org. See LICENSE.txt
|
||||
//
|
||||
// Created by: Jon Reid, http://qualitycoding.org/
|
||||
// Docs: http://hamcrest.github.com/OCHamcrest/
|
||||
// Source: https://github.com/hamcrest/OCHamcrest
|
||||
//
|
||||
|
||||
#import "HCIsInstanceOf.h"
|
||||
|
||||
#import "HCDescription.h"
|
||||
#import "HCRequireNonNilObject.h"
|
||||
|
||||
|
||||
@implementation HCIsInstanceOf
|
||||
|
||||
+ (id)isInstanceOf:(Class)type
|
||||
{
|
||||
return [[self alloc] initWithType:type];
|
||||
}
|
||||
|
||||
- (id)initWithType:(Class)aClass
|
||||
{
|
||||
HCRequireNonNilObject(aClass);
|
||||
|
||||
self = [super init];
|
||||
if (self)
|
||||
theClass = aClass;
|
||||
return self;
|
||||
}
|
||||
|
||||
- (BOOL)matches:(id)item
|
||||
{
|
||||
return [item isKindOfClass:theClass];
|
||||
}
|
||||
|
||||
- (void)describeTo:(id<HCDescription>)description
|
||||
{
|
||||
[[description appendText:@"an instance of "]
|
||||
appendText:NSStringFromClass(theClass)];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
|
||||
#pragma mark -
|
||||
|
||||
id<HCMatcher> HC_instanceOf(Class aClass)
|
||||
{
|
||||
return [HCIsInstanceOf isInstanceOf:aClass];
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
//
|
||||
// OCHamcrest - HCIsNil.h
|
||||
// Copyright 2012 hamcrest.org. See LICENSE.txt
|
||||
//
|
||||
// Created by: Jon Reid, http://qualitycoding.org/
|
||||
// Docs: http://hamcrest.github.com/OCHamcrest/
|
||||
// Source: https://github.com/hamcrest/OCHamcrest
|
||||
//
|
||||
|
||||
#import <OCHamcrest/HCBaseMatcher.h>
|
||||
|
||||
|
||||
@interface HCIsNil : HCBaseMatcher
|
||||
|
||||
+ (id)isNil;
|
||||
|
||||
@end
|
||||
|
||||
|
||||
OBJC_EXPORT id<HCMatcher> HC_nilValue(void);
|
||||
|
||||
/**
|
||||
Matches if object is @c nil.
|
||||
|
||||
(In the event of a name clash, don't \#define @c HC_SHORTHAND and use the synonym
|
||||
@c HC_nilValue instead.)
|
||||
|
||||
@ingroup object_matchers
|
||||
*/
|
||||
#ifdef HC_SHORTHAND
|
||||
#define nilValue() HC_nilValue()
|
||||
#endif
|
||||
|
||||
|
||||
OBJC_EXPORT id<HCMatcher> HC_notNilValue(void);
|
||||
|
||||
/**
|
||||
Matches if object is not @c nil.
|
||||
|
||||
(In the event of a name clash, don't \#define @c HC_SHORTHAND and use the synonym
|
||||
@c HC_notNilValue instead.)
|
||||
|
||||
@ingroup object_matchers
|
||||
*/
|
||||
#ifdef HC_SHORTHAND
|
||||
#define notNilValue() HC_notNilValue()
|
||||
#endif
|
||||
@@ -0,0 +1,46 @@
|
||||
//
|
||||
// OCHamcrest - HCIsNil.m
|
||||
// Copyright 2012 hamcrest.org. See LICENSE.txt
|
||||
//
|
||||
// Created by: Jon Reid, http://qualitycoding.org/
|
||||
// Docs: http://hamcrest.github.com/OCHamcrest/
|
||||
// Source: https://github.com/hamcrest/OCHamcrest
|
||||
//
|
||||
|
||||
#import "HCIsNil.h"
|
||||
|
||||
#import "HCDescription.h"
|
||||
#import "HCIsNot.h"
|
||||
|
||||
|
||||
@implementation HCIsNil
|
||||
|
||||
+ (id)isNil
|
||||
{
|
||||
return [[self alloc] init];
|
||||
}
|
||||
|
||||
- (BOOL)matches:(id)item
|
||||
{
|
||||
return item == nil;
|
||||
}
|
||||
|
||||
- (void)describeTo:(id<HCDescription>)description
|
||||
{
|
||||
[description appendText:@"nil"];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
|
||||
#pragma mark -
|
||||
|
||||
id<HCMatcher> HC_nilValue()
|
||||
{
|
||||
return [HCIsNil isNil];
|
||||
}
|
||||
|
||||
id<HCMatcher> HC_notNilValue()
|
||||
{
|
||||
return HC_isNot([HCIsNil isNil]);
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
//
|
||||
// OCHamcrest - HCIsSame.h
|
||||
// Copyright 2012 hamcrest.org. See LICENSE.txt
|
||||
//
|
||||
// Created by: Jon Reid, http://qualitycoding.org/
|
||||
// Docs: http://hamcrest.github.com/OCHamcrest/
|
||||
// Source: https://github.com/hamcrest/OCHamcrest
|
||||
//
|
||||
|
||||
#import <OCHamcrest/HCBaseMatcher.h>
|
||||
|
||||
|
||||
@interface HCIsSame : HCBaseMatcher
|
||||
{
|
||||
id object;
|
||||
}
|
||||
|
||||
+ (id)isSameAs:(id)anObject;
|
||||
- (id)initSameAs:(id)anObject;
|
||||
|
||||
@end
|
||||
|
||||
|
||||
OBJC_EXPORT id<HCMatcher> HC_sameInstance(id object);
|
||||
|
||||
/**
|
||||
sameInstance(anObject) -
|
||||
Matches if evaluated object is the same instance as a given object.
|
||||
|
||||
@param anObject The object to compare against as the expected value.
|
||||
|
||||
This matcher compares the address of the evaluated object to determine if it is the same object
|
||||
as @a anObject.
|
||||
|
||||
(In the event of a name clash, don't \#define @c HC_SHORTHAND and use the synonym
|
||||
@c HC_sameInstance instead.)
|
||||
|
||||
@ingroup object_matchers
|
||||
*/
|
||||
#ifdef HC_SHORTHAND
|
||||
#define sameInstance HC_sameInstance
|
||||
#endif
|
||||
@@ -0,0 +1,57 @@
|
||||
//
|
||||
// OCHamcrest - HCIsSame.m
|
||||
// Copyright 2012 hamcrest.org. See LICENSE.txt
|
||||
//
|
||||
// Created by: Jon Reid, http://qualitycoding.org/
|
||||
// Docs: http://hamcrest.github.com/OCHamcrest/
|
||||
// Source: https://github.com/hamcrest/OCHamcrest
|
||||
//
|
||||
|
||||
#import "HCIsSame.h"
|
||||
|
||||
#import "HCDescription.h"
|
||||
|
||||
|
||||
@implementation HCIsSame
|
||||
|
||||
+ (id)isSameAs:(id)anObject
|
||||
{
|
||||
return [[self alloc] initSameAs:anObject];
|
||||
}
|
||||
|
||||
- (id)initSameAs:(id)anObject
|
||||
{
|
||||
self = [super init];
|
||||
if (self)
|
||||
object = anObject;
|
||||
return self;
|
||||
}
|
||||
|
||||
- (BOOL)matches:(id)item
|
||||
{
|
||||
return item == object;
|
||||
}
|
||||
|
||||
- (void)describeMismatchOf:(id)item to:(id<HCDescription>)mismatchDescription
|
||||
{
|
||||
[mismatchDescription appendText:@"was "];
|
||||
if (item)
|
||||
[mismatchDescription appendText:[NSString stringWithFormat:@"%p ", (__bridge void *)item]];
|
||||
[mismatchDescription appendDescriptionOf:item];
|
||||
}
|
||||
|
||||
- (void)describeTo:(id<HCDescription>)description
|
||||
{
|
||||
[[description appendText:[NSString stringWithFormat:@"same instance as %p ", (__bridge void *)object]]
|
||||
appendDescriptionOf:object];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
|
||||
#pragma mark -
|
||||
|
||||
id<HCMatcher> HC_sameInstance(id object)
|
||||
{
|
||||
return [HCIsSame isSameAs:object];
|
||||
}
|
||||
+49
@@ -0,0 +1,49 @@
|
||||
//
|
||||
// OCHamcrest - HCIsEqualIgnoringCase.h
|
||||
// Copyright 2012 hamcrest.org. See LICENSE.txt
|
||||
//
|
||||
// Created by: Jon Reid, http://qualitycoding.org/
|
||||
// Docs: http://hamcrest.github.com/OCHamcrest/
|
||||
// Source: https://github.com/hamcrest/OCHamcrest
|
||||
//
|
||||
|
||||
#import <OCHamcrest/HCBaseMatcher.h>
|
||||
|
||||
|
||||
@interface HCIsEqualIgnoringCase : HCBaseMatcher
|
||||
{
|
||||
NSString *string;
|
||||
}
|
||||
|
||||
+ (id)isEqualIgnoringCase:(NSString *)aString;
|
||||
- (id)initWithString:(NSString *)aString;
|
||||
|
||||
@end
|
||||
|
||||
|
||||
OBJC_EXPORT id<HCMatcher> HC_equalToIgnoringCase(NSString *aString);
|
||||
|
||||
/**
|
||||
equalToIgnoringCase(aString) -
|
||||
Matches if object is a string equal to a given string, ignoring case differences.
|
||||
|
||||
@param aString The string to compare against as the expected value. This value must not be @c nil.
|
||||
|
||||
This matcher first checks whether the evaluated object is a string. If so, it compares it with
|
||||
@a aString, ignoring differences of case.
|
||||
|
||||
Example:
|
||||
|
||||
@par
|
||||
@ref equalToIgnoringCase(@"hello world")
|
||||
|
||||
will match "heLLo WorlD".
|
||||
|
||||
(In the event of a name clash, don't \#define @c HC_SHORTHAND and use the synonym
|
||||
@c HC_equalToIgnoringCase instead.)
|
||||
|
||||
@ingroup text_matchers
|
||||
*/
|
||||
#ifdef HC_SHORTHAND
|
||||
#define equalToIgnoringCase HC_equalToIgnoringCase
|
||||
#endif
|
||||
+55
@@ -0,0 +1,55 @@
|
||||
//
|
||||
// OCHamcrest - HCIsEqualIgnoringCase.m
|
||||
// Copyright 2012 hamcrest.org. See LICENSE.txt
|
||||
//
|
||||
// Created by: Jon Reid, http://qualitycoding.org/
|
||||
// Docs: http://hamcrest.github.com/OCHamcrest/
|
||||
// Source: https://github.com/hamcrest/OCHamcrest
|
||||
//
|
||||
|
||||
#import "HCIsEqualIgnoringCase.h"
|
||||
|
||||
#import "HCDescription.h"
|
||||
#import "HCRequireNonNilObject.h"
|
||||
|
||||
|
||||
@implementation HCIsEqualIgnoringCase
|
||||
|
||||
+ (id)isEqualIgnoringCase:(NSString *)aString
|
||||
{
|
||||
return [[self alloc] initWithString:aString];
|
||||
}
|
||||
|
||||
- (id)initWithString:(NSString *)aString
|
||||
{
|
||||
HCRequireNonNilObject(aString);
|
||||
|
||||
self = [super init];
|
||||
if (self)
|
||||
string = [aString copy];
|
||||
return self;
|
||||
}
|
||||
|
||||
- (BOOL)matches:(id)item
|
||||
{
|
||||
if (![item isKindOfClass:[NSString class]])
|
||||
return NO;
|
||||
|
||||
return [string caseInsensitiveCompare:item] == NSOrderedSame;
|
||||
}
|
||||
|
||||
- (void)describeTo:(id<HCDescription>)description
|
||||
{
|
||||
[[description appendDescriptionOf:string]
|
||||
appendText:@" ignoring case"];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
|
||||
#pragma mark -
|
||||
|
||||
id<HCMatcher> HC_equalToIgnoringCase(NSString *aString)
|
||||
{
|
||||
return [HCIsEqualIgnoringCase isEqualIgnoringCase:aString];
|
||||
}
|
||||
Vendored
+50
@@ -0,0 +1,50 @@
|
||||
//
|
||||
// OCHamcrest - HCIsEqualIgnoringWhiteSpace.h
|
||||
// Copyright 2012 hamcrest.org. See LICENSE.txt
|
||||
//
|
||||
// Created by: Jon Reid, http://qualitycoding.org/
|
||||
// Docs: http://hamcrest.github.com/OCHamcrest/
|
||||
// Source: https://github.com/hamcrest/OCHamcrest
|
||||
//
|
||||
|
||||
#import <OCHamcrest/HCBaseMatcher.h>
|
||||
|
||||
|
||||
@interface HCIsEqualIgnoringWhiteSpace : HCBaseMatcher
|
||||
{
|
||||
NSString *originalString;
|
||||
NSString *strippedString;
|
||||
}
|
||||
|
||||
+ (id)isEqualIgnoringWhiteSpace:(NSString *)aString;
|
||||
- (id)initWithString:(NSString *)aString;
|
||||
|
||||
@end
|
||||
|
||||
|
||||
OBJC_EXPORT id<HCMatcher> HC_equalToIgnoringWhiteSpace(NSString *aString);
|
||||
|
||||
/**
|
||||
equalToIgnoringWhiteSpace(aString) -
|
||||
Matches if object is a string equal to a given string, ignoring differences in whitespace.
|
||||
|
||||
@param aString The string to compare against as the expected value. This value must not be @c nil.
|
||||
|
||||
This matcher first checks whether the evaluated object is a string. If so, it compares it with
|
||||
@a aString, ignoring differences in runs of whitespace.
|
||||
|
||||
Example:
|
||||
|
||||
@par
|
||||
@ref equalToIgnoringWhiteSpace(@"hello world")
|
||||
|
||||
will match @verbatim "hello world" @endverbatim
|
||||
|
||||
(In the event of a name clash, don't \#define @c HC_SHORTHAND and use the synonym
|
||||
@c HC_equalToIgnoringWhiteSpace instead.)
|
||||
|
||||
@ingroup text_matchers
|
||||
*/
|
||||
#ifdef HC_SHORTHAND
|
||||
#define equalToIgnoringWhiteSpace HC_equalToIgnoringWhiteSpace
|
||||
#endif
|
||||
Vendored
+97
@@ -0,0 +1,97 @@
|
||||
//
|
||||
// OCHamcrest - HCIsEqualIgnoringWhiteSpace.m
|
||||
// Copyright 2012 hamcrest.org. See LICENSE.txt
|
||||
//
|
||||
// Created by: Jon Reid, http://qualitycoding.org/
|
||||
// Docs: http://hamcrest.github.com/OCHamcrest/
|
||||
// Source: https://github.com/hamcrest/OCHamcrest
|
||||
//
|
||||
|
||||
#import "HCIsEqualIgnoringWhiteSpace.h"
|
||||
|
||||
#import "HCDescription.h"
|
||||
#import "HCRequireNonNilObject.h"
|
||||
|
||||
|
||||
static void removeTrailingSpace(NSMutableString *string)
|
||||
{
|
||||
NSUInteger length = [string length];
|
||||
if (length > 0)
|
||||
{
|
||||
NSUInteger charIndex = length - 1;
|
||||
if (isspace([string characterAtIndex:charIndex]))
|
||||
[string deleteCharactersInRange:NSMakeRange(charIndex, 1)];
|
||||
}
|
||||
}
|
||||
|
||||
static NSMutableString *stripSpace(NSString *string)
|
||||
{
|
||||
NSUInteger length = [string length];
|
||||
NSMutableString *result = [NSMutableString stringWithCapacity:length];
|
||||
bool lastWasSpace = true;
|
||||
for (NSUInteger charIndex = 0; charIndex < length; ++charIndex)
|
||||
{
|
||||
unichar character = [string characterAtIndex:charIndex];
|
||||
if (isspace(character))
|
||||
{
|
||||
if (!lastWasSpace)
|
||||
[result appendString:@" "];
|
||||
lastWasSpace = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
[result appendFormat:@"%C", character];
|
||||
lastWasSpace = false;
|
||||
}
|
||||
}
|
||||
|
||||
removeTrailingSpace(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
#pragma mark -
|
||||
|
||||
@implementation HCIsEqualIgnoringWhiteSpace
|
||||
|
||||
+ (id)isEqualIgnoringWhiteSpace:(NSString *)aString
|
||||
{
|
||||
return [[self alloc] initWithString:aString];
|
||||
}
|
||||
|
||||
- (id)initWithString:(NSString *)aString
|
||||
{
|
||||
HCRequireNonNilObject(aString);
|
||||
|
||||
self = [super init];
|
||||
if (self)
|
||||
{
|
||||
originalString = [aString copy];
|
||||
strippedString = stripSpace(aString);
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (BOOL)matches:(id)item
|
||||
{
|
||||
if (![item isKindOfClass:[NSString class]])
|
||||
return NO;
|
||||
|
||||
return [strippedString isEqualToString:stripSpace(item)];
|
||||
}
|
||||
|
||||
- (void)describeTo:(id<HCDescription>)description
|
||||
{
|
||||
[[description appendDescriptionOf:originalString]
|
||||
appendText:@" ignoring whitespace"];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
|
||||
#pragma mark -
|
||||
|
||||
id<HCMatcher> HC_equalToIgnoringWhiteSpace(NSString *aString)
|
||||
{
|
||||
return [HCIsEqualIgnoringWhiteSpace isEqualIgnoringWhiteSpace:aString];
|
||||
}
|
||||
+45
@@ -0,0 +1,45 @@
|
||||
//
|
||||
// OCHamcrest - HCStringContains.h
|
||||
// Copyright 2012 hamcrest.org. See LICENSE.txt
|
||||
//
|
||||
// Created by: Jon Reid, http://qualitycoding.org/
|
||||
// Docs: http://hamcrest.github.com/OCHamcrest/
|
||||
// Source: https://github.com/hamcrest/OCHamcrest
|
||||
//
|
||||
|
||||
#import <OCHamcrest/HCSubstringMatcher.h>
|
||||
|
||||
|
||||
@interface HCStringContains : HCSubstringMatcher
|
||||
|
||||
+ (id)stringContains:(NSString *)aSubstring;
|
||||
|
||||
@end
|
||||
|
||||
|
||||
OBJC_EXPORT id<HCMatcher> HC_containsString(NSString *aSubstring);
|
||||
|
||||
/**
|
||||
containsString(aString) -
|
||||
Matches if object is a string containing a given string.
|
||||
|
||||
@param aString The string to search for. This value must not be @c nil.
|
||||
|
||||
This matcher first checks whether the evaluated object is a string. If so, it checks whether it
|
||||
contains @a aString.
|
||||
|
||||
Example:
|
||||
|
||||
@par
|
||||
@ref containsString(@"def")
|
||||
|
||||
will match "abcdefg".
|
||||
|
||||
(In the event of a name clash, don't \#define @c HC_SHORTHAND and use the synonym
|
||||
@c HC_containsString instead.)
|
||||
|
||||
@ingroup text_matchers
|
||||
*/
|
||||
#ifdef HC_SHORTHAND
|
||||
#define containsString HC_containsString
|
||||
#endif
|
||||
+41
@@ -0,0 +1,41 @@
|
||||
//
|
||||
// OCHamcrest - HCStringContains.m
|
||||
// Copyright 2012 hamcrest.org. See LICENSE.txt
|
||||
//
|
||||
// Created by: Jon Reid, http://qualitycoding.org/
|
||||
// Docs: http://hamcrest.github.com/OCHamcrest/
|
||||
// Source: https://github.com/hamcrest/OCHamcrest
|
||||
//
|
||||
|
||||
#import "HCStringContains.h"
|
||||
|
||||
|
||||
@implementation HCStringContains
|
||||
|
||||
+ (id)stringContains:(NSString *)aString
|
||||
{
|
||||
return [[self alloc] initWithSubstring:aString];
|
||||
}
|
||||
|
||||
- (BOOL)matches:(id)item
|
||||
{
|
||||
if (![item respondsToSelector:@selector(rangeOfString:)])
|
||||
return NO;
|
||||
|
||||
return [item rangeOfString:substring].location != NSNotFound;
|
||||
}
|
||||
|
||||
- (NSString *)relationship
|
||||
{
|
||||
return @"containing";
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
|
||||
#pragma mark -
|
||||
|
||||
id<HCMatcher> HC_containsString(NSString *aString)
|
||||
{
|
||||
return [HCStringContains stringContains:aString];
|
||||
}
|
||||
+50
@@ -0,0 +1,50 @@
|
||||
//
|
||||
// OCHamcrest - HCStringContainsInOrder.h
|
||||
// Copyright 2012 hamcrest.org. See LICENSE.txt
|
||||
//
|
||||
// Created by: Jon Reid, http://qualitycoding.org/
|
||||
// Docs: http://hamcrest.github.com/OCHamcrest/
|
||||
// Source: https://github.com/hamcrest/OCHamcrest
|
||||
//
|
||||
|
||||
#import <OCHamcrest/HCBaseMatcher.h>
|
||||
|
||||
|
||||
@interface HCStringContainsInOrder : HCBaseMatcher
|
||||
{
|
||||
NSArray *substrings;
|
||||
}
|
||||
|
||||
+ (id)containsInOrder:(NSArray *)substringList;
|
||||
- (id)initWithSubstrings:(NSArray *)substringList;
|
||||
|
||||
@end
|
||||
|
||||
|
||||
OBJC_EXPORT id<HCMatcher> HC_stringContainsInOrder(NSString *substring, ...) NS_REQUIRES_NIL_TERMINATION;
|
||||
|
||||
/**
|
||||
stringContainsInOrder(firstString, ...) -
|
||||
Matches if object is a string containing a given list of substrings in relative order.
|
||||
|
||||
@param firstString,... A comma-separated list of strings ending with @c nil.
|
||||
|
||||
This matcher first checks whether the evaluated object is a string. If so, it checks whether it
|
||||
contains a given list of strings, in relative order to each other. The searches are performed
|
||||
starting from the beginning of the evaluated string.
|
||||
|
||||
Example:
|
||||
|
||||
@par
|
||||
@ref stringContainsInOrder(@"bc", @"fg", @"jkl", nil)
|
||||
|
||||
will match "abcdefghijklm".
|
||||
|
||||
(In the event of a name clash, don't \#define @c HC_SHORTHAND and use the synonym
|
||||
@c HC_stringContainsInOrder instead.)
|
||||
|
||||
@ingroup text_matchers
|
||||
*/
|
||||
#ifdef HC_SHORTHAND
|
||||
#define stringContainsInOrder HC_stringContainsInOrder
|
||||
#endif
|
||||
+85
@@ -0,0 +1,85 @@
|
||||
//
|
||||
// OCHamcrest - HCStringContainsInOrder.m
|
||||
// Copyright 2012 hamcrest.org. See LICENSE.txt
|
||||
//
|
||||
// Created by: Jon Reid, http://qualitycoding.org/
|
||||
// Docs: http://hamcrest.github.com/OCHamcrest/
|
||||
// Source: https://github.com/hamcrest/OCHamcrest
|
||||
//
|
||||
|
||||
#import "HCStringContainsInOrder.h"
|
||||
|
||||
#import "HCDescription.h"
|
||||
|
||||
|
||||
@implementation HCStringContainsInOrder
|
||||
|
||||
+ (id)containsInOrder:(NSArray *)substringList
|
||||
{
|
||||
return [[self alloc] initWithSubstrings:substringList];
|
||||
}
|
||||
|
||||
- (id)initWithSubstrings:(NSArray *)substringList
|
||||
{
|
||||
self = [super init];
|
||||
if (self)
|
||||
{
|
||||
for (id substring in substringList)
|
||||
{
|
||||
if (![substring isKindOfClass:[NSString class]])
|
||||
{
|
||||
@throw [NSException exceptionWithName:@"NotAString"
|
||||
reason:@"Arguments must be strings"
|
||||
userInfo:nil];
|
||||
}
|
||||
}
|
||||
|
||||
substrings = substringList;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (BOOL)matches:(id)item
|
||||
{
|
||||
if (![item isKindOfClass:[NSString class]])
|
||||
return NO;
|
||||
|
||||
NSRange searchRange = NSMakeRange(0, [item length]);
|
||||
for (NSString *substring in substrings)
|
||||
{
|
||||
NSRange substringRange = [item rangeOfString:substring options:0 range:searchRange];
|
||||
if (substringRange.location == NSNotFound)
|
||||
return NO;
|
||||
searchRange.location = substringRange.location + substringRange.length;
|
||||
searchRange.length = [item length] - searchRange.location;
|
||||
}
|
||||
return YES;
|
||||
}
|
||||
|
||||
- (void)describeTo:(id<HCDescription>)description
|
||||
{
|
||||
[description appendList:substrings start:@"a string containing " separator:@", " end:@" in order"];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
|
||||
#pragma mark -
|
||||
|
||||
id<HCMatcher> HC_stringContainsInOrder(NSString *substring, ...)
|
||||
{
|
||||
va_list args;
|
||||
va_start(args, substring);
|
||||
NSMutableArray *substringList = [NSMutableArray arrayWithObject:substring];
|
||||
|
||||
substring = va_arg(args, NSString *);
|
||||
while (substring != nil)
|
||||
{
|
||||
[substringList addObject:substring];
|
||||
substring = va_arg(args, NSString *);
|
||||
}
|
||||
|
||||
va_end(args);
|
||||
|
||||
return [HCStringContainsInOrder containsInOrder:substringList];
|
||||
}
|
||||
+45
@@ -0,0 +1,45 @@
|
||||
//
|
||||
// OCHamcrest - HCStringEndsWith.h
|
||||
// Copyright 2012 hamcrest.org. See LICENSE.txt
|
||||
//
|
||||
// Created by: Jon Reid, http://qualitycoding.org/
|
||||
// Docs: http://hamcrest.github.com/OCHamcrest/
|
||||
// Source: https://github.com/hamcrest/OCHamcrest
|
||||
//
|
||||
|
||||
#import <OCHamcrest/HCSubstringMatcher.h>
|
||||
|
||||
|
||||
@interface HCStringEndsWith : HCSubstringMatcher
|
||||
|
||||
+ (id)stringEndsWith:(NSString *)aSubstring;
|
||||
|
||||
@end
|
||||
|
||||
|
||||
OBJC_EXPORT id<HCMatcher> HC_endsWith(NSString *aSubstring);
|
||||
|
||||
/**
|
||||
endsWith(aString) -
|
||||
Matches if object is a string ending with a given string.
|
||||
|
||||
@param aString The string to search for. This value must not be @c nil.
|
||||
|
||||
This matcher first checks whether the evaluated object is a string. If so, it checks if
|
||||
@a aString matches the ending characters of the evaluated object.
|
||||
|
||||
Example:
|
||||
|
||||
@par
|
||||
@ref endsWith(@"bar")
|
||||
|
||||
will match "foobar".
|
||||
|
||||
(In the event of a name clash, don't \#define @c HC_SHORTHAND and use the synonym
|
||||
@c HC_endsWith instead.)
|
||||
|
||||
@ingroup text_matchers
|
||||
*/
|
||||
#ifdef HC_SHORTHAND
|
||||
#define endsWith HC_endsWith
|
||||
#endif
|
||||
+41
@@ -0,0 +1,41 @@
|
||||
//
|
||||
// OCHamcrest - HCStringEndsWith.m
|
||||
// Copyright 2012 hamcrest.org. See LICENSE.txt
|
||||
//
|
||||
// Created by: Jon Reid, http://qualitycoding.org/
|
||||
// Docs: http://hamcrest.github.com/OCHamcrest/
|
||||
// Source: https://github.com/hamcrest/OCHamcrest
|
||||
//
|
||||
|
||||
#import "HCStringEndsWith.h"
|
||||
|
||||
|
||||
@implementation HCStringEndsWith
|
||||
|
||||
+ (id)stringEndsWith:(NSString *)aString
|
||||
{
|
||||
return [[self alloc] initWithSubstring:aString];
|
||||
}
|
||||
|
||||
- (BOOL)matches:(id)item
|
||||
{
|
||||
if (![item respondsToSelector:@selector(hasSuffix:)])
|
||||
return NO;
|
||||
|
||||
return [item hasSuffix:substring];
|
||||
}
|
||||
|
||||
- (NSString *)relationship
|
||||
{
|
||||
return @"ending with";
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
|
||||
#pragma mark -
|
||||
|
||||
id<HCMatcher> HC_endsWith(NSString *aString)
|
||||
{
|
||||
return [HCStringEndsWith stringEndsWith:aString];
|
||||
}
|
||||
+45
@@ -0,0 +1,45 @@
|
||||
//
|
||||
// OCHamcrest - HCStringStartsWith.h
|
||||
// Copyright 2012 hamcrest.org. See LICENSE.txt
|
||||
//
|
||||
// Created by: Jon Reid, http://qualitycoding.org/
|
||||
// Docs: http://hamcrest.github.com/OCHamcrest/
|
||||
// Source: https://github.com/hamcrest/OCHamcrest
|
||||
//
|
||||
|
||||
#import <OCHamcrest/HCSubstringMatcher.h>
|
||||
|
||||
|
||||
@interface HCStringStartsWith : HCSubstringMatcher
|
||||
|
||||
+ (id)stringStartsWith:(NSString *)aSubstring;
|
||||
|
||||
@end
|
||||
|
||||
|
||||
OBJC_EXPORT id<HCMatcher> HC_startsWith(NSString *aSubstring);
|
||||
|
||||
/**
|
||||
startsWith(aString) -
|
||||
Matches if object is a string starting with a given string.
|
||||
|
||||
@param aString The string to search for. This value must not be @c nil.
|
||||
|
||||
This matcher first checks whether the evaluated object is a string. If so, it checks if
|
||||
@a aString matches the beginning characters of the evaluated object.
|
||||
|
||||
Example:
|
||||
|
||||
@par
|
||||
@ref endsWith(@"foo")
|
||||
|
||||
will match "foobar".
|
||||
|
||||
(In the event of a name clash, don't \#define @c HC_SHORTHAND and use the synonym
|
||||
@c HC_startsWith instead.)
|
||||
|
||||
@ingroup text_matchers
|
||||
*/
|
||||
#ifdef HC_SHORTHAND
|
||||
#define startsWith HC_startsWith
|
||||
#endif
|
||||
+41
@@ -0,0 +1,41 @@
|
||||
//
|
||||
// OCHamcrest - HCStringStartsWith.m
|
||||
// Copyright 2012 hamcrest.org. See LICENSE.txt
|
||||
//
|
||||
// Created by: Jon Reid, http://qualitycoding.org/
|
||||
// Docs: http://hamcrest.github.com/OCHamcrest/
|
||||
// Source: https://github.com/hamcrest/OCHamcrest
|
||||
//
|
||||
|
||||
#import "HCStringStartsWith.h"
|
||||
|
||||
|
||||
@implementation HCStringStartsWith
|
||||
|
||||
+ (id)stringStartsWith:(NSString *)aSubstring
|
||||
{
|
||||
return [[self alloc] initWithSubstring:aSubstring];
|
||||
}
|
||||
|
||||
- (BOOL)matches:(id)item
|
||||
{
|
||||
if (![item respondsToSelector:@selector(hasPrefix:)])
|
||||
return NO;
|
||||
|
||||
return [item hasPrefix:substring];
|
||||
}
|
||||
|
||||
- (NSString *)relationship
|
||||
{
|
||||
return @"starting with";
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
|
||||
#pragma mark -
|
||||
|
||||
id<HCMatcher> HC_startsWith(NSString *aString)
|
||||
{
|
||||
return [HCStringStartsWith stringStartsWith:aString];
|
||||
}
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
//
|
||||
// OCHamcrest - HCSubstringMatcher.h
|
||||
// Copyright 2012 hamcrest.org. See LICENSE.txt
|
||||
//
|
||||
// Created by: Jon Reid, http://qualitycoding.org/
|
||||
// Docs: http://hamcrest.github.com/OCHamcrest/
|
||||
// Source: https://github.com/hamcrest/OCHamcrest
|
||||
//
|
||||
|
||||
#import <OCHamcrest/HCBaseMatcher.h>
|
||||
|
||||
|
||||
@interface HCSubstringMatcher : HCBaseMatcher
|
||||
{
|
||||
NSString *substring;
|
||||
}
|
||||
|
||||
- (id)initWithSubstring:(NSString *)aString;
|
||||
|
||||
@end
|
||||
+41
@@ -0,0 +1,41 @@
|
||||
//
|
||||
// OCHamcrest - HCSubstringMatcher.m
|
||||
// Copyright 2012 hamcrest.org. See LICENSE.txt
|
||||
//
|
||||
// Created by: Jon Reid, http://qualitycoding.org/
|
||||
// Docs: http://hamcrest.github.com/OCHamcrest/
|
||||
// Source: https://github.com/hamcrest/OCHamcrest
|
||||
//
|
||||
|
||||
#import "HCSubstringMatcher.h"
|
||||
|
||||
#import "HCDescription.h"
|
||||
#import "HCRequireNonNilObject.h"
|
||||
|
||||
|
||||
@interface HCSubstringMatcher (SubclassResponsibility)
|
||||
- (NSString *)relationship;
|
||||
@end
|
||||
|
||||
|
||||
@implementation HCSubstringMatcher
|
||||
|
||||
- (id)initWithSubstring:(NSString *)aString
|
||||
{
|
||||
HCRequireNonNilObject(aString);
|
||||
|
||||
self = [super init];
|
||||
if (self)
|
||||
substring = [aString copy];
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)describeTo:(id<HCDescription>)description
|
||||
{
|
||||
[[[[description appendText:@"a string "]
|
||||
appendText:[self relationship]]
|
||||
appendText:@" "]
|
||||
appendDescriptionOf:substring];
|
||||
}
|
||||
|
||||
@end
|
||||
Reference in new issue
Block a user