Permalink
Browse files

Initial Commit

  • Loading branch information...
0 parents commit ef8cbfff110ed37e1dd956d016a36203c879702d @petejkim petejkim committed May 7, 2011
@@ -0,0 +1,8 @@
+.DS_Store
+*.xcworkspace
+xcuserdata
+.idea
+build/
+*.pbxuser
+*.mode1v3
+

Large diffs are not rendered by default.

Oops, something went wrong.
19 LICENSE
@@ -0,0 +1,19 @@
+Copyright (c) 2011 Peter Jihoon Kim
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
@@ -0,0 +1,17 @@
+# Expecta
+
+An Objective-C/Cocoa Matcher Library
+
+## STATUS
+
+Under development. Not quite usable at this point.
+
+## USAGE
+
+>`[expect(x).to beNil];` passes if `x` is `nil`
+>
+>`[expect(x).notTo beNil];` passes if `x` is not `nil`
+
+## LICENSE
+
+Copyright (c) 2011 Peter Jihoon Kim. This software is licensed under the MIT License.
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+ <key>CFBundleDevelopmentRegion</key>
+ <string>en</string>
+ <key>CFBundleExecutable</key>
+ <string>${EXECUTABLE_NAME}</string>
+ <key>CFBundleIdentifier</key>
+ <string>petejkim.${PRODUCT_NAME:rfc1034identifier}</string>
+ <key>CFBundleInfoDictionaryVersion</key>
+ <string>6.0</string>
+ <key>CFBundleName</key>
+ <string>${PRODUCT_NAME}</string>
+ <key>CFBundlePackageType</key>
+ <string>APPL</string>
+ <key>CFBundleShortVersionString</key>
+ <string>1.0</string>
+ <key>CFBundleSignature</key>
+ <string>????</string>
+ <key>CFBundleVersion</key>
+ <string>1</string>
+ <key>LSMinimumSystemVersion</key>
+ <string>${MACOSX_DEPLOYMENT_TARGET}</string>
+ <key>NSPrincipalClass</key>
+ <string>NSApplication</string>
+</dict>
+</plist>
@@ -0,0 +1,3 @@
+#ifdef __OBJC__
+ #import <Foundation/Foundation.h>
+#endif
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+ <key>CFBundleDevelopmentRegion</key>
+ <string>en</string>
+ <key>CFBundleExecutable</key>
+ <string>${EXECUTABLE_NAME}</string>
+ <key>CFBundleIdentifier</key>
+ <string>petejkim.${PRODUCT_NAME:rfc1034identifier}</string>
+ <key>CFBundleInfoDictionaryVersion</key>
+ <string>6.0</string>
+ <key>CFBundlePackageType</key>
+ <string>BNDL</string>
+ <key>CFBundleShortVersionString</key>
+ <string>1.0</string>
+ <key>CFBundleSignature</key>
+ <string>????</string>
+ <key>CFBundleVersion</key>
+ <string>1</string>
+</dict>
+</plist>
@@ -0,0 +1,8 @@
+//
+// Prefix header for all source files of the 'ExpectaTests' target in the 'ExpectaTests' project
+//
+
+#ifdef __OBJC__
+ #import <Foundation/Foundation.h>
+ #import <SenTestingKit/SenTestingKit.h>
+#endif
@@ -0,0 +1,5 @@
+#import <Cocoa/Cocoa.h>
+
+int main(int argc, char *argv[]) {
+ return NSApplicationMain(argc, (const char **)argv);
+}
@@ -0,0 +1,8 @@
+#import <Foundation/Foundation.h>
+#import "EXExpect.h"
+
+@interface EXExpect (BeNil)
+
+- (void)beNil;
+
+@end
@@ -0,0 +1,10 @@
+#import "EXExpect+BeNil.h"
+
+@implementation EXExpect (BeNil)
+
+- (void)beNil {
+ [self match:^BOOL{ return self.actual == nil; }
+ description:@"nil"];
+}
+
+@end
@@ -0,0 +1,29 @@
+#import <Foundation/Foundation.h>
+
+@interface EXExpect : NSObject {
+ id _actual;
+ id _testCase;
+ int _lineNumber;
+ char *_fileName;
+ BOOL _negative;
+}
+
+@property(nonatomic, assign) id actual;
+@property(nonatomic, assign) id testCase;
+@property(nonatomic) int lineNumber;
+@property(nonatomic) char *fileName;
+@property(nonatomic) BOOL negative;
+
+@property(nonatomic, readonly) id to;
+@property(nonatomic, readonly) id notTo;
+
+- (id)initWithActual:(id)actual testCase:(id)testCase lineNumber:(int)lineNumber fileName:(char *)fileName;
++ (EXExpect *)expectWithActual:(id)actual testCase:(id)testCase lineNumber:(int)lineNumber fileName:(char *)fileName;
+
+- (id)to;
+- (id)notTo;
+
+- (NSException *)failureExceptionWithDescription:(NSString *)description;
+- (void)match:(BOOL(^)())predicate description:(NSString *)description;
+
+@end
@@ -0,0 +1,60 @@
+#import "Expecta.h"
+#import "EXExpect.h"
+
+@interface NSObject (EXExpect_TestCase)
+- (void)failWithException:(NSException *)exception;
+@end
+
+@implementation EXExpect
+
+@synthesize actual=_actual, testCase=_testCase, negative=_negative, lineNumber=_lineNumber, fileName=_fileName;
+@dynamic to, notTo;
+
+- (id)initWithActual:(id)actual testCase:(id)testCase lineNumber:(int)lineNumber fileName:(char *)fileName {
+ self = [super init];
+ if(self) {
+ self.actual = actual;
+ self.testCase = testCase;
+ self.lineNumber = lineNumber;
+ self.fileName = fileName;
+ }
+ return self;
+}
+
++ (EXExpect *)expectWithActual:(id)actual testCase:(id)testCase lineNumber:(int)lineNumber fileName:(char *)fileName {
+ return [[[EXExpect alloc] initWithActual:actual testCase:(id)testCase lineNumber:lineNumber fileName:fileName] autorelease];
+}
+
+- (void)dealloc {
+ [super dealloc];
+}
+
+- (id)to {
+ return self;
+}
+
+- (id)notTo {
+ self.negative = YES;
+ return self;
+}
+
+- (NSException *)failureExceptionWithDescription:(NSString *)description {
+ NSString *reason = [NSString stringWithFormat:@"%s:%d expected: %@%@, got: %@",
+ self.fileName,
+ self.lineNumber,
+ (self.negative ? @"not " : @""),
+ description,
+ self.actual == nil ? @"nil" : [self.actual description]];
+ return [NSException exceptionWithName:ExpectaException reason:reason userInfo:nil];
+}
+
+- (void)match:(BOOL(^)())predicate description:(NSString *)description {
+ BOOL result = predicate();
+ result = self.negative ? !result : result;
+ if(!result) {
+ [self.testCase failWithException:[self failureExceptionWithDescription:description]];
+ }
+}
+
+@end
+
@@ -0,0 +1,6 @@
+#import "EXExpect.h"
+#import "EXExpect+BeNil.h"
+
+#define expect(actual) [EXExpect expectWithActual:(actual) testCase:self lineNumber:__LINE__ fileName:__FILE__]
+
+#define ExpectaException @"Expecta Error"
@@ -0,0 +1,8 @@
+@class EXExpect, FakeTestCase;
+
+@interface ExpectaTest : SenTestCase {
+ EXExpect *obj;
+ FakeTestCase *fakeTestCase;
+}
+
+@end
@@ -0,0 +1,39 @@
+#import "ExpectaTest.h"
+#import "FakeTestCase.h"
+#import "Expecta.h"
+
+#define assertPass(expr) \
+STAssertNoThrowSpecific((expr), NSException, @"")
+
+#define assertFail(expr, message) \
+STAssertThrowsSpecificNamed((expr), NSException, (message), @"")
+
+@implementation ExpectaTest
+
+- (void)setUp {
+ [super setUp];
+ fakeTestCase = [FakeTestCase new];
+ obj = [[EXExpect alloc] initWithActual:nil testCase:fakeTestCase lineNumber:123 fileName:"foo.m"];
+}
+
+- (void)tearDown {
+ [obj release];
+ [fakeTestCase release];
+ [super tearDown];
+}
+
+- (void)test_to_beNil {
+ obj.actual = nil;
+ assertPass([obj.to beNil]);
+ obj.actual = @"foo";
+ assertFail([obj.to beNil], @"foo.m:123 expected: nil, got: foo");
+}
+
+- (void)test_notTo_beNil {
+ obj.actual = @"foo";
+ assertPass([obj.notTo beNil]);
+ obj.actual = nil;
+ assertFail([obj.notTo beNil], @"foo.m:123 expected: not nil, got: nil");
+}
+
+@end
@@ -0,0 +1,5 @@
+@interface FakeTestCase : NSObject
+
+- (void)failWithException:(NSException *)exception;
+
+@end
@@ -0,0 +1,10 @@
+#import "FakeTestCase.h"
+
+@implementation FakeTestCase
+
+- (void)failWithException:(NSException *)exception {
+ NSException *e = [NSException exceptionWithName:[exception reason] reason:[exception reason] userInfo:nil];
+ [e raise];
+}
+
+@end

0 comments on commit ef8cbff

Please sign in to comment.