diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2022-01-14 19:33:22 -0800 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2022-01-14 19:33:22 -0800 |
commit | e7af6a5ec68b905b6d7e9d55a6dd875ff85d6eed (patch) | |
tree | ac316f41befb4cf5c3e063b8905a08017993dd9c /tests/012 | |
parent | f2fd34058d58cd637efc2fa3208d8f1703a4e7ed (diff) | |
download | txr-e7af6a5ec68b905b6d7e9d55a6dd875ff85d6eed.tar.gz txr-e7af6a5ec68b905b6d7e9d55a6dd875ff85d6eed.tar.bz2 txr-e7af6a5ec68b905b6d7e9d55a6dd875ff85d6eed.zip |
testing: cover compiled, non-inlined lambda.
The lambda.tl test, when compiled, is only testing the
compiler's implementation of the inlined lambda: code
generated from a lambda expression to which arguments are
statically applied. We augment this to also compile
real lambda functions which are called. Everything passes.
* tests/012/lambda.tl (call-lambda): New function.
(ltest): New macro, specifically geared for testing lambda
expressions. When *compile-test* is true, this generates code
which performs two tests: applying the arguments directly to
the lambda, and evaluating the lambda to a function which is
passed to call-lambda, which will then apply the arguments.
We cannot use apply, because the compiler sees through that
and will inline the lambda anyway.
(mltest): Multi-expression version of ltest. This is a drop-in
replacement for mtest in the rest of the file.
Diffstat (limited to 'tests/012')
-rw-r--r-- | tests/012/lambda.tl | 41 |
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 (: :)) |