Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

test improvements, handler simplification with macro, some cleanup in…

… nu.nu
  • Loading branch information...
commit a22f3cf4140c8e41894893193ea8a1e1886240be 1 parent a6f3b50
@timburks authored
View
4 MacOS/Nu-framework/Nu.xcodeproj/project.pbxproj
@@ -69,6 +69,7 @@
2230622B13A54EDC00B67882 /* test_undo.nu in Resources */ = {isa = PBXBuildFile; fileRef = 223061FD13A54EDC00B67882 /* test_undo.nu */; };
2230622C13A54EDC00B67882 /* test_varargs.nu in Resources */ = {isa = PBXBuildFile; fileRef = 223061FE13A54EDC00B67882 /* test_varargs.nu */; };
224276FF11DD748600940005 /* Nu.h in Headers */ = {isa = PBXBuildFile; fileRef = 224276FE11DD748600940005 /* Nu.h */; };
+ 2256C21613AD134600830F69 /* handlers.m in Sources */ = {isa = PBXBuildFile; fileRef = 2256C21513AD134600830F69 /* handlers.m */; };
2276E5E013A5E4AB006A166B /* NuProperty.h in Headers */ = {isa = PBXBuildFile; fileRef = 2276E5DE13A5E4AB006A166B /* NuProperty.h */; };
2276E5E113A5E4AB006A166B /* NuProperty.m in Sources */ = {isa = PBXBuildFile; fileRef = 2276E5DF13A5E4AB006A166B /* NuProperty.m */; };
2276E5E213A5E4AB006A166B /* NuProperty.m in Sources */ = {isa = PBXBuildFile; fileRef = 2276E5DF13A5E4AB006A166B /* NuProperty.m */; };
@@ -251,6 +252,7 @@
223061FD13A54EDC00B67882 /* test_undo.nu */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = test_undo.nu; sourceTree = "<group>"; };
223061FE13A54EDC00B67882 /* test_varargs.nu */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = test_varargs.nu; sourceTree = "<group>"; };
224276FE11DD748600940005 /* Nu.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Nu.h; sourceTree = "<group>"; };
+ 2256C21513AD134600830F69 /* handlers.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = handlers.m; path = ../../../util/handlers.m; sourceTree = "<group>"; };
2276E5DE13A5E4AB006A166B /* NuProperty.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NuProperty.h; sourceTree = "<group>"; };
2276E5DF13A5E4AB006A166B /* NuProperty.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = NuProperty.m; sourceTree = "<group>"; };
228306F411DDBBD100A5C690 /* beautify.nu */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = beautify.nu; sourceTree = "<group>"; };
@@ -627,6 +629,7 @@
22EE2BFF13A4731600895861 /* NuApp */ = {
isa = PBXGroup;
children = (
+ 2256C21513AD134600830F69 /* handlers.m */,
22EE2C0813A4731600895861 /* NuAppDelegate.h */,
22EE2C0913A4731600895861 /* NuAppDelegate.m */,
22EE2C0013A4731600895861 /* Supporting Files */,
@@ -949,6 +952,7 @@
22EE2C6D13A4757B00895861 /* raw_api.c in Sources */,
22EE2C6F13A4757B00895861 /* types.c in Sources */,
2276E5E213A5E4AB006A166B /* NuProperty.m in Sources */,
+ 2256C21613AD134600830F69 /* handlers.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
View
21 MacOS/Nu-framework/Nu.xcodeproj/xcuserdata/tim.xcuserdatad/xcdebugger/Breakpoints.xcbkptlist
@@ -1,21 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<Bucket
- type = "1"
- version = "1.0">
- <FileBreakpoints>
- <FileBreakpoint
- shouldBeEnabled = "No"
- ignoreCount = "0"
- continueAfterRunningActions = "No"
- isPathRelative = "0"
- filePath = "/Volumes/Users/tim/Desktop/Repositories/nu/objc/NuClass.m"
- timestampString = "329806178.235263"
- startingColumnNumber = "9223372036854775807"
- endingColumnNumber = "9223372036854775807"
- startingLineNumber = "277"
- endingLineNumber = "277"
- landmarkName = "-propertyWithName:"
- landmarkType = "5">
- </FileBreakpoint>
- </FileBreakpoints>
-</Bucket>
View
6 MacOS/Nu-framework/NuApp/NuAppDelegate.m
@@ -56,9 +56,7 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
encoding:NSUTF8StringEncoding
error:NULL];
[[Nu sharedParser] parseEval:s];
-
- [[Nu sharedParser] parseEval:@"(global uname (do () \"iOS\"))"];
-
+
NSString *resourceDirectory = [[NSBundle mainBundle] resourcePath];
NSArray *files = [[NSFileManager defaultManager]
@@ -78,7 +76,7 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
}
}
[regex release];
-
+ NSLog(@"running tests");
[[Nu sharedParser] parseEval:@"(NuTestCase runAllTests)"];
NSLog(@"ok");
return YES;
View
12 nu/match.nu
@@ -91,7 +91,7 @@
;; Patterns like (head . tail) recurse.
((and (pair? pat)
(pair? (pat cdr))
- (eq '. (second pat))
+ (eq '. (pat second))
(pair? ((pat cdr) cdr))
(eq nil (((pat cdr) cdr) cdr)))
(let ((bindings1 (destructure (pat 0) (seq 0)))
@@ -103,8 +103,8 @@
((and (pair? pat)
(eq 'quote (pat 0))
(pair? (pat cdr))
- (symbol? (second pat)))
- (if (eq (second pat) seq)
+ (symbol? (pat second)))
+ (if (eq (pat second) seq)
(then '()) ; literal symbol match produces no bindings
(else (throw* "NuMatchException"
"Failed match of literal symbol #{pat} to #{seq}"))))
@@ -152,7 +152,7 @@
;; Patterns like (head . tail)
((and (pair? pat)
(pair? (cdr pat))
- (eq '. (second pat))
+ (eq '. (pat second))
(pair? (cdr (cdr pat)))
(eq nil (cdr (cdr (cdr pat)))))
;(puts "mdest: (h . t): #{pat} #{seq}")
@@ -164,9 +164,9 @@
((and (pair? pat)
(eq 'quote (car pat))
(pair? (cdr pat))
- (symbol? (second pat)))
+ (symbol? (pat second)))
;(puts "mdest: 'Literal: #{pat} #{seq}")
- (if (eq (second pat) seq)
+ (if (eq (pat second) seq)
(then '()) ; literal symbol match produces no bindings
(else (throw* "NuMatchException"
"Failed match of literal symbol #{pat} to #{seq}"))))
View
31 nu/nu.nu
@@ -18,17 +18,6 @@
(global NSUTF8StringEncoding 4)
(global NSLog (NuBridgedFunction functionWithName:"NSLog" signature:"v@"))
-;; Warning! I want to deprecate these.
-(global second (do (my-list) (car (cdr my-list))))
-(global third (do (my-list) (car (cdr (cdr my-list)))))
-(global fourth (do (my-list) (car (cdr (cdr (cdr my-list))))))
-(global fifth (do (my-list) (car (cdr (cdr (cdr (cdr my-list)))))))
-(global sixth (do (my-list) (car (cdr (cdr (cdr (cdr (cdr my-list))))))))
-(global seventh (do (my-list) (car (cdr (cdr (cdr (cdr (cdr (cdr my-list)))))))))
-(global eighth (do (my-list) (car (cdr (cdr (cdr (cdr (cdr (cdr (cdr my-list))))))))))
-(global ninth (do (my-list) (car (cdr (cdr (cdr (cdr (cdr (cdr (cdr (cdr my-list)))))))))))
-(global tenth (do (my-list) (car (cdr (cdr (cdr (cdr (cdr (cdr (cdr (cdr (cdr my-list))))))))))))
-
(global rand
(do (maximum)
(let ((r (NuMath random)))
@@ -159,7 +148,7 @@
(else (do (a b) (a compare:b)))))
(((apply array ls) sortedArrayUsingBlock:block) list)))
-(if (eq (uname) "Darwin") ;; throw is currently only available with the Darwin runtime
+(if (or (eq (uname) "Darwin") (eq (uname "iOS"))) ;; throw is currently only available with the Darwin runtime
(then
;; Evaluates an expression and raises a NuAssertionFailure if the result is false.
;; For example (assert (eq 1 1)) does nothing but (assert (eq (+ 1 1) 1)) throws
@@ -186,8 +175,6 @@
(global throw (macro-0 _ (NSLog "warning: throw is unavailable")))))
-
-
;; Returns an array of filenames matching a given pattern.
;; the pattern is a string that is converted into a regular expression.
(global filelist
@@ -221,22 +208,6 @@
(else (self appendString:object))))
(class NSObject
-
- ;; Write objects as XML property lists (only for NSData, NSString, NSNumber, NSDate, NSArray, and NSDictionary objects)
- (- writeToPropertyList:name is
- (set xmlData (NSPropertyListSerialization dataFromPropertyList:self
- format:100 ;; NSPropertyListXMLFormat_v1_0
- errorDescription:nil))
- (if xmlData (xmlData writeToFile:name atomically:YES)
- (else (puts ((error value) description)))))
-
- ;; Read objects from property lists
- (+ readFromPropertyList:name is
- (NSPropertyListSerialization propertyListFromData:(NSData dataWithContentsOfFile:name)
- mutabilityOption:0 ;; NSPropertyListImmutable
- format:nil
- errorDescription:nil))
-
(- XMLPropertyListRepresentation is
(NSPropertyListSerialization dataFromPropertyList:self
format:100 ;; NSPropertyListXMLFormat_v1_0
View
6 nu/test.nu
@@ -67,11 +67,11 @@
(((testClass alloc) init) run))))
(puts "")
- (puts "All: completed #{$tests} tests/#{$assertions} assertions/#{$failures} failures/#{$errors} errors")
+ (NSLog "All: completed #{$tests} tests/#{$assertions} assertions/#{$failures} failures/#{$errors} errors")
(puts "")
(if (or $failures $errors)
- (then (puts "FAILURE (#{$failures} failures, #{$errors} errors)"))
- (else (puts "SUCCESS (0 failures, 0 errors)")))
+ (then (NSLog "FAILURE (#{$failures} failures, #{$errors} errors)"))
+ (else (NSLog "SUCCESS (0 failures, 0 errors)")))
(+ $failures $errors))
;; Run all the test cases for a particular instance of NuTestCase.
View
176 objc/NuHandler.m
@@ -137,122 +137,35 @@ static IMP handler_returning_void(void *userdata) {
});
}
-static IMP handler_returning_id(void *userdata) {
- return imp_implementationWithBlock(^(id receiver, ...) {
- struct handler_description description;
- description.handler = NULL;
- description.description = userdata;
- va_list ap;
- va_start(ap, receiver);
- id result;
- nu_handler(&result, &description, receiver, ap);
- return result;
- });
-}
-
-static IMP handler_returning_int(void *userdata) {
- return imp_implementationWithBlock(^(id receiver, ...) {
- struct handler_description description;
- description.handler = NULL;
- description.description = userdata;
- va_list ap;
- va_start(ap, receiver);
- int result;
- nu_handler(&result, &description, receiver, ap);
- return result;
- });
-}
-
-static IMP handler_returning_bool(void *userdata) {
- return imp_implementationWithBlock(^(id receiver, ...) {
- struct handler_description description;
- description.handler = NULL;
- description.description = userdata;
- va_list ap;
- va_start(ap, receiver);
- BOOL result;
- nu_handler(&result, &description, receiver, ap);
- return result;
- });
-}
-
-static IMP handler_returning_float(void *userdata) {
- return imp_implementationWithBlock(^(id receiver, ...) {
- struct handler_description description;
- description.handler = NULL;
- description.description = userdata;
- va_list ap;
- va_start(ap, receiver);
- float result;
- nu_handler(&result, &description, receiver, ap);
- return result;
- });
-}
-
-static IMP handler_returning_double(void *userdata) {
- return imp_implementationWithBlock(^(id receiver, ...) {
- struct handler_description description;
- description.handler = NULL;
- description.description = userdata;
- va_list ap;
- va_start(ap, receiver);
- double result;
- nu_handler(&result, &description, receiver, ap);
- return result;
- });
-}
-
-static IMP handler_returning_cgrect(void *userdata) {
- return imp_implementationWithBlock(^(id receiver, ...) {
- struct handler_description description;
- description.handler = NULL;
- description.description = userdata;
- va_list ap;
- va_start(ap, receiver);
- CGRect result;
- nu_handler(&result, &description, receiver, ap);
- return result;
- });
-}
-
-static IMP handler_returning_cgpoint(void *userdata) {
- return imp_implementationWithBlock(^(id receiver, ...) {
- struct handler_description description;
- description.handler = NULL;
- description.description = userdata;
- va_list ap;
- va_start(ap, receiver);
- CGPoint result;
- nu_handler(&result, &description, receiver, ap);
- return result;
- });
-}
-
-static IMP handler_returning_cgsize(void *userdata) {
- return imp_implementationWithBlock(^(id receiver, ...) {
- struct handler_description description;
- description.handler = NULL;
- description.description = userdata;
- va_list ap;
- va_start(ap, receiver);
- CGSize result;
- nu_handler(&result, &description, receiver, ap);
- return result;
- });
-}
-
-static IMP handler_returning_nsrange(void *userdata) {
- return imp_implementationWithBlock(^(id receiver, ...) {
- struct handler_description description;
- description.handler = NULL;
- description.description = userdata;
- va_list ap;
- va_start(ap, receiver);
- NSRange result;
- nu_handler(&result, &description, receiver, ap);
- return result;
- });
-}
+#define MAKE_HANDLER_WITH_TYPE(type) \
+static IMP handler_returning_ ## type (void* userdata) \
+{ \
+ return imp_implementationWithBlock(^(id receiver, ...) { \
+ struct handler_description description; \
+ description.handler = NULL; \
+ description.description = userdata; \
+ va_list ap; \
+ va_start(ap, receiver); \
+ type result; \
+ nu_handler(&result, &description, receiver, ap); \
+ return result; \
+ }); \
+}
+
+MAKE_HANDLER_WITH_TYPE(id)
+MAKE_HANDLER_WITH_TYPE(int)
+MAKE_HANDLER_WITH_TYPE(bool)
+MAKE_HANDLER_WITH_TYPE(float)
+MAKE_HANDLER_WITH_TYPE(double)
+MAKE_HANDLER_WITH_TYPE(CGRect)
+MAKE_HANDLER_WITH_TYPE(CGPoint)
+MAKE_HANDLER_WITH_TYPE(CGSize)
+#ifndef IPHONE
+MAKE_HANDLER_WITH_TYPE(NSRect)
+MAKE_HANDLER_WITH_TYPE(NSPoint)
+MAKE_HANDLER_WITH_TYPE(NSSize)
+#endif
+MAKE_HANDLER_WITH_TYPE(NSRange)
static NSMutableDictionary *handlerWarehouse = nil;
@@ -289,17 +202,34 @@ + (IMP) handlerWithSelector:(SEL)sel block:(NuBlock *)block signature:(const cha
else if ([returnType isEqualToString:@"d"]) {
return handler_returning_double(userdata);
}
- else if ([returnType isEqualToString:@"{_CGRect={_CGPoint=ff}{_CGSize=ff}}"]) {
- return handler_returning_cgrect(userdata);
+ else if ([returnType isEqualToString:@"{CGRect={CGPoint=ff}{CGSize=ff}}"]) {
+ return handler_returning_CGRect(userdata);
}
- else if ([returnType isEqualToString:@"{_CGPoint=ff}"]) {
- return handler_returning_cgpoint(userdata);
+ else if ([returnType isEqualToString:@"{CGPoint=ff}"]) {
+ return handler_returning_CGPoint(userdata);
}
- else if ([returnType isEqualToString:@"{_CGSize=ff}"]) {
- return handler_returning_cgsize(userdata);
+ else if ([returnType isEqualToString:@"{CGSize=ff}"]) {
+ return handler_returning_CGSize(userdata);
}
else if ([returnType isEqualToString:@"{_NSRange=II}"]) {
- return handler_returning_nsrange(userdata);
+ return handler_returning_NSRange(userdata);
+ }
+#ifndef IPHONE
+ else if ([returnType isEqualToString:@"{_NSRect={_NSPoint=dd}{_NSSize=dd}}"]) {
+ return handler_returning_NSRect(userdata);
+ }
+ else if ([returnType isEqualToString:@"{_NSPoint=dd}"]) {
+ return handler_returning_NSPoint(userdata);
+ }
+ else if ([returnType isEqualToString:@"{_NSSize=dd}"]) {
+ return handler_returning_NSSize(userdata);
+ }
+ else if ([returnType isEqualToString:@"{_NSRange=QQ}"]) {
+ return handler_returning_NSRange(userdata);
+ }
+#endif
+ else {
+ NSLog(@"UNKNOWN RETURN TYPE %@", returnType);
}
// the following is deprecated. Now that we can create IMPs from blocks, we don't need handler pools.
if (!handlerWarehouse) {
View
4 objc/NuOperator.m
@@ -1891,7 +1891,11 @@ @interface Nu_uname_operator : NuOperator {}
@implementation Nu_uname_operator
- (id) callWithArguments:(id)cdr context:(NSMutableDictionary *)context
{
+#ifdef IPHONE
+ return @"iOS";
+#else
return @"Darwin";
+#endif
}
@end
View
3  test/test_bridge.nu
@@ -5,11 +5,12 @@
(class TestBridge is NuTestCase
(- (id) testConstants is
+ (if (eq (uname) "Darwin")
(set floatTypeSignature (if (eq (Nu sizeOfPointer) 8) (then "d") (else "f")))
(assert_equal 0 (NuBridgedConstant constantWithName:"NSBlack" signature:floatTypeSignature))
(assert_equal 1 (NuBridgedConstant constantWithName:"NSWhite" signature:floatTypeSignature))
(assert_equal '(0 0 0 0) (NuBridgedConstant constantWithName:"NSZeroRect" signature:"{_NSRect}"))
- (assert_equal (NSApplication sharedApplication) (NuBridgedConstant constantWithName:"NSApp" signature:"@")))
+ (assert_equal (NSApplication sharedApplication) (NuBridgedConstant constantWithName:"NSApp" signature:"@"))))
(- (id) testFunctions is
(set strcmp (NuBridgedFunction functionWithName:"strcmp" signature:"i**"))
View
34 test/test_regex.nu
@@ -1,7 +1,7 @@
;; test_regex.nu
;; tests for Nu regular expression support.
;;
-;; Copyright (c) 2007 Tim Burks, Radtastical Inc.
+;; Copyright (c) 2007,2011 Tim Burks, Radtastical Inc.
(class TestRegex is NuTestCase
@@ -10,27 +10,29 @@
(set match (r findInString:"abcdefghijklmnopqrstuvwxyz"))
(assert_equal 24 ((match groupAtIndex:1) length)))
- (if (eq (uname) "Darwin") ;; requires UTF-8
- (- (id) testScrapeWithOperator is
- (set s (NSString stringWithContentsOfFile:"test/test.html" encoding:NSUTF8StringEncoding error:nil))
- (set r (regex <<-END
+ (- (id) testScrapeWithOperator is
+ (set s (NSString stringWithContentsOfFile:((NSBundle mainBundle) pathForResource:"test" ofType:"html")))
+ (unless s
+ (set s (NSString stringWithContentsOfFile:"test/test.html" encoding:NSUTF8StringEncoding error:nil)))
+ (set r (regex <<-END
<a href="/search([^\"]*)"END))
- (set matches (r findAllInString:s))
- (assert_equal 10 (matches count))
- (assert_equal "?q=bicycle+pedal&amp;hl=en&amp;start=10&amp;sa=N" ((matches lastObject) groupAtIndex:1))))
+ (set matches (r findAllInString:s))
+ (assert_equal 10 (matches count))
+ (assert_equal "?q=bicycle+pedal&amp;hl=en&amp;start=10&amp;sa=N" ((matches lastObject) groupAtIndex:1)))
(- (id) testRegex is
(set match (/a(.*)z/ findInString:"abcdefghijklmnopqrstuvwxyz"))
(assert_equal 24 ((match groupAtIndex:1) length)))
- (if (eq (uname) "Darwin") ;; requires UTF-8
- (- (id) testRegexScraping is
- (set s (NSString stringWithContentsOfFile:"test/test.html" encoding:NSUTF8StringEncoding error:nil))
- (set r /<a href="\/search([^"]*)"/)
- (set matches (r findAllInString:s))
- (assert_equal 10 (matches count))
- (assert_equal "?q=bicycle+pedal&amp;hl=en&amp;start=10&amp;sa=N"
- ((matches lastObject) groupAtIndex:1))))
+ (- (id) testRegexScraping is
+ (set s (NSString stringWithContentsOfFile:((NSBundle mainBundle) pathForResource:"test" ofType:"html")))
+ (unless s
+ (set s (NSString stringWithContentsOfFile:"test/test.html" encoding:NSUTF8StringEncoding error:nil)))
+ (set r /<a href="\/search([^"]*)"/)
+ (set matches (r findAllInString:s))
+ (assert_equal 10 (matches count))
+ (assert_equal "?q=bicycle+pedal&amp;hl=en&amp;start=10&amp;sa=N"
+ ((matches lastObject) groupAtIndex:1)))
(- (id) testExtendedRegex is
(set r /foo # comment
Please sign in to comment.
Something went wrong with that request. Please try again.