rewrite assoc-value to look up the alist entry only once
[alexandria.git] / tests.lisp
blobf717402c6561ca79fac74aa1dda620eb8ebbbd9d
1 (in-package :cl-user)
3 (defpackage :alexandria-tests
4 (:use :cl :alexandria #+sbcl :sb-rt #-sbcl :rtest)
5 (:import-from #+sbcl :sb-rt #-sbcl :rtest
6 #:*compile-tests* #:*expected-failures*))
8 (in-package :alexandria-tests)
10 (defun run-tests (&key ((:compiled *compile-tests)))
11 (do-tests))
13 ;;;; Arrays
15 (deftest copy-array.1
16 (let* ((orig (vector 1 2 3))
17 (copy (copy-array orig)))
18 (values (eq orig copy) (equalp orig copy)))
19 nil t)
21 (deftest copy-array.2
22 (let ((orig (make-array 1024 :fill-pointer 0)))
23 (vector-push-extend 1 orig)
24 (vector-push-extend 2 orig)
25 (vector-push-extend 3 orig)
26 (let ((copy (copy-array orig)))
27 (values (eq orig copy) (equalp orig copy)
28 (array-has-fill-pointer-p copy)
29 (eql (fill-pointer orig) (fill-pointer copy)))))
30 nil t t t)
32 (deftest array-index.1
33 (typep 0 'array-index)
36 ;;;; Conditions
38 (deftest unwind-protect-case.1
39 (let (result)
40 (unwind-protect-case ()
41 (random 10)
42 (:normal (push :normal result))
43 (:abort (push :abort result))
44 (:always (push :always result)))
45 result)
46 (:always :normal))
48 (deftest unwind-protect-case.2
49 (let (result)
50 (unwind-protect-case ()
51 (random 10)
52 (:always (push :always result))
53 (:normal (push :normal result))
54 (:abort (push :abort result)))
55 result)
56 (:normal :always))
58 (deftest unwind-protect-case.3
59 (let (result1 result2 result3)
60 (ignore-errors
61 (unwind-protect-case ()
62 (error "FOOF!")
63 (:normal (push :normal result1))
64 (:abort (push :abort result1))
65 (:always (push :always result1))))
66 (catch 'foof
67 (unwind-protect-case ()
68 (throw 'foof 42)
69 (:normal (push :normal result2))
70 (:abort (push :abort result2))
71 (:always (push :always result2))))
72 (block foof
73 (unwind-protect-case ()
74 (return-from foof 42)
75 (:normal (push :normal result3))
76 (:abort (push :abort result3))
77 (:always (push :always result3))))
78 (values result1 result2 result3))
79 (:always :abort)
80 (:always :abort)
81 (:always :abort))
83 (deftest unwind-protect-case.4
84 (let (result)
85 (unwind-protect-case (aborted-p)
86 (random 42)
87 (:always (setq result aborted-p)))
88 result)
89 nil)
91 (deftest unwind-protect-case.5
92 (let (result)
93 (block foof
94 (unwind-protect-case (aborted-p)
95 (return-from foof)
96 (:always (setq result aborted-p))))
97 result)
100 ;;;; Control flow
102 (deftest switch.1
103 (switch (13 :test =)
104 (12 :oops)
105 (13.0 :yay))
106 :yay)
108 (deftest switch.2
109 (switch (13)
110 ((+ 12 2) :oops)
111 ((- 13 1) :oops2)
112 (t :yay))
113 :yay)
115 (deftest eswitch.1
116 (let ((x 13))
117 (eswitch (x :test =)
118 (12 :oops)
119 (13.0 :yay)))
120 :yay)
122 (deftest eswitch.2
123 (let ((x 13))
124 (eswitch (x :key 1+)
125 (11 :oops)
126 (14 :yay)))
127 :yay)
129 (deftest cswitch.1
130 (cswitch (13 :test =)
131 (12 :oops)
132 (13.0 :yay))
133 :yay)
135 (deftest cswitch.2
136 (cswitch (13 :key 1-)
137 (12 :yay)
138 (13.0 :oops))
139 :yay)
141 (deftest whichever.1
142 (let ((x (whichever 1 2 3)))
143 (and (member x '(1 2 3)) t))
146 (deftest whichever.2
147 (let* ((a 1)
148 (b 2)
149 (c 3)
150 (x (whichever a b c)))
151 (and (member x '(1 2 3)) t))
154 (deftest xor.1
155 (xor nil nil 1 nil)
159 ;;;; Definitions
161 (deftest define-constant.1
162 (let ((name (gensym)))
163 (eval `(define-constant ,name "FOO" :test 'equal))
164 (eval `(define-constant ,name "FOO" :test 'equal))
165 (values (equal "FOO" (symbol-value name))
166 (constantp name)))
170 (deftest define-constant.2
171 (let ((name (gensym)))
172 (eval `(define-constant ,name 13))
173 (eval `(define-constant ,name 13))
174 (values (eql 13 (symbol-value name))
175 (constantp name)))
179 ;;;; Errors
181 ;;; TYPEP is specified to return a generalized boolean and, for
182 ;;; example, ECL exploits this by returning the superclasses of ERROR
183 ;;; in this case.
184 (defun errorp (x)
185 (not (null (typep x 'error))))
187 (deftest required-argument.1
188 (multiple-value-bind (res err)
189 (ignore-errors (required-argument))
190 (errorp err))
193 ;;;; Hash tables
195 (deftest ensure-hash-table.1
196 (let ((table (make-hash-table))
197 (x (list 1)))
198 (multiple-value-bind (value already-there)
199 (ensure-gethash x table 42)
200 (and (= value 42)
201 (not already-there)
202 (= 42 (gethash x table))
203 (multiple-value-bind (value2 already-there2)
204 (ensure-gethash x table 13)
205 (and (= value2 42)
206 already-there2
207 (= 42 (gethash x table)))))))
210 #+clisp (pushnew 'copy-hash-table.1 *expected-failures*)
212 (deftest copy-hash-table.1
213 (let ((orig (make-hash-table :test 'eq :size 123))
214 (foo "foo"))
215 (setf (gethash orig orig) t
216 (gethash foo orig) t)
217 (let ((eq-copy (copy-hash-table orig))
218 (eql-copy (copy-hash-table orig :test 'eql))
219 (equal-copy (copy-hash-table orig :test 'equal))
220 ;; CLISP overflows the stack with this bit.
221 ;; See <http://sourceforge.net/tracker/index.php?func=detail&aid=2029069&group_id=1355&atid=101355>.
222 #-clisp (equalp-copy (copy-hash-table orig :test 'equalp)))
223 (list (eql (hash-table-size eq-copy) (hash-table-size orig))
224 (eql (hash-table-rehash-size eq-copy)
225 (hash-table-rehash-size orig))
226 (hash-table-count eql-copy)
227 (gethash orig eq-copy)
228 (gethash (copy-seq foo) eql-copy)
229 (gethash foo eql-copy)
230 (gethash (copy-seq foo) equal-copy)
231 (gethash "FOO" equal-copy)
232 #-clisp (gethash "FOO" equalp-copy))))
233 (t t 2 t nil t t nil t))
235 (deftest copy-hash-table.2
236 (let ((ht (make-hash-table))
237 (list (list :list (vector :A :B :C))))
238 (setf (gethash 'list ht) list)
239 (let* ((shallow-copy (copy-hash-table ht))
240 (deep1-copy (copy-hash-table ht :key 'copy-list))
241 (list (gethash 'list ht))
242 (shallow-list (gethash 'list shallow-copy))
243 (deep1-list (gethash 'list deep1-copy)))
244 (list (eq ht shallow-copy)
245 (eq ht deep1-copy)
246 (eq list shallow-list)
247 (eq list deep1-list) ; outer list was copied.
248 (eq (second list) (second shallow-list))
249 (eq (second list) (second deep1-list)) ; inner vector wasn't copied.
251 (nil nil t nil t t))
253 (deftest maphash-keys.1
254 (let ((keys nil)
255 (table (make-hash-table)))
256 (declare (notinline maphash-keys))
257 (dotimes (i 10)
258 (setf (gethash i table) t))
259 (maphash-keys (lambda (k) (push k keys)) table)
260 (set-equal keys '(0 1 2 3 4 5 6 7 8 9)))
263 (deftest maphash-values.1
264 (let ((vals nil)
265 (table (make-hash-table)))
266 (declare (notinline maphash-values))
267 (dotimes (i 10)
268 (setf (gethash i table) (- i)))
269 (maphash-values (lambda (v) (push v vals)) table)
270 (set-equal vals '(0 -1 -2 -3 -4 -5 -6 -7 -8 -9)))
273 (deftest hash-table-keys.1
274 (let ((table (make-hash-table)))
275 (dotimes (i 10)
276 (setf (gethash i table) t))
277 (set-equal (hash-table-keys table) '(0 1 2 3 4 5 6 7 8 9)))
280 (deftest hash-table-values.1
281 (let ((table (make-hash-table)))
282 (dotimes (i 10)
283 (setf (gethash (gensym) table) i))
284 (set-equal (hash-table-values table) '(0 1 2 3 4 5 6 7 8 9)))
287 (deftest hash-table-alist.1
288 (let ((table (make-hash-table)))
289 (dotimes (i 10)
290 (setf (gethash i table) (- i)))
291 (let ((alist (hash-table-alist table)))
292 (list (length alist)
293 (assoc 0 alist)
294 (assoc 3 alist)
295 (assoc 9 alist)
296 (assoc nil alist))))
297 (10 (0 . 0) (3 . -3) (9 . -9) nil))
299 (deftest hash-table-plist.1
300 (let ((table (make-hash-table)))
301 (dotimes (i 10)
302 (setf (gethash i table) (- i)))
303 (let ((plist (hash-table-plist table)))
304 (list (length plist)
305 (getf plist 0)
306 (getf plist 2)
307 (getf plist 7)
308 (getf plist nil))))
309 (20 0 -2 -7 nil))
311 #+clisp (pushnew 'alist-hash-table.1 *expected-failures*)
313 (deftest alist-hash-table.1
314 (let* ((alist '((0 a) (1 b) (2 c)))
315 (table (alist-hash-table alist)))
316 (list (hash-table-count table)
317 (gethash 0 table)
318 (gethash 1 table)
319 (gethash 2 table)
320 (hash-table-test table))) ; CLISP returns EXT:FASTHASH-EQL.
321 (3 (a) (b) (c) eql))
323 #+clisp (pushnew 'plist-hash-table.1 *expected-failures*)
325 (deftest plist-hash-table.1
326 (let* ((plist '(:a 1 :b 2 :c 3))
327 (table (plist-hash-table plist :test 'eq)))
328 (list (hash-table-count table)
329 (gethash :a table)
330 (gethash :b table)
331 (gethash :c table)
332 (gethash 2 table)
333 (gethash nil table)
334 (hash-table-test table))) ; CLISP returns EXT:FASTHASH-EQ.
335 (3 1 2 3 nil nil eq))
337 ;;;; Functions
339 (deftest disjoin.1
340 (let ((disjunction (disjoin (lambda (x)
341 (and (consp x) :cons))
342 (lambda (x)
343 (and (stringp x) :string)))))
344 (list (funcall disjunction 'zot)
345 (funcall disjunction '(foo bar))
346 (funcall disjunction "test")))
347 (nil :cons :string))
349 (deftest disjoin.2
350 (let ((disjunction (disjoin #'zerop)))
351 (list (funcall disjunction 0)
352 (funcall disjunction 1)))
353 (t nil))
355 (deftest conjoin.1
356 (let ((conjunction (conjoin #'consp
357 (lambda (x)
358 (stringp (car x)))
359 (lambda (x)
360 (char (car x) 0)))))
361 (list (funcall conjunction 'zot)
362 (funcall conjunction '(foo))
363 (funcall conjunction '("foo"))))
364 (nil nil #\f))
366 (deftest conjoin.2
367 (let ((conjunction (conjoin #'zerop)))
368 (list (funcall conjunction 0)
369 (funcall conjunction 1)))
370 (t nil))
372 (deftest compose.1
373 (let ((composite (compose '1+
374 (lambda (x)
375 (* x 2))
376 #'read-from-string)))
377 (funcall composite "1"))
380 (deftest compose.2
381 (let ((composite
382 (locally (declare (notinline compose))
383 (compose '1+
384 (lambda (x)
385 (* x 2))
386 #'read-from-string))))
387 (funcall composite "2"))
390 (deftest compose.3
391 (let ((compose-form (funcall (compiler-macro-function 'compose)
392 '(compose '1+
393 (lambda (x)
394 (* x 2))
395 #'read-from-string)
396 nil)))
397 (let ((fun (funcall (compile nil `(lambda () ,compose-form)))))
398 (funcall fun "3")))
401 (deftest compose.4
402 (let ((composite (compose #'zerop)))
403 (list (funcall composite 0)
404 (funcall composite 1)))
405 (t nil))
407 (deftest multiple-value-compose.1
408 (let ((composite (multiple-value-compose
409 #'truncate
410 (lambda (x y)
411 (values y x))
412 (lambda (x)
413 (with-input-from-string (s x)
414 (values (read s) (read s)))))))
415 (multiple-value-list (funcall composite "2 7")))
416 (3 1))
418 (deftest multiple-value-compose.2
419 (let ((composite (locally (declare (notinline multiple-value-compose))
420 (multiple-value-compose
421 #'truncate
422 (lambda (x y)
423 (values y x))
424 (lambda (x)
425 (with-input-from-string (s x)
426 (values (read s) (read s))))))))
427 (multiple-value-list (funcall composite "2 11")))
428 (5 1))
430 (deftest multiple-value-compose.3
431 (let ((compose-form (funcall (compiler-macro-function 'multiple-value-compose)
432 '(multiple-value-compose
433 #'truncate
434 (lambda (x y)
435 (values y x))
436 (lambda (x)
437 (with-input-from-string (s x)
438 (values (read s) (read s)))))
439 nil)))
440 (let ((fun (funcall (compile nil `(lambda () ,compose-form)))))
441 (multiple-value-list (funcall fun "2 9"))))
442 (4 1))
444 (deftest multiple-value-compose.4
445 (let ((composite (multiple-value-compose #'truncate)))
446 (multiple-value-list (funcall composite 9 2)))
447 (4 1))
449 (deftest curry.1
450 (let ((curried (curry '+ 3)))
451 (funcall curried 1 5))
454 (deftest curry.2
455 (let ((curried (locally (declare (notinline curry))
456 (curry '* 2 3))))
457 (funcall curried 7))
460 (deftest curry.3
461 (let ((curried-form (funcall (compiler-macro-function 'curry)
462 '(curry '/ 8)
463 nil)))
464 (let ((fun (funcall (compile nil `(lambda () ,curried-form)))))
465 (funcall fun 2)))
468 (deftest rcurry.1
469 (let ((r (rcurry '/ 2)))
470 (funcall r 8))
473 (deftest named-lambda.1
474 (let ((fac (named-lambda fac (x)
475 (if (> x 1)
476 (* x (fac (- x 1)))
477 x))))
478 (funcall fac 5))
479 120)
481 (deftest named-lambda.2
482 (let ((fac (named-lambda fac (&key x)
483 (if (> x 1)
484 (* x (fac :x (- x 1)))
485 x))))
486 (funcall fac :x 5))
487 120)
489 ;;;; Lists
491 (deftest alist-plist.1
492 (alist-plist '((a . 1) (b . 2) (c . 3)))
493 (a 1 b 2 c 3))
495 (deftest plist-alist.1
496 (plist-alist '(a 1 b 2 c 3))
497 ((a . 1) (b . 2) (c . 3)))
499 (deftest unionf.1
500 (let* ((list (list 1 2 3))
501 (orig list))
502 (unionf list (list 1 2 4))
503 (values (equal orig (list 1 2 3))
504 (eql (length list) 4)
505 (set-difference list (list 1 2 3 4))
506 (set-difference (list 1 2 3 4) list)))
510 nil)
512 (deftest nunionf.1
513 (let ((list (list 1 2 3)))
514 (nunionf list (list 1 2 4))
515 (values (eql (length list) 4)
516 (set-difference (list 1 2 3 4) list)
517 (set-difference list (list 1 2 3 4))))
520 nil)
522 (deftest appendf.1
523 (let* ((list (list 1 2 3))
524 (orig list))
525 (appendf list '(4 5 6) '(7 8))
526 (list list (eq list orig)))
527 ((1 2 3 4 5 6 7 8) nil))
529 (deftest nconcf.1
530 (let ((list1 (list 1 2 3))
531 (list2 (list 4 5 6)))
532 (nconcf list1 list2 (list 7 8 9))
533 list1)
534 (1 2 3 4 5 6 7 8 9))
536 (deftest circular-list.1
537 (let ((circle (circular-list 1 2 3)))
538 (list (first circle)
539 (second circle)
540 (third circle)
541 (fourth circle)
542 (eq circle (nthcdr 3 circle))))
543 (1 2 3 1 t))
545 (deftest circular-list-p.1
546 (let* ((circle (circular-list 1 2 3 4))
547 (tree (list circle circle))
548 (dotted (cons circle t))
549 (proper (list 1 2 3 circle))
550 (tailcirc (list* 1 2 3 circle)))
551 (list (circular-list-p circle)
552 (circular-list-p tree)
553 (circular-list-p dotted)
554 (circular-list-p proper)
555 (circular-list-p tailcirc)))
556 (t nil nil nil t))
558 (deftest circular-list-p.2
559 (circular-list-p 'foo)
560 nil)
562 (deftest circular-tree-p.1
563 (let* ((circle (circular-list 1 2 3 4))
564 (tree1 (list circle circle))
565 (tree2 (let* ((level2 (list 1 nil 2))
566 (level1 (list level2)))
567 (setf (second level2) level1)
568 level1))
569 (dotted (cons circle t))
570 (proper (list 1 2 3 circle))
571 (tailcirc (list* 1 2 3 circle))
572 (quite-proper (list 1 2 3))
573 (quite-dotted (list 1 (cons 2 3))))
574 (list (circular-tree-p circle)
575 (circular-tree-p tree1)
576 (circular-tree-p tree2)
577 (circular-tree-p dotted)
578 (circular-tree-p proper)
579 (circular-tree-p tailcirc)
580 (circular-tree-p quite-proper)
581 (circular-tree-p quite-dotted)))
582 (t t t t t t nil nil))
584 (deftest proper-list-p.1
585 (let ((l1 (list 1))
586 (l2 (list 1 2))
587 (l3 (cons 1 2))
588 (l4 (list (cons 1 2) 3))
589 (l5 (circular-list 1 2)))
590 (list (proper-list-p l1)
591 (proper-list-p l2)
592 (proper-list-p l3)
593 (proper-list-p l4)
594 (proper-list-p l5)))
595 (t t nil t nil))
597 (deftest proper-list-p.2
598 (proper-list-p '(1 2 . 3))
599 nil)
601 (deftest proper-list.type.1
602 (let ((l1 (list 1))
603 (l2 (list 1 2))
604 (l3 (cons 1 2))
605 (l4 (list (cons 1 2) 3))
606 (l5 (circular-list 1 2)))
607 (list (typep l1 'proper-list)
608 (typep l2 'proper-list)
609 (typep l3 'proper-list)
610 (typep l4 'proper-list)
611 (typep l5 'proper-list)))
612 (t t nil t nil))
614 (deftest proper-list-length.1
615 (values
616 (proper-list-length nil)
617 (proper-list-length (list 1))
618 (proper-list-length (list 2 2))
619 (proper-list-length (list 3 3 3))
620 (proper-list-length (list 4 4 4 4))
621 (proper-list-length (list 5 5 5 5 5))
622 (proper-list-length (list 6 6 6 6 6 6))
623 (proper-list-length (list 7 7 7 7 7 7 7))
624 (proper-list-length (list 8 8 8 8 8 8 8 8))
625 (proper-list-length (list 9 9 9 9 9 9 9 9 9)))
626 0 1 2 3 4 5 6 7 8 9)
628 (deftest proper-list-length.2
629 (flet ((plength (x)
630 (handler-case
631 (proper-list-length x)
632 (type-error ()
633 :ok))))
634 (values
635 (plength (list* 1))
636 (plength (list* 2 2))
637 (plength (list* 3 3 3))
638 (plength (list* 4 4 4 4))
639 (plength (list* 5 5 5 5 5))
640 (plength (list* 6 6 6 6 6 6))
641 (plength (list* 7 7 7 7 7 7 7))
642 (plength (list* 8 8 8 8 8 8 8 8))
643 (plength (list* 9 9 9 9 9 9 9 9 9))))
644 :ok :ok :ok
645 :ok :ok :ok
646 :ok :ok :ok)
648 (deftest lastcar.1
649 (let ((l1 (list 1))
650 (l2 (list 1 2)))
651 (list (lastcar l1)
652 (lastcar l2)))
653 (1 2))
655 (deftest lastcar.error.2
656 (handler-case
657 (progn
658 (lastcar (circular-list 1 2 3))
659 nil)
660 (error ()
664 (deftest setf-lastcar.1
665 (let ((l (list 1 2 3 4)))
666 (values (lastcar l)
667 (progn
668 (setf (lastcar l) 42)
669 (lastcar l))))
673 (deftest setf-lastcar.2
674 (let ((l (circular-list 1 2 3)))
675 (multiple-value-bind (res err)
676 (ignore-errors (setf (lastcar l) 4))
677 (typep err 'type-error)))
680 (deftest make-circular-list.1
681 (let ((l (make-circular-list 3 :initial-element :x)))
682 (setf (car l) :y)
683 (list (eq l (nthcdr 3 l))
684 (first l)
685 (second l)
686 (third l)
687 (fourth l)))
688 (t :y :x :x :y))
690 (deftest circular-list.type.1
691 (let* ((l1 (list 1 2 3))
692 (l2 (circular-list 1 2 3))
693 (l3 (list* 1 2 3 l2)))
694 (list (typep l1 'circular-list)
695 (typep l2 'circular-list)
696 (typep l3 'circular-list)))
697 (nil t t))
699 (deftest ensure-list.1
700 (let ((x (list 1))
701 (y 2))
702 (list (ensure-list x)
703 (ensure-list y)))
704 ((1) (2)))
706 (deftest ensure-cons.1
707 (let ((x (cons 1 2))
708 (y nil)
709 (z "foo"))
710 (values (ensure-cons x)
711 (ensure-cons y)
712 (ensure-cons z)))
713 (1 . 2)
714 (nil)
715 ("foo"))
717 (deftest setp.1
718 (setp '(1))
721 (deftest setp.2
722 (setp nil)
725 (deftest setp.3
726 (setp "foo")
727 nil)
729 (deftest setp.4
730 (setp '(1 2 3 1))
731 nil)
733 (deftest setp.5
734 (setp '(1 2 3))
737 (deftest setp.6
738 (setp '(a :a))
741 (deftest setp.7
742 (setp '(a :a) :key 'character)
743 nil)
745 (deftest setp.8
746 (setp '(a :a) :key 'character :test (constantly nil))
749 (deftest set-equal.1
750 (set-equal '(1 2 3) '(3 1 2))
753 (deftest set-equal.2
754 (set-equal '("Xa") '("Xb")
755 :test (lambda (a b) (eql (char a 0) (char b 0))))
758 (deftest set-equal.3
759 (set-equal '(1 2) '(4 2))
760 nil)
762 (deftest set-equal.4
763 (set-equal '(a b c) '(:a :b :c) :key 'string :test 'equal)
766 (deftest set-equal.5
767 (set-equal '(a d c) '(:a :b :c) :key 'string :test 'equal)
768 nil)
770 (deftest set-equal.6
771 (set-equal '(a b c) '(a b c d))
772 nil)
774 (deftest map-product.1
775 (map-product 'cons '(2 3) '(1 4))
776 ((2 . 1) (2 . 4) (3 . 1) (3 . 4)))
778 (deftest map-product.2
779 (map-product #'cons '(2 3) '(1 4))
780 ((2 . 1) (2 . 4) (3 . 1) (3 . 4)))
782 (deftest flatten.1
783 (flatten '((1) 2 (((3 4))) ((((5)) 6)) 7))
784 (1 2 3 4 5 6 7))
786 (deftest remove-from-plist.1
787 (let ((orig '(a 1 b 2 c 3 d 4)))
788 (list (remove-from-plist orig 'a 'c)
789 (remove-from-plist orig 'b 'd)
790 (remove-from-plist orig 'b)
791 (remove-from-plist orig 'a)
792 (remove-from-plist orig 'd 42 "zot")
793 (remove-from-plist orig 'a 'b 'c 'd)
794 (remove-from-plist orig 'a 'b 'c 'd 'x)
795 (equal orig '(a 1 b 2 c 3 d 4))))
796 ((b 2 d 4)
797 (a 1 c 3)
798 (a 1 c 3 d 4)
799 (b 2 c 3 d 4)
800 (a 1 b 2 c 3)
805 (deftest mappend.1
806 (mappend (compose 'list '*) '(1 2 3) '(1 2 3))
807 (1 4 9))
809 (deftest assoc-value.1
810 (let ((key1 '(complex key))
811 (key2 'simple-key)
812 (alist '())
813 (result '()))
814 (push 1 (assoc-value alist key1 :test #'equal))
815 (push 2 (assoc-value alist key1 :test 'equal))
816 (push 42 (assoc-value alist key2))
817 (push 43 (assoc-value alist key2 :test 'eq))
818 (push (assoc-value alist key1 :test #'equal) result)
819 (push (assoc-value alist key2) result)
821 (push 'very (rassoc-value alist (list 2 1) :test #'equal))
822 (push (cdr (assoc '(very complex key) alist :test #'equal)) result)
823 result)
824 ((2 1) (43 42) (2 1)))
826 ;;;; Numbers
828 (deftest clamp.1
829 (list (clamp 1.5 1 2)
830 (clamp 2.0 1 2)
831 (clamp 1.0 1 2)
832 (clamp 3 1 2)
833 (clamp 0 1 2))
834 (1.5 2.0 1.0 2 1))
836 (deftest gaussian-random.1
837 (let ((min -0.2)
838 (max +0.2))
839 (multiple-value-bind (g1 g2)
840 (gaussian-random min max)
841 (values (<= min g1 max)
842 (<= min g2 max)
843 (/= g1 g2) ;uh
849 (deftest iota.1
850 (iota 3)
851 (0 1 2))
853 (deftest iota.2
854 (iota 3 :start 0.0d0)
855 (0.0d0 1.0d0 2.0d0))
857 (deftest iota.3
858 (iota 3 :start 2 :step 3.0)
859 (2.0 5.0 8.0))
861 (deftest map-iota.1
862 (let (all)
863 (declare (notinline map-iota))
864 (values (map-iota (lambda (x) (push x all))
866 :start 2
867 :step 1.1d0)
868 all))
870 (4.2d0 3.1d0 2.0d0))
872 (deftest lerp.1
873 (lerp 0.5 1 2)
874 1.5)
876 (deftest lerp.2
877 (lerp 0.1 1 2)
878 1.1)
880 (deftest mean.1
881 (mean '(1 2 3))
884 (deftest mean.2
885 (mean '(1 2 3 4))
886 5/2)
888 (deftest mean.3
889 (mean '(1 2 10))
890 13/3)
892 (deftest median.1
893 (median '(100 0 99 1 98 2 97))
896 (deftest median.2
897 (median '(100 0 99 1 98 2 97 96))
898 193/2)
900 (deftest variance.1
901 (variance (list 1 2 3))
902 2/3)
904 (deftest standard-deviation.1
905 (< 0 (standard-deviation (list 1 2 3)) 1)
908 (deftest maxf.1
909 (let ((x 1))
910 (maxf x 2)
914 (deftest maxf.2
915 (let ((x 1))
916 (maxf x 0)
920 (deftest maxf.3
921 (let ((x 1)
922 (c 0))
923 (maxf x (incf c))
924 (list x c))
925 (1 1))
927 (deftest maxf.4
928 (let ((xv (vector 0 0 0))
929 (p 0))
930 (maxf (svref xv (incf p)) (incf p))
931 (list p xv))
932 (2 #(0 2 0)))
934 (deftest minf.1
935 (let ((y 1))
936 (minf y 0)
940 (deftest minf.2
941 (let ((xv (vector 10 10 10))
942 (p 0))
943 (minf (svref xv (incf p)) (incf p))
944 (list p xv))
945 (2 #(10 2 10)))
947 ;;;; Arrays
949 #+nil
950 (deftest array-index.type)
952 #+nil
953 (deftest copy-array)
955 ;;;; Sequences
957 (deftest rotate.1
958 (list (rotate (list 1 2 3) 0)
959 (rotate (list 1 2 3) 1)
960 (rotate (list 1 2 3) 2)
961 (rotate (list 1 2 3) 3)
962 (rotate (list 1 2 3) 4))
963 ((1 2 3)
964 (3 1 2)
965 (2 3 1)
966 (1 2 3)
967 (3 1 2)))
969 (deftest rotate.2
970 (list (rotate (vector 1 2 3 4) 0)
971 (rotate (vector 1 2 3 4))
972 (rotate (vector 1 2 3 4) 2)
973 (rotate (vector 1 2 3 4) 3)
974 (rotate (vector 1 2 3 4) 4)
975 (rotate (vector 1 2 3 4) 5))
976 (#(1 2 3 4)
977 #(4 1 2 3)
978 #(3 4 1 2)
979 #(2 3 4 1)
980 #(1 2 3 4)
981 #(4 1 2 3)))
983 (deftest rotate.3
984 (list (rotate (list 1 2 3) 0)
985 (rotate (list 1 2 3) -1)
986 (rotate (list 1 2 3) -2)
987 (rotate (list 1 2 3) -3)
988 (rotate (list 1 2 3) -4))
989 ((1 2 3)
990 (2 3 1)
991 (3 1 2)
992 (1 2 3)
993 (2 3 1)))
995 (deftest rotate.4
996 (list (rotate (vector 1 2 3 4) 0)
997 (rotate (vector 1 2 3 4) -1)
998 (rotate (vector 1 2 3 4) -2)
999 (rotate (vector 1 2 3 4) -3)
1000 (rotate (vector 1 2 3 4) -4)
1001 (rotate (vector 1 2 3 4) -5))
1002 (#(1 2 3 4)
1003 #(2 3 4 1)
1004 #(3 4 1 2)
1005 #(4 1 2 3)
1006 #(1 2 3 4)
1007 #(2 3 4 1)))
1009 (deftest rotate.5
1010 (values (rotate (list 1) 17)
1011 (rotate (list 1) -5))
1013 (1))
1015 (deftest shuffle.1
1016 (let ((s (shuffle (iota 100))))
1017 (list (equal s (iota 100))
1018 (every (lambda (x)
1019 (member x s))
1020 (iota 100))
1021 (every (lambda (x)
1022 (typep x '(integer 0 99)))
1023 s)))
1024 (nil t t))
1026 (deftest shuffle.2
1027 (let ((s (shuffle (coerce (iota 100) 'vector))))
1028 (list (equal s (coerce (iota 100) 'vector))
1029 (every (lambda (x)
1030 (find x s))
1031 (iota 100))
1032 (every (lambda (x)
1033 (typep x '(integer 0 99)))
1034 s)))
1035 (nil t t))
1037 (deftest random-elt.1
1038 (let ((s1 #(1 2 3 4))
1039 (s2 '(1 2 3 4)))
1040 (list (dotimes (i 1000 nil)
1041 (unless (member (random-elt s1) s2)
1042 (return nil))
1043 (when (/= (random-elt s1) (random-elt s1))
1044 (return t)))
1045 (dotimes (i 1000 nil)
1046 (unless (member (random-elt s2) s2)
1047 (return nil))
1048 (when (/= (random-elt s2) (random-elt s2))
1049 (return t)))))
1050 (t t))
1052 (deftest removef.1
1053 (let* ((x '(1 2 3))
1054 (x* x)
1055 (y #(1 2 3))
1056 (y* y))
1057 (removef x 1)
1058 (removef y 3)
1059 (list x x* y y*))
1060 ((2 3)
1061 (1 2 3)
1062 #(1 2)
1063 #(1 2 3)))
1065 (deftest deletef.1
1066 (let* ((x (list 1 2 3))
1067 (x* x)
1068 (y (vector 1 2 3)))
1069 (deletef x 2)
1070 (deletef y 1)
1071 (list x x* y))
1072 ((1 3)
1073 (1 3)
1074 #(2 3)))
1076 (deftest map-permutations.1
1077 (let ((seq (list 1 2 3))
1078 (seen nil)
1079 (ok t))
1080 (map-permutations (lambda (s)
1081 (unless (set-equal s seq)
1082 (setf ok nil))
1083 (when (member s seen :test 'equal)
1084 (setf ok nil))
1085 (push s seen))
1087 :copy t)
1088 (values ok (length seen)))
1092 (deftest proper-sequence.type.1
1093 (mapcar (lambda (x)
1094 (typep x 'proper-sequence))
1095 (list (list 1 2 3)
1096 (vector 1 2 3)
1097 #2a((1 2) (3 4))
1098 (circular-list 1 2 3 4)))
1099 (t t nil nil))
1101 (deftest emptyp.1
1102 (mapcar #'emptyp
1103 (list (list 1)
1104 (circular-list 1)
1106 (vector)
1107 (vector 1)))
1108 (nil nil t t nil))
1110 (deftest sequence-of-length-p.1
1111 (mapcar #'sequence-of-length-p
1112 (list nil
1114 (list 1)
1115 (vector 1)
1116 (list 1 2)
1117 (vector 1 2)
1118 (list 1 2)
1119 (vector 1 2)
1120 (list 1 2)
1121 (vector 1 2))
1122 (list 0
1132 (t t t t t t nil nil nil nil))
1134 (deftest length=.1
1135 (mapcar #'length=
1136 (list nil
1138 (list 1)
1139 (vector 1)
1140 (list 1 2)
1141 (vector 1 2)
1142 (list 1 2)
1143 (vector 1 2)
1144 (list 1 2)
1145 (vector 1 2))
1146 (list 0
1156 (t t t t t t nil nil nil nil))
1158 (deftest length=.2
1159 ;; test the compiler macro
1160 (macrolet ((x (&rest args)
1161 (funcall
1162 (compile nil
1163 `(lambda ()
1164 (length= ,@args))))))
1165 (list (x 2 '(1 2))
1166 (x '(1 2) '(3 4))
1167 (x '(1 2) 2)
1168 (x '(1 2) 2 '(3 4))
1169 (x 1 2 3)))
1170 (t t t t nil))
1172 (deftest copy-sequence.1
1173 (let ((l (list 1 2 3))
1174 (v (vector #\a #\b #\c)))
1175 (declare (notinline copy-sequence))
1176 (let ((l.list (copy-sequence 'list l))
1177 (l.vector (copy-sequence 'vector l))
1178 (l.spec-v (copy-sequence '(vector fixnum) l))
1179 (v.vector (copy-sequence 'vector v))
1180 (v.list (copy-sequence 'list v))
1181 (v.string (copy-sequence 'string v)))
1182 (list (member l (list l.list l.vector l.spec-v))
1183 (member v (list v.vector v.list v.string))
1184 (equal l.list l)
1185 (equalp l.vector #(1 2 3))
1186 (eql (upgraded-array-element-type 'fixnum)
1187 (array-element-type l.spec-v))
1188 (equalp v.vector v)
1189 (equal v.list '(#\a #\b #\c))
1190 (equal "abc" v.string))))
1191 (nil nil t t t t t t))
1193 (deftest first-elt.1
1194 (mapcar #'first-elt
1195 (list (list 1 2 3)
1196 "abc"
1197 (vector :a :b :c)))
1198 (1 #\a :a))
1200 (deftest first-elt.error.1
1201 (mapcar (lambda (x)
1202 (handler-case
1203 (first-elt x)
1204 (type-error ()
1205 :type-error)))
1206 (list nil
1209 :zot))
1210 (:type-error
1211 :type-error
1212 :type-error
1213 :type-error))
1215 (deftest setf-first-elt.1
1216 (let ((l (list 1 2 3))
1217 (s (copy-seq "foobar"))
1218 (v (vector :a :b :c)))
1219 (setf (first-elt l) -1
1220 (first-elt s) #\x
1221 (first-elt v) 'zot)
1222 (values l s v))
1223 (-1 2 3)
1224 "xoobar"
1225 #(zot :b :c))
1227 (deftest setf-first-elt.error.1
1228 (let ((l 'foo))
1229 (multiple-value-bind (res err)
1230 (ignore-errors (setf (first-elt l) 4))
1231 (typep err 'type-error)))
1234 (deftest last-elt.1
1235 (mapcar #'last-elt
1236 (list (list 1 2 3)
1237 (vector :a :b :c)
1238 "FOOBAR"
1239 #*001
1240 #*010))
1241 (3 :c #\R 1 0))
1243 (deftest last-elt.error.1
1244 (mapcar (lambda (x)
1245 (handler-case
1246 (last-elt x)
1247 (type-error ()
1248 :type-error)))
1249 (list nil
1252 :zot
1253 (circular-list 1 2 3)
1254 (list* 1 2 3 (circular-list 4 5))))
1255 (:type-error
1256 :type-error
1257 :type-error
1258 :type-error
1259 :type-error
1260 :type-error))
1262 (deftest setf-last-elt.1
1263 (let ((l (list 1 2 3))
1264 (s (copy-seq "foobar"))
1265 (b (copy-seq #*010101001)))
1266 (setf (last-elt l) '???
1267 (last-elt s) #\?
1268 (last-elt b) 0)
1269 (values l s b))
1270 (1 2 ???)
1271 "fooba?"
1272 #*010101000)
1274 (deftest setf-last-elt.error.1
1275 (handler-case
1276 (setf (last-elt 'foo) 13)
1277 (type-error ()
1278 :type-error))
1279 :type-error)
1281 (deftest starts-with.1
1282 (list (starts-with 1 '(1 2 3))
1283 (starts-with 1 #(1 2 3))
1284 (starts-with #\x "xyz")
1285 (starts-with 2 '(1 2 3))
1286 (starts-with 3 #(1 2 3))
1287 (starts-with 1 1)
1288 (starts-with nil nil))
1289 (t t t nil nil nil nil))
1291 (deftest starts-with.2
1292 (values (starts-with 1 '(-1 2 3) :key '-)
1293 (starts-with "foo" '("foo" "bar") :test 'equal)
1294 (starts-with "f" '(#\f) :key 'string :test 'equal)
1295 (starts-with -1 '(0 1 2) :key #'1+)
1296 (starts-with "zot" '("ZOT") :test 'equal))
1301 nil)
1303 (deftest ends-with.1
1304 (list (ends-with 3 '(1 2 3))
1305 (ends-with 3 #(1 2 3))
1306 (ends-with #\z "xyz")
1307 (ends-with 2 '(1 2 3))
1308 (ends-with 1 #(1 2 3))
1309 (ends-with 1 1)
1310 (ends-with nil nil))
1311 (t t t nil nil nil nil))
1313 (deftest ends-with.2
1314 (values (ends-with 2 '(0 13 1) :key '1+)
1315 (ends-with "foo" (vector "bar" "foo") :test 'equal)
1316 (ends-with "X" (vector 1 2 #\X) :key 'string :test 'equal)
1317 (ends-with "foo" "foo" :test 'equal))
1321 nil)
1323 (deftest ends-with.error.1
1324 (handler-case
1325 (ends-with 3 (circular-list 3 3 3 1 3 3))
1326 (type-error ()
1327 :type-error))
1328 :type-error)
1330 (deftest sequences.passing-improper-lists
1331 (macrolet ((signals-error-p (form)
1332 `(handler-case
1333 (progn ,form nil)
1334 (type-error (e)
1335 t)))
1336 (cut (fn &rest args)
1337 (with-gensyms (arg)
1338 (print`(lambda (,arg)
1339 (apply ,fn (list ,@(substitute arg '_ args))))))))
1340 (let ((circular-list (make-circular-list 5 :initial-element :foo))
1341 (dotted-list (list* 'a 'b 'c 'd)))
1342 (loop for nth from 0
1343 for fn in (list
1344 (cut #'lastcar _)
1345 (cut #'rotate _ 3)
1346 (cut #'rotate _ -3)
1347 (cut #'shuffle _)
1348 (cut #'random-elt _)
1349 (cut #'last-elt _)
1350 (cut #'ends-with :foo _))
1351 nconcing
1352 (let ((on-circular-p (signals-error-p (funcall fn circular-list)))
1353 (on-dotted-p (signals-error-p (funcall fn dotted-list))))
1354 (when (or (not on-circular-p) (not on-dotted-p))
1355 (append
1356 (unless on-circular-p
1357 (let ((*print-circle* t))
1358 (list
1359 (format nil
1360 "No appropriate error signalled when passing ~S to ~Ath entry."
1361 circular-list nth))))
1362 (unless on-dotted-p
1363 (list
1364 (format nil
1365 "No appropriate error signalled when passing ~S to ~Ath entry."
1366 dotted-list nth)))))))))
1367 nil)
1369 (deftest with-unique-names.1
1370 (let ((*gensym-counter* 0))
1371 (let ((syms (with-unique-names (foo bar quux)
1372 (list foo bar quux))))
1373 (list (find-if #'symbol-package syms)
1374 (equal '("FOO0" "BAR1" "QUUX2")
1375 (mapcar #'symbol-name syms)))))
1376 (nil t))
1378 (deftest with-unique-names.2
1379 (let ((*gensym-counter* 0))
1380 (let ((syms (with-unique-names ((foo "_foo_") (bar -bar-) (quux #\q))
1381 (list foo bar quux))))
1382 (list (find-if #'symbol-package syms)
1383 (equal '("_foo_0" "-BAR-1" "q2")
1384 (mapcar #'symbol-name syms)))))
1385 (nil t))
1387 (deftest with-unique-names.3
1388 (let ((*gensym-counter* 0))
1389 (multiple-value-bind (res err)
1390 (ignore-errors
1391 (eval
1392 '(let ((syms
1393 (with-unique-names ((foo "_foo_") (bar -bar-) (quux 42))
1394 (list foo bar quux))))
1395 (list (find-if #'symbol-package syms)
1396 (equal '("_foo_0" "-BAR-1" "q2")
1397 (mapcar #'symbol-name syms))))))
1398 (errorp err)))
1401 (deftest once-only.1
1402 (macrolet ((cons1.good (x)
1403 (once-only (x)
1404 `(cons ,x ,x)))
1405 (cons1.bad (x)
1406 `(cons ,x ,x)))
1407 (let ((y 0))
1408 (list (cons1.good (incf y))
1410 (cons1.bad (incf y))
1411 y)))
1412 ((1 . 1) 1 (2 . 3) 3))
1414 (deftest once-only.2
1415 (macrolet ((cons1 (x)
1416 (once-only ((y x))
1417 `(cons ,y ,y))))
1418 (let ((z 0))
1419 (list (cons1 (incf z))
1421 (cons1 (incf z)))))
1422 ((1 . 1) 1 (2 . 2)))
1424 (deftest parse-body.1
1425 (parse-body '("doc" "body") :documentation t)
1426 ("body")
1428 "doc")
1430 (deftest parse-body.2
1431 (parse-body '("body") :documentation t)
1432 ("body")
1434 nil)
1436 (deftest parse-body.3
1437 (parse-body '("doc" "body"))
1438 ("doc" "body")
1440 nil)
1442 (deftest parse-body.4
1443 (parse-body '((declare (foo)) "doc" (declare (bar)) body) :documentation t)
1444 (body)
1445 ((declare (foo)) (declare (bar)))
1446 "doc")
1448 (deftest parse-body.5
1449 (parse-body '((declare (foo)) "doc" (declare (bar)) body))
1450 ("doc" (declare (bar)) body)
1451 ((declare (foo)))
1452 nil)
1454 (deftest parse-body.6
1455 (multiple-value-bind (res err)
1456 (ignore-errors
1457 (parse-body '("foo" "bar" "quux")
1458 :documentation t))
1459 (errorp err))
1462 ;;;; Symbols
1464 (deftest ensure-symbol.1
1465 (ensure-symbol :cons :cl)
1466 cons
1467 :external)
1469 (deftest ensure-symbol.2
1470 (ensure-symbol "CONS" :alexandria)
1471 cons
1472 :inherited)
1474 (deftest ensure-symbol.3
1475 (ensure-symbol 'foo :keyword)
1476 :foo
1477 :external)
1479 (deftest ensure-symbol.4
1480 (ensure-symbol #\* :alexandria)
1482 :inherited)
1484 (deftest format-symbol.1
1485 (let ((s (format-symbol nil "X-~D" 13)))
1486 (list (symbol-package s)
1487 (symbol-name s)))
1488 (nil "X-13"))
1490 (deftest format-symbol.2
1491 (format-symbol :keyword "SYM-~A" :bolic)
1492 :sym-bolic)
1494 (deftest format-symbol.3
1495 (let ((*package* (find-package :cl)))
1496 (format-symbol t "FIND-~A" 'package))
1497 find-package)
1499 (deftest make-keyword.1
1500 (list (make-keyword 'zot)
1501 (make-keyword "FOO")
1502 (make-keyword #\Q))
1503 (:zot :foo :q))
1505 (deftest make-gensym-list.1
1506 (let ((*gensym-counter* 0))
1507 (let ((syms (make-gensym-list 3 "FOO")))
1508 (list (find-if 'symbol-package syms)
1509 (equal '("FOO0" "FOO1" "FOO2")
1510 (mapcar 'symbol-name syms)))))
1511 (nil t))
1513 (deftest make-gensym-list.2
1514 (let ((*gensym-counter* 0))
1515 (let ((syms (make-gensym-list 3)))
1516 (list (find-if 'symbol-package syms)
1517 (equal '("G0" "G1" "G2")
1518 (mapcar 'symbol-name syms)))))
1519 (nil t))
1521 ;;;; Type-system
1523 (deftest of-type.1
1524 (locally
1525 (declare (notinline of-type))
1526 (let ((f (of-type 'string)))
1527 (list (funcall f "foo")
1528 (funcall f 'bar))))
1529 (t nil))
1531 (deftest type=.1
1532 (type= 'string 'string)
1536 (deftest type=.2
1537 (type= 'list '(or null cons))
1541 (deftest type=.3
1542 (type= 'null '(and symbol list))
1546 (deftest type=.4
1547 (type= 'string '(satisfies emptyp))
1549 nil)
1551 (deftest type=.5
1552 (type= 'string 'list)
1556 (macrolet
1557 ((test (type numbers)
1558 `(deftest ,(format-symbol t "CDR5.~A" type)
1559 (let ((numbers ,numbers))
1560 (values (mapcar (of-type ',(format-symbol t "NEGATIVE-~A" type)) numbers)
1561 (mapcar (of-type ',(format-symbol t "NON-POSITIVE-~A" type)) numbers)
1562 (mapcar (of-type ',(format-symbol t "NON-NEGATIVE-~A" type)) numbers)
1563 (mapcar (of-type ',(format-symbol t "POSITIVE-~A" type)) numbers)))
1564 (t t t nil nil nil nil)
1565 (t t t t nil nil nil)
1566 (nil nil nil t t t t)
1567 (nil nil nil nil t t t))))
1568 (test fixnum (list most-negative-fixnum -42 -1 0 1 42 most-positive-fixnum))
1569 (test integer (list (1- most-negative-fixnum) -42 -1 0 1 42 (1+ most-positive-fixnum)))
1570 (test rational (list (1- most-negative-fixnum) -42/13 -1 0 1 42/13 (1+ most-positive-fixnum)))
1571 (test real (list most-negative-long-float -42/13 -1 0 1 42/13 most-positive-long-float))
1572 (test float (list most-negative-short-float -42.02 -1.0 0.0 1.0 42.02 most-positive-short-float))
1573 (test short-float (list most-negative-short-float -42.02s0 -1.0s0 0.0s0 1.0s0 42.02s0 most-positive-short-float))
1574 (test single-float (list most-negative-single-float -42.02f0 -1.0f0 0.0f0 1.0f0 42.02f0 most-positive-single-float))
1575 (test double-float (list most-negative-double-float -42.02d0 -1.0d0 0.0d0 1.0d0 42.02d0 most-positive-double-float))
1576 (test long-float (list most-negative-long-float -42.02l0 -1.0l0 0.0l0 1.0l0 42.02l0 most-positive-long-float)))
1578 ;;;; Bindings
1580 (declaim (notinline opaque))
1581 (defun opaque (x)
1584 (deftest if-let.1
1585 (if-let (x (opaque :ok))
1587 :bad)
1588 :ok)
1590 (deftest if-let.2
1591 (if-let (x (opaque nil))
1592 :bad
1593 (and (not x) :ok))
1594 :ok)
1596 (deftest if-let.3
1597 (let ((x 1))
1598 (if-let ((x 2)
1599 (y x))
1600 (+ x y)
1601 :oops))
1604 (deftest if-let.4
1605 (if-let ((x 1)
1606 (y nil))
1607 :oops
1608 (and (not y) x))
1611 (deftest if-let.5
1612 (if-let (x)
1613 :oops
1614 (not x))
1617 (deftest if-let.error.1
1618 (handler-case
1619 (eval '(if-let x
1620 :oops
1621 :oops))
1622 (type-error ()
1623 :type-error))
1624 :type-error)
1626 (deftest when-let.1
1627 (when-let (x (opaque :ok))
1628 (setf x (cons x x))
1630 (:ok . :ok))
1632 (deftest when-let.2
1633 (when-let ((x 1)
1634 (y nil)
1635 (z 3))
1636 :oops)
1637 nil)
1639 (deftest when-let.3
1640 (let ((x 1))
1641 (when-let ((x 2)
1642 (y x))
1643 (+ x y)))
1646 (deftest when-let.error.1
1647 (handler-case
1648 (eval '(when-let x :oops))
1649 (type-error ()
1650 :type-error))
1651 :type-error)
1653 (deftest when-let*.1
1654 (let ((x 1))
1655 (when-let* ((x 2)
1656 (y x))
1657 (+ x y)))
1660 (deftest when-let*.2
1661 (let ((y 1))
1662 (when-let* (x y)
1663 (1+ x)))
1666 (deftest when-let*.3
1667 (when-let* ((x t)
1668 (y (consp x))
1669 (z (error "OOPS")))
1671 nil)
1673 (deftest when-let*.error.1
1674 (handler-case
1675 (eval '(when-let* x :oops))
1676 (type-error ()
1677 :type-error))
1678 :type-error)
1680 (deftest nth-value-or.1
1681 (multiple-value-bind (a b c)
1682 (nth-value-or 1
1683 (values 1 nil 1)
1684 (values 2 2 2))
1685 (= a b c 2))
1688 (deftest doplist.1
1689 (let (keys values)
1690 (doplist (k v '(a 1 b 2 c 3) (values t (reverse keys) (reverse values) k v))
1691 (push k keys)
1692 (push v values)))
1694 (a b c)
1695 (1 2 3)
1697 nil)