Browse files

Upgraded QUnit..m

  • Loading branch information...
1 parent 5d2a3cc commit f7b209245ee235dcbf1d728615d8673f6468feef Kevin Malakoff committed Jul 30, 2012
View
26 SubjectiveScript.m.xcodeproj/project.pbxproj
@@ -7,6 +7,8 @@
objects = {
/* Begin PBXBuildFile section */
+ 0A02E1B115C69E70006BD268 /* QUnitTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 0A02E1AE15C69E70006BD268 /* QUnitTests.m */; };
+ 0A02E1B215C69E70006BD268 /* QUWrap.m in Sources */ = {isa = PBXBuildFile; fileRef = 0A02E1B015C69E70006BD268 /* QUWrap.m */; };
0A15526F15C54CD1006B9219 /* SS+System.h in Headers */ = {isa = PBXBuildFile; fileRef = 0A15526D15C54CD1006B9219 /* SS+System.h */; };
0A15527015C54CD1006B9219 /* SS+System.m in Sources */ = {isa = PBXBuildFile; fileRef = 0A15526E15C54CD1006B9219 /* SS+System.m */; };
0A15527115C54CD1006B9219 /* SS+System.m in Sources */ = {isa = PBXBuildFile; fileRef = 0A15526E15C54CD1006B9219 /* SS+System.m */; };
@@ -98,8 +100,6 @@
0AF1939115C5454900937CC7 /* SS+Functions.m in Sources */ = {isa = PBXBuildFile; fileRef = 0AF1938B15C5454900937CC7 /* SS+Functions.m */; };
0AF1939215C5454900937CC7 /* SS+Functions.m in Sources */ = {isa = PBXBuildFile; fileRef = 0AF1938B15C5454900937CC7 /* SS+Functions.m */; };
0AF1939315C5454900937CC7 /* SSArguments.h in Headers */ = {isa = PBXBuildFile; fileRef = 0AF1938C15C5454900937CC7 /* SSArguments.h */; };
- 0AF1939D15C54A2000937CC7 /* QUnit+Tests.m in Sources */ = {isa = PBXBuildFile; fileRef = 0AF1939A15C54A2000937CC7 /* QUnit+Tests.m */; };
- 0AF1939E15C54A2000937CC7 /* QUnit.m in Sources */ = {isa = PBXBuildFile; fileRef = 0AF1939C15C54A2000937CC7 /* QUnit.m */; };
0AFE255415B59CD1008A8BA9 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 0AFE255315B59CD1008A8BA9 /* Foundation.framework */; };
0AFE255A15B59CD1008A8BA9 /* SubjectiveScript.m in Sources */ = {isa = PBXBuildFile; fileRef = 0AFE255915B59CD1008A8BA9 /* SubjectiveScript.m */; };
0AFE256215B59CD1008A8BA9 /* SenTestingKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 0AFE256115B59CD1008A8BA9 /* SenTestingKit.framework */; };
@@ -121,6 +121,11 @@
/* End PBXContainerItemProxy section */
/* Begin PBXFileReference section */
+ 0A02E1AC15C69E70006BD268 /* QUnit.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = QUnit.h; sourceTree = "<group>"; };
+ 0A02E1AD15C69E70006BD268 /* QUnitTests.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = QUnitTests.h; sourceTree = "<group>"; };
+ 0A02E1AE15C69E70006BD268 /* QUnitTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = QUnitTests.m; sourceTree = "<group>"; };
+ 0A02E1AF15C69E70006BD268 /* QUWrap.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = QUWrap.h; sourceTree = "<group>"; };
+ 0A02E1B015C69E70006BD268 /* QUWrap.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = QUWrap.m; sourceTree = "<group>"; };
0A15526D15C54CD1006B9219 /* SS+System.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "SS+System.h"; sourceTree = "<group>"; };
0A15526E15C54CD1006B9219 /* SS+System.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "SS+System.m"; sourceTree = "<group>"; };
0A2B796D15C674690020D370 /* ISO8601DateFormatter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ISO8601DateFormatter.h; sourceTree = "<group>"; };
@@ -201,10 +206,6 @@
0AF1938A15C5454900937CC7 /* SS+Functions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "SS+Functions.h"; sourceTree = "<group>"; };
0AF1938B15C5454900937CC7 /* SS+Functions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "SS+Functions.m"; sourceTree = "<group>"; };
0AF1938C15C5454900937CC7 /* SSArguments.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SSArguments.h; sourceTree = "<group>"; };
- 0AF1939915C54A2000937CC7 /* QUnit+Tests.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "QUnit+Tests.h"; sourceTree = "<group>"; };
- 0AF1939A15C54A2000937CC7 /* QUnit+Tests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "QUnit+Tests.m"; sourceTree = "<group>"; };
- 0AF1939B15C54A2000937CC7 /* QUnit.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = QUnit.h; sourceTree = "<group>"; };
- 0AF1939C15C54A2000937CC7 /* QUnit.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = QUnit.m; sourceTree = "<group>"; };
0AFE255015B59CD1008A8BA9 /* libSubjectiveScript.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libSubjectiveScript.a; sourceTree = BUILT_PRODUCTS_DIR; };
0AFE255315B59CD1008A8BA9 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; };
0AFE255715B59CD1008A8BA9 /* SubjectiveScript-Prefix.pch */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "SubjectiveScript-Prefix.pch"; sourceTree = "<group>"; };
@@ -390,10 +391,11 @@
0AF1939815C54A2000937CC7 /* QUnitTestCase.m */ = {
isa = PBXGroup;
children = (
- 0AF1939915C54A2000937CC7 /* QUnit+Tests.h */,
- 0AF1939A15C54A2000937CC7 /* QUnit+Tests.m */,
- 0AF1939B15C54A2000937CC7 /* QUnit.h */,
- 0AF1939C15C54A2000937CC7 /* QUnit.m */,
+ 0A02E1AC15C69E70006BD268 /* QUnit.h */,
+ 0A02E1AD15C69E70006BD268 /* QUnitTests.h */,
+ 0A02E1AE15C69E70006BD268 /* QUnitTests.m */,
+ 0A02E1AF15C69E70006BD268 /* QUWrap.h */,
+ 0A02E1B015C69E70006BD268 /* QUWrap.m */,
);
path = QUnitTestCase.m;
sourceTree = "<group>";
@@ -667,8 +669,6 @@
0AF1938315C53DB400937CC7 /* NSNumber+JavaScript.m in Sources */,
0AF1938F15C5454900937CC7 /* NSString+Versioning.m in Sources */,
0AF1939215C5454900937CC7 /* SS+Functions.m in Sources */,
- 0AF1939D15C54A2000937CC7 /* QUnit+Tests.m in Sources */,
- 0AF1939E15C54A2000937CC7 /* QUnit.m in Sources */,
0A15527115C54CD1006B9219 /* SS+System.m in Sources */,
0AC6D60B15C618F6004C3000 /* SS+JavaScriptTests.m in Sources */,
0AC6D60E15C6190E004C3000 /* NSObject+JavaScriptTests.m in Sources */,
@@ -685,6 +685,8 @@
0AC6D62F15C61A86004C3000 /* String+SSTests.m in Sources */,
0AC6D63215C61D72004C3000 /* Functions+JavaScriptTests.m in Sources */,
0A2B797115C674690020D370 /* ISO8601DateFormatter.m in Sources */,
+ 0A02E1B115C69E70006BD268 /* QUnitTests.m in Sources */,
+ 0A02E1B215C69E70006BD268 /* QUWrap.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
View
2 SubjectiveScriptTests/JavaScript/Array+JavaScriptTests.m
@@ -14,7 +14,7 @@ @implementation Array_JavaScriptTests
- (void)test_length
{
- equalI(AI(1,2,3).length, 3, @"length works");
+ equal(AI(1,2,3).length, 3, @"length works");
}
- (void)test_hasOwnProperty
View
2 SubjectiveScriptTests/SubjectiveScriptTests.m
@@ -15,7 +15,7 @@ @implementation SubjectiveScriptTests
- (void)testArray
{
A* people = AO(OKV({@"name", @"curly"}, {@"age", N.I(50)}), OKV({@"name", @"moe"}, {@"age", N.I(30)}));
- equalI(people.count, 2, @"right number of people");
+ equal(people.count, 2, @"right number of people");
}
@end
View
19 SubjectiveScriptTests/Vendor/QUnitTestCase.m/QUWrap.h
@@ -0,0 +1,19 @@
+//
+// QUWrap.h
+// QUnit.m
+//
+// Created by Kevin Malakoff on 7/30/12.
+// Copyright (c) 2012 Kevin Malakoff. All rights reserved.
+//
+
+#import <Foundation/Foundation.h>
+
+
+@interface QUWrap : NSObject
+
++ (id)wrap:(void*)value type:(char[2])type;
+
+@end
+
+
+#define QUWrapValue(_value) [QUWrap wrap:(void*)_value type:@encode(__typeof__(_value))]
View
45 SubjectiveScriptTests/Vendor/QUnitTestCase.m/QUWrap.m
@@ -0,0 +1,45 @@
+//
+// QUWrap.m
+// QUnit.m
+//
+// Created by Kevin Malakoff on 7/30/12.
+// Copyright (c) 2012 Kevin Malakoff. All rights reserved.
+//
+
+#import "QUWrap.h"
+#import <objc/runtime.h>
+
+@implementation QUWrap
+
++ (id)wrap:(void*)value type:(char[2])type
+{
+ NSAssert(type[0]!=_C_FLT && type[0]!=_C_DBL, @"QUnit current doesn't support floats and doubles");
+
+ switch(type[0])
+ {
+ case _C_ID:
+#if __has_feature(objc_arc)
+ return (__bridge id)value;
+#else
+ return (id)value;
+#endif
+ case _C_INT:
+ return [NSNumber numberWithInt:(int)value];
+ case _C_UINT:
+ return [NSNumber numberWithUnsignedInt:(unsigned int)value];
+ case _C_LNG:
+ return [NSNumber numberWithInteger:(NSInteger)value];
+ case _C_ULNG:
+ return [NSNumber numberWithUnsignedInteger:(NSUInteger)value];
+ case _C_CHR:
+ return [NSNumber numberWithBool:(BOOL)value];
+ default:
+#if __has_feature(objc_arc)
+ return (__bridge id)value;
+#else
+ return (id)value;
+#endif
+ }
+}
+
+@end
View
31 SubjectiveScriptTests/Vendor/QUnitTestCase.m/QUnit.h
@@ -27,54 +27,45 @@
// OTHER DEALINGS IN THE SOFTWARE.
//
-#import <SenTestingKit/SenTestingKit.h> // adds QUnit syntax on top of SenTestingKit
-
-@interface QUnit : NSObject
-@end
-
-#ifndef QUNIT_TESTS
-#define QUNIT_TESTS
-#import "QUnit+Tests.h"
+#import "QUnitTests.h"
+#import "QUWrap.h"
/////////////////////////////
// Equality
/////////////////////////////
#define equal(_actual, _expected, _description, ...) \
- [QUnit equal:self actual:_actual expected:_expected expression:[NSString stringWithFormat:@"(%s) == (%s)", #_actual, #_expected] description:[NSString stringWithFormat:(_description), ##__VA_ARGS__] filename:[NSString stringWithUTF8String:__FILE__] lineNumber:__LINE__ strict:NO];
-
-#define equalI(_actual, _expected, _description, ...) \
- [QUnit equal:self actual:[NSNumber numberWithInteger:_actual] expected:[NSNumber numberWithInteger:_expected] expression:[NSString stringWithFormat:@"(%s) == (%s)", #_actual, #_expected] description:[NSString stringWithFormat:(_description), ##__VA_ARGS__] filename:[NSString stringWithUTF8String:__FILE__] lineNumber:__LINE__ strict:NO];
+ [QUnitTests equal:self actual:QUWrapValue(_actual) expected:QUWrapValue(_expected) expression:[NSString stringWithFormat:@"(%s) == (%s)", #_actual, #_expected] description:[NSString stringWithFormat:(_description), ##__VA_ARGS__] filename:[NSString stringWithUTF8String:__FILE__] lineNumber:__LINE__ strict:NO];
#define strictEqual(_actual, _expected, _description, ...) \
- [QUnit equal:self actual:_actual expected:_expected expression:[NSString stringWithFormat:@"(%s) == (%s)", #_actual, #_expected] description:[NSString stringWithFormat:(_description), ##__VA_ARGS__] filename:[NSString stringWithUTF8String:__FILE__] lineNumber:__LINE__ strict:YES];
+ [QUnitTests equal:self actual:QUWrapValue(_actual) expected:QUWrapValue(_expected) expression:[NSString stringWithFormat:@"(%s) == (%s)", #_actual, #_expected] description:[NSString stringWithFormat:(_description), ##__VA_ARGS__] filename:[NSString stringWithUTF8String:__FILE__] lineNumber:__LINE__ strict:YES];
#define deepEqual(_actual, _expected, _description, ...) \
- [QUnit deepEqual:self actual:_actual expected:_expected expression:[NSString stringWithFormat:@"(%s) == (%s)", #_actual, #_expected] description:[NSString stringWithFormat:(_description), ##__VA_ARGS__] filename:[NSString stringWithUTF8String:__FILE__] lineNumber:__LINE__];
+ [QUnitTests deepEqual:self actual:QUWrapValue(_actual) expected:QUWrapValue(_expected) expression:[NSString stringWithFormat:@"(%s) == (%s)", #_actual, #_expected] description:[NSString stringWithFormat:(_description), ##__VA_ARGS__] filename:[NSString stringWithUTF8String:__FILE__] lineNumber:__LINE__];
/////////////////////////////
// Non-Equality
/////////////////////////////
#define notEqual(_actual, _expected, _description, ...) \
- [QUnit notEqual:self actual:_actual expected:_expected expression:[NSString stringWithFormat:@"(%s) == (%s)", #_actual, #_expected] description:[NSString stringWithFormat:(_description), ##__VA_ARGS__] filename:[NSString stringWithUTF8String:__FILE__] lineNumber:__LINE__ strict:NO];
+ [QUnitTests notEqual:self actual:QUWrapValue(_actual) expected:QUWrapValue(_expected) expression:[NSString stringWithFormat:@"(%s) == (%s)", #_actual, #_expected] description:[NSString stringWithFormat:(_description), ##__VA_ARGS__] filename:[NSString stringWithUTF8String:__FILE__] lineNumber:__LINE__ strict:NO];
#define notStrictEqual(_actual, _expected, _description, ...) \
- [QUnit notEqual:self actual:_actual expected:_expected expression:[NSString stringWithFormat:@"(%s) == (%s)", #_actual, #_expected] description:[NSString stringWithFormat:(_description), ##__VA_ARGS__] filename:[NSString stringWithUTF8String:__FILE__] lineNumber:__LINE__ strict:YES];
+ [QUnitTests notEqual:self actual:QUWrapValue(_actual) expected:QUWrapValue(_expected) expression:[NSString stringWithFormat:@"(%s) == (%s)", #_actual, #_expected] description:[NSString stringWithFormat:(_description), ##__VA_ARGS__] filename:[NSString stringWithUTF8String:__FILE__] lineNumber:__LINE__ strict:YES];
/////////////////////////////
// Acceptance
/////////////////////////////
#define ok(_result, _description, ...) \
- [QUnit ok:self result:_result expression:[NSString stringWithFormat:@"(%s) == true", #_result] description:[NSString stringWithFormat:(_description), ##__VA_ARGS__] filename:[NSString stringWithUTF8String:__FILE__] lineNumber:__LINE__];
+ [QUnitTests ok:self result:_result expression:[NSString stringWithFormat:@"(%s) == true", #_result] description:[NSString stringWithFormat:(_description), ##__VA_ARGS__] filename:[NSString stringWithUTF8String:__FILE__] lineNumber:__LINE__];
/////////////////////////////
// Exceptions
/////////////////////////////
#define raises(_callback, _expectedExceptionName, _description, ...) \
- [QUnit raises:self callback:_callback expectedExceptionName:_expectedExceptionName expression:[NSString stringWithFormat:@"(%s)", #_callback] description:[NSString stringWithFormat:(_description), ##__VA_ARGS__] filename:[NSString stringWithUTF8String:__FILE__] lineNumber:__LINE__];
+ [QUnitTests raises:self callback:_callback expectedExceptionName:_expectedExceptionName expression:[NSString stringWithFormat:@"(%s)", #_callback] description:[NSString stringWithFormat:(_description), ##__VA_ARGS__] filename:[NSString stringWithUTF8String:__FILE__] lineNumber:__LINE__];
/////////////////////////////
// Asynchronous
@@ -91,6 +82,4 @@
[self failWithException:([NSException failureInFile:[NSString stringWithUTF8String:__FILE__] atLine:__LINE__ withDescription:@"QUnit: async test timed out"])]; \
}); \
_callback(); \
-}
-
-#endif
+}
View
13 SubjectiveScriptTests/Vendor/QUnitTestCase.m/QUnit.m
@@ -1,13 +0,0 @@
-//
-// QUnit.m
-// QUnit
-//
-// Created by Kevin Malakoff on 7/29/12.
-// Copyright (c) 2012 Kevin Malakoff. All rights reserved.
-//
-
-#import "QUnit.h"
-
-@implementation QUnit
-
-@end
View
7 ...ests/Vendor/QUnitTestCase.m/QUnit+Tests.h → ...Tests/Vendor/QUnitTestCase.m/QUnitTests.h
@@ -1,5 +1,5 @@
//
-// QUnit.h
+// QUnitTests.h
// QUnit.m
//
// Created by Kevin Malakoff on 7/23/12.
@@ -27,9 +27,10 @@
// OTHER DEALINGS IN THE SOFTWARE.
//
-#import "QUnit.h"
+#import <Foundation/Foundation.h>
+#import <SenTestingKit/SenTestingKit.h> // adds QUnit syntax on top of SenTestingKit
-@interface QUnit (Tests)
+@interface QUnitTests : NSObject
+ (void)equal:(SenTestCase*)testCase actual:(id)actual expected:(id)expected expression:(NSString*)expression description:(NSString*)description filename:(NSString*)filename lineNumber:(NSUInteger)lineNumber strict:(BOOL)strict;
+ (void)deepEqual:(SenTestCase*)testCase actual:(id)actual expected:(id)expected expression:(NSString*)expression description:(NSString*)description filename:(NSString*)filename lineNumber:(NSUInteger)lineNumber;
View
10 ...ests/Vendor/QUnitTestCase.m/QUnit+Tests.m → ...Tests/Vendor/QUnitTestCase.m/QUnitTests.m
@@ -1,5 +1,5 @@
//
-// QUnitTest.m
+// QUnitTests.m
// QUnit.m
//
// Created by Kevin Malakoff on 7/23/12.
@@ -27,9 +27,9 @@
// OTHER DEALINGS IN THE SOFTWARE.
//
-#import "QUnit.h"
+#import "QUnitTests.h"
-@implementation QUnit (Tests)
+@implementation QUnitTests
+ (void)equal:(SenTestCase*)testCase actual:(id)actual expected:(id)expected expression:(NSString*)expression description:(NSString*)description filename:(NSString*)filename lineNumber:(NSUInteger)lineNumber strict:(BOOL)strict
{
@@ -72,12 +72,12 @@ + (void)deepEqual:(SenTestCase*)testCase actual:(id)actual expected:(id)expected
// check each element
for (NSInteger index=0; index<actualArray.count; index++) {
- [QUnit equal:testCase actual:[actualArray objectAtIndex:index] expected:[expectedArray objectAtIndex:index] expression:expression description:description filename:filename lineNumber:lineNumber strict:YES];
+ [QUnitTests equal:testCase actual:[actualArray objectAtIndex:index] expected:[expectedArray objectAtIndex:index] expression:expression description:description filename:filename lineNumber:lineNumber strict:YES];
}
}
else
- [QUnit equal:testCase actual:actual expected:expected expression:expression description:description filename:filename lineNumber:lineNumber strict:YES];
+ [QUnitTests equal:testCase actual:actual expected:expected expression:expression description:description filename:filename lineNumber:lineNumber strict:YES];
}
+ (void)notEqual:(SenTestCase*)testCase actual:(id)actual expected:(id)expected expression:(NSString*)expression description:(NSString*)description filename:(NSString*)filename lineNumber:(NSUInteger)lineNumber strict:(BOOL)strict

0 comments on commit f7b2092

Please sign in to comment.