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
)))
16 (let* ((orig (vector 1 2 3))
17 (copy (copy-array orig
)))
18 (values (eq orig copy
) (equalp orig copy
)))
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
)))))
32 (deftest array-index
.1
33 (typep 0 'array-index
)
38 (deftest unwind-protect-case
.1
40 (unwind-protect-case ()
42 (:normal
(push :normal result
))
43 (:abort
(push :abort result
))
44 (:always
(push :always result
)))
48 (deftest unwind-protect-case
.2
50 (unwind-protect-case ()
52 (:always
(push :always result
))
53 (:normal
(push :normal result
))
54 (:abort
(push :abort result
)))
58 (deftest unwind-protect-case
.3
59 (let (result1 result2 result3
)
61 (unwind-protect-case ()
63 (:normal
(push :normal result1
))
64 (:abort
(push :abort result1
))
65 (:always
(push :always result1
))))
67 (unwind-protect-case ()
69 (:normal
(push :normal result2
))
70 (:abort
(push :abort result2
))
71 (:always
(push :always result2
))))
73 (unwind-protect-case ()
75 (:normal
(push :normal result3
))
76 (:abort
(push :abort result3
))
77 (:always
(push :always result3
))))
78 (values result1 result2 result3
))
83 (deftest unwind-protect-case
.4
85 (unwind-protect-case (aborted-p)
87 (:always
(setq result aborted-p
)))
91 (deftest unwind-protect-case
.5
94 (unwind-protect-case (aborted-p)
96 (:always
(setq result aborted-p
))))
130 (cswitch (13 :test
=)
136 (cswitch (13 :key
1-
)
142 (let ((x (whichever 1 2 3)))
143 (and (member x
'(1 2 3)) t
))
150 (x (whichever a b c
)))
151 (and (member x
'(1 2 3)) t
))
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
))
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
))
181 ;;; TYPEP is specified to return a generalized boolean and, for
182 ;;; example, ECL exploits this by returning the superclasses of ERROR
185 (not (null (typep x
'error
))))
187 (deftest required-argument
.1
188 (multiple-value-bind (res err
)
189 (ignore-errors (required-argument))
195 (deftest ensure-hash-table
.1
196 (let ((table (make-hash-table))
198 (multiple-value-bind (value already-there
)
199 (ensure-gethash x table
42)
202 (= 42 (gethash x table
))
203 (multiple-value-bind (value2 already-there2
)
204 (ensure-gethash x table
13)
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))
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
)
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.
253 (deftest maphash-keys
.1
255 (table (make-hash-table)))
256 (declare (notinline maphash-keys
))
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
265 (table (make-hash-table)))
266 (declare (notinline maphash-values
))
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)))
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)))
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)))
290 (setf (gethash i table
) (- i
)))
291 (let ((alist (hash-table-alist table
)))
297 (10 (0 .
0) (3 . -
3) (9 . -
9) nil
))
299 (deftest hash-table-plist
.1
300 (let ((table (make-hash-table)))
302 (setf (gethash i table
) (- i
)))
303 (let ((plist (hash-table-plist table
)))
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
)
320 (hash-table-test table
))) ; CLISP returns EXT:FASTHASH-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
)
334 (hash-table-test table
))) ; CLISP returns EXT:FASTHASH-EQ.
335 (3 1 2 3 nil nil eq
))
340 (let ((disjunction (disjoin (lambda (x)
341 (and (consp x
) :cons
))
343 (and (stringp x
) :string
)))))
344 (list (funcall disjunction
'zot
)
345 (funcall disjunction
'(foo bar
))
346 (funcall disjunction
"test")))
350 (let ((disjunction (disjoin #'zerop
)))
351 (list (funcall disjunction
0)
352 (funcall disjunction
1)))
356 (let ((conjunction (conjoin #'consp
361 (list (funcall conjunction
'zot
)
362 (funcall conjunction
'(foo))
363 (funcall conjunction
'("foo"))))
367 (let ((conjunction (conjoin #'zerop
)))
368 (list (funcall conjunction
0)
369 (funcall conjunction
1)))
373 (let ((composite (compose '1+
376 #'read-from-string
)))
377 (funcall composite
"1"))
382 (locally (declare (notinline compose
))
386 #'read-from-string
))))
387 (funcall composite
"2"))
391 (let ((compose-form (funcall (compiler-macro-function 'compose
)
397 (let ((fun (funcall (compile nil
`(lambda () ,compose-form
)))))
402 (let ((composite (compose #'zerop
)))
403 (list (funcall composite
0)
404 (funcall composite
1)))
407 (deftest multiple-value-compose
.1
408 (let ((composite (multiple-value-compose
413 (with-input-from-string (s x
)
414 (values (read s
) (read s
)))))))
415 (multiple-value-list (funcall composite
"2 7")))
418 (deftest multiple-value-compose
.2
419 (let ((composite (locally (declare (notinline multiple-value-compose
))
420 (multiple-value-compose
425 (with-input-from-string (s x
)
426 (values (read s
) (read s
))))))))
427 (multiple-value-list (funcall composite
"2 11")))
430 (deftest multiple-value-compose
.3
431 (let ((compose-form (funcall (compiler-macro-function 'multiple-value-compose
)
432 '(multiple-value-compose
437 (with-input-from-string (s x
)
438 (values (read s
) (read s
)))))
440 (let ((fun (funcall (compile nil
`(lambda () ,compose-form
)))))
441 (multiple-value-list (funcall fun
"2 9"))))
444 (deftest multiple-value-compose
.4
445 (let ((composite (multiple-value-compose #'truncate
)))
446 (multiple-value-list (funcall composite
9 2)))
450 (let ((curried (curry '+ 3)))
451 (funcall curried
1 5))
455 (let ((curried (locally (declare (notinline curry
))
461 (let ((curried-form (funcall (compiler-macro-function 'curry
)
464 (let ((fun (funcall (compile nil
`(lambda () ,curried-form
)))))
469 (let ((r (rcurry '/ 2)))
473 (deftest named-lambda
.1
474 (let ((fac (named-lambda fac
(x)
481 (deftest named-lambda
.2
482 (let ((fac (named-lambda fac
(&key x
)
484 (* x
(fac :x
(- x
1)))
491 (deftest alist-plist
.1
492 (alist-plist '((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)))
500 (let* ((list (list 1 2 3))
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
)))
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))))
523 (let* ((list (list 1 2 3))
525 (appendf list
'(4 5 6) '(7 8))
526 (list list
(eq list orig
)))
527 ((1 2 3 4 5 6 7 8) nil
))
530 (let ((list1 (list 1 2 3))
531 (list2 (list 4 5 6)))
532 (nconcf list1 list2
(list 7 8 9))
536 (deftest circular-list
.1
537 (let ((circle (circular-list 1 2 3)))
542 (eq circle
(nthcdr 3 circle
))))
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
)))
558 (deftest circular-list-p
.2
559 (circular-list-p 'foo
)
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
)
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
588 (l4 (list (cons 1 2) 3))
589 (l5 (circular-list 1 2)))
590 (list (proper-list-p l1
)
597 (deftest proper-list-p
.2
598 (proper-list-p '(1 2 .
3))
601 (deftest proper-list.type
.1
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
)))
614 (deftest proper-list-length
.1
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)))
628 (deftest proper-list-length
.2
631 (proper-list-length x
)
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))))
655 (deftest lastcar.error
.2
658 (lastcar (circular-list 1 2 3))
664 (deftest setf-lastcar
.1
665 (let ((l (list 1 2 3 4)))
668 (setf (lastcar l
) 42)
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
)))
683 (list (eq l
(nthcdr 3 l
))
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
)))
699 (deftest ensure-list
.1
702 (list (ensure-list x
)
706 (deftest ensure-cons
.1
710 (values (ensure-cons x
)
742 (setp '(a :a
) :key
'character
)
746 (setp '(a :a
) :key
'character
:test
(constantly nil
))
750 (set-equal '(1 2 3) '(3 1 2))
754 (set-equal '("Xa") '("Xb")
755 :test
(lambda (a b
) (eql (char a
0) (char b
0))))
759 (set-equal '(1 2) '(4 2))
763 (set-equal '(a b c
) '(:a
:b
:c
) :key
'string
:test
'equal
)
767 (set-equal '(a d c
) '(:a
:b
:c
) :key
'string
:test
'equal
)
771 (set-equal '(a b c
) '(a b c d
))
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)))
783 (flatten '((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))))
806 (mappend (compose 'list
'*) '(1 2 3) '(1 2 3))
809 (deftest assoc-value
.1
810 (let ((key1 '(complex key
))
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
)
824 ((2 1) (43 42) (2 1)))
829 (list (clamp 1.5 1 2)
836 (deftest gaussian-random
.1
839 (multiple-value-bind (g1 g2
)
840 (gaussian-random min max
)
841 (values (<= min g1 max
)
854 (iota 3 :start
0.0d0
)
858 (iota 3 :start
2 :step
3.0)
863 (declare (notinline map-iota
))
864 (values (map-iota (lambda (x) (push x all
))
893 (median '(100 0 99 1 98 2 97))
897 (median '(100 0 99 1 98 2 97 96))
901 (variance (list 1 2 3))
904 (deftest standard-deviation
.1
905 (< 0 (standard-deviation (list 1 2 3)) 1)
928 (let ((xv (vector 0 0 0))
930 (maxf (svref xv
(incf p
)) (incf p
))
941 (let ((xv (vector 10 10 10))
943 (minf (svref xv
(incf p
)) (incf p
))
950 (deftest array-index.type
)
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))
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))
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))
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))
1010 (values (rotate (list 1) 17)
1011 (rotate (list 1) -
5))
1016 (let ((s (shuffle (iota 100))))
1017 (list (equal s
(iota 100))
1022 (typep x
'(integer 0 99)))
1027 (let ((s (shuffle (coerce (iota 100) 'vector
))))
1028 (list (equal s
(coerce (iota 100) 'vector
))
1033 (typep x
'(integer 0 99)))
1037 (deftest random-elt
.1
1038 (let ((s1 #(1 2 3 4))
1040 (list (dotimes (i 1000 nil
)
1041 (unless (member (random-elt s1
) s2
)
1043 (when (/= (random-elt s1
) (random-elt s1
))
1045 (dotimes (i 1000 nil
)
1046 (unless (member (random-elt s2
) s2
)
1048 (when (/= (random-elt s2
) (random-elt s2
))
1066 (let* ((x (list 1 2 3))
1076 (deftest map-permutations
.1
1077 (let ((seq (list 1 2 3))
1080 (map-permutations (lambda (s)
1081 (unless (set-equal s seq
)
1083 (when (member s seen
:test
'equal
)
1088 (values ok
(length seen
)))
1092 (deftest proper-sequence.type
.1
1094 (typep x
'proper-sequence
))
1098 (circular-list 1 2 3 4)))
1110 (deftest sequence-of-length-p
.1
1111 (mapcar #'sequence-of-length-p
1132 (t t t t t t nil nil nil nil
))
1156 (t t t t t t nil nil nil nil
))
1159 ;; test the compiler macro
1160 (macrolet ((x (&rest args
)
1164 (length= ,@args
))))))
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
))
1185 (equalp l.vector
#(1 2 3))
1186 (eql (upgraded-array-element-type 'fixnum
)
1187 (array-element-type l.spec-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
1200 (deftest first-elt.error
.1
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
1227 (deftest setf-first-elt.error
.1
1229 (multiple-value-bind (res err
)
1230 (ignore-errors (setf (first-elt l
) 4))
1231 (typep err
'type-error
)))
1243 (deftest last-elt.error
.1
1253 (circular-list 1 2 3)
1254 (list* 1 2 3 (circular-list 4 5))))
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
) '???
1274 (deftest setf-last-elt.error
.1
1276 (setf (last-elt 'foo
) 13)
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))
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
))
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))
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
))
1323 (deftest ends-with.error
.1
1325 (ends-with 3 (circular-list 3 3 3 1 3 3))
1330 (deftest sequences.passing-improper-lists
1331 (macrolet ((signals-error-p (form)
1336 (cut (fn &rest args
)
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
1348 (cut #'random-elt _
)
1350 (cut #'ends-with
:foo _
))
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
))
1356 (unless on-circular-p
1357 (let ((*print-circle
* t
))
1360 "No appropriate error signalled when passing ~S to ~Ath entry."
1361 circular-list nth
))))
1365 "No appropriate error signalled when passing ~S to ~Ath entry."
1366 dotted-list nth
)))))))))
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
)))))
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
)))))
1387 (deftest with-unique-names
.3
1388 (let ((*gensym-counter
* 0))
1389 (multiple-value-bind (res err
)
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
))))))
1401 (deftest once-only
.1
1402 (macrolet ((cons1.good
(x)
1408 (list (cons1.good
(incf y
))
1410 (cons1.bad
(incf y
))
1412 ((1 .
1) 1 (2 .
3) 3))
1414 (deftest once-only
.2
1415 (macrolet ((cons1 (x)
1419 (list (cons1 (incf z
))
1422 ((1 .
1) 1 (2 .
2)))
1424 (deftest parse-body
.1
1425 (parse-body '("doc" "body") :documentation t
)
1430 (deftest parse-body
.2
1431 (parse-body '("body") :documentation t
)
1436 (deftest parse-body
.3
1437 (parse-body '("doc" "body"))
1442 (deftest parse-body
.4
1443 (parse-body '((declare (foo)) "doc" (declare (bar)) body
) :documentation t
)
1445 ((declare (foo)) (declare (bar)))
1448 (deftest parse-body
.5
1449 (parse-body '((declare (foo)) "doc" (declare (bar)) body
))
1450 ("doc" (declare (bar)) body
)
1454 (deftest parse-body
.6
1455 (multiple-value-bind (res err
)
1457 (parse-body '("foo" "bar" "quux")
1464 (deftest ensure-symbol
.1
1465 (ensure-symbol :cons
:cl
)
1469 (deftest ensure-symbol
.2
1470 (ensure-symbol "CONS" :alexandria
)
1474 (deftest ensure-symbol
.3
1475 (ensure-symbol 'foo
:keyword
)
1479 (deftest ensure-symbol
.4
1480 (ensure-symbol #\
* :alexandria
)
1484 (deftest format-symbol
.1
1485 (let ((s (format-symbol nil
"X-~D" 13)))
1486 (list (symbol-package s
)
1490 (deftest format-symbol
.2
1491 (format-symbol :keyword
"SYM-~A" :bolic
)
1494 (deftest format-symbol
.3
1495 (let ((*package
* (find-package :cl
)))
1496 (format-symbol t
"FIND-~A" 'package
))
1499 (deftest make-keyword
.1
1500 (list (make-keyword 'zot
)
1501 (make-keyword "FOO")
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
)))))
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
)))))
1525 (declare (notinline of-type
))
1526 (let ((f (of-type 'string
)))
1527 (list (funcall f
"foo")
1532 (type= 'string
'string
)
1537 (type= 'list
'(or null cons
))
1542 (type= 'null
'(and symbol list
))
1547 (type= 'string
'(satisfies emptyp
))
1552 (type= 'string
'list
)
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
)))
1580 (declaim (notinline opaque
))
1585 (if-let (x (opaque :ok
))
1591 (if-let (x (opaque nil
))
1617 (deftest if-let.error
.1
1627 (when-let (x (opaque :ok
))
1646 (deftest when-let.error
.1
1648 (eval '(when-let x
:oops
))
1653 (deftest when-let
*.1
1660 (deftest when-let
*.2
1666 (deftest when-let
*.3
1673 (deftest when-let
*.error
.1
1675 (eval '(when-let* x
:oops
))
1680 (deftest nth-value-or
.1
1681 (multiple-value-bind (a b c
)
1690 (doplist (k v
'(a 1 b
2 c
3) (values t
(reverse keys
) (reverse values
) k v
))