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,43 @@
// OCHamcrest by Jon Reid, https://qualitycoding.org/
// Copyright 2019 hamcrest.org. See LICENSE.txt
#import <OCHamcrest/HCBaseMatcher.h>
NS_ASSUME_NONNULL_BEGIN
/*!
* @abstract Matchers numbers close to a value, within a delta range.
*/
@interface HCIsCloseTo : HCBaseMatcher
- (instancetype)initWithValue:(double)value delta:(double)delta NS_DESIGNATED_INITIALIZER;
- (instancetype)init NS_UNAVAILABLE;
@end
FOUNDATION_EXPORT id HC_closeTo(double value, double delta);
#ifndef HC_DISABLE_SHORT_SYNTAX
/*!
* @abstract Creates a matcher for NSNumbers that matches when the examined number is close to the
* specified value, within the specified delta.
* @param value The expected value of matching numbers.
* @param delta The delta within which matches will be allowed.
* @discussion Invokes <code>-doubleValue</code> on the examined number to get its value.
*
* <b>Example</b><br />
* <pre>assertThat(\@1.03, closeTo(1.0, 0.03)</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_closeTo instead.
*/
static inline id closeTo(double value, double delta)
{
return HC_closeTo(value, delta);
}
#endif
NS_ASSUME_NONNULL_END

View File

@@ -0,0 +1,69 @@
// OCHamcrest by Jon Reid, https://qualitycoding.org/
// Copyright 2019 hamcrest.org. See LICENSE.txt
#import "HCIsCloseTo.h"
@interface HCIsCloseTo ()
@property (nonatomic, assign, readonly) double value;
@property (nonatomic, assign, readonly) double delta;
@end
@implementation HCIsCloseTo
- (id)initWithValue:(double)value delta:(double)delta
{
self = [super init];
if (self)
{
_value = value;
_delta = delta;
}
return self;
}
- (BOOL)matches:(nullable id)item
{
if ([self itemIsNotNumber:item])
return NO;
return [self actualDelta:item] <= self.delta;
}
- (double)actualDelta:(id)item
{
return fabs([item doubleValue] - self.value);
}
- (BOOL)itemIsNotNumber:(id)item
{
return ![item isKindOfClass:[NSNumber class]];
}
- (void)describeMismatchOf:(nullable id)item to:(nullable id <HCDescription>)mismatchDescription
{
if ([self itemIsNotNumber:item])
[super describeMismatchOf:item to:mismatchDescription];
else
{
[[[mismatchDescription appendDescriptionOf:item]
appendText:@" differed by "]
appendDescriptionOf:@([self actualDelta:item])];
}
}
- (void)describeTo:(id <HCDescription>)description
{
[[[[description appendText:@"a numeric value within "]
appendDescriptionOf:@(self.delta)]
appendText:@" of "]
appendDescriptionOf:@(self.value)];
}
@end
id HC_closeTo(double value, double delta)
{
return [[HCIsCloseTo alloc] initWithValue:value delta:delta];
}

View File

@@ -0,0 +1,289 @@
// OCHamcrest by Jon Reid, https://qualitycoding.org/
// Copyright 2019 hamcrest.org. See LICENSE.txt
#import <OCHamcrest/HCBaseMatcher.h>
NS_ASSUME_NONNULL_BEGIN
FOUNDATION_EXPORT id HC_equalToChar(char value);
#ifndef HC_DISABLE_SHORT_SYNTAX
/*!
* @abstract Creates a matcher that matches when the examined object is equal to an NSNumber created
* from the specified char value.
* @param value The char value from which to create an NSNumber.
* @discussion Consider using <code>equalTo(\@(value))</code> instead.
*
* <b>Name Clash</b><br />
* In the event of a name clash, <code>#define HC_DISABLE_SHORT_SYNTAX</code> and use the synonym
* HC_equalToChar instead.
*/
static inline id equalToChar(char value)
{
return HC_equalToChar(value);
}
#endif
FOUNDATION_EXPORT id HC_equalToDouble(double value);
#ifndef HC_DISABLE_SHORT_SYNTAX
/*!
* @abstract Creates a matcher that matches when the examined object is equal to an NSNumber created
* from the specified double value.
* @param value The double value from which to create an NSNumber.
* @discussion Consider using <code>equalTo(\@(value))</code> instead.
*
* <b>Name Clash</b><br />
* In the event of a name clash, <code>#define HC_DISABLE_SHORT_SYNTAX</code> and use the synonym
* HC_equalToDouble instead.
*/
static inline id equalToDouble(double value)
{
return HC_equalToDouble(value);
}
#endif
FOUNDATION_EXPORT id HC_equalToFloat(float value);
#ifndef HC_DISABLE_SHORT_SYNTAX
/*!
* @abstract Creates a matcher that matches when the examined object is equal to an NSNumber created
* from the specified float value.
* @param value The float value from which to create an NSNumber.
* @discussion Consider using <code>equalTo(\@(value))</code> instead.
*
* <b>Name Clash</b><br />
* In the event of a name clash, <code>#define HC_DISABLE_SHORT_SYNTAX</code> and use the synonym
* HC_equalToFloat instead.
*/
static inline id equalToFloat(float value)
{
return HC_equalToFloat(value);
}
#endif
FOUNDATION_EXPORT id HC_equalToInt(int value);
#ifndef HC_DISABLE_SHORT_SYNTAX
/*!
* @abstract Creates a matcher that matches when the examined object is equal to an NSNumber created
* from the specified int value.
* @param value The int value from which to create an NSNumber.
* @discussion Consider using <code>equalTo(\@(value))</code> instead.
*
* <b>Name Clash</b><br />
* In the event of a name clash, <code>#define HC_DISABLE_SHORT_SYNTAX</code> and use the synonym
* HC_equalToInt instead.
*/
static inline id equalToInt(int value)
{
return HC_equalToInt(value);
}
#endif
FOUNDATION_EXPORT id HC_equalToLong(long value);
#ifndef HC_DISABLE_SHORT_SYNTAX
/*!
* @abstract Creates a matcher that matches when the examined object is equal to an NSNumber created
* from the specified long value.
* @param value The long value from which to create an NSNumber.
* @discussion Consider using <code>equalTo(\@(value))</code> instead.
*
* <b>Name Clash</b><br />
* In the event of a name clash, <code>#define HC_DISABLE_SHORT_SYNTAX</code> and use the synonym
* HC_equalToLong instead.
*/
static inline id equalToLong(long value)
{
return HC_equalToLong(value);
}
#endif
FOUNDATION_EXPORT id HC_equalToLongLong(long long value);
#ifndef HC_DISABLE_SHORT_SYNTAX
/*!
* @abstract Creates a matcher that matches when the examined object is equal to an NSNumber created
* from the specified long long value.
* @param value The long long value from which to create an NSNumber.
* @discussion Consider using <code>equalTo(\@(value))</code> instead.
*
* <b>Name Clash</b><br />
* In the event of a name clash, <code>#define HC_DISABLE_SHORT_SYNTAX</code> and use the synonym
* HC_equalToLongLong instead.
*/
static inline id equalToLongLong(long long value)
{
return HC_equalToLongLong(value);
}
#endif
FOUNDATION_EXPORT id HC_equalToShort(short value);
#ifndef HC_DISABLE_SHORT_SYNTAX
/*!
* @abstract Creates a matcher that matches when the examined object is equal to an NSNumber created
* from the specified short value.
* @param value The short value from which to create an NSNumber.
* @discussion Consider using <code>equalTo(\@(value))</code> instead.
*
* <b>Name Clash</b><br />
* In the event of a name clash, <code>#define HC_DISABLE_SHORT_SYNTAX</code> and use the synonym
* HC_equalToShort instead.
*/
static inline id equalToShort(short value)
{
return HC_equalToShort(value);
}
#endif
FOUNDATION_EXPORT id HC_equalToUnsignedChar(unsigned char value);
#ifndef HC_DISABLE_SHORT_SYNTAX
/*!
* @abstract equalToUnsignedChar(value) -
* Creates a matcher that matches when the examined object is equal to an NSNumber created from the
* specified unsigned char value.
* @param value The unsigned char value from which to create an NSNumber.
* @discussion Consider using <code>equalTo(\@(value))</code> instead.
*
* <b>Name Clash</b><br />
* In the event of a name clash, <code>#define HC_DISABLE_SHORT_SYNTAX</code> and use the synonym
* HC_equalToUnsignedChar instead.
*/
static inline id equalToUnsignedChar(unsigned char value)
{
return HC_equalToUnsignedChar(value);
}
#endif
FOUNDATION_EXPORT id HC_equalToUnsignedInt(unsigned int value);
#ifndef HC_DISABLE_SHORT_SYNTAX
/*!
* @abstract Creates a matcher that matches when the examined object is equal to an NSNumber created
* from the specified unsigned int value.
* @param value The unsigned int value from which to create an NSNumber.
* @discussion Consider using <code>equalTo(\@(value))</code> instead.
*
* <b>Name Clash</b><br />
* In the event of a name clash, <code>#define HC_DISABLE_SHORT_SYNTAX</code> and use the synonym
* HC_equalToUnsignedInt instead.
*/
static inline id equalToUnsignedInt(unsigned int value)
{
return HC_equalToUnsignedInt(value);
}
#endif
FOUNDATION_EXPORT id HC_equalToUnsignedLong(unsigned long value);
#ifndef HC_DISABLE_SHORT_SYNTAX
/*!
* @abstract Creates a matcher that matches when the examined object is equal to an NSNumber created
* from the specified unsigned long value.
* @param value The unsigned long value from which to create an NSNumber.
* @discussion Consider using <code>equalTo(\@(value))</code> instead.
*
* <b>Name Clash</b><br />
* In the event of a name clash, <code>#define HC_DISABLE_SHORT_SYNTAX</code> and use the synonym
* HC_equalToUnsignedLong instead.
*/
static inline id equalToUnsignedLong(unsigned long value)
{
return HC_equalToUnsignedLong(value);
}
#endif
FOUNDATION_EXPORT id HC_equalToUnsignedLongLong(unsigned long long value);
#ifndef HC_DISABLE_SHORT_SYNTAX
/*!
* @abstract Creates a matcher that matches when the examined object is equal to an NSNumber created
* from the specified unsigned long long value.
* @param value The unsigned long long value from which to create an NSNumber.
* @discussion Consider using <code>equalTo(\@(value))</code> instead.
*
* <b>Name Clash</b><br />
* In the event of a name clash, <code>#define HC_DISABLE_SHORT_SYNTAX</code> and use the synonym
* HC_equalToUnsignedLongLong instead.
*/
static inline id equalToUnsignedLongLong(unsigned long long value)
{
return HC_equalToUnsignedLongLong(value);
}
#endif
FOUNDATION_EXPORT id HC_equalToUnsignedShort(unsigned short value);
#ifndef HC_DISABLE_SHORT_SYNTAX
/*!
* @abstract Creates a matcher that matches when the examined object is equal to an NSNumber created
* from the specified unsigned short value.
* @param value The unsigned short value from which to create an NSNumber.
* @discussion Consider using <code>equalTo(\@(value))</code> instead.
*
* <b>Name Clash</b><br />
* In the event of a name clash, <code>#define HC_DISABLE_SHORT_SYNTAX</code> and use the synonym
* HC_equalToUnsignedShort instead.
*/
static inline id equalToUnsignedShort(unsigned short value)
{
return HC_equalToUnsignedShort(value);
}
#endif
FOUNDATION_EXPORT id HC_equalToInteger(NSInteger value);
#ifndef HC_DISABLE_SHORT_SYNTAX
/*!
* @abstract Creates a matcher that matches when the examined object is equal to an NSNumber created
* from the specified NSInteger value.
* @param value The NSInteger value from which to create an NSNumber.
* @discussion Consider using <code>equalTo(\@(value))</code> instead.
*
* <b>Name Clash</b><br />
* In the event of a name clash, <code>#define HC_DISABLE_SHORT_SYNTAX</code> and use the synonym
* HC_equalToInteger instead.
*/
static inline id equalToInteger(NSInteger value)
{
return HC_equalToInteger(value);
}
#endif
FOUNDATION_EXPORT id HC_equalToUnsignedInteger(NSUInteger value);
#ifndef HC_DISABLE_SHORT_SYNTAX
/*!
* @abstract Creates a matcher that matches when the examined object is equal to an NSNumber created
* from the specified NSUInteger value.
* @param value The NSUInteger value from which to create an NSNumber.
* @discussion Consider using <code>equalTo(\@(value))</code> instead.
*
* <b>Name Clash</b><br />
* In the event of a name clash, <code>#define HC_DISABLE_SHORT_SYNTAX</code> and use the synonym
* HC_equalToUnsignedInteger instead.
*/
static inline id equalToUnsignedInteger(NSUInteger value)
{
return HC_equalToUnsignedInteger(value);
}
#endif
NS_ASSUME_NONNULL_END

View File

@@ -0,0 +1,77 @@
// OCHamcrest by Jon Reid, https://qualitycoding.org/
// Copyright 2019 hamcrest.org. See LICENSE.txt
#import "HCIsEqualToNumber.h"
#import "HCIsEqual.h"
FOUNDATION_EXPORT id HC_equalToChar(char value)
{
return HC_equalTo(@(value));
}
FOUNDATION_EXPORT id HC_equalToDouble(double value)
{
return HC_equalTo(@(value));
}
FOUNDATION_EXPORT id HC_equalToFloat(float value)
{
return HC_equalTo(@(value));
}
FOUNDATION_EXPORT id HC_equalToInt(int value)
{
return HC_equalTo(@(value));
}
FOUNDATION_EXPORT id HC_equalToLong(long value)
{
return HC_equalTo(@(value));
}
FOUNDATION_EXPORT id HC_equalToLongLong(long long value)
{
return HC_equalTo(@(value));
}
FOUNDATION_EXPORT id HC_equalToShort(short value)
{
return HC_equalTo(@(value));
}
FOUNDATION_EXPORT id HC_equalToUnsignedChar(unsigned char value)
{
return HC_equalTo(@(value));
}
FOUNDATION_EXPORT id HC_equalToUnsignedInt(unsigned int value)
{
return HC_equalTo(@(value));
}
FOUNDATION_EXPORT id HC_equalToUnsignedLong(unsigned long value)
{
return HC_equalTo(@(value));
}
FOUNDATION_EXPORT id HC_equalToUnsignedLongLong(unsigned long long value)
{
return HC_equalTo(@(value));
}
FOUNDATION_EXPORT id HC_equalToUnsignedShort(unsigned short value)
{
return HC_equalTo(@(value));
}
FOUNDATION_EXPORT id HC_equalToInteger(NSInteger value)
{
return HC_equalTo(@(value));
}
FOUNDATION_EXPORT id HC_equalToUnsignedInteger(NSUInteger value)
{
return HC_equalTo(@(value));
}

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 true values.
*/
@interface HCIsTrue : HCBaseMatcher
@end
/*!
* @abstract Matches false values.
*/
@interface HCIsFalse : HCBaseMatcher
@end
FOUNDATION_EXPORT id HC_isTrue(void);
#ifndef HC_DISABLE_SHORT_SYNTAX
/*!
* @abstract Creates a matcher that matches when the examined object is an non-zero NSNumber.
* @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_isTrue instead.
*/
static inline id isTrue(void)
{
return HC_isTrue();
}
#endif
FOUNDATION_EXPORT id HC_isFalse(void);
#ifndef HC_DISABLE_SHORT_SYNTAX
/*!
* @abstract Creates a matcher that matches when the examined object is NSNumber zero.
* @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_isFalse instead.
*/
static inline id isFalse(void)
{
return HC_isFalse();
}
#endif
NS_ASSUME_NONNULL_END

View File

@@ -0,0 +1,55 @@
// OCHamcrest by Jon Reid, https://qualitycoding.org/
// Copyright 2019 hamcrest.org. See LICENSE.txt
#import "HCIsTrueFalse.h"
@implementation HCIsTrue
- (BOOL)matches:(nullable id)item
{
if (![item isKindOfClass:[NSNumber class]])
return NO;
return [item boolValue];
}
- (void)describeTo:(id <HCDescription>)description
{
[description appendText:@"true (non-zero)"];
}
@end
FOUNDATION_EXPORT id HC_isTrue(void)
{
return [[HCIsTrue alloc] init];
}
#pragma mark -
@implementation HCIsFalse
- (BOOL)matches:(nullable id)item
{
if (![item isKindOfClass:[NSNumber class]])
return NO;
return ![item boolValue];
}
- (void)describeTo:(id <HCDescription>)description
{
[description appendText:@"false (zero)"];
}
@end
FOUNDATION_EXPORT id HC_isFalse(void)
{
return [[HCIsFalse alloc] init];
}

View File

@@ -0,0 +1,340 @@
// OCHamcrest by Jon Reid, https://qualitycoding.org/
// Copyright 2019 hamcrest.org. See LICENSE.txt
#import <Foundation/Foundation.h>
@protocol HCMatcher;
NS_ASSUME_NONNULL_BEGIN
FOUNDATION_EXPORT void HC_assertThatBoolWithLocation(id testCase, BOOL actual,
id <HCMatcher> matcher, char const *fileName, int lineNumber);
#define HC_assertThatBool(actual, matcher) \
HC_assertThatBoolWithLocation(self, actual, matcher, __FILE__, __LINE__)
#ifndef HC_DISABLE_SHORT_SYNTAX
/*!
* @abstract assertThatBool(actual, matcher) -
* Asserts that BOOL actual value, converted to an NSNumber, satisfies matcher.
* @param actual The BOOL value to convert to an NSNumber for evaluation.
* @param matcher The matcher to satisfy as the expected condition.
* @discussion Consider using <code>assertThat(\@(actual), matcher)</code> instead.
*
* <b>Name Clash</b><br />
* In the event of a name clash, <code>#define HC_DISABLE_SHORT_SYNTAX</code> and use the synonym
* HC_assertThatBool instead.
*/
#define assertThatBool(actual, matcher) HC_assertThatBool(actual, matcher)
#endif
FOUNDATION_EXPORT void HC_assertThatCharWithLocation(id testCase, char actual,
id <HCMatcher> matcher, char const *fileName, int lineNumber);
#define HC_assertThatChar(actual, matcher) \
HC_assertThatCharWithLocation(self, actual, matcher, __FILE__, __LINE__)
#ifndef HC_DISABLE_SHORT_SYNTAX
/*!
* @abstract assertThatChar(actual, matcher) -
* Asserts that char actual value, converted to an NSNumber, satisfies matcher.
* @param actual The char value to convert to an NSNumber for evaluation.
* @param matcher The matcher to satisfy as the expected condition.
* @discussion Consider using <code>assertThat(\@(actual), matcher)</code> instead.
*
* <b>Name Clash</b><br />
* In the event of a name clash, <code>#define HC_DISABLE_SHORT_SYNTAX</code> and use the synonym
* HC_assertThatChar instead.
*/
#define assertThatChar(actual, matcher) HC_assertThatChar(actual, matcher)
#endif
FOUNDATION_EXPORT void HC_assertThatDoubleWithLocation(id testCase, double actual,
id <HCMatcher> matcher, char const *fileName, int lineNumber);
#define HC_assertThatDouble(actual, matcher) \
HC_assertThatDoubleWithLocation(self, actual, matcher, __FILE__, __LINE__)
#ifndef HC_DISABLE_SHORT_SYNTAX
/*!
* @abstract HC_assertThatDouble(actual, matcher) -
* Asserts that double actual value, converted to an NSNumber, satisfies matcher.
* @param actual The double value to convert to an NSNumber for evaluation.
* @param matcher The matcher to satisfy as the expected condition.
* @discussion Consider using <code>assertThat(\@(actual), matcher)</code> instead.
*
* <b>Name Clash</b><br />
* In the event of a name clash, <code>#define HC_DISABLE_SHORT_SYNTAX</code> and use the synonym
* HC_assertThatDouble instead.
*/
#define assertThatDouble(actual, matcher) HC_assertThatDouble(actual, matcher)
#endif
FOUNDATION_EXPORT void HC_assertThatFloatWithLocation(id testCase, float actual,
id <HCMatcher> matcher, char const *fileName, int lineNumber);
#define HC_assertThatFloat(actual, matcher) \
HC_assertThatFloatWithLocation(self, actual, matcher, __FILE__, __LINE__)
#ifndef HC_DISABLE_SHORT_SYNTAX
/*!
* @abstract assertThatFloat(actual, matcher) -
* Asserts that float actual value, converted to an NSNumber, satisfies matcher.
* @param actual The float value to convert to an NSNumber for evaluation.
* @param matcher The matcher to satisfy as the expected condition.
* @discussion Consider using <code>assertThat(\@(actual), matcher)</code> instead.
*
* <b>Name Clash</b><br />
* In the event of a name clash, <code>#define HC_DISABLE_SHORT_SYNTAX</code> and use the synonym
* HC_assertThatFloat instead.
*/
#define assertThatFloat(actual, matcher) HC_assertThatFloat(actual, matcher)
#endif
FOUNDATION_EXPORT void HC_assertThatIntWithLocation(id testCase, int actual,
id <HCMatcher> matcher, char const *fileName, int lineNumber);
#define HC_assertThatInt(actual, matcher) \
HC_assertThatIntWithLocation(self, actual, matcher, __FILE__, __LINE__)
#ifndef HC_DISABLE_SHORT_SYNTAX
/*!
* @abstract assertThatInt(actual, matcher) -
* Asserts that int actual value, converted to an NSNumber, satisfies matcher.
* @param actual The int value to convert to an NSNumber for evaluation.
* @param matcher The matcher to satisfy as the expected condition.
* @discussion Consider using <code>assertThat(\@(actual), matcher)</code> instead.
*
* <b>Name Clash</b><br />
* In the event of a name clash, <code>#define HC_DISABLE_SHORT_SYNTAX</code> and use the synonym
* HC_assertThatInt instead.
*/
#define assertThatInt(actual, matcher) HC_assertThatInt(actual, matcher)
#endif
FOUNDATION_EXPORT void HC_assertThatLongWithLocation(id testCase, long actual,
id <HCMatcher> matcher, char const *fileName, int lineNumber);
#define HC_assertThatLong(actual, matcher) \
HC_assertThatLongWithLocation(self, actual, matcher, __FILE__, __LINE__)
#ifndef HC_DISABLE_SHORT_SYNTAX
/*!
* @abstract assertThatLong(actual, matcher) -
* Asserts that long actual value, converted to an NSNumber, satisfies matcher.
* @param actual The long value to convert to an NSNumber for evaluation.
* @param matcher The matcher to satisfy as the expected condition.
* @discussion Consider using <code>assertThat(\@(actual), matcher)</code> instead.
*
* <b>Name Clash</b><br />
* In the event of a name clash, <code>#define HC_DISABLE_SHORT_SYNTAX</code> and use the synonym
* HC_assertThatLong instead.
*/
#define assertThatLong(actual, matcher) HC_assertThatLong(actual, matcher)
#endif
FOUNDATION_EXPORT void HC_assertThatLongLongWithLocation(id testCase, long long actual,
id <HCMatcher> matcher, char const *fileName, int lineNumber);
#define HC_assertThatLongLong(actual, matcher) \
HC_assertThatLongLongWithLocation(self, actual, matcher, __FILE__, __LINE__)
#ifndef HC_DISABLE_SHORT_SYNTAX
/*!
* @abstract assertThatLongLong(actual, matcher) -
* Asserts that <code>long long</code> actual value, converted to an NSNumber, satisfies matcher.
* @param actual The long long value to convert to an NSNumber for evaluation.
* @param matcher The matcher to satisfy as the expected condition.
* @discussion Consider using <code>assertThat(\@(actual), matcher)</code> instead.
*
* <b>Name Clash</b><br />
* In the event of a name clash, <code>#define HC_DISABLE_SHORT_SYNTAX</code> and use the synonym
* HC_assertThatLongLong instead.
*/
#define assertThatLongLong(actual, matcher) HC_assertThatLongLong(actual, matcher)
#endif
FOUNDATION_EXPORT void HC_assertThatShortWithLocation(id testCase, short actual,
id <HCMatcher> matcher, char const *fileName, int lineNumber);
#define HC_assertThatShort(actual, matcher) \
HC_assertThatShortWithLocation(self, actual, matcher, __FILE__, __LINE__)
#ifndef HC_DISABLE_SHORT_SYNTAX
/*!
* @abstract assertThatShort(actual, matcher) -
* Asserts that short actual value, converted to an NSNumber, satisfies matcher.
* @param actual The short value to convert to an NSNumber for evaluation.
* @param matcher The matcher to satisfy as the expected condition.
* @discussion Consider using <code>assertThat(\@(actual), matcher)</code> instead.
*
* <b>Name Clash</b><br />
* In the event of a name clash, <code>#define HC_DISABLE_SHORT_SYNTAX</code> and use the synonym
* HC_assertThatShort instead.
*/
#define assertThatShort(actual, matcher) HC_assertThatShort(actual, matcher)
#endif
FOUNDATION_EXPORT void HC_assertThatUnsignedCharWithLocation(id testCase, unsigned char actual,
id <HCMatcher> matcher, char const *fileName, int lineNumber);
#define HC_assertThatUnsignedChar(actual, matcher) \
HC_assertThatUnsignedCharWithLocation(self, actual, matcher, __FILE__, __LINE__)
#ifndef HC_DISABLE_SHORT_SYNTAX
/*!
* @abstract assertThatUnsignedChar(actual, matcher) -
* Asserts that unsigned char actual value, converted to an NSNumber, satisfies matcher.
* @param actual The unsigned char value to convert to an NSNumber for evaluation.
* @param matcher The matcher to satisfy as the expected condition.
* @discussion Consider using <code>assertThat(\@(actual), matcher)</code> instead.
*
* <b>Name Clash</b><br />
* In the event of a name clash, <code>#define HC_DISABLE_SHORT_SYNTAX</code> and use the synonym
* HC_assertThatUnsignedChar instead.
*/
#define assertThatUnsignedChar(actual, matcher) HC_assertThatUnsignedChar(actual, matcher)
#endif
FOUNDATION_EXPORT void HC_assertThatUnsignedIntWithLocation(id testCase, unsigned int actual,
id <HCMatcher> matcher, char const *fileName, int lineNumber);
#define HC_assertThatUnsignedInt(actual, matcher) \
HC_assertThatUnsignedIntWithLocation(self, actual, matcher, __FILE__, __LINE__)
#ifndef HC_DISABLE_SHORT_SYNTAX
/*!
* @abstract assertThatUnsignedInt(actual, matcher) -
* Asserts that unsigned int actual value, converted to an NSNumber, satisfies matcher.
* @param actual The unsigned int value to convert to an NSNumber for evaluation.
* @param matcher The matcher to satisfy as the expected condition.
* @discussion Consider using <code>assertThat(\@(actual), matcher)</code> instead.
*
* <b>Name Clash</b><br />
* In the event of a name clash, <code>#define HC_DISABLE_SHORT_SYNTAX</code> and use the synonym
* HC_assertThatUnsignedInt instead.
*/
#define assertThatUnsignedInt(actual, matcher) HC_assertThatUnsignedInt(actual, matcher)
#endif
FOUNDATION_EXPORT void HC_assertThatUnsignedLongWithLocation(id testCase, unsigned long actual,
id <HCMatcher> matcher, char const *fileName, int lineNumber);
#define HC_assertThatUnsignedLong(actual, matcher) \
HC_assertThatUnsignedLongWithLocation(self, actual, matcher, __FILE__, __LINE__)
#ifndef HC_DISABLE_SHORT_SYNTAX
/*!
* @abstract assertThatUnsignedLong(actual, matcher) -
* Asserts that unsigned long actual value, converted to an NSNumber, satisfies matcher.
* @param actual The unsigned long value to convert to an NSNumber for evaluation.
* @param matcher The matcher to satisfy as the expected condition.
* @discussion Consider using <code>assertThat(\@(actual), matcher)</code> instead.
*
* <b>Name Clash</b><br />
* In the event of a name clash, <code>#define HC_DISABLE_SHORT_SYNTAX</code> and use the synonym
* HC_assertThatUnsignedLong instead.
*/
#define assertThatUnsignedLong(actual, matcher) HC_assertThatUnsignedLong(actual, matcher)
#endif
FOUNDATION_EXPORT void HC_assertThatUnsignedLongLongWithLocation(id testCase, unsigned long long actual,
id <HCMatcher> matcher, char const *fileName, int lineNumber);
#define HC_assertThatUnsignedLongLong(actual, matcher) \
HC_assertThatUnsignedLongLongWithLocation(self, actual, matcher, __FILE__, __LINE__)
#ifndef HC_DISABLE_SHORT_SYNTAX
/*!
* @abstract assertThatUnsignedLongLong(actual, matcher) -
* Asserts that unsigned long long actual value, converted to an NSNumber, satisfies matcher.
* @param actual The unsigned long long value to convert to an NSNumber for evaluation.
* @param matcher The matcher to satisfy as the expected condition.
* @discussion Consider using <code>assertThat(\@(actual), matcher)</code> instead.
*
* <b>Name Clash</b><br />
* In the event of a name clash, <code>#define HC_DISABLE_SHORT_SYNTAX</code> and use the synonym
* HC_assertThatUnsignedLongLong instead.
*/
#define assertThatUnsignedLongLong(actual, matcher) HC_assertThatUnsignedLongLong(actual, matcher)
#endif
FOUNDATION_EXPORT void HC_assertThatUnsignedShortWithLocation(id testCase, unsigned short actual,
id <HCMatcher> matcher, char const *fileName, int lineNumber);
#define HC_assertThatUnsignedShort(actual, matcher) \
HC_assertThatUnsignedShortWithLocation(self, actual, matcher, __FILE__, __LINE__)
#ifndef HC_DISABLE_SHORT_SYNTAX
/*!
* @abstract assertThatUnsignedShort(actual, matcher) -
* Asserts that unsigned short actual value, converted to an NSNumber, satisfies matcher.
* @param actual The unsigned short value to convert to an NSNumber for evaluation.
* @param matcher The matcher to satisfy as the expected condition.
* @discussion Consider using <code>assertThat(\@(actual), matcher)</code> instead.
*
* <b>Name Clash</b><br />
* In the event of a name clash, <code>#define HC_DISABLE_SHORT_SYNTAX</code> and use the synonym
* HC_assertThatUnsignedShort instead.
*/
#define assertThatUnsignedShort(actual, matcher) HC_assertThatUnsignedShort(actual, matcher)
#endif
FOUNDATION_EXPORT void HC_assertThatIntegerWithLocation(id testCase, NSInteger actual,
id <HCMatcher> matcher, char const *fileName, int lineNumber);
#define HC_assertThatInteger(actual, matcher) \
HC_assertThatIntegerWithLocation(self, actual, matcher, __FILE__, __LINE__)
#ifndef HC_DISABLE_SHORT_SYNTAX
/*!
* @abstract assertThatInteger(actual, matcher) -
* Asserts that NSInteger actual value, converted to an NSNumber, satisfies matcher.
* @param actual The NSInteger value to convert to an NSNumber for evaluation.
* @param matcher The matcher to satisfy as the expected condition.
* @discussion Consider using <code>assertThat(\@(actual), matcher)</code> instead.
*
* <b>Name Clash</b><br />
* In the event of a name clash, <code>#define HC_DISABLE_SHORT_SYNTAX</code> and use the synonym
* HC_assertThatInteger instead.
*/
#define assertThatInteger(actual, matcher) HC_assertThatInteger(actual, matcher)
#endif
FOUNDATION_EXPORT void HC_assertThatUnsignedIntegerWithLocation(id testCase, NSUInteger actual,
id <HCMatcher> matcher, char const *fileName, int lineNumber);
#define HC_assertThatUnsignedInteger(actual, matcher) \
HC_assertThatUnsignedIntegerWithLocation(self, actual, matcher, __FILE__, __LINE__)
#ifndef HC_DISABLE_SHORT_SYNTAX
/*!
* @abstract assertThatUnsignedInteger(actual, matcher) -
* Asserts that NSUInteger actual value, converted to an NSNumber, satisfies matcher.
* @param actual The NSUInteger value to convert to an NSNumber for evaluation.
* @param matcher The matcher to satisfy as the expected condition.
* @discussion Consider using <code>assertThat(\@(actual), matcher)</code> instead.
*
* <b>Name Clash</b><br />
* In the event of a name clash, <code>#define HC_DISABLE_SHORT_SYNTAX</code> and use the synonym
* HC_assertThatUnsignedInteger instead.
*/
#define assertThatUnsignedInteger(actual, matcher) HC_assertThatUnsignedInteger(actual, matcher)
#endif
NS_ASSUME_NONNULL_END

View File

@@ -0,0 +1,97 @@
// OCHamcrest by Jon Reid, https://qualitycoding.org/
// Copyright 2019 hamcrest.org. See LICENSE.txt
#import "HCNumberAssert.h"
#import "HCAssertThat.h"
FOUNDATION_EXPORT void HC_assertThatBoolWithLocation(id testCase, BOOL actual,
id <HCMatcher> matcher, char const * fileName, int lineNumber)
{
HC_assertThatWithLocation(testCase, @(actual), matcher, fileName, lineNumber);
}
FOUNDATION_EXPORT void HC_assertThatCharWithLocation(id testCase, char actual,
id <HCMatcher> matcher, char const * fileName, int lineNumber)
{
HC_assertThatWithLocation(testCase, @(actual), matcher, fileName, lineNumber);
}
FOUNDATION_EXPORT void HC_assertThatDoubleWithLocation(id testCase, double actual,
id <HCMatcher> matcher, char const * fileName, int lineNumber)
{
HC_assertThatWithLocation(testCase, @(actual), matcher, fileName, lineNumber);
}
FOUNDATION_EXPORT void HC_assertThatFloatWithLocation(id testCase, float actual,
id <HCMatcher> matcher, char const * fileName, int lineNumber)
{
HC_assertThatWithLocation(testCase, @(actual), matcher, fileName, lineNumber);
}
FOUNDATION_EXPORT void HC_assertThatIntWithLocation(id testCase, int actual,
id <HCMatcher> matcher, char const * fileName, int lineNumber)
{
HC_assertThatWithLocation(testCase, @(actual), matcher, fileName, lineNumber);
}
FOUNDATION_EXPORT void HC_assertThatLongWithLocation(id testCase, long actual,
id <HCMatcher> matcher, char const * fileName, int lineNumber)
{
HC_assertThatWithLocation(testCase, @(actual), matcher, fileName, lineNumber);
}
FOUNDATION_EXPORT void HC_assertThatLongLongWithLocation(id testCase, long long actual,
id <HCMatcher> matcher, char const * fileName, int lineNumber)
{
HC_assertThatWithLocation(testCase, @(actual), matcher, fileName, lineNumber);
}
FOUNDATION_EXPORT void HC_assertThatShortWithLocation(id testCase, short actual,
id <HCMatcher> matcher, char const * fileName, int lineNumber)
{
HC_assertThatWithLocation(testCase, @(actual), matcher, fileName, lineNumber);
}
FOUNDATION_EXPORT void HC_assertThatUnsignedCharWithLocation(id testCase, unsigned char actual,
id <HCMatcher> matcher, char const * fileName, int lineNumber)
{
HC_assertThatWithLocation(testCase, @(actual), matcher, fileName, lineNumber);
}
FOUNDATION_EXPORT void HC_assertThatUnsignedIntWithLocation(id testCase, unsigned int actual,
id <HCMatcher> matcher, char const * fileName, int lineNumber)
{
HC_assertThatWithLocation(testCase, @(actual), matcher, fileName, lineNumber);
}
FOUNDATION_EXPORT void HC_assertThatUnsignedLongWithLocation(id testCase, unsigned long actual,
id <HCMatcher> matcher, char const * fileName, int lineNumber)
{
HC_assertThatWithLocation(testCase, @(actual), matcher, fileName, lineNumber);
}
FOUNDATION_EXPORT void HC_assertThatUnsignedLongLongWithLocation(id testCase, unsigned long long actual,
id <HCMatcher> matcher, char const * fileName, int lineNumber)
{
HC_assertThatWithLocation(testCase, @(actual), matcher, fileName, lineNumber);
}
FOUNDATION_EXPORT void HC_assertThatUnsignedShortWithLocation(id testCase, unsigned short actual,
id <HCMatcher> matcher, char const * fileName, int lineNumber)
{
HC_assertThatWithLocation(testCase, @(actual), matcher, fileName, lineNumber);
}
FOUNDATION_EXPORT void HC_assertThatIntegerWithLocation(id testCase, NSInteger actual,
id <HCMatcher> matcher, char const * fileName, int lineNumber)
{
HC_assertThatWithLocation(testCase, @(actual), matcher, fileName, lineNumber);
}
FOUNDATION_EXPORT void HC_assertThatUnsignedIntegerWithLocation(id testCase, NSUInteger actual,
id <HCMatcher> matcher, char const * fileName, int lineNumber)
{
HC_assertThatWithLocation(testCase, @(actual), matcher, fileName, lineNumber);
}

View File

@@ -0,0 +1,114 @@
// OCHamcrest by Jon Reid, https://qualitycoding.org/
// Copyright 2019 hamcrest.org. See LICENSE.txt
#import <OCHamcrest/HCBaseMatcher.h>
NS_ASSUME_NONNULL_BEGIN
/*!
* @abstract Matches values with <code>-compare:</code>.
*/
@interface HCOrderingComparison : HCBaseMatcher
- (instancetype)initComparing:(id)expectedValue
minCompare:(NSComparisonResult)min
maxCompare:(NSComparisonResult)max
comparisonDescription:(NSString *)comparisonDescription NS_DESIGNATED_INITIALIZER;
- (instancetype)init NS_UNAVAILABLE;
@end
FOUNDATION_EXPORT id HC_greaterThan(id value);
#ifndef HC_DISABLE_SHORT_SYNTAX
/*!
* @abstract Creates a matcher that matches when the examined object is greater than the specified
* value, as reported by the <code>-compare:</code> method of the <b>examined</b> object.
* @param value The value which, when passed to the <code>-compare:</code> method of the examined
* object, should return NSOrderedAscending.
* @discussion
* <b>Example</b><br />
* <pre>assertThat(\@2, greaterThan(\@1))</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_greaterThan instead.
*/
static inline id greaterThan(id value)
{
return HC_greaterThan(value);
}
#endif
FOUNDATION_EXPORT id HC_greaterThanOrEqualTo(id value);
#ifndef HC_DISABLE_SHORT_SYNTAX
/*!
* @abstract Creates a matcher that matches when the examined object is greater than or equal to the
* specified value, as reported by the <code>-compare:</code> method of the <b>examined</b> object.
* @param value The value which, when passed to the <code>-compare:</code> method of the examined
* object, should return NSOrderedAscending or NSOrderedSame.
* @discussion
* <b>Example</b><br />
* <pre>assertThat(\@1, greaterThanOrEqualTo(\@1))</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_greaterThanOrEqualTo instead.
*/
static inline id greaterThanOrEqualTo(id value)
{
return HC_greaterThanOrEqualTo(value);
}
#endif
FOUNDATION_EXPORT id HC_lessThan(id value);
#ifndef HC_DISABLE_SHORT_SYNTAX
/*!
* @abstract Creates a matcher that matches when the examined object is less than the specified
* value, as reported by the <code>-compare:</code> method of the <b>examined</b> object.
* @param value The value which, when passed to the <code>-compare:</code> method of the examined
* object, should return NSOrderedDescending.
* @discussion
* <b>Example</b><br />
* <pre>assertThat(\@1, lessThan(\@2))</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_lessThan instead.
*/
static inline id lessThan(id value)
{
return HC_lessThan(value);
}
#endif
FOUNDATION_EXPORT id HC_lessThanOrEqualTo(id value);
#ifndef HC_DISABLE_SHORT_SYNTAX
/*!
* @abstract Creates a matcher that matches when the examined object is less than or equal to the
* specified value, as reported by the <code>-compare:</code> method of the <b>examined</b> object.
* @param value The value which, when passed to the <code>-compare:</code> method of the examined
* object, should return NSOrderedDescending or NSOrderedSame.
* @discussion
* <b>Example</b><br />
* <pre>assertThat(\@1, lessThanOrEqualTo(\@1))</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_lessThanOrEqualTo instead.
*/
static inline id lessThanOrEqualTo(id value)
{
return HC_lessThanOrEqualTo(value);
}
#endif
NS_ASSUME_NONNULL_END

View File

@@ -0,0 +1,97 @@
// OCHamcrest by Jon Reid, https://qualitycoding.org/
// Copyright 2019 hamcrest.org. See LICENSE.txt
#import "HCOrderingComparison.h"
@interface HCOrderingComparison ()
@property (nonatomic, strong, readonly) id expected;
@property (nonatomic, assign, readonly) NSComparisonResult minCompare;
@property (nonatomic, assign, readonly) NSComparisonResult maxCompare;
@property (nonatomic, copy, readonly) NSString *comparisonDescription;
@end
@implementation HCOrderingComparison
- (instancetype)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:(nullable id)item
{
if (item == nil)
return NO;
NSComparisonResult compare;
@try
{
compare = [self.expected compare:item];
}
@catch (NSException *e)
{
return NO;
}
return self.minCompare <= compare && compare <= self.maxCompare;
}
- (void)describeTo:(id <HCDescription>)description
{
[[[[description appendText:@"a value "]
appendText:self.comparisonDescription]
appendText:@" "]
appendDescriptionOf:self.expected];
}
@end
id HC_greaterThan(id value)
{
return [[HCOrderingComparison alloc] initComparing:value
minCompare:NSOrderedAscending
maxCompare:NSOrderedAscending
comparisonDescription:@"greater than"];
}
id HC_greaterThanOrEqualTo(id value)
{
return [[HCOrderingComparison alloc] initComparing:value
minCompare:NSOrderedAscending
maxCompare:NSOrderedSame
comparisonDescription:@"greater than or equal to"];
}
id HC_lessThan(id value)
{
return [[HCOrderingComparison alloc] initComparing:value
minCompare:NSOrderedDescending
maxCompare:NSOrderedDescending
comparisonDescription:@"less than"];
}
id HC_lessThanOrEqualTo(id value)
{
return [[HCOrderingComparison alloc] initComparing:value
minCompare:NSOrderedSame
maxCompare:NSOrderedDescending
comparisonDescription:@"less than or equal to"];
}