summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--tests/012/lambda.tl41
1 files changed, 28 insertions, 13 deletions
diff --git a/tests/012/lambda.tl b/tests/012/lambda.tl
index 65a3738c..d417f458 100644
--- a/tests/012/lambda.tl
+++ b/tests/012/lambda.tl
@@ -1,6 +1,21 @@
(load "../common")
-(mtest
+(defun call-lambda (fn . args)
+ [fn . args])
+
+(defmacro ltest (:match :form f)
+ (([(lambda . @rest) . @args] @expected)
+ (if *compile-test*
+ ^(progn
+ (test [(lambda ,*rest) ,*args] ,expected)
+ (test (call-lambda (lambda ,*rest) ,*args) ,expected))
+ ^(test [(lambda ,*rest) ,*args] ,expected)))
+ ((@else . rest) (compile-error f "bad syntax")))
+
+(defmacro mltest (. pairs)
+ ^(progn ,*(mapcar (op cons 'ltest) (tuples 2 pairs))))
+
+(mltest
[(lambda ())] nil
[(lambda (a) a)] :error
[(lambda (a) a) 1] 1
@@ -9,28 +24,28 @@
[(lambda (a b c) (list a b c)) 1 2] :error
[(lambda (a b c) (list a b c)) 1 2 3] (1 2 3))
-(mtest
+(mltest
[(lambda (: a) a)] nil
[(lambda (: (a 1)) a)] 1
[(lambda (: (a 1)) a) 2] 2
[(lambda (: (a 1 a-p)) (list a a-p))] (1 nil)
[(lambda (: (a 1 a-p)) (list a a-p)) 2] (2 t))
-(mtest
+(mltest
[(lambda (x : a) a)] :error
[(lambda (x : (a 1)) a)] :error
[(lambda (x : (a 1)) a) 2] 1
[(lambda (x : (a 1 a-p)) (list a a-p))] :error
[(lambda (x : (a 1 a-p)) (list a a-p)) 2] (1 nil))
-(mtest
+(mltest
[(lambda (x : a) (list x a)) 0] (0 nil)
[(lambda (x : (a 1)) (list x a)) 0] (0 1)
[(lambda (x : (a 1)) (list x a)) 0 2] (0 2)
[(lambda (x : (a 1 a-p)) (list x a a-p)) 0] (0 1 nil)
[(lambda (x : (a 1 a-p)) (list x a a-p)) 0 2] (0 2 t))
-(mtest
+(mltest
[(lambda (x y : (a 3) (b 4) . r) (list x y a b r))] :error
[(lambda (x y : (a 3) (b 4) . r) (list x y a b r)) 1] :error
[(lambda (x y : (a 3) (b 4) . r) (list x y a b r)) 1 2] (1 2 3 4 nil)
@@ -40,14 +55,14 @@
(defvarl vs '(a))
-(mtest
+(mltest
[(lambda (x y : (a 3) (b 4) . r) (list x y a b r)) . vs] :error
[(lambda (x y : (a 3) (b 4) . r) (list x y a b r)) 1 . vs] (1 a 3 4 nil)
[(lambda (x y : (a 3) (b 4) . r) (list x y a b r)) 1 2 . vs] (1 2 a 4 nil)
[(lambda (x y : (a 3) (b 4) . r) (list x y a b r)) 1 2 3 . vs] (1 2 3 a nil)
[(lambda (x y : (a 3) (b 4) . r) (list x y a b r)) 1 2 3 4 . vs] (1 2 3 4 (a)))
-(mtest
+(mltest
[(lambda (x y : (a 3) (b 4)) (list x y a b)) . vs] :error
[(lambda (x y : (a 3) (b 4)) (list x y a b)) 1 . vs] (1 a 3 4)
[(lambda (x y : (a 3) (b 4)) (list x y a b)) 1 2 . vs] (1 2 a 4)
@@ -57,7 +72,7 @@
(test
[(lambda (x y : (a 3 u) (b 4 v) . r) (list x y a u b v r)) . vs] :error)
-(mtest
+(mltest
[(lambda (x y : (a 3 u) (b 4 v) . r) (list x y a u b v r)) 1 . vs]
(1 a 3 nil 4 nil nil)
[(lambda (x y : (a 3 u) (b 4 v) . r) (list x y a u b v r)) 1 2 . vs]
@@ -75,7 +90,7 @@
(defvarl vl '(a b c d))
-(mtest
+(mltest
[(lambda (x y : (a 3) (b 4) . r) (list x y a b r)) . vl] (a b c d nil)
[(lambda (x y : (a 3) (b 4) . r) (list x y a b r)) 1 . vl] (1 a b c (d))
[(lambda (x y : (a 3) (b 4) . r) (list x y a b r)) 1 2 . vl] (1 2 a b (c d))
@@ -83,18 +98,18 @@
[(lambda (x y : (a 3) (b 4) . r) (list x y a b r)) 1 2 3 4 . vl] (1 2 3 4 (a b c d))
[(lambda (x y : (a 3) (b 4) . r) (list x y a b r)) 1 2 3 4 5 . vl] (1 2 3 4 (5 a b c d)))
-(mtest
+(mltest
[(lambda (x y : (a 3) (b 4)) (list x y a b)) . vl] (a b c d)
[(lambda (x y : (a 3) (b 4)) (list x y a b)) 1 . vl] :error)
-(mtest
+(mltest
[(lambda (x : y) (list x y)) 1 :] (1 nil)
[(lambda (x : y z) (list x y z)) 1 :] (1 nil nil)
[(lambda (x : y z) (list x y z)) 1 2 :] (1 2 nil)
[(lambda (x : y z) (list x y z)) 1 nil :] (1 nil nil)
[(lambda (x : y z) (list x y z)) 1 nil nil] (1 nil nil))
-(mtest
+(mltest
[(lambda (x : (y nil)) (list x y)) 1 :] (1 nil)
[(lambda (x : (y nil) (z)) (list x y z)) 1 :] (1 nil nil)
[(lambda (x : (y nil) (z)) (list x y z)) 1 2 :] (1 2 nil)
@@ -103,7 +118,7 @@
(defvarl vc '(: : : :))
-(mtest
+(mltest
[(lambda (x y : (a 3) (b 4) . r) (list x y a b r)) . vc] (: : 3 4 nil)
[(lambda (x y : (a 3) (b 4) . r) (list x y a b r)) 1 . vc] (1 : 3 4 (:))
[(lambda (x y : (a 3) (b 4) . r) (list x y a b r)) 1 2 . vc] (1 2 3 4 (: :))