├── RubyficationTests ├── en.lproj │ └── InfoPlist.strings ├── RubyficationTests-Prefix.pch ├── RubyficationTests.h ├── RubyficationTests.m ├── RubyficationTests-Info.plist └── DateSpec.m ├── .gitignore ├── Rubyfication ├── Rubyfication-Prefix.pch ├── NSArray+activesupport.h ├── NSString+functional.h ├── NSString+activesupport.h ├── NSString+functional.m ├── NSArray+functional.h ├── NSArray+helpers.h ├── NSDate+helpers.h ├── NSString+helpers.h ├── NSString+activesupport.m ├── NSArray+activesupport.m ├── NSArray+functional.m └── NSDate+helpers.m ├── Kiwi ├── KiwiNewMacros.h ├── KWProbe.h ├── KWCountType.h ├── NSValue+KiwiAdditions.h ├── KWFormatter.h ├── KWBeNonNilMatcher.h ├── KWExpectationType.h ├── KWBeNilMatcher.h ├── KWBeZeroMatcher.h ├── KWCaptureSpy.h ├── KWDeviceInfo.h ├── KWHCMatcher.h ├── KWReporting.h ├── KWMessageSpying.h ├── KWBeEmptyMatcher.h ├── KWEqualMatcher.h ├── KiwiBlockMacros.h ├── KWBeIdenticalToMatcher.h ├── KWBeKindOfClassMatcher.h ├── KWExampleGroupDelegate.h ├── KWAny.h ├── NSObject+KiwiMockAdditions.h ├── KWBeMemberOfClassMatcher.h ├── KWRespondToSelectorMatcher.h ├── KWBeSubclassOfClassMatcher.h ├── KWAfterAllNode.h ├── KWAfterEachNode.h ├── KWBeforeAllNode.h ├── KWConformToProtocolMatcher.h ├── NSMethodSignature+KiwiAdditions.h ├── KWBeTrueMatcher.h ├── KWBeforeEachNode.h ├── KWVerifying.h ├── KWExampleNode.h ├── KWNull.h ├── KWHamcrestMatcher.h ├── KWBeWithinMatcher.h ├── NSObject+KiwiVerifierAdditions.h ├── KWStringPrefixMatcher.h ├── KWFutureObject.h ├── KWWorkarounds.h ├── KWProbePoller.h ├── KWStringContainsMatcher.h ├── NSMethodSignature+KiwiAdditions.m ├── KWBeBetweenMatcher.h ├── KWBlockRaiseMatcher.h ├── NSValue+KiwiAdditions.m ├── KWDeviceInfo.m ├── KWStringUtilities.h ├── KWBlock.h ├── KWAfterAllNode.m ├── KWAfterEachNode.m ├── KWBeforeAllNode.m ├── KWBeforeEachNode.m ├── KWContainMatcher.h ├── KWHaveValueMatcher.h ├── KWRaiseMatcher.h ├── NSObject+KiwiVerifierAdditions.m ├── NSObject+KiwiMockAdditions.m ├── KWItNode.h ├── KWInequalityMatcher.h ├── KWHamrestMatchingAdditions.h ├── KWWorkarounds.m ├── KWExampleSuite.h ├── KWAny.m ├── KWCallSite.h ├── KWNull.m ├── KWFutureObject.m ├── KWRegisterMatchersNode.h ├── KWStringPrefixMatcher.m ├── KWExistVerifier.h ├── KWExampleNodeVisitor.h ├── KWMatching.h ├── KWSpec.h ├── KWFailure.h ├── KWBlockNode.h ├── KWMatcher.h ├── KWPendingNode.h ├── KWStringContainsMatcher.m ├── NSInvocation+KiwiAdditions.h ├── KWMatchers.h ├── KWAsyncVerifier.h ├── KWFormatter.m ├── KiwiConfiguration.h ├── KWBeNilMatcher.m ├── KWBlockNode.m ├── KWBeNonNilMatcher.m ├── NSNumber+KiwiAdditions.h ├── KWObjCUtilities.h ├── KWBlock.m ├── KWInvocationCapturer.h ├── NSObject+KiwiStubAdditions.h ├── KWBeZeroMatcher.m ├── KWHamcrestMatcher.m ├── KWMatcherFactory.h ├── KWRegisterMatchersNode.m ├── KWHaveMatcher.h ├── KWBeKindOfClassMatcher.m ├── KWRespondToSelectorMatcher.m ├── KWConformToProtocolMatcher.m ├── KWBeMemberOfClassMatcher.m ├── KWCallSite.m ├── KWTestCase.h ├── KWMessageTracker.h ├── KWBeSubclassOfClassMatcher.m ├── KWMessagePattern.h ├── KWStub.h ├── KWIntercept.h ├── KWProbePoller.m ├── KWCaptureSpy.m ├── KWExampleGroupBuilder.h ├── KWBeTrueMatcher.m ├── KWMatchVerifier.h ├── KWItNode.m ├── KWBeEmptyMatcher.m ├── KWPendingNode.m ├── KWHamrestMatchingAdditions.m ├── KWMatchers.m ├── KWBeIdenticalToMatcher.m ├── KWUserDefinedMatcher.h ├── KWEqualMatcher.m ├── KWFailure.m ├── KWExampleSuite.m ├── KWContextNode.h ├── KWExistVerifier.m ├── KWMatcher.m ├── KWBeBetweenMatcher.m ├── KWValue.h ├── KWReceiveMatcher.h ├── Kiwi.h ├── KWContainMatcher.m ├── KWInvocationCapturer.m ├── KiwiMacros.h ├── KWStringUtilities.m ├── KWMock.h ├── KWExample.h ├── NSInvocation+KiwiAdditions.m ├── KWAsyncVerifier.m ├── KWObjCUtilities.m ├── KWHaveValueMatcher.m └── KWBlockRaiseMatcher.m ├── CocoaOniguruma ├── CocoaOniguruma-Prefix.pch ├── oniguruma │ ├── COPYING │ ├── st.h │ ├── regversion.c │ ├── enc │ │ └── ascii.c │ └── regtrav.c ├── OnigRegexpUtility.h └── OnigRegexp.h └── README.textile /RubyficationTests/en.lproj/InfoPlist.strings: -------------------------------------------------------------------------------- 1 | /* Localized versions of Info.plist keys */ 2 | 3 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | build/ 2 | .DS_Store 3 | **/*.pbxuser 4 | *.mode2v3 5 | *.mode1v3 6 | **/*.perspectivev* 7 | **/xcuserdata/* 8 | **/*.xcworkspace/* 9 | -------------------------------------------------------------------------------- /Rubyfication/Rubyfication-Prefix.pch: -------------------------------------------------------------------------------- 1 | // 2 | // Prefix header for all source files of the 'Rubyfication' target in the 'Rubyfication' project 3 | // 4 | 5 | #ifdef __OBJC__ 6 | #import 7 | #endif 8 | -------------------------------------------------------------------------------- /Kiwi/KiwiNewMacros.h: -------------------------------------------------------------------------------- 1 | // 2 | // KiwiNewMacros.h 3 | // Kiwi 4 | // 5 | // Created by Luke Redpath on 11/07/2011. 6 | // Copyright 2011 Allen Ding. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | -------------------------------------------------------------------------------- /CocoaOniguruma/CocoaOniguruma-Prefix.pch: -------------------------------------------------------------------------------- 1 | // 2 | // Prefix header for all source files of the 'CocoaOniguruma' target in the 'CocoaOniguruma' project 3 | // 4 | 5 | #ifdef __OBJC__ 6 | #import 7 | #import "OnigRegexp.h" 8 | #endif 9 | -------------------------------------------------------------------------------- /RubyficationTests/RubyficationTests-Prefix.pch: -------------------------------------------------------------------------------- 1 | // 2 | // Prefix header for all source files of the 'RubyficationTests' target in the 'RubyficationTests' project 3 | // 4 | 5 | #ifdef __OBJC__ 6 | #import 7 | #import 8 | #endif 9 | -------------------------------------------------------------------------------- /Kiwi/KWProbe.h: -------------------------------------------------------------------------------- 1 | // 2 | // KWProbe.h 3 | // iOSFalconCore 4 | // 5 | // Created by Luke Redpath on 13/01/2011. 6 | // Copyright 2011 LJR Software Limited. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @protocol KWProbe 12 | - (BOOL)isSatisfied; 13 | - (void)sample; 14 | @end 15 | -------------------------------------------------------------------------------- /Kiwi/KWCountType.h: -------------------------------------------------------------------------------- 1 | // 2 | // Licensed under the terms in License.txt 3 | // 4 | // Copyright 2010 Allen Ding. All rights reserved. 5 | // 6 | 7 | #import "KiwiConfiguration.h" 8 | 9 | enum { 10 | KWCountTypeExact, 11 | KWCountTypeAtLeast, 12 | KWCountTypeAtMost 13 | }; 14 | 15 | typedef NSUInteger KWCountType; 16 | -------------------------------------------------------------------------------- /Kiwi/NSValue+KiwiAdditions.h: -------------------------------------------------------------------------------- 1 | // 2 | // Licensed under the terms in License.txt 3 | // 4 | // Copyright 2010 Allen Ding. All rights reserved. 5 | // 6 | 7 | #import "KiwiConfiguration.h" 8 | 9 | @interface NSValue(KiwiAdditions) 10 | 11 | #pragma mark - 12 | #pragma mark Accessing Data 13 | 14 | - (NSData *)dataValue; 15 | 16 | @end 17 | -------------------------------------------------------------------------------- /Kiwi/KWFormatter.h: -------------------------------------------------------------------------------- 1 | // 2 | // Licensed under the terms in License.txt 3 | // 4 | // Copyright 2010 Allen Ding. All rights reserved. 5 | // 6 | 7 | #import "KiwiConfiguration.h" 8 | 9 | @interface KWFormatter : NSObject 10 | 11 | #pragma mark - 12 | #pragma mark Getting Descriptions 13 | 14 | + (NSString *)formatObject:(id)anObject; 15 | 16 | @end 17 | -------------------------------------------------------------------------------- /Kiwi/KWBeNonNilMatcher.h: -------------------------------------------------------------------------------- 1 | // 2 | // KWBeNotNilMatcher.h 3 | // Kiwi 4 | // 5 | // Created by Luke Redpath on 17/01/2011. 6 | // Copyright 2011 Allen Ding. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "KWMatcher.h" 11 | 12 | @interface KWBeNonNilMatcher : KWMatcher { 13 | 14 | } 15 | - (void)beNonNil; 16 | @end 17 | -------------------------------------------------------------------------------- /Kiwi/KWExpectationType.h: -------------------------------------------------------------------------------- 1 | // 2 | // Licensed under the terms in License.txt 3 | // 4 | // Copyright 2010 Allen Ding. All rights reserved. 5 | // 6 | 7 | #import "KiwiConfiguration.h" 8 | 9 | enum { 10 | KWExpectationTypeShould, 11 | KWExpectationTypeShouldNot, 12 | KWExpectationTypeMaybe 13 | }; 14 | 15 | typedef NSUInteger KWExpectationType; 16 | -------------------------------------------------------------------------------- /Kiwi/KWBeNilMatcher.h: -------------------------------------------------------------------------------- 1 | // 2 | // KWBeNilMatcher.h 3 | // iOSFalconCore 4 | // 5 | // Created by Luke Redpath on 14/01/2011. 6 | // Copyright 2011 LJR Software Limited. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "KWMatcher.h" 11 | 12 | @interface KWBeNilMatcher : KWMatcher { 13 | 14 | } 15 | - (void)beNil; 16 | @end 17 | -------------------------------------------------------------------------------- /Kiwi/KWBeZeroMatcher.h: -------------------------------------------------------------------------------- 1 | // 2 | // Licensed under the terms in License.txt 3 | // 4 | // Copyright 2010 Allen Ding. All rights reserved. 5 | // 6 | 7 | #import "KiwiConfiguration.h" 8 | #import "KWMatcher.h" 9 | 10 | @interface KWBeZeroMatcher : KWMatcher 11 | 12 | #pragma mark - 13 | #pragma mark Configuring Matchers 14 | 15 | - (void)beZero; 16 | 17 | @end 18 | -------------------------------------------------------------------------------- /Kiwi/KWCaptureSpy.h: -------------------------------------------------------------------------------- 1 | #import 2 | #import "KWMock.h" 3 | #import "KWMessageSpying.h" 4 | 5 | @interface KWCaptureSpy : NSObject { 6 | id _argument; 7 | NSUInteger _argumentIndex; 8 | } 9 | 10 | - (id)initWithArgumentIndex:(NSUInteger)index; 11 | @property(nonatomic, readonly, retain) id argument; 12 | 13 | @end 14 | -------------------------------------------------------------------------------- /Kiwi/KWDeviceInfo.h: -------------------------------------------------------------------------------- 1 | // 2 | // Licensed under the terms in License.txt 3 | // 4 | // Copyright 2010 Allen Ding. All rights reserved. 5 | // 6 | 7 | #import "KiwiConfiguration.h" 8 | 9 | @interface KWDeviceInfo : NSObject 10 | 11 | #pragma mark - 12 | #pragma mark Getting the Device Type 13 | 14 | + (BOOL)isSimulator; 15 | + (BOOL)isPhysical; 16 | 17 | @end 18 | -------------------------------------------------------------------------------- /Kiwi/KWHCMatcher.h: -------------------------------------------------------------------------------- 1 | /** 2 | * This is a minimal version of HCMatcher from the Hamcrest library, purely 3 | * to support Hamcrest integration with Kiwi. 4 | * 5 | * The Hamcrest project can be found here: http://code.google.com/p/hamcrest/ 6 | */ 7 | 8 | #import 9 | 10 | @protocol HCMatcher 11 | - (BOOL)matches:(id)item; 12 | @end 13 | -------------------------------------------------------------------------------- /Kiwi/KWReporting.h: -------------------------------------------------------------------------------- 1 | // 2 | // Licensed under the terms in License.txt 3 | // 4 | // Copyright 2010 Allen Ding. All rights reserved. 5 | // 6 | 7 | #import "KiwiConfiguration.h" 8 | 9 | @class KWFailure; 10 | 11 | @protocol KWReporting 12 | 13 | #pragma mark - 14 | #pragma mark Reporting Failures 15 | 16 | - (void)reportFailure:(KWFailure *)failure; 17 | 18 | @end 19 | -------------------------------------------------------------------------------- /Kiwi/KWMessageSpying.h: -------------------------------------------------------------------------------- 1 | // 2 | // Licensed under the terms in License.txt 3 | // 4 | // Copyright 2010 Allen Ding. All rights reserved. 5 | // 6 | 7 | #import "KiwiConfiguration.h" 8 | 9 | @protocol KWMessageSpying 10 | 11 | #pragma mark - 12 | #pragma mark Spying on Messages 13 | 14 | - (void)object:(id)anObject didReceiveInvocation:(NSInvocation *)anInvocation; 15 | 16 | @end 17 | -------------------------------------------------------------------------------- /RubyficationTests/RubyficationTests.h: -------------------------------------------------------------------------------- 1 | // 2 | // RubyficationTests.h 3 | // RubyficationTests 4 | // 5 | // Created by Fabio Akita on 4/23/11. 6 | // Copyright 2011 __MyCompanyName__. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "NSString+helpers.h" 11 | 12 | @interface RubyficationTests : SenTestCase { 13 | @private 14 | 15 | } 16 | 17 | @end 18 | -------------------------------------------------------------------------------- /Kiwi/KWBeEmptyMatcher.h: -------------------------------------------------------------------------------- 1 | // 2 | // Licensed under the terms in License.txt 3 | // 4 | // Copyright 2010 Allen Ding. All rights reserved. 5 | // 6 | 7 | #import "KiwiConfiguration.h" 8 | #import "KWMatcher.h" 9 | 10 | @interface KWBeEmptyMatcher : KWMatcher { 11 | @private 12 | NSUInteger count; 13 | } 14 | 15 | #pragma mark - 16 | #pragma mark Configuring Matchers 17 | 18 | - (void)beEmpty; 19 | 20 | @end 21 | -------------------------------------------------------------------------------- /Kiwi/KWEqualMatcher.h: -------------------------------------------------------------------------------- 1 | // 2 | // Licensed under the terms in License.txt 3 | // 4 | // Copyright 2010 Allen Ding. All rights reserved. 5 | // 6 | 7 | #import "KiwiConfiguration.h" 8 | #import "KWMatcher.h" 9 | 10 | @interface KWEqualMatcher : KWMatcher { 11 | @private 12 | id otherSubject; 13 | } 14 | 15 | #pragma mark - 16 | #pragma mark Configuring Matchers 17 | 18 | - (void)equal:(id)anObject; 19 | 20 | @end 21 | -------------------------------------------------------------------------------- /Kiwi/KiwiBlockMacros.h: -------------------------------------------------------------------------------- 1 | // 2 | // KiwiBlockMacros.h 3 | // Kiwi 4 | // 5 | // Created by Luke Redpath on 11/07/2011. 6 | // Copyright 2011 Allen Ding. All rights reserved. 7 | // 8 | 9 | // user defined matchers 10 | #define registerMatcher(name) \ 11 | \ 12 | @interface NSObject (KWUserDefinedMatchersDefinitions) \ 13 | - (void)name; \ 14 | @end \ 15 | 16 | #define defineMatcher(...) KWDefineMatchers(__VA_ARGS__) 17 | -------------------------------------------------------------------------------- /RubyficationTests/RubyficationTests.m: -------------------------------------------------------------------------------- 1 | // 2 | // RubyficationTests.m 3 | // RubyficationTests 4 | // 5 | // Created by Fabio Akita on 4/23/11. 6 | // Copyright 2011 __MyCompanyName__. All rights reserved. 7 | // 8 | 9 | #import "RubyficationTests.h" 10 | #import "NSArray+functional.h" 11 | 12 | @implementation RubyficationTests 13 | 14 | - (void)testExample 15 | { 16 | STAssertTrue(TRUE, @"dummy"); 17 | } 18 | 19 | @end 20 | -------------------------------------------------------------------------------- /Kiwi/KWBeIdenticalToMatcher.h: -------------------------------------------------------------------------------- 1 | // 2 | // Licensed under the terms in License.txt 3 | // 4 | // Copyright 2010 Allen Ding. All rights reserved. 5 | // 6 | 7 | #import "KiwiConfiguration.h" 8 | #import "KWMatcher.h" 9 | 10 | @interface KWBeIdenticalToMatcher : KWMatcher { 11 | @private 12 | id otherSubject; 13 | } 14 | 15 | #pragma mark - 16 | #pragma mark Configuring Matchers 17 | 18 | - (void)beIdenticalTo:(id)anObject; 19 | 20 | @end 21 | -------------------------------------------------------------------------------- /Kiwi/KWBeKindOfClassMatcher.h: -------------------------------------------------------------------------------- 1 | // 2 | // Licensed under the terms in License.txt 3 | // 4 | // Copyright 2010 Allen Ding. All rights reserved. 5 | // 6 | 7 | #import "KiwiConfiguration.h" 8 | #import "KWMatcher.h" 9 | 10 | @interface KWBeKindOfClassMatcher : KWMatcher { 11 | @private 12 | Class targetClass; 13 | } 14 | 15 | #pragma mark - 16 | #pragma mark Configuring Matchers 17 | 18 | - (void)beKindOfClass:(Class)aClass; 19 | 20 | @end 21 | -------------------------------------------------------------------------------- /Kiwi/KWExampleGroupDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // KWExampleGroupDelegate.h 3 | // Kiwi 4 | // 5 | // Created by Luke Redpath on 08/09/2011. 6 | // Copyright 2011 Allen Ding. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @class KWExample; 12 | @class KWFailure; 13 | 14 | @protocol KWExampleDelegate 15 | 16 | - (void)example:(KWExample *)example didFailWithFailure:(KWFailure *)failure; 17 | 18 | @end 19 | -------------------------------------------------------------------------------- /Kiwi/KWAny.h: -------------------------------------------------------------------------------- 1 | // 2 | // Licensed under the terms in License.txt 3 | // 4 | // Copyright 2010 Allen Ding. All rights reserved. 5 | // 6 | 7 | #import "KiwiConfiguration.h" 8 | 9 | // KWAny exists to determine arguments in a message pattern that should 10 | // match any value. Used for pointers as well as for scalar values. 11 | @interface KWAny : NSObject 12 | 13 | #pragma mark - 14 | #pragma mark Initializing 15 | 16 | + (id)any; 17 | 18 | @end 19 | -------------------------------------------------------------------------------- /Kiwi/NSObject+KiwiMockAdditions.h: -------------------------------------------------------------------------------- 1 | // 2 | // Licensed under the terms in License.txt 3 | // 4 | // Copyright 2010 Allen Ding. All rights reserved. 5 | // 6 | 7 | #import "KiwiConfiguration.h" 8 | 9 | @interface NSObject(KiwiMockAdditions) 10 | 11 | #pragma mark - 12 | #pragma mark Creating Mocks 13 | 14 | + (id)mock; 15 | + (id)mockWithName:(NSString *)aName; 16 | 17 | + (id)nullMock; 18 | + (id)nullMockWithName:(NSString *)aName; 19 | 20 | @end 21 | -------------------------------------------------------------------------------- /Kiwi/KWBeMemberOfClassMatcher.h: -------------------------------------------------------------------------------- 1 | // 2 | // Licensed under the terms in License.txt 3 | // 4 | // Copyright 2010 Allen Ding. All rights reserved. 5 | // 6 | 7 | #import "KiwiConfiguration.h" 8 | #import "KWMatcher.h" 9 | 10 | @interface KWBeMemberOfClassMatcher : KWMatcher { 11 | @private 12 | Class targetClass; 13 | } 14 | 15 | #pragma mark - 16 | #pragma mark Configuring Matchers 17 | 18 | - (void)beMemberOfClass:(Class)aClass; 19 | 20 | @end 21 | -------------------------------------------------------------------------------- /Kiwi/KWRespondToSelectorMatcher.h: -------------------------------------------------------------------------------- 1 | // 2 | // Licensed under the terms in License.txt 3 | // 4 | // Copyright 2010 Allen Ding. All rights reserved. 5 | // 6 | 7 | #import "KiwiConfiguration.h" 8 | #import "KWMatcher.h" 9 | 10 | @interface KWRespondToSelectorMatcher : KWMatcher { 11 | @private 12 | SEL selector; 13 | } 14 | 15 | #pragma mark - 16 | #pragma mark Configuring Matchers 17 | 18 | - (void)respondToSelector:(SEL)aSelector; 19 | 20 | @end 21 | -------------------------------------------------------------------------------- /Kiwi/KWBeSubclassOfClassMatcher.h: -------------------------------------------------------------------------------- 1 | // 2 | // Licensed under the terms in License.txt 3 | // 4 | // Copyright 2010 Allen Ding. All rights reserved. 5 | // 6 | 7 | #import "KiwiConfiguration.h" 8 | #import "KWMatcher.h" 9 | 10 | @interface KWBeSubclassOfClassMatcher : KWMatcher { 11 | @private 12 | Class targetClass; 13 | } 14 | 15 | #pragma mark - 16 | #pragma mark Configuring Matchers 17 | 18 | - (void)beSubclassOfClass:(Class)aClass; 19 | 20 | @end 21 | -------------------------------------------------------------------------------- /Kiwi/KWAfterAllNode.h: -------------------------------------------------------------------------------- 1 | // 2 | // Licensed under the terms in License.txt 3 | // 4 | // Copyright 2010 Allen Ding. All rights reserved. 5 | // 6 | 7 | #import "KiwiConfiguration.h" 8 | #import "KWBlockNode.h" 9 | #import "KWExampleNode.h" 10 | 11 | @interface KWAfterAllNode : KWBlockNode 12 | 13 | #pragma mark - 14 | #pragma mark Initializing 15 | 16 | + (id)afterAllNodeWithCallSite:(KWCallSite *)aCallSite block:(KWVoidBlock)aBlock; 17 | 18 | @end 19 | -------------------------------------------------------------------------------- /Kiwi/KWAfterEachNode.h: -------------------------------------------------------------------------------- 1 | // 2 | // Licensed under the terms in License.txt 3 | // 4 | // Copyright 2010 Allen Ding. All rights reserved. 5 | // 6 | 7 | #import "KiwiConfiguration.h" 8 | #import "KWBlockNode.h" 9 | #import "KWExampleNode.h" 10 | 11 | @interface KWAfterEachNode : KWBlockNode 12 | 13 | #pragma mark - 14 | #pragma mark Initializing 15 | 16 | + (id)afterEachNodeWithCallSite:(KWCallSite *)aCallSite block:(KWVoidBlock)aBlock; 17 | 18 | @end 19 | -------------------------------------------------------------------------------- /Kiwi/KWBeforeAllNode.h: -------------------------------------------------------------------------------- 1 | // 2 | // Licensed under the terms in License.txt 3 | // 4 | // Copyright 2010 Allen Ding. All rights reserved. 5 | // 6 | 7 | #import "KiwiConfiguration.h" 8 | #import "KWBlockNode.h" 9 | #import "KWExampleNode.h" 10 | 11 | @interface KWBeforeAllNode : KWBlockNode 12 | 13 | #pragma mark - 14 | #pragma mark Initializing 15 | 16 | + (id)beforeAllNodeWithCallSite:(KWCallSite *)aCallSite block:(KWVoidBlock)aBlock; 17 | 18 | @end 19 | -------------------------------------------------------------------------------- /Kiwi/KWConformToProtocolMatcher.h: -------------------------------------------------------------------------------- 1 | // 2 | // Licensed under the terms in License.txt 3 | // 4 | // Copyright 2010 Allen Ding. All rights reserved. 5 | // 6 | 7 | #import "KiwiConfiguration.h" 8 | #import "KWMatcher.h" 9 | 10 | @interface KWConformToProtocolMatcher : KWMatcher { 11 | @private 12 | Protocol *protocol; 13 | } 14 | 15 | #pragma mark - 16 | #pragma mark Configuring Matchers 17 | 18 | - (void)conformToProtocol:(Protocol *)aProtocol; 19 | 20 | @end 21 | -------------------------------------------------------------------------------- /Kiwi/NSMethodSignature+KiwiAdditions.h: -------------------------------------------------------------------------------- 1 | // 2 | // Licensed under the terms in License.txt 3 | // 4 | // Copyright 2010 Allen Ding. All rights reserved. 5 | // 6 | 7 | #import "KiwiConfiguration.h" 8 | 9 | @interface NSMethodSignature(KiwiAdditions) 10 | 11 | #pragma mark - 12 | #pragma mark Getting Information on Message Arguments 13 | 14 | - (NSUInteger)numberOfMessageArguments; 15 | - (const char *)messageArgumentTypeAtIndex:(NSUInteger)anIndex; 16 | 17 | @end 18 | -------------------------------------------------------------------------------- /Kiwi/KWBeTrueMatcher.h: -------------------------------------------------------------------------------- 1 | // 2 | // Licensed under the terms in License.txt 3 | // 4 | // Copyright 2010 Allen Ding. All rights reserved. 5 | // 6 | 7 | #import "KiwiConfiguration.h" 8 | #import "KWMatcher.h" 9 | 10 | @interface KWBeTrueMatcher : KWMatcher { 11 | @private 12 | BOOL expectedValue; 13 | } 14 | 15 | #pragma mark - 16 | #pragma mark Configuring Matchers 17 | 18 | - (void)beTrue; 19 | - (void)beFalse; 20 | - (void)beYes; 21 | - (void)beNo; 22 | 23 | @end 24 | -------------------------------------------------------------------------------- /Kiwi/KWBeforeEachNode.h: -------------------------------------------------------------------------------- 1 | // 2 | // Licensed under the terms in License.txt 3 | // 4 | // Copyright 2010 Allen Ding. All rights reserved. 5 | // 6 | 7 | #import "KiwiConfiguration.h" 8 | #import "KWBlockNode.h" 9 | #import "KWExampleNode.h" 10 | 11 | @interface KWBeforeEachNode : KWBlockNode 12 | 13 | #pragma mark - 14 | #pragma mark Initializing 15 | 16 | + (id)beforeEachNodeWithCallSite:(KWCallSite *)aCallSite block:(KWVoidBlock)aBlock; 17 | 18 | @end 19 | -------------------------------------------------------------------------------- /Kiwi/KWVerifying.h: -------------------------------------------------------------------------------- 1 | // 2 | // Licensed under the terms in License.txt 3 | // 4 | // Copyright 2010 Allen Ding. All rights reserved. 5 | // 6 | 7 | #import "KiwiConfiguration.h" 8 | 9 | @protocol KWVerifying 10 | 11 | - (NSString *)descriptionForAnonymousItNode; 12 | 13 | #pragma mark - 14 | #pragma mark Setting Subjects 15 | 16 | - (void)setSubject:(id)anObject; 17 | 18 | #pragma mark - 19 | #pragma mark Ending Examples 20 | 21 | - (void)exampleWillEnd; 22 | 23 | @end 24 | -------------------------------------------------------------------------------- /Rubyfication/NSArray+activesupport.h: -------------------------------------------------------------------------------- 1 | // 2 | // NSArray+activesupport.h 3 | // Rubyfication 4 | // 5 | // Created by Fabio Akita on 2/2/11. 6 | // Copyright 2011 Gonow Tecnologia. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @class NSArray; 12 | 13 | @interface NSArray (activesupport) 14 | 15 | - (NSArray*) from:(NSUInteger)position; 16 | - (NSArray*) to:(NSUInteger)position; 17 | - (id) second; 18 | - (id) third; 19 | - (id) fortyTwo; 20 | 21 | @end 22 | -------------------------------------------------------------------------------- /Kiwi/KWExampleNode.h: -------------------------------------------------------------------------------- 1 | // 2 | // Licensed under the terms in License.txt 3 | // 4 | // Copyright 2010 Allen Ding. All rights reserved. 5 | // 6 | 7 | #import "KiwiConfiguration.h" 8 | 9 | @class KWContextNode; 10 | @protocol KWExampleNodeVisitor; 11 | 12 | @protocol KWExampleNode 13 | 14 | #pragma mark - 15 | #pragma mark Accepting Visitors 16 | 17 | - (void)acceptExampleNodeVisitor:(id)aVisitor; 18 | 19 | @optional 20 | 21 | - (NSArray *)contextStack; 22 | 23 | @end 24 | -------------------------------------------------------------------------------- /Kiwi/KWNull.h: -------------------------------------------------------------------------------- 1 | // 2 | // Licensed under the terms in License.txt 3 | // 4 | // Copyright 2010 Allen Ding. All rights reserved. 5 | // 6 | 7 | #import "KiwiConfiguration.h" 8 | 9 | // KWNull exists to represent the same thing as NSNull, except that Kiwi needs 10 | // to distinguish between null singletons used internally and those a user 11 | // is using as an object parameter. 12 | @interface KWNull : NSObject 13 | 14 | #pragma mark - 15 | #pragma mark Initializing 16 | 17 | + (id)null; 18 | 19 | @end 20 | -------------------------------------------------------------------------------- /Kiwi/KWHamcrestMatcher.h: -------------------------------------------------------------------------------- 1 | // 2 | // KWHamcrestMatcher.h 3 | // Kiwi 4 | // 5 | // Created by Luke Redpath on 24/01/2011. 6 | // Copyright 2011 Allen Ding. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "KWMatcher.h" 11 | 12 | @protocol HCMatcher; 13 | 14 | @interface KWHamcrestMatcher : KWMatcher { 15 | id hamcrestMatcher; 16 | } 17 | 18 | #pragma mark - 19 | #pragma mark Configuring Matchers 20 | 21 | - (void)match:(id)aMatcher; 22 | 23 | @end 24 | -------------------------------------------------------------------------------- /Kiwi/KWBeWithinMatcher.h: -------------------------------------------------------------------------------- 1 | // 2 | // Licensed under the terms in License.txt 3 | // 4 | // Copyright 2010 Allen Ding. All rights reserved. 5 | // 6 | 7 | #import "KiwiConfiguration.h" 8 | #import "KWMatcher.h" 9 | 10 | @interface KWBeWithinMatcher : KWMatcher { 11 | @private 12 | id distance; 13 | id otherValue; 14 | } 15 | 16 | #pragma mark - 17 | #pragma mark Configuring Matchers 18 | 19 | - (void)beWithin:(id)aDistance of:(id)aValue; 20 | - (void)equal:(double)aValue withDelta:(double)aDelta; 21 | 22 | @end 23 | -------------------------------------------------------------------------------- /Kiwi/NSObject+KiwiVerifierAdditions.h: -------------------------------------------------------------------------------- 1 | // 2 | // Licensed under the terms in License.txt 3 | // 4 | // Copyright 2010 Allen Ding. All rights reserved. 5 | // 6 | 7 | #import "KiwiConfiguration.h" 8 | 9 | @protocol KWVerifying; 10 | 11 | @interface NSObject(KiwiVerifierAdditions) 12 | 13 | #pragma mark - 14 | #pragma mark Attaching to Verifiers 15 | 16 | - (id)attachToVerifier:(id)aVerifier; 17 | - (id)attachToVerifier:(id)firstVerifier verifier:(id)secondVerifier; 18 | 19 | @end 20 | -------------------------------------------------------------------------------- /Rubyfication/NSString+functional.h: -------------------------------------------------------------------------------- 1 | // 2 | // NSString+functional.h 3 | // Rubyfication 4 | // 5 | // Created by Fabio Akita on 1/30/11. 6 | // Copyright 2011 Gonow Tecnologia. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @class NSString; 12 | 13 | @interface NSString (functional) 14 | 15 | #if defined(NS_BLOCKS_AVAILABLE) 16 | 17 | - (void) eachLine:(void (^) (NSString*))block; 18 | - (void) eachLine:(NSString*)separator withBlock:(void (^) (NSString*))block; 19 | 20 | #endif 21 | 22 | @end 23 | -------------------------------------------------------------------------------- /Kiwi/KWStringPrefixMatcher.h: -------------------------------------------------------------------------------- 1 | // 2 | // StringPrefixMatcher.h 3 | // Kiwi 4 | // 5 | // Created by Luke Redpath on 17/01/2011. 6 | // Copyright 2011 Allen Ding. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "KWHCMatcher.h" 11 | 12 | @interface KWStringPrefixMatcher : NSObject { 13 | NSString *prefix; 14 | } 15 | + (id)matcherWithPrefix:(NSString *)aPrefix; 16 | - (id)initWithPrefix:(NSString *)aPrefix; 17 | @end 18 | 19 | #define hasPrefix(prefix) [KWStringPrefixMatcher matcherWithPrefix:prefix] 20 | -------------------------------------------------------------------------------- /Kiwi/KWFutureObject.h: -------------------------------------------------------------------------------- 1 | // 2 | // KWFutureObject.h 3 | // iOSFalconCore 4 | // 5 | // Created by Luke Redpath on 13/01/2011. 6 | // Copyright 2011 LJR Software Limited. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | typedef id (^KWFutureObjectBlock)(void); 12 | 13 | @interface KWFutureObject : NSObject { 14 | KWFutureObjectBlock block; 15 | } 16 | + (id)objectWithObjectPointer:(id *)pointer; 17 | + (id)futureObjectWithBlock:(KWFutureObjectBlock)block; 18 | - (id)initWithBlock:(KWFutureObjectBlock)aBlock; 19 | - (id)object; 20 | @end 21 | -------------------------------------------------------------------------------- /Kiwi/KWWorkarounds.h: -------------------------------------------------------------------------------- 1 | // 2 | // Licensed under the terms in License.txt 3 | // 4 | // Copyright 2010 Allen Ding. All rights reserved. 5 | // 6 | 7 | #import "KiwiConfiguration.h" 8 | 9 | #if KW_TARGET_HAS_INVOCATION_EXCEPTION_BUG 10 | 11 | #pragma mark - 12 | #pragma mark Invocation Exception Bug Workaround 13 | 14 | // See KiwiConfiguration.h for notes. 15 | void KWSetExceptionFromAcrossInvocationBoundary(NSException *anException); 16 | NSException *KWGetAndClearExceptionFromAcrossInvocationBoundary(void); 17 | 18 | #endif // #if KW_TARGET_HAS_INVOCATION_EXCEPTION_BUG 19 | -------------------------------------------------------------------------------- /Kiwi/KWProbePoller.h: -------------------------------------------------------------------------------- 1 | // 2 | // KWProbePoller.h 3 | // iOSFalconCore 4 | // 5 | // Created by Luke Redpath on 13/01/2011. 6 | // Copyright 2011 LJR Software Limited. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "KWProbe.h" 11 | 12 | #define kKW_DEFAULT_PROBE_DELAY 0.1 13 | 14 | @interface KWProbePoller : NSObject 15 | { 16 | NSTimeInterval timeoutInterval; 17 | NSTimeInterval delayInterval; 18 | } 19 | - (id)initWithTimeout:(NSTimeInterval)theTimeout delay:(NSTimeInterval)theDelay; 20 | - (BOOL)check:(id)probe; 21 | @end 22 | -------------------------------------------------------------------------------- /Kiwi/KWStringContainsMatcher.h: -------------------------------------------------------------------------------- 1 | // 2 | // KWStringContainsMatcher.h 3 | // Kiwi 4 | // 5 | // Created by Stewart Gleadow on 7/06/12. 6 | // Copyright (c) 2012 Allen Ding. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "KWHCMatcher.h" 11 | 12 | @interface KWStringContainsMatcher : NSObject { 13 | NSString *substring; 14 | } 15 | 16 | + (id)matcherWithSubstring:(NSString *)aSubstring; 17 | - (id)initWithSubstring:(NSString *)aSubstring; 18 | 19 | @end 20 | 21 | #define hasSubstring(substring) [KWStringContainsMatcher matcherWithSubstring:substring] 22 | -------------------------------------------------------------------------------- /Kiwi/NSMethodSignature+KiwiAdditions.m: -------------------------------------------------------------------------------- 1 | // 2 | // Licensed under the terms in License.txt 3 | // 4 | // Copyright 2010 Allen Ding. All rights reserved. 5 | // 6 | 7 | #import "NSMethodSignature+KiwiAdditions.h" 8 | 9 | @implementation NSMethodSignature(KiwiAdditions) 10 | 11 | #pragma mark - 12 | #pragma mark Getting Information on Message Arguments 13 | 14 | - (NSUInteger)numberOfMessageArguments { 15 | return [self numberOfArguments] - 2; 16 | } 17 | 18 | - (const char *)messageArgumentTypeAtIndex:(NSUInteger)anIndex { 19 | return [self getArgumentTypeAtIndex:anIndex + 2]; 20 | } 21 | 22 | @end 23 | -------------------------------------------------------------------------------- /Kiwi/KWBeBetweenMatcher.h: -------------------------------------------------------------------------------- 1 | // 2 | // Licensed under the terms in License.txt 3 | // 4 | // Copyright 2010 Allen Ding. All rights reserved. 5 | // 6 | 7 | #import "KiwiConfiguration.h" 8 | #import "KWMatcher.h" 9 | 10 | @interface KWBeBetweenMatcher : KWMatcher { 11 | @private 12 | id lowerEndpoint; 13 | id upperEndpoint; 14 | } 15 | 16 | #pragma mark - 17 | #pragma mark Configuring Matchers 18 | 19 | // TODO: 'and' below is a reserved word in C++ 20 | - (void)beBetween:(id)aLowerEndpoint and:(id)anUpperEndpoint; 21 | - (void)beInTheIntervalFrom:(id)aLowerEndpoint to:(id)anUpperEndpoint; 22 | 23 | @end 24 | -------------------------------------------------------------------------------- /Rubyfication/NSString+activesupport.h: -------------------------------------------------------------------------------- 1 | // 2 | // NSString+activesupport.h 3 | // Rubyfication 4 | // 5 | // Created by Fabio Akita on 1/30/11. 6 | // Copyright 2011 Gonow Tecnologia. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @class NSString; 12 | 13 | @interface NSString (activesupport) 14 | 15 | - (NSString*) at:(NSUInteger)position; 16 | - (NSString*) from:(NSUInteger)position; 17 | - (NSString*) to:(NSUInteger)position; 18 | - (NSString*) first; 19 | - (NSString*) first:(NSUInteger)limit; 20 | - (NSString*) last; 21 | - (NSString*) last:(NSUInteger)limit; 22 | 23 | @end 24 | -------------------------------------------------------------------------------- /Kiwi/KWBlockRaiseMatcher.h: -------------------------------------------------------------------------------- 1 | // 2 | // Licensed under the terms in License.txt 3 | // 4 | // Copyright 2010 Allen Ding. All rights reserved. 5 | // 6 | 7 | #import "KiwiConfiguration.h" 8 | #import "KWMatcher.h" 9 | 10 | @interface KWBlockRaiseMatcher : KWMatcher { 11 | @private 12 | NSException *exception; 13 | NSException *actualException; 14 | } 15 | 16 | #pragma mark - 17 | #pragma mark Configuring Matchers 18 | 19 | - (void)raise; 20 | - (void)raiseWithName:(NSString *)aName; 21 | - (void)raiseWithReason:(NSString *)aReason; 22 | - (void)raiseWithName:(NSString *)aName reason:(NSString *)aReason; 23 | 24 | @end 25 | -------------------------------------------------------------------------------- /Kiwi/NSValue+KiwiAdditions.m: -------------------------------------------------------------------------------- 1 | // 2 | // Licensed under the terms in License.txt 3 | // 4 | // Copyright 2010 Allen Ding. All rights reserved. 5 | // 6 | 7 | #import "NSValue+KiwiAdditions.h" 8 | #import "KWObjCUtilities.h" 9 | 10 | @implementation NSValue(KiwiAdditions) 11 | 12 | #pragma mark - 13 | #pragma mark Accessing Data 14 | 15 | - (NSData *)dataValue { 16 | NSUInteger length = KWObjCTypeLength([self objCType]); 17 | void *buffer = malloc(length); 18 | [self getValue:buffer]; 19 | NSData *data = [NSData dataWithBytes:buffer length:length]; 20 | free(buffer); 21 | return data; 22 | } 23 | 24 | @end 25 | -------------------------------------------------------------------------------- /Kiwi/KWDeviceInfo.m: -------------------------------------------------------------------------------- 1 | // 2 | // Licensed under the terms in License.txt 3 | // 4 | // Copyright 2010 Allen Ding. All rights reserved. 5 | // 6 | 7 | #import "KWDeviceInfo.h" 8 | 9 | #if TARGET_IPHONE_SIMULATOR 10 | 11 | #import 12 | 13 | #endif // #if TARGET_IPHONE_SIMULATOR 14 | 15 | @implementation KWDeviceInfo 16 | 17 | #pragma mark - 18 | #pragma mark Getting the Device Type 19 | 20 | + (BOOL)isSimulator { 21 | #if TARGET_IPHONE_SIMULATOR 22 | return YES; 23 | #else 24 | return NO; 25 | #endif // #if TARGET_IPHONE_SIMULATOR 26 | } 27 | 28 | + (BOOL)isPhysical { 29 | return ![self isSimulator]; 30 | } 31 | 32 | @end 33 | -------------------------------------------------------------------------------- /Kiwi/KWStringUtilities.h: -------------------------------------------------------------------------------- 1 | // 2 | // Licensed under the terms in License.txt 3 | // 4 | // Copyright 2010 Allen Ding. All rights reserved. 5 | // 6 | 7 | #import "KiwiConfiguration.h" 8 | 9 | #pragma mark - 10 | #pragma mark Checking for Case Separated Words 11 | 12 | BOOL KWStringHasWordPrefix(NSString *string, NSString *prefix); 13 | BOOL KWStringHasStrictWordPrefix(NSString *string, NSString *prefix); 14 | BOOL KWStringHasWord(NSString *string, NSString *word); 15 | 16 | #pragma mark - 17 | #pragma mark Getting Type Encodings 18 | 19 | NSString *KWEncodingWithObjCTypes(const char *firstType, ...) NS_REQUIRES_NIL_TERMINATION; 20 | NSString *KWEncodingForVoidMethod(void); 21 | -------------------------------------------------------------------------------- /Rubyfication/NSString+functional.m: -------------------------------------------------------------------------------- 1 | // 2 | // NSString+functional.m 3 | // Rubyfication 4 | // 5 | // Created by Fabio Akita on 1/30/11. 6 | // Copyright 2011 GonowTecnologia. All rights reserved. 7 | // 8 | 9 | #import "NSString+functional.h" 10 | 11 | 12 | @implementation NSString (functional) 13 | 14 | #if defined(NS_BLOCKS_AVAILABLE) 15 | 16 | - (void) eachLine:(void (^) (NSString*))block { 17 | [self eachLine:@"\n" withBlock:block]; 18 | } 19 | 20 | - (void) eachLine:(NSString*)separator withBlock:(void (^) (NSString*))block { 21 | for (NSString* line in [self componentsSeparatedByString:separator]) { 22 | block(line); 23 | } 24 | } 25 | 26 | #endif 27 | 28 | @end 29 | -------------------------------------------------------------------------------- /Kiwi/KWBlock.h: -------------------------------------------------------------------------------- 1 | // 2 | // Licensed under the terms in License.txt 3 | // 4 | // Copyright 2010 Allen Ding. All rights reserved. 5 | // 6 | 7 | #import "KiwiConfiguration.h" 8 | 9 | typedef void (^KWVoidBlock)(void); 10 | 11 | @interface KWBlock : NSObject { 12 | @private 13 | KWVoidBlock block; 14 | } 15 | 16 | #pragma mark - 17 | #pragma mark Initializing 18 | - (id)initWithBlock:(KWVoidBlock)aBlock; 19 | 20 | + (id)blockWithBlock:(KWVoidBlock)aBlock; 21 | 22 | #pragma mark - 23 | #pragma mark Calling Blocks 24 | 25 | - (void)call; 26 | 27 | @end 28 | 29 | #pragma mark - 30 | #pragma mark Creating Blocks 31 | 32 | KWBlock *theBlock(KWVoidBlock aBlock); 33 | KWBlock *lambda(KWVoidBlock aBlock); 34 | -------------------------------------------------------------------------------- /Kiwi/KWAfterAllNode.m: -------------------------------------------------------------------------------- 1 | // 2 | // Licensed under the terms in License.txt 3 | // 4 | // Copyright 2010 Allen Ding. All rights reserved. 5 | // 6 | 7 | #import "KWAfterAllNode.h" 8 | #import "KWExampleNodeVisitor.h" 9 | 10 | @implementation KWAfterAllNode 11 | 12 | #pragma mark - 13 | #pragma mark Initializing 14 | 15 | + (id)afterAllNodeWithCallSite:(KWCallSite *)aCallSite block:(KWVoidBlock)aBlock { 16 | return [[[self alloc] initWithCallSite:aCallSite description:nil block:aBlock] autorelease]; 17 | } 18 | 19 | #pragma mark - 20 | #pragma mark Accepting Visitors 21 | 22 | - (void)acceptExampleNodeVisitor:(id)aVisitor { 23 | [aVisitor visitAfterAllNode:self]; 24 | } 25 | 26 | @end 27 | -------------------------------------------------------------------------------- /Kiwi/KWAfterEachNode.m: -------------------------------------------------------------------------------- 1 | // 2 | // Licensed under the terms in License.txt 3 | // 4 | // Copyright 2010 Allen Ding. All rights reserved. 5 | // 6 | 7 | #import "KWAfterEachNode.h" 8 | #import "KWExampleNodeVisitor.h" 9 | 10 | @implementation KWAfterEachNode 11 | 12 | #pragma mark - 13 | #pragma mark Initializing 14 | 15 | + (id)afterEachNodeWithCallSite:(KWCallSite *)aCallSite block:(KWVoidBlock)aBlock { 16 | return [[[self alloc] initWithCallSite:aCallSite description:nil block:aBlock] autorelease]; 17 | } 18 | 19 | #pragma mark - 20 | #pragma mark Accepting Visitors 21 | 22 | - (void)acceptExampleNodeVisitor:(id)aVisitor { 23 | [aVisitor visitAfterEachNode:self]; 24 | } 25 | 26 | @end 27 | -------------------------------------------------------------------------------- /Kiwi/KWBeforeAllNode.m: -------------------------------------------------------------------------------- 1 | // 2 | // Licensed under the terms in License.txt 3 | // 4 | // Copyright 2010 Allen Ding. All rights reserved. 5 | // 6 | 7 | #import "KWBeforeAllNode.h" 8 | #import "KWExampleNodeVisitor.h" 9 | 10 | @implementation KWBeforeAllNode 11 | 12 | #pragma mark - 13 | #pragma mark Initializing 14 | 15 | + (id)beforeAllNodeWithCallSite:(KWCallSite *)aCallSite block:(KWVoidBlock)aBlock { 16 | return [[[self alloc] initWithCallSite:aCallSite description:nil block:aBlock] autorelease]; 17 | } 18 | 19 | #pragma mark - 20 | #pragma mark Accepting Visitors 21 | 22 | - (void)acceptExampleNodeVisitor:(id)aVisitor { 23 | [aVisitor visitBeforeAllNode:self]; 24 | } 25 | 26 | @end 27 | -------------------------------------------------------------------------------- /Kiwi/KWBeforeEachNode.m: -------------------------------------------------------------------------------- 1 | // 2 | // Licensed under the terms in License.txt 3 | // 4 | // Copyright 2010 Allen Ding. All rights reserved. 5 | // 6 | 7 | #import "KWBeforeEachNode.h" 8 | #import "KWExampleNodeVisitor.h" 9 | 10 | @implementation KWBeforeEachNode 11 | 12 | #pragma mark - 13 | #pragma mark Initializing 14 | 15 | + (id)beforeEachNodeWithCallSite:(KWCallSite *)aCallSite block:(KWVoidBlock)aBlock { 16 | return [[[self alloc] initWithCallSite:aCallSite description:nil block:aBlock] autorelease]; 17 | } 18 | 19 | #pragma mark - 20 | #pragma mark Accepting Visitors 21 | 22 | - (void)acceptExampleNodeVisitor:(id)aVisitor { 23 | [aVisitor visitBeforeEachNode:self]; 24 | } 25 | 26 | @end 27 | -------------------------------------------------------------------------------- /Kiwi/KWContainMatcher.h: -------------------------------------------------------------------------------- 1 | // 2 | // Licensed under the terms in License.txt 3 | // 4 | // Copyright 2010 Allen Ding. All rights reserved. 5 | // 6 | 7 | #import "KiwiConfiguration.h" 8 | #import "KWMatcher.h" 9 | #import "KWMatchVerifier.h" 10 | 11 | @interface KWContainMatcher : KWMatcher { 12 | @private 13 | NSArray *objects; 14 | } 15 | 16 | #pragma mark - 17 | #pragma mark Configuring Matchers 18 | 19 | - (void)contain:(id)anObject; 20 | - (void)containObjectsInArray:(NSArray *)anArray; 21 | 22 | @end 23 | 24 | @interface KWMatchVerifier(KWContainMatcherAdditions) 25 | 26 | #pragma mark - 27 | #pragma mark Verifying 28 | 29 | - (void)containObjects:(id)firstObject, ... NS_REQUIRES_NIL_TERMINATION; 30 | 31 | @end 32 | -------------------------------------------------------------------------------- /Kiwi/KWHaveValueMatcher.h: -------------------------------------------------------------------------------- 1 | // 2 | // KWHaveValueMatcher.h 3 | // Kiwi 4 | // 5 | // Created by Luke Redpath on 24/01/2011. 6 | // Copyright 2011 Allen Ding. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "KWMatcher.h" 11 | 12 | @interface KWHaveValueMatcher : KWMatcher { 13 | @private 14 | 15 | NSString *expectedKey; 16 | NSString *expectedKeyPath; 17 | id expectedValue; 18 | } 19 | 20 | #pragma mark - 21 | #pragma mark Configuring Matchers 22 | 23 | - (void)haveValue:(id)value forKey:(NSString *)key; 24 | - (void)haveValue:(id)value forKeyPath:(NSString *)keyPath; 25 | - (void)haveValueForKey:(NSString *)key; 26 | - (void)haveValueForKeyPath:(NSString *)keyPath; 27 | 28 | @end 29 | -------------------------------------------------------------------------------- /Kiwi/KWRaiseMatcher.h: -------------------------------------------------------------------------------- 1 | // 2 | // Licensed under the terms in License.txt 3 | // 4 | // Copyright 2010 Allen Ding. All rights reserved. 5 | // 6 | 7 | #import "KiwiConfiguration.h" 8 | #import "KWMatcher.h" 9 | 10 | @interface KWRaiseMatcher : KWMatcher { 11 | @private 12 | SEL selector; 13 | NSException *exception; 14 | NSException *actualException; 15 | } 16 | 17 | #pragma mark - 18 | #pragma mark Configuring Matchers 19 | 20 | - (void)raiseWhenSent:(SEL)aSelector; 21 | - (void)raiseWithName:(NSString *)aName whenSent:(SEL)aSelector; 22 | - (void)raiseWithReason:(NSString *)aReason whenSent:(SEL)aSelector; 23 | - (void)raiseWithName:(NSString *)aName reason:(NSString *)aReason whenSent:(SEL)aSelector; 24 | 25 | @end 26 | -------------------------------------------------------------------------------- /Kiwi/NSObject+KiwiVerifierAdditions.m: -------------------------------------------------------------------------------- 1 | // 2 | // Licensed under the terms in License.txt 3 | // 4 | // Copyright 2010 Allen Ding. All rights reserved. 5 | // 6 | 7 | #import "NSObject+KiwiVerifierAdditions.h" 8 | #import "KWVerifying.h" 9 | 10 | @implementation NSObject(KiwiVerifierAdditions) 11 | 12 | #pragma mark - 13 | #pragma mark Attaching to Verifiers 14 | 15 | - (id)attachToVerifier:(id)aVerifier { 16 | [aVerifier setSubject:self]; 17 | return aVerifier; 18 | } 19 | 20 | - (id)attachToVerifier:(id)firstVerifier verifier:(id)secondVerifier { 21 | [firstVerifier setSubject:self]; 22 | [secondVerifier setSubject:self]; 23 | return firstVerifier; 24 | } 25 | 26 | @end 27 | -------------------------------------------------------------------------------- /Rubyfication/NSArray+functional.h: -------------------------------------------------------------------------------- 1 | // 2 | // NSArray+functional.h 3 | // Rubyfication 4 | // 5 | // Created by Fabio Akita on 1/28/11. 6 | // Copyright 2011 Gonow Tecnologia. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @class NSArray; 12 | 13 | @interface NSArray (functional) 14 | 15 | #if defined(NS_BLOCKS_AVAILABLE) 16 | 17 | - (void) each:(void (^) (id))block; 18 | - (NSArray*) map:(id (^) (id))block; 19 | - (id) inject:(id)initialValue with:(id (^) (id total, id item))block; 20 | - (void) eachIndex:(void (^) (int))block; 21 | - (NSArray*) select:(BOOL (^) (id))block; 22 | - (NSArray*) reject:(BOOL (^) (id))block; 23 | - (void) reverseEach:(void (^) (id))block; 24 | 25 | #endif 26 | 27 | @end 28 | -------------------------------------------------------------------------------- /Kiwi/NSObject+KiwiMockAdditions.m: -------------------------------------------------------------------------------- 1 | // 2 | // Licensed under the terms in License.txt 3 | // 4 | // Copyright 2010 Allen Ding. All rights reserved. 5 | // 6 | 7 | #import "NSObject+KiwiMockAdditions.h" 8 | #import "KWMock.h" 9 | 10 | @implementation NSObject(KiwiMockAdditions) 11 | 12 | #pragma mark - 13 | #pragma mark Creating Mocks 14 | 15 | + (id)mock { 16 | return [KWMock mockForClass:[self class]]; 17 | } 18 | 19 | + (id)mockWithName:(NSString *)aName { 20 | return [KWMock mockWithName:aName forClass:[self class]]; 21 | } 22 | 23 | + (id)nullMock { 24 | return [KWMock nullMockForClass:[self class]]; 25 | } 26 | 27 | + (id)nullMockWithName:(NSString *)aName { 28 | return [KWMock nullMockWithName:aName forClass:[self class]]; 29 | } 30 | 31 | @end 32 | -------------------------------------------------------------------------------- /Rubyfication/NSArray+helpers.h: -------------------------------------------------------------------------------- 1 | // 2 | // NSArray+helpers.h 3 | // Rubyfication 4 | // 5 | // Created by Fabio Akita on 1/28/11. 6 | // Copyright 2011 Gonow Tecnologia. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @class NSArray; 12 | 13 | @interface NSArray (helpers) 14 | 15 | - (NSArray*) slice:(int)start; 16 | - (NSArray*) slice:(int)start until:(int)until; 17 | - (NSArray*) concat:(NSArray*)otherArray; 18 | - (NSArray*) compact; 19 | - (BOOL) isEmpty; 20 | - (int) index:(id)item; 21 | - (id) first; 22 | - (id) last; 23 | - (NSString*) join:(NSString*)separator; 24 | - (NSArray*) reverse; 25 | - (NSArray*) shuffle; 26 | - (NSArray*) take:(int)elements; 27 | - (NSArray*) zip:(NSArray*)firstArg, ... NS_REQUIRES_NIL_TERMINATION; 28 | 29 | @end 30 | -------------------------------------------------------------------------------- /Kiwi/KWItNode.h: -------------------------------------------------------------------------------- 1 | // 2 | // Licensed under the terms in License.txt 3 | // 4 | // Copyright 2010 Allen Ding. All rights reserved. 5 | // 6 | 7 | #import "KiwiConfiguration.h" 8 | #import "KWBlockNode.h" 9 | #import "KWExampleNode.h" 10 | 11 | @class KWPendingNode; 12 | @class KWExample; 13 | @class KWContextNode; 14 | 15 | @interface KWItNode : KWBlockNode 16 | 17 | @property (nonatomic, assign) KWExample *example; 18 | @property (nonatomic, retain, readonly) KWContextNode *context; 19 | 20 | #pragma mark - 21 | #pragma mark Initializing 22 | 23 | + (id)itNodeWithCallSite:(KWCallSite *)aCallSite 24 | description:(NSString *)aDescription 25 | context:(KWContextNode *)context 26 | block:(KWVoidBlock)aBlock; 27 | 28 | @end 29 | -------------------------------------------------------------------------------- /Kiwi/KWInequalityMatcher.h: -------------------------------------------------------------------------------- 1 | // 2 | // Licensed under the terms in License.txt 3 | // 4 | // Copyright 2010 Allen Ding. All rights reserved. 5 | // 6 | 7 | #import "KiwiConfiguration.h" 8 | #import "KWMatcher.h" 9 | 10 | enum { 11 | KWInequalityTypeLessThan, 12 | KWInequalityTypeLessThanOrEqualTo, 13 | KWInequalityTypeGreaterThan, 14 | KWInequalityTypeGreaterThanOrEqualTo 15 | }; 16 | 17 | typedef NSUInteger KWInequalityType; 18 | 19 | @interface KWInequalityMatcher : KWMatcher { 20 | @private 21 | KWInequalityType inequalityType; 22 | id otherValue; 23 | } 24 | 25 | #pragma mark - 26 | #pragma mark Configuring Matchers 27 | 28 | - (void)beLessThan:(id)aValue; 29 | - (void)beLessThanOrEqualTo:(id)aValue; 30 | - (void)beGreaterThan:(id)aValue; 31 | - (void)beGreaterThanOrEqualTo:(id)aValue; 32 | 33 | @end 34 | -------------------------------------------------------------------------------- /Kiwi/KWHamrestMatchingAdditions.h: -------------------------------------------------------------------------------- 1 | // 2 | // NSObject+KiwiAdditions.h 3 | // Kiwi 4 | // 5 | // Created by Luke Redpath on 24/01/2011. 6 | // Copyright 2011 Allen Ding. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface NSObject (KiwiHamcrestAdditions) 12 | 13 | - (BOOL)isEqualOrMatches:(id)object; 14 | 15 | @end 16 | 17 | @protocol HCMatcher; 18 | 19 | @interface NSArray (KiwiHamcrestAdditions) 20 | 21 | - (BOOL)containsObjectEqualToOrMatching:(id)object; 22 | - (BOOL)containsObjectMatching:(id)matcher; 23 | 24 | @end 25 | 26 | @interface NSSet (KiwiHamcrestAdditions) 27 | 28 | - (BOOL)containsObjectEqualToOrMatching:(id)object; 29 | 30 | @end 31 | 32 | @interface NSOrderedSet (KiwiHamcrestAdditions) 33 | 34 | - (BOOL)containsObjectEqualToOrMatching:(id)object; 35 | 36 | @end -------------------------------------------------------------------------------- /Kiwi/KWWorkarounds.m: -------------------------------------------------------------------------------- 1 | // 2 | // Licensed under the terms in License.txt 3 | // 4 | // Copyright 2010 Allen Ding. All rights reserved. 5 | // 6 | 7 | #import "KWWorkarounds.h" 8 | 9 | #if KW_TARGET_HAS_INVOCATION_EXCEPTION_BUG 10 | 11 | static NSException *KWExceptionAcrossInvokeBoundary = nil; 12 | 13 | void KWSetExceptionFromAcrossInvocationBoundary(NSException *anException) { 14 | if (KWExceptionAcrossInvokeBoundary != nil) 15 | return; 16 | 17 | KWExceptionAcrossInvokeBoundary = [anException retain]; 18 | } 19 | 20 | NSException *KWGetAndClearExceptionFromAcrossInvocationBoundary(void) { 21 | NSException *exception = [KWExceptionAcrossInvokeBoundary autorelease]; 22 | KWExceptionAcrossInvokeBoundary = nil; 23 | return exception; 24 | } 25 | 26 | #endif // #if KW_TARGET_HAS_INVOCATION_EXCEPTION_BUG 27 | -------------------------------------------------------------------------------- /Kiwi/KWExampleSuite.h: -------------------------------------------------------------------------------- 1 | // 2 | // KWExampleSuite.h 3 | // Kiwi 4 | // 5 | // Created by Luke Redpath on 17/10/2011. 6 | // Copyright (c) 2011 Allen Ding. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "KWExampleNodeVisitor.h" 11 | 12 | @class KWContextNode; 13 | @class KWExample; 14 | @class SenTestCase; 15 | 16 | @interface KWExampleSuite : NSObject { 17 | KWContextNode *rootNode; 18 | NSMutableArray *examples; 19 | } 20 | - (id)initWithRootNode:(KWContextNode *)contextNode; 21 | - (void)addExample:(KWExample *)example; 22 | - (void)markLastExampleAsLastInContext:(KWContextNode *)context; 23 | - (NSArray *)invocationsForTestCase; 24 | @end 25 | 26 | @interface NSInvocation (KWExampleGroup) 27 | - (void)kw_setExample:(KWExample *)exampleGroup; 28 | - (KWExample *)kw_example; 29 | @end 30 | -------------------------------------------------------------------------------- /Kiwi/KWAny.m: -------------------------------------------------------------------------------- 1 | // 2 | // Licensed under the terms in License.txt 3 | // 4 | // Copyright 2010 Allen Ding. All rights reserved. 5 | // 6 | 7 | #import "KWAny.h" 8 | 9 | @implementation KWAny 10 | 11 | #pragma mark - 12 | #pragma mark Initializing 13 | 14 | static KWAny *sharedAny = nil; 15 | 16 | + (id)any { 17 | if (sharedAny == nil) { 18 | sharedAny = [[super allocWithZone:nil] init]; 19 | } 20 | 21 | return sharedAny; 22 | } 23 | 24 | + (id)allocWithZone:(NSZone *)zone { 25 | return [[self any] retain]; 26 | } 27 | 28 | - (id)copyWithZone:(NSZone *)zone { 29 | return self; 30 | } 31 | 32 | - (id)retain { 33 | return self; 34 | } 35 | 36 | - (NSUInteger)retainCount { 37 | return NSUIntegerMax; 38 | } 39 | 40 | - (oneway void)release { 41 | } 42 | 43 | - (id)autorelease { 44 | return self; 45 | } 46 | 47 | @end 48 | -------------------------------------------------------------------------------- /Kiwi/KWCallSite.h: -------------------------------------------------------------------------------- 1 | // 2 | // Licensed under the terms in License.txt 3 | // 4 | // Copyright 2010 Allen Ding. All rights reserved. 5 | // 6 | 7 | #import "KiwiConfiguration.h" 8 | 9 | @interface KWCallSite : NSObject { 10 | @private 11 | NSString *filename; 12 | NSUInteger lineNumber; 13 | } 14 | 15 | #pragma mark - 16 | #pragma mark Initializing 17 | 18 | - (id)initWithFilename:(NSString *)aFilename lineNumber:(NSUInteger)aLineNumber; 19 | 20 | + (id)callSiteWithFilename:(NSString *)aFilename lineNumber:(NSUInteger)aLineNumber; 21 | 22 | #pragma mark - 23 | #pragma mark Properties 24 | 25 | @property (nonatomic, readonly, copy) NSString *filename; 26 | @property (nonatomic, readonly) NSUInteger lineNumber; 27 | 28 | #pragma mark - 29 | #pragma mark Identifying and Comparing 30 | 31 | - (BOOL)isEqualToCallSite:(KWCallSite *)aCallSite; 32 | 33 | @end 34 | -------------------------------------------------------------------------------- /RubyficationTests/RubyficationTests-Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | ${EXECUTABLE_NAME} 9 | CFBundleIdentifier 10 | ___VARIABLE_bundleIdentifierPrefix:bundleIdentifier___.${PRODUCT_NAME:rfc1034identifier} 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundlePackageType 14 | BNDL 15 | CFBundleShortVersionString 16 | 1.0 17 | CFBundleSignature 18 | ???? 19 | CFBundleVersion 20 | 1 21 | 22 | 23 | -------------------------------------------------------------------------------- /Kiwi/KWNull.m: -------------------------------------------------------------------------------- 1 | // 2 | // Licensed under the terms in License.txt 3 | // 4 | // Copyright 2010 Allen Ding. All rights reserved. 5 | // 6 | 7 | #import "KWNull.h" 8 | 9 | @implementation KWNull 10 | 11 | #pragma mark - 12 | #pragma mark Initializing 13 | 14 | static KWNull *sharedNull = nil; 15 | 16 | + (id)null { 17 | if (sharedNull == nil) { 18 | sharedNull = [[super allocWithZone:nil] init]; 19 | } 20 | 21 | return sharedNull; 22 | } 23 | 24 | + (id)allocWithZone:(NSZone *)zone { 25 | return [[self null] retain]; 26 | } 27 | 28 | - (id)copyWithZone:(NSZone *)zone { 29 | return self; 30 | } 31 | 32 | - (id)retain { 33 | return self; 34 | } 35 | 36 | - (NSUInteger)retainCount { 37 | return NSUIntegerMax; 38 | } 39 | 40 | - (oneway void)release { 41 | } 42 | 43 | - (id)autorelease { 44 | return self; 45 | } 46 | 47 | @end 48 | -------------------------------------------------------------------------------- /Kiwi/KWFutureObject.m: -------------------------------------------------------------------------------- 1 | // 2 | // KWFutureObject.m 3 | // iOSFalconCore 4 | // 5 | // Created by Luke Redpath on 13/01/2011. 6 | // Copyright 2011 LJR Software Limited. All rights reserved. 7 | // 8 | 9 | #import "KWFutureObject.h" 10 | 11 | 12 | @implementation KWFutureObject 13 | 14 | + (id)objectWithObjectPointer:(id *)pointer; 15 | { 16 | return [self futureObjectWithBlock:^{ return *pointer; }]; 17 | } 18 | 19 | + (id)futureObjectWithBlock:(KWFutureObjectBlock)block; 20 | { 21 | return [[[self alloc] initWithBlock:block] autorelease]; 22 | } 23 | 24 | - (id)initWithBlock:(KWFutureObjectBlock)aBlock; 25 | { 26 | if ((self = [super init])) { 27 | block = [aBlock copy]; 28 | } 29 | return self; 30 | } 31 | 32 | - (id)object; 33 | { 34 | return block(); 35 | } 36 | 37 | - (void)dealloc 38 | { 39 | [block release]; 40 | [super dealloc]; 41 | } 42 | 43 | @end 44 | -------------------------------------------------------------------------------- /Rubyfication/NSDate+helpers.h: -------------------------------------------------------------------------------- 1 | // 2 | // NSDate+helpers.h 3 | // Rubyfication 4 | // 5 | // Created by Fabio Akita on 4/4/11. 6 | // Copyright 2011 Gonow Tecnologia. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @class NSDate; 12 | 13 | @interface NSDate (helpers) 14 | 15 | + (NSDate*) local:(int)year month:(int)month day:(int)day hours:(int)hours minutes:(int)minutes seconds:(int)seconds; 16 | + (NSDate*) local:(int)year month:(int)month day:(int)day hours:(int)hours minutes:(int)minutes; 17 | + (NSDate*) local:(int)year month:(int)month day:(int)day hours:(int)hours; 18 | + (NSDate*) local:(int)year month:(int)month day:(int)day; 19 | + (NSDate*) local:(int)year month:(int)month; 20 | + (NSDate*) local:(int)year; 21 | + (NSDate*) parse:(NSString*)date; 22 | 23 | + (NSString*) formatter:(NSString*)format; 24 | 25 | - (NSString*) toFormattedString:(NSString*)format; 26 | @end 27 | -------------------------------------------------------------------------------- /Kiwi/KWRegisterMatchersNode.h: -------------------------------------------------------------------------------- 1 | // 2 | // Licensed under the terms in License.txt 3 | // 4 | // Copyright 2010 Allen Ding. All rights reserved. 5 | // 6 | 7 | #import "KiwiConfiguration.h" 8 | #import "KWExampleNode.h" 9 | 10 | @class KWCallSite; 11 | 12 | @interface KWRegisterMatchersNode : NSObject { 13 | @private 14 | KWCallSite *callSite; 15 | NSString *namespacePrefix; 16 | } 17 | 18 | #pragma mark - 19 | #pragma mark Initializing 20 | 21 | - (id)initWithCallSite:(KWCallSite *)aCallSite namespacePrefix:(NSString *)aNamespacePrefix; 22 | 23 | + (id)registerMatchersNodeWithCallSite:(KWCallSite *)aCallSite namespacePrefix:(NSString *)aNamespacePrefix; 24 | 25 | #pragma mark - 26 | #pragma mark Getting Call Sites 27 | 28 | @property (nonatomic, readonly) KWCallSite *callSite; 29 | 30 | #pragma mark - 31 | #pragma mark Getting Namespace Prefixes 32 | 33 | @property (nonatomic, readonly) NSString *namespacePrefix; 34 | 35 | @end 36 | -------------------------------------------------------------------------------- /Kiwi/KWStringPrefixMatcher.m: -------------------------------------------------------------------------------- 1 | // 2 | // StringPrefixMatcher.m 3 | // Kiwi 4 | // 5 | // Created by Luke Redpath on 17/01/2011. 6 | // Copyright 2011 Allen Ding. All rights reserved. 7 | // 8 | 9 | #import "KWStringPrefixMatcher.h" 10 | 11 | 12 | @implementation KWStringPrefixMatcher 13 | 14 | + (id)matcherWithPrefix:(NSString *)aPrefix; 15 | { 16 | return [[[self alloc] initWithPrefix:aPrefix] autorelease]; 17 | } 18 | 19 | - (id)initWithPrefix:(NSString *)aPrefix; 20 | { 21 | if ((self = [super init])) { 22 | prefix = [aPrefix copy]; 23 | } 24 | return self; 25 | } 26 | 27 | - (void)dealloc 28 | { 29 | [prefix release]; 30 | [super dealloc]; 31 | } 32 | 33 | - (BOOL)matches:(id)item 34 | { 35 | if (![item respondsToSelector:@selector(hasPrefix:)]) 36 | return NO; 37 | 38 | return [item hasPrefix:prefix]; 39 | } 40 | 41 | - (NSString *)description 42 | { 43 | return [NSString stringWithFormat:@"a string with prefix '%@'", prefix]; 44 | } 45 | 46 | @end 47 | -------------------------------------------------------------------------------- /Kiwi/KWExistVerifier.h: -------------------------------------------------------------------------------- 1 | // 2 | // Licensed under the terms in License.txt 3 | // 4 | // Copyright 2010 Allen Ding. All rights reserved. 5 | // 6 | 7 | #import "KiwiConfiguration.h" 8 | #import "KWExpectationType.h" 9 | #import "KWVerifying.h" 10 | 11 | @class KWCallSite; 12 | 13 | @protocol KWReporting; 14 | 15 | @interface KWExistVerifier : NSObject { 16 | @private 17 | KWExpectationType expectationType; 18 | KWCallSite *callSite; 19 | id reporter; 20 | id subject; 21 | } 22 | 23 | #pragma mark - 24 | #pragma mark Initializing 25 | 26 | - (id)initWithExpectationType:(KWExpectationType)anExpectationType callSite:(KWCallSite *)aCallSite reporter:(id)aReporter; 27 | 28 | + (id)existVerifierWithExpectationType:(KWExpectationType)anExpectationType callSite:(KWCallSite *)aCallSite reporter:(id)aReporter; 29 | 30 | #pragma mark - 31 | #pragma mark Properties 32 | 33 | @property (nonatomic, readwrite, retain) id subject; 34 | 35 | @end 36 | -------------------------------------------------------------------------------- /Kiwi/KWExampleNodeVisitor.h: -------------------------------------------------------------------------------- 1 | // 2 | // Licensed under the terms in License.txt 3 | // 4 | // Copyright 2010 Allen Ding. All rights reserved. 5 | // 6 | 7 | #import "KiwiConfiguration.h" 8 | 9 | @class KWAfterAllNode; 10 | @class KWAfterEachNode; 11 | @class KWBeforeAllNode; 12 | @class KWBeforeEachNode; 13 | @class KWContextNode; 14 | @class KWItNode; 15 | @class KWPendingNode; 16 | @class KWRegisterMatchersNode; 17 | 18 | @protocol KWExampleNodeVisitor 19 | 20 | #pragma mark - 21 | #pragma mark Visiting Nodes 22 | 23 | @optional 24 | 25 | - (void)visitContextNode:(KWContextNode *)aNode; 26 | - (void)visitRegisterMatchersNode:(KWRegisterMatchersNode *)aNode; 27 | - (void)visitBeforeAllNode:(KWBeforeAllNode *)aNode; 28 | - (void)visitAfterAllNode:(KWAfterAllNode *)aNode; 29 | - (void)visitBeforeEachNode:(KWBeforeEachNode *)aNode; 30 | - (void)visitAfterEachNode:(KWAfterEachNode *)aNode; 31 | - (void)visitItNode:(KWItNode *)aNode; 32 | - (void)visitPendingNode:(KWPendingNode *)aNode; 33 | 34 | @end 35 | -------------------------------------------------------------------------------- /Kiwi/KWMatching.h: -------------------------------------------------------------------------------- 1 | // 2 | // Licensed under the terms in License.txt 3 | // 4 | // Copyright 2010 Allen Ding. All rights reserved. 5 | // 6 | 7 | #import "KiwiConfiguration.h" 8 | 9 | @protocol KWMatching 10 | 11 | #pragma mark - 12 | #pragma mark Initializing 13 | 14 | - (id)initWithSubject:(id)anObject; 15 | 16 | #pragma mark - 17 | #pragma mark Getting Matcher Strings 18 | 19 | + (NSArray *)matcherStrings; 20 | 21 | #pragma mark - 22 | #pragma mark Getting Matcher Compatability 23 | 24 | + (BOOL)canMatchSubject:(id)anObject; 25 | 26 | #pragma mark - 27 | #pragma mark Matching 28 | 29 | @optional 30 | 31 | - (BOOL)shouldBeEvaluatedAtEndOfExample; 32 | - (BOOL)willEvaluateMultipleTimes; 33 | - (void)setWillEvaluateMultipleTimes:(BOOL)shouldEvaluateMultipleTimes; 34 | 35 | @required 36 | 37 | - (BOOL)evaluate; 38 | 39 | #pragma mark - 40 | #pragma mark Getting Failure Messages 41 | 42 | - (NSString *)failureMessageForShould; 43 | - (NSString *)failureMessageForShouldNot; 44 | 45 | @end 46 | -------------------------------------------------------------------------------- /Kiwi/KWSpec.h: -------------------------------------------------------------------------------- 1 | // 2 | // Licensed under the terms in License.txt 3 | // 4 | // Copyright 2010 Allen Ding. All rights reserved. 5 | // 6 | 7 | #import "KiwiConfiguration.h" 8 | #import 9 | #import "KWExpectationType.h" 10 | #import "KWVerifying.h" 11 | #import "KWExampleGroupDelegate.h" 12 | 13 | 14 | @class KWCallSite; 15 | 16 | @interface KWSpec : SenTestCase 17 | 18 | #pragma mark - 19 | #pragma mark Adding Verifiers 20 | 21 | + (id)addVerifier:(id)aVerifier; 22 | + (id)addExistVerifierWithExpectationType:(KWExpectationType)anExpectationType callSite:(KWCallSite *)aCallSite; 23 | + (id)addMatchVerifierWithExpectationType:(KWExpectationType)anExpectationType callSite:(KWCallSite *)aCallSite; 24 | + (id)addAsyncVerifierWithExpectationType:(KWExpectationType)anExpectationType callSite:(KWCallSite *)aCallSite timeout:(NSInteger)timeout; 25 | 26 | #pragma mark - 27 | #pragma mark Building Example Groups 28 | 29 | + (void)buildExampleGroups; 30 | 31 | @end 32 | -------------------------------------------------------------------------------- /Kiwi/KWFailure.h: -------------------------------------------------------------------------------- 1 | // 2 | // Licensed under the terms in License.txt 3 | // 4 | // Copyright 2010 Allen Ding. All rights reserved. 5 | // 6 | 7 | #import "KiwiConfiguration.h" 8 | 9 | @class KWCallSite; 10 | 11 | @interface KWFailure : NSObject { 12 | @private 13 | KWCallSite *callSite; 14 | NSString *message; 15 | } 16 | 17 | #pragma mark - 18 | #pragma mark Initializing 19 | 20 | - (id)initWithCallSite:(KWCallSite *)aCallSite message:(NSString *)aMessage; 21 | - (id)initWithCallSite:(KWCallSite *)aCallSite format:(NSString *)format, ...; 22 | 23 | + (id)failureWithCallSite:(KWCallSite *)aCallSite message:(NSString *)aMessage; 24 | + (id)failureWithCallSite:(KWCallSite *)aCallSite format:(NSString *)format, ...; 25 | 26 | #pragma mark - 27 | #pragma mark Properties 28 | 29 | @property (nonatomic, readonly) NSString *message; 30 | @property (nonatomic, readonly) KWCallSite *callSite; 31 | 32 | #pragma mark - 33 | #pragma mark Getting Exception Representations 34 | 35 | - (NSException *)exceptionValue; 36 | 37 | @end 38 | -------------------------------------------------------------------------------- /Kiwi/KWBlockNode.h: -------------------------------------------------------------------------------- 1 | // 2 | // Licensed under the terms in License.txt 3 | // 4 | // Copyright 2010 Allen Ding. All rights reserved. 5 | // 6 | 7 | #import "KiwiConfiguration.h" 8 | #import "KWBlock.h" 9 | 10 | @class KWCallSite; 11 | 12 | @interface KWBlockNode : NSObject { 13 | @private 14 | KWCallSite *callSite; 15 | NSString *description; 16 | KWVoidBlock block; 17 | } 18 | 19 | #pragma mark - 20 | #pragma mark Initializing 21 | 22 | - (id)initWithCallSite:(KWCallSite *)aCallSite description:(NSString *)aDescription block:(KWVoidBlock)aBlock; 23 | 24 | #pragma mark - 25 | #pragma mark Getting Call Sites 26 | 27 | @property (nonatomic, readonly) KWCallSite *callSite; 28 | 29 | #pragma mark - 30 | #pragma mark Getting Descriptions 31 | 32 | @property (nonatomic, copy) NSString *description; 33 | 34 | #pragma mark - 35 | #pragma mark Getting Blocks 36 | 37 | @property (nonatomic, readonly) KWVoidBlock block; 38 | 39 | #pragma mark - 40 | #pragma mark Performing blocks 41 | 42 | - (void)performBlock; 43 | 44 | @end 45 | -------------------------------------------------------------------------------- /Kiwi/KWMatcher.h: -------------------------------------------------------------------------------- 1 | // 2 | // Licensed under the terms in License.txt 3 | // 4 | // Copyright 2010 Allen Ding. All rights reserved. 5 | // 6 | 7 | #import "KiwiConfiguration.h" 8 | #import "KWMatching.h" 9 | 10 | @interface KWMatcher : NSObject { 11 | @protected 12 | id subject; 13 | } 14 | 15 | #pragma mark - 16 | #pragma mark Initializing 17 | 18 | - (id)initWithSubject:(id)anObject; 19 | 20 | + (id)matcherWithSubject:(id)anObject; 21 | 22 | #pragma mark - 23 | #pragma mark Properties 24 | 25 | @property (nonatomic, readonly) id subject; 26 | 27 | #pragma mark - 28 | #pragma mark Getting Matcher Strings 29 | 30 | + (NSArray *)matcherStrings; 31 | 32 | #pragma mark - 33 | #pragma mark Getting Matcher Compatability 34 | 35 | + (BOOL)canMatchSubject:(id)anObject; 36 | 37 | #pragma mark - 38 | #pragma mark Matching 39 | 40 | - (BOOL)evaluate; 41 | 42 | #pragma mark - 43 | #pragma mark Getting Failure Messages 44 | 45 | - (NSString *)failureMessageForShould; 46 | - (NSString *)failureMessageForShouldNot; 47 | 48 | @end 49 | -------------------------------------------------------------------------------- /Kiwi/KWPendingNode.h: -------------------------------------------------------------------------------- 1 | // 2 | // Licensed under the terms in License.txt 3 | // 4 | // Copyright 2010 Allen Ding. All rights reserved. 5 | // 6 | 7 | #import "KiwiConfiguration.h" 8 | #import "KWExampleNode.h" 9 | 10 | @class KWContextNode; 11 | @class KWCallSite; 12 | 13 | @interface KWPendingNode : NSObject { 14 | @private 15 | KWCallSite *callSite; 16 | NSString *description; 17 | } 18 | @property (nonatomic, readonly, retain) KWContextNode *context; 19 | 20 | #pragma mark - 21 | #pragma mark Initializing 22 | 23 | - (id)initWithCallSite:(KWCallSite *)aCallSite context:(KWContextNode *)context description:(NSString *)aDescription; 24 | 25 | + (id)pendingNodeWithCallSite:(KWCallSite *)aCallSite context:(KWContextNode *)context description:(NSString *)aDescription; 26 | 27 | #pragma mark - 28 | #pragma mark Getting Call Sites 29 | 30 | @property (nonatomic, readonly) KWCallSite *callSite; 31 | 32 | #pragma mark - 33 | #pragma mark Getting Descriptions 34 | 35 | @property (nonatomic, readonly) NSString *description; 36 | 37 | @end 38 | -------------------------------------------------------------------------------- /Kiwi/KWStringContainsMatcher.m: -------------------------------------------------------------------------------- 1 | // 2 | // StringContainsMatcher.m 3 | // Kiwi 4 | // 5 | // Created by Stewart Gleadow on 7/06/12. 6 | // Copyright (c) 2012 Allen Ding. All rights reserved. 7 | // 8 | 9 | #import "KWStringContainsMatcher.h" 10 | 11 | @implementation KWStringContainsMatcher 12 | 13 | + (id)matcherWithSubstring:(NSString *)aSubstring; 14 | { 15 | return [[[self alloc] initWithSubstring:aSubstring] autorelease]; 16 | } 17 | 18 | - (id)initWithSubstring:(NSString *)aSubstring; 19 | { 20 | if ((self = [super init])) { 21 | substring = [aSubstring copy]; 22 | } 23 | return self; 24 | } 25 | 26 | - (void)dealloc 27 | { 28 | [substring release]; 29 | [super dealloc]; 30 | } 31 | 32 | - (BOOL)matches:(id)item 33 | { 34 | if (![item respondsToSelector:@selector(rangeOfString:)]) 35 | return NO; 36 | 37 | return [item rangeOfString:substring].location != NSNotFound; 38 | } 39 | 40 | - (NSString *)description 41 | { 42 | return [NSString stringWithFormat:@"a string with substring '%@'", substring]; 43 | } 44 | 45 | @end 46 | -------------------------------------------------------------------------------- /Kiwi/NSInvocation+KiwiAdditions.h: -------------------------------------------------------------------------------- 1 | // 2 | // Licensed under the terms in License.txt 3 | // 4 | // Copyright 2010 Allen Ding. All rights reserved. 5 | // 6 | 7 | #import "KiwiConfiguration.h" 8 | 9 | @interface NSInvocation(KiwiAdditions) 10 | 11 | #pragma mark - 12 | #pragma mark Creating NSInvocation Objects 13 | 14 | + (NSInvocation *)invocationWithTarget:(id)anObject selector:(SEL)aSelector; 15 | + (NSInvocation *)invocationWithTarget:(id)anObject selector:(SEL)aSelector messageArguments:(const void *)firstBytes, ...; 16 | 17 | #pragma mark - 18 | #pragma mark Accessing Message Arguments 19 | 20 | // Message arguments are invocation arguments that begin after the target and selector arguments. These methods provide 21 | // convenient ways to access them. 22 | 23 | - (NSData *)messageArgumentDataAtIndex:(NSUInteger)anIndex; 24 | - (void)getMessageArgument:(void *)buffer atIndex:(NSUInteger)anIndex; 25 | - (void)setMessageArgument:(const void *)bytes atIndex:(NSUInteger)anIndex; 26 | - (void)setMessageArguments:(const void *)firstBytes, ...; 27 | 28 | @end 29 | -------------------------------------------------------------------------------- /Kiwi/KWMatchers.h: -------------------------------------------------------------------------------- 1 | // 2 | // KWMatchers.h 3 | // Kiwi 4 | // 5 | // Created by Luke Redpath on 17/06/2011. 6 | // Copyright 2011 Allen Ding. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @class KWUserDefinedMatcherBuilder; 12 | 13 | typedef void (^KWMatchersBuildingBlock)(KWUserDefinedMatcherBuilder *); 14 | 15 | @class KWUserDefinedMatcher; 16 | 17 | @interface KWMatchers : NSObject { 18 | NSMutableDictionary *userDefinedMatchers; 19 | } 20 | + (id)matchers; 21 | 22 | #pragma mark - 23 | #pragma mark Defining Matchers 24 | 25 | + (void)defineMatcher:(NSString *)selectorString as:(KWMatchersBuildingBlock)block; 26 | - (void)defineMatcher:(NSString *)selectorString as:(KWMatchersBuildingBlock)block; 27 | - (void)addUserDefinedMatcherBuilder:(KWUserDefinedMatcherBuilder *)builder; 28 | 29 | #pragma mark - 30 | #pragma mark Building Matchers 31 | 32 | - (KWUserDefinedMatcher *)matcherForSelector:(SEL)selector subject:(id)subject; 33 | @end 34 | 35 | void KWDefineMatchers(NSString *selectorString, KWMatchersBuildingBlock block); 36 | -------------------------------------------------------------------------------- /Kiwi/KWAsyncVerifier.h: -------------------------------------------------------------------------------- 1 | // 2 | // KWAsyncVerifier.h 3 | // iOSFalconCore 4 | // 5 | // Created by Luke Redpath on 13/01/2011. 6 | // Copyright 2011 LJR Software Limited. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "KWMatchVerifier.h" 11 | #import "KWProbe.h" 12 | 13 | #define kKW_DEFAULT_PROBE_TIMEOUT 1.0 14 | 15 | @class KWAsyncMatcherProbe; 16 | 17 | @interface KWAsyncVerifier : KWMatchVerifier 18 | { 19 | NSTimeInterval timeout; 20 | } 21 | @property (nonatomic, assign) NSTimeInterval timeout; 22 | 23 | + (id)asyncVerifierWithExpectationType:(KWExpectationType)anExpectationType callSite:(KWCallSite *)aCallSite matcherFactory:(KWMatcherFactory *)aMatcherFactory reporter:(id)aReporter probeTimeout:(NSTimeInterval)probeTimeout; 24 | - (void)verifyWithProbe:(KWAsyncMatcherProbe *)aProbe; 25 | @end 26 | 27 | @interface KWAsyncMatcherProbe : NSObject 28 | { 29 | id matcher; 30 | BOOL matchResult; 31 | } 32 | @property (nonatomic, readonly) id matcher; 33 | 34 | - (id)initWithMatcher:(id)aMatcher; 35 | @end 36 | -------------------------------------------------------------------------------- /Kiwi/KWFormatter.m: -------------------------------------------------------------------------------- 1 | // 2 | // Licensed under the terms in License.txt 3 | // 4 | // Copyright 2010 Allen Ding. All rights reserved. 5 | // 6 | 7 | #import "KWFormatter.h" 8 | 9 | @implementation KWFormatter 10 | 11 | #pragma mark - 12 | #pragma mark Getting Descriptions 13 | 14 | + (NSString *)formatObject:(id)anObject { 15 | if ([anObject isKindOfClass:[NSString class]]) 16 | return [NSString stringWithFormat:@"\"%@\"", anObject]; 17 | 18 | if ([anObject conformsToProtocol:@protocol(NSFastEnumeration)]) { 19 | NSMutableString *description = [[[NSMutableString alloc] initWithString:@"("] autorelease]; 20 | NSUInteger index = 0; 21 | 22 | for (id object in anObject) { 23 | if (index == 0) 24 | [description appendFormat:@"%@", [self formatObject:object]]; 25 | else 26 | [description appendFormat:@", %@", [self formatObject:object]]; 27 | 28 | ++index; 29 | } 30 | 31 | [description appendString:@")"]; 32 | return description; 33 | } 34 | 35 | return [anObject description]; 36 | } 37 | 38 | @end 39 | -------------------------------------------------------------------------------- /Rubyfication/NSString+helpers.h: -------------------------------------------------------------------------------- 1 | // 2 | // NSString+helpers.h 3 | // Rubyfication 4 | // 5 | // Created by Fabio Akita on 1/30/11. 6 | // Copyright 2011 Gonow Tecnologia. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "OnigRegexp.h" 11 | 12 | @class NSString; 13 | 14 | @interface NSString (helpers) 15 | 16 | - (NSString*) concat:(NSString*)anotherString; 17 | - (NSString*) slice:(int)start; 18 | - (NSString*) slice:(int)start until:(int)until; 19 | - (NSString*) center:(int)length; 20 | - (NSString*) center:(int)length withPad:(NSString*)padStr; 21 | - (BOOL) isEmpty; 22 | - (BOOL) endWith:(NSString*)anotherString; 23 | - (int) index:(NSString*)str; 24 | - (NSString*) insert:(NSString*)str at:(int)position; 25 | - (NSString*) ljust:(int)length; 26 | - (NSString*) ljust:(int)length withPad:(NSString*)padStr; 27 | - (NSString*) reverse; 28 | - (NSString*) rjust:(int)length; 29 | - (NSString*) rjust:(int)length withPad:(NSString*)padStr; 30 | 31 | - (NSString*) gsub:(NSString*)pattern with:(id)replacement; 32 | - (NSString*) gsub:(NSString*)pattern withBlock:(NSString* (^)(OnigResult*))replacement; 33 | 34 | @end 35 | -------------------------------------------------------------------------------- /Kiwi/KiwiConfiguration.h: -------------------------------------------------------------------------------- 1 | // 2 | // Licensed under the terms in License.txt 3 | // 4 | // Copyright 2010 Allen Ding. All rights reserved. 5 | // 6 | 7 | #import 8 | 9 | #define KW_VERSION 0.9001 10 | 11 | // Blocks being unavailable cripples the usability of Kiwi, but is supported 12 | // because they are not available on anything less than a device running 3.2. 13 | #if !defined(__BLOCKS__) 14 | #error "Kiwi requires blocks support." 15 | #endif 16 | 17 | // As of iPhone SDK 4 GM, exceptions thrown across an NSInvocation -invoke or 18 | // forwardInvocation: boundary in the simulator will terminate the app instead 19 | // of being caught in @catch blocks from the caller side of the -invoke. Kiwi 20 | // tries to handle this by storing the first exception that it would have 21 | // otherwise thrown in a nasty global that callers can look for and handle. 22 | // (Buggy termination is less desirable than global variables). 23 | // 24 | // Obviously, this can only handles cases where Kiwi itself would have raised 25 | // an exception. 26 | #if TARGET_IPHONE_SIMULATOR 27 | #define KW_TARGET_HAS_INVOCATION_EXCEPTION_BUG 1 28 | #endif 29 | -------------------------------------------------------------------------------- /Kiwi/KWBeNilMatcher.m: -------------------------------------------------------------------------------- 1 | // 2 | // KWBeNilMatcher.m 3 | // iOSFalconCore 4 | // 5 | // Created by Luke Redpath on 14/01/2011. 6 | // Copyright 2011 LJR Software Limited. All rights reserved. 7 | // 8 | 9 | #import "KWBeNilMatcher.h" 10 | #import "KWFormatter.h" 11 | 12 | @implementation KWBeNilMatcher 13 | 14 | #pragma mark - 15 | #pragma mark Getting Matcher Strings 16 | 17 | + (NSArray *)matcherStrings { 18 | return [NSArray arrayWithObjects:@"beNil", nil]; 19 | } 20 | 21 | #pragma mark - 22 | #pragma mark Matching 23 | 24 | - (BOOL)evaluate { 25 | return (BOOL)(self.subject == nil); 26 | } 27 | 28 | #pragma mark - 29 | #pragma mark Getting Failure Messages 30 | 31 | - (NSString *)failureMessageForShould { 32 | return [NSString stringWithFormat:@"expected subject to be nil, got %@", 33 | [KWFormatter formatObject:self.subject]]; 34 | } 35 | 36 | - (NSString *)failureMessageForShouldNot { 37 | return [NSString stringWithFormat:@"expected %@ not to be nil", 38 | [KWFormatter formatObject:self.subject]]; 39 | } 40 | 41 | - (void)beNil {} 42 | 43 | - (NSString *)description 44 | { 45 | return @"be nil"; 46 | } 47 | 48 | @end 49 | -------------------------------------------------------------------------------- /Kiwi/KWBlockNode.m: -------------------------------------------------------------------------------- 1 | // 2 | // Licensed under the terms in License.txt 3 | // 4 | // Copyright 2010 Allen Ding. All rights reserved. 5 | // 6 | 7 | #import "KWBlockNode.h" 8 | 9 | @implementation KWBlockNode 10 | 11 | @synthesize description = _description; 12 | 13 | #pragma mark - 14 | #pragma mark Initializing 15 | 16 | - (id)initWithCallSite:(KWCallSite *)aCallSite description:(NSString *)aDescription block:(KWVoidBlock)aBlock{ 17 | if ((self = [super init])) { 18 | callSite = [aCallSite retain]; 19 | _description = [aDescription copy]; 20 | 21 | if (aBlock != nil) 22 | block = Block_copy(aBlock); 23 | } 24 | 25 | return self; 26 | } 27 | 28 | - (void)dealloc { 29 | [callSite release]; 30 | [description release]; 31 | 32 | if (block != nil) 33 | Block_release(block); 34 | 35 | [super dealloc]; 36 | } 37 | 38 | - (void)performBlock 39 | { 40 | if (block != nil) { block(); } 41 | } 42 | 43 | #pragma mark - 44 | #pragma mark Getting Call Sites 45 | 46 | @synthesize callSite; 47 | 48 | #pragma mark - 49 | #pragma mark Accepting Visitors 50 | 51 | @synthesize block; 52 | 53 | @end 54 | -------------------------------------------------------------------------------- /Kiwi/KWBeNonNilMatcher.m: -------------------------------------------------------------------------------- 1 | // 2 | // KWBeNotNilMatcher.m 3 | // Kiwi 4 | // 5 | // Created by Luke Redpath on 17/01/2011. 6 | // Copyright 2011 Allen Ding. All rights reserved. 7 | // 8 | 9 | #import "KWBeNonNilMatcher.h" 10 | #import "KWFormatter.h" 11 | 12 | @implementation KWBeNonNilMatcher 13 | 14 | #pragma mark - 15 | #pragma mark Getting Matcher Strings 16 | 17 | + (NSArray *)matcherStrings { 18 | return [NSArray arrayWithObjects:@"beNonNil", nil]; 19 | } 20 | 21 | #pragma mark - 22 | #pragma mark Matching 23 | 24 | - (BOOL)evaluate { 25 | return (BOOL)(self.subject != nil); 26 | } 27 | 28 | #pragma mark - 29 | #pragma mark Getting Failure Messages 30 | 31 | - (NSString *)failureMessageForShould { 32 | return [NSString stringWithFormat:@"expected subject to be non-nil, got %@", 33 | [KWFormatter formatObject:self.subject]]; 34 | } 35 | 36 | - (NSString *)failureMessageForShouldNot { 37 | return [NSString stringWithFormat:@"expected %@ not to be non-nil", 38 | [KWFormatter formatObject:self.subject]]; 39 | } 40 | 41 | - (NSString *)description 42 | { 43 | return @"be non-nil"; 44 | } 45 | 46 | - (void)beNonNil {} 47 | 48 | @end 49 | -------------------------------------------------------------------------------- /Kiwi/NSNumber+KiwiAdditions.h: -------------------------------------------------------------------------------- 1 | // 2 | // Licensed under the terms in License.txt 3 | // 4 | // Copyright 2010 Allen Ding. All rights reserved. 5 | // 6 | 7 | #import "KiwiConfiguration.h" 8 | 9 | @interface NSNumber(KiwiAdditions) 10 | 11 | #pragma mark - 12 | #pragma mark Creating Numbers 13 | 14 | + (id)numberWithBytes:(const void *)bytes objCType:(const char *)anObjCType; 15 | + (id)numberWithBoolBytes:(const void *)bytes; 16 | + (id)numberWithCharBytes:(const void *)bytes; 17 | + (id)numberWithDoubleBytes:(const void *)bytes; 18 | + (id)numberWithFloatBytes:(const void *)bytes; 19 | + (id)numberWithIntBytes:(const void *)bytes; 20 | + (id)numberWithIntegerBytes:(const void *)bytes; 21 | + (id)numberWithLongBytes:(const void *)bytes; 22 | + (id)numberWithLongLongBytes:(const void *)bytes; 23 | + (id)numberWithShortBytes:(const void *)bytes; 24 | + (id)numberWithUnsignedCharBytes:(const void *)bytes; 25 | + (id)numberWithUnsignedIntBytes:(const void *)bytes; 26 | + (id)numberWithUnsignedIntegerBytes:(const void *)bytes; 27 | + (id)numberWithUnsignedLongBytes:(const void *)bytes; 28 | + (id)numberWithUnsignedLongLongBytes:(const void *)bytes; 29 | + (id)numberWithUnsignedShortBytes:(const void *)bytes; 30 | 31 | @end 32 | -------------------------------------------------------------------------------- /Kiwi/KWObjCUtilities.h: -------------------------------------------------------------------------------- 1 | // 2 | // Licensed under the terms in License.txt 3 | // 4 | // Copyright 2010 Allen Ding. All rights reserved. 5 | // 6 | 7 | #import "KiwiConfiguration.h" 8 | 9 | #pragma mark - 10 | #pragma mark Objective-C Type Utilities 11 | 12 | BOOL KWObjCTypeEqualToObjCType(const char *firstObjCType, const char *secondObjCType); 13 | BOOL KWObjCTypeIsNumeric(const char *objCType); 14 | BOOL KWObjCTypeIsFloatingPoint(const char *objCType); 15 | BOOL KWObjCTypeIsIntegral(const char *objCType); 16 | BOOL KWObjCTypeIsSignedIntegral(const char *objCType); 17 | BOOL KWObjCTypeIsUnsignedIntegral(const char *objCType); 18 | BOOL KWObjCTypeIsObject(const char *objCType); 19 | BOOL KWObjCTypeIsCharString(const char *objCType); 20 | BOOL KWObjCTypeIsClass(const char *objCType); 21 | BOOL KWObjCTypeIsSelector(const char *objCType); 22 | BOOL KWObjCTypeIsPointerToType(const char *objCType); 23 | BOOL KWObjCTypeIsPointerLike(const char *objCType); 24 | BOOL KWObjCTypeIsUnknown(const char *objCType); 25 | BOOL KWObjCTypeIsBlock(const char *objCType); 26 | 27 | NSUInteger KWObjCTypeLength(const char *objCType); 28 | 29 | #pragma mark - 30 | #pragma mark Selector Utlities 31 | 32 | NSUInteger KWSelectorParameterCount(SEL selector); -------------------------------------------------------------------------------- /Kiwi/KWBlock.m: -------------------------------------------------------------------------------- 1 | // 2 | // Licensed under the terms in License.txt 3 | // 4 | // Copyright 2010 Allen Ding. All rights reserved. 5 | // 6 | 7 | #import "KWBlock.h" 8 | 9 | @interface KWBlock() 10 | 11 | #pragma mark - 12 | #pragma mark Properties 13 | 14 | @property (nonatomic, readonly, assign) KWVoidBlock block; 15 | 16 | @end 17 | 18 | @implementation KWBlock 19 | 20 | #pragma mark - 21 | #pragma mark Initializing 22 | 23 | - (id)initWithBlock:(KWVoidBlock)aBlock { 24 | if ((self = [super init])) { 25 | block = Block_copy(aBlock); 26 | } 27 | 28 | return self; 29 | } 30 | 31 | + (id)blockWithBlock:(KWVoidBlock)aBlock { 32 | return [[[self alloc] initWithBlock:aBlock] autorelease]; 33 | } 34 | 35 | - (void)dealloc { 36 | Block_release(block); 37 | [super dealloc]; 38 | } 39 | 40 | #pragma mark - 41 | #pragma mark Properties 42 | 43 | @synthesize block; 44 | 45 | #pragma mark - 46 | #pragma mark Calling Blocks 47 | 48 | - (void)call { 49 | block(); 50 | } 51 | 52 | @end 53 | 54 | #pragma mark - 55 | #pragma mark Creating Blocks 56 | 57 | KWBlock *theBlock(KWVoidBlock aBlock) { 58 | return lambda(aBlock); 59 | } 60 | 61 | KWBlock *lambda(KWVoidBlock aBlock) { 62 | return [KWBlock blockWithBlock:aBlock]; 63 | } 64 | -------------------------------------------------------------------------------- /Kiwi/KWInvocationCapturer.h: -------------------------------------------------------------------------------- 1 | // 2 | // Licensed under the terms in License.txt 3 | // 4 | // Copyright 2010 Allen Ding. All rights reserved. 5 | // 6 | 7 | #import "KiwiConfiguration.h" 8 | 9 | @protocol KWInvocationCapturerDelegate; 10 | 11 | @interface KWInvocationCapturer : NSProxy { 12 | @private 13 | id delegate; 14 | NSDictionary *userInfo; 15 | } 16 | 17 | #pragma mark - 18 | #pragma mark Initializing 19 | 20 | - (id)initWithDelegate:(id)aDelegate; 21 | - (id)initWithDelegate:(id)aDelegate userInfo:(NSDictionary *)aUserInfo; 22 | 23 | + (id)invocationCapturerWithDelegate:(id)aDelegate; 24 | + (id)invocationCapturerWithDelegate:(id)aDelegate userInfo:(NSDictionary *)aUserInfo; 25 | 26 | #pragma mark - 27 | #pragma mark Properties 28 | 29 | @property (nonatomic, readonly) id delegate; 30 | @property (nonatomic, readonly) NSDictionary *userInfo; 31 | 32 | @end 33 | 34 | @protocol KWInvocationCapturerDelegate 35 | 36 | #pragma mark - 37 | #pragma mark Capturing Invocations 38 | 39 | - (NSMethodSignature *)invocationCapturer:(KWInvocationCapturer *)anInvocationCapturer methodSignatureForSelector:(SEL)aSelector; 40 | - (void)invocationCapturer:(KWInvocationCapturer *)anInvocationCapturer didCaptureInvocation:(NSInvocation *)anInvocation; 41 | 42 | @end 43 | -------------------------------------------------------------------------------- /README.textile: -------------------------------------------------------------------------------- 1 | h2. Objective-C Rubyfication Project 2 | 3 | Objective-C is a great language and Cocoa provides a great set of tools. But if 4 | you are like me and came from Ruby, you will miss lots of things. Some things 5 | can be achieved in Obj-C but with added verbosity. 6 | 7 | But, Obj-C has features such as Blocks, Categories, Selectors, Variable length 8 | arguments list for methods, and this allow us to emulate much of the Ruby 9 | standard libraries and syntax to Obj-C. 10 | 11 | The idea is to implement Categories to add Ruby-ish features to existing Obj-C classes 12 | such as NSString and NSArray. 13 | 14 | Then you can code like this: 15 | 16 |

17 | NSString* a = @"hello\nworld\nagain";
18 | NSMutableArray* b = [[NSMutableArray alloc] init];
19 | [a eachLine:^(NSString* line){
20 |   [b addObject:line];
21 | }];
22 | 
23 | NSDate* ref = [NSDate parse:@"2010-01-01 10:15:30"];
24 | 
25 | 26 | Feel free to add new features and let me know if this is useful or not, right 27 | now I am doing this just for the fun of it. 28 | 29 | h2. Credits 30 | 31 | * "Fabio Akita":http://www.akitaonrails.com 32 | * "Satoshi Nakagawa":https://github.com/psychs/cocoaoniguruma/ for the Oniguruma port 33 | * "Allen Ding":https://github.com/allending/Kiwi for Kiwi -------------------------------------------------------------------------------- /Kiwi/NSObject+KiwiStubAdditions.h: -------------------------------------------------------------------------------- 1 | // 2 | // Licensed under the terms in License.txt 3 | // 4 | // Copyright 2010 Allen Ding. All rights reserved. 5 | // 6 | 7 | #import "KiwiConfiguration.h" 8 | 9 | @class KWMessagePattern; 10 | 11 | @protocol KWMessageSpying; 12 | 13 | @interface NSObject(KiwiStubAdditions) 14 | 15 | #pragma mark - 16 | #pragma mark Stubbing Methods 17 | 18 | - (void)stub:(SEL)aSelector; 19 | - (void)stub:(SEL)aSelector withArguments:(id)firstArgument, ...; 20 | - (void)stub:(SEL)aSelector andReturn:(id)aValue; 21 | - (void)stub:(SEL)aSelector andReturn:(id)aValue withArguments:(id)firstArgument, ...; 22 | 23 | - (id)stub; 24 | - (id)stubAndReturn:(id)aValue; 25 | - (id)stubAndReturn:(id)aValue times:(id)times afterThatReturn:(id)aSecondValue; 26 | 27 | - (void)stubMessagePattern:(KWMessagePattern *)aMessagePattern andReturn:(id)aValue; 28 | - (void)stubMessagePattern:(KWMessagePattern *)aMessagePattern andReturn:(id)aValue times:(id)times afterThatReturn:(id)aSecondValue; 29 | 30 | - (void)clearStubs; 31 | 32 | #pragma mark - 33 | #pragma mark Spying on Messages 34 | 35 | - (void)addMessageSpy:(id)aSpy forMessagePattern:(KWMessagePattern *)aMessagePattern; 36 | - (void)removeMessageSpy:(id)aSpy forMessagePattern:(KWMessagePattern *)aMessagePattern; 37 | 38 | @end 39 | -------------------------------------------------------------------------------- /Kiwi/KWBeZeroMatcher.m: -------------------------------------------------------------------------------- 1 | // 2 | // Licensed under the terms in License.txt 3 | // 4 | // Copyright 2010 Allen Ding. All rights reserved. 5 | // 6 | 7 | #import "KWBeZeroMatcher.h" 8 | #import "KWFormatter.h" 9 | #import "KWValue.h" 10 | 11 | @implementation KWBeZeroMatcher 12 | 13 | #pragma mark - 14 | #pragma mark Getting Matcher Strings 15 | 16 | + (NSArray *)matcherStrings { 17 | return [NSArray arrayWithObject:@"beZero"]; 18 | } 19 | 20 | #pragma mark - 21 | #pragma mark Matching 22 | 23 | - (BOOL)evaluate { 24 | if (![self.subject respondsToSelector:@selector(boolValue)]) 25 | [NSException raise:@"KWMatcherException" format:@"subject does not respond to -numberValue"]; 26 | 27 | return [[self.subject numberValue] isEqualToNumber:[NSNumber numberWithInt:0]]; 28 | } 29 | 30 | #pragma mark - 31 | #pragma mark Getting Failure Messages 32 | 33 | - (NSString *)failureMessageForShould { 34 | return [NSString stringWithFormat:@"expected subject to be zero, got %@", 35 | [KWFormatter formatObject:self.subject]]; 36 | } 37 | 38 | - (NSString *)failureMessageForShouldNot { 39 | return [NSString stringWithFormat:@"expected subject not to be zero"]; 40 | } 41 | 42 | #pragma mark - 43 | #pragma mark Configuring Matchers 44 | 45 | - (void)beZero { 46 | } 47 | 48 | @end 49 | -------------------------------------------------------------------------------- /Kiwi/KWHamcrestMatcher.m: -------------------------------------------------------------------------------- 1 | // 2 | // KWHamcrestMatcher.m 3 | // Kiwi 4 | // 5 | // Created by Luke Redpath on 24/01/2011. 6 | // Copyright 2011 Allen Ding. All rights reserved. 7 | // 8 | 9 | #import "KWHamcrestMatcher.h" 10 | #import "KWHCMatcher.h" 11 | 12 | @interface KWHamcrestMatcher () 13 | 14 | #pragma mark - 15 | #pragma mark Properties 16 | 17 | @property (nonatomic, retain) id matcher; 18 | 19 | @end 20 | 21 | @implementation KWHamcrestMatcher 22 | 23 | @synthesize matcher; 24 | 25 | - (void)dealloc 26 | { 27 | [matcher release]; 28 | [super dealloc]; 29 | } 30 | 31 | #pragma mark - 32 | #pragma mark Matching 33 | 34 | - (BOOL)evaluate { 35 | return [self.matcher matches:self.subject]; 36 | } 37 | 38 | - (NSString *)failureMessageForShould { 39 | return [NSString stringWithFormat:@"expected subject to match %@", self.matcher]; 40 | } 41 | 42 | - (NSString *)description 43 | { 44 | return [NSString stringWithFormat:@"match %@", [self.matcher description]]; 45 | } 46 | 47 | #pragma mark - 48 | #pragma mark Getting Matcher Strings 49 | 50 | + (NSArray *)matcherStrings { 51 | return [NSArray arrayWithObjects:@"match:", nil]; 52 | } 53 | 54 | #pragma mark - 55 | #pragma mark Configuring Matchers 56 | 57 | - (void)match:(id)aMatcher; 58 | { 59 | self.matcher = aMatcher; 60 | } 61 | 62 | @end 63 | -------------------------------------------------------------------------------- /Kiwi/KWMatcherFactory.h: -------------------------------------------------------------------------------- 1 | // 2 | // Licensed under the terms in License.txt 3 | // 4 | // Copyright 2010 Allen Ding. All rights reserved. 5 | // 6 | 7 | #import "KiwiConfiguration.h" 8 | #import "KWMatching.h" 9 | 10 | @class KWFailure; 11 | @class KWMatcher; 12 | @class KWUserDefinedMatcherBuilder; 13 | 14 | @interface KWMatcherFactory : NSObject { 15 | @private 16 | NSMutableArray *registeredMatcherClasses; 17 | NSMutableDictionary *matcherClassChains; 18 | } 19 | 20 | #pragma mark - 21 | #pragma mark Initializing 22 | 23 | - (id)init; 24 | 25 | #pragma mark - 26 | #pragma mark Properties 27 | 28 | @property (nonatomic, readonly) NSArray *registeredMatcherClasses; 29 | 30 | #pragma mark - 31 | #pragma mark Registering Matcher Classes 32 | 33 | - (void)registerMatcherClass:(Class)aClass; 34 | - (void)registerMatcherClassesWithNamespacePrefix:(NSString *)aNamespacePrefix; 35 | 36 | #pragma mark - 37 | #pragma mark Registering User Defined Matchers 38 | 39 | //- (void)registerUserDefinedMatcherWithBuilder:(KWUserDefinedMatcherBuilder *)aBuilder; 40 | 41 | #pragma mark - 42 | #pragma mark Getting Method Signatures 43 | 44 | - (NSMethodSignature *)methodSignatureForMatcherSelector:(SEL)aSelector; 45 | 46 | #pragma mark - 47 | #pragma mark Getting Matchers 48 | 49 | - (KWMatcher *)matcherFromInvocation:(NSInvocation *)anInvocation subject:(id)subject; 50 | 51 | @end 52 | -------------------------------------------------------------------------------- /Kiwi/KWRegisterMatchersNode.m: -------------------------------------------------------------------------------- 1 | // 2 | // Licensed under the terms in License.txt 3 | // 4 | // Copyright 2010 Allen Ding. All rights reserved. 5 | // 6 | 7 | #import "KWRegisterMatchersNode.h" 8 | #import "KWExampleNodeVisitor.h" 9 | 10 | @implementation KWRegisterMatchersNode 11 | 12 | #pragma mark - 13 | #pragma mark Initializing 14 | 15 | - (id)initWithCallSite:(KWCallSite *)aCallSite namespacePrefix:(NSString *)aNamespacePrefix { 16 | if ((self = [super init])) { 17 | callSite = [aCallSite retain]; 18 | namespacePrefix = [aNamespacePrefix copy]; 19 | } 20 | 21 | return self; 22 | } 23 | 24 | + (id)registerMatchersNodeWithCallSite:(KWCallSite *)aCallSite namespacePrefix:(NSString *)aNamespacePrefix { 25 | return [[[self alloc] initWithCallSite:aCallSite namespacePrefix:aNamespacePrefix] autorelease]; 26 | } 27 | 28 | - (void)dealloc { 29 | [callSite release]; 30 | [namespacePrefix release]; 31 | [super dealloc]; 32 | } 33 | 34 | #pragma mark - 35 | #pragma mark Getting Call Sites 36 | 37 | @synthesize callSite; 38 | 39 | #pragma mark - 40 | #pragma mark Getting Namespace Prefixes 41 | 42 | @synthesize namespacePrefix; 43 | 44 | #pragma mark - 45 | #pragma mark Accepting Visitors 46 | 47 | - (void)acceptExampleNodeVisitor:(id)aVisitor { 48 | [aVisitor visitRegisterMatchersNode:self]; 49 | } 50 | 51 | @end 52 | -------------------------------------------------------------------------------- /Rubyfication/NSString+activesupport.m: -------------------------------------------------------------------------------- 1 | // 2 | // NSString+activesupport.m 3 | // Rubyfication 4 | // 5 | // Created by Fabio Akita on 1/30/11. 6 | // Copyright 2011 Gonow Tecnologia. All rights reserved. 7 | // 8 | 9 | #import "NSString+activesupport.h" 10 | 11 | 12 | @implementation NSString (activesupport) 13 | 14 | - (NSString*) at:(NSUInteger)position { 15 | @try { 16 | return [NSString stringWithFormat:@"%C", [self characterAtIndex:position]]; 17 | } 18 | @catch (NSException * e) { 19 | return nil; 20 | } 21 | } 22 | 23 | - (NSString*) from:(NSUInteger)position { 24 | return [self substringFromIndex:position]; 25 | } 26 | 27 | - (NSString*) to:(NSUInteger)position { 28 | return [self substringToIndex:position]; 29 | } 30 | 31 | - (NSString*) first { 32 | return [self first:1]; 33 | } 34 | 35 | - (NSString*) first:(NSUInteger)limit { 36 | if (limit == 0) { 37 | return @""; 38 | } else if (limit >= [self length]) { 39 | return self; 40 | } 41 | return [self substringToIndex:limit]; 42 | } 43 | 44 | - (NSString*) last { 45 | return [self last:1]; 46 | } 47 | 48 | - (NSString*) last:(NSUInteger)limit { 49 | if (limit == 0) { 50 | return @""; 51 | } else if (limit >= [self length]) { 52 | return self; 53 | } 54 | return [self substringFromIndex:[self length] - limit]; 55 | } 56 | 57 | 58 | @end 59 | -------------------------------------------------------------------------------- /Kiwi/KWHaveMatcher.h: -------------------------------------------------------------------------------- 1 | // 2 | // Licensed under the terms in License.txt 3 | // 4 | // Copyright 2010 Allen Ding. All rights reserved. 5 | // 6 | 7 | #import "KiwiConfiguration.h" 8 | #import "KWCountType.h" 9 | #import "KWMatcher.h" 10 | #import "KWMatchVerifier.h" 11 | 12 | @interface KWHaveMatcher : KWMatcher { 13 | @private 14 | KWCountType countType; 15 | NSUInteger count; 16 | NSInvocation *invocation; 17 | NSUInteger actualCount; 18 | } 19 | 20 | #pragma mark - 21 | #pragma mark Configuring Matchers 22 | 23 | - (void)haveCountOf:(NSUInteger)aCount; 24 | - (void)haveCountOfAtLeast:(NSUInteger)aCount; 25 | - (void)haveCountOfAtMost:(NSUInteger)aCount; 26 | - (void)have:(NSUInteger)aCount itemsForInvocation:(NSInvocation *)anInvocation; 27 | - (void)haveAtLeast:(NSUInteger)aCount itemsForInvocation:(NSInvocation *)anInvocation; 28 | - (void)haveAtMost:(NSUInteger)aCount itemsForInvocation:(NSInvocation *)anInvocation; 29 | 30 | @end 31 | 32 | @protocol KWContainmentCountMatcherTerminals 33 | 34 | #pragma mark - 35 | #pragma mark Terminals 36 | 37 | - (id)objects; 38 | - (id)items; 39 | - (id)elements; 40 | 41 | @end 42 | 43 | @interface KWMatchVerifier(KWHaveMatcherAdditions) 44 | 45 | #pragma mark - 46 | #pragma mark Verifying 47 | 48 | #pragma mark Invocation Capturing Methods 49 | 50 | - (id)have:(NSUInteger)aCount; 51 | - (id)haveAtLeast:(NSUInteger)aCount; 52 | - (id)haveAtMost:(NSUInteger)aCount; 53 | 54 | @end 55 | -------------------------------------------------------------------------------- /Kiwi/KWBeKindOfClassMatcher.m: -------------------------------------------------------------------------------- 1 | // 2 | // Licensed under the terms in License.txt 3 | // 4 | // Copyright 2010 Allen Ding. All rights reserved. 5 | // 6 | 7 | #import "KWBeKindOfClassMatcher.h" 8 | #import "KWFormatter.h" 9 | 10 | @interface KWBeKindOfClassMatcher() 11 | 12 | #pragma mark - 13 | #pragma mark Properties 14 | 15 | @property (nonatomic, readwrite, assign) Class targetClass; 16 | 17 | @end 18 | 19 | @implementation KWBeKindOfClassMatcher 20 | 21 | #pragma mark - 22 | #pragma mark Properties 23 | 24 | @synthesize targetClass; 25 | 26 | #pragma mark - 27 | #pragma mark Getting Matcher Strings 28 | 29 | + (NSArray *)matcherStrings { 30 | return [NSArray arrayWithObject:@"beKindOfClass:"]; 31 | } 32 | 33 | #pragma mark - 34 | #pragma mark Matching 35 | 36 | - (BOOL)evaluate { 37 | return [self.subject isKindOfClass:self.targetClass]; 38 | } 39 | 40 | #pragma mark - 41 | #pragma mark Getting Failure Messages 42 | 43 | - (NSString *)failureMessageForShould { 44 | return [NSString stringWithFormat:@"expected subject to be kind of %@", 45 | NSStringFromClass(self.targetClass)]; 46 | } 47 | 48 | - (NSString *)description 49 | { 50 | return [NSString stringWithFormat:@"be kind of %@", NSStringFromClass(self.targetClass)]; 51 | } 52 | 53 | #pragma mark - 54 | #pragma mark Configuring Matchers 55 | 56 | - (void)beKindOfClass:(Class)aClass { 57 | self.targetClass = aClass; 58 | } 59 | 60 | @end 61 | -------------------------------------------------------------------------------- /Kiwi/KWRespondToSelectorMatcher.m: -------------------------------------------------------------------------------- 1 | // 2 | // Licensed under the terms in License.txt 3 | // 4 | // Copyright 2010 Allen Ding. All rights reserved. 5 | // 6 | 7 | #import "KWRespondToSelectorMatcher.h" 8 | #import "KWFormatter.h" 9 | 10 | @interface KWRespondToSelectorMatcher() 11 | 12 | #pragma mark - 13 | #pragma mark Properties 14 | 15 | @property (nonatomic, readwrite) SEL selector; 16 | 17 | @end 18 | 19 | @implementation KWRespondToSelectorMatcher 20 | 21 | #pragma mark - 22 | #pragma mark Properties 23 | 24 | @synthesize selector; 25 | 26 | #pragma mark - 27 | #pragma mark Getting Matcher Strings 28 | 29 | + (NSArray *)matcherStrings { 30 | return [NSArray arrayWithObject:@"respondToSelector:"]; 31 | } 32 | 33 | #pragma mark - 34 | #pragma mark Matching 35 | 36 | - (BOOL)evaluate { 37 | return [self.subject respondsToSelector:self.selector]; 38 | } 39 | 40 | #pragma mark - 41 | #pragma mark Getting Failure Messages 42 | 43 | - (NSString *)failureMessageForShould { 44 | return [NSString stringWithFormat:@"expected subject to respond to -%@", 45 | NSStringFromSelector(self.selector)]; 46 | } 47 | 48 | - (NSString *)description 49 | { 50 | return [NSString stringWithFormat:@"respond to -%@", NSStringFromSelector(self.selector)]; 51 | } 52 | 53 | #pragma mark - 54 | #pragma mark Configuring Matchers 55 | 56 | - (void)respondToSelector:(SEL)aSelector { 57 | self.selector = aSelector; 58 | } 59 | 60 | @end 61 | -------------------------------------------------------------------------------- /Kiwi/KWConformToProtocolMatcher.m: -------------------------------------------------------------------------------- 1 | // 2 | // Licensed under the terms in License.txt 3 | // 4 | // Copyright 2010 Allen Ding. All rights reserved. 5 | // 6 | 7 | #import "KWConformToProtocolMatcher.h" 8 | #import "KWFormatter.h" 9 | 10 | @interface KWConformToProtocolMatcher() 11 | 12 | #pragma mark - 13 | #pragma mark Properties 14 | 15 | @property (nonatomic, readwrite, assign) Protocol *protocol; 16 | 17 | @end 18 | 19 | @implementation KWConformToProtocolMatcher 20 | 21 | #pragma mark - 22 | #pragma mark Properties 23 | 24 | @synthesize protocol; 25 | 26 | #pragma mark - 27 | #pragma mark Getting Matcher Strings 28 | 29 | + (NSArray *)matcherStrings { 30 | return [NSArray arrayWithObject:@"conformToProtocol:"]; 31 | } 32 | 33 | #pragma mark - 34 | #pragma mark Matching 35 | 36 | - (BOOL)evaluate { 37 | return [self.subject conformsToProtocol:self.protocol]; 38 | } 39 | 40 | #pragma mark - 41 | #pragma mark Getting Failure Messages 42 | 43 | - (NSString *)failureMessageForShould { 44 | return [NSString stringWithFormat:@"expected subject to conform to %@ protocol", 45 | NSStringFromProtocol(self.protocol)]; 46 | } 47 | 48 | - (NSString *)description 49 | { 50 | return [NSString stringWithFormat:@"conform to %@ protocol", NSStringFromProtocol(self.protocol)]; 51 | } 52 | 53 | #pragma mark - 54 | #pragma mark Configuring Matchers 55 | 56 | - (void)conformToProtocol:(Protocol *)aProtocol { 57 | self.protocol = aProtocol; 58 | } 59 | 60 | @end 61 | -------------------------------------------------------------------------------- /Kiwi/KWBeMemberOfClassMatcher.m: -------------------------------------------------------------------------------- 1 | // 2 | // Licensed under the terms in License.txt 3 | // 4 | // Copyright 2010 Allen Ding. All rights reserved. 5 | // 6 | 7 | #import "KWBeMemberOfClassMatcher.h" 8 | #import "KWFormatter.h" 9 | 10 | @interface KWBeMemberOfClassMatcher() 11 | 12 | #pragma mark - 13 | #pragma mark Properties 14 | 15 | @property (nonatomic, readwrite, assign) Class targetClass; 16 | 17 | @end 18 | 19 | @implementation KWBeMemberOfClassMatcher 20 | 21 | #pragma mark - 22 | #pragma mark Properties 23 | 24 | @synthesize targetClass; 25 | 26 | #pragma mark - 27 | #pragma mark Getting Matcher Strings 28 | 29 | + (NSArray *)matcherStrings { 30 | return [NSArray arrayWithObject:@"beMemberOfClass:"]; 31 | } 32 | 33 | #pragma mark - 34 | #pragma mark Matching 35 | 36 | - (BOOL)evaluate { 37 | return [self.subject isMemberOfClass:self.targetClass]; 38 | } 39 | 40 | #pragma mark - 41 | #pragma mark Getting Failure Messages 42 | 43 | - (NSString *)failureMessageForShould { 44 | return [NSString stringWithFormat:@"expected subject to be member of %@", 45 | NSStringFromClass(self.targetClass)]; 46 | } 47 | 48 | - (NSString *)description 49 | { 50 | return [NSString stringWithFormat:@"be member of %@", 51 | NSStringFromClass(self.targetClass)]; 52 | } 53 | 54 | #pragma mark - 55 | #pragma mark Configuring Matchers 56 | 57 | - (void)beMemberOfClass:(Class)aClass { 58 | self.targetClass = aClass; 59 | } 60 | 61 | @end 62 | -------------------------------------------------------------------------------- /Kiwi/KWCallSite.m: -------------------------------------------------------------------------------- 1 | // 2 | // Licensed under the terms in License.txt 3 | // 4 | // Copyright 2010 Allen Ding. All rights reserved. 5 | // 6 | 7 | #import "KWCallSite.h" 8 | 9 | @implementation KWCallSite 10 | 11 | #pragma mark - 12 | #pragma mark Initializing 13 | 14 | - (id)initWithFilename:(NSString *)aFilename lineNumber:(NSUInteger)aLineNumber { 15 | if ((self = [super init])) { 16 | filename = [aFilename copy]; 17 | lineNumber = aLineNumber; 18 | } 19 | 20 | return self; 21 | } 22 | 23 | + (id)callSiteWithFilename:(NSString *)aFilename lineNumber:(NSUInteger)aLineNumber { 24 | return [[[self alloc] initWithFilename:aFilename lineNumber:aLineNumber] autorelease]; 25 | } 26 | 27 | - (void)dealloc { 28 | [filename release]; 29 | [super dealloc]; 30 | } 31 | 32 | #pragma mark - 33 | #pragma mark Accessing Call Site Properties 34 | 35 | @synthesize filename; 36 | @synthesize lineNumber; 37 | 38 | #pragma mark - 39 | #pragma mark Identifying and Comparing 40 | 41 | - (NSUInteger)hash { 42 | return [[NSString stringWithFormat:@"%@%u", self.filename, (unsigned)self.lineNumber] hash]; 43 | } 44 | 45 | - (BOOL)isEqual:(id)anObject { 46 | if (![anObject isKindOfClass:[KWCallSite class]]) 47 | return NO; 48 | 49 | return [self isEqualToCallSite:anObject]; 50 | } 51 | 52 | - (BOOL)isEqualToCallSite:(KWCallSite *)aCallSite { 53 | return [self.filename isEqualToString:aCallSite.filename] && (self.lineNumber == aCallSite.lineNumber); 54 | } 55 | 56 | @end 57 | -------------------------------------------------------------------------------- /Kiwi/KWTestCase.h: -------------------------------------------------------------------------------- 1 | // 2 | // Licensed under the terms in License.txt 3 | // 4 | // Copyright 2010 Allen Ding. All rights reserved. 5 | // 6 | 7 | #import "KiwiConfiguration.h" 8 | #import 9 | #import "KWExpectationType.h" 10 | #import "KWReporting.h" 11 | 12 | @class KWCallSite; 13 | @class KWMatcherFactory; 14 | 15 | @protocol KWVerifying; 16 | 17 | // Deprecated. This is here just in case blocks are not enabled. 18 | @interface KWTestCase : SenTestCase { 19 | @private 20 | KWMatcherFactory *matcherFactory; 21 | NSMutableArray *verifiers; 22 | NSMutableArray *failures; 23 | } 24 | 25 | #pragma mark - 26 | #pragma mark Configuring Example Environments 27 | 28 | - (void)setUpExampleEnvironment; 29 | - (void)tearDownExampleEnvironment; 30 | 31 | #pragma mark - 32 | #pragma mark Marking Pending Examples 33 | 34 | - (void)markPendingWithCallSite:(KWCallSite *)aCallSite; 35 | - (void)markPendingWithCallSite:(KWCallSite *)aCallSite :(NSString *)aDescription; 36 | 37 | #pragma mark - 38 | #pragma mark Adding Verifiers 39 | 40 | - (id)addVerifier:(id)aVerifier; 41 | - (id)addExistVerifierWithExpectationType:(KWExpectationType)anExpectationType callSite:(KWCallSite *)aCallSite; 42 | - (id)addMatchVerifierWithExpectationType:(KWExpectationType)anExpectationType callSite:(KWCallSite *)aCallSite; 43 | - (id)addAsyncVerifierWithExpectationType:(KWExpectationType)anExpectationType callSite:(KWCallSite *)aCallSite timeout:(NSInteger)timeout; 44 | 45 | @end 46 | -------------------------------------------------------------------------------- /Kiwi/KWMessageTracker.h: -------------------------------------------------------------------------------- 1 | // 2 | // Licensed under the terms in License.txt 3 | // 4 | // Copyright 2010 Allen Ding. All rights reserved. 5 | // 6 | 7 | #import "KiwiConfiguration.h" 8 | #import "KWCountType.h" 9 | #import "KWMessageSpying.h" 10 | 11 | @class KWMessagePattern; 12 | 13 | @interface KWMessageTracker : NSObject { 14 | @private 15 | id subject; 16 | KWMessagePattern *messagePattern; 17 | KWCountType countType; 18 | NSUInteger count; 19 | NSUInteger receivedCount; 20 | } 21 | 22 | #pragma mark - 23 | #pragma mark Initializing 24 | 25 | - (id)initWithSubject:(id)anObject messagePattern:(KWMessagePattern *)aMessagePattern countType:(KWCountType)aCountType count:(NSUInteger)aCount; 26 | 27 | + (id)messageTrackerWithSubject:(id)anObject messagePattern:(KWMessagePattern *)aMessagePattern countType:(KWCountType)aCountType count:(NSUInteger)aCount; 28 | 29 | #pragma mark - 30 | #pragma mark Properties 31 | 32 | @property (nonatomic, readonly) id subject; 33 | @property (nonatomic, readonly) KWMessagePattern *messagePattern; 34 | @property (nonatomic, readonly) KWCountType countType; 35 | @property (nonatomic, readonly) NSUInteger count; 36 | 37 | #pragma mark - 38 | #pragma mark Stopping Tracking 39 | 40 | - (void)stopTracking; 41 | 42 | #pragma mark - 43 | #pragma mark Getting Message Tracker Status 44 | 45 | - (BOOL)succeeded; 46 | 47 | #pragma mark - 48 | #pragma mark Getting Phrases 49 | 50 | - (NSString *)expectedCountPhrase; 51 | - (NSString *)receivedCountPhrase; 52 | 53 | @end 54 | -------------------------------------------------------------------------------- /Kiwi/KWBeSubclassOfClassMatcher.m: -------------------------------------------------------------------------------- 1 | // 2 | // Licensed under the terms in License.txt 3 | // 4 | // Copyright 2010 Allen Ding. All rights reserved. 5 | // 6 | 7 | #import "KWBeSubclassOfClassMatcher.h" 8 | #import "KWFormatter.h" 9 | 10 | @interface KWBeSubclassOfClassMatcher() 11 | 12 | #pragma mark - 13 | #pragma mark Properties 14 | 15 | @property (nonatomic, readwrite, assign) Class targetClass; 16 | 17 | @end 18 | 19 | @implementation KWBeSubclassOfClassMatcher 20 | 21 | #pragma mark - 22 | #pragma mark Properties 23 | 24 | @synthesize targetClass; 25 | 26 | #pragma mark - 27 | #pragma mark Getting Matcher Strings 28 | 29 | + (NSArray *)matcherStrings { 30 | return [NSArray arrayWithObject:@"beSubclassOfClass:"]; 31 | } 32 | 33 | #pragma mark - 34 | #pragma mark Matching 35 | 36 | - (BOOL)evaluate { 37 | return [self.subject isSubclassOfClass:self.targetClass]; 38 | } 39 | 40 | #pragma mark - 41 | #pragma mark Getting Failure Messages 42 | 43 | - (NSString *)failureMessageForShould { 44 | return [NSString stringWithFormat:@"expected subject to be subclass of %@", 45 | NSStringFromClass(self.targetClass)]; 46 | } 47 | 48 | - (NSString *)description 49 | { 50 | return [NSString stringWithFormat:@"be member of %@", 51 | NSStringFromClass(self.targetClass)]; 52 | } 53 | 54 | #pragma mark - 55 | #pragma mark Configuring Matchers 56 | 57 | - (void)beSubclassOfClass:(Class)aClass { 58 | self.targetClass = aClass; 59 | } 60 | 61 | @end 62 | -------------------------------------------------------------------------------- /Kiwi/KWMessagePattern.h: -------------------------------------------------------------------------------- 1 | // 2 | // Licensed under the terms in License.txt 3 | // 4 | // Copyright 2010 Allen Ding. All rights reserved. 5 | // 6 | 7 | #import "KiwiConfiguration.h" 8 | 9 | @interface KWMessagePattern : NSObject { 10 | @private 11 | SEL selector; 12 | NSArray *argumentFilters; 13 | } 14 | 15 | #pragma mark - 16 | #pragma mark Initializing 17 | 18 | - (id)initWithSelector:(SEL)aSelector; 19 | - (id)initWithSelector:(SEL)aSelector argumentFilters:(NSArray *)anArray; 20 | - (id)initWithSelector:(SEL)aSelector firstArgumentFilter:(id)firstArgumentFilter argumentList:(va_list)argumentList; 21 | 22 | + (id)messagePatternWithSelector:(SEL)aSelector; 23 | + (id)messagePatternWithSelector:(SEL)aSelector argumentFilters:(NSArray *)anArray; 24 | + (id)messagePatternWithSelector:(SEL)aSelector firstArgumentFilter:(id)firstArgumentFilter argumentList:(va_list)argumentList; 25 | 26 | + (id)messagePatternFromInvocation:(NSInvocation *)anInvocation; 27 | 28 | #pragma mark - 29 | #pragma mark Properties 30 | 31 | @property (nonatomic, readonly) SEL selector; 32 | @property (nonatomic, readonly) NSArray *argumentFilters; 33 | 34 | #pragma mark - 35 | #pragma mark Matching Invocations 36 | 37 | - (BOOL)matchesInvocation:(NSInvocation *)anInvocation; 38 | 39 | #pragma mark - 40 | #pragma mark Comparing Message Patterns 41 | 42 | - (BOOL)isEqualToMessagePattern:(KWMessagePattern *)aMessagePattern; 43 | 44 | #pragma mark - 45 | #pragma mark Retrieving String Representations 46 | 47 | - (NSString *)stringValue; 48 | 49 | @end 50 | -------------------------------------------------------------------------------- /Kiwi/KWStub.h: -------------------------------------------------------------------------------- 1 | // 2 | // Licensed under the terms in License.txt 3 | // 4 | // Copyright 2010 Allen Ding. All rights reserved. 5 | // 6 | 7 | #import "KiwiConfiguration.h" 8 | 9 | @class KWMessagePattern; 10 | 11 | @interface KWStub : NSObject { 12 | @private 13 | KWMessagePattern *messagePattern; 14 | id value; 15 | id returnValueTimes; 16 | int returnedValueTimes; 17 | id secondValue; 18 | } 19 | 20 | #pragma mark - 21 | #pragma mark Initializing 22 | 23 | - (id)initWithMessagePattern:(KWMessagePattern *)aMessagePattern; 24 | - (id)initWithMessagePattern:(KWMessagePattern *)aMessagePattern value:(id)aValue; 25 | - (id)initWithMessagePattern:(KWMessagePattern *)aMessagePattern value:(id)aValue times:(id)times afterThatReturn:(id)aSecondValue; 26 | 27 | + (id)stubWithMessagePattern:(KWMessagePattern *)aMessagePattern; 28 | + (id)stubWithMessagePattern:(KWMessagePattern *)aMessagePattern value:(id)aValue; 29 | + (id)stubWithMessagePattern:(KWMessagePattern *)aMessagePattern value:(id)aValue times:(id)times afterThatReturn:(id)aSecondValue; 30 | 31 | #pragma mark - 32 | #pragma mark Properties 33 | 34 | @property (nonatomic, readonly) KWMessagePattern *messagePattern; 35 | @property (nonatomic, readonly) id value; 36 | @property (nonatomic, readonly) id returnValueTimes; 37 | @property (nonatomic, readonly) int returnedValueTimes; 38 | @property (nonatomic, readonly) id secondValue; 39 | 40 | #pragma mark - 41 | #pragma mark Processing Invocations 42 | 43 | - (BOOL)processInvocation:(NSInvocation *)anInvocation; 44 | 45 | @end 46 | -------------------------------------------------------------------------------- /CocoaOniguruma/oniguruma/COPYING: -------------------------------------------------------------------------------- 1 | Oniguruma LICENSE 2 | ----------------- 3 | 4 | /*- 5 | * Copyright (c) 2002-2007 K.Kosako 6 | * All rights reserved. 7 | * 8 | * Redistribution and use in source and binary forms, with or without 9 | * modification, are permitted provided that the following conditions 10 | * are met: 11 | * 1. Redistributions of source code must retain the above copyright 12 | * notice, this list of conditions and the following disclaimer. 13 | * 2. Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in the 15 | * documentation and/or other materials provided with the distribution. 16 | * 17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 18 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 21 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 | * SUCH DAMAGE. 28 | */ 29 | -------------------------------------------------------------------------------- /Rubyfication/NSArray+activesupport.m: -------------------------------------------------------------------------------- 1 | // 2 | // NSArray+activesupport.m 3 | // Rubyfication 4 | // 5 | // Created by Fabio Akita on 2/2/11. 6 | // Copyright 2011 Gonow Tecnologia. All rights reserved. 7 | // 8 | 9 | #import "NSArray+activesupport.h" 10 | 11 | 12 | @implementation NSArray (activesupport) 13 | 14 | - (NSArray*) from:(NSUInteger)position { 15 | if (position == 0) { 16 | return self; 17 | } 18 | if (position >= [self count]) { 19 | return [[[NSArray alloc] init] autorelease]; 20 | } 21 | 22 | NSRange theRange; 23 | theRange.location = position; 24 | theRange.length = [self count] - position; 25 | 26 | return [self subarrayWithRange:theRange]; 27 | } 28 | 29 | - (NSArray*) to:(NSUInteger)position { 30 | if (position >= [self count]) { 31 | return self; 32 | } 33 | 34 | NSRange theRange; 35 | theRange.location = 0; 36 | theRange.length = position + 1; 37 | 38 | return [self subarrayWithRange:theRange]; 39 | } 40 | 41 | - (id) second { 42 | @try { 43 | return [self objectAtIndex:1]; 44 | } 45 | @catch (NSException * e) { 46 | return [NSNull null]; 47 | } 48 | } 49 | 50 | - (id) third { 51 | @try { 52 | return [self objectAtIndex:2]; 53 | } 54 | @catch (NSException * e) { 55 | return [NSNull null]; 56 | } 57 | } 58 | 59 | - (id) fortyTwo { 60 | @try { 61 | return [self objectAtIndex:41]; 62 | } 63 | @catch (NSException * e) { 64 | return [NSNull null]; 65 | } 66 | } 67 | 68 | @end 69 | -------------------------------------------------------------------------------- /Kiwi/KWIntercept.h: -------------------------------------------------------------------------------- 1 | // 2 | // Licensed under the terms in License.txt 3 | // 4 | // Copyright 2010 Allen Ding. All rights reserved. 5 | // 6 | 7 | #import "KiwiConfiguration.h" 8 | #import 9 | 10 | @class KWMessagePattern; 11 | @class KWStub; 12 | 13 | #pragma mark - 14 | #pragma mark Getting Forwarding Implementations 15 | 16 | IMP KWRegularForwardingImplementation(void); 17 | IMP KWStretForwardingImplementation(void); 18 | IMP KWForwardingImplementationForMethodEncoding(const char* encoding); 19 | 20 | #pragma mark - 21 | #pragma mark Getting Intercept Class Information 22 | 23 | BOOL KWObjectIsClass(id anObject); 24 | BOOL KWClassIsInterceptClass(Class aClass); 25 | NSString *KWInterceptClassNameForClass(Class aClass); 26 | Class KWInterceptClassForCanonicalClass(Class canonicalClass); 27 | Class KWRealClassForClass(Class aClass); 28 | 29 | #pragma mark - 30 | #pragma mark Enabling Intercepting 31 | 32 | Class KWSetupObjectInterceptSupport(id anObject); 33 | void KWSetupMethodInterceptSupport(Class interceptClass, SEL aSelector); 34 | 35 | #pragma mark - Managing Stubs & Spies 36 | void KWClearStubsAndSpies(void); 37 | 38 | #pragma mark - 39 | #pragma mark Managing Objects Stubs 40 | 41 | void KWAssociateObjectStub(id anObject, KWStub *aStub); 42 | void KWClearObjectStubs(id anObject); 43 | void KWClearAllObjectStubs(void); 44 | 45 | #pragma mark - 46 | #pragma mark Managing Message Spies 47 | 48 | void KWAssociateMessageSpy(id anObject, id aSpy, KWMessagePattern *aMessagePattern); 49 | void KWClearObjectSpy(id anObject, id aSpy, KWMessagePattern *aMessagePattern); 50 | void KWClearAllMessageSpies(void); 51 | -------------------------------------------------------------------------------- /Kiwi/KWProbePoller.m: -------------------------------------------------------------------------------- 1 | // 2 | // KWProbePoller.m 3 | // iOSFalconCore 4 | // 5 | // Created by Luke Redpath on 13/01/2011. 6 | // Copyright 2011 LJR Software Limited. All rights reserved. 7 | // 8 | 9 | #import "KWProbePoller.h" 10 | 11 | @interface KWTimeout : NSObject 12 | { 13 | NSDate *timeoutDate; 14 | } 15 | - (id)initWithTimeout:(NSTimeInterval)timeout; 16 | - (BOOL)hasTimedOut; 17 | @end 18 | 19 | @implementation KWTimeout 20 | 21 | - (id)initWithTimeout:(NSTimeInterval)timeout 22 | { 23 | if ((self = [super init])) { 24 | timeoutDate = [[NSDate alloc] initWithTimeIntervalSinceNow:timeout]; 25 | } 26 | return self; 27 | } 28 | 29 | - (void)dealloc 30 | { 31 | [timeoutDate release]; 32 | [super dealloc]; 33 | } 34 | 35 | - (BOOL)hasTimedOut 36 | { 37 | return [timeoutDate timeIntervalSinceDate:[NSDate date]] < 0; 38 | } 39 | 40 | @end 41 | 42 | #pragma mark - 43 | 44 | @implementation KWProbePoller 45 | 46 | - (id)initWithTimeout:(NSTimeInterval)theTimeout delay:(NSTimeInterval)theDelay; 47 | { 48 | if ((self = [super init])) { 49 | timeoutInterval = theTimeout; 50 | delayInterval = theDelay; 51 | } 52 | return self; 53 | } 54 | 55 | - (BOOL)check:(id)probe; 56 | { 57 | KWTimeout *timeout = [[KWTimeout alloc] initWithTimeout:timeoutInterval]; 58 | 59 | while (![probe isSatisfied]) { 60 | if ([timeout hasTimedOut]) { 61 | [timeout release]; 62 | return NO; 63 | } 64 | [[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:delayInterval]]; 65 | [probe sample]; 66 | } 67 | [timeout release]; 68 | 69 | return YES; 70 | } 71 | 72 | @end 73 | -------------------------------------------------------------------------------- /Kiwi/KWCaptureSpy.m: -------------------------------------------------------------------------------- 1 | #import "KWCaptureSpy.h" 2 | #import "KWObjCUtilities.h" 3 | #import "NSInvocation+KiwiAdditions.h" 4 | #import "NSMethodSignature+KiwiAdditions.h" 5 | #import "KWValue.h" 6 | 7 | @implementation KWCaptureSpy 8 | @dynamic argument; 9 | 10 | - (id)initWithArgumentIndex:(NSUInteger)index { 11 | if ((self = [super init])) { 12 | _argumentIndex = index; 13 | } 14 | return self; 15 | } 16 | 17 | - (id)argument { 18 | if (!_argument) { 19 | @throw [NSException exceptionWithName:NSInternalInconsistencyException reason:@"Argument requested has yet to be captured." userInfo:nil]; 20 | } 21 | return [[_argument retain] autorelease]; 22 | } 23 | 24 | - (void)object:(id)anObject didReceiveInvocation:(NSInvocation *)anInvocation { 25 | if (!_argument) { 26 | NSMethodSignature *signature = [anInvocation methodSignature]; 27 | const char *objCType = [signature messageArgumentTypeAtIndex:_argumentIndex]; 28 | if (KWObjCTypeIsObject(objCType)) { 29 | id argument = nil; 30 | [anInvocation getMessageArgument:&argument atIndex:_argumentIndex]; 31 | if (KWObjCTypeIsBlock(objCType)) { 32 | _argument = [argument copy]; 33 | } else { 34 | _argument = [argument retain]; 35 | } 36 | } else { 37 | NSData *data = [anInvocation messageArgumentDataAtIndex:_argumentIndex]; 38 | _argument = [[KWValue valueWithBytes:[data bytes] objCType:objCType] retain]; 39 | } 40 | } 41 | } 42 | 43 | - (void)dealloc { 44 | [_argument release]; 45 | [super dealloc]; 46 | } 47 | @end 48 | -------------------------------------------------------------------------------- /Kiwi/KWExampleGroupBuilder.h: -------------------------------------------------------------------------------- 1 | // 2 | // Licensed under the terms in License.txt 3 | // 4 | // Copyright 2010 Allen Ding. All rights reserved. 5 | // 6 | 7 | #import "KiwiConfiguration.h" 8 | #import "KWBlock.h" 9 | 10 | @class KWCallSite; 11 | @class KWExample; 12 | @class KWExampleSuite; 13 | 14 | @interface KWExampleGroupBuilder : NSObject { 15 | @private 16 | NSMutableArray *contextNodeStack; 17 | NSMutableSet *suites; 18 | } 19 | 20 | #pragma mark - 21 | #pragma mark Initializing 22 | 23 | + (id)sharedExampleGroupBuilder; 24 | 25 | #pragma mark - 26 | #pragma mark Building Example Groups 27 | 28 | @property (nonatomic, readonly) BOOL isBuildingExampleGroup; 29 | @property (nonatomic, retain, readonly) KWExampleSuite *exampleSuite; 30 | @property (nonatomic, retain) KWExample *currentExample; 31 | 32 | - (KWExampleSuite *)buildExampleGroups:(void (^)(void))buildingBlock; 33 | - (KWExample *)currentExample; 34 | 35 | - (void)pushContextNodeWithCallSite:(KWCallSite *)aCallSite description:(NSString *)aDescription; 36 | - (void)popContextNode; 37 | - (void)setRegisterMatchersNodeWithCallSite:(KWCallSite *)aCallSite namespacePrefix:(NSString *)aNamespacePrefix; 38 | - (void)setBeforeAllNodeWithCallSite:(KWCallSite *)aCallSite block:(KWVoidBlock)aBlock; 39 | - (void)setAfterAllNodeWithCallSite:(KWCallSite *)aCallSite block:(KWVoidBlock)aBlock; 40 | - (void)setBeforeEachNodeWithCallSite:(KWCallSite *)aCallSite block:(KWVoidBlock)aBlock; 41 | - (void)setAfterEachNodeWithCallSite:(KWCallSite *)aCallSite block:(KWVoidBlock)aBlock; 42 | - (void)addItNodeWithCallSite:(KWCallSite *)aCallSite description:(NSString *)aDescription block:(KWVoidBlock)aBlock; 43 | - (void)addPendingNodeWithCallSite:(KWCallSite *)aCallSite description:(NSString *)aDescription; 44 | 45 | @end 46 | -------------------------------------------------------------------------------- /Kiwi/KWBeTrueMatcher.m: -------------------------------------------------------------------------------- 1 | // 2 | // Licensed under the terms in License.txt 3 | // 4 | // Copyright 2010 Allen Ding. All rights reserved. 5 | // 6 | 7 | #import "KWBeTrueMatcher.h" 8 | 9 | @interface KWBeTrueMatcher() 10 | 11 | #pragma mark - 12 | #pragma mark Properties 13 | 14 | @property (nonatomic, readwrite) BOOL expectedValue; 15 | 16 | @end 17 | 18 | @implementation KWBeTrueMatcher 19 | 20 | #pragma mark - 21 | #pragma mark Properties 22 | 23 | @synthesize expectedValue; 24 | 25 | #pragma mark - 26 | #pragma mark Getting Matcher Strings 27 | 28 | + (NSArray *)matcherStrings { 29 | return [NSArray arrayWithObjects:@"beTrue", @"beFalse", @"beYes", @"beNo", nil]; 30 | } 31 | 32 | #pragma mark - 33 | #pragma mark Matching 34 | 35 | - (BOOL)evaluate { 36 | if (![self.subject respondsToSelector:@selector(boolValue)]) 37 | [NSException raise:@"KWMatcherException" format:@"subject does not respond to -boolValue"]; 38 | 39 | return [self.subject boolValue] == self.expectedValue; 40 | } 41 | 42 | #pragma mark - 43 | #pragma mark Getting Failure Messages 44 | 45 | - (NSString *)failureMessageForShould { 46 | return [NSString stringWithFormat:@"expected subject to be %@", 47 | expectedValue ? @"true" : @"false"]; 48 | } 49 | 50 | - (NSString *)description 51 | { 52 | if (self.expectedValue == YES) { 53 | return @"be true"; 54 | } 55 | return @"be false"; 56 | } 57 | 58 | #pragma mark - 59 | #pragma mark Configuring Matchers 60 | 61 | - (void)beTrue { 62 | self.expectedValue = YES; 63 | } 64 | 65 | - (void)beFalse { 66 | self.expectedValue = NO; 67 | } 68 | 69 | - (void)beYes { 70 | self.expectedValue = YES; 71 | } 72 | 73 | - (void)beNo { 74 | self.expectedValue = NO; 75 | } 76 | 77 | @end 78 | -------------------------------------------------------------------------------- /Kiwi/KWMatchVerifier.h: -------------------------------------------------------------------------------- 1 | // 2 | // Licensed under the terms in License.txt 3 | // 4 | // Copyright 2010 Allen Ding. All rights reserved. 5 | // 6 | 7 | #import "KiwiConfiguration.h" 8 | #import "KWExpectationType.h" 9 | #import "KWVerifying.h" 10 | 11 | @class KWCallSite; 12 | @class KWMatcherFactory; 13 | 14 | @protocol KWMatching; 15 | @protocol KWReporting; 16 | 17 | @interface KWMatchVerifier : NSObject { 18 | @private 19 | KWExpectationType expectationType; 20 | KWCallSite *callSite; 21 | KWMatcherFactory *matcherFactory; 22 | id reporter; 23 | id subject; 24 | id endOfExampleMatcher; 25 | } 26 | 27 | #pragma mark - 28 | #pragma mark Properties 29 | 30 | @property (nonatomic, readonly) KWExpectationType expectationType; 31 | @property (nonatomic, readonly) KWCallSite *callSite; 32 | @property (nonatomic, readonly) KWMatcherFactory *matcherFactory; 33 | @property (nonatomic, readonly) id reporter; 34 | @property (nonatomic, readwrite, retain) id subject; 35 | 36 | #pragma mark - 37 | #pragma mark Initializing 38 | 39 | - (id)initForShouldWithCallSite:(KWCallSite *)aCallSite matcherFactory:(KWMatcherFactory *)aMatcherFactory reporter:(id)aReporter; 40 | - (id)initForShouldNotWithCallSite:(KWCallSite *)aCallSite matcherFactory:(KWMatcherFactory *)aMatcherFactory reporter:(id)aReporter; 41 | - (id)initWithExpectationType:(KWExpectationType)anExpectationType callSite:(KWCallSite *)aCallSite matcherFactory:(KWMatcherFactory *)aMatcherFactory reporter:(id)aReporter; 42 | 43 | + (id)matchVerifierWithExpectationType:(KWExpectationType)anExpectationType callSite:(KWCallSite *)aCallSite matcherFactory:(KWMatcherFactory *)aMatcherFactory reporter:(id)aReporter; 44 | 45 | @end 46 | -------------------------------------------------------------------------------- /Rubyfication/NSArray+functional.m: -------------------------------------------------------------------------------- 1 | // 2 | // NSArray+functional.m 3 | // Rubyfication 4 | // 5 | // Created by Fabio Akita on 1/28/11. 6 | // Copyright 2011 Gonow Tecnologia. All rights reserved. 7 | // 8 | 9 | #import "NSArray+functional.h" 10 | 11 | 12 | @implementation NSArray (functional) 13 | 14 | #if defined(NS_BLOCKS_AVAILABLE) 15 | 16 | - (void) each:(void (^) (id))block { 17 | int i = 0; 18 | for (i = 0; i < [self count]; i ++) { 19 | block([self objectAtIndex:i]); 20 | } 21 | } 22 | 23 | - (NSArray*) map:(id (^) (id))block { 24 | NSMutableArray* ret = [[NSMutableArray alloc] init]; 25 | for (id obj in self) { 26 | [ret addObject:block(obj)]; 27 | } 28 | return [ret autorelease]; 29 | } 30 | 31 | - (id) inject:(id)initialValue with:(id (^) (id total, id item))block { 32 | for (id obj in self) { 33 | initialValue = block(initialValue, obj); 34 | } 35 | return initialValue; 36 | } 37 | 38 | - (void) eachIndex:(void (^) (int))block { 39 | int i; 40 | for (i = 0; i < [self count]; i ++) { 41 | block(i); 42 | } 43 | } 44 | 45 | - (NSArray*) select:(BOOL (^) (id))block { 46 | NSMutableArray* ret = [[NSMutableArray alloc] init]; 47 | for (id obj in self) { 48 | if (block(obj)) { 49 | [ret addObject:obj]; 50 | } 51 | } 52 | return [ret autorelease]; 53 | } 54 | 55 | 56 | - (NSArray*) reject:(BOOL (^) (id))block { 57 | NSMutableArray* ret = [[NSMutableArray alloc] init]; 58 | for (id obj in self) { 59 | if (!block(obj)) { 60 | [ret addObject:obj]; 61 | } 62 | } 63 | return [ret autorelease]; 64 | } 65 | 66 | - (void) reverseEach:(void (^) (id))block { 67 | for (int i = [self count] - 1; i >= 0; i --) { 68 | block([self objectAtIndex:i]); 69 | } 70 | } 71 | 72 | #endif 73 | 74 | @end 75 | -------------------------------------------------------------------------------- /Kiwi/KWItNode.m: -------------------------------------------------------------------------------- 1 | // 2 | // Licensed under the terms in License.txt 3 | // 4 | // Copyright 2010 Allen Ding. All rights reserved. 5 | // 6 | 7 | #import "KWItNode.h" 8 | #import "KWExampleNodeVisitor.h" 9 | #import "KWExample.h" 10 | #import "KWVerifying.h" 11 | #import "KWContextNode.h" 12 | 13 | @interface KWItNode () 14 | 15 | @property (nonatomic, retain, readwrite) KWContextNode *context; 16 | 17 | @end 18 | 19 | @implementation KWItNode 20 | 21 | @synthesize context = _context; 22 | @synthesize example; 23 | 24 | #pragma mark - 25 | #pragma mark Initializing 26 | 27 | + (id)itNodeWithCallSite:(KWCallSite *)aCallSite 28 | description:(NSString *)aDescription 29 | context:(KWContextNode *)context 30 | block:(KWVoidBlock)aBlock; 31 | { 32 | KWItNode *itNode = [[self alloc] initWithCallSite:aCallSite description:aDescription block:aBlock]; 33 | itNode.context = context; 34 | return [itNode autorelease]; 35 | } 36 | 37 | #pragma mark - 38 | #pragma mark Accepting Visitors 39 | 40 | - (void)acceptExampleNodeVisitor:(id)aVisitor { 41 | [aVisitor visitItNode:self]; 42 | } 43 | 44 | #pragma mark - 45 | #pragma mark Runtime Description support 46 | 47 | - (NSString *)description 48 | { 49 | NSString *description = [super description]; 50 | if (description == nil) { 51 | description = [self.example generateDescriptionForAnonymousItNode]; 52 | } 53 | return description; 54 | } 55 | 56 | #pragma mark - 57 | #pragma mark - Accessing the context stack 58 | 59 | - (NSArray *)contextStack 60 | { 61 | NSMutableArray *contextStack = [NSMutableArray array]; 62 | 63 | KWContextNode *currentContext = _context; 64 | 65 | while (currentContext) { 66 | [contextStack addObject:currentContext]; 67 | currentContext = currentContext.parentContext; 68 | } 69 | return contextStack; 70 | } 71 | 72 | @end 73 | -------------------------------------------------------------------------------- /CocoaOniguruma/oniguruma/st.h: -------------------------------------------------------------------------------- 1 | /* This is a public domain general purpose hash table package written by Peter Moore @ UCB. */ 2 | 3 | /* @(#) st.h 5.1 89/12/14 */ 4 | 5 | #ifndef ST_INCLUDED 6 | 7 | #define ST_INCLUDED 8 | 9 | typedef unsigned long st_data_t; 10 | #define ST_DATA_T_DEFINED 11 | 12 | typedef struct st_table st_table; 13 | 14 | struct st_hash_type { 15 | int (*compare)(); 16 | int (*hash)(); 17 | }; 18 | 19 | struct st_table { 20 | struct st_hash_type *type; 21 | int num_bins; 22 | int num_entries; 23 | struct st_table_entry **bins; 24 | }; 25 | 26 | #define st_is_member(table,key) st_lookup(table,key,(st_data_t *)0) 27 | 28 | enum st_retval {ST_CONTINUE, ST_STOP, ST_DELETE, ST_CHECK}; 29 | 30 | #ifndef _ 31 | # define _(args) args 32 | #endif 33 | #ifndef ANYARGS 34 | # ifdef __cplusplus 35 | # define ANYARGS ... 36 | # else 37 | # define ANYARGS 38 | # endif 39 | #endif 40 | 41 | st_table *st_init_table _((struct st_hash_type *)); 42 | st_table *st_init_table_with_size _((struct st_hash_type *, int)); 43 | st_table *st_init_numtable _((void)); 44 | st_table *st_init_numtable_with_size _((int)); 45 | st_table *st_init_strtable _((void)); 46 | st_table *st_init_strtable_with_size _((int)); 47 | int st_delete _((st_table *, st_data_t *, st_data_t *)); 48 | int st_delete_safe _((st_table *, st_data_t *, st_data_t *, st_data_t)); 49 | int st_insert _((st_table *, st_data_t, st_data_t)); 50 | int st_lookup _((st_table *, st_data_t, st_data_t *)); 51 | int st_foreach _((st_table *, int (*)(ANYARGS), st_data_t)); 52 | void st_add_direct _((st_table *, st_data_t, st_data_t)); 53 | void st_free_table _((st_table *)); 54 | void st_cleanup_safe _((st_table *, st_data_t)); 55 | st_table *st_copy _((st_table *)); 56 | 57 | #define ST_NUMCMP ((int (*)()) 0) 58 | #define ST_NUMHASH ((int (*)()) -2) 59 | 60 | #define st_numcmp ST_NUMCMP 61 | #define st_numhash ST_NUMHASH 62 | 63 | #endif /* ST_INCLUDED */ 64 | -------------------------------------------------------------------------------- /Kiwi/KWBeEmptyMatcher.m: -------------------------------------------------------------------------------- 1 | // 2 | // Licensed under the terms in License.txt 3 | // 4 | // Copyright 2010 Allen Ding. All rights reserved. 5 | // 6 | 7 | #import "KWBeEmptyMatcher.h" 8 | #import "KWFormatter.h" 9 | 10 | @interface KWBeEmptyMatcher() 11 | 12 | #pragma mark - 13 | #pragma mark Properties 14 | 15 | @property (nonatomic, readwrite) NSUInteger count; 16 | 17 | @end 18 | 19 | @implementation KWBeEmptyMatcher 20 | 21 | #pragma mark - 22 | #pragma mark Properties 23 | 24 | @synthesize count; 25 | 26 | #pragma mark - 27 | #pragma mark Getting Matcher Strings 28 | 29 | + (NSArray *)matcherStrings { 30 | return [NSArray arrayWithObject:@"beEmpty"]; 31 | } 32 | 33 | #pragma mark - 34 | #pragma mark Matching 35 | 36 | - (BOOL)evaluate { 37 | if ([self.subject respondsToSelector:@selector(count)]) { 38 | self.count = [self.subject count]; 39 | return self.count == 0; 40 | } 41 | else if ([self.subject respondsToSelector:@selector(length)]) { 42 | self.count = [self.subject length]; 43 | return self.count == 0; 44 | } 45 | 46 | [NSException raise:@"KWMatcherException" format:@"subject does not respond to -count or -length"]; 47 | return NO; 48 | } 49 | 50 | #pragma mark - 51 | #pragma mark Getting Failure Messages 52 | 53 | - (NSString *)countPhrase { 54 | if (self.count == 1) 55 | return @"1 item"; 56 | else 57 | return [NSString stringWithFormat:@"%u items", (unsigned)self.count]; 58 | } 59 | 60 | - (NSString *)failureMessageForShould { 61 | return [NSString stringWithFormat:@"expected subject to be empty, got %@", [self countPhrase]]; 62 | } 63 | 64 | - (NSString *)failureMessageForShouldNot { 65 | return @"expected subject not to be empty"; 66 | } 67 | 68 | - (NSString *)description 69 | { 70 | return @"be empty"; 71 | } 72 | 73 | #pragma mark - 74 | #pragma mark Configuring Matchers 75 | 76 | - (void)beEmpty { 77 | } 78 | 79 | @end 80 | -------------------------------------------------------------------------------- /Kiwi/KWPendingNode.m: -------------------------------------------------------------------------------- 1 | // 2 | // Licensed under the terms in License.txt 3 | // 4 | // Copyright 2010 Allen Ding. All rights reserved. 5 | // 6 | 7 | #import "KWPendingNode.h" 8 | #import "KWExampleNodeVisitor.h" 9 | #import "KWContextNode.h" 10 | 11 | @implementation KWPendingNode 12 | 13 | @synthesize context = _context; 14 | 15 | #pragma mark - 16 | #pragma mark Initializing 17 | 18 | - (id)initWithCallSite:(KWCallSite *)aCallSite context:(KWContextNode *)context description:(NSString *)aDescription { 19 | if ((self = [super init])) { 20 | callSite = [aCallSite retain]; 21 | description = [aDescription copy]; 22 | _context = [context retain]; 23 | } 24 | 25 | return self; 26 | } 27 | 28 | + (id)pendingNodeWithCallSite:(KWCallSite *)aCallSite context:(KWContextNode *)context description:(NSString *)aDescription { 29 | return [[[self alloc] initWithCallSite:aCallSite context:context description:aDescription] autorelease]; 30 | } 31 | 32 | - (void)dealloc { 33 | [_context release]; 34 | [callSite release]; 35 | [description release]; 36 | [super dealloc]; 37 | } 38 | 39 | #pragma mark - 40 | #pragma mark Getting Call Sites 41 | 42 | @synthesize callSite; 43 | 44 | #pragma mark - 45 | #pragma mark Getting Descriptions 46 | 47 | @synthesize description; 48 | 49 | #pragma mark - 50 | #pragma mark Accepting Visitors 51 | 52 | - (void)acceptExampleNodeVisitor:(id)aVisitor { 53 | [aVisitor visitPendingNode:self]; 54 | } 55 | 56 | #pragma mark - 57 | #pragma mark - Accessing the context stack 58 | 59 | - (NSArray *)contextStack 60 | { 61 | NSMutableArray *contextStack = [NSMutableArray array]; 62 | 63 | KWContextNode *currentContext = _context; 64 | 65 | while (currentContext) { 66 | [contextStack addObject:currentContext]; 67 | currentContext = currentContext.parentContext; 68 | } 69 | return contextStack; 70 | } 71 | 72 | @end 73 | -------------------------------------------------------------------------------- /Kiwi/KWHamrestMatchingAdditions.m: -------------------------------------------------------------------------------- 1 | // 2 | // NSObject+KiwiAdditions.m 3 | // Kiwi 4 | // 5 | // Created by Luke Redpath on 24/01/2011. 6 | // Copyright 2011 Allen Ding. All rights reserved. 7 | // 8 | 9 | #import "KWHamrestMatchingAdditions.h" 10 | #import "KWHCMatcher.h" 11 | 12 | @implementation NSObject (KiwiHamcrestAdditions) 13 | 14 | - (BOOL)isEqualOrMatches:(id)object 15 | { 16 | if ([self conformsToProtocol:@protocol(HCMatcher)]) { 17 | return [(id)self matches:object]; 18 | } 19 | return [self isEqual:object]; 20 | } 21 | 22 | @end 23 | 24 | @implementation NSArray (KiwiHamcrestAdditions) 25 | 26 | - (BOOL)containsObjectEqualToOrMatching:(id)object 27 | { 28 | if ([object conformsToProtocol:@protocol(HCMatcher)]) { 29 | return [self containsObjectMatching:object]; 30 | } 31 | return [self containsObject:object]; 32 | } 33 | 34 | - (BOOL)containsObjectMatching:(id)matcher 35 | { 36 | NSIndexSet *indexSet = [self indexesOfObjectsPassingTest:^(id obj, NSUInteger idx, BOOL *stop) { 37 | BOOL matches = [matcher matches:obj]; 38 | if (matches) { 39 | *stop = YES; 40 | } 41 | return matches; 42 | }]; 43 | 44 | return (indexSet.count > 0); 45 | } 46 | 47 | @end 48 | 49 | @implementation NSSet (KiwiHamcrestAdditions) 50 | 51 | - (BOOL)containsObjectEqualToOrMatching:(id)object 52 | { 53 | if ([object conformsToProtocol:@protocol(HCMatcher)]) { 54 | return [[self allObjects] containsObjectMatching:object]; 55 | } 56 | return [self containsObject:object]; 57 | } 58 | 59 | @end 60 | 61 | @implementation NSOrderedSet (KiwiHamcrestAdditions) 62 | 63 | - (BOOL)containsObjectEqualToOrMatching:(id)object 64 | { 65 | if ([object conformsToProtocol:@protocol(HCMatcher)]) { 66 | return [[self array] containsObjectMatching:object]; 67 | } 68 | return [self containsObject:object]; 69 | } 70 | 71 | @end 72 | 73 | 74 | -------------------------------------------------------------------------------- /CocoaOniguruma/OnigRegexpUtility.h: -------------------------------------------------------------------------------- 1 | // Created by Satoshi Nakagawa. 2 | // You can redistribute it and/or modify it under the new BSD license. 3 | 4 | #import 5 | #import "oniguruma.h" 6 | #import "OnigRegexp.h" 7 | 8 | 9 | @class OnigRegexp; 10 | @class OnigResult; 11 | 12 | 13 | @interface NSString (OnigRegexpUtility) 14 | 15 | // pattern is OnigRegexp or NSString 16 | 17 | - (NSRange)rangeOfRegexp:(id)pattern; 18 | 19 | // based on ruby's split 20 | 21 | - (NSArray*)split; 22 | - (NSArray*)splitByRegexp:(id)pattern; 23 | - (NSArray*)splitByRegexp:(id)pattern limit:(int)limit; 24 | 25 | // based on ruby's gsub 26 | 27 | - (NSString*)replaceByRegexp:(id)pattern with:(NSString*)string; 28 | - (NSString*)replaceAllByRegexp:(id)pattern with:(NSString*)string; 29 | 30 | - (NSString*)replaceByRegexp:(id)pattern withCallback:(id)object selector:(SEL)sel; 31 | - (NSString*)replaceAllByRegexp:(id)pattern withCallback:(id)object selector:(SEL)sel; 32 | 33 | #if defined(NS_BLOCKS_AVAILABLE) 34 | - (NSString*)replaceByRegexp:(id)pattern withBlock:(NSString* (^)(OnigResult*))block; 35 | - (NSString*)replaceAllByRegexp:(id)pattern withBlock:(NSString* (^)(OnigResult*))block; 36 | #endif 37 | 38 | @end 39 | 40 | 41 | @interface NSMutableString (OnigRegexpUtility) 42 | 43 | // pattern is OnigRegexp or NSString 44 | 45 | // based on ruby's gsub 46 | 47 | - (NSMutableString*)replaceByRegexp:(id)pattern with:(NSString*)string; 48 | - (NSMutableString*)replaceAllByRegexp:(id)pattern with:(NSString*)string; 49 | 50 | - (NSMutableString*)replaceByRegexp:(id)pattern withCallback:(id)object selector:(SEL)sel; 51 | - (NSMutableString*)replaceAllByRegexp:(id)pattern withCallback:(id)object selector:(SEL)sel; 52 | 53 | #if defined(NS_BLOCKS_AVAILABLE) 54 | - (NSMutableString*)replaceByRegexp:(id)pattern withBlock:(NSString* (^)(OnigResult*))block; 55 | - (NSMutableString*)replaceAllByRegexp:(id)pattern withBlock:(NSString* (^)(OnigResult*))block; 56 | #endif 57 | @end 58 | -------------------------------------------------------------------------------- /Kiwi/KWMatchers.m: -------------------------------------------------------------------------------- 1 | // 2 | // KWMatchers.m 3 | // Kiwi 4 | // 5 | // Created by Luke Redpath on 17/06/2011. 6 | // Copyright 2011 Allen Ding. All rights reserved. 7 | // 8 | 9 | #import "KWMatchers.h" 10 | #import "KWUserDefinedMatcher.h" 11 | 12 | @implementation KWMatchers 13 | 14 | #pragma mark - 15 | #pragma mark Singleton implementation 16 | 17 | static id sharedMatchers = nil; 18 | 19 | + (void)initialize { 20 | if (self == [KWMatchers class]) { 21 | sharedMatchers = [[self alloc] init]; 22 | } 23 | } 24 | 25 | + (id)matchers { 26 | return sharedMatchers; 27 | } 28 | 29 | - (id)init { 30 | if ((self = [super init])) { 31 | userDefinedMatchers = [[NSMutableDictionary alloc] init]; 32 | } 33 | return self; 34 | } 35 | 36 | #pragma mark - 37 | #pragma mark Defining Matchers 38 | 39 | + (void)defineMatcher:(NSString *)selectorString as:(KWMatchersBuildingBlock)block { 40 | [[self matchers] defineMatcher:selectorString as:block]; 41 | } 42 | 43 | - (void)defineMatcher:(NSString *)selectorString as:(KWMatchersBuildingBlock)block { 44 | KWUserDefinedMatcherBuilder *builder = [KWUserDefinedMatcherBuilder builderForSelector:NSSelectorFromString(selectorString)]; 45 | block(builder); 46 | [userDefinedMatchers setObject:builder forKey:builder.key]; 47 | } 48 | 49 | - (void)addUserDefinedMatcherBuilder:(KWUserDefinedMatcherBuilder *)builder { 50 | [userDefinedMatchers setObject:builder forKey:builder.key]; 51 | } 52 | 53 | #pragma mark - 54 | #pragma mark Building Matchers 55 | 56 | - (KWUserDefinedMatcher *)matcherForSelector:(SEL)selector subject:(id)subject { 57 | KWUserDefinedMatcherBuilder *builder = [userDefinedMatchers objectForKey:NSStringFromSelector(selector)]; 58 | 59 | if (builder == nil) 60 | return nil; 61 | 62 | return [builder buildMatcherWithSubject:subject]; 63 | } 64 | 65 | 66 | @end 67 | 68 | void KWDefineMatchers(NSString *selectorString, KWMatchersBuildingBlock block) 69 | { 70 | [KWMatchers defineMatcher:selectorString as:block]; 71 | } 72 | 73 | -------------------------------------------------------------------------------- /Kiwi/KWBeIdenticalToMatcher.m: -------------------------------------------------------------------------------- 1 | // 2 | // Licensed under the terms in License.txt 3 | // 4 | // Copyright 2010 Allen Ding. All rights reserved. 5 | // 6 | 7 | #import "KWBeIdenticalToMatcher.h" 8 | #import "KWFormatter.h" 9 | 10 | @interface KWBeIdenticalToMatcher() 11 | 12 | #pragma mark - 13 | #pragma mark Properties 14 | 15 | @property (nonatomic, readwrite, retain) id otherSubject; 16 | 17 | @end 18 | 19 | @implementation KWBeIdenticalToMatcher 20 | 21 | #pragma mark - 22 | #pragma mark Initializing 23 | 24 | - (void)dealloc { 25 | [otherSubject release]; 26 | [super dealloc]; 27 | } 28 | 29 | #pragma mark - 30 | #pragma mark Properties 31 | 32 | @synthesize otherSubject; 33 | 34 | #pragma mark - 35 | #pragma mark Getting Matcher Strings 36 | 37 | + (NSArray *)matcherStrings { 38 | return [NSArray arrayWithObject:@"beIdenticalTo:"]; 39 | } 40 | 41 | #pragma mark - 42 | #pragma mark Matching 43 | 44 | - (BOOL)evaluate { 45 | return self.subject == self.otherSubject; 46 | } 47 | 48 | #pragma mark - 49 | #pragma mark Getting Failure Messages 50 | 51 | - (NSString *)failureMessageForShould { 52 | return [NSString stringWithFormat:@"expected subject to be identical to %@ (%p), got %@ (%p)", 53 | [KWFormatter formatObject:self.otherSubject], 54 | self.otherSubject, 55 | [KWFormatter formatObject:self.subject], 56 | self.subject]; 57 | } 58 | 59 | - (NSString *)failureMessageForShouldNot { 60 | return [NSString stringWithFormat:@"expected subject not to be identical to %@ (%p)", 61 | [KWFormatter formatObject:self.otherSubject], 62 | self.otherSubject]; 63 | } 64 | 65 | - (NSString *)description 66 | { 67 | return [NSString stringWithFormat:@"be identical to %@", self.otherSubject]; 68 | } 69 | 70 | #pragma mark - 71 | #pragma mark Configuring Matchers 72 | 73 | - (void)beIdenticalTo:(id)anObject { 74 | self.otherSubject = anObject; 75 | } 76 | 77 | @end 78 | -------------------------------------------------------------------------------- /Kiwi/KWUserDefinedMatcher.h: -------------------------------------------------------------------------------- 1 | // 2 | // KWUserDefinedMatcher.h 3 | // Kiwi 4 | // 5 | // Created by Luke Redpath on 16/06/2011. 6 | // Copyright 2011 Allen Ding. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "KWMatcher.h" 11 | 12 | typedef BOOL (^KWUserDefinedMatcherBlock)(); 13 | 14 | @interface KWUserDefinedMatcher : KWMatcher 15 | { 16 | KWUserDefinedMatcherBlock matcherBlock; 17 | SEL selector; 18 | NSInvocation *invocation; 19 | NSString *failureMessageForShould; 20 | NSString *failureMessageForShouldNot; 21 | } 22 | @property (nonatomic, assign) SEL selector; 23 | @property (nonatomic, copy) NSString *failureMessageForShould; 24 | @property (nonatomic, copy) NSString *failureMessageForShouldNot; 25 | @property (nonatomic, assign) KWUserDefinedMatcherBlock matcherBlock; 26 | @property (nonatomic, copy) NSString *description; 27 | 28 | + (id)matcherWithSubject:(id)aSubject block:(KWUserDefinedMatcherBlock)aBlock; 29 | - (id)initWithSubject:(id)aSubject block:(KWUserDefinedMatcherBlock)aBlock; 30 | - (void)setSubject:(id)aSubject; 31 | @end 32 | 33 | #pragma mark - 34 | 35 | typedef NSString * (^KWUserDefinedMatcherMessageBlock)(id); 36 | 37 | @interface KWUserDefinedMatcherBuilder : NSObject 38 | { 39 | KWUserDefinedMatcher *matcher; 40 | KWUserDefinedMatcherMessageBlock failureMessageForShouldBlock; 41 | KWUserDefinedMatcherMessageBlock failureMessageForShouldNotBlock; 42 | NSString *description; 43 | } 44 | @property (nonatomic, readonly) NSString *key; 45 | 46 | + (id)builder; 47 | + (id)builderForSelector:(SEL)aSelector; 48 | - (id)initWithSelector:(SEL)aSelector; 49 | 50 | #pragma mark - 51 | #pragma mark Configuring The Matcher 52 | 53 | - (void)match:(KWUserDefinedMatcherBlock)block; 54 | - (void)failureMessageForShould:(KWUserDefinedMatcherMessageBlock)block; 55 | - (void)failureMessageForShouldNot:(KWUserDefinedMatcherMessageBlock)block; 56 | - (void)description:(NSString *)description; 57 | 58 | #pragma mark - 59 | #pragma mark Buiding The Matcher 60 | 61 | - (KWUserDefinedMatcher *)buildMatcherWithSubject:(id)subject; 62 | @end 63 | -------------------------------------------------------------------------------- /Kiwi/KWEqualMatcher.m: -------------------------------------------------------------------------------- 1 | // 2 | // Licensed under the terms in License.txt 3 | // 4 | // Copyright 2010 Allen Ding. All rights reserved. 5 | // 6 | 7 | #import "KWEqualMatcher.h" 8 | #import "KWFormatter.h" 9 | #import "KWValue.h" 10 | 11 | @interface KWEqualMatcher() 12 | 13 | #pragma mark - 14 | #pragma mark Properties 15 | 16 | @property (nonatomic, readwrite, retain) id otherSubject; 17 | 18 | @end 19 | 20 | @implementation KWEqualMatcher 21 | 22 | #pragma mark - 23 | #pragma mark Initializing 24 | 25 | - (void)dealloc { 26 | [otherSubject release]; 27 | [super dealloc]; 28 | } 29 | 30 | #pragma mark - 31 | #pragma mark Properties 32 | 33 | @synthesize otherSubject; 34 | 35 | #pragma mark - 36 | #pragma mark Getting Matcher Strings 37 | 38 | + (NSArray *)matcherStrings { 39 | return [NSArray arrayWithObjects:@"equal:", nil]; 40 | } 41 | 42 | #pragma mark - 43 | #pragma mark Matching 44 | 45 | - (BOOL)evaluate { 46 | /** handle this as a special case; KWValue supports NSNumber equality but not vice-versa **/ 47 | if ([self.subject isKindOfClass:[NSNumber class]] && [self.otherSubject isKindOfClass:[KWValue class]]) { 48 | return [self.otherSubject isEqual:self.subject]; 49 | } 50 | return [self.subject isEqual:self.otherSubject]; 51 | } 52 | 53 | #pragma mark - 54 | #pragma mark Getting Failure Messages 55 | 56 | - (NSString *)failureMessageForShould { 57 | return [NSString stringWithFormat:@"expected subject to equal %@, got %@", 58 | [KWFormatter formatObject:self.otherSubject], 59 | [KWFormatter formatObject:self.subject]]; 60 | } 61 | 62 | - (NSString *)failureMessageForShouldNot { 63 | return [NSString stringWithFormat:@"expected subject not to equal %@", 64 | [KWFormatter formatObject:self.otherSubject]]; 65 | } 66 | 67 | - (NSString *)description 68 | { 69 | return [NSString stringWithFormat:@"equal %@", [KWFormatter formatObject:self.otherSubject]]; 70 | } 71 | 72 | #pragma mark - 73 | #pragma mark Configuring Matchers 74 | 75 | - (void)equal:(id)anObject { 76 | self.otherSubject = anObject; 77 | } 78 | 79 | @end 80 | -------------------------------------------------------------------------------- /Kiwi/KWFailure.m: -------------------------------------------------------------------------------- 1 | // 2 | // Licensed under the terms in License.txt 3 | // 4 | // Copyright 2010 Allen Ding. All rights reserved. 5 | // 6 | 7 | #import "KWFailure.h" 8 | #import 9 | #import "KWCallSite.h" 10 | 11 | @implementation KWFailure 12 | 13 | #pragma mark - 14 | #pragma mark Initializing 15 | 16 | - (id)initWithCallSite:(KWCallSite *)aCallSite message:(NSString *)aMessage { 17 | if ((self = [super init])) { 18 | callSite = [aCallSite retain]; 19 | message = [aMessage copy]; 20 | } 21 | 22 | return self; 23 | } 24 | 25 | - (id)initWithCallSite:(KWCallSite *)aCallSite format:(NSString *)format, ... { 26 | va_list argumentList; 27 | va_start(argumentList, format); 28 | NSString *aMessage = [[[NSString alloc] initWithFormat:format arguments:argumentList] autorelease]; 29 | return [self initWithCallSite:aCallSite message:aMessage]; 30 | } 31 | 32 | + (id)failureWithCallSite:(KWCallSite *)aCallSite message:(NSString *)aMessage { 33 | return [[[self alloc] initWithCallSite:aCallSite message:aMessage] autorelease]; 34 | } 35 | 36 | + (id)failureWithCallSite:(KWCallSite *)aCallSite format:(NSString *)format, ... { 37 | va_list argumentList; 38 | va_start(argumentList, format); 39 | NSString *message = [[[NSString alloc] initWithFormat:format arguments:argumentList] autorelease]; 40 | return [self failureWithCallSite:aCallSite message:message]; 41 | } 42 | 43 | - (void)dealloc { 44 | [callSite release]; 45 | [message release]; 46 | [super dealloc]; 47 | } 48 | 49 | #pragma mark - 50 | #pragma mark Properties 51 | 52 | @synthesize message; 53 | @synthesize callSite; 54 | 55 | #pragma mark - 56 | #pragma mark Getting Exception Representations 57 | 58 | - (NSException *)exceptionValue { 59 | NSNumber *lineNumber = [NSNumber numberWithUnsignedInteger:self.callSite.lineNumber]; 60 | NSDictionary *userInfo = [NSDictionary dictionaryWithObjectsAndKeys:self.callSite.filename, SenTestFilenameKey, 61 | lineNumber, SenTestLineNumberKey, nil]; 62 | return [NSException exceptionWithName:@"KWFailureException" reason:message userInfo:userInfo]; 63 | } 64 | 65 | @end 66 | -------------------------------------------------------------------------------- /Kiwi/KWExampleSuite.m: -------------------------------------------------------------------------------- 1 | // 2 | // KWExampleSuite.m 3 | // Kiwi 4 | // 5 | // Created by Luke Redpath on 17/10/2011. 6 | // Copyright (c) 2011 Allen Ding. All rights reserved. 7 | // 8 | 9 | #import "KWExampleSuite.h" 10 | #import "KWExample.h" 11 | #import "KWStringUtilities.h" 12 | #import "KWBeforeAllNode.h" 13 | #import "KWAfterAllNode.h" 14 | #import "NSMethodSignature+KiwiAdditions.h" 15 | #import 16 | 17 | #define kKWINVOCATION_EXAMPLE_GROUP_KEY @"__KWExampleGroupKey" 18 | 19 | @implementation KWExampleSuite 20 | 21 | - (id)initWithRootNode:(KWContextNode *)contextNode 22 | { 23 | if ((self = [super init])) { 24 | rootNode = [contextNode retain]; 25 | examples = [[NSMutableArray alloc] init]; 26 | } 27 | return self; 28 | } 29 | 30 | - (void)dealloc 31 | { 32 | [examples release]; 33 | [rootNode release]; 34 | [super dealloc]; 35 | } 36 | 37 | - (void)addExample:(KWExample *)example 38 | { 39 | [examples addObject:example]; 40 | [example setSuite:self]; 41 | } 42 | 43 | - (void)markLastExampleAsLastInContext:(KWContextNode *)context 44 | { 45 | [[examples objectAtIndex:examples.count-1] setLastInContext:context]; 46 | } 47 | 48 | - (NSArray *)invocationsForTestCase; 49 | { 50 | NSMutableArray *invocations = [NSMutableArray array]; 51 | 52 | // Add a single dummy invocation for each example group 53 | 54 | for (KWExample *exampleGroup in examples) { 55 | NSMethodSignature *methodSignature = [NSMethodSignature signatureWithObjCTypes:[KWEncodingForVoidMethod() UTF8String]]; 56 | NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:methodSignature]; 57 | [invocations addObject:invocation]; 58 | [invocation kw_setExample:exampleGroup]; 59 | } 60 | 61 | return invocations; 62 | } 63 | 64 | @end 65 | 66 | #pragma mark - 67 | 68 | // because SenTest will modify the invocation target, we'll have to store 69 | // another reference to the example group so we can retrieve it later 70 | 71 | @implementation NSInvocation (KWExampleGroup) 72 | 73 | - (void)kw_setExample:(KWExample *)exampleGroup 74 | { 75 | objc_setAssociatedObject(self, kKWINVOCATION_EXAMPLE_GROUP_KEY, exampleGroup, OBJC_ASSOCIATION_RETAIN); 76 | } 77 | 78 | - (KWExample *)kw_example 79 | { 80 | return objc_getAssociatedObject(self, kKWINVOCATION_EXAMPLE_GROUP_KEY); 81 | } 82 | 83 | @end 84 | 85 | -------------------------------------------------------------------------------- /CocoaOniguruma/oniguruma/regversion.c: -------------------------------------------------------------------------------- 1 | /********************************************************************** 2 | regversion.c - Oniguruma (regular expression library) 3 | **********************************************************************/ 4 | /*- 5 | * Copyright (c) 2002-2008 K.Kosako 6 | * All rights reserved. 7 | * 8 | * Redistribution and use in source and binary forms, with or without 9 | * modification, are permitted provided that the following conditions 10 | * are met: 11 | * 1. Redistributions of source code must retain the above copyright 12 | * notice, this list of conditions and the following disclaimer. 13 | * 2. Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in the 15 | * documentation and/or other materials provided with the distribution. 16 | * 17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 18 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 21 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 | * SUCH DAMAGE. 28 | */ 29 | 30 | #include "config.h" 31 | #include "oniguruma.h" 32 | #include 33 | 34 | extern const char* 35 | onig_version(void) 36 | { 37 | static char s[12]; 38 | 39 | sprintf(s, "%d.%d.%d", 40 | ONIGURUMA_VERSION_MAJOR, 41 | ONIGURUMA_VERSION_MINOR, 42 | ONIGURUMA_VERSION_TEENY); 43 | return s; 44 | } 45 | 46 | extern const char* 47 | onig_copyright(void) 48 | { 49 | static char s[58]; 50 | 51 | sprintf(s, "Oniguruma %d.%d.%d : Copyright (C) 2002-2008 K.Kosako", 52 | ONIGURUMA_VERSION_MAJOR, 53 | ONIGURUMA_VERSION_MINOR, 54 | ONIGURUMA_VERSION_TEENY); 55 | return s; 56 | } 57 | -------------------------------------------------------------------------------- /Kiwi/KWContextNode.h: -------------------------------------------------------------------------------- 1 | // 2 | // Licensed under the terms in License.txt 3 | // 4 | // Copyright 2010 Allen Ding. All rights reserved. 5 | // 6 | 7 | #import "KiwiConfiguration.h" 8 | #import "KWExampleNode.h" 9 | 10 | @class KWAfterAllNode; 11 | @class KWAfterEachNode; 12 | @class KWBeforeAllNode; 13 | @class KWBeforeEachNode; 14 | @class KWCallSite; 15 | @class KWItNode; 16 | @class KWPendingNode; 17 | @class KWRegisterMatchersNode; 18 | @class KWExample; 19 | 20 | @interface KWContextNode : NSObject { 21 | @private 22 | KWContextNode *parentContext; 23 | KWCallSite *callSite; 24 | NSString *description; 25 | KWRegisterMatchersNode *registerMatchersNode; 26 | KWBeforeAllNode *beforeAllNode; 27 | KWAfterAllNode *afterAllNode; 28 | KWBeforeEachNode *beforeEachNode; 29 | KWAfterEachNode *afterEachNode; 30 | NSMutableArray *nodes; 31 | BOOL performedExampleCount; 32 | } 33 | 34 | #pragma mark - 35 | #pragma mark Initializing 36 | 37 | - (id)initWithCallSite:(KWCallSite *)aCallSite parentContext:(KWContextNode *)node description:(NSString *)aDescription; 38 | 39 | + (id)contextNodeWithCallSite:(KWCallSite *)aCallSite parentContext:(KWContextNode *)contextNode description:(NSString *)aDescription; 40 | 41 | #pragma mark - 42 | #pragma mark Getting Call Sites 43 | 44 | @property (nonatomic, readonly) KWCallSite *callSite; 45 | 46 | #pragma mark - 47 | #pragma mark Getting Descriptions 48 | 49 | @property (nonatomic, readonly) NSString *description; 50 | 51 | #pragma mark - 52 | #pragma mark Managing Nodes 53 | 54 | @property (nonatomic, readwrite, retain) KWRegisterMatchersNode *registerMatchersNode; 55 | @property (nonatomic, readwrite, retain) KWBeforeAllNode *beforeAllNode; 56 | @property (nonatomic, readwrite, retain) KWAfterAllNode *afterAllNode; 57 | @property (nonatomic, readwrite, retain) KWBeforeEachNode *beforeEachNode; 58 | @property (nonatomic, readwrite, retain) KWAfterEachNode *afterEachNode; 59 | @property (nonatomic, readonly) KWContextNode *parentContext; 60 | @property (nonatomic, readonly) NSArray *nodes; 61 | 62 | - (void)addContextNode:(KWContextNode *)aNode; 63 | - (void)addItNode:(KWItNode *)aNode; 64 | - (void)addPendingNode:(KWPendingNode *)aNode; 65 | 66 | - (void)performExample:(KWExample *)example withBlock:(void (^)(void))exampleBlock; 67 | 68 | #pragma mark - 69 | #pragma mark Accepting Visitors 70 | 71 | - (void)acceptExampleNodeVisitor:(id)aVisitor; 72 | 73 | @end 74 | -------------------------------------------------------------------------------- /Kiwi/KWExistVerifier.m: -------------------------------------------------------------------------------- 1 | // 2 | // Licensed under the terms in License.txt 3 | // 4 | // Copyright 2010 Allen Ding. All rights reserved. 5 | // 6 | 7 | #import "KWExistVerifier.h" 8 | #import "KWFailure.h" 9 | #import "KWFormatter.h" 10 | #import "KWReporting.h" 11 | 12 | @interface KWExistVerifier() 13 | 14 | #pragma mark - 15 | #pragma mark Properties 16 | 17 | @property (nonatomic, readonly) KWExpectationType expectationType; 18 | @property (nonatomic, readonly) KWCallSite *callSite; 19 | @property (nonatomic, readonly) id reporter; 20 | 21 | @end 22 | 23 | @implementation KWExistVerifier 24 | 25 | #pragma mark - 26 | #pragma mark Initializing 27 | 28 | - (id)initWithExpectationType:(KWExpectationType)anExpectationType callSite:(KWCallSite *)aCallSite reporter:(id)aReporter { 29 | if ((self = [super init])) { 30 | expectationType = anExpectationType; 31 | callSite = [aCallSite retain]; 32 | reporter = aReporter; 33 | } 34 | 35 | return self; 36 | } 37 | 38 | + (id)existVerifierWithExpectationType:(KWExpectationType)anExpectationType callSite:(KWCallSite *)aCallSite reporter:(id)aReporter { 39 | return [[[self alloc] initWithExpectationType:anExpectationType callSite:aCallSite reporter:aReporter] autorelease]; 40 | } 41 | 42 | - (void)dealloc { 43 | [callSite release]; 44 | [subject release]; 45 | [super dealloc]; 46 | } 47 | 48 | - (NSString *)descriptionForAnonymousItNode 49 | { 50 | if (self.expectationType == KWExpectationTypeShould) { 51 | return @"should exist"; 52 | } 53 | return @"should not exist"; 54 | } 55 | 56 | #pragma mark - 57 | #pragma mark Properties 58 | 59 | @synthesize expectationType; 60 | @synthesize callSite; 61 | @synthesize reporter; 62 | @synthesize subject; 63 | 64 | #pragma mark - 65 | #pragma mark Ending Examples 66 | 67 | - (void)exampleWillEnd { 68 | if (self.expectationType == KWExpectationTypeShould && self.subject == nil) { 69 | KWFailure *failure = [KWFailure failureWithCallSite:self.callSite message:@"expected subject not to be nil"]; 70 | [self.reporter reportFailure:failure]; 71 | } else if (self.expectationType == KWExpectationTypeShouldNot && self.subject != nil) { 72 | KWFailure *failure = [KWFailure failureWithCallSite:self.callSite format:@"expected subject to be nil, got %@", 73 | [KWFormatter formatObject:self.subject]]; 74 | [self.reporter reportFailure:failure]; 75 | } 76 | } 77 | 78 | @end 79 | -------------------------------------------------------------------------------- /Kiwi/KWMatcher.m: -------------------------------------------------------------------------------- 1 | // 2 | // Licensed under the terms in License.txt 3 | // 4 | // Copyright 2010 Allen Ding. All rights reserved. 5 | // 6 | 7 | #import "KWMatcher.h" 8 | #import "KWFormatter.h" 9 | #import "KWFutureObject.h" 10 | 11 | @implementation KWMatcher 12 | 13 | #pragma mark - 14 | #pragma mark Initializing 15 | 16 | - (id)initWithSubject:(id)anObject { 17 | if ((self = [super init])) { 18 | subject = [anObject retain]; 19 | } 20 | 21 | return self; 22 | } 23 | 24 | + (id)matcherWithSubject:(id)anObject { 25 | return [[[self alloc] initWithSubject:anObject] autorelease]; 26 | } 27 | 28 | - (void)dealloc { 29 | [subject release]; 30 | [super dealloc]; 31 | } 32 | 33 | #pragma mark - 34 | #pragma mark Properties 35 | 36 | @synthesize subject; 37 | 38 | - (id)subject 39 | { 40 | if ([subject isKindOfClass:[KWFutureObject class]]) { 41 | return [(KWFutureObject *)subject object]; 42 | } 43 | return subject; 44 | } 45 | 46 | #pragma mark - 47 | #pragma mark Getting Matcher Strings 48 | 49 | + (NSArray *)matcherStrings { 50 | return nil; 51 | } 52 | 53 | #pragma mark - 54 | #pragma mark Getting Matcher Compatability 55 | 56 | + (BOOL)canMatchSubject:(id)anObject { 57 | return YES; 58 | } 59 | 60 | #pragma mark - 61 | #pragma mark Matching 62 | 63 | - (BOOL)evaluate { 64 | [NSException raise:NSInternalInconsistencyException format:@"%@ must override -evaluate", 65 | [KWFormatter formatObject:[self class]]]; 66 | return NO; 67 | } 68 | 69 | #pragma mark - 70 | #pragma mark Getting Failure Messages 71 | 72 | - (NSString *)failureMessageForShould { 73 | return @"subject did not meet expectation"; 74 | } 75 | 76 | - (NSString *)failureMessageForShouldNot { 77 | NSString *failureMessageForShould = [self failureMessageForShould]; 78 | NSRange markerRange = [failureMessageForShould rangeOfString:@" to "]; 79 | 80 | if (markerRange.location == NSNotFound) 81 | return @"subject did not meet expectation"; 82 | 83 | NSRange replacementRange = NSMakeRange(0, markerRange.location + markerRange.length); 84 | NSString *message = [failureMessageForShould stringByReplacingOccurrencesOfString:@" to " 85 | withString:@" not to " 86 | options:0 87 | range:replacementRange]; 88 | return message; 89 | } 90 | 91 | @end 92 | -------------------------------------------------------------------------------- /Kiwi/KWBeBetweenMatcher.m: -------------------------------------------------------------------------------- 1 | // 2 | // Licensed under the terms in License.txt 3 | // 4 | // Copyright 2010 Allen Ding. All rights reserved. 5 | // 6 | 7 | #import "KWBeBetweenMatcher.h" 8 | #import "KWFormatter.h" 9 | 10 | @interface KWBeBetweenMatcher() 11 | 12 | #pragma mark - 13 | #pragma mark Properties 14 | 15 | @property (nonatomic, readwrite, retain) id lowerEndpoint; 16 | @property (nonatomic, readwrite, retain) id upperEndpoint; 17 | 18 | @end 19 | 20 | @implementation KWBeBetweenMatcher 21 | 22 | #pragma mark - 23 | #pragma mark Initializing 24 | 25 | - (void)dealloc { 26 | [lowerEndpoint release]; 27 | [upperEndpoint release]; 28 | [super dealloc]; 29 | } 30 | 31 | #pragma mark - 32 | #pragma mark Properties 33 | 34 | @synthesize lowerEndpoint; 35 | @synthesize upperEndpoint; 36 | 37 | #pragma mark - 38 | #pragma mark Getting Matcher Strings 39 | 40 | + (NSArray *)matcherStrings { 41 | return [NSArray arrayWithObjects:@"beBetween:and:", @"beInTheIntervalFrom:to:", nil]; 42 | } 43 | 44 | #pragma mark - 45 | #pragma mark Matching 46 | 47 | - (BOOL)evaluate { 48 | if (![self.subject respondsToSelector:@selector(compare:)]) 49 | [NSException raise:@"KWMatcherException" format:@"subject does not respond to -compare:"]; 50 | 51 | NSComparisonResult lowerResult = [self.subject compare:self.lowerEndpoint]; 52 | NSComparisonResult upperResult = [self.subject compare:self.upperEndpoint]; 53 | return (lowerResult == NSOrderedDescending || lowerResult == NSOrderedSame) && 54 | (upperResult == NSOrderedAscending || upperResult == NSOrderedSame); 55 | } 56 | 57 | #pragma mark - 58 | #pragma mark Getting Failure Messages 59 | 60 | - (NSString *)failureMessageForShould { 61 | return [NSString stringWithFormat:@"expected subject to be in the interval [%@, %@], got %@", 62 | [KWFormatter formatObject:self.lowerEndpoint], 63 | [KWFormatter formatObject:self.upperEndpoint], 64 | [KWFormatter formatObject:self.subject]]; 65 | } 66 | 67 | - (NSString *)description 68 | { 69 | return [NSString stringWithFormat:@"be between %@ and %@", self.lowerEndpoint, self.upperEndpoint]; 70 | } 71 | 72 | #pragma mark - 73 | #pragma mark Configuring Matchers 74 | 75 | - (void)beBetween:(id)aLowerEndpoint and:(id)anUpperEndpoint { 76 | [self beInTheIntervalFrom:aLowerEndpoint to:anUpperEndpoint]; 77 | } 78 | 79 | - (void)beInTheIntervalFrom:(id)aLowerEndpoint to:(id)anUpperEndpoint { 80 | self.lowerEndpoint = aLowerEndpoint; 81 | self.upperEndpoint = anUpperEndpoint; 82 | } 83 | 84 | @end 85 | -------------------------------------------------------------------------------- /CocoaOniguruma/oniguruma/enc/ascii.c: -------------------------------------------------------------------------------- 1 | /********************************************************************** 2 | ascii.c - Oniguruma (regular expression library) 3 | **********************************************************************/ 4 | /*- 5 | * Copyright (c) 2002-2006 K.Kosako 6 | * All rights reserved. 7 | * 8 | * Redistribution and use in source and binary forms, with or without 9 | * modification, are permitted provided that the following conditions 10 | * are met: 11 | * 1. Redistributions of source code must retain the above copyright 12 | * notice, this list of conditions and the following disclaimer. 13 | * 2. Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in the 15 | * documentation and/or other materials provided with the distribution. 16 | * 17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 18 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 21 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 | * SUCH DAMAGE. 28 | */ 29 | 30 | #include "regenc.h" 31 | 32 | static int 33 | ascii_is_code_ctype(OnigCodePoint code, unsigned int ctype) 34 | { 35 | if (code < 128) 36 | return ONIGENC_IS_ASCII_CODE_CTYPE(code, ctype); 37 | else 38 | return FALSE; 39 | } 40 | 41 | OnigEncodingType OnigEncodingASCII = { 42 | onigenc_single_byte_mbc_enc_len, 43 | "US-ASCII", /* name */ 44 | 1, /* max byte length */ 45 | 1, /* min byte length */ 46 | onigenc_is_mbc_newline_0x0a, 47 | onigenc_single_byte_mbc_to_code, 48 | onigenc_single_byte_code_to_mbclen, 49 | onigenc_single_byte_code_to_mbc, 50 | onigenc_ascii_mbc_case_fold, 51 | onigenc_ascii_apply_all_case_fold, 52 | onigenc_ascii_get_case_fold_codes_by_str, 53 | onigenc_minimum_property_name_to_ctype, 54 | ascii_is_code_ctype, 55 | onigenc_not_support_get_ctype_code_range, 56 | onigenc_single_byte_left_adjust_char_head, 57 | onigenc_always_true_is_allowed_reverse_match 58 | }; 59 | -------------------------------------------------------------------------------- /CocoaOniguruma/OnigRegexp.h: -------------------------------------------------------------------------------- 1 | // Created by Satoshi Nakagawa. 2 | // You can redistribute it and/or modify it under the new BSD license. 3 | 4 | #import 5 | #import "oniguruma.h" 6 | #import "OnigRegexpUtility.h" 7 | 8 | 9 | @class OnigResult; 10 | 11 | typedef enum { 12 | OnigOptionNone = ONIG_OPTION_NONE, 13 | OnigOptionIgnorecase = ONIG_OPTION_IGNORECASE, 14 | OnigOptionExtend = ONIG_OPTION_EXTEND, 15 | OnigOptionMultiline = ONIG_OPTION_MULTILINE, 16 | OnigOptionSingleline = ONIG_OPTION_SINGLELINE, 17 | OnigOptionFindLongest = ONIG_OPTION_FIND_LONGEST, 18 | OnigOptionFindNotEmpty = ONIG_OPTION_FIND_NOT_EMPTY, 19 | OnigOptionNegateSingleLine = ONIG_OPTION_NEGATE_SINGLELINE, 20 | OnigOptionDontCaptureGroup = ONIG_OPTION_DONT_CAPTURE_GROUP, 21 | OnigOptionCaptureGroup = ONIG_OPTION_CAPTURE_GROUP, 22 | 23 | /* options (search time) */ 24 | OnigOptionNotbol = ONIG_OPTION_NOTBOL, 25 | OnigOptionNoteol = ONIG_OPTION_NOTEOL, 26 | OnigOptionPosixRegion = ONIG_OPTION_POSIX_REGION, 27 | OnigOptionMaxbit = ONIG_OPTION_MAXBIT 28 | } OnigOption; 29 | 30 | @interface OnigRegexp : NSObject 31 | { 32 | regex_t* _entity; 33 | NSString* _expression; 34 | } 35 | 36 | + (OnigRegexp*)compile:(NSString*)expression; 37 | + (OnigRegexp*)compileIgnorecase:(NSString*)expression; 38 | + (OnigRegexp*)compile:(NSString*)expression ignorecase:(BOOL)ignorecase multiline:(BOOL)multiline; 39 | + (OnigRegexp*)compile:(NSString*)expression ignorecase:(BOOL)ignorecase multiline:(BOOL)multiline extended:(BOOL)extended; 40 | + (OnigRegexp*)compile:(NSString*)expression options:(OnigOption)options; 41 | 42 | - (OnigResult*)search:(NSString*)target; 43 | - (OnigResult*)search:(NSString*)target start:(int)start; 44 | - (OnigResult*)search:(NSString*)target start:(int)start end:(int)end; 45 | - (OnigResult*)search:(NSString*)target range:(NSRange)range; 46 | 47 | - (OnigResult*)match:(NSString*)target; 48 | - (OnigResult*)match:(NSString*)target start:(int)start; 49 | 50 | - (NSString*)expression; 51 | 52 | @end 53 | 54 | 55 | @interface OnigResult : NSObject 56 | { 57 | OnigRegexp* _expression; 58 | OnigRegion* _region; 59 | NSString* _target; 60 | } 61 | 62 | - (NSString*)target; 63 | 64 | - (int)count; 65 | - (NSString*)stringAt:(int)index; 66 | - (NSArray*)strings; 67 | - (NSRange)rangeAt:(int)index; 68 | - (int)locationAt:(int)index; 69 | - (int)lengthAt:(int)index; 70 | 71 | - (NSString*)body; 72 | - (NSRange)bodyRange; 73 | 74 | - (NSString*)preMatch; 75 | - (NSString*)postMatch; 76 | 77 | // named capture support 78 | - (int)indexForName:(NSString*)name; 79 | - (NSIndexSet*)indexesForName:(NSString*)name; 80 | - (NSString*)stringForName:(NSString*)name; 81 | - (NSArray*)stringsForName:(NSString*)name; 82 | 83 | @end 84 | -------------------------------------------------------------------------------- /Kiwi/KWValue.h: -------------------------------------------------------------------------------- 1 | // 2 | // Licensed under the terms in License.txt 3 | // 4 | // Copyright 2010 Allen Ding. All rights reserved. 5 | // 6 | 7 | #import "KiwiConfiguration.h" 8 | 9 | @interface KWValue : NSObject { 10 | @private 11 | const char *objCType; 12 | id value; 13 | } 14 | 15 | #pragma mark - 16 | #pragma mark Initializing 17 | 18 | - (id)initWithBytes:(const void *)bytes objCType:(const char *)anObjCType; 19 | 20 | + (id)valueWithBytes:(const void *)bytes objCType:(const char *)anObjCType; 21 | + (id)valueWithBool:(BOOL)aValue; 22 | + (id)valueWithChar:(char)aValue; 23 | + (id)valueWithDouble:(double)aValue; 24 | + (id)valueWithFloat:(float)aValue; 25 | + (id)valueWithInt:(int)aValue; 26 | + (id)valueWithInteger:(NSInteger)aValue; 27 | + (id)valueWithLong:(long)aValue; 28 | + (id)valueWithLongLong:(long long)value; 29 | + (id)valueWithShort:(short)aValue; 30 | + (id)valueWithUnsignedChar:(unsigned char)aValue; 31 | + (id)valueWithUnsignedInt:(unsigned int)aValue; 32 | + (id)valueWithUnsignedInteger:(NSUInteger)aValue; 33 | + (id)valueWithUnsignedLong:(unsigned long)aValue; 34 | + (id)valueWithUnsignedLongLong:(unsigned long long)aValue; 35 | + (id)valueWithUnsignedShort:(unsigned short)aValue; 36 | 37 | #pragma mark - 38 | #pragma mark Properties 39 | 40 | @property (nonatomic, readonly) const char *objCType; 41 | @property (nonatomic, readonly) BOOL isNumeric; 42 | 43 | #pragma mark - 44 | #pragma mark Accessing Numeric Values 45 | 46 | - (NSNumber *)numberValue; 47 | - (BOOL)boolValue; 48 | - (char)charValue; 49 | - (double)doubleValue; 50 | - (float)floatValue; 51 | - (int)intValue; 52 | - (NSInteger)integerValue; 53 | - (long)longValue; 54 | - (long long)longLongValue; 55 | - (short)shortValue; 56 | - (unsigned char)unsignedCharValue; 57 | - (unsigned int)unsignedIntValue; 58 | - (NSUInteger)unsignedIntegerValue; 59 | - (unsigned long)unsignedLongValue; 60 | - (unsigned long long)unsignedLongLongValue; 61 | - (unsigned short)unsignedShortValue; 62 | 63 | #pragma mark - 64 | #pragma mark Accessing Data 65 | 66 | - (NSData *)dataValue; 67 | - (void)getValue:(void *)buffer; 68 | 69 | #pragma mark - 70 | #pragma mark Accessing Numeric Data 71 | 72 | - (NSData *)dataForObjCType:(const char *)anObjCType; 73 | - (NSData *)boolData; 74 | - (NSData *)charData; 75 | - (NSData *)doubleData; 76 | - (NSData *)floatData; 77 | - (NSData *)intData; 78 | - (NSData *)integerData; 79 | - (NSData *)longData; 80 | - (NSData *)longLongData; 81 | - (NSData *)shortData; 82 | - (NSData *)unsignedCharData; 83 | - (NSData *)unsignedIntData; 84 | - (NSData *)unsignedIntegerData; 85 | - (NSData *)unsignedLongData; 86 | - (NSData *)unsignedLongLongData; 87 | - (NSData *)unsignedShortData; 88 | 89 | #pragma mark - 90 | #pragma mark Comparing Values 91 | 92 | - (NSComparisonResult)compare:(KWValue *)aValue; 93 | 94 | - (BOOL)isEqualToKWValue:(KWValue *)aValue; 95 | - (BOOL)isEqualToNumber:(NSNumber *)aValue; 96 | 97 | @end 98 | -------------------------------------------------------------------------------- /Kiwi/KWReceiveMatcher.h: -------------------------------------------------------------------------------- 1 | // 2 | // Licensed under the terms in License.txt 3 | // 4 | // Copyright 2010 Allen Ding. All rights reserved. 5 | // 6 | 7 | #import "KiwiConfiguration.h" 8 | #import "KWCountType.h" 9 | #import "KWMatcher.h" 10 | #import "KWMatchVerifier.h" 11 | 12 | @class KWMessagePattern; 13 | @class KWMessageTracker; 14 | 15 | @interface KWReceiveMatcher : KWMatcher { 16 | @private 17 | KWMessageTracker *messageTracker; 18 | BOOL willEvaluateMultipleTimes; 19 | } 20 | @property (nonatomic, assign) BOOL willEvaluateMultipleTimes; 21 | 22 | #pragma mark - 23 | #pragma mark Configuring Matchers 24 | 25 | - (void)receive:(SEL)aSelector; 26 | - (void)receive:(SEL)aSelector withCount:(NSUInteger)aCount; 27 | - (void)receive:(SEL)aSelector withCountAtLeast:(NSUInteger)aCount; 28 | - (void)receive:(SEL)aSelector withCountAtMost:(NSUInteger)aCount; 29 | - (void)receive:(SEL)aSelector andReturn:(id)aValue; 30 | - (void)receive:(SEL)aSelector andReturn:(id)aValue withCount:(NSUInteger)aCount; 31 | - (void)receive:(SEL)aSelector andReturn:(id)aValue withCountAtLeast:(NSUInteger)aCount; 32 | - (void)receive:(SEL)aSelector andReturn:(id)aValue withCountAtMost:(NSUInteger)aCount; 33 | - (void)receiveMessagePattern:(KWMessagePattern *)aMessagePattern countType:(KWCountType)aCountType count:(NSUInteger)aCount; 34 | - (void)receiveMessagePattern:(KWMessagePattern *)aMessagePattern andReturn:(id)aValue countType:(KWCountType)aCountType count:(NSUInteger)aCount; 35 | 36 | @end 37 | 38 | @interface KWMatchVerifier(KWReceiveMatcherAdditions) 39 | 40 | #pragma mark - 41 | #pragma mark Verifying 42 | 43 | - (void)receive:(SEL)aSelector withArguments:(id)firstArgument, ...; 44 | - (void)receive:(SEL)aSelector withCount:(NSUInteger)aCount arguments:(id)firstArgument, ...; 45 | - (void)receive:(SEL)aSelector withCountAtLeast:(NSUInteger)aCount arguments:(id)firstArgument, ...; 46 | - (void)receive:(SEL)aSelector withCountAtMost:(NSUInteger)aCount arguments:(id)firstArgument, ...; 47 | - (void)receive:(SEL)aSelector andReturn:(id)aValue withArguments:(id)firstArgument, ...; 48 | - (void)receive:(SEL)aSelector andReturn:(id)aValue withCount:(NSUInteger)aCount arguments:(id)firstArgument, ...; 49 | - (void)receive:(SEL)aSelector andReturn:(id)aValue withCountAtLeast:(NSUInteger)aCount arguments:(id)firstArgument, ...; 50 | - (void)receive:(SEL)aSelector andReturn:(id)aValue withCountAtMost:(NSUInteger)aCount arguments:(id)firstArgument, ...; 51 | 52 | #pragma mark Invocation Capturing Methods 53 | 54 | - (id)receive; 55 | - (id)receiveWithCount:(NSUInteger)aCount; 56 | - (id)receiveWithCountAtLeast:(NSUInteger)aCount; 57 | - (id)receiveWithCountAtMost:(NSUInteger)aCount; 58 | - (id)receiveAndReturn:(id)aValue; 59 | - (id)receiveAndReturn:(id)aValue withCount:(NSUInteger)aCount; 60 | - (id)receiveAndReturn:(id)aValue withCountAtLeast:(NSUInteger)aCount; 61 | - (id)receiveAndReturn:(id)aValue withCountAtMost:(NSUInteger)aCount; 62 | 63 | @end 64 | -------------------------------------------------------------------------------- /Kiwi/Kiwi.h: -------------------------------------------------------------------------------- 1 | // 2 | // Licensed under the terms in License.txt 3 | // 4 | // Copyright 2010 Allen Ding. All rights reserved. 5 | // 6 | 7 | // This needs to come first. 8 | #import "KiwiConfiguration.h" 9 | #import 10 | 11 | #if defined(__cplusplus) 12 | extern "C" { 13 | #endif 14 | 15 | #import "KWAfterAllNode.h" 16 | #import "KWAfterEachNode.h" 17 | #import "KWAny.h" 18 | #import "KWAsyncVerifier.h" 19 | #import "KWBeBetweenMatcher.h" 20 | #import "KWBeEmptyMatcher.h" 21 | #import "KWBeIdenticalToMatcher.h" 22 | #import "KWBeKindOfClassMatcher.h" 23 | #import "KWBeMemberOfClassMatcher.h" 24 | #import "KWBeSubclassOfClassMatcher.h" 25 | #import "KWBeTrueMatcher.h" 26 | #import "KWBeNilMatcher.h" 27 | #import "KWBeNonNilMatcher.h" 28 | #import "KWBeWithinMatcher.h" 29 | #import "KWBeZeroMatcher.h" 30 | #import "KWBeforeAllNode.h" 31 | #import "KWBeforeEachNode.h" 32 | #import "KWBlock.h" 33 | #import "KWBlockNode.h" 34 | #import "KWBlockRaiseMatcher.h" 35 | #import "KWCallSite.h" 36 | #import "KWConformToProtocolMatcher.h" 37 | #import "KWContainMatcher.h" 38 | #import "KWContextNode.h" 39 | #import "KWDeviceInfo.h" 40 | #import "KWEqualMatcher.h" 41 | #import "KWExample.h" 42 | #import "KWExampleGroupBuilder.h" 43 | #import "KWExampleNode.h" 44 | #import "KWExampleNodeVisitor.h" 45 | #import "KWExistVerifier.h" 46 | #import "KWExpectationType.h" 47 | #import "KWFailure.h" 48 | #import "KWFormatter.h" 49 | #import "KWFutureObject.h" 50 | #import "KWHamcrestMatcher.h" 51 | #import "KWHaveMatcher.h" 52 | #import "KWHaveValueMatcher.h" 53 | #import "KWInequalityMatcher.h" 54 | #import "KWInvocationCapturer.h" 55 | #import "KWItNode.h" 56 | #import "KWMatchVerifier.h" 57 | #import "KWMatcher.h" 58 | #import "KWMatchers.h" 59 | #import "KWMatcherFactory.h" 60 | #import "KWMatching.h" 61 | #import "KWMessagePattern.h" 62 | #import "KWMessageSpying.h" 63 | #import "KWMock.h" 64 | #import "KWNull.h" 65 | #import "KWObjCUtilities.h" 66 | #import "KWPendingNode.h" 67 | #import "KWRaiseMatcher.h" 68 | #import "KWReceiveMatcher.h" 69 | #import "KWRegisterMatchersNode.h" 70 | #import "KWRespondToSelectorMatcher.h" 71 | #import "KWSpec.h" 72 | #import "KWStringUtilities.h" 73 | #import "KWStub.h" 74 | #import "KWTestCase.h" 75 | #import "KWUserDefinedMatcher.h" 76 | #import "KWValue.h" 77 | #import "KWVerifying.h" 78 | #import "KWCaptureSpy.h" 79 | #import "KWStringPrefixMatcher.h" 80 | #import "KWStringContainsMatcher.h" 81 | 82 | 83 | // Public Foundation Categories 84 | #import "NSObject+KiwiMockAdditions.h" 85 | #import "NSObject+KiwiStubAdditions.h" 86 | #import "NSObject+KiwiVerifierAdditions.h" 87 | 88 | #import "KiwiMacros.h" 89 | 90 | // Some Foundation headers use Kiwi keywords (e.g. 'should') as identifiers for 91 | // parameter names. Including this last allows the use of Kiwi keywords without 92 | // conflicting with these headers (hopefully!). 93 | #import "KiwiBlockMacros.h" 94 | 95 | #if defined(__cplusplus) 96 | } 97 | #endif 98 | 99 | -------------------------------------------------------------------------------- /Kiwi/KWContainMatcher.m: -------------------------------------------------------------------------------- 1 | // 2 | // Licensed under the terms in License.txt 3 | // 4 | // Copyright 2010 Allen Ding. All rights reserved. 5 | // 6 | 7 | #import "KWContainMatcher.h" 8 | #import "KWFormatter.h" 9 | #import "KWHamrestMatchingAdditions.h" 10 | 11 | @interface KWContainMatcher() 12 | 13 | #pragma mark - 14 | #pragma mark Properties 15 | 16 | @property (nonatomic, readwrite, retain) id objects; 17 | 18 | @end 19 | 20 | @implementation KWContainMatcher 21 | 22 | #pragma mark - 23 | #pragma mark Initializing 24 | 25 | - (void)dealloc { 26 | [objects release]; 27 | [super dealloc]; 28 | } 29 | 30 | #pragma mark - 31 | #pragma mark Properties 32 | 33 | @synthesize objects; 34 | 35 | #pragma mark - 36 | #pragma mark Getting Matcher Strings 37 | 38 | + (NSArray *)matcherStrings { 39 | return [NSArray arrayWithObjects:@"contain:", @"containObjectsInArray:", nil]; 40 | } 41 | 42 | #pragma mark - 43 | #pragma mark Matching 44 | 45 | - (BOOL)evaluate { 46 | if (![self.subject respondsToSelector:@selector(containsObjectEqualToOrMatching:)]) 47 | [NSException raise:@"KWMatcherException" format:@"subject does not respond to -containsObjectEqualToOrMatching:"]; 48 | 49 | for (id object in self.objects) { 50 | if (![self.subject containsObjectEqualToOrMatching:object]) 51 | return NO; 52 | } 53 | 54 | return YES; 55 | } 56 | 57 | #pragma mark - 58 | #pragma mark Getting Failure Messages 59 | 60 | - (NSString *)objectsPhrase { 61 | if ([self.objects count] == 1) 62 | return [KWFormatter formatObject:[self.objects objectAtIndex:0]]; 63 | 64 | return [NSString stringWithFormat:@"all of %@", [KWFormatter formatObject:self.objects]]; 65 | } 66 | 67 | - (NSString *)failureMessageForShould { 68 | return [NSString stringWithFormat:@"expected subject to contain %@", [self objectsPhrase]]; 69 | } 70 | 71 | - (NSString *)description 72 | { 73 | return [NSString stringWithFormat:@"contain %@", [self objectsPhrase]]; 74 | } 75 | 76 | #pragma mark - 77 | #pragma mark Configuring Matchers 78 | 79 | - (void)contain:(id)anObject { 80 | self.objects = [NSArray arrayWithObject:anObject]; 81 | } 82 | 83 | - (void)containObjectsInArray:(NSArray *)anArray { 84 | self.objects = anArray; 85 | } 86 | 87 | @end 88 | 89 | @implementation KWMatchVerifier(KWContainMatcherAdditions) 90 | 91 | #pragma mark - 92 | #pragma mark Verifying 93 | 94 | - (void)containObjects:(id)firstObject, ... { 95 | NSMutableArray *objects = [NSMutableArray array]; 96 | 97 | va_list argumentList; 98 | va_start(argumentList, firstObject); 99 | id object = firstObject; 100 | 101 | while (object != nil) { 102 | [objects addObject:object]; 103 | object = va_arg(argumentList, id); 104 | } 105 | 106 | va_end(argumentList); 107 | [(id)self containObjectsInArray:objects]; 108 | } 109 | 110 | @end 111 | -------------------------------------------------------------------------------- /Kiwi/KWInvocationCapturer.m: -------------------------------------------------------------------------------- 1 | // 2 | // Licensed under the terms in License.txt 3 | // 4 | // Copyright 2010 Allen Ding. All rights reserved. 5 | // 6 | 7 | #import "KWInvocationCapturer.h" 8 | #import "KWWorkarounds.h" 9 | #import "NSInvocation+KiwiAdditions.h" 10 | 11 | @implementation KWInvocationCapturer 12 | 13 | #pragma mark - 14 | #pragma mark Initializing 15 | 16 | - (id)initWithDelegate:(id)aDelegate { 17 | return [self initWithDelegate:aDelegate userInfo:nil]; 18 | } 19 | 20 | - (id)initWithDelegate:(id)aDelegate userInfo:(NSDictionary *)aUserInfo { 21 | delegate = aDelegate; 22 | userInfo = [aUserInfo retain]; 23 | return self; 24 | } 25 | 26 | + (id)invocationCapturerWithDelegate:(id)aDelegate { 27 | return [self invocationCapturerWithDelegate:aDelegate userInfo:nil]; 28 | } 29 | 30 | + (id)invocationCapturerWithDelegate:(id)aDelegate userInfo:(NSDictionary *)aUserInfo { 31 | return [[[self alloc] initWithDelegate:aDelegate userInfo:aUserInfo] autorelease]; 32 | } 33 | 34 | - (void)dealloc { 35 | [userInfo release]; 36 | [super dealloc]; 37 | } 38 | 39 | #pragma mark - 40 | #pragma mark Properties 41 | 42 | @synthesize delegate; 43 | @synthesize userInfo; 44 | 45 | #pragma mark - 46 | #pragma mark Capturing Invocations 47 | 48 | - (void)KW_captureInvocation:(NSInvocation *)anInvocation { 49 | [self.delegate invocationCapturer:self didCaptureInvocation:anInvocation]; 50 | } 51 | 52 | #pragma mark - 53 | #pragma mark Handling Invocations 54 | 55 | - (NSMethodSignature *)methodSignatureForSelector:(SEL)aSelector { 56 | return [self.delegate invocationCapturer:self methodSignatureForSelector:aSelector]; 57 | } 58 | 59 | - (void)forwardInvocation:(NSInvocation *)anInvocation { 60 | #if KW_TARGET_HAS_INVOCATION_EXCEPTION_BUG 61 | @try { 62 | #endif // #if KW_TARGET_HAS_INVOCATION_EXCEPTION_BUG 63 | 64 | [self KW_captureInvocation:anInvocation]; 65 | 66 | #if KW_TARGET_HAS_INVOCATION_EXCEPTION_BUG 67 | } @catch (NSException *exception) { 68 | KWSetExceptionFromAcrossInvocationBoundary(exception); 69 | } 70 | #endif // #if KW_TARGET_HAS_INVOCATION_EXCEPTION_BUG 71 | } 72 | 73 | #pragma mark - 74 | #pragma mark Whitelisted NSObject Methods 75 | 76 | // The return values from these methods should never be needed, so just call 77 | // the super implementation after capturing the invocation. 78 | 79 | - (BOOL)isEqual:(id)anObject { 80 | NSInvocation *invocation = [NSInvocation invocationWithTarget:self selector:_cmd messageArguments:&anObject]; 81 | [self KW_captureInvocation:invocation]; 82 | return [super isEqual:anObject]; 83 | } 84 | 85 | - (NSUInteger)hash { 86 | NSInvocation *invocation = [NSInvocation invocationWithTarget:self selector:_cmd]; 87 | [self KW_captureInvocation:invocation]; 88 | return [super hash]; 89 | } 90 | 91 | - (NSString *)description { 92 | NSInvocation *invocation = [NSInvocation invocationWithTarget:self selector:_cmd]; 93 | [self KW_captureInvocation:invocation]; 94 | return [super description]; 95 | } 96 | 97 | @end 98 | -------------------------------------------------------------------------------- /Kiwi/KiwiMacros.h: -------------------------------------------------------------------------------- 1 | // 2 | // Licensed under the terms in License.txt 3 | // 4 | // Copyright 2010 Allen Ding. All rights reserved. 5 | // 6 | 7 | #import "KiwiConfiguration.h" 8 | 9 | #pragma mark - 10 | #pragma mark Support Macros 11 | 12 | #define KW_THIS_CALLSITE [KWCallSite callSiteWithFilename:@__FILE__ lineNumber:__LINE__] 13 | #define KW_ADD_EXIST_VERIFIER(expectationType) [self addExistVerifierWithExpectationType:expectationType callSite:KW_THIS_CALLSITE] 14 | #define KW_ADD_MATCH_VERIFIER(expectationType) [self addMatchVerifierWithExpectationType:expectationType callSite:KW_THIS_CALLSITE] 15 | #define KW_ADD_ASYNC_VERIFIER(expectationType, timeOut) [self addAsyncVerifierWithExpectationType:expectationType callSite:KW_THIS_CALLSITE timeout:timeOut] 16 | 17 | #pragma mark - 18 | #pragma mark Keywords 19 | 20 | // Kiwi macros used in specs for verifying expectations. 21 | #define should attachToVerifier:KW_ADD_MATCH_VERIFIER(KWExpectationTypeShould) verifier:KW_ADD_EXIST_VERIFIER(KWExpectationTypeShould) 22 | #define shouldNot attachToVerifier:KW_ADD_MATCH_VERIFIER(KWExpectationTypeShouldNot) verifier:KW_ADD_EXIST_VERIFIER(KWExpectationTypeShould) 23 | #define shouldBeNil attachToVerifier:KW_ADD_EXIST_VERIFIER(KWExpectationTypeShouldNot) 24 | #define shouldNotBeNil attachToVerifier:KW_ADD_EXIST_VERIFIER(KWExpectationTypeShould) 25 | #define shouldEventually attachToVerifier:KW_ADD_ASYNC_VERIFIER(KWExpectationTypeShould, kKW_DEFAULT_PROBE_TIMEOUT) 26 | #define shouldEventuallyBeforeTimingOutAfter(timeout) attachToVerifier:KW_ADD_ASYNC_VERIFIER(KWExpectationTypeShould, timeout) 27 | 28 | // wait for is like a shouldEventually but will not fail if it's never satisfied 29 | #define waitFor attachToVerifier:KW_ADD_ASYNC_VERIFIER(KWExpectationTypeMaybe, kKW_DEFAULT_PROBE_TIMEOUT) 30 | 31 | // used to wrap a pointer to an object that will change in the future (used with shouldEventually) 32 | #define theObject(objectPtr) [KWFutureObject objectWithObjectPointer:objectPtr] // DEPRECATED 33 | #define theReturnValueOfBlock(block) [KWFutureObject futureObjectWithBlock:block] // DEPRECATED 34 | #define expectFutureValue(futureValue) [KWFutureObject futureObjectWithBlock:^{ return futureValue; }] 35 | 36 | // used for message patterns to allow matching any value 37 | #define any() [KWAny any] 38 | 39 | // If a gcc compatible compiler is available, use the statement and 40 | // declarations in expression extension to provide a convenient catch-all macro 41 | // to create KWValues. 42 | #if defined(__GNUC__) 43 | #define theValue(expr) \ 44 | ({ \ 45 | __typeof__(expr) kiwiReservedPrefix_lVar = expr; \ 46 | [KWValue valueWithBytes:&kiwiReservedPrefix_lVar objCType:@encode(__typeof__(expr))]; \ 47 | }) 48 | #endif // #if defined(__GNUC__) 49 | 50 | // Example group declarations. 51 | #define SPEC_BEGIN(name) \ 52 | \ 53 | @interface name : KWSpec \ 54 | \ 55 | @end \ 56 | \ 57 | @implementation name \ 58 | \ 59 | + (void)buildExampleGroups { \ 60 | 61 | #define SPEC_END \ 62 | } \ 63 | \ 64 | @end 65 | -------------------------------------------------------------------------------- /CocoaOniguruma/oniguruma/regtrav.c: -------------------------------------------------------------------------------- 1 | /********************************************************************** 2 | regtrav.c - Oniguruma (regular expression library) 3 | **********************************************************************/ 4 | /*- 5 | * Copyright (c) 2002-2004 K.Kosako 6 | * All rights reserved. 7 | * 8 | * Redistribution and use in source and binary forms, with or without 9 | * modification, are permitted provided that the following conditions 10 | * are met: 11 | * 1. Redistributions of source code must retain the above copyright 12 | * notice, this list of conditions and the following disclaimer. 13 | * 2. Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in the 15 | * documentation and/or other materials provided with the distribution. 16 | * 17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 18 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 21 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 | * SUCH DAMAGE. 28 | */ 29 | 30 | #include "regint.h" 31 | 32 | #ifdef USE_CAPTURE_HISTORY 33 | 34 | static int 35 | capture_tree_traverse(OnigCaptureTreeNode* node, int at, 36 | int(*callback_func)(int,int,int,int,int,void*), 37 | int level, void* arg) 38 | { 39 | int r, i; 40 | 41 | if (node == (OnigCaptureTreeNode* )0) 42 | return 0; 43 | 44 | if ((at & ONIG_TRAVERSE_CALLBACK_AT_FIRST) != 0) { 45 | r = (*callback_func)(node->group, node->beg, node->end, 46 | level, ONIG_TRAVERSE_CALLBACK_AT_FIRST, arg); 47 | if (r != 0) return r; 48 | } 49 | 50 | for (i = 0; i < node->num_childs; i++) { 51 | r = capture_tree_traverse(node->childs[i], at, 52 | callback_func, level + 1, arg); 53 | if (r != 0) return r; 54 | } 55 | 56 | if ((at & ONIG_TRAVERSE_CALLBACK_AT_LAST) != 0) { 57 | r = (*callback_func)(node->group, node->beg, node->end, 58 | level, ONIG_TRAVERSE_CALLBACK_AT_LAST, arg); 59 | if (r != 0) return r; 60 | } 61 | 62 | return 0; 63 | } 64 | #endif /* USE_CAPTURE_HISTORY */ 65 | 66 | extern int 67 | onig_capture_tree_traverse(OnigRegion* region, int at, 68 | int(*callback_func)(int,int,int,int,int,void*), void* arg) 69 | { 70 | #ifdef USE_CAPTURE_HISTORY 71 | return capture_tree_traverse(region->history_root, at, 72 | callback_func, 0, arg); 73 | #else 74 | return ONIG_NO_SUPPORT_CONFIG; 75 | #endif 76 | } 77 | -------------------------------------------------------------------------------- /Kiwi/KWStringUtilities.m: -------------------------------------------------------------------------------- 1 | // 2 | // Licensed under the terms in License.txt 3 | // 4 | // Copyright 2010 Allen Ding. All rights reserved. 5 | // 6 | 7 | #import "KWStringUtilities.h" 8 | 9 | #pragma mark - 10 | #pragma mark Checking for Case Separated Words 11 | 12 | BOOL KWStringHasWordPrefix(NSString *string, NSString *prefix) { 13 | return [string isEqualToString:prefix] || KWStringHasStrictWordPrefix(string, prefix); 14 | } 15 | 16 | BOOL KWStringHasStrictWordPrefix(NSString *string, NSString *prefix) { 17 | if (![string hasPrefix:prefix] || [string length] == [prefix length]) 18 | return NO; 19 | 20 | unichar firstCharacterAfterPrefix = [string characterAtIndex:[prefix length]]; 21 | NSCharacterSet *uppercaseCharacterSet = [NSCharacterSet uppercaseLetterCharacterSet]; 22 | return [uppercaseCharacterSet characterIsMember:firstCharacterAfterPrefix]; 23 | } 24 | 25 | BOOL KWStringHasWord(NSString *string, NSString *word) { 26 | if (KWStringHasWordPrefix(string, word)) 27 | return YES; 28 | 29 | NSCharacterSet *lowercaseCharacterSet = [NSCharacterSet lowercaseLetterCharacterSet]; 30 | NSCharacterSet *uppercaseCharacterSet = [NSCharacterSet uppercaseLetterCharacterSet]; 31 | NSRange searchRange = NSMakeRange(0, [string length]); 32 | 33 | // Never match if word begins with a lowercase letter and was not a prefix. 34 | if ([lowercaseCharacterSet characterIsMember:[word characterAtIndex:0]]) 35 | return NO; 36 | 37 | while (1) { 38 | if (searchRange.location >= [string length]) 39 | return NO; 40 | 41 | NSRange range = [string rangeOfString:word options:0 range:searchRange]; 42 | searchRange.location = range.location + range.length; 43 | searchRange.length = [string length] - searchRange.location; 44 | 45 | if (range.location == NSNotFound) 46 | return NO; 47 | 48 | if (range.location > 0) { 49 | unichar charBeforeRange = [string characterAtIndex:range.location - 1]; 50 | 51 | 52 | if (![lowercaseCharacterSet characterIsMember:charBeforeRange]) 53 | continue; 54 | } 55 | 56 | if (range.location + range.length < [string length]) { 57 | unichar charAfterRange = [string characterAtIndex:range.location + range.length]; 58 | 59 | if (![uppercaseCharacterSet characterIsMember:charAfterRange]) 60 | continue; 61 | } 62 | 63 | return YES; 64 | } 65 | } 66 | 67 | #pragma mark - 68 | #pragma mark Getting Type Encodings 69 | 70 | NSString *KWEncodingWithObjCTypes(const char *firstType, ...) { 71 | if (firstType == nil) 72 | return nil; 73 | 74 | NSMutableString *encoding = [NSMutableString stringWithCapacity:8]; 75 | va_list argumentList; 76 | va_start(argumentList, firstType); 77 | const char *type = firstType; 78 | 79 | do { 80 | [encoding appendFormat:@"%s", type]; 81 | type = va_arg(argumentList, const char *); 82 | } while (type != nil); 83 | 84 | va_end(argumentList); 85 | return encoding; 86 | } 87 | 88 | NSString *KWEncodingForVoidMethod(void) { 89 | return KWEncodingWithObjCTypes(@encode(void), @encode(id), @encode(SEL), nil); 90 | } 91 | -------------------------------------------------------------------------------- /Kiwi/KWMock.h: -------------------------------------------------------------------------------- 1 | // 2 | // Licensed under the terms in License.txt 3 | // 4 | // Copyright 2010 Allen Ding. All rights reserved. 5 | // 6 | 7 | #import "KiwiConfiguration.h" 8 | #import "KWInvocationCapturer.h" 9 | 10 | @class KWMessagePattern; 11 | @class KWCaptureSpy; 12 | 13 | @protocol KWMessageSpying; 14 | @protocol KWVerifying; 15 | 16 | @interface KWMock : NSObject { 17 | @private 18 | BOOL isNullMock; 19 | NSString *name; 20 | Class mockedClass; 21 | Protocol *mockedProtocol; 22 | NSMutableArray *stubs; 23 | NSMutableArray *expectedMessagePatterns; 24 | NSMutableDictionary *messageSpies; 25 | } 26 | 27 | #pragma mark - 28 | #pragma mark Initializing 29 | 30 | - (id)initForClass:(Class)aClass; 31 | - (id)initForProtocol:(Protocol *)aProtocol; 32 | - (id)initWithName:(NSString *)aName forClass:(Class)aClass; 33 | - (id)initWithName:(NSString *)aName forProtocol:(Protocol *)aProtocol; 34 | 35 | - (id)initAsNullMockForClass:(Class)aClass; 36 | - (id)initAsNullMockForProtocol:(Protocol *)aProtocol; 37 | - (id)initAsNullMockWithName:(NSString *)aName forClass:(Class)aClass; 38 | - (id)initAsNullMockWithName:(NSString *)aName forProtocol:(Protocol *)aProtocol; 39 | 40 | + (id)mockForClass:(Class)aClass; 41 | + (id)mockForProtocol:(Protocol *)aProtocol; 42 | + (id)mockWithName:(NSString *)aName forClass:(Class)aClass; 43 | + (id)mockWithName:(NSString *)aName forProtocol:(Protocol *)aProtocol; 44 | 45 | + (id)nullMockForClass:(Class)aClass; 46 | + (id)nullMockForProtocol:(Protocol *)aProtocol; 47 | + (id)nullMockWithName:(NSString *)aName forClass:(Class)aClass ; 48 | + (id)nullMockWithName:(NSString *)aName forProtocol:(Protocol *)aProtocol; 49 | 50 | #pragma mark - 51 | #pragma mark Properties 52 | 53 | @property (nonatomic, readonly) BOOL isNullMock; 54 | @property (nonatomic, readonly) NSString *name; 55 | @property (nonatomic, readonly) Class mockedClass; 56 | @property (nonatomic, readonly) Protocol *mockedProtocol; 57 | 58 | #pragma mark - 59 | #pragma mark Stubbing Methods 60 | 61 | - (void)stub:(SEL)aSelector; 62 | - (void)stub:(SEL)aSelector withArguments:(id)firstArgument, ...; 63 | - (void)stub:(SEL)aSelector andReturn:(id)aValue; 64 | - (void)stub:(SEL)aSelector andReturn:(id)aValue withArguments:(id)firstArgument, ...; 65 | 66 | - (id)stub; 67 | - (id)stubAndReturn:(id)aValue; 68 | - (id)stubAndReturn:(id)aValue times:(id)times afterThatReturn:(id)aSecondValue; 69 | 70 | - (void)stubMessagePattern:(KWMessagePattern *)aMessagePattern andReturn:(id)aValue; 71 | - (void)stubMessagePattern:(KWMessagePattern *)aMessagePattern andReturn:(id)aValue times:(id)times afterThatReturn:(id)aSecondValue; 72 | 73 | - (void)clearStubs; 74 | 75 | #pragma mark - 76 | #pragma mark Spying on Messages 77 | 78 | - (void)addMessageSpy:(id)aSpy forMessagePattern:(KWMessagePattern *)aMessagePattern; 79 | - (void)removeMessageSpy:(id)aSpy forMessagePattern:(KWMessagePattern *)aMessagePattern; 80 | - (KWCaptureSpy *)captureArgument:(SEL)selector atIndex:(NSUInteger)index; 81 | 82 | 83 | #pragma mark - 84 | #pragma mark Expecting Messages 85 | 86 | - (void)expect:(SEL)aSelector; 87 | - (void)expect:(SEL)aSelector withArguments:(id)firstArgument, ...; 88 | 89 | - (id)expect; 90 | 91 | - (void)expectMessagePattern:(KWMessagePattern *)aMessagePattern; 92 | 93 | @end 94 | -------------------------------------------------------------------------------- /RubyficationTests/DateSpec.m: -------------------------------------------------------------------------------- 1 | #import "Kiwi.h" 2 | #import "NSDate+helpers.h" 3 | 4 | SPEC_BEGIN(DateSpec) 5 | 6 | describe(@"NSDate", ^{ 7 | __block NSDate* ref = nil; 8 | 9 | context(@"constructors", ^{ 10 | it(@"long local constructor should compare to string to date converstion", ^{ 11 | ref = [NSDate parse:@"2010-01-01 10:15:30"]; 12 | NSDate* date = [NSDate local:2010 month:1 day:1 hours:10 minutes:15 seconds:30]; 13 | [[date should] equal:ref]; 14 | }); 15 | 16 | it(@"long local constructor with default seconds should compare to string to date converstion", ^{ 17 | ref = [NSDate parse:@"2010-01-01 10:15:00"]; 18 | NSDate* date = [NSDate local:2010 month:1 day:1 hours:10 minutes:15]; 19 | [[date should] equal:ref]; 20 | }); 21 | 22 | it(@"long local constructor with default seconds and minutes should compare to string to date converstion", ^{ 23 | ref = [NSDate parse:@"2010-01-01 10:00:00"]; 24 | NSDate* date = [NSDate local:2010 month:1 day:1 hours:10]; 25 | [[date should] equal:ref]; 26 | }); 27 | 28 | it(@"long local constructor with default seconds, minutes, and hours should compare to string to date converstion", ^{ 29 | ref = [NSDate parse:@"2010-01-01 00:00:00"]; 30 | NSDate* date = [NSDate local:2010 month:1 day:1]; 31 | [[date should] equal:ref]; 32 | }); 33 | 34 | it(@"long local constructor with default seconds, minutes, hours, and day should compare to string to date converstion", ^{ 35 | ref = [NSDate parse:@"2010-01-01 00:00:00"]; 36 | NSDate* date = [NSDate local:2010 month:1]; 37 | [[date should] equal:ref]; 38 | }); 39 | 40 | it(@"long local constructor with default seconds, minutes, hours, day, and month should compare to string to date converstion", ^{ 41 | ref = [NSDate parse:@"2010-01-01 00:00:00"]; 42 | NSDate* date = [NSDate local:2010]; 43 | [[date should] equal:ref]; 44 | }); 45 | }); 46 | 47 | context(@"formatters", ^{ 48 | beforeEach(^{ 49 | ref = [NSDate local:2010 month:1 day:1 hours:10 minutes:15 seconds:30]; 50 | }); 51 | 52 | it(@"should convert the date to the short format", ^{ 53 | [[[ref toFormattedString:@"short"] should] equal:@"01 Jan 10:15"]; 54 | }); 55 | 56 | it(@"should convert the date to the long format", ^{ 57 | [[[ref toFormattedString:@"long"] should] equal:@"January 01, 2010 10:15"]; 58 | }); 59 | 60 | it(@"should convert the date to the db format", ^{ 61 | [[[ref toFormattedString:@"db"] should] equal:@"2010-01-01 10:15:30"]; 62 | }); 63 | 64 | it(@"should convert the date to the number format", ^{ 65 | [[[ref toFormattedString:@"number"] should] equal:@"20100101101530"]; 66 | }); 67 | 68 | it(@"should convert the date to the rfc822 format", ^{ 69 | [[[ref toFormattedString:@"rfc822"] should] equal:@"Fri, 01 Jan 2010 10:15:30"]; 70 | }); 71 | 72 | it(@"should convert the date to the rfc3339 format", ^{ 73 | [[[ref toFormattedString:@"rfc3339"] should] equal:@"2010-01-01T10:15:30BRST"]; 74 | }); 75 | }); 76 | }); 77 | 78 | SPEC_END -------------------------------------------------------------------------------- /Kiwi/KWExample.h: -------------------------------------------------------------------------------- 1 | // 2 | // Licensed under the terms in License.txt 3 | // 4 | // Copyright 2010 Allen Ding. All rights reserved. 5 | // 6 | 7 | #import "KiwiConfiguration.h" 8 | #import "KWBlock.h" 9 | #import "KWVerifying.h" 10 | #import "KWExpectationType.h" 11 | #import "KWExampleNode.h" 12 | #import "KWExampleNodeVisitor.h" 13 | #import "KWReporting.h" 14 | #import "KWExampleGroupDelegate.h" 15 | 16 | @class KWCallSite; 17 | @class KWExampleSuite; 18 | @class KWContextNode; 19 | @class KWSpec; 20 | @class KWMatcherFactory; 21 | 22 | @interface KWExample : NSObject { 23 | id exampleNode; 24 | BOOL passed; 25 | } 26 | @property (nonatomic, retain) KWContextNode *lastInContext; 27 | @property (nonatomic, assign) KWExampleSuite *suite; 28 | 29 | - (id)initWithExampleNode:(id)node; 30 | 31 | #pragma mark - Adding Verifiers 32 | 33 | - (id)addVerifier:(id)aVerifier; 34 | - (id)addExistVerifierWithExpectationType:(KWExpectationType)anExpectationType callSite:(KWCallSite *)aCallSite; 35 | - (id)addMatchVerifierWithExpectationType:(KWExpectationType)anExpectationType callSite:(KWCallSite *)aCallSite; 36 | - (id)addAsyncVerifierWithExpectationType:(KWExpectationType)anExpectationType callSite:(KWCallSite *)aCallSite timeout:(NSInteger)timeout; 37 | 38 | #pragma mark - Running 39 | 40 | - (void)runWithDelegate:(id)delegate; 41 | 42 | #pragma mark - 43 | #pragma mark Anonymous It Node Descriptions 44 | 45 | - (NSString *)generateDescriptionForAnonymousItNode; 46 | 47 | #pragma mark - 48 | #pragma mark Checking if last in context 49 | 50 | - (BOOL)isLastInContext:(KWContextNode *)context; 51 | 52 | #pragma mark - 53 | #pragma mark Full description with context 54 | 55 | - (NSString *)descriptionWithContext; 56 | 57 | @end 58 | 59 | #pragma mark - 60 | #pragma mark Building Example Groups 61 | 62 | void describe(NSString *aDescription, KWVoidBlock aBlock); 63 | void context(NSString *aDescription, KWVoidBlock aBlock); 64 | void registerMatchers(NSString *aNamespacePrefix); 65 | void beforeAll(KWVoidBlock aBlock); 66 | void afterAll(KWVoidBlock aBlock); 67 | void beforeEach(KWVoidBlock aBlock); 68 | void afterEach(KWVoidBlock aBlock); 69 | void it(NSString *aDescription, KWVoidBlock aBlock); 70 | void specify(KWVoidBlock aBlock); 71 | void pending_(NSString *aDescription, KWVoidBlock ignoredBlock); 72 | 73 | void describeWithCallSite(KWCallSite *aCallSite, NSString *aDescription, KWVoidBlock aBlock); 74 | void contextWithCallSite(KWCallSite *aCallSite, NSString *aDescription, KWVoidBlock aBlock); 75 | void registerMatchersWithCallSite(KWCallSite *aCallSite, NSString *aNamespacePrefix); 76 | void beforeAllWithCallSite(KWCallSite *aCallSite, KWVoidBlock aBlock); 77 | void afterAllWithCallSite(KWCallSite *aCallSite, KWVoidBlock aBlock); 78 | void beforeEachWithCallSite(KWCallSite *aCallSite, KWVoidBlock aBlock); 79 | void afterEachWithCallSite(KWCallSite *aCallSite, KWVoidBlock aBlock); 80 | void itWithCallSite(KWCallSite *aCallSite, NSString *aDescription, KWVoidBlock aBlock); 81 | void pendingWithCallSite(KWCallSite *aCallSite, NSString *aDescription, KWVoidBlock ignoredBlock); 82 | 83 | #define PRAGMA(x) _Pragma (#x) 84 | #define PENDING(x) PRAGMA(message ( "Pending: " #x )) 85 | 86 | #define pending(title, args...) \ 87 | PENDING(title) \ 88 | pending_(title, ## args) 89 | #define xit(title, args...) \ 90 | PENDING(title) \ 91 | pending_(title, ## args) 92 | -------------------------------------------------------------------------------- /Kiwi/NSInvocation+KiwiAdditions.m: -------------------------------------------------------------------------------- 1 | // 2 | // Licensed under the terms in License.txt 3 | // 4 | // Copyright 2010 Allen Ding. All rights reserved. 5 | // 6 | 7 | #import "NSInvocation+KiwiAdditions.h" 8 | #import "KWFormatter.h" 9 | #import "KWObjCUtilities.h" 10 | #import "NSMethodSignature+KiwiAdditions.h" 11 | 12 | @implementation NSInvocation(KiwiAdditions) 13 | 14 | #pragma mark - 15 | #pragma mark Creating NSInvocation Objects 16 | 17 | + (NSInvocation *)invocationWithTarget:(id)anObject selector:(SEL)aSelector { 18 | return [self invocationWithTarget:anObject selector:aSelector messageArguments:nil]; 19 | } 20 | 21 | + (NSInvocation *)invocationWithTarget:(id)anObject selector:(SEL)aSelector messageArguments:(const void *)firstBytes, ... { 22 | if (anObject == nil) { 23 | [NSException raise:NSInvalidArgumentException format:@"%@ - target must not be nil", 24 | NSStringFromSelector(_cmd)]; 25 | } 26 | 27 | NSMethodSignature *signature = [anObject methodSignatureForSelector:aSelector]; 28 | 29 | if (signature == nil) { 30 | [NSException raise:NSInvalidArgumentException format:@"%@ - target returned nil for -methodSignatureForSelector", 31 | NSStringFromSelector(_cmd)]; 32 | } 33 | 34 | NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:signature]; 35 | [invocation setTarget:anObject]; 36 | [invocation setSelector:aSelector]; 37 | NSUInteger numberOfMessageArguments = [signature numberOfMessageArguments]; 38 | 39 | if (numberOfMessageArguments == 0) 40 | return invocation; 41 | 42 | va_list argumentList; 43 | va_start(argumentList, firstBytes); 44 | const void *bytes = firstBytes; 45 | 46 | for (NSUInteger i = 0; i < numberOfMessageArguments && bytes != nil; ++i) { 47 | [invocation setMessageArgument:bytes atIndex:i]; 48 | bytes = va_arg(argumentList, const void *); 49 | } 50 | 51 | va_end(argumentList); 52 | return invocation; 53 | } 54 | 55 | #pragma mark - 56 | #pragma mark Accessing Message Arguments 57 | 58 | - (NSData *)messageArgumentDataAtIndex:(NSUInteger)anIndex { 59 | NSUInteger length = KWObjCTypeLength([[self methodSignature] messageArgumentTypeAtIndex:anIndex]); 60 | void *buffer = malloc(length); 61 | [self getMessageArgument:buffer atIndex:anIndex]; 62 | // NSData takes over ownership of buffer 63 | NSData* data = [NSData dataWithBytesNoCopy:buffer length:length]; 64 | return data; 65 | } 66 | 67 | - (void)getMessageArgument:(void *)buffer atIndex:(NSUInteger)anIndex { 68 | [self getArgument:buffer atIndex:anIndex + 2]; 69 | } 70 | 71 | - (void)setMessageArgument:(const void *)bytes atIndex:(NSUInteger)anIndex { 72 | [self setArgument:(void *)bytes atIndex:anIndex + 2]; 73 | } 74 | 75 | - (void)setMessageArguments:(const void *)firstBytes, ... { 76 | NSUInteger numberOfMessageArguments = [[self methodSignature] numberOfMessageArguments]; 77 | 78 | if (numberOfMessageArguments == 0) 79 | return; 80 | 81 | va_list argumentList; 82 | va_start(argumentList, firstBytes); 83 | const void *bytes = firstBytes; 84 | 85 | for (NSUInteger i = 0; i < numberOfMessageArguments && bytes != nil; ++i) { 86 | [self setMessageArgument:bytes atIndex:i]; 87 | bytes = va_arg(argumentList, const void *); 88 | } 89 | 90 | va_end(argumentList); 91 | } 92 | 93 | @end 94 | -------------------------------------------------------------------------------- /Kiwi/KWAsyncVerifier.m: -------------------------------------------------------------------------------- 1 | // 2 | // KWAsyncVerifier.m 3 | // iOSFalconCore 4 | // 5 | // Created by Luke Redpath on 13/01/2011. 6 | // Copyright 2011 LJR Software Limited. All rights reserved. 7 | // 8 | 9 | #import "KWAsyncVerifier.h" 10 | #import "KWFailure.h" 11 | #import "KWMatching.h" 12 | #import "KWReporting.h" 13 | #import "KWProbePoller.h" 14 | 15 | @implementation KWAsyncVerifier 16 | 17 | @synthesize timeout; 18 | 19 | + (id)asyncVerifierWithExpectationType:(KWExpectationType)anExpectationType callSite:(KWCallSite *)aCallSite matcherFactory:(KWMatcherFactory *)aMatcherFactory reporter:(id)aReporter probeTimeout:(NSTimeInterval)probeTimeout; 20 | { 21 | KWAsyncVerifier *verifier = [[self alloc] initWithExpectationType:anExpectationType callSite:aCallSite matcherFactory:aMatcherFactory reporter:aReporter]; 22 | verifier.timeout = probeTimeout; 23 | return [verifier autorelease]; 24 | } 25 | 26 | - (id)initWithExpectationType:(KWExpectationType)anExpectationType callSite:(KWCallSite *)aCallSite matcherFactory:(KWMatcherFactory *)aMatcherFactory reporter:(id)aReporter { 27 | if ((self = [super initWithExpectationType:anExpectationType callSite:aCallSite matcherFactory:aMatcherFactory reporter:aReporter])) { 28 | self.timeout = kKW_DEFAULT_PROBE_TIMEOUT; 29 | } 30 | return self; 31 | } 32 | 33 | - (void)verifyWithProbe:(KWAsyncMatcherProbe *)aProbe { 34 | @try { 35 | KWProbePoller *poller = [[KWProbePoller alloc] initWithTimeout:self.timeout delay:kKW_DEFAULT_PROBE_DELAY]; 36 | 37 | if (![poller check:aProbe]) { 38 | if (self.expectationType == KWExpectationTypeShould) { 39 | NSString *message = [aProbe.matcher failureMessageForShould]; 40 | KWFailure *failure = [KWFailure failureWithCallSite:self.callSite message:message]; 41 | [self.reporter reportFailure:failure]; 42 | } else if (self.expectationType == KWExpectationTypeShouldNot) { 43 | NSString *message = [aProbe.matcher failureMessageForShouldNot]; 44 | KWFailure *failure = [KWFailure failureWithCallSite:self.callSite message:message]; 45 | [self.reporter reportFailure:failure]; 46 | } else if (self.expectationType == KWExpectationTypeMaybe) { 47 | // don't do anything 48 | } 49 | } 50 | [poller release]; 51 | 52 | } @catch (NSException *exception) { 53 | KWFailure *failure = [KWFailure failureWithCallSite:self.callSite message:[exception description]]; 54 | [self.reporter reportFailure:failure]; 55 | } 56 | } 57 | 58 | - (void)verifyWithMatcher:(id)aMatcher { 59 | KWAsyncMatcherProbe *probe = [[[KWAsyncMatcherProbe alloc] initWithMatcher:aMatcher] autorelease]; 60 | [self verifyWithProbe:probe]; 61 | } 62 | 63 | @end 64 | 65 | @implementation KWAsyncMatcherProbe 66 | 67 | @synthesize matcher; 68 | 69 | - (id)initWithMatcher:(id)aMatcher; 70 | { 71 | if ((self = [super init])) { 72 | matcher = [aMatcher retain]; 73 | 74 | // make sure the matcher knows we are going to evaluate it multiple times 75 | if ([aMatcher respondsToSelector:@selector(willEvaluateMultipleTimes)]) { 76 | [aMatcher setWillEvaluateMultipleTimes:YES]; 77 | } 78 | } 79 | return self; 80 | } 81 | 82 | - (void)dealloc 83 | { 84 | [matcher release]; 85 | [super dealloc]; 86 | } 87 | 88 | - (BOOL)isSatisfied; 89 | { 90 | return matchResult; 91 | } 92 | 93 | - (void)sample; 94 | { 95 | matchResult = [matcher evaluate]; 96 | } 97 | 98 | @end 99 | 100 | -------------------------------------------------------------------------------- /Kiwi/KWObjCUtilities.m: -------------------------------------------------------------------------------- 1 | // 2 | // Licensed under the terms in License.txt 3 | // 4 | // Copyright 2010 Allen Ding. All rights reserved. 5 | // 6 | 7 | #import "KWObjCUtilities.h" 8 | #import "KWStringUtilities.h" 9 | 10 | #pragma mark - 11 | #pragma mark Objective-C Type Utilities 12 | 13 | BOOL KWObjCTypeEqualToObjCType(const char *firstObjCType, const char *secondObjCType) { 14 | return strcmp(firstObjCType, secondObjCType) == 0; 15 | } 16 | 17 | BOOL KWObjCTypeIsNumeric(const char *objCType) { 18 | return KWObjCTypeIsFloatingPoint(objCType) || KWObjCTypeIsIntegral(objCType); 19 | } 20 | 21 | BOOL KWObjCTypeIsFloatingPoint(const char *objCType) { 22 | return strcmp(objCType, @encode(float)) == 0 || strcmp(objCType, @encode(double)) == 0; 23 | } 24 | 25 | BOOL KWObjCTypeIsIntegral(const char *objCType) { 26 | return KWObjCTypeIsSignedIntegral(objCType) || KWObjCTypeIsUnsignedIntegral(objCType); 27 | } 28 | 29 | BOOL KWObjCTypeIsSignedIntegral(const char *objCType) { 30 | return strcmp(objCType, @encode(char)) == 0 || 31 | strcmp(objCType, @encode(int)) == 0 || 32 | strcmp(objCType, @encode(short)) == 0 || 33 | strcmp(objCType, @encode(long)) == 0 || 34 | strcmp(objCType, @encode(long long)) == 0; 35 | } 36 | 37 | BOOL KWObjCTypeIsUnsignedIntegral(const char *objCType) { 38 | return strcmp(objCType, @encode(unsigned char)) == 0 || 39 | strcmp(objCType, @encode(unsigned int)) == 0 || 40 | strcmp(objCType, @encode(unsigned short)) == 0 || 41 | strcmp(objCType, @encode(unsigned long)) == 0 || 42 | strcmp(objCType, @encode(unsigned long long)) == 0; 43 | } 44 | 45 | BOOL KWObjCTypeIsObject(const char *objCType) { 46 | return strcmp(objCType, @encode(id)) == 0 || strcmp(objCType, "@?") == 0; 47 | } 48 | 49 | BOOL KWObjCTypeIsCharString(const char *objCType) { 50 | return strcmp(objCType, @encode(char *)) == 0; 51 | } 52 | 53 | BOOL KWObjCTypeIsClass(const char *objCType) { 54 | return strcmp(objCType, @encode(Class)) == 0; 55 | } 56 | 57 | BOOL KWObjCTypeIsSelector(const char *objCType) { 58 | return strcmp(objCType, @encode(SEL)) == 0; 59 | } 60 | 61 | BOOL KWObjCTypeIsPointerToType(const char *objCType) { 62 | return *objCType == '^'; 63 | } 64 | 65 | BOOL KWObjCTypeIsPointerLike(const char *objCType) { 66 | return KWObjCTypeIsObject(objCType) || 67 | KWObjCTypeIsCharString(objCType) || 68 | KWObjCTypeIsClass(objCType) || 69 | KWObjCTypeIsSelector(objCType) || 70 | KWObjCTypeIsPointerToType(objCType); 71 | } 72 | 73 | BOOL KWObjCTypeIsUnknown(const char *objCType) { 74 | return *objCType == '?'; 75 | } 76 | 77 | NSUInteger KWObjCTypeLength(const char *objCType) { 78 | NSString *encoding = KWEncodingWithObjCTypes(objCType, @encode(id), @encode(SEL), nil); 79 | NSMethodSignature *signature = [NSMethodSignature signatureWithObjCTypes:[encoding UTF8String]]; 80 | return [signature methodReturnLength]; 81 | } 82 | 83 | BOOL KWObjCTypeIsBlock(const char *objCType) { 84 | return strcmp(objCType, "@?") == 0; 85 | } 86 | 87 | 88 | #pragma mark - 89 | #pragma mark Selector Utlities 90 | 91 | NSUInteger KWSelectorParameterCount(SEL selector) { 92 | NSString *selectorString = NSStringFromSelector(selector); 93 | NSUInteger length = [selectorString length]; 94 | NSUInteger parameterCount = 0; 95 | 96 | for (NSUInteger i = 0; i < length; ++i) { 97 | if ([selectorString characterAtIndex:i] == ':') 98 | ++parameterCount; 99 | } 100 | 101 | return parameterCount; 102 | } 103 | -------------------------------------------------------------------------------- /Kiwi/KWHaveValueMatcher.m: -------------------------------------------------------------------------------- 1 | // 2 | // KWHaveValueMatcher.m 3 | // Kiwi 4 | // 5 | // Created by Luke Redpath on 24/01/2011. 6 | // Copyright 2011 Allen Ding. All rights reserved. 7 | // 8 | 9 | #import "KWHaveValueMatcher.h" 10 | #import "KWHamrestMatchingAdditions.h" 11 | #import "KWHCMatcher.h" 12 | #import "KWFormatter.h" 13 | 14 | @interface KWHaveValueMatcher() 15 | 16 | #pragma mark - 17 | #pragma mark Properties 18 | 19 | @property (nonatomic, retain) NSString *expectedKey; 20 | @property (nonatomic, retain) NSString *expectedKeyPath; 21 | @property (nonatomic, retain) id expectedValue; 22 | 23 | - (id)subjectValue; 24 | 25 | @end 26 | 27 | @implementation KWHaveValueMatcher 28 | 29 | @synthesize expectedKey, expectedKeyPath, expectedValue; 30 | 31 | - (void)dealloc 32 | { 33 | [expectedKeyPath release]; 34 | [expectedKey release]; 35 | [expectedValue release]; 36 | [super dealloc]; 37 | } 38 | 39 | #pragma mark - 40 | #pragma mark Getting Matcher Strings 41 | 42 | + (NSArray *)matcherStrings { 43 | return [NSArray arrayWithObjects:@"haveValue:forKey:", 44 | @"haveValueForKey:", 45 | @"haveValue:forKeyPath:", 46 | @"haveValueForKeyPath:", nil]; 47 | } 48 | 49 | #pragma mark - 50 | #pragma mark Matching 51 | 52 | - (BOOL)evaluate { 53 | BOOL matched = NO; 54 | 55 | @try { 56 | id value = [self subjectValue]; 57 | 58 | if (value) { 59 | matched = YES; 60 | 61 | if (self.expectedValue) { 62 | matched = [self.expectedValue isEqualOrMatches:value]; 63 | } 64 | } 65 | } 66 | @catch (NSException * e) {} // catch KVO non-existent key errors 67 | 68 | return matched; 69 | } 70 | 71 | - (NSString *)failureMessageForShould { 72 | if (self.expectedValue == nil) { 73 | return [NSString stringWithFormat:@"expected subject to have a value for key %@", self.expectedKey]; 74 | } 75 | return [NSString stringWithFormat:@"expected subject to have value %@ for key %@", self.expectedValue, self.expectedKey]; 76 | } 77 | 78 | - (id)subjectValue; 79 | { 80 | id value = nil; 81 | 82 | if (self.expectedKey) { 83 | value = [self.subject valueForKey:self.expectedKey]; 84 | } else 85 | if (self.expectedKeyPath) { 86 | value = [self.subject valueForKeyPath:self.expectedKeyPath]; 87 | } 88 | return value; 89 | } 90 | 91 | - (NSString *)description 92 | { 93 | NSString *keyDescription = nil; 94 | 95 | if (self.expectedKey) { 96 | keyDescription = [NSString stringWithFormat:@"key %@", [KWFormatter formatObject:self.expectedKey]]; 97 | } 98 | else { 99 | keyDescription = [NSString stringWithFormat:@"keypath %@", [KWFormatter formatObject:self.expectedKeyPath]]; 100 | } 101 | 102 | NSString *valueDescription = nil; 103 | 104 | if (self.expectedValue) { 105 | valueDescription = [NSString stringWithFormat:@"value %@", [KWFormatter formatObject:self.expectedValue]]; 106 | } 107 | else { 108 | valueDescription = @"value"; 109 | } 110 | 111 | return [NSString stringWithFormat:@"have %@ for %@", valueDescription, keyDescription]; 112 | } 113 | 114 | #pragma mark - 115 | #pragma mark Configuring Matchers 116 | 117 | - (void)haveValue:(id)value forKey:(NSString *)key; 118 | { 119 | self.expectedKey = key; 120 | self.expectedValue = value; 121 | } 122 | 123 | - (void)haveValue:(id)value forKeyPath:(NSString *)key; 124 | { 125 | self.expectedKeyPath = key; 126 | self.expectedValue = value; 127 | } 128 | 129 | - (void)haveValueForKey:(NSString *)key; 130 | { 131 | self.expectedKey = key; 132 | self.expectedValue = nil; 133 | } 134 | 135 | - (void)haveValueForKeyPath:(NSString *)keyPath; 136 | { 137 | self.expectedKeyPath = keyPath; 138 | self.expectedValue = nil; 139 | } 140 | 141 | @end 142 | -------------------------------------------------------------------------------- /Rubyfication/NSDate+helpers.m: -------------------------------------------------------------------------------- 1 | // 2 | // NSDate+helpers.m 3 | // Rubyfication 4 | // 5 | // Created by Fabio Akita on 4/4/11. 6 | // Copyright 2011 Gonow Tecnologia. All rights reserved. 7 | // 8 | 9 | #import "NSDate+helpers.h" 10 | #import "time.h" 11 | 12 | 13 | @implementation NSDate (helpers) 14 | 15 | #pragma - 16 | #pragma NSDate Constructors 17 | 18 | + (NSDate*) local:(int)year month:(int)month day:(int)day hours:(int)hours minutes:(int)minutes seconds:(int)seconds { 19 | NSCalendar *gregorian = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar]; 20 | NSDateComponents *comps = [[NSDateComponents alloc] init]; 21 | [comps setYear:year]; 22 | [comps setMonth:month]; 23 | [comps setDay:day]; 24 | [comps setHour:hours]; 25 | [comps setMinute:minutes]; 26 | [comps setSecond:seconds]; 27 | NSDate *date = [gregorian dateFromComponents:comps]; 28 | [comps release]; 29 | [gregorian release]; 30 | return date; 31 | } 32 | 33 | + (NSDate*) local:(int)year month:(int)month day:(int)day hours:(int)hours minutes:(int)minutes { 34 | return [NSDate local:year month:month day:day hours:hours minutes:minutes seconds:0]; 35 | } 36 | 37 | + (NSDate*) local:(int)year month:(int)month day:(int)day hours:(int)hours { 38 | return [NSDate local:year month:month day:day hours:hours minutes:0 seconds:0]; 39 | } 40 | 41 | + (NSDate*) local:(int)year month:(int)month day:(int)day { 42 | return [NSDate local:year month:month day:day hours:0 minutes:0 seconds:0]; 43 | } 44 | 45 | + (NSDate*) local:(int)year month:(int)month { 46 | return [NSDate local:year month:month day:1 hours:0 minutes:0 seconds:0]; 47 | } 48 | 49 | + (NSDate*) local:(int)year { 50 | return [NSDate local:year month:1 day:1 hours:0 minutes:0 seconds:0]; 51 | } 52 | 53 | + (NSDate*) parse:(NSString*)date { 54 | NSDateFormatter *inputFormatter = [[NSDateFormatter alloc] init]; 55 | if ([date length] >= 19) { 56 | [inputFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"]; 57 | } else if ([date length] == 16) { 58 | [inputFormatter setDateFormat:@"yyyy-MM-dd HH:mm"]; 59 | } else if ([date length] == 13) { 60 | [inputFormatter setDateFormat:@"yyyy-MM-dd HH"]; 61 | } else { 62 | [inputFormatter setDateFormat:@"yyyy-MM-dd"]; 63 | } 64 | [inputFormatter autorelease]; 65 | return [inputFormatter dateFromString:date]; 66 | } 67 | 68 | #pragma - 69 | #pragma Formatter 70 | 71 | - (NSString*) toFormattedString:(NSString*)format { 72 | time_t unixTime = (time_t) [self timeIntervalSince1970]; 73 | struct tm timeStruct; 74 | localtime_r(&unixTime, &timeStruct); 75 | 76 | char buffer[30]; 77 | strftime(buffer, 30, [[NSDate formatter:format] cStringUsingEncoding:[NSString defaultCStringEncoding]], &timeStruct); 78 | NSString* output = [NSString stringWithCString:buffer encoding:[NSString defaultCStringEncoding]]; 79 | return output; 80 | } 81 | 82 | + (NSString*) formatter:(NSString*)format { 83 | NSString* formatter = nil; 84 | if ([format isEqualToString:@"short"]) { 85 | formatter = @"%d %b %H:%M"; 86 | } else if ([format isEqualToString:@"long"]) { 87 | formatter = @"%B %d, %Y %H:%M"; 88 | } else if ([format isEqualToString:@"db"]) { 89 | formatter = @"%Y-%m-%d %H:%M:%S"; 90 | } else if ([format isEqualToString:@"number"]) { 91 | formatter = @"%Y%m%d%H%M%S"; 92 | } else if ([format isEqualToString:@"rfc822"]) { 93 | formatter = @"%a, %d %b %Y %H:%M:%S"; 94 | } else if ([format isEqualToString:@"rfc3339"]) { 95 | formatter = @"%Y-%m-%dT%H:%M:%S%Z"; 96 | } else { 97 | formatter = @"%Y-%m-%d %H:%M:%S"; 98 | } 99 | return formatter; 100 | } 101 | 102 | @end 103 | -------------------------------------------------------------------------------- /Kiwi/KWBlockRaiseMatcher.m: -------------------------------------------------------------------------------- 1 | // 2 | // Licensed under the terms in License.txt 3 | // 4 | // Copyright 2010 Allen Ding. All rights reserved. 5 | // 6 | 7 | #import "KWBlockRaiseMatcher.h" 8 | #import "KWBlock.h" 9 | 10 | @interface KWBlockRaiseMatcher() 11 | 12 | #pragma mark - 13 | #pragma mark Properties 14 | 15 | @property (nonatomic, readwrite, retain) NSException *exception; 16 | @property (nonatomic, readwrite, retain) NSException *actualException; 17 | 18 | @end 19 | 20 | @implementation KWBlockRaiseMatcher 21 | 22 | #pragma mark - 23 | #pragma mark Initializing 24 | 25 | - (void)dealloc { 26 | [exception release]; 27 | [actualException release]; 28 | [super dealloc]; 29 | } 30 | 31 | #pragma mark - 32 | #pragma mark Properties 33 | 34 | @synthesize exception; 35 | @synthesize actualException; 36 | 37 | #pragma mark - 38 | #pragma mark Getting Matcher Strings 39 | 40 | + (NSArray *)matcherStrings { 41 | return [NSArray arrayWithObjects:@"raise", 42 | @"raiseWithName:", 43 | @"raiseWithReason:", 44 | @"raiseWithName:reason:", nil]; 45 | } 46 | 47 | #pragma mark - 48 | #pragma mark Matching 49 | 50 | - (BOOL)evaluate { 51 | if (![self.subject isKindOfClass:[KWBlock class]]) 52 | [NSException raise:@"KWMatcherException" format:@"subject must be a KWBlock"]; 53 | 54 | @try { 55 | [self.subject call]; 56 | } @catch (NSException *anException) { 57 | self.actualException = anException; 58 | 59 | if ([self.exception name] != nil && ![[self.exception name] isEqualToString:[anException name]]) 60 | return NO; 61 | 62 | if ([self.exception reason] != nil && ![[self.exception reason] isEqualToString:[anException reason]]) 63 | return NO; 64 | 65 | return YES; 66 | } 67 | 68 | return NO; 69 | } 70 | 71 | #pragma mark - 72 | #pragma mark Getting Failure Messages 73 | 74 | + (NSString *)exceptionPhraseWithException:(NSException *)anException { 75 | if (anException == nil) 76 | return @"nothing"; 77 | 78 | NSString *namePhrase = nil; 79 | 80 | if ([anException name] == nil) 81 | namePhrase = @"exception"; 82 | else 83 | namePhrase = [anException name]; 84 | 85 | if ([anException reason] == nil) 86 | return namePhrase; 87 | 88 | return [NSString stringWithFormat:@"%@ \"%@\"", namePhrase, [anException reason]]; 89 | } 90 | 91 | - (NSString *)failureMessageForShould { 92 | return [NSString stringWithFormat:@"expected %@, but %@ raised", 93 | [[self class] exceptionPhraseWithException:self.exception], 94 | [[self class] exceptionPhraseWithException:self.actualException]]; 95 | } 96 | 97 | - (NSString *)failureMessageForShouldNot { 98 | return [NSString stringWithFormat:@"expected %@ not to be raised", 99 | [[self class] exceptionPhraseWithException:self.actualException]]; 100 | } 101 | 102 | #pragma mark - 103 | #pragma mark Configuring Matchers 104 | 105 | - (void)raise { 106 | [self raiseWithName:nil reason:nil]; 107 | } 108 | 109 | - (void)raiseWithName:(NSString *)aName { 110 | [self raiseWithName:aName reason:nil]; 111 | } 112 | 113 | - (void)raiseWithReason:(NSString *)aReason { 114 | [self raiseWithName:nil reason:aReason]; 115 | } 116 | 117 | - (void)raiseWithName:(NSString *)aName reason:(NSString *)aReason { 118 | self.exception = [NSException exceptionWithName:aName reason:aReason userInfo:nil]; 119 | } 120 | 121 | - (NSString *)description 122 | { 123 | return [NSString stringWithFormat:@"raise %@", [[self class] exceptionPhraseWithException:self.exception]]; 124 | } 125 | 126 | @end 127 | --------------------------------------------------------------------------------