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,41 @@
// OCHamcrest by Jon Reid, https://qualitycoding.org/
// Copyright 2019 hamcrest.org. See LICENSE.txt
#import <OCHamcrest/HCBaseMatcher.h>
NS_ASSUME_NONNULL_BEGIN
/*!
* @abstract Provides a custom description to another matcher.
*/
@interface HCDescribedAs : HCBaseMatcher
- (instancetype)initWithDescription:(NSString *)description
forMatcher:(id <HCMatcher>)matcher
overValues:(NSArray *)templateValues NS_DESIGNATED_INITIALIZER;
- (instancetype)init NS_UNAVAILABLE;
@end
FOUNDATION_EXPORT id HC_describedAs(NSString *description, id <HCMatcher> matcher, ...) NS_REQUIRES_NIL_TERMINATION;
#ifndef HC_DISABLE_SHORT_SYNTAX
/*!
* @abstract Wraps an existing matcher, overriding its description with that specified. All other
* functions are delegated to the decorated matcher, including its mismatch description.
* @param description The new description for the wrapped matcher.
* @param matcher The matcher to wrap, followed by a comma-separated list of substitution
* values ending with <code>nil</code>.
* @discussion The description may contain substitution placeholders %0, %1, etc. These will be
* replaced by any values that follow the matcher.
*
* <b>Name Clash</b><br />
* In the event of a name clash, <code>#define HC_DISABLE_SHORT_SYNTAX</code> and use the synonym
* HC_describedAs instead.
*/
#define describedAs(description, matcher, ...) HC_describedAs(description, matcher, ##__VA_ARGS__)
#endif
NS_ASSUME_NONNULL_END

View File

@@ -0,0 +1,121 @@
// OCHamcrest by Jon Reid, https://qualitycoding.org/
// Copyright 2019 hamcrest.org. See LICENSE.txt
#import "HCDescribedAs.h"
@interface NSString (OCHamcrest)
@end
@implementation NSString (OCHamcrest)
// Parse decimal number (-1 if not found) and return remaining string.
- (NSString *)och_getDecimalNumber:(int *)number
{
int decimal = 0;
BOOL readDigit = NO;
NSUInteger length = self.length;
NSUInteger index;
for (index = 0; index < length; ++index)
{
unichar character = [self characterAtIndex:index];
if (!isdigit(character))
break;
decimal = decimal * 10 + character - '0';
readDigit = YES;
}
if (!readDigit)
{
*number = -1;
return self;
}
*number = decimal;
return [self substringFromIndex:index];
}
@end
@interface HCDescribedAs ()
@property (nonatomic, copy, readonly) NSString *descriptionTemplate;
@property (nonatomic, strong, readonly) id <HCMatcher> matcher;
@property (nonatomic, copy, readonly) NSArray *values;
@end
@implementation HCDescribedAs
- (instancetype)initWithDescription:(NSString *)description
forMatcher:(id <HCMatcher>)matcher
overValues:(NSArray *)templateValues
{
self = [super init];
if (self)
{
_descriptionTemplate = [description copy];
_matcher = matcher;
_values = [templateValues copy];
}
return self;
}
- (BOOL)matches:(nullable id)item
{
return [self.matcher matches:item];
}
- (void)describeMismatchOf:(nullable id)item to:(nullable id <HCDescription>)mismatchDescription
{
[self.matcher describeMismatchOf:item to:mismatchDescription];
}
- (void)describeTo:(id <HCDescription>)description
{
NSArray<NSString *> *components = [self.descriptionTemplate componentsSeparatedByString:@"%"];
BOOL firstComponent = YES;
for (NSString *component in components)
{
if (firstComponent)
{
firstComponent = NO;
[description appendText:component];
}
else
{
[self appendTemplateForComponent:component toDescription:description];
}
}
}
- (void)appendTemplateForComponent:(NSString *)component toDescription:(id <HCDescription>)description
{
int index;
NSString *remainder = [component och_getDecimalNumber:&index];
if (index < 0)
[[description appendText:@"%"] appendText:component];
else
[[description appendDescriptionOf:self.values[(NSUInteger)index]] appendText:remainder];
}
@end
id 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 alloc] initWithDescription:description
forMatcher:matcher
overValues:valueList];
}

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 Decorates another matcher.
*/
@interface HCIs : HCBaseMatcher
- (instancetype)initWithMatcher:(id <HCMatcher>)matcher NS_DESIGNATED_INITIALIZER;
- (instancetype)init NS_UNAVAILABLE;
@end
FOUNDATION_EXPORT id HC_is(_Nullable id value);
#ifndef HC_DISABLE_SHORT_SYNTAX
/*!
* @abstract Wraps an existing matcher, or provides a shortcut to the frequently
* used <code>is(equalTo(x))</code>.
* @param value The matcher to satisfy, or an expected value for <em>equalTo</em> matching.
* @discussion
* If <em>value</em>is a matcher, its behavior is retained, but the test may be slightly more
* expressive. For example:
* <ul>
* <li><code>assertThat(\@(value), equalTo(\@5))</code></li>
* <li><code>assertThat(\@(value), is(equalTo(\@5)))</code></li>
* </ul>
*
* If <em>value</em>is not a matcher, it is wrapped in an <em>equalTo</em> matcher. This makes the
* following statements equivalent:
* <ul>
* <li><code>assertThat(cheese, equalTo(smelly))</code></li>
* <li><code>assertThat(cheese, is(equalTo(smelly)))</code></li>
* <li><code>assertThat(cheese, is(smelly))</code></li>
* </ul>
*
* Choose the style that makes your expression most readable. This will vary depending on context.
*
* <b>Name Clash</b><br />
* In the event of a name clash, <code>#define HC_DISABLE_SHORT_SYNTAX</code> and use the synonym
* HC_is instead.
*/
static inline id is(_Nullable id value)
{
return HC_is(value);
}
#endif
NS_ASSUME_NONNULL_END

View File

@@ -0,0 +1,44 @@
// OCHamcrest by Jon Reid, https://qualitycoding.org/
// Copyright 2019 hamcrest.org. See LICENSE.txt
#import "HCIs.h"
#import "HCWrapInMatcher.h"
@interface HCIs ()
@property (nonatomic, strong, readonly) id <HCMatcher> matcher;
@end
@implementation HCIs
- (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)describeMismatchOf:(nullable id)item to:(nullable id <HCDescription>)mismatchDescription
{
[self.matcher describeMismatchOf:item to:mismatchDescription];
}
- (void)describeTo:(id <HCDescription>)description
{
[description appendDescriptionOf:self.matcher];
}
@end
id HC_is(_Nullable id value)
{
return [[HCIs alloc] initWithMatcher:HCWrapInMatcher(value)];
}