Commit f87559f5 authored by pfdietz's avatar pfdietz
Browse files

Add tests that arguments to many standardized macros are expandedin the...

Add tests that arguments to many standardized macros are expandedin the correct environment, if the macro implementation does thatexpansion itself (for example, if CONSTANTP does macro expansion)
parent c4c5f9e0
......@@ -293,4 +293,69 @@
(loop for nil from 5 above 0 collect (incf i)))
(1 2 3 4 5))
;;; Test that explicit calls to macroexpand in subforms
;;; are done in the correct environment
(deftest loop.1.57
(macrolet
((%m (z) z))
(loop for i from (expand-in-current-env (%m 1)) to 5 collect i))
(1 2 3 4 5))
(deftest loop.1.58
(macrolet
((%m (z) z))
(loop for i from 1 to (expand-in-current-env (%m 5)) collect i))
(1 2 3 4 5))
(deftest loop.1.59
(macrolet
((%m (z) z))
(loop for i from 1 to 5 by (expand-in-current-env (%m 2)) collect i))
(1 3 5))
(deftest loop.1.60
(macrolet
((%m (z) z))
(loop for i downfrom (expand-in-current-env (%m 10))
to 3
collect i))
(10 9 8 7 6 5 4 3))
(deftest loop.1.61
(macrolet
((%m (z) z))
(loop for i downfrom 10
to (expand-in-current-env (%m 3))
collect i))
(10 9 8 7 6 5 4 3))
(deftest loop.1.62
(macrolet
((%m (z) z))
(loop for i from (expand-in-current-env (%m 10))
downto 3
collect i))
(10 9 8 7 6 5 4 3))
(deftest loop.1.63
(macrolet
((%m (z) z))
(loop for i from 10
downto (expand-in-current-env (%m 3))
collect i))
(10 9 8 7 6 5 4 3))
(deftest loop.1.64
(macrolet
((%m (z) z))
(loop for i from (expand-in-current-env (%m 1)) below 5 collect i))
(1 2 3 4))
(deftest loop.1.65
(macrolet
((%m (z) z))
(loop for i from 1 below (expand-in-current-env (%m 5)) collect i))
(1 2 3 4))
......@@ -500,3 +500,60 @@
(deftest loop.10.104
(loop for i in nil sum i of-type long-float)
0.0l0)
;;; Test that explicit calls to macroexpand in subforms
;;; are done in the correct environment
(deftest loop.10.105
(macrolet
((%m (z) z))
(loop for x from 1 to 10 count (expand-in-current-env (%m (< x 5)))))
4)
(deftest loop.10.106
(macrolet
((%m (z) z))
(loop for x from 1 to 10 counting (expand-in-current-env (%m t))))
10)
(deftest loop.10.106
(macrolet
((%m (z) z))
(loop for x from 1 to 10 count (expand-in-current-env (%m nil))))
0)
(deftest loop.10.107
(macrolet
((%m (z) z))
(loop for x in '(1 4 10 5 7 9) maximize (expand-in-current-env (%m x))))
10)
(deftest loop.10.108
(macrolet
((%m (z) z))
(loop for x in '(1 4 10 5 7 9) maximizing (expand-in-current-env (%m 17))))
17)
(deftest loop.10.109
(macrolet
((%m (z) z))
(loop for x in '(5 4 10 1 7 9) minimize (expand-in-current-env (%m x))))
1)
(deftest loop.10.110
(macrolet
((%m (z) z))
(loop for x in '(5 4 10 1 7 9) minimizing (expand-in-current-env (%m 3))))
3)
(deftest loop.10.111
(macrolet
((%m (z) z))
(loop for x in '(1 4 10 5 7 9) sum (expand-in-current-env (%m x))))
36)
(deftest loop.10.112
(macrolet
((%m (z) z))
(loop for x in '(1 4 10 5 7 9) summing (expand-in-current-env (%m 2))))
12)
......@@ -206,4 +206,11 @@
until (> i 12) collect i)
:good)
;;; Test that explicit calls to macroexpand in subforms
;;; are done in the correct environment
(deftest loop.11.35
(macrolet
((%m (z) z))
(loop repeat (expand-in-current-env (%m 5)) collect 'x))
(x x x x x))
......@@ -237,4 +237,38 @@
collect i into foo)
1)
;;; Test that explicit calls to macroexpand in subforms
;;; are done in the correct environment
(deftest loop.12.56
(macrolet
((%m (z) z))
(loop for i in '(1 2 3 4) always (expand-in-current-env (%m (< i 10)))))
t)
(deftest loop.12.57
(macrolet
((%m (z) z))
(loop for i in '(1 2 3 4) always (expand-in-current-env (%m t))))
t)
(deftest loop.12.58
(macrolet
((%m (z) z))
(loop for i in '(1 2 3 4) never (expand-in-current-env (%m (>= i 10)))))
t)
(deftest loop.12.59
(macrolet
((%m (z) z))
(loop for i in '(1 2 3 4) never (expand-in-current-env (%m t))))
nil)
(deftest loop.12.60
(macrolet
((%m (z) z))
(loop for i in '(1 2 3 4)
thereis (expand-in-current-env (%m (and (>= i 2) (+ i 1))))))
3)
......@@ -431,4 +431,24 @@
:bad)
:good)
;;; Test that explicit calls to macroexpand in subforms
;;; are done in the correct environment
(deftest loop.13.88
(macrolet
((%m (z) z))
(loop do (expand-in-current-env (%m (return 10)))))
10)
(deftest loop.13.89
(macrolet
((%m (z) z))
(loop for i from 0 below 100 by 7
when (> i 50) return (expand-in-current-env (%m i))))
56)
(deftest loop.13.90
(macrolet
((%m (z) z))
(loop return (expand-in-current-env (%m 'a))))
a)
......@@ -331,3 +331,38 @@
(loop for x in '(1 2 nil 3 4 nil 6 nil)
when x summing it)
16)
;;; Test that explicit calls to macroexpand in subforms
;;; are done in the correct environment
(deftest loop.14.46
(macrolet
((%m (z) z))
(loop for x from 1 to 6
when (expand-in-current-env (%m (evenp x)))
collect x))
(2 4 6))
(deftest loop.14.47
(macrolet
((%m (z) z))
(loop for x from 1 to 6
unless (expand-in-current-env (%m (evenp x)))
collect x))
(1 3 5))
(deftest loop.14.48
(macrolet
((%m (z) z))
(loop for x from 1 to 6
when (expand-in-current-env (%m t))
sum x))
21)
(deftest loop.14.49
(macrolet
((%m (z) z))
(loop for x from 1 to 10
if (expand-in-current-env (%m (evenp x)))
collect x end))
(2 4 6 8 10))
......@@ -131,3 +131,15 @@
and j = 0 then (+ j i)
collect j)
(0 1 3 6 10))
;;; Test that explicit calls to macroexpand in subforms
;;; are done in the correct environment
(deftest loop.17.22
(macrolet
((%m (z) z))
(loop with x = 0
initially (expand-in-current-env (%m (incf x)))
until t
finally (expand-in-current-env (%m (return x)))))
1)
......@@ -140,3 +140,24 @@
1 2 2)
;;; Test that explicit calls to macroexpand in subforms
;;; are done in the correct environment
(deftest loop.2.24
(macrolet
((%m (z) z))
(loop for x in (expand-in-current-env (%m '(1 2 3))) sum x))
6)
(deftest loop.2.25
(macrolet
((%m (z) z))
(loop for (x . y) in (expand-in-current-env (%m '((a . b) (c . d) (e . f))))
collect (list x y)))
((a b) (c d) (e f)))
(deftest loop.2.26
(macrolet
((%m (z) z))
(loop as x in (expand-in-current-env (%m '(1 2 3))) sum x))
6)
\ No newline at end of file
......@@ -135,3 +135,33 @@
a b i))
(a c e g)
1 2 2)
;;; Test that explicit calls to macroexpand in subforms
;;; are done in the correct environment
(deftest loop.3.24
(macrolet
((%m (z) z))
(loop for x on (expand-in-current-env (%m '(1 2 3))) sum (car x)))
6)
(deftest loop.3.25
(macrolet
((%m (z) z))
(loop for e on (expand-in-current-env (%m '(a b c d e f))) by #'cddr
collect (car e)))
(a c e))
(deftest loop.3.26
(macrolet
((%m (z) z))
(loop for e on '(a b c d e f)
by (expand-in-current-env (%m #'cddr))
collect (car e)))
(a c e))
(deftest loop.3.27
(macrolet
((%m (z) z))
(loop as x on (expand-in-current-env (%m '(1 2 3))) sum (car x)))
6)
......@@ -58,3 +58,51 @@
for x = 1 count x until t))
program-error)
t)
;;; Test that explicit calls to macroexpand in subforms
;;; are done in the correct environment
(deftest loop.4.9
(macrolet
((%m (z) z))
(loop
for x = (expand-in-current-env (%m 1)) then (1+ x)
until (> x 5)
collect x))
(1 2 3 4 5))
(deftest loop.4.10
(macrolet
((%m (z) z))
(loop
for x = 1 then (expand-in-current-env (%m (1+ x)))
until (> x 5)
collect x))
(1 2 3 4 5))
(deftest loop.4.11
(macrolet
((%m (z) z))
(loop
for x = 1 then (1+ x)
until (expand-in-current-env (%m (> x 5)))
collect x))
(1 2 3 4 5))
(deftest loop.4.12
(macrolet
((%m (z) z))
(loop
for x = 1 then (1+ x)
while (expand-in-current-env (%m (<= x 5)))
collect x))
(1 2 3 4 5))
(deftest loop.4.13
(macrolet
((%m (z) z))
(loop
for x = 1 then (1+ x)
until (> x 5)
collect (expand-in-current-env (%m x))))
(1 2 3 4 5))
......@@ -190,6 +190,24 @@
collect (list fvals r)))
nil)
;;; Test that explicit calls to macroexpand in subforms
;;; are done in the correct environment
(deftest loop.5.44
(macrolet
((%m (z) z))
(loop for x across (expand-in-current-env (%m "148X")) collect x))
(#\1 #\4 #\8 #\X))
(deftest loop.5.45
(macrolet
((%m (z) z))
(loop as x across (expand-in-current-env (%m #*00110110)) collect x))
(0 0 1 1 0 1 1 0))
;;; FIXME
;;; Add tests for other specialized array types (integer types, floats, complex)
;;; Error cases
(deftest loop.5.error.1
......@@ -219,5 +237,3 @@
for e from 1 to 5 collect e))
program-error)
t)
......@@ -253,6 +253,24 @@
#'symbol<)
(a b c))
;;; Test that explicit calls to macroexpand in subforms
;;; are done in the correct environment
(deftest loop.6.41
(macrolet
((%m (z) z))
(loop for x being the hash-value of
(expand-in-current-env (%m *loop.6.hash.1*)) sum x))
6)
(deftest loop.6.42
(macrolet
((%m (z) z))
(sort (loop for x being the hash-key of
(expand-in-current-env (%m *loop.6.hash.1*)) collect x)
#'symbol<))
(a b c))
;;; Error tests
(deftest loop.6.error.1
......
......@@ -209,3 +209,35 @@
#'string<)
("A" "B" "BAR" "BAZ" "C" "FOO"))
;;; Test that explicit calls to macroexpand in subforms
;;; are done in the correct environment
(deftest loop.7.33
(macrolet
((%m (z) z))
(sort (mapcar #'symbol-name
(loop for x being the symbols of
(expand-in-current-env (%m "LOOP.CL-TEST.1"))
collect x))
#'string<))
("A" "B" "BAR" "BAZ" "C" "FOO"))
(deftest loop.7.34
(macrolet
((%m (z) z))
(sort (mapcar #'symbol-name
(loop for x being the external-symbols of
(expand-in-current-env (%m "LOOP.CL-TEST.1"))
collect x))
#'string<))
("A" "B" "C"))
(deftest loop.7.35
(macrolet
((%m (z) z))
(sort (mapcar #'symbol-name
(loop for x being the present-symbols of
(expand-in-current-env (%m "LOOP.CL-TEST.2"))
collect x))
#'string<))
("X" "Y" "Z"))
......@@ -116,6 +116,15 @@
return 3)
2)
;;; Test that explicit calls to macroexpand in subforms
;;; are done in the correct environment
(deftest loop.8.24
(macrolet
((%m (z) z))
(loop with x = (expand-in-current-env (%m 1)) do (return x)))
1)
;;; Error cases
;;; The spec says (in section 6.1.1.7) that:
......
......@@ -226,3 +226,40 @@
(deftest loop.9.42
(loop for x in '(a b c d e) nconc (cons x 'foo))
(a b c d e . foo))
;;; Test that explicit calls to macroexpand in subforms
;;; are done in the correct environment
(deftest loop.9.43
(macrolet
((%m (z) z))
(loop for x in '(1 2 3) collect (expand-in-current-env (%m (- x)))))
(-1 -2 -3))
(deftest loop.9.44
(macrolet
((%m (z) z))
(loop for x in '(1 2 3) collecting (expand-in-current-env (%m (list x)))))
((1) (2) (3)))
(deftest loop.9.45
(macrolet
((%m (z) z))
(loop for x in '(a b c)
collect (expand-in-current-env (%m (list x))) into foo
finally (return (reverse foo))))
((c) (b) (a)))
(deftest loop.9.46
(macrolet
((%m (z) z))
(loop for x in '((a b) (c d) (e f g) () (i))
append (expand-in-current-env (%m x))))
(a b c d e f g i))
(deftest loop.9.47
(macrolet
((%m (z) z))
(loop for x in '((a b) (c d) (e f g) () (i))
nconc (expand-in-current-env (%m (copy-seq x)))))
(a b c d e f g i))
......@@ -84,6 +84,17 @@
(multiple-value-bind () (values 1 2 3 4 5))
nil)
;;; Test that explicit calls to macroexpand in subforms
;;; are done in the correct environment
(deftest multiple-value-bind.14
(macrolet
((%m (z) z))
(multiple-value-bind (x y z)
(expand-in-current-env (%m (values 1 2 3)))
(list x y z)))
(1 2 3))
;;; Error cases
(deftest multiple-value-bind.error.1
......
......@@ -37,12 +37,30 @@
always (equal x (multiple-value-list (values-list x)))))
nil)
;;; Test that explicit calls to macroexpand in subforms
;;; are done in the correct environment
(deftest multiple-value-list.8
(macrolet
((%m (z) z))
(multiple-value-list (expand-in-current-env (%m 1))))
(1))
(deftest multiple-value-list.9
(macrolet
((%m (z) z))
(multiple-value-list (expand-in-current-env (%m (values 1 2 3)))))
(1 2 3))
;;; Test that the argument is evaluated just once
(deftest multiple-value-list.order.1
(let ((i 0))
(values (multiple-value-list (incf i)) i))
(1) 1)
;;; Error tests
(deftest multiple-value-list.error.1
(signals-error (funcall (macro-function 'multiple-value-list))
program-error)
......
......@@ -119,6 +119,27 @@
(multiple-value-setq nil (values 'a 'b))
a)
;;; Test that explicit calls to macroexpand in subforms
;;; are done in the correct environment
(deftest multiple-value-setq.16
(macrolet
((%m (z) z))
(let ((x :bad))
(symbol-macrolet ((z (expand-in-current-env (%m x))))
(multiple-value-setq (z) :good))
x))
:good)
(deftest multiple-value-setq.17
(macrolet
((%m (z) z))
(let ((x :bad))
(values
(multiple-value-setq (x) (expand-in-current-env (%m :good)))
x)))
:good :good)
;;; Error tests
(deftest multiple-value-setq.error.1
......
......@@ -27,6 +27,23 @@
(nth-value 100 'a)
nil)
;;; Test that explicit calls to macroexpand in subforms
;;; are done in the correct environment
(deftest nth-value.6
(macrolet
((%m (z) z))
(nth-value (expand-in-current-env (%m 1)) (values 'a 'b 'c)))
b)
(deftest nth-value.7
(macrolet
((%m (z) z))
(nth-value 1 (expand-in-current-env (%m (values 'a 'b 'c)))))
b)
;;; Order of evaluation test
(deftest nth-value.order.1
(let ((i 0) x y)
(values
......@@ -35,6 +52,8 @@
i x y))
d 2 1 2)
;;; Error tests
(deftest nth-value.error.1
(signals-error (funcall (macro-function 'nth-value))
program-error)
......
......@@ -41,6 +41,28 @@
(or (values nil 1 2) (values 1 nil 2))
1 nil 2)
;;; Test that explicit calls to macroexpand in subforms
;;; are done in the correct environment
(deftest or.10