X-Git-Url: http://repo.macrolet.net/gitweb/?a=blobdiff_plain;f=tests%2Floop.pure.lisp;h=95933d4d5ac8cd99b7294d4a0a3b6fc5cc0d7f34;hb=8922e16df316133288d46695ff2d7596c397a6a0;hp=307129b5103e106ee0fddcd1eb9aa46856d1655b;hpb=89925c1f87e50d52862bf26bfa07962925ddb403;p=sbcl.git diff --git a/tests/loop.pure.lisp b/tests/loop.pure.lisp index 307129b..95933d4 100644 --- a/tests/loop.pure.lisp +++ b/tests/loop.pure.lisp @@ -110,3 +110,72 @@ (loop named foo do (loop-finish) finally (return :good)) :bad) :good)) + +(assert (= (loop with (a nil) = '(1 2) return a) 1)) +(assert (= (loop with (nil a) = '(1 2) return a) 2)) +(assert (= (loop with (a . nil) = '(1 2) return a) 1)) +(assert (equal (loop with (nil . a) = '(1 2) return a) '(2))) + +(multiple-value-bind (result error) + (ignore-errors + (loop for i in '(1 2 3) collect i always (< i 4))) + (assert (null result)) + (assert (typep error 'program-error))) +(assert (equal + (loop for i in '(1 2 3) collect i into foo always (< i 4) + finally (return foo)) + '(1 2 3))) +(assert (equal + (loop for i in '(1 2 3) collect i into foo always (= i 4) + finally (return foo)) + nil)) +(multiple-value-bind (result error) + (ignore-errors + (loop for i in '(1 2 3) always (< i 4) collect i)) + (assert (null result)) + (assert (typep error 'program-error))) +(assert (equal + (loop for i in '(1 2 3) always (< i 4) collect i into foo + finally (return foo)) + '(1 2 3))) +(assert (equal + (loop for i in '(1 2 3) always (= i 4) collect i into foo + finally (return foo)) + nil)) +(multiple-value-bind (result error) + (ignore-errors + (loop for i in '(1 2 3) thereis (= i 3) collect i)) + (assert (null result)) + (assert (typep error 'program-error))) + +(multiple-value-bind (result error) + (ignore-errors + (loop with i = 1 for x from 1 to 3 collect x into i)) + (assert (null result)) + (assert (typep error 'program-error))) +(multiple-value-bind (result error) + ;; this one has a plausible interpretation in terms of LET*, but + ;; ANSI seems specifically to disallow it + (ignore-errors + (loop with i = 1 with i = (1+ i) + for x from 1 to 3 + collect (+ x i))) + (assert (null result)) + (assert (typep error 'program-error))) + +(let ((it 'z)) + (assert (equal + ;; this one just seems weird. Nevertheless... + (loop for i in '(a b c d) + when i + collect it + and collect it) + '(a z b z c z d z)))) + +(let ((ht (make-hash-table))) + (setf (gethash 1 ht) 3) + (setf (gethash 7 ht) 15) + (assert (= (loop for v fixnum being each hash-key in ht sum v) 8)) + (assert (= (loop for v fixnum being each hash-value in ht sum v) 18)) + (assert (raises-error? (loop for v float being each hash-value in ht sum v) + type-error)))