This commit is contained in:
giuseppenuc committed 2016-02-24 16:56:39 +01:00
1 parent d281d765ea
commit 5b074a5176
1261 files changed
+199158 -7303

No files matched your search

@@ -0,0 +1,7 @@
.DS_Store
.idea
build/
*.pbxuser
*.perspectivev3
project.xcworkspace/
xcuserdata/
@@ -0,0 +1,3 @@
[submodule "Source/XcodeCoverage"]
path = Source/XcodeCoverage
url = git://github.com/jonreid/XcodeCoverage.git
+209
View File
@@ -0,0 +1,209 @@
== NEXT VERSION IN PROGRESS
* Removed CocoaPods spec, since it's maintained at CocoaPods.
* Fixed unit tests so they remain quiet when handling expected test failures.
* Replaced older code coverage scripts with XcodeCoverage submodule.
== Version 1.9 ==
23 Nov 2012
* Improved matchers:
- Changed hasCount/hasCountOf mismatch description so that count comes first (if object has a count).
* Project changes:
- Fixed warnings revealed by latest Xcode. Thanks to: David Hart
- Changed iOS Architecture support to "Standard" (which includes armv7s)
- Changed Mac Architecture support to 64-bit only
- Converted source, tests, and examples to ARC
== Version 1.8 ==
09 Jul 2012
The primary purpose of this release is to make it easier to add OCHamcrest to iOS projects. No more need to specify "Other Linker Flags"! Depending on your project, you may be able to eliminate:
* -lstdc++
* -ObjC
Also, the repository has a new official home: https://github.com/hamcrest/OCHamcrest/
* No need to specify "Other Linker Flags" in iOS projects:
- Changed all Objective-C++ to Objective-C
- Eliminated categories
* Deprecated:
- C++ template function boxNumber.
- conformsToProtocol clashed with the method of the same name. It has been renamed to "conformsTo".
* Deleted following items deprecated in v1.2:
- -[HCDescription appendValue]
- +[HCInvocationMatcher createInvocationForSelector:onClass:]
- NSObject+SelfDescribingValue
== Version 1.7 ==
20 Feb 2012
* New matchers:
- "conformsToProtocol" matches objects that conform to a given protocol. Thanks to: Todd Farrell
* Improved matchers:
- "hasProperty" now works for methods with primitive return types. Thanks to: Christopher Pickslay
* Other improvements:
- Rewrote introductory sections of documentation.
== Version 1.6 ==
27 Sep 2011
* New matchers:
- "hasProperty" matches the return value of a method with a given name. (It could be a property, but really can be any method with no arguments that returns an object.) Thanks to: Justin Shacklette
* Improvements:
- Rewrote documentation.
- Matchers that require a nil-terminated list now generate a compiler error if you don't have nil at the end.
* Fixes:
- "stringContainsInOrder" was missing from the master header; now it's there.
== Version 1.5 ==
29 Apr 2011
* Fixed crash when trying to describe an object with nil description.
* Packaging:
- Updated project to Xcode 4. iOS framework / documentation / distribution scripts are now external, run from command-line instead of Xcode.
- Improved documentation by adding Factory headings pointing from implementing classes back to their factories.
* New matcher:
- "stringContainsInOrder" matches string containing given list of substrings, in order.
* Improved matchers:
- Changed "sameInstance" mismatch description to omit address when describing nil.
- For consistency, changed "anyOf" and "allOf" to implicitly wrap non-matcher values in equalTo.
== Version 1.4 ==
13 Feb 2011
* New matchers:
- "hasEntries" matches dictionary containing key-value pairs satisfying a given list of alternating keys and value matchers.
* Added complete descriptions to macros so they appear in Xcode 4 Quick Help. (Couldn't add arguments to macros without breaking backwards compatibility.)
* Improved descriptions:
- Improved description of "hasEntry", removing colon so it doesn't get truncated in Xcode's error display.
- "is" no longer says "is ..." in its description, but just lets the inner description pass through.
- Consistently use articles to begin descriptions, such as "a dictionary containing" instead of "dictionary containing".
== Version 1.3 ==
05 Jan 2011
* Improved descriptions and mismatch descriptions of several matchers, including:
- Fixed "contains" and "containsInAnyOrder" to describe mismatch if item is not a collection.
- Fixed "describedAs" and "is" to use their nested matchers to generate mismatch descriptions.
- "sameInstance" is more readable, and includes object memory addresses.
- If object has a count, "hasCount" mismatch describes actual count.
- Don't wrap angle brackets around a description that already has them.
- Improved readability of several matchers.
* "instanceOf" now guards against nil being passed as the expected type.
== Version 1.2 ==
03 Jan 2011
* New matchers:
- "hasCount" matches collections for which -count satisfies a given matcher.
- "hasCountOf" matches collections for which -count equals a given count.
- "empty" matches empty collection.
* Fixed assertThat to describe the diagnosis of the mismatch, not just the mismatched value.
* Expanded helper class HCInvocationMatcher:
- New property "shortMismatchDescription" determines whether mismatch description is short or long. Default is long description.
- New method -invokeOn: invokes stored invocation on given item.
* Since nil cannot be directly stored in collections, collection matchers now guard against nil.
* Expanded BaseDescription's -appendDescriptionOf: to handle all types of values, not just self-describing values.
* Deprecated:
- Description's -appendValue: no longer needed; call -appendDescriptionOf: instead. This also means NSObject+SelfDescribingValue is no longer needed.
- Renamed HCInvocation's helper class method +createInvocationForSelector:onClass: to +invocationForSelector:onClass:
- New helper function HCRequireNonNilObject should be used in place of HCRequireNonNilString.
== Version 1.1.2 ==
28 Dec 2010
* New matchers:
- "contains" matches collection containing matching items in order.
- "containsInAnyOrder" matches collection containing matching items in any order.
* Fixed crash that occurred when trying to describe the matchers allOf, anyOf and isIn on iOS. Related to -ObjC linker flag.
* Changed documentation from HTML to Xcode documentation set. Run "make install" from the Documentation folder to install.
* Rearranged documentation modules to make things easier to find.
* Changed convenience methods to invoke superclass and return id, to support possibility of subclassing matchers.
1.1.2 fixes to 1.1:
- Added the new matchers to the master header and to the iOS target.
- Fixed distribution zip file to preserve symlinks in frameworks.
== Version 1.0 ==
26 Oct 2010
First official release, including:
* Documentation
* Examples for
- Cocoa
- iOS
- Creating a custom matcher
07 Oct 2010
* For iOS: Added OCHamcrestIOS.framework target which provides release builds for both simulator and device into a single framework. Yes, a framework that can be used for iOS development without requiring users to mess with header search paths and link settings. Simply drop the framework into your project and #import <OCHamcrestIOS/OCHamcrestIOS.h> - Aaron Jacobs
06 Oct 2010
* Work around bug in iPhone simulator that causes a test failure to terminate the app. Fix provided by Aaron Jacobs.
06 Sep 2010
* Added static library target and changes for iOS.
01 Dec 2009
* Added assertThat___ and equalTo___ for all types understood by NSNumber. For example: assertThatInt(42, equalToInt(42))
24 Nov 2009
* Changed assertThat behavior to work more seamlessly with OCUnit: Instead of throwing an exception, it calls the same method as OCUnit's assertion macros to fail the test. As a result, a failing assertThat will not terminate the test, so that the test can record other failures. (Following normal OCUnit behavior, you can instruct the test case to terminate at the first failure by invoking raiseAfterFailure.)
This change requires that assertThat be called only within subclasses of SenTestCase, which wasn't the case before. You will need to recompile your tests.
If you need an original-style assertion that can be called outside of a SenTestCase, email your request to hamcrest-dev@googlegroups.com
24 Nov 2009
* Support Xcode 3.2's redesigned Build Results window by removing colons from assertThat description.
17 Oct 2009
* Added helper class HCInvocationMatcher for building other matchers from NSInvocations. See HCHasDescription for an example.
11 Aug 2009
* Renamed framework to OCHamcrest.
07 Jul 2009
* Added support for Mac OS X 10.4 projects.
28 Jan 2009
* Fixed compiler errors when used with Objective-C++ (.mm files).
24 Jan 2009
* Added means for matchers to describe mismatches. You can use either matches:describingMismatchTo: to do it one shot, or call describeMismatchOf:To: once you know a particular item does not match.
18 Jul 2008
* Changed matchers whose description looks similar to a function call so that the description matches the name of the factory function.
13 Apr 2008
* Initial release
File diff suppressed because it is too large. Load diff
@@ -0,0 +1,9 @@
DOCSET_NAME=org.hamcrest.OCHamcrest.docset
DESTDIR=~/Library/Developer/Shared/Documentation/DocSets
install:
mkdir -p $(DESTDIR)
cp -R $(DOCSET_NAME) $(DESTDIR)
uninstall:
rm -rf $(DESTDIR)/$(DOCSET_NAME)
@@ -0,0 +1,3 @@
Run "make install" to install the OCHamcrest documentation so that it can be opened in the Xcode documentation window.
Run "make uninstall" to remove.
@@ -0,0 +1,270 @@
// !$*UTF8*$!
{
archiveVersion = 1;
classes = {
};
objectVersion = 46;
objects = {
/* Begin PBXBuildFile section */
0817B62B147ED03A00C5401D /* SenTestingKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 0817B62A147ED03A00C5401D /* SenTestingKit.framework */; };
089BA20D1298F19A00D4F34F /* IsGivenDayOfWeek.m in Sources */ = {isa = PBXBuildFile; fileRef = 089BA20C1298F19A00D4F34F /* IsGivenDayOfWeek.m */; };
08B5196E12A0678400147210 /* OCHamcrest.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 08B5196D12A0678400147210 /* OCHamcrest.framework */; };
08B51A4D12A0688B00147210 /* OCHamcrest.framework in CopyFiles */ = {isa = PBXBuildFile; fileRef = 08B5196D12A0678400147210 /* OCHamcrest.framework */; };
0FC264990DA88F1100B4CD6B /* SampleTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 0FC264980DA88F1100B4CD6B /* SampleTest.m */; };
/* End PBXBuildFile section */
/* Begin PBXCopyFilesBuildPhase section */
08B5189B12A0642100147210 /* CopyFiles */ = {
isa = PBXCopyFilesBuildPhase;
buildActionMask = 2147483647;
dstPath = "";
dstSubfolderSpec = 16;
files = (
08B51A4D12A0688B00147210 /* OCHamcrest.framework in CopyFiles */,
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXCopyFilesBuildPhase section */
/* Begin PBXFileReference section */
0817B62A147ED03A00C5401D /* SenTestingKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = SenTestingKit.framework; path = Library/Frameworks/SenTestingKit.framework; sourceTree = DEVELOPER_DIR; };
089BA20B1298F19A00D4F34F /* IsGivenDayOfWeek.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = IsGivenDayOfWeek.h; sourceTree = "<group>"; usesTabs = 0; };
089BA20C1298F19A00D4F34F /* IsGivenDayOfWeek.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = IsGivenDayOfWeek.m; sourceTree = "<group>"; usesTabs = 0; };
08B5196D12A0678400147210 /* OCHamcrest.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = OCHamcrest.framework; path = ../../OCHamcrest.framework; sourceTree = SOURCE_ROOT; };
0FC2648E0DA88ECB00B4CD6B /* Example.octest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = Example.octest; sourceTree = BUILT_PRODUCTS_DIR; };
0FC264900DA88ECB00B4CD6B /* Example-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "Example-Info.plist"; sourceTree = "<group>"; };
0FC264980DA88F1100B4CD6B /* SampleTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SampleTest.m; sourceTree = "<group>"; usesTabs = 0; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
0FC2648B0DA88ECB00B4CD6B /* Frameworks */ = {
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
08B5196E12A0678400147210 /* OCHamcrest.framework in Frameworks */,
0817B62B147ED03A00C5401D /* SenTestingKit.framework in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXFrameworksBuildPhase section */
/* Begin PBXGroup section */
0FC264760DA88EAA00B4CD6B = {
isa = PBXGroup;
children = (
089BA20B1298F19A00D4F34F /* IsGivenDayOfWeek.h */,
089BA20C1298F19A00D4F34F /* IsGivenDayOfWeek.m */,
0FC264980DA88F1100B4CD6B /* SampleTest.m */,
0FC2658B0DA8981900B4CD6B /* Resources */,
0FC2658F0DA8983200B4CD6B /* Frameworks */,
0FC2648F0DA88ECB00B4CD6B /* Products */,
);
sourceTree = "<group>";
};
0FC2648F0DA88ECB00B4CD6B /* Products */ = {
isa = PBXGroup;
children = (
0FC2648E0DA88ECB00B4CD6B /* Example.octest */,
);
name = Products;
sourceTree = "<group>";
};
0FC2658B0DA8981900B4CD6B /* Resources */ = {
isa = PBXGroup;
children = (
0FC264900DA88ECB00B4CD6B /* Example-Info.plist */,
);
name = Resources;
sourceTree = "<group>";
};
0FC2658F0DA8983200B4CD6B /* Frameworks */ = {
isa = PBXGroup;
children = (
0817B62A147ED03A00C5401D /* SenTestingKit.framework */,
08B5196D12A0678400147210 /* OCHamcrest.framework */,
);
name = Frameworks;
sourceTree = "<group>";
};
/* End PBXGroup section */
/* Begin PBXNativeTarget section */
0FC2648D0DA88ECB00B4CD6B /* Example */ = {
isa = PBXNativeTarget;
buildConfigurationList = 0FC264940DA88ECB00B4CD6B /* Build configuration list for PBXNativeTarget "Example" */;
buildPhases = (
0FC2648A0DA88ECB00B4CD6B /* Sources */,
0FC2648B0DA88ECB00B4CD6B /* Frameworks */,
08B5189B12A0642100147210 /* CopyFiles */,
0FC2648C0DA88ECB00B4CD6B /* ShellScript */,
);
buildRules = (
);
dependencies = (
);
name = Example;
productName = Example;
productReference = 0FC2648E0DA88ECB00B4CD6B /* Example.octest */;
productType = "com.apple.product-type.bundle";
};
/* End PBXNativeTarget section */
/* Begin PBXProject section */
0FC264780DA88EAA00B4CD6B /* Project object */ = {
isa = PBXProject;
attributes = {
LastUpgradeCheck = 0450;
};
buildConfigurationList = 0FC2647B0DA88EAA00B4CD6B /* Build configuration list for PBXProject "CustomDateMatcher" */;
compatibilityVersion = "Xcode 3.2";
developmentRegion = English;
hasScannedForEncodings = 0;
knownRegions = (
English,
Japanese,
French,
German,
);
mainGroup = 0FC264760DA88EAA00B4CD6B;
productRefGroup = 0FC2648F0DA88ECB00B4CD6B /* Products */;
projectDirPath = "";
projectRoot = "";
targets = (
0FC2648D0DA88ECB00B4CD6B /* Example */,
);
};
/* End PBXProject section */
/* Begin PBXShellScriptBuildPhase section */
0FC2648C0DA88ECB00B4CD6B /* ShellScript */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputPaths = (
);
outputPaths = (
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "# Run the unit tests in this test bundle.\n\"${SYSTEM_DEVELOPER_DIR}/Tools/RunUnitTests\"\n";
};
/* End PBXShellScriptBuildPhase section */
/* Begin PBXSourcesBuildPhase section */
0FC2648A0DA88ECB00B4CD6B /* Sources */ = {
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
0FC264990DA88F1100B4CD6B /* SampleTest.m in Sources */,
089BA20D1298F19A00D4F34F /* IsGivenDayOfWeek.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXSourcesBuildPhase section */
/* Begin XCBuildConfiguration section */
0FC264790DA88EAA00B4CD6B /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
ARCHS = "$(ARCHS_STANDARD_64_BIT)";
CLANG_WARN_OBJCPP_ARC_ABI = YES;
COPY_PHASE_STRIP = NO;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = macosx;
};
name = Debug;
};
0FC2647A0DA88EAA00B4CD6B /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
ARCHS = "$(ARCHS_STANDARD_64_BIT)";
CLANG_WARN_OBJCPP_ARC_ABI = YES;
COPY_PHASE_STRIP = YES;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = macosx;
};
name = Release;
};
0FC264920DA88ECB00B4CD6B /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
CLANG_ENABLE_OBJC_ARC = YES;
COMBINE_HIDPI_IMAGES = YES;
COPY_PHASE_STRIP = NO;
FRAMEWORK_SEARCH_PATHS = (
"$(DEVELOPER_LIBRARY_DIR)/Frameworks",
"$(FRAMEWORK_SEARCH_PATHS_QUOTED_FOR_TARGET_1)",
);
FRAMEWORK_SEARCH_PATHS_QUOTED_FOR_TARGET_1 = "\"$(SRCROOT)/../..\"";
GCC_DYNAMIC_NO_PIC = NO;
GCC_ENABLE_OBJC_EXCEPTIONS = YES;
GCC_MODEL_TUNING = G5;
GCC_OPTIMIZATION_LEVEL = 0;
INFOPLIST_FILE = "Example-Info.plist";
INSTALL_PATH = "$(USER_LIBRARY_DIR)/Bundles";
OTHER_LDFLAGS = (
"-framework",
Foundation,
"-framework",
SenTestingKit,
);
PRODUCT_NAME = Example;
WRAPPER_EXTENSION = octest;
};
name = Debug;
};
0FC264930DA88ECB00B4CD6B /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
CLANG_ENABLE_OBJC_ARC = YES;
COMBINE_HIDPI_IMAGES = YES;
COPY_PHASE_STRIP = YES;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
FRAMEWORK_SEARCH_PATHS = (
"$(DEVELOPER_LIBRARY_DIR)/Frameworks",
"$(FRAMEWORK_SEARCH_PATHS_QUOTED_FOR_TARGET_1)",
);
FRAMEWORK_SEARCH_PATHS_QUOTED_FOR_TARGET_1 = "\"$(SRCROOT)/../..\"";
GCC_ENABLE_OBJC_EXCEPTIONS = YES;
GCC_MODEL_TUNING = G5;
INFOPLIST_FILE = "Example-Info.plist";
INSTALL_PATH = "$(USER_LIBRARY_DIR)/Bundles";
OTHER_LDFLAGS = (
"-framework",
Foundation,
"-framework",
SenTestingKit,
);
PRODUCT_NAME = Example;
WRAPPER_EXTENSION = octest;
ZERO_LINK = NO;
};
name = Release;
};
/* End XCBuildConfiguration section */
/* Begin XCConfigurationList section */
0FC2647B0DA88EAA00B4CD6B /* Build configuration list for PBXProject "CustomDateMatcher" */ = {
isa = XCConfigurationList;
buildConfigurations = (
0FC264790DA88EAA00B4CD6B /* Debug */,
0FC2647A0DA88EAA00B4CD6B /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
0FC264940DA88ECB00B4CD6B /* Build configuration list for PBXNativeTarget "Example" */ = {
isa = XCConfigurationList;
buildConfigurations = (
0FC264920DA88ECB00B4CD6B /* Debug */,
0FC264930DA88ECB00B4CD6B /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
/* End XCConfigurationList section */
};
rootObject = 0FC264780DA88EAA00B4CD6B /* Project object */;
}
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>English</string>
<key>CFBundleExecutable</key>
<string>${EXECUTABLE_NAME}</string>
<key>CFBundleIdentifier</key>
<string>org.hamcrest.Example</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundlePackageType</key>
<string>BNDL</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>1.0</string>
</dict>
</plist>
@@ -0,0 +1,17 @@
#import <OCHamcrest/HCBaseMatcher.h>
#import <objc/objc-api.h>
// Matches dates that fall on a given day of the week.
@interface IsGivenDayOfWeek : HCBaseMatcher
{
NSInteger day; // Sunday is 0, Saturday is 6
}
+ (id)isGivenDayOfWeek:(NSInteger)dayOfWeek;
- (id)initWithDay:(NSInteger)dayOfWeek;
@end
// Factory function to generate Saturday matcher.
OBJC_EXPORT id <HCMatcher> onASaturday();
@@ -0,0 +1,42 @@
#import "IsGivenDayOfWeek.h"
#import <OCHamcrest/HCDescription.h>
@implementation IsGivenDayOfWeek
+ (id)isGivenDayOfWeek:(NSInteger)dayOfWeek
{
return [[self alloc] initWithDay:dayOfWeek];
}
- (id)initWithDay:(NSInteger)dayOfWeek
{
self = [super init];
if (self)
day = dayOfWeek;
return self;
}
// Test whether item matches.
- (BOOL)matches:(id)item
{
if (![item respondsToSelector:@selector(dayOfWeek)])
return NO;
return [item dayOfWeek] == day;
}
// Describe the matcher.
- (void)describeTo:(id <HCDescription>)description
{
NSString* dayAsString[] =
{ @"Sunday", @"Monday", @"Tuesday", @"Wednesday", @"Thursday", @"Friday", @"Saturday" };
[[description appendText:@"calendar date falling on "] appendText:dayAsString[day]];
}
@end
id <HCMatcher> onASaturday()
{
return [IsGivenDayOfWeek isGivenDayOfWeek:6];
}
@@ -0,0 +1,34 @@
#import <SenTestingKit/SenTestingKit.h>
#define HC_SHORTHAND
#import <OCHamcrest/OCHamcrest.h>
#import "IsGivenDayOfWeek.h"
@interface SampleTest : SenTestCase
@end
@implementation SampleTest
- (void)testDateIsOnASaturday
{
// Example of a successful match.
NSCalendarDate* date = [NSCalendarDate dateWithString:@"26 Apr 2008" calendarFormat:@"%d %b %Y"];
assertThat(date, is(onASaturday()));
}
- (void)testFailsWithMismatchedDate
{
// Example of what happens with date that doesn't match.
NSCalendarDate* date = [NSCalendarDate dateWithString:@"06 Apr 2008" calendarFormat:@"%d %b %Y"];
assertThat(date, is(onASaturday()));
}
- (void)testFailsWithNonDate
{
// Example of what happens with object that isn't a date.
NSString* nonDate = @"oops";
assertThat(nonDate, is(onASaturday()));
}
@end
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>English</string>
<key>CFBundleExecutable</key>
<string>${EXECUTABLE_NAME}</string>
<key>CFBundleIdentifier</key>
<string>org.hamcrest.Example</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundlePackageType</key>
<string>BNDL</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>1.0</string>
</dict>
</plist>
@@ -0,0 +1,24 @@
#import <SenTestingKit/SenTestingKit.h>
#define HC_SHORTHAND
#import <OCHamcrest/OCHamcrest.h>
@interface Example : SenTestCase
@end
@implementation Example
- (void)testUsingAssertThat
{
assertThat(@"xx", is(@"xx"));
assertThat(@"yy", isNot(@"xx"));
assertThat(@"i like cheese", containsString(@"cheese"));
}
- (void)testUsingNumbers
{
assertThatInt(42, is(@42));
assertThatUnsignedShort(6 * 9, isNot(@42U));
}
@end
@@ -0,0 +1,251 @@
// !$*UTF8*$!
{
archiveVersion = 1;
classes = {
};
objectVersion = 46;
objects = {
/* Begin PBXBuildFile section */
0817B622147ECFFC00C5401D /* SenTestingKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 0817B621147ECFFC00C5401D /* SenTestingKit.framework */; };
08B519DB12A0681600147210 /* OCHamcrest.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 08B519DA12A0681600147210 /* OCHamcrest.framework */; };
08B519DC12A0682300147210 /* OCHamcrest.framework in CopyFiles */ = {isa = PBXBuildFile; fileRef = 08B519DA12A0681600147210 /* OCHamcrest.framework */; };
0FC264990DA88F1100B4CD6B /* Example.m in Sources */ = {isa = PBXBuildFile; fileRef = 0FC264980DA88F1100B4CD6B /* Example.m */; };
/* End PBXBuildFile section */
/* Begin PBXCopyFilesBuildPhase section */
08B518CA12A065C700147210 /* CopyFiles */ = {
isa = PBXCopyFilesBuildPhase;
buildActionMask = 2147483647;
dstPath = "";
dstSubfolderSpec = 16;
files = (
08B519DC12A0682300147210 /* OCHamcrest.framework in CopyFiles */,
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXCopyFilesBuildPhase section */
/* Begin PBXFileReference section */
0817B621147ECFFC00C5401D /* SenTestingKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = SenTestingKit.framework; path = Library/Frameworks/SenTestingKit.framework; sourceTree = DEVELOPER_DIR; };
08B519DA12A0681600147210 /* OCHamcrest.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = OCHamcrest.framework; path = ../../OCHamcrest.framework; sourceTree = SOURCE_ROOT; };
0FC2648E0DA88ECB00B4CD6B /* Example.octest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = Example.octest; sourceTree = BUILT_PRODUCTS_DIR; };
0FC264900DA88ECB00B4CD6B /* Example-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "Example-Info.plist"; sourceTree = "<group>"; };
0FC264980DA88F1100B4CD6B /* Example.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Example.m; sourceTree = "<group>"; usesTabs = 0; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
0FC2648B0DA88ECB00B4CD6B /* Frameworks */ = {
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
08B519DB12A0681600147210 /* OCHamcrest.framework in Frameworks */,
0817B622147ECFFC00C5401D /* SenTestingKit.framework in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXFrameworksBuildPhase section */
/* Begin PBXGroup section */
0FC264760DA88EAA00B4CD6B = {
isa = PBXGroup;
children = (
0FC264980DA88F1100B4CD6B /* Example.m */,
0FC2658B0DA8981900B4CD6B /* Resources */,
0FC2658F0DA8983200B4CD6B /* Frameworks */,
0FC2648F0DA88ECB00B4CD6B /* Products */,
);
sourceTree = "<group>";
};
0FC2648F0DA88ECB00B4CD6B /* Products */ = {
isa = PBXGroup;
children = (
0FC2648E0DA88ECB00B4CD6B /* Example.octest */,
);
name = Products;
sourceTree = "<group>";
};
0FC2658B0DA8981900B4CD6B /* Resources */ = {
isa = PBXGroup;
children = (
0FC264900DA88ECB00B4CD6B /* Example-Info.plist */,
);
name = Resources;
sourceTree = "<group>";
};
0FC2658F0DA8983200B4CD6B /* Frameworks */ = {
isa = PBXGroup;
children = (
0817B621147ECFFC00C5401D /* SenTestingKit.framework */,
08B519DA12A0681600147210 /* OCHamcrest.framework */,
);
name = Frameworks;
sourceTree = "<group>";
};
/* End PBXGroup section */
/* Begin PBXNativeTarget section */
0FC2648D0DA88ECB00B4CD6B /* Example */ = {
isa = PBXNativeTarget;
buildConfigurationList = 0FC264940DA88ECB00B4CD6B /* Build configuration list for PBXNativeTarget "Example" */;
buildPhases = (
0FC2648A0DA88ECB00B4CD6B /* Sources */,
0FC2648B0DA88ECB00B4CD6B /* Frameworks */,
08B518CA12A065C700147210 /* CopyFiles */,
0FC2648C0DA88ECB00B4CD6B /* ShellScript */,
);
buildRules = (
);
dependencies = (
);
name = Example;
productName = Example;
productReference = 0FC2648E0DA88ECB00B4CD6B /* Example.octest */;
productType = "com.apple.product-type.bundle";
};
/* End PBXNativeTarget section */
/* Begin PBXProject section */
0FC264780DA88EAA00B4CD6B /* Project object */ = {
isa = PBXProject;
attributes = {
LastUpgradeCheck = 0420;
};
buildConfigurationList = 0FC2647B0DA88EAA00B4CD6B /* Build configuration list for PBXProject "MacExample" */;
compatibilityVersion = "Xcode 3.2";
developmentRegion = English;
hasScannedForEncodings = 0;
knownRegions = (
English,
Japanese,
French,
German,
);
mainGroup = 0FC264760DA88EAA00B4CD6B;
productRefGroup = 0FC2648F0DA88ECB00B4CD6B /* Products */;
projectDirPath = "";
projectRoot = "";
targets = (
0FC2648D0DA88ECB00B4CD6B /* Example */,
);
};
/* End PBXProject section */
/* Begin PBXShellScriptBuildPhase section */
0FC2648C0DA88ECB00B4CD6B /* ShellScript */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputPaths = (
);
outputPaths = (
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "# Run the unit tests in this test bundle.\n\"${SYSTEM_DEVELOPER_DIR}/Tools/RunUnitTests\"\n";
};
/* End PBXShellScriptBuildPhase section */
/* Begin PBXSourcesBuildPhase section */
0FC2648A0DA88ECB00B4CD6B /* Sources */ = {
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
0FC264990DA88F1100B4CD6B /* Example.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXSourcesBuildPhase section */
/* Begin XCBuildConfiguration section */
0FC264790DA88EAA00B4CD6B /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
ARCHS = "$(ARCHS_STANDARD_64_BIT)";
COPY_PHASE_STRIP = NO;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = macosx;
};
name = Debug;
};
0FC2647A0DA88EAA00B4CD6B /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
ARCHS = "$(ARCHS_STANDARD_64_BIT)";
COPY_PHASE_STRIP = YES;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = macosx;
};
name = Release;
};
0FC264920DA88ECB00B4CD6B /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
CLANG_ENABLE_OBJC_ARC = YES;
COPY_PHASE_STRIP = NO;
FRAMEWORK_SEARCH_PATHS = (
"$(DEVELOPER_LIBRARY_DIR)/Frameworks",
"$(FRAMEWORK_SEARCH_PATHS_QUOTED_FOR_TARGET_1)",
);
GCC_DYNAMIC_NO_PIC = NO;
GCC_ENABLE_OBJC_EXCEPTIONS = YES;
GCC_OPTIMIZATION_LEVEL = 0;
INFOPLIST_FILE = "Example-Info.plist";
INSTALL_PATH = "$(USER_LIBRARY_DIR)/Bundles";
OTHER_LDFLAGS = (
"-framework",
Foundation,
);
PRODUCT_NAME = Example;
WRAPPER_EXTENSION = octest;
};
name = Debug;
};
0FC264930DA88ECB00B4CD6B /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
CLANG_ENABLE_OBJC_ARC = YES;
COPY_PHASE_STRIP = YES;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
FRAMEWORK_SEARCH_PATHS = (
"$(DEVELOPER_LIBRARY_DIR)/Frameworks",
"$(FRAMEWORK_SEARCH_PATHS_QUOTED_FOR_TARGET_1)",
);
GCC_ENABLE_OBJC_EXCEPTIONS = YES;
INFOPLIST_FILE = "Example-Info.plist";
INSTALL_PATH = "$(USER_LIBRARY_DIR)/Bundles";
OTHER_LDFLAGS = (
"-framework",
Foundation,
);
PRODUCT_NAME = Example;
WRAPPER_EXTENSION = octest;
};
name = Release;
};
/* End XCBuildConfiguration section */
/* Begin XCConfigurationList section */
0FC2647B0DA88EAA00B4CD6B /* Build configuration list for PBXProject "MacExample" */ = {
isa = XCConfigurationList;
buildConfigurations = (
0FC264790DA88EAA00B4CD6B /* Debug */,
0FC2647A0DA88EAA00B4CD6B /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
0FC264940DA88ECB00B4CD6B /* Build configuration list for PBXNativeTarget "Example" */ = {
isa = XCConfigurationList;
buildConfigurations = (
0FC264920DA88ECB00B4CD6B /* Debug */,
0FC264930DA88ECB00B4CD6B /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
/* End XCConfigurationList section */
};
rootObject = 0FC264780DA88EAA00B4CD6B /* Project object */;
}
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>English</string>
<key>CFBundleExecutable</key>
<string>${EXECUTABLE_NAME}</string>
<key>CFBundleIdentifier</key>
<string>com.yourcompany.${PRODUCT_NAME:rfc1034identifier}</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundlePackageType</key>
<string>BNDL</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>1.0</string>
</dict>
</plist>
@@ -0,0 +1,24 @@
#import <SenTestingKit/SenTestingKit.h>
#define HC_SHORTHAND
#import <OCHamcrestIOS/OCHamcrestIOS.h>
@interface Example : SenTestCase
@end
@implementation Example
- (void)testUsingAssertThat
{
assertThat(@"xx", is(@"xx"));
assertThat(@"yy", isNot(@"xx"));
assertThat(@"I like cheese", containsString(@"cheese"));
}
- (void)testUsingNumbers
{
assertThatInt(42, is(@42));
assertThatUnsignedShort(6 * 9, isNot(@42U));
}
@end
@@ -0,0 +1,238 @@
// !$*UTF8*$!
{
archiveVersion = 1;
classes = {
};
objectVersion = 45;
objects = {
/* Begin PBXBuildFile section */
0817B615147ECF5500C5401D /* SenTestingKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 0817B614147ECF5500C5401D /* SenTestingKit.framework */; };
087F064E151C2E150030C044 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 087F064D151C2E150030C044 /* Foundation.framework */; };
089B9DED1298DB1100D4F34F /* Example.m in Sources */ = {isa = PBXBuildFile; fileRef = 089B9DEC1298DB1100D4F34F /* Example.m */; };
08B51A8712A068BC00147210 /* OCHamcrestIOS.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 08B51A8612A068BC00147210 /* OCHamcrestIOS.framework */; };
/* End PBXBuildFile section */
/* Begin PBXFileReference section */
0817B614147ECF5500C5401D /* SenTestingKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = SenTestingKit.framework; path = Library/Frameworks/SenTestingKit.framework; sourceTree = DEVELOPER_DIR; };
087F064D151C2E150030C044 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; };
089B9DC71298DA0B00D4F34F /* Example.octest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = Example.octest; sourceTree = BUILT_PRODUCTS_DIR; };
089B9DC81298DA0B00D4F34F /* Example-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "Example-Info.plist"; sourceTree = "<group>"; };
089B9DEC1298DB1100D4F34F /* Example.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Example.m; sourceTree = "<group>"; usesTabs = 0; };
08B51A8612A068BC00147210 /* OCHamcrestIOS.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = OCHamcrestIOS.framework; path = ../../OCHamcrestIOS.framework; sourceTree = SOURCE_ROOT; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
089B9DC41298DA0B00D4F34F /* Frameworks */ = {
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
087F064E151C2E150030C044 /* Foundation.framework in Frameworks */,
0817B615147ECF5500C5401D /* SenTestingKit.framework in Frameworks */,
08B51A8712A068BC00147210 /* OCHamcrestIOS.framework in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXFrameworksBuildPhase section */
/* Begin PBXGroup section */
034768DFFF38A50411DB9C8B /* Products */ = {
isa = PBXGroup;
children = (
089B9DC71298DA0B00D4F34F /* Example.octest */,
);
name = Products;
sourceTree = "<group>";
};
0867D691FE84028FC02AAC07 /* iOSExample */ = {
isa = PBXGroup;
children = (
089B9DEC1298DB1100D4F34F /* Example.m */,
089B9F4B1298DE6400D4F34F /* Resources */,
0867D69AFE84028FC02AAC07 /* Frameworks */,
034768DFFF38A50411DB9C8B /* Products */,
);
name = iOSExample;
sourceTree = "<group>";
};
0867D69AFE84028FC02AAC07 /* Frameworks */ = {
isa = PBXGroup;
children = (
087F064D151C2E150030C044 /* Foundation.framework */,
0817B614147ECF5500C5401D /* SenTestingKit.framework */,
08B51A8612A068BC00147210 /* OCHamcrestIOS.framework */,
);
name = Frameworks;
sourceTree = "<group>";
};
089B9F4B1298DE6400D4F34F /* Resources */ = {
isa = PBXGroup;
children = (
089B9DC81298DA0B00D4F34F /* Example-Info.plist */,
);
name = Resources;
sourceTree = "<group>";
};
/* End PBXGroup section */
/* Begin PBXNativeTarget section */
089B9DC61298DA0B00D4F34F /* Example */ = {
isa = PBXNativeTarget;
buildConfigurationList = 089B9DCC1298DA0C00D4F34F /* Build configuration list for PBXNativeTarget "Example" */;
buildPhases = (
089B9DC31298DA0B00D4F34F /* Sources */,
089B9DC41298DA0B00D4F34F /* Frameworks */,
089B9DC51298DA0B00D4F34F /* ShellScript */,
);
buildRules = (
);
dependencies = (
);
name = Example;
productName = Example;
productReference = 089B9DC71298DA0B00D4F34F /* Example.octest */;
productType = "com.apple.product-type.bundle";
};
/* End PBXNativeTarget section */
/* Begin PBXProject section */
0867D690FE84028FC02AAC07 /* Project object */ = {
isa = PBXProject;
buildConfigurationList = 1DEB922208733DC00010E9CD /* Build configuration list for PBXProject "iOSExample" */;
compatibilityVersion = "Xcode 3.1";
developmentRegion = English;
hasScannedForEncodings = 1;
knownRegions = (
English,
Japanese,
French,
German,
);
mainGroup = 0867D691FE84028FC02AAC07 /* iOSExample */;
productRefGroup = 034768DFFF38A50411DB9C8B /* Products */;
projectDirPath = "";
projectRoot = "";
targets = (
089B9DC61298DA0B00D4F34F /* Example */,
);
};
/* End PBXProject section */
/* Begin PBXShellScriptBuildPhase section */
089B9DC51298DA0B00D4F34F /* ShellScript */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputPaths = (
);
outputPaths = (
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "# Run the unit tests in this test bundle.\n\"${SYSTEM_DEVELOPER_DIR}/Tools/RunUnitTests\"\n";
};
/* End PBXShellScriptBuildPhase section */
/* Begin PBXSourcesBuildPhase section */
089B9DC31298DA0B00D4F34F /* Sources */ = {
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
089B9DED1298DB1100D4F34F /* Example.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXSourcesBuildPhase section */
/* Begin XCBuildConfiguration section */
089B9DCA1298DA0C00D4F34F /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "";
COPY_PHASE_STRIP = NO;
FRAMEWORK_SEARCH_PATHS = (
"\"$(SDKROOT)/Developer/Library/Frameworks\"",
"\"$(DEVELOPER_LIBRARY_DIR)/Frameworks\"",
"\"$(SRCROOT)/../..\"",
);
GCC_ENABLE_FIX_AND_CONTINUE = NO;
GCC_OPTIMIZATION_LEVEL = 0;
INFOPLIST_FILE = "Example-Info.plist";
PRODUCT_NAME = Example;
WRAPPER_EXTENSION = octest;
};
name = Debug;
};
089B9DCB1298DA0C00D4F34F /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "";
COPY_PHASE_STRIP = YES;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
FRAMEWORK_SEARCH_PATHS = (
"\"$(SDKROOT)/Developer/Library/Frameworks\"",
"\"$(DEVELOPER_LIBRARY_DIR)/Frameworks\"",
"\"$(SRCROOT)/../..\"",
);
GCC_ENABLE_FIX_AND_CONTINUE = NO;
INFOPLIST_FILE = "Example-Info.plist";
PRODUCT_NAME = Example;
WRAPPER_EXTENSION = octest;
};
name = Release;
};
1DEB922308733DC00010E9CD /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
ARCHS = "$(ARCHS_STANDARD_32_BIT)";
CLANG_WARN_OBJCPP_ARC_ABI = YES;
GCC_C_LANGUAGE_STANDARD = c99;
GCC_OPTIMIZATION_LEVEL = 0;
GCC_WARN_ABOUT_RETURN_TYPE = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
ONLY_ACTIVE_ARCH = YES;
OTHER_LDFLAGS = "-ObjC";
SDKROOT = iphoneos;
};
name = Debug;
};
1DEB922408733DC00010E9CD /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
ARCHS = "$(ARCHS_STANDARD_32_BIT)";
CLANG_WARN_OBJCPP_ARC_ABI = YES;
GCC_C_LANGUAGE_STANDARD = c99;
GCC_WARN_ABOUT_RETURN_TYPE = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
ONLY_ACTIVE_ARCH = YES;
OTHER_LDFLAGS = "-ObjC";
SDKROOT = iphoneos;
};
name = Release;
};
/* End XCBuildConfiguration section */
/* Begin XCConfigurationList section */
089B9DCC1298DA0C00D4F34F /* Build configuration list for PBXNativeTarget "Example" */ = {
isa = XCConfigurationList;
buildConfigurations = (
089B9DCA1298DA0C00D4F34F /* Debug */,
089B9DCB1298DA0C00D4F34F /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
1DEB922208733DC00010E9CD /* Build configuration list for PBXProject "iOSExample" */ = {
isa = XCConfigurationList;
buildConfigurations = (
1DEB922308733DC00010E9CD /* Debug */,
1DEB922408733DC00010E9CD /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
/* End XCConfigurationList section */
};
rootObject = 0867D690FE84028FC02AAC07 /* Project object */;
}
+27
View File
@@ -0,0 +1,27 @@
BSD License
Copyright 2012 hamcrest.org
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
Redistributions of source code must retain the above copyright notice, this list of
conditions and the following disclaimer. Redistributions in binary form must reproduce
the above copyright notice, this list of conditions and the following disclaimer in
the documentation and/or other materials provided with the distribution.
Neither the name of Hamcrest nor the names of its contributors may be used to endorse
or promote products derived from this software without specific prior written
permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
DAMAGE.
+314
View File
@@ -0,0 +1,314 @@
![ochamcrest](http://hamcrest.org/images/logo.jpg)
What is OCHamcrest?
===================
OCHamcrest is:
* a library of "matcher" objects that let you declare rules for whether a given
object matches the criteria or not.
* a framework for writing your own matchers.
Matchers are useful for a variety of purposes, such as UI validation. But
they're most commonly used for writing unit tests that are expressive and
flexible.
OCHamcrest can be used for either iOS or OS X development with:
* OCUnit (SenTestingKit) built in to Xcode
* Google Toolbox for Mac (GTM)
* GHUnit
* Cedar BDD framework
* OCMock
* OCMockito
How do I add OCHamcrest to my project?
======================================
__Building:__
If you want to build OCHamcrest yourself, clone the repo, then
```sh
$ git submodule update --init
$ cd Source
$ ./MakeDistribution.sh
```
Or just use the pre-built release available at
[QualityCoding.org](http://qualitycoding.org/resources/).
__iOS Project Setup:__
Add OCHamcrestIOS.framework to your project.
Add:
#define HC_SHORTHAND
#import <OCHamcrestIOS/OCHamcrestIOS.h>
__OS X Project Setup:__
Add OCHamcrest.framework to your project.
Add a Copy Files build phase to copy OCHamcrest.framework to your Products
Directory. For unit test bundles, make sure this Copy Files phase comes before
the Run Script phase that executes tests.
Add:
#define HC_SHORTHAND
#import <OCHamcrest/OCHamcrest.h>
Note: If your Console shows
otest[57510:203] *** NSTask: Task create for path '...' failed: 22, "Invalid argument". Terminating temporary process.
double-check your Copy Files phase.
My first OCHamcrest test
========================
We'll start by writing a very simple Xcode unit test, but instead of using
OCUnit's ``STAssertEqualObjects`` function, we'll use OCHamcrest's
``assertThat`` construct and a predefined matcher:
```obj-c
#import <SenTestingKit/SenTestingKit.h>
#define HC_SHORTHAND
#import <OCHamcrest/OCHamcrest.h>
@interface BiscuitTest : SenTestCase
@end
@implementation BiscuitTest
- (void)testEquals
{
Biscuit* theBiscuit = [Biscuit biscuitNamed:@"Ginger"];
Biscuit* myBiscuit = [Biscuit biscuitNamed:@"Ginger"];
assertThat(theBiscuit, equalTo(myBiscuit));
}
@end
```
The ``assertThat`` function is a stylized sentence for making a test assertion.
In this example, the subject of the assertion is the object ``theBiscuit``,
which is the first method parameter. The second method parameter is a matcher
for ``Biscuit`` objects, here a matcher that checks one object is equal to
another using the ``-isEqual:`` method. The test passes since the ``Biscuit``
class defines an ``-isEqual:`` method.
OCHamcrest's functions are actually declared with an "HC" package prefix (such
as ``HC_assertThat`` and ``HC_equalTo``) to avoid name clashes. To make test
writing faster and test code more legible, shorthand macros are provided if
``HC_SHORTHAND`` is defined before including the OCHamcrest header. For example,
instead of writing ``HC_assertThat``, simply write ``assertThat``.
Predefined matchers
===================
OCHamcrest comes with a library of useful matchers:
* Object
* ``conformsTo`` - match object that conforms to protocol
* ``equalTo`` - match equal object
* ``hasDescription`` - match object's ``-description``
* ``hasProperty`` - match return value of method with given name
* ``instanceOf`` - match object type
* ``nilValue``, ``notNilValue`` - match ``nil``, or not ``nil``
* ``sameInstance`` - match same object
* Number
* ``closeTo`` - match number close to a given value
* equalTo&lt;TypeName&gt; - match number equal to a primitive number (such as
``equalToInt`` for an ``int``)
* ``greaterThan``, ``greaterThanOrEqualTo``, ``lessThan``,
``lessThanOrEqualTo`` - match numeric ordering
* Text
* ``containsString`` - match part of a string
* ``endsWith`` - match the end of a string
* ``equalToIgnoringCase`` - match the complete string but ignore case
* ``equalToIgnoringWhitespace`` - match the complete string but ignore
extra whitespace
* ``startsWith`` - match the beginning of a string
* ``stringContainsInOrder`` - match parts of a string, in relative order
* Logical
* ``allOf`` - "and" together all matchers
* ``anyOf`` - "or" together all matchers
* ``anything`` - match anything (useful in composite matchers when you don't
care about a particular value)
* ``isNot`` - negate the matcher
* Collection
* ``contains`` - exactly match the entire collection
* ``containsInAnyOrder`` - match the entire collection, but in any order
* ``empty`` - match empty collection
* ``hasCount`` - match number of elements against another matcher
* ``hasCountOf`` - match collection with given number of elements
* ``hasEntries`` - match dictionary with list of key-value pairs
* ``hasEntry`` - match dictionary containing a key-value pair
* ``hasItem`` - match if given item appears in the collection
* ``hasItems`` - match if all given items appear in the collection, in any order
* ``hasKey`` - match dictionary with a key
* ``hasValue`` - match dictionary with a value
* ``onlyContains`` - match if collection's items appear in given list
* Decorator
* ``describedAs`` - give the matcher a custom failure description
* ``is`` - decorator to improve readability - see `Syntactic sugar` below
The arguments for many of these matchers accept not just a matching value, but
another matcher, so matchers can be composed for greater flexibility. For
example, ``only_contains(endsWith(@"."))`` will match any collection where
every item is a string ending with period.
Syntactic sugar
===============
OCHamcrest strives to make your tests as readable as possible. For example, the
``is`` matcher is a wrapper that doesn't add any extra behavior to the
underlying matcher. The following assertions are all equivalent:
```obj-c
assertThat(theBiscuit, equalTo(myBiscuit));
assertThat(theBiscuit, is(equalTo(myBiscuit)));
assertThat(theBiscuit, is(myBiscuit));
```
The last form is allowed since ``is`` wraps non-matcher arguments with
``equalTo``. Other matchers that take matchers as arguments provide similar
shortcuts, wrapping non-matcher arguments in ``equalTo``.
Writing custom matchers
=======================
OCHamcrest comes bundled with lots of useful matchers, but you'll probably find
that you need to create your own from time to time to fit your testing needs.
This commonly occurs when you find a fragment of code that tests the same set of
properties over and over again (and in different tests), and you want to bundle
the fragment into a single assertion. By writing your own matcher you'll
eliminate code duplication and make your tests more readable!
Let's write our own matcher for testing if a calendar date falls on a Saturday.
This is the test we want to write:
```obj-c
- (void)testDateIsOnASaturday
{
NSCalendarDate* date = [NSCalendarDate dateWithString:@"26 Apr 2008" calendarFormat:@"%d %b %Y"];
assertThat(date, is(onASaturday()))
}
```
Here's the interface:
```obj-c
#import <OCHamcrest/HCBaseMatcher.h>
#import <objc/objc-api.h>
@interface IsGivenDayOfWeek : HCBaseMatcher
{
NSInteger day; // Sunday is 0, Saturday is 6
}
+ (id)isGivenDayOfWeek:(NSInteger)dayOfWeek;
- (id)initWithDay:(NSInteger)dayOfWeek;
@end
OBJC_EXPORT id <HCMatcher> onASaturday();
```
The interface consists of two parts: a class definition, and a factory function
(with C binding). Here's what the implementation looks like:
```obj-c
#import "IsGivenDayOfWeek.h"
#import <OCHamcrest/HCDescription.h>
@implementation IsGivenDayOfWeek
+ (id)isGivenDayOfWeek:(NSInteger)dayOfWeek
{
return [[self alloc] initWithDay:dayOfWeek];
}
- (id)initWithDay:(NSInteger)dayOfWeek
{
self = [super init];
if (self)
day = dayOfWeek;
return self;
}
// Test whether item matches.
- (BOOL)matches:(id)item
{
if (![item respondsToSelector:@selector(dayOfWeek)])
return NO;
return [item dayOfWeek] == day;
}
// Describe the matcher.
- (void)describeTo:(id <HCDescription>)description
{
NSString* dayAsString[] =
{ @"Sunday", @"Monday", @"Tuesday", @"Wednesday", @"Thursday", @"Friday", @"Saturday" };
[[description appendText:@"calendar date falling on "] appendText:dayAsString[day]];
}
@end
id <HCMatcher> onASaturday()
{
return [IsGivenDayOfWeek isGivenDayOfWeek:6];
}
```
For our Matcher implementation we implement the ``-matches:`` method (which
calls ``-dayOfWeek`` after confirming that the argument has such a method) and
the ``-describe_to:`` method (which is used to produce a failure message when a
test fails). Here's an example of how the failure message looks:
NSCalendarDate* date = [NSCalendarDate dateWithString: @"6 April 2008" calendarFormat: @"%d %B %Y"];
assertThat(date, is(onASaturday()));
fails with the message
Expected: is calendar date falling on Saturday, got: <06 April 2008>
and Xcode shows it as a build error. Clicking the error message takes you to the
assertion that failed.
Even though the ``onASaturday`` function creates a new matcher each time it is
called, you should not assume this is the only usage pattern for your matcher.
Therefore you should make sure your matcher is stateless, so a single instance
can be reused between matches.
More resources
==============
* [Documentation](http://hamcrest.org/OCHamcrest/)
* [Sources](https://github.com/hamcrest/OCHamcrest)
* [Hamcrest](http://hamcrest.org)
* [Quality Coding](http://qualitycoding.org/) - Tools, tips &
techniques for _building quality in_ to iOS development
@@ -0,0 +1,42 @@
//
// OCHamcrest - HCAssertThat.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 <objc/objc-api.h>
@protocol HCMatcher;
OBJC_EXPORT void HC_assertThatWithLocation(id testCase, id actual, id<HCMatcher> matcher,
const char *fileName, int lineNumber);
#define HC_assertThat(actual, matcher) \
HC_assertThatWithLocation(self, actual, matcher, __FILE__, __LINE__)
/**
assertThat(actual, matcher) -
Asserts that actual value satisfies matcher.
@param actual The object to evaluate as the actual value.
@param matcher The matcher to satisfy as the expected condition.
@c assertThat passes the actual value to the matcher for evaluation. If the matcher is not
satisfied, an exception is thrown describing the mismatch.
@c assertThat is designed to integrate well with OCUnit and other unit testing frameworks.
Unmet assertions are reported as test failures. In Xcode, these failures can be clicked to
reveal the line of the assertion.
In the event of a name clash, don't \#define @c HC_SHORTHAND and use the synonym
@c HC_assertThat instead.
@ingroup integration
*/
#ifdef HC_SHORTHAND
#define assertThat HC_assertThat
#endif
@@ -0,0 +1,89 @@
//
// OCHamcrest - HCAssertThat.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 "HCAssertThat.h"
#import "HCStringDescription.h"
#import "HCMatcher.h"
/**
Create OCUnit failure
With OCUnit's extension to NSException, this is effectively the same as
@code
[NSException failureInFile: [NSString stringWithUTF8String:fileName]
atLine: lineNumber
withDescription: description]
@endcode
except we use an NSInvocation so that OCUnit (SenTestingKit) does not have to be linked.
*/
static NSException *createOCUnitException(const char* fileName, int lineNumber, __unsafe_unretained NSString *description)
{
__unsafe_unretained NSException *result = nil;
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wundeclared-selector"
SEL selector = @selector(failureInFile:atLine:withDescription:);
#pragma clang diagnostic pop
NSMethodSignature *signature = [[NSException class] methodSignatureForSelector:selector];
NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:signature];
[invocation setTarget:[NSException class]];
[invocation setSelector:selector];
__unsafe_unretained id fileArg = @(fileName);
[invocation setArgument:&fileArg atIndex:2];
[invocation setArgument:&lineNumber atIndex:3];
[invocation setArgument:&description atIndex:4];
[invocation invoke];
[invocation getReturnValue:&result];
return result;
}
static NSException *createAssertThatFailure(const char *fileName, int lineNumber, NSString *description)
{
// If the Hamcrest client has linked to OCUnit, generate an OCUnit failure.
if (NSClassFromString(@"SenTestCase") != Nil)
return createOCUnitException(fileName, lineNumber, description);
NSString *failureReason = [NSString stringWithFormat:@"%s:%d: matcher error: %@",
fileName, lineNumber, description];
return [NSException exceptionWithName:@"Hamcrest Error" reason:failureReason userInfo:nil];
}
#pragma mark -
// As of 2010-09-09, the iPhone simulator has a bug where you can't catch
// exceptions when they are thrown across NSInvocation boundaries. (See
// dmaclach's comment at http://openradar.appspot.com/8081169 ) So instead of
// using an NSInvocation to call failWithException:assertThatFailure without
// linking in OCUnit, we simply pretend it exists on NSObject.
@interface NSObject (HCExceptionBugHack)
- (void)failWithException:(NSException *)exception;
@end
void HC_assertThatWithLocation(id testCase, id actual, id<HCMatcher> matcher,
const char *fileName, int lineNumber)
{
if (![matcher matches:actual])
{
HCStringDescription *description = [HCStringDescription stringDescription];
[[[description appendText:@"Expected "]
appendDescriptionOf:matcher]
appendText:@", but "];
[matcher describeMismatchOf:actual to:description];
NSException *assertThatFailure = createAssertThatFailure(fileName, lineNumber,
[description description]);
[testCase failWithException:assertThatFailure];
}
}
@@ -0,0 +1,33 @@
//
// OCHamcrest - HCBaseDescription.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>
#import <OCHamcrest/HCDescription.h>
/**
Base class for all HCDescription implementations.
@ingroup core
*/
@interface HCBaseDescription : NSObject <HCDescription>
@end
/**
Methods that must be provided by subclasses of HCBaseDescription.
*/
@interface HCBaseDescription (SubclassMustImplement)
/**
Append the string @a str to the description.
*/
- (void)append:(NSString *)str;
@end
@@ -0,0 +1,107 @@
//
// OCHamcrest - HCBaseDescription.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 "HCBaseDescription.h"
#import "HCMatcher.h"
@implementation HCBaseDescription
- (id<HCDescription>)appendText:(NSString *)text
{
[self append:text];
return self;
}
- (id<HCDescription>)appendDescriptionOf:(id)value
{
if (value == nil)
[self append:@"nil"];
else if ([value conformsToProtocol:@protocol(HCSelfDescribing)])
[value describeTo:self];
else if ([value isKindOfClass:[NSString class]])
[self toCSyntaxString:value];
else
[self appendObjectDescriptionOf:value];
return self;
}
- (id<HCDescription>)appendObjectDescriptionOf:(id)value
{
NSString *description = [value description];
NSUInteger descriptionLength = [description length];
if (descriptionLength == 0)
[self append:[NSString stringWithFormat:@"<%@: %p>", NSStringFromClass([value class]), (__bridge void *)value]];
else if ([description characterAtIndex:0] == '<'
&& [description characterAtIndex:descriptionLength - 1] == '>')
{
[self append:description];
}
else
{
[self append:@"<"];
[self append:description];
[self append:@">"];
}
return self;
}
- (id<HCDescription>)appendList:(NSArray *)values
start:(NSString *)start
separator:(NSString *)separator
end:(NSString *)end
{
BOOL separate = NO;
[self append:start];
for (id item in values)
{
if (separate)
[self append:separator];
[self appendDescriptionOf:item];
separate = YES;
}
[self append:end];
return self;
}
- (void)toCSyntaxString:(NSString *)unformatted
{
[self append:@"\""];
NSUInteger length = [unformatted length];
for (NSUInteger index = 0; index < length; ++index)
[self toCSyntax:[unformatted characterAtIndex:index]];
[self append:@"\""];
}
- (void)toCSyntax:(unichar)ch
{
switch (ch)
{
case '"':
[self append:@"\\\""];
break;
case '\n':
[self append:@"\\n"];
break;
case '\r':
[self append:@"\\r"];
break;
case '\t':
[self append:@"\\t"];
break;
default:
[self append:[NSString stringWithCharacters:&ch length:1]];
break;
}
}
@end
@@ -0,0 +1,27 @@
//
// OCHamcrest - HCBaseMatcher.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>
#import <OCHamcrest/HCMatcher.h>
#import <objc/objc-api.h> // Convenience header, to provide OBJC_EXPORT
/**
Base class for all HCMatcher implementations.
Most implementations can just implement @c -matches: and let
<code>-matches:describingMismatchTo:</code> call it. But if it makes more sense to generate the
mismatch description during the matching, override <code>-matches:describingMismatchTo:</code>
and have @c -matches: call it with a @c nil description.
@ingroup core
*/
@interface HCBaseMatcher : NSObject <HCMatcher>
@end
@@ -0,0 +1,55 @@
//
// OCHamcrest - HCBaseMatcher.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 "HCBaseMatcher.h"
#import "HCStringDescription.h"
#define ABSTRACT_METHOD [self subclassResponsibility:_cmd]
@implementation HCBaseMatcher
- (NSString *)description
{
return [HCStringDescription stringFrom:self];
}
- (BOOL)matches:(id)item
{
ABSTRACT_METHOD;
return NO;
}
- (BOOL)matches:(id)item describingMismatchTo:(id<HCDescription>)mismatchDescription
{
BOOL matchResult = [self matches:item];
if (!matchResult)
[self describeMismatchOf:item to:mismatchDescription];
return matchResult;
}
- (void)describeMismatchOf:(id)item to:(id<HCDescription>)mismatchDescription
{
[[mismatchDescription appendText:@"was "] appendDescriptionOf:item];
}
- (void)describeTo:(id<HCDescription>)description
{
ABSTRACT_METHOD;
}
- (void)subclassResponsibility:(SEL)command
{
NSString *className = NSStringFromClass([self class]);
[NSException raise:NSGenericException
format:@"-[%@ %@] not implemented", className, NSStringFromSelector(command)];
}
@end
@@ -0,0 +1,48 @@
//
// OCHamcrest - HCDescription.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>
/**
A description of an HCMatcher.
An HCMatcher will describe itself to a description which can later be used for reporting.
@ingroup core
*/
@protocol HCDescription <NSObject>
/**
Appends some plain text to the description.
@return @c self, for chaining.
*/
- (id<HCDescription>)appendText:(NSString *)text;
/**
Appends description of given value to @c self.
If the value implements the @ref HCSelfDescribing protocol, then it will be used.
@return @c self, for chaining.
*/
- (id<HCDescription>)appendDescriptionOf:(id)value;
/**
Appends a list of objects to the description.
@return @c self, for chaining.
*/
- (id<HCDescription>)appendList:(NSArray *)values
start:(NSString *)start
separator:(NSString *)separator
end:(NSString *)end;
@end
@@ -0,0 +1,56 @@
//
// OCHamcrest - HCMatcher.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 "HCSelfDescribing.h"
/**
A matcher over acceptable values.
A matcher is able to describe itself to give feedback when it fails.
HCMatcher implementations should @b not directly implement this protocol.
Instead, @b extend the HCBaseMatcher class, which will ensure that the HCMatcher API can grow
to support new features and remain compatible with all HCMatcher implementations.
@ingroup core
*/
@protocol HCMatcher <HCSelfDescribing>
/**
Evaluates the matcher for argument @a item.
@param item The object against which the matcher is evaluated.
@return @c YES if @a item matches, otherwise @c NO.
*/
- (BOOL)matches:(id)item;
/**
Evaluates the matcher for argument @a item.
@param item The object against which the matcher is evaluated.
@param mismatchDescription The description to be built or appended to if @a item does not match.
@return @c YES if @a item matches, otherwise @c NO.
*/
- (BOOL)matches:(id)item describingMismatchTo:(id<HCDescription>)mismatchDescription;
/**
Generates a description of why the matcher has not accepted the item.
The description will be part of a larger description of why a matching failed, so it should be
concise.
This method assumes that @c matches:item is false, but will not check this.
@param item The item that the HCMatcher has rejected.
@param mismatchDescription The description to be built or appended to.
*/
- (void)describeMismatchOf:(id)item to:(id<HCDescription>)mismatchDescription;
@end
@@ -0,0 +1,32 @@
//
// OCHamcrest - HCSelfDescribing.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 HCDescription;
/**
The ability of an object to describe itself.
@ingroup core
*/
@protocol HCSelfDescribing <NSObject>
/**
Generates a description of the object.
The description may be part of a description of a larger object of which this is just a
component, so it should be worded appropriately.
@param description The description to be built or appended to.
*/
- (void)describeTo:(id<HCDescription>)description;
@end
@@ -0,0 +1,43 @@
//
// OCHamcrest - HCStringDescription.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/HCBaseDescription.h>
@protocol HCSelfDescribing;
/**
An HCDescription that is stored as a string.
@ingroup core
*/
@interface HCStringDescription : HCBaseDescription
{
NSMutableString *accumulator;
}
/**
Returns the description of an HCSelfDescribing object as a string.
@param selfDescribing The object to be described.
@return The description of the object.
*/
+ (NSString *)stringFrom:(id<HCSelfDescribing>)selfDescribing;
/**
Returns an empty description.
*/
+ (HCStringDescription *)stringDescription;
/**
Returns an initialized HCStringDescription object that is empty.
*/
- (id)init;
@end
@@ -0,0 +1,47 @@
//
// OCHamcrest - HCStringDescription.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 "HCStringDescription.h"
#import "HCSelfDescribing.h"
@implementation HCStringDescription
+ (NSString *)stringFrom:(id<HCSelfDescribing>)selfDescribing
{
HCStringDescription *description = [HCStringDescription stringDescription];
[description appendDescriptionOf:selfDescribing];
return [description description];
}
+ (HCStringDescription *)stringDescription
{
return [[HCStringDescription alloc] init];
}
- (id)init
{
self = [super init];
if (self)
accumulator = [[NSMutableString alloc] init];
return self;
}
- (NSString *)description
{
return accumulator;
}
- (void)append:(NSString *)str
{
[accumulator appendString:str];
}
@end
@@ -0,0 +1,23 @@
//
// OCHamcrest - HCCollectMatchers.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>
#import <objc/objc-api.h>
#import <stdarg.h>
@protocol HCMatcher;
/**
Returns an array of matchers from a variable-length comma-separated list terminated by @c nil.
@ingroup helpers
*/
OBJC_EXPORT NSMutableArray *HCCollectMatchers(id item1, va_list args);
@@ -0,0 +1,27 @@
//
// OCHamcrest - HCCollectMatchers.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 "HCCollectMatchers.h"
#import "HCWrapInMatcher.h"
NSMutableArray *HCCollectMatchers(id item, va_list args)
{
NSMutableArray *matcherList = [NSMutableArray arrayWithObject:HCWrapInMatcher(item)];
item = va_arg(args, id);
while (item != nil)
{
[matcherList addObject:HCWrapInMatcher(item)];
item = va_arg(args, id);
}
return matcherList;
}
@@ -0,0 +1,57 @@
//
// OCHamcrest - HCInvocationMatcher.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>
/**
Supporting class for matching a feature of an object.
Tests whether the result of passing a given invocation to the value satisfies a given matcher.
@ingroup helpers
*/
@interface HCInvocationMatcher : HCBaseMatcher
{
NSInvocation *invocation;
id<HCMatcher> subMatcher;
BOOL shortMismatchDescription;
}
/**
Determines whether a mismatch will be described in short form.
Default is long form, which describes the object, the name of the invocation, and the
sub-matcher's mismatch diagnosis. Short form only has the sub-matcher's mismatch diagnosis.
*/
@property (assign, nonatomic) BOOL shortMismatchDescription;
/**
Helper method for creating an invocation.
A class is specified only so we can determine the method signature.
*/
+ (NSInvocation *)invocationForSelector:(SEL)selector onClass:(Class)aClass;
/**
Returns an HCInvocationMatcher object initialized with an invocation and a matcher.
*/
- (id)initWithInvocation:(NSInvocation *)anInvocation matching:(id<HCMatcher>)aMatcher;
/**
Invokes stored invocation on given item and returns the result.
*/
- (id)invokeOn:(id)item;
/**
Returns string representation of the invocation's selector.
*/
- (NSString *)stringFromSelector;
@end
@@ -0,0 +1,85 @@
//
// OCHamcrest - HCInvocationMatcher.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 "HCInvocationMatcher.h"
#import "HCDescription.h"
@implementation HCInvocationMatcher
@synthesize shortMismatchDescription;
+ (NSInvocation *)invocationForSelector:(SEL)selector onClass:(Class)aClass
{
NSMethodSignature* signature = [aClass instanceMethodSignatureForSelector:selector];
NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:signature];
[invocation setSelector:selector];
return invocation;
}
- (id)initWithInvocation:(NSInvocation *)anInvocation matching:(id<HCMatcher>)aMatcher
{
self = [super init];
if (self)
{
invocation = anInvocation;
subMatcher = aMatcher;
}
return self;
}
- (NSString *)stringFromSelector
{
return NSStringFromSelector([invocation selector]);
}
- (id)invokeOn:(id)item
{
__unsafe_unretained id result = nil;
[invocation invokeWithTarget:item];
[invocation getReturnValue:&result];
return result;
}
- (BOOL)matches:(id)item
{
if (![item respondsToSelector:[invocation selector]])
return NO;
return [subMatcher matches:[self invokeOn:item]];
}
- (void)describeMismatchOf:(id)item to:(id<HCDescription>)mismatchDescription
{
if (![item respondsToSelector:[invocation selector]])
[super describeMismatchOf:item to:mismatchDescription];
else
{
if (!shortMismatchDescription)
{
[[[[mismatchDescription appendDescriptionOf:item]
appendText:@" "]
appendText:[self stringFromSelector]]
appendText:@" "];
}
[subMatcher describeMismatchOf:[self invokeOn:item] to:mismatchDescription];
}
}
- (void)describeTo:(id<HCDescription>)description
{
[[[[description appendText:@"an object with "]
appendText:[self stringFromSelector]]
appendText:@" "]
appendDescriptionOf:subMatcher];
}
@end
@@ -0,0 +1,19 @@
//
// OCHamcrest - HCRequireNonNilObject.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>
#import <objc/objc-api.h>
/**
Throws an NSException if @a obj is @c nil.
@ingroup helpers
*/
OBJC_EXPORT void HCRequireNonNilObject(id obj);
@@ -0,0 +1,21 @@
//
// OCHamcrest - HCRequireNonNilObject.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 "HCRequireNonNilObject.h"
void HCRequireNonNilObject(id obj)
{
if (obj == nil)
{
@throw [NSException exceptionWithName:@"NilObject"
reason:@"Must be non-nil object"
userInfo:nil];
}
}
@@ -0,0 +1,21 @@
//
// OCHamcrest - HCRequireNonNilString.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>
#import <objc/objc-api.h>
/**
Throws an NSException if @a string is @c nil.
@b Deprecated: Use @ref HCRequireNonNilObject instead.
@ingroup helpers
*/
OBJC_EXPORT void HCRequireNonNilString(NSString *string) __attribute__((deprecated));
@@ -0,0 +1,21 @@
//
// OCHamcrest - HCRequireNonNilString.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 "HCRequireNonNilString.h"
void HCRequireNonNilString(NSString *string)
{
if (string == nil)
{
@throw [NSException exceptionWithName:@"NotAString"
reason:@"Must be non-nil string"
userInfo:nil];
}
}
@@ -0,0 +1,22 @@
//
// OCHamcrest - HCWrapInMatcher.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 <objc/objc-api.h>
@protocol HCMatcher;
/**
Wraps argument in a matcher, if necessary.
@return The argument as-if if it is already a matcher, otherwise wrapped in an @ref equalTo matcher.
@ingroup helpers
*/
OBJC_EXPORT id<HCMatcher> HCWrapInMatcher(id matcherOrValue);
@@ -0,0 +1,24 @@
//
// OCHamcrest - HCWrapInMatcher.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 "HCWrapInMatcher.h"
#import "HCIsEqual.h"
id<HCMatcher> HCWrapInMatcher(id matcherOrValue)
{
if (!matcherOrValue)
return nil;
if ([matcherOrValue conformsToProtocol:@protocol(HCMatcher)])
return matcherOrValue;
else
return HC_equalTo(matcherOrValue);
}
@@ -0,0 +1,120 @@
//
// OCHamcrest - CustomMatchers.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
//
/**
@page custom-matchers Writing custom matchers
OCHamcrest comes bundled with lots of useful matchers, but you'll probably find that you need to
create your own from time to time to fit your testing needs.
This commonly occurs when you find a fragment of code that tests the same set of properties over
and over again (and in different tests), and you want to bundle the fragment into a single assertion.
By writing your own matcher you'll eliminate code duplication and make your tests more readable!
Let's write our own matcher for testing if a calendar date falls on a Saturday. This is the test
we want to write:
@code
- (void)testDateIsOnASaturday
{
NSCalendarDate* date = [NSCalendarDate dateWithString:@"26 Apr 2008" calendarFormat:@"%d %b %Y"];
assertThat(date, is(onASaturday()))
}
@endcode
Here's the interface:
@code
#import <OCHamcrest/HCBaseMatcher.h>
#import <objc/objc-api.h>
@interface IsGivenDayOfWeek : HCBaseMatcher
{
NSInteger day; // Sunday is 0, Saturday is 6
}
+ (id)isGivenDayOfWeek:(NSInteger)dayOfWeek;
- (id)initWithDay:(NSInteger)dayOfWeek;
@end
OBJC_EXPORT id <HCMatcher> onASaturday();
@endcode
The interface consists of two parts: a class definition, and a factory function (with C binding).
Here's what the implementation looks like:
@code
#import "IsGivenDayOfWeek.h"
#import <OCHamcrest/HCDescription.h>
@implementation IsGivenDayOfWeek
+ (id)isGivenDayOfWeek:(NSInteger)dayOfWeek
{
return [[self alloc] initWithDay:dayOfWeek];
}
- (id)initWithDay:(NSInteger)dayOfWeek
{
self = [super init];
if (self != nil)
day = dayOfWeek;
return self;
}
// Test whether item matches.
- (BOOL)matches:(id)item
{
if (![item respondsToSelector:@selector(dayOfWeek)])
return NO;
return [item dayOfWeek] == day;
}
// Describe the matcher.
- (void)describeTo:(id <HCDescription>)description
{
NSString *dayAsString[] =
{ @"Sunday", @"Monday", @"Tuesday", @"Wednesday", @"Thursday", @"Friday", @"Saturday" };
[[description appendText:@"calendar date falling on "] appendText:dayAsString[day]];
}
@end
id <HCMatcher> onASaturday()
{
return [IsGivenDayOfWeek isGivenDayOfWeek:6];
}
@endcode
For our Matcher implementation we implement the @c -matches: method (which calls
@c -dayOfWeek after confirming that the argument has such a method) and the
@c -describe_to: method (which is used to produce a failure message when a test fails).
Here's an example of how the failure message looks:
@code
NSCalendarDate* date = [NSCalendarDate dateWithString: @"6 April 2008"
calendarFormat: @"%d %B %Y"];
assertThat(date, is(onASaturday()));
@endcode
fails with the message
@verbatim Expected: is calendar date falling on Saturday, got: <06 April 2008> @endverbatim
and Xcode shows it as a build error. Clicking the error message takes you to the assertion that
failed.
Even though the @c onASaturday function creates a new matcher each time it is called, you should
not assume this is the only usage pattern for your matcher. Therefore you should make sure your
matcher is stateless, so a single instance can be reused between matches.
*/
@@ -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
@@ -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));
}
@@ -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
@@ -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];
}
@@ -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
@@ -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];
}
@@ -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
@@ -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];
}
@@ -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
@@ -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]];
}
@@ -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
@@ -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)];
}
@@ -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
@@ -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];
}
@@ -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
@@ -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)];
}
@@ -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
@@ -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)];
}
@@ -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
@@ -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];
}
@@ -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
@@ -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];
}
@@ -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
@@ -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)];
}
@@ -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
@@ -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
@@ -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];
}
@@ -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
@@ -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)
@@ -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
@@ -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)
@@ -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
@@ -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"];
}
@@ -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
@@ -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);
}
@@ -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
@@ -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)];
}
@@ -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
@@ -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];
}
@@ -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
@@ -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];
}
@@ -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
@@ -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];
}
Loaded 100 of 1261 files, more files were not shown because too many files have changed in this diff. Show more