X-Git-Url: http://repo.macrolet.net/gitweb/?a=blobdiff_plain;f=tests%2Floop.pure.lisp;h=278fa4c5c60bf2440bd8786211462b6f3e7ee964;hb=8833e4478c33f09e642c8886fc3505348a744299;hp=5275cc4ba528b6e8d553f6e336359676eedc3e62;hpb=c3d4cd43d7cd8e0495dbb9c11fd9c121ea069a45;p=sbcl.git diff --git a/tests/loop.pure.lisp b/tests/loop.pure.lisp index 5275cc4..278fa4c 100644 --- a/tests/loop.pure.lisp +++ b/tests/loop.pure.lisp @@ -67,3 +67,107 @@ ;;; similar to gcl/ansi-test LOOP.1.27, and fixed at the same time: (assert (equal (loop for x downto 7 by 2 from 13 collect x) '(13 11 9 7))) + +;;; some more from gcl/ansi-test: +(let ((table (make-hash-table))) + (setf (gethash 'foo table) '(bar baz)) + (assert (= (loop for nil being the hash-keys of table count t) 1)) + (assert (equal (loop for nil being the hash-keys of table + using (hash-value (v1 . v2)) + when v1 + return v2) + '(baz)))) + +(assert (= (loop for nil being the external-symbols of :cl count t) 978)) +(assert (= (loop for x being the external-symbols of :cl count x) 977)) + +(let ((*package* (find-package :cl))) + (assert (= (loop for x being each external-symbol count t) 978))) + +(assert (eq (loop for a = (return t) return nil) t)) + +(multiple-value-bind (result error) + (ignore-errors + (loop for nil being the external-symbols of :nonexistent-package + count t)) + (assert (null result)) + (assert (typep error 'package-error))) + +(assert (equal (loop for i from 1 repeat (the (integer 7 7) 7) collect i) + '(1 2 3 4 5 6 7))) + +(multiple-value-bind (result error) + (ignore-errors + (eval '(loop for i from 1 repeat 7 of-type fixnum collect i))) + (assert (null result)) + (assert (typep error 'program-error))) + +(assert (equal + (ignore-errors (loop for i from 1 repeat 6.5 collect i)) + (ignore-errors (loop for i from 1 repeat (eval '6.5) collect i)))) + +(assert (eq (block nil + (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))))