Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

reenabled more unit tests for iOS.

oddly, test_match.nu is broken in the simulator only.
  • Loading branch information...
commit 9adda501045ff18da495c321f23c87b3f5d89efa 1 parent 78fc726
@timburks authored
View
4 MacOS/Nu-framework/Nu.xcodeproj/xcuserdata/tim.xcuserdatad/xcschemes/NuApp.xcscheme
@@ -25,7 +25,7 @@
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.GDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.GDB"
shouldUseLaunchSchemeArgsEnv = "YES"
- buildConfiguration = "Release">
+ buildConfiguration = "Debug">
<Testables>
</Testables>
</TestAction>
@@ -34,7 +34,7 @@
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.GDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
- buildConfiguration = "Release"
+ buildConfiguration = "Debug"
enablesOpenGLESFrameCapture = "YES">
<BuildableProductRunnable>
<BuildableReference
View
4 MacOS/Nu-framework/NuApp/NuAppDelegate.m
@@ -45,8 +45,8 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
NuInit();
- [[Nu sharedParser] parseEval:@"(load \"nu.nu\""];
- [[Nu sharedParser] parseEval:@"(load \"test.nu\""];
+ [[Nu sharedParser] parseEval:@"(load \"nu\")"];
+ [[Nu sharedParser] parseEval:@"(load \"test\")"];
NSString *resourceDirectory = [[NSBundle mainBundle] resourcePath];
View
17 test/test_characters.nu
@@ -30,23 +30,20 @@
(assert_equal 32 '\s'))
(- (id) testOctalEscapedCharacters is
- (if (eq (uname) "Darwin") ;; requires UTF-8
- (assert_equal 0 '\000'))
+ (assert_equal 0 '\000')
(assert_equal 1 '\001')
(assert_equal 255 '\377'))
(- (id) testHexEscapedCharacters is
- (if (eq (uname) "Darwin") ;; requires UTF-8
- (assert_equal 0 '\x00'))
+ (assert_equal 0 '\x00')
(assert_equal 1 '\x01')
(assert_equal 255 '\xfF'))
- (if (eq (uname) "Darwin") ;; requires UTF-8
- (- (id) testUnicodeEscapedCharacters is
- (assert_equal 0 '\u0000')
- (assert_equal 1 '\u0001')
- (assert_equal 65535 '\uFfFf')
- (assert_equal 255 '\u00ff')))
+ (- (id) testUnicodeEscapedCharacters is
+ (assert_equal 0 '\u0000')
+ (assert_equal 1 '\u0001')
+ (assert_equal 65535 '\uFfFf')
+ (assert_equal 255 '\u00ff'))
(- (id) testFourCharacterIntegers is
(assert_equal 1886604404 'psLt')
View
74 test/test_exceptions.nu
@@ -2,7 +2,7 @@
;; tests for Nu exception handling.
;;
;; Copyright (c) 2007 Tim Burks, Radtastical Inc.
-(if (eq (uname) "Darwin")
+
(class TestExceptions is NuTestCase
(- (id) testRangeException is
@@ -37,42 +37,38 @@
(assert_equal "UserException" name)
(assert_equal 99 z))
- (if (eq (uname) "Darwin")
- (- (id) testUserThrownException is
- (set name nil)
- (set before nil)
- (set after nil)
- (set z nil)
- (try
- (set before "this should always be set")
- (throw ((NSException alloc) initWithName:"UserException" reason:"" userInfo:nil))
- (set after "this should never be set")
- (catch (exception) (set name (exception name)))
- (finally (set z 99)))
- (assert_equal "this should always be set" before)
- (assert_equal nil after)
- (assert_equal "UserException" name)
- (assert_equal 99 z))
-
- (- (id) testUserThrownObject is
- (set object nil)
- (set before nil)
- (set after nil)
- (set z nil)
- (try
- (set before "this should always be set")
- (throw 99)
- (catch (thrown) (set object thrown))
- (finally (set z 99)))
- (assert_equal "this should always be set" before)
- (assert_equal nil after)
- (assert_equal 99 object)
- (assert_equal 99 z))
-
- (- (id) testAssertThrown is
- (assert_throws "UserException"
- (do () (throw ((NSException alloc) initWithName:"UserException" reason:"" userInfo:nil)))))))
-
-
+ (- (id) testUserThrownException is
+ (set name nil)
+ (set before nil)
+ (set after nil)
+ (set z nil)
+ (try
+ (set before "this should always be set")
+ (throw ((NSException alloc) initWithName:"UserException" reason:"" userInfo:nil))
+ (set after "this should never be set")
+ (catch (exception) (set name (exception name)))
+ (finally (set z 99)))
+ (assert_equal "this should always be set" before)
+ (assert_equal nil after)
+ (assert_equal "UserException" name)
+ (assert_equal 99 z))
+
+ (- (id) testUserThrownObject is
+ (set object nil)
+ (set before nil)
+ (set after nil)
+ (set z nil)
+ (try
+ (set before "this should always be set")
+ (throw 99)
+ (catch (thrown) (set object thrown))
+ (finally (set z 99)))
+ (assert_equal "this should always be set" before)
+ (assert_equal nil after)
+ (assert_equal 99 object)
+ (assert_equal 99 z))
+
+ (- (id) testAssertThrown is
+ (assert_throws "UserException"
+ (do () (throw ((NSException alloc) initWithName:"UserException" reason:"" userInfo:nil))))))
-)
View
514 test/test_match.nu
@@ -3,262 +3,260 @@
;;
;; Copyright (c) 2008 Issac Trotts
-(if (eq (uname) "Darwin") ;; pattern matching is broken on Linux because it relies on throw, which is not working with the GNU runtime.
-
- (load "match")
+(load "match")
- (class TestDestructuring is NuTestCase
-
- (- (id) testFindFirstMatch is
- (assert_equal '() (_find-first-match 1 '()))
- (assert_equal '(let () 2) (_find-first-match 1 '((1 2))))
- (assert_equal '(let () 4) (_find-first-match 3 '((1 2) (3 4))))
- (assert_equal '(let () 5) (_find-first-match 'a '((1 2) ('a 5) (3 4))))
- (assert_equal '(let ((a 1) (b 2)) a)
- (_find-first-match '(1 2) '(((a b) a) ((a) a))))
- (assert_equal '(let ((a 1)) 1)
- (_find-first-match 1 '((a 1) (b 2)))))
-
- ;; match
- (- (id) testMatch is
- (assert_equal 1 (match 1 (x x)))
- (assert_equal 2 (match 2 (x x) (y (+ y 1)))) ;; First match is used.
-
- (assert_equal 'nothing (match nil (0 'zero) (nil 'nothing)))
-
- ;; Make sure nil doesn't get treated as a pattern name.
- (assert_equal 'nada (match 0 (nil 'zilch) (x 'nada)))
-
- (assert_equal '(1 2) (match '(1 2) ((a a) a) ((a b) (list a b))))
-
- (function people-to-string (people)
- (match people
- (() "no people")
- ((p1) "one person: #{p1}")
- ((p1 p2) "two people: #{p1} and #{p2}")
- (else "too many people: #{(people length)}")))
- (assert_equal "no people" (people-to-string '()))
- (assert_equal "one person: Tim" (people-to-string '(Tim)))
- (assert_equal "two people: Tim and Matz" (people-to-string '(Tim Matz)))
- (assert_equal "too many people: 3" (people-to-string '(Tim Guido Matz)))
-
- ;; If there is no else or wildcard (_) clause then it throws an exception.
- (assert_throws "NuMatchException"
- (match '(1 2)
- (() 'foo)
- ((a b c) 'bar))))
-
- (- (id) testMatchWithLiterals is
- ;; Toy algebraic simplifier
- (function simplify (expr)
- (match expr
- ((+ 0 a) a)
- ((+ a 0) a)
- ((+ a a) (list '* 2 a))
- (else expr)))
- (assert_equal 'foo (simplify '(+ 0 foo)))
- (assert_equal 'foo (simplify '(+ foo 0)))
- (assert_equal '(* 2 x) (simplify '(+ x x)))
- (assert_equal '(+ foo 1) (simplify '(+ foo 1))))
-
- (- (id) testMatchWithWildCards is
- (assert_equal '(1 4)
- (match '(1 (2 (3)) 4 5)
- ((a _ b _) (list a b)))))
-
- (- (id) testRestOfListPatterns is
- (assert_equal '(1 (2 3))
- (match '(1 2 3)
- ((a . b) (list a b))))
- (assert_equal '(1 2 (3))
- (match '(1 2 3)
- ((a b . c) (list a b c))))
-
- ;; This is probably an inefficient way to implement map.
- (function silly-map (f a-list)
- (match a-list
- (() '())
- ((head . tail)
- (cons (f head) (silly-map f tail)))))
- (function add1 (x) (+ 1 x))
- (assert_equal '() (silly-map add1 '()))
- (assert_equal '(1) (silly-map add1 '(0)))
- (assert_equal '(1 3) (silly-map add1 '(0 2)))
- (assert_equal '(1 2 3) (silly-map add1 '(0 1 2))))
-
- (- (id) testSymbolicLiterals is
- (assert_equal 1 (match 'a ('a 1)))
- (assert_equal 2 (match '(a 2) (('a x) x)))
- (assert_throws "NuMatchException" (match '(a 2) (('b x) x)))
-
- (function to-num (thing)
- (match thing
- ('Baz 7)
- (('Foo x) x)
- (('Bar x y) (+ x y))))
- (assert_equal 42 (to-num '(Foo 42)))
- (assert_equal 9 (to-num '(Bar 4 5)))
- (assert_equal 7 (to-num 'Baz))
-
- (function fruit-desc (fruit)
- (match fruit
- (('Apple crunchiness) "Apple #{crunchiness}-crunchy")
- (('BananaBunch n) "Banana bunch with #{n} bananas")
- (('Orange desc) "Orange #{desc}")))
-
- (assert_equal "Apple 2.5-crunchy" (fruit-desc '(Apple 2.5)))
- (assert_equal "Banana bunch with 5 bananas"
- (fruit-desc '(BananaBunch 5)))
- (assert_equal "Orange bergamot" (fruit-desc '(Orange "bergamot"))))
-
- (- (id) testSymbolicLiteralsInTrees is
- (assert_equal 1 (match '(a)
- ('(a) 1)
- ('a 2)))
- (assert_equal 3 (match '(a)
- ('a 2)
- ('(a) 3))))
-
- (- (id) testQuoteLeafSymbols is
- (assert_equal '() (_quote-leaf-symbols '()))
- (assert_equal 1 (_quote-leaf-symbols 1))
- (assert_equal '(1) (_quote-leaf-symbols '(1)))
- (assert_equal ''a (_quote-leaf-symbols 'a))
- (assert_equal '( 'a 'b) (_quote-leaf-symbols '(a b)))
- (assert_equal '(('a 'c) 'b) (_quote-leaf-symbols '((a c) b)))
- (assert_equal '( 'a ('c 'b)) (_quote-leaf-symbols '(a (c b)))))
-
- (- (id) testCheckBindings is
- (check-bindings '()) ;; empty set of bindings should not throw
- (check-bindings '((a 1)))
- (check-bindings '((a 1) (a 1))) ;; consistent
- (assert_throws "NuMatchException"
- (do () (check-bindings '((a 1) (a 2)))))) ;; inconsistent
-
- ;; match-do
- (- (id) testMatchDo is
- (set f (match-do (() 1)))
- (assert_equal 1 (f))
- (assert_throws "NuMatchException" (f 'extra_arg))
-
- (set f (match-do (() nil) ((a) a)))
- (assert_equal nil (f))
- (assert_equal 1 (f 1))
- (assert_throws "NuMatchException" (f 1 'extra_arg))
-
- (set f (match-do ((((a) b)) (list a b)) (_ 'default)))
- (assert_equal '(1 2) (f '((1) 2)))
- (assert_equal 'default (f))
- (assert_equal 'default (f 1))
- (assert_equal 'default (f 1 2)))
-
- ;; match-function
- (- (id) testMatchFunction is
- (match-function f
- (() 0)
- ((a) 1)
- ((a b) 2)
- (_ 'many))
- (assert_equal 0 (f))
- (assert_equal 1 (f 'a))
- (assert_equal 2 (f 'a 'b))
- (assert_equal 'many (f 'a 'b 'c))
-
- (match-function f
- (((a)) a)
- (((a (b))) (list b a))
- (((a (b (c)))) (list a b c)))
-
- (assert_equal 2 (f '(2)))
- (assert_equal '(1 3) (f '(3 (1))))
- (assert_equal '(7 8 9) (f '(7 (8 (9)))))
- (assert_throws "NuMatchException" (f 1))
-
- (function slow-map (f lst)
- (match-function loop
- ((nil) '())
- (((a . rest))
- (cons (f a) (loop rest))))
- (loop lst))
- (function add-1 (x) (+ x 1))
- (assert_equal '() (slow-map add-1 '()))
- (assert_equal '(1) (slow-map add-1 '(0)))
- (assert_equal '(1 2) (slow-map add-1 '(0 1)))
- (assert_equal '(4 3 2) (slow-map add-1 '(3 2 1))))
-
- ;; match-let1
- (- (id) testMatchLet1 is
- (assert_equal 3 (match-let1 a 3
- a))
- (assert_equal 3 (match-let1 (a) '(3)
- a))
- (assert_equal '(1 2 3)
- (match-let1 (a b c) '(1 2 3)
- (list a b c)))
- (assert_equal '(1 2 3 4)
- (match-let1 (a (b c) d) '(1 (2 3) 4)
- (list a b c d)))
- (assert_throws "NuCarCalledOnAtom"
- (do () (match-let1 (a) ()
- nil)))
- (assert_throws "NuCarCalledOnAtom"
- (do () (match-let1 (a b) (1)
- (list a b))))
- (assert_equal '(1 2)
- (match-let1 a '(1 2)
- a))
- (assert_equal '(1 (2 3))
- (match-let1 (a b) '(1 (2 3))
- (list a b)))
-
- ;; Test it with expressions on the right.
- (assert_equal (list 3 12)
- (match-let1 (a b) (list (+ 1 2) (* 3 4))
- (list a b)))
-
- ;; Test it with symbols on the right.
- (assert_equal '(bottle rum)
- (match-let1 (yo ho) '(bottle rum)
- (list yo ho)))
-
- ;; The same symbol can show up twice in the LHS (left hand side) as long as it
- ;; binds to eq things on the RHS (right hand side).
- (assert_equal '(bottle rum)
- (match-let1 (yo ho ho) '(bottle rum rum)
- (list yo ho)))
-
- ;; An error occurs if we try to match the same symbol to two different things on
- ;; the right.
- (assert_throws "NuMatchException"
- (match-let1 (a a) '(1 2)
- nil)))
-
- ;; match-setmatch-set
- (- (id) testMatchSet is
- (match-set a 3)
- (assert_equal 3 a)
-
- (match-set a '(3))
- (assert_equal '(3) a)
-
- (match-set (a) '(3))
- (assert_equal 3 a)
-
- (match-set a '(1 2))
- (assert_equal '(1 2) a)
-
- (match-set (a (b c) d) '(1 (2 3) 4))
- (assert_equal '(1 2 3 4)
- (list a b c d))
-
- (assert_throws "NuCarCalledOnAtom"
- (do () (match-set (a) ())))
-
- (assert_throws "NuCarCalledOnAtom"
- (do () (match-set (a b) (1))))
-
- (match-set (a b) '(1 (2 3)))
- (assert_equal '(1 (2 3)) (list a b))
-
- (assert_throws "NuMatchException"
- (match-set (a a) '(1 2))))))
+(class TestDestructuring is NuTestCase
+
+ (- (id) testFindFirstMatch is
+ (assert_equal '() (_find-first-match 1 '()))
+ (assert_equal '(let () 2) (_find-first-match 1 '((1 2))))
+ (assert_equal '(let () 4) (_find-first-match 3 '((1 2) (3 4))))
+ (assert_equal '(let () 5) (_find-first-match 'a '((1 2) ('a 5) (3 4))))
+ (assert_equal '(let ((a 1) (b 2)) a)
+ (_find-first-match '(1 2) '(((a b) a) ((a) a))))
+ (assert_equal '(let ((a 1)) 1)
+ (_find-first-match 1 '((a 1) (b 2)))))
+
+ ;; match
+ (- (id) testMatch is
+ (assert_equal 1 (match 1 (x x)))
+ (assert_equal 2 (match 2 (x x) (y (+ y 1)))) ;; First match is used.
+
+ (assert_equal 'nothing (match nil (0 'zero) (nil 'nothing)))
+
+ ;; Make sure nil doesn't get treated as a pattern name.
+ (assert_equal 'nada (match 0 (nil 'zilch) (x 'nada)))
+
+ (assert_equal '(1 2) (match '(1 2) ((a a) a) ((a b) (list a b))))
+
+ (function people-to-string (people)
+ (match people
+ (() "no people")
+ ((p1) "one person: #{p1}")
+ ((p1 p2) "two people: #{p1} and #{p2}")
+ (else "too many people: #{(people length)}")))
+ (assert_equal "no people" (people-to-string '()))
+ (assert_equal "one person: Tim" (people-to-string '(Tim)))
+ (assert_equal "two people: Tim and Matz" (people-to-string '(Tim Matz)))
+ (assert_equal "too many people: 3" (people-to-string '(Tim Guido Matz)))
+
+ ;; If there is no else or wildcard (_) clause then it throws an exception.
+ (assert_throws "NuMatchException"
+ (match '(1 2)
+ (() 'foo)
+ ((a b c) 'bar))))
+
+ (- (id) testMatchWithLiterals is
+ ;; Toy algebraic simplifier
+ (function simplify (expr)
+ (match expr
+ ((+ 0 a) a)
+ ((+ a 0) a)
+ ((+ a a) (list '* 2 a))
+ (else expr)))
+ (assert_equal 'foo (simplify '(+ 0 foo)))
+ (assert_equal 'foo (simplify '(+ foo 0)))
+ (assert_equal '(* 2 x) (simplify '(+ x x)))
+ (assert_equal '(+ foo 1) (simplify '(+ foo 1))))
+
+ (- (id) testMatchWithWildCards is
+ (assert_equal '(1 4)
+ (match '(1 (2 (3)) 4 5)
+ ((a _ b _) (list a b)))))
+
+ (- (id) testRestOfListPatterns is
+ (assert_equal '(1 (2 3))
+ (match '(1 2 3)
+ ((a . b) (list a b))))
+ (assert_equal '(1 2 (3))
+ (match '(1 2 3)
+ ((a b . c) (list a b c))))
+
+ ;; This is probably an inefficient way to implement map.
+ (function silly-map (f a-list)
+ (match a-list
+ (() '())
+ ((head . tail)
+ (cons (f head) (silly-map f tail)))))
+ (function add1 (x) (+ 1 x))
+ (assert_equal '() (silly-map add1 '()))
+ (assert_equal '(1) (silly-map add1 '(0)))
+ (assert_equal '(1 3) (silly-map add1 '(0 2)))
+ (assert_equal '(1 2 3) (silly-map add1 '(0 1 2))))
+
+ (- (id) testSymbolicLiterals is
+ (assert_equal 1 (match 'a ('a 1)))
+ (assert_equal 2 (match '(a 2) (('a x) x)))
+ (assert_throws "NuMatchException" (match '(a 2) (('b x) x)))
+
+ (function to-num (thing)
+ (match thing
+ ('Baz 7)
+ (('Foo x) x)
+ (('Bar x y) (+ x y))))
+ (assert_equal 42 (to-num '(Foo 42)))
+ (assert_equal 9 (to-num '(Bar 4 5)))
+ (assert_equal 7 (to-num 'Baz))
+
+ (function fruit-desc (fruit)
+ (match fruit
+ (('Apple crunchiness) "Apple #{crunchiness}-crunchy")
+ (('BananaBunch n) "Banana bunch with #{n} bananas")
+ (('Orange desc) "Orange #{desc}")))
+
+ (assert_equal "Apple 2.5-crunchy" (fruit-desc '(Apple 2.5)))
+ (assert_equal "Banana bunch with 5 bananas"
+ (fruit-desc '(BananaBunch 5)))
+ (assert_equal "Orange bergamot" (fruit-desc '(Orange "bergamot"))))
+
+ (- (id) testSymbolicLiteralsInTrees is
+ (assert_equal 1 (match '(a)
+ ('(a) 1)
+ ('a 2)))
+ (assert_equal 3 (match '(a)
+ ('a 2)
+ ('(a) 3))))
+
+ (- (id) testQuoteLeafSymbols is
+ (assert_equal '() (_quote-leaf-symbols '()))
+ (assert_equal 1 (_quote-leaf-symbols 1))
+ (assert_equal '(1) (_quote-leaf-symbols '(1)))
+ (assert_equal ''a (_quote-leaf-symbols 'a))
+ (assert_equal '( 'a 'b) (_quote-leaf-symbols '(a b)))
+ (assert_equal '(('a 'c) 'b) (_quote-leaf-symbols '((a c) b)))
+ (assert_equal '( 'a ('c 'b)) (_quote-leaf-symbols '(a (c b)))))
+
+ (- (id) testCheckBindings is
+ (check-bindings '()) ;; empty set of bindings should not throw
+ (check-bindings '((a 1)))
+ (check-bindings '((a 1) (a 1))) ;; consistent
+ (assert_throws "NuMatchException"
+ (do () (check-bindings '((a 1) (a 2)))))) ;; inconsistent
+
+ ;; match-do
+ (- (id) testMatchDo is
+ (set f (match-do (() 1)))
+ (assert_equal 1 (f))
+ (assert_throws "NuMatchException" (f 'extra_arg))
+
+ (set f (match-do (() nil) ((a) a)))
+ (assert_equal nil (f))
+ (assert_equal 1 (f 1))
+ (assert_throws "NuMatchException" (f 1 'extra_arg))
+
+ (set f (match-do ((((a) b)) (list a b)) (_ 'default)))
+ (assert_equal '(1 2) (f '((1) 2)))
+ (assert_equal 'default (f))
+ (assert_equal 'default (f 1))
+ (assert_equal 'default (f 1 2)))
+
+ ;; match-function
+ (- (id) testMatchFunction is
+ (match-function f
+ (() 0)
+ ((a) 1)
+ ((a b) 2)
+ (_ 'many))
+ (assert_equal 0 (f))
+ (assert_equal 1 (f 'a))
+ (assert_equal 2 (f 'a 'b))
+ (assert_equal 'many (f 'a 'b 'c))
+
+ (match-function f
+ (((a)) a)
+ (((a (b))) (list b a))
+ (((a (b (c)))) (list a b c)))
+
+ (assert_equal 2 (f '(2)))
+ (assert_equal '(1 3) (f '(3 (1))))
+ (assert_equal '(7 8 9) (f '(7 (8 (9)))))
+ (assert_throws "NuMatchException" (f 1))
+
+ (function slow-map (f lst)
+ (match-function loop
+ ((nil) '())
+ (((a . rest))
+ (cons (f a) (loop rest))))
+ (loop lst))
+ (function add-1 (x) (+ x 1))
+ (assert_equal '() (slow-map add-1 '()))
+ (assert_equal '(1) (slow-map add-1 '(0)))
+ (assert_equal '(1 2) (slow-map add-1 '(0 1)))
+ (assert_equal '(4 3 2) (slow-map add-1 '(3 2 1))))
+
+ ;; match-let1
+ (- (id) testMatchLet1 is
+ (assert_equal 3 (match-let1 a 3
+ a))
+ (assert_equal 3 (match-let1 (a) '(3)
+ a))
+ (assert_equal '(1 2 3)
+ (match-let1 (a b c) '(1 2 3)
+ (list a b c)))
+ (assert_equal '(1 2 3 4)
+ (match-let1 (a (b c) d) '(1 (2 3) 4)
+ (list a b c d)))
+ (assert_throws "NuCarCalledOnAtom"
+ (do () (match-let1 (a) ()
+ nil)))
+ (assert_throws "NuCarCalledOnAtom"
+ (do () (match-let1 (a b) (1)
+ (list a b))))
+ (assert_equal '(1 2)
+ (match-let1 a '(1 2)
+ a))
+ (assert_equal '(1 (2 3))
+ (match-let1 (a b) '(1 (2 3))
+ (list a b)))
+
+ ;; Test it with expressions on the right.
+ (assert_equal (list 3 12)
+ (match-let1 (a b) (list (+ 1 2) (* 3 4))
+ (list a b)))
+
+ ;; Test it with symbols on the right.
+ (assert_equal '(bottle rum)
+ (match-let1 (yo ho) '(bottle rum)
+ (list yo ho)))
+
+ ;; The same symbol can show up twice in the LHS (left hand side) as long as it
+ ;; binds to eq things on the RHS (right hand side).
+ (assert_equal '(bottle rum)
+ (match-let1 (yo ho ho) '(bottle rum rum)
+ (list yo ho)))
+
+ ;; An error occurs if we try to match the same symbol to two different things on
+ ;; the right.
+ (assert_throws "NuMatchException"
+ (match-let1 (a a) '(1 2)
+ nil)))
+
+ ;; match-setmatch-set
+ (- (id) testMatchSet is
+ (match-set a 3)
+ (assert_equal 3 a)
+
+ (match-set a '(3))
+ (assert_equal '(3) a)
+
+ (match-set (a) '(3))
+ (assert_equal 3 a)
+
+ (match-set a '(1 2))
+ (assert_equal '(1 2) a)
+
+ (match-set (a (b c) d) '(1 (2 3) 4))
+ (assert_equal '(1 2 3 4)
+ (list a b c d))
+
+ (assert_throws "NuCarCalledOnAtom"
+ (do () (match-set (a) ())))
+
+ (assert_throws "NuCarCalledOnAtom"
+ (do () (match-set (a b) (1))))
+
+ (match-set (a b) '(1 (2 3)))
+ (assert_equal '(1 (2 3)) (list a b))
+
+ (assert_throws "NuMatchException"
+ (match-set (a a) '(1 2)))))
View
3  test/test_profiler.nu
@@ -40,6 +40,5 @@
(set onetime ((results "1") time))
(set twotime ((results "2") time))
(set threetime ((results "3") time))
- (if (eq (uname) "Darwin")
- (assert_true (>= toptime (+ onetime twotime threetime))))))
+ (assert_true (>= toptime (+ onetime twotime threetime)))))
View
30 test/test_strings.nu
@@ -27,23 +27,20 @@
(assert_equal "24" "#{(* 6 4)}"))
(- (id) testOctalEscapedStrings is
- (if (eq (uname) "Darwin") ;; requires UTF-8
- (assert_equal 0 ("\000" characterAtIndex:0)))
+ (assert_equal 0 ("\000" characterAtIndex:0))
(assert_equal 1 ("\001" characterAtIndex:0))
(assert_equal 255 ("\377" characterAtIndex:0)))
(- (id) testHexEscapedStrings is
- (if (eq (uname) "Darwin") ;; requires UTF-8
- (assert_equal 0 ("\x00" characterAtIndex:0)))
+ (assert_equal 0 ("\x00" characterAtIndex:0))
(assert_equal 1 ("\x01" characterAtIndex:0))
(assert_equal 255 ("\xfF" characterAtIndex:0)))
- (if (eq (uname) "Darwin") ;; requires UTF-8
- (- (id) testUnicodeEscapedStrings is
- (assert_equal 0 ("\u0000" characterAtIndex:0))
- (assert_equal 1 ("\u0001" characterAtIndex:0))
- (assert_equal 255 ("\u00ff" characterAtIndex:0))
- (assert_equal 65535 ("\uFfFf" characterAtIndex:0))))
+ (- (id) testUnicodeEscapedStrings is
+ (assert_equal 0 ("\u0000" characterAtIndex:0))
+ (assert_equal 1 ("\u0001" characterAtIndex:0))
+ (assert_equal 255 ("\u00ff" characterAtIndex:0))
+ (assert_equal 65535 ("\uFfFf" characterAtIndex:0)))
(- (id) testEscapedHereStrings is
(set x <<+END
@@ -73,14 +70,13 @@
(assert_equal 1 (x characterAtIndex:1))
(assert_equal 255 (x characterAtIndex:2)))
- (if (eq (uname) "Darwin") ;; requires UTF-8
- (- (id) testUnicodeEscapedHereStrings is
- (set x <<+END
+ (- (id) testUnicodeEscapedHereStrings is
+ (set x <<+END
\u0000\u0001\u00ff\uFfFfEND)
- (assert_equal 0 (x characterAtIndex:0))
- (assert_equal 1 (x characterAtIndex:1))
- (assert_equal 255 (x characterAtIndex:2))
- (assert_equal 65535 (x characterAtIndex:3))))
+ (assert_equal 0 (x characterAtIndex:0))
+ (assert_equal 1 (x characterAtIndex:1))
+ (assert_equal 255 (x characterAtIndex:2))
+ (assert_equal 65535 (x characterAtIndex:3)))
(- (id) testExplicitlyUnescapedStrings is
(assert_equal 92 (-"\n" characterAtIndex:0))
View
3  test/test_templates.nu
@@ -3,7 +3,6 @@
;;
;; Copyright (c) 2007 Tim Burks, Radtastical Inc.
-(if (eq (uname) "Darwin")
(load "template")
(class TestTemplates is NuTestCase
@@ -34,4 +33,4 @@ END)
(set result (eval template))
(assert_equal goal result)))
-)
+
Please sign in to comment.
Something went wrong with that request. Please try again.