Adds cocoapods for libraries.

Adds OCMockito and OCHamcrest libs.
This commit is contained in:
2020-09-05 22:06:51 -07:00
parent f688898d96
commit bab5a55c3b
364 changed files with 17147 additions and 1 deletions

View File

@@ -0,0 +1,64 @@
// OCHamcrest by Jon Reid, https://qualitycoding.org/
// Copyright 2019 hamcrest.org. See LICENSE.txt
#import <OCHamcrest/HCDiagnosingMatcher.h>
NS_ASSUME_NONNULL_BEGIN
/*!
* @abstract Calculates the logical conjunction of multiple matchers.
* @discussion Evaluation is shortcut, so subsequent matchers are not called if an earlier matcher
* returns <code>NO</code>.
*/
@interface HCAllOf : HCDiagnosingMatcher
- (instancetype)initWithMatchers:(NSArray<id <HCMatcher>> *)matchers NS_DESIGNATED_INITIALIZER;
- (instancetype)init NS_UNAVAILABLE;
@end
FOUNDATION_EXPORT id HC_allOfIn(NSArray<id <HCMatcher>> *matchers);
#ifndef HC_DISABLE_SHORT_SYNTAX
/*!
* @abstract Creates a matcher that matches when the examined object matches <b>all</b> of the
* specified matchers.
* @param matchers An array of matchers. Any element that is not a matcher is implicitly wrapped in
* an <em>equalTo</em> matcher to check for equality.
* @discussion
* <b>Example</b><br />
* <pre>assertThat(\@"myValue", allOfIn(\@[startsWith(\@"my"), containsSubstring(\@"Val")]))</pre>
*
* <b>Name Clash</b><br />
* In the event of a name clash, <code>#define HC_DISABLE_SHORT_SYNTAX</code> and use the synonym
* HC_allOfIn instead.
*/
static inline id allOfIn(NSArray *matchers)
{
return HC_allOfIn(matchers);
}
#endif
FOUNDATION_EXPORT id HC_allOf(id matchers, ...) NS_REQUIRES_NIL_TERMINATION;
#ifndef HC_DISABLE_SHORT_SYNTAX
/*!
* @abstract Creates a matcher that matches when the examined object matches <b>all</b> of the
* specified matchers.
* @param matchers... A comma-separated list of matchers ending with <code>nil</code>. Any argument
* that is not a matcher is implicitly wrapped in an <em>equalTo</em> matcher to check for equality.
* @discussion
* <b>Example</b><br />
* <pre>assertThat(\@"myValue", allOf(startsWith(\@"my"), containsSubstring(\@"Val"), nil))</pre>
*
* <b>Name Clash</b><br />
* In the event of a name clash, <code>#define HC_DISABLE_SHORT_SYNTAX</code> and use the synonym
* HC_allOf instead.
*/
#define allOf(matchers...) HC_allOf(matchers)
#endif
NS_ASSUME_NONNULL_END

View File

@@ -0,0 +1,60 @@
// OCHamcrest by Jon Reid, https://qualitycoding.org/
// Copyright 2019 hamcrest.org. See LICENSE.txt
#import "HCAllOf.h"
#import "HCCollect.h"
@interface HCAllOf ()
@property (nonatomic, copy, readonly) NSArray<id <HCMatcher>> *matchers;
@end
@implementation HCAllOf
- (instancetype)initWithMatchers:(NSArray<id <HCMatcher>> *)matchers
{
self = [super init];
if (self)
_matchers = [matchers copy];
return self;
}
- (BOOL)matches:(nullable id)item describingMismatchTo:(id <HCDescription>)mismatchDescription
{
for (id <HCMatcher> oneMatcher in self.matchers)
{
if (![oneMatcher matches:item])
{
[[[mismatchDescription appendText:@"instead of "]
appendDescriptionOf:oneMatcher]
appendText:@", "];
[oneMatcher describeMismatchOf:item to:mismatchDescription];
return NO;
}
}
return YES;
}
- (void)describeTo:(id <HCDescription>)description
{
[description appendList:self.matchers start:@"(" separator:@" and " end:@")"];
}
@end
id HC_allOfIn(NSArray *matchers)
{
return [[HCAllOf alloc] initWithMatchers:HCWrapIntoMatchers(matchers)];
}
id HC_allOf(id matchers, ...)
{
va_list args;
va_start(args, matchers);
NSArray *array = HCCollectItems(matchers, args);
va_end(args);
return HC_allOfIn(array);
}

View File

@@ -0,0 +1,62 @@
// OCHamcrest by Jon Reid, https://qualitycoding.org/
// Copyright 2019 hamcrest.org. See LICENSE.txt
#import <OCHamcrest/HCBaseMatcher.h>
NS_ASSUME_NONNULL_BEGIN
/*!
* @abstract Calculates the logical disjunction of multiple matchers.
* @discussion Evaluation is shortcut, so subsequent matchers are not called if an earlier matcher
* returns <code>NO</code>.
*/
@interface HCAnyOf : HCBaseMatcher
- (instancetype)initWithMatchers:(NSArray<id <HCMatcher>> *)matchers NS_DESIGNATED_INITIALIZER;
- (instancetype)init NS_UNAVAILABLE;
@end
FOUNDATION_EXPORT id HC_anyOfIn(NSArray *matchers);
#ifndef HC_DISABLE_SHORT_SYNTAX
/*!
* @abstract Creates a matcher that matches when the examined object matches <b>any</b> of the
* specified matchers.
* @param matchers An array of matchers. Any element that is not a matcher is implicitly wrapped in
* an <em>equalTo</em> matcher to check for equality.
* @discussion
* <b>Example</b><br />
* <pre>assertThat(\@"myValue", allOf(\@[startsWith(\@"foo"), containsSubstring(\@"Val")]))</pre>
*
* <b>Name Clash</b><br />
* In the event of a name clash, <code>#define HC_DISABLE_SHORT_SYNTAX</code> and use the synonym
* HC_anyOf instead.
*/
static inline id anyOfIn(NSArray *matchers)
{
return HC_anyOfIn(matchers);
}
#endif
FOUNDATION_EXPORT id HC_anyOf(id matchers, ...) NS_REQUIRES_NIL_TERMINATION;
#ifndef HC_DISABLE_SHORT_SYNTAX
/*!
* @abstract Creates a matcher that matches when the examined object matches <b>any</b> of the
* specified matchers.
* @param matchers... A comma-separated list of matchers ending with <code>nil</code>. Any argument
* that is not a matcher is implicitly wrapped in an <em>equalTo</em> matcher to check for equality.
* @discussion
* <b>Example</b><br />
* <pre>assertThat(\@"myValue", allOf(startsWith(\@"foo"), containsSubstring(\@"Val"), nil))</pre>
*
* <b>Name Clash</b><br />
* In the event of a name clash, <code>#define HC_DISABLE_SHORT_SYNTAX</code> and use the synonym
* HC_anyOf instead.
*/
#define anyOf(matchers...) HC_anyOf(matchers)
#endif
NS_ASSUME_NONNULL_END

View File

@@ -0,0 +1,52 @@
// OCHamcrest by Jon Reid, https://qualitycoding.org/
// Copyright 2019 hamcrest.org. See LICENSE.txt
#import "HCAnyOf.h"
#import "HCCollect.h"
@interface HCAnyOf ()
@property (nonatomic, copy, readonly) NSArray<id <HCMatcher>> *matchers;
@end
@implementation HCAnyOf
- (instancetype)initWithMatchers:(NSArray<id <HCMatcher>> *)matchers
{
self = [super init];
if (self)
_matchers = [matchers copy];
return self;
}
- (BOOL)matches:(nullable id)item
{
for (id <HCMatcher> oneMatcher in self.matchers)
if ([oneMatcher matches:item])
return YES;
return NO;
}
- (void)describeTo:(id <HCDescription>)description
{
[description appendList:self.matchers start:@"(" separator:@" or " end:@")"];
}
@end
id HC_anyOfIn(NSArray *matchers)
{
return [[HCAnyOf alloc] initWithMatchers:HCWrapIntoMatchers(matchers)];
}
id HC_anyOf(id matchers, ...)
{
va_list args;
va_start(args, matchers);
NSArray *array = HCCollectItems(matchers, args);
va_end(args);
return HC_anyOfIn(array);
}

View File

@@ -0,0 +1,55 @@
// OCHamcrest by Jon Reid, https://qualitycoding.org/
// Copyright 2019 hamcrest.org. See LICENSE.txt
#import <OCHamcrest/HCBaseMatcher.h>
NS_ASSUME_NONNULL_BEGIN
/*!
* @abstract Matches anything.
*/
@interface HCIsAnything : HCBaseMatcher
- (instancetype)init;
- (instancetype)initWithDescription:(NSString *)description NS_DESIGNATED_INITIALIZER;
@end
FOUNDATION_EXPORT id HC_anything(void);
#ifndef HC_DISABLE_SHORT_SYNTAX
/*!
* @abstract Creates a matcher that always matches, regardless of the examined object.
* @discussion
* <b>Name Clash</b><br />
* In the event of a name clash, <code>#define HC_DISABLE_SHORT_SYNTAX</code> and use the synonym
* HC_anything instead.
*/
static inline id anything(void)
{
return HC_anything();
}
#endif
FOUNDATION_EXPORT id HC_anythingWithDescription(NSString *description);
#ifndef HC_DISABLE_SHORT_SYNTAX
/*!
* @abstract Creates a matcher that matches anything, regardless of the examined object, but
* describes itself with the specified NSString.
* @param description A meaningful string used to describe this matcher.
* @discussion
* <b>Name Clash</b><br />
* In the event of a name clash, <code>#define HC_DISABLE_SHORT_SYNTAX</code> and use the synonym
* HC_anything instead.
*/
static inline id anythingWithDescription(NSString *description)
{
return HC_anythingWithDescription(description);
}
#endif
NS_ASSUME_NONNULL_END

View File

@@ -0,0 +1,47 @@
// OCHamcrest by Jon Reid, https://qualitycoding.org/
// Copyright 2019 hamcrest.org. See LICENSE.txt
#import "HCIsAnything.h"
@implementation HCIsAnything
{
NSString *_description;
}
- (instancetype)init
{
self = [self initWithDescription:@"ANYTHING"];
return self;
}
- (instancetype)initWithDescription:(NSString *)description
{
self = [super init];
if (self)
_description = [description copy];
return self;
}
- (BOOL)matches:(nullable id)item
{
return YES;
}
- (void)describeTo:(id <HCDescription>)aDescription
{
[aDescription appendText:_description];
}
@end
id HC_anything()
{
return [[HCIsAnything alloc] init];
}
id HC_anythingWithDescription(NSString *description)
{
return [[HCIsAnything alloc] initWithDescription:description];
}

View File

@@ -0,0 +1,44 @@
// OCHamcrest by Jon Reid, https://qualitycoding.org/
// Copyright 2019 hamcrest.org. See LICENSE.txt
#import <OCHamcrest/HCBaseMatcher.h>
NS_ASSUME_NONNULL_BEGIN
/*!
* @abstract Calculates the logical negation of a matcher.
*/
@interface HCIsNot : HCBaseMatcher
- (instancetype)initWithMatcher:(id <HCMatcher>)matcher NS_DESIGNATED_INITIALIZER;
- (instancetype)init NS_UNAVAILABLE;
@end
FOUNDATION_EXPORT id HC_isNot(_Nullable id value);
#ifndef HC_DISABLE_SHORT_SYNTAX
/*!
* @abstract Creates a matcher that wraps an existing matcher, but inverts the logic by which it
* will match.
* @param value The matcher to negate, or an expected value to match for inequality.
* @discussion If <em>value</em> is not a matcher, it is implicitly wrapped in an <em>equalTo</em>
* matcher to check for equality, and thus matches for inequality.
*
* <b>Examples</b><br />
* <pre>assertThat(cheese, isNot(equalTo(smelly)))</pre>
* <pre>assertThat(cheese, isNot(smelly))</pre>
*
* <b>Name Clash</b><br />
* In the event of a name clash, <code>#define HC_DISABLE_SHORT_SYNTAX</code> and use the synonym
* HC_isNot instead.
*/
static inline id isNot(_Nullable id value)
{
return HC_isNot(value);
}
#endif
NS_ASSUME_NONNULL_END

View File

@@ -0,0 +1,43 @@
// OCHamcrest by Jon Reid, https://qualitycoding.org/
// Copyright 2019 hamcrest.org. See LICENSE.txt
#import "HCIsNot.h"
#import "HCWrapInMatcher.h"
@interface HCIsNot ()
@property (nonatomic, strong, readonly) id <HCMatcher> matcher;
@end
@implementation HCIsNot
- (instancetype)initWithMatcher:(id <HCMatcher>)matcher
{
self = [super init];
if (self)
_matcher = matcher;
return self;
}
- (BOOL)matches:(nullable id)item
{
return ![self.matcher matches:item];
}
- (void)describeTo:(id <HCDescription>)description
{
[[description appendText:@"not "] appendDescriptionOf:self.matcher];
}
- (void)describeMismatchOf:(nullable id)item to:(nullable id <HCDescription>)mismatchDescription
{
[self.matcher describeMismatchOf:item to:mismatchDescription];
}
@end
id HC_isNot(_Nullable id value)
{
return [[HCIsNot alloc] initWithMatcher:HCWrapInMatcher(value)];
}