3 (eval-when (:compile-toplevel
:load-toplevel
)
8 (defpackage :alexandria-test
9 (:use
:cl
:alexandria
:sb-rt
))
11 (in-package :alexandria-test
)
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 (deftest required-argument
.1
182 (multiple-value-bind (res err
)
183 (ignore-errors (required-argument))
189 (deftest ensure-hash-table
.1
190 (let ((table (make-hash-table))
192 (multiple-value-bind (value already-there
)
193 (ensure-gethash x table
42)
196 (= 42 (gethash x table
))
197 (multiple-value-bind (value2 already-there2
)
198 (ensure-gethash x table
13)
201 (= 42 (gethash x table
)))))))
204 (deftest copy-hash-table
.1
205 (let ((orig (make-hash-table :test
'eq
:size
123))
207 (setf (gethash orig orig
) t
208 (gethash foo orig
) t
)
209 (let ((eq-copy (copy-hash-table orig
))
210 (eql-copy (copy-hash-table orig
:test
'eql
))
211 (equal-copy (copy-hash-table orig
:test
'equal
))
212 (equalp-copy (copy-hash-table orig
:test
'equalp
)))
213 (list (hash-table-size eq-copy
)
214 (hash-table-count eql-copy
)
215 (gethash orig eq-copy
)
216 (gethash (copy-seq foo
) eql-copy
)
217 (gethash foo eql-copy
)
218 (gethash (copy-seq foo
) equal-copy
)
219 (gethash "FOO" equal-copy
)
220 (gethash "FOO" equalp-copy
))))
221 (123 2 t nil t t nil t
))
223 (deftest copy-hash-table
.2
224 (let ((ht (make-hash-table))
225 (list (list :list
(vector :A
:B
:C
))))
226 (setf (gethash 'list ht
) list
)
227 (let* ((shallow-copy (copy-hash-table ht
))
228 (deep1-copy (copy-hash-table ht
:key
'copy-list
))
229 (list (gethash 'list ht
))
230 (shallow-list (gethash 'list shallow-copy
))
231 (deep1-list (gethash 'list deep1-copy
)))
232 (list (eq ht shallow-copy
)
234 (eq list shallow-list
)
235 (eq list deep1-list
) ; outer list was copied.
236 (eq (second list
) (second shallow-list
))
237 (eq (second list
) (second deep1-list
)) ; inner vector wasn't copied.
241 (deftest maphash-keys
.1
243 (table (make-hash-table)))
244 (declare (notinline maphash-keys
))
246 (setf (gethash i table
) t
))
247 (maphash-keys (lambda (k) (push k keys
)) table
)
248 (set-equal keys
'(0 1 2 3 4 5 6 7 8 9)))
251 (deftest maphash-values
.1
253 (table (make-hash-table)))
254 (declare (notinline maphash-values
))
256 (setf (gethash i table
) (- i
)))
257 (maphash-values (lambda (v) (push v vals
)) table
)
258 (set-equal vals
'(0 -
1 -
2 -
3 -
4 -
5 -
6 -
7 -
8 -
9)))
261 (deftest hash-table-keys
.1
262 (let ((table (make-hash-table)))
264 (setf (gethash i table
) t
))
265 (set-equal (hash-table-keys table
) '(0 1 2 3 4 5 6 7 8 9)))
268 (deftest hash-table-values
.1
269 (let ((table (make-hash-table)))
271 (setf (gethash (gensym) table
) i
))
272 (set-equal (hash-table-values table
) '(0 1 2 3 4 5 6 7 8 9)))
275 (deftest hash-table-alist
.1
276 (let ((table (make-hash-table)))
278 (setf (gethash i table
) (- i
)))
279 (let ((alist (hash-table-alist table
)))
285 (10 (0 .
0) (3 . -
3) (9 . -
9) nil
))
287 (deftest hash-table-plist
.1
288 (let ((table (make-hash-table)))
290 (setf (gethash i table
) (- i
)))
291 (let ((plist (hash-table-plist table
)))
299 (deftest alist-hash-table
.1
300 (let* ((alist '((0 a
) (1 b
) (2 c
)))
301 (table (alist-hash-table alist
)))
302 (list (hash-table-count table
)
306 (hash-table-test table
)))
309 (deftest plist-hash-table
.1
310 (let* ((plist '(:a
1 :b
2 :c
3))
311 (table (plist-hash-table plist
:test
'eq
)))
312 (list (hash-table-count table
)
318 (hash-table-test table
)))
319 (3 1 2 3 nil nil eq
))
324 (let ((disjunction (disjoin (lambda (x)
325 (and (consp x
) :cons
))
327 (and (stringp x
) :string
)))))
328 (list (funcall disjunction
'zot
)
329 (funcall disjunction
'(foo bar
))
330 (funcall disjunction
"test")))
334 (let ((conjunction (conjoin #'consp
339 (list (funcall conjunction
'zot
)
340 (funcall conjunction
'(foo))
341 (funcall conjunction
'("foo"))))
345 (let ((composite (compose '1+
348 #'read-from-string
)))
349 (funcall composite
"1"))
354 (locally (declare (notinline compose
))
358 #'read-from-string
))))
359 (funcall composite
"2"))
363 (let ((compose-form (funcall (compiler-macro-function 'compose
)
369 (let ((fun (funcall (compile nil
`(lambda () ,compose-form
)))))
373 (deftest multiple-value-compose
.1
374 (let ((composite (multiple-value-compose
379 (with-input-from-string (s x
)
380 (values (read s
) (read s
)))))))
381 (multiple-value-list (funcall composite
"2 7")))
384 (deftest multiple-value-compose
.2
385 (let ((composite (locally (declare (notinline multiple-value-compose
))
386 (multiple-value-compose
391 (with-input-from-string (s x
)
392 (values (read s
) (read s
))))))))
393 (multiple-value-list (funcall composite
"2 11")))
396 (deftest multiple-value-compose
.3
397 (let ((compose-form (funcall (compiler-macro-function 'multiple-value-compose
)
398 '(multiple-value-compose
403 (with-input-from-string (s x
)
404 (values (read s
) (read s
)))))
406 (let ((fun (funcall (compile nil
`(lambda () ,compose-form
)))))
407 (multiple-value-list (funcall fun
"2 9"))))
411 (let ((curried (curry '+ 3)))
412 (funcall curried
1 5))
416 (let ((curried (locally (declare (notinline curry
))
422 (let ((curried-form (funcall (compiler-macro-function 'curry
)
425 (let ((fun (funcall (compile nil
`(lambda () ,curried-form
)))))
430 (let ((r (rcurry '/ 2)))
434 (deftest named-lambda
.1
435 (let ((fac (named-lambda fac
(x)
442 (deftest named-lambda
.2
443 (let ((fac (named-lambda fac
(&key x
)
445 (* x
(fac :x
(- x
1)))
452 (deftest alist-plist
.1
453 (alist-plist '((a .
1) (b .
2) (c .
3)))
456 (deftest plist-alist
.1
457 (plist-alist '(a 1 b
2 c
3))
458 ((a .
1) (b .
2) (c .
3)))
461 (let* ((list (list 1 2 3))
463 (unionf list
(list 1 2 4))
464 (values (equal orig
(list 1 2 3))
465 (eql (length list
) 4)
466 (set-difference list
(list 1 2 3 4))
467 (set-difference (list 1 2 3 4) list
)))
474 (let ((list (list 1 2 3)))
475 (nunionf list
(list 1 2 4))
476 (values (eql (length list
) 4)
477 (set-difference (list 1 2 3 4) list
)
478 (set-difference list
(list 1 2 3 4))))
484 (let* ((list (list 1 2 3))
486 (appendf list
'(4 5 6) '(7 8))
487 (list list
(eq list orig
)))
488 ((1 2 3 4 5 6 7 8) nil
))
491 (let ((list1 (list 1 2 3))
492 (list2 (list 4 5 6)))
493 (nconcf list1 list2
(list 7 8 9))
497 (deftest circular-list
.1
498 (let ((circle (circular-list 1 2 3)))
503 (eq circle
(nthcdr 3 circle
))))
506 (deftest circular-list-p
.1
507 (let* ((circle (circular-list 1 2 3 4))
508 (tree (list circle circle
))
509 (dotted (cons circle t
))
510 (proper (list 1 2 3 circle
))
511 (tailcirc (list* 1 2 3 circle
)))
512 (list (circular-list-p circle
)
513 (circular-list-p tree
)
514 (circular-list-p dotted
)
515 (circular-list-p proper
)
516 (circular-list-p tailcirc
)))
519 (deftest circular-list-p
.2
520 (circular-list-p 'foo
)
523 (deftest circular-tree-p
.1
524 (let* ((circle (circular-list 1 2 3 4))
525 (tree1 (list circle circle
))
526 (tree2 (let* ((level2 (list 1 nil
2))
527 (level1 (list level2
)))
528 (setf (second level2
) level1
)
530 (dotted (cons circle t
))
531 (proper (list 1 2 3 circle
))
532 (tailcirc (list* 1 2 3 circle
))
533 (quite-proper (list 1 2 3))
534 (quite-dotted (list 1 (cons 2 3))))
535 (list (circular-tree-p circle
)
536 (circular-tree-p tree1
)
537 (circular-tree-p tree2
)
538 (circular-tree-p dotted
)
539 (circular-tree-p proper
)
540 (circular-tree-p tailcirc
)
541 (circular-tree-p quite-proper
)
542 (circular-tree-p quite-dotted
)))
543 (t t t t t t nil nil
))
545 (deftest proper-list-p
.1
549 (l4 (list (cons 1 2) 3))
550 (l5 (circular-list 1 2)))
551 (list (proper-list-p l1
)
558 (deftest proper-list-p
.2
559 (proper-list-p '(1 2 .
3))
562 (deftest proper-list.type
.1
566 (l4 (list (cons 1 2) 3))
567 (l5 (circular-list 1 2)))
568 (list (typep l1
'proper-list
)
569 (typep l2
'proper-list
)
570 (typep l3
'proper-list
)
571 (typep l4
'proper-list
)
572 (typep l5
'proper-list
)))
575 (deftest proper-list-length
.1
577 (proper-list-length nil
)
578 (proper-list-length (list 1))
579 (proper-list-length (list 2 2))
580 (proper-list-length (list 3 3 3))
581 (proper-list-length (list 4 4 4 4))
582 (proper-list-length (list 5 5 5 5 5))
583 (proper-list-length (list 6 6 6 6 6 6))
584 (proper-list-length (list 7 7 7 7 7 7 7))
585 (proper-list-length (list 8 8 8 8 8 8 8 8))
586 (proper-list-length (list 9 9 9 9 9 9 9 9 9)))
589 (deftest proper-list-length
.2
592 (proper-list-length x
)
597 (plength (list* 2 2))
598 (plength (list* 3 3 3))
599 (plength (list* 4 4 4 4))
600 (plength (list* 5 5 5 5 5))
601 (plength (list* 6 6 6 6 6 6))
602 (plength (list* 7 7 7 7 7 7 7))
603 (plength (list* 8 8 8 8 8 8 8 8))
604 (plength (list* 9 9 9 9 9 9 9 9 9))))
616 (deftest lastcar.error
.2
619 (lastcar (circular-list 1 2 3))
625 (deftest setf-lastcar
.1
626 (let ((l (list 1 2 3 4)))
629 (setf (lastcar l
) 42)
634 (deftest setf-lastcar
.2
635 (let ((l (circular-list 1 2 3)))
636 (multiple-value-bind (res err
)
637 (ignore-errors (setf (lastcar l
) 4))
638 (typep err
'type-error
)))
641 (deftest make-circular-list
.1
642 (let ((l (make-circular-list 3 :initial-element
:x
)))
644 (list (eq l
(nthcdr 3 l
))
651 (deftest circular-list.type
.1
652 (let* ((l1 (list 1 2 3))
653 (l2 (circular-list 1 2 3))
654 (l3 (list* 1 2 3 l2
)))
655 (list (typep l1
'circular-list
)
656 (typep l2
'circular-list
)
657 (typep l3
'circular-list
)))
660 (deftest ensure-list
.1
663 (list (ensure-list x
)
667 (deftest ensure-cons
.1
671 (values (ensure-cons x
)
703 (setp '(a :a
) :key
'character
)
707 (setp '(a :a
) :key
'character
:test
(constantly nil
))
711 (set-equal '(1 2 3) '(3 1 2))
715 (set-equal '("Xa") '("Xb")
716 :test
(lambda (a b
) (eql (char a
0) (char b
0))))
720 (set-equal '(1 2) '(4 2))
724 (set-equal '(a b c
) '(:a
:b
:c
) :key
'string
:test
'equal
)
728 (set-equal '(a d c
) '(:a
:b
:c
) :key
'string
:test
'equal
)
732 (set-equal '(a b c
) '(a b c d
))
735 (deftest map-product
.1
736 (map-product 'cons
'(2 3) '(1 4))
737 ((2 .
1) (2 .
4) (3 .
1) (3 .
4)))
739 (deftest map-product
.2
740 (map-product #'cons
'(2 3) '(1 4))
741 ((2 .
1) (2 .
4) (3 .
1) (3 .
4)))
744 (flatten '((1) 2 (((3 4))) ((((5)) 6)) 7))
747 (deftest remove-from-plist
.1
748 (let ((orig '(a 1 b
2 c
3 d
4)))
749 (list (remove-from-plist orig
'a
'c
)
750 (remove-from-plist orig
'b
'd
)
751 (remove-from-plist orig
'b
)
752 (remove-from-plist orig
'a
)
753 (remove-from-plist orig
'd
42 "zot")
754 (remove-from-plist orig
'a
'b
'c
'd
)
755 (remove-from-plist orig
'a
'b
'c
'd
'x
)
756 (equal orig
'(a 1 b
2 c
3 d
4))))
767 (mappend (compose 'list
'*) '(1 2 3) '(1 2 3))
773 (list (clamp 1.5 1 2)
780 (deftest gaussian-random
.1
783 (multiple-value-bind (g1 g2
)
784 (gaussian-random min max
)
785 (values (<= min g1 max
)
798 (iota 3 :start
0.0d0
)
802 (iota 3 :start
2 :step
3.0)
807 (declare (notinline map-iota
))
808 (values (map-iota (lambda (x) (push x all
))
837 (median '(100 0 99 1 98 2 97))
841 (median '(100 0 99 1 98 2 97 96))
845 (variance (list 1 2 3))
848 (deftest standard-deviation
.1
849 (< 0 (standard-deviation (list 1 2 3)) 1)
872 (let ((xv (vector 0 0 0))
874 (maxf (svref xv
(incf p
)) (incf p
))
885 (let ((xv (vector 10 10 10))
887 (minf (svref xv
(incf p
)) (incf p
))
894 (deftest array-index.type
)
902 (list (rotate (list 1 2 3) 0)
903 (rotate (list 1 2 3) 1)
904 (rotate (list 1 2 3) 2)
905 (rotate (list 1 2 3) 3)
906 (rotate (list 1 2 3) 4))
914 (list (rotate (vector 1 2 3 4) 0)
915 (rotate (vector 1 2 3 4))
916 (rotate (vector 1 2 3 4) 2)
917 (rotate (vector 1 2 3 4) 3)
918 (rotate (vector 1 2 3 4) 4)
919 (rotate (vector 1 2 3 4) 5))
928 (list (rotate (list 1 2 3) 0)
929 (rotate (list 1 2 3) -
1)
930 (rotate (list 1 2 3) -
2)
931 (rotate (list 1 2 3) -
3)
932 (rotate (list 1 2 3) -
4))
940 (list (rotate (vector 1 2 3 4) 0)
941 (rotate (vector 1 2 3 4) -
1)
942 (rotate (vector 1 2 3 4) -
2)
943 (rotate (vector 1 2 3 4) -
3)
944 (rotate (vector 1 2 3 4) -
4)
945 (rotate (vector 1 2 3 4) -
5))
954 (values (rotate (list 1) 17)
955 (rotate (list 1) -
5))
960 (let ((s (shuffle (iota 100))))
961 (list (equal s
(iota 100))
966 (typep x
'(integer 0 99)))
971 (let ((s (shuffle (coerce (iota 100) 'vector
))))
972 (list (equal s
(coerce (iota 100) 'vector
))
977 (typep x
'(integer 0 99)))
981 (deftest random-elt
.1
982 (let ((s1 #(1 2 3 4))
984 (list (dotimes (i 1000 nil
)
985 (unless (member (random-elt s1
) s2
)
987 (when (/= (random-elt s1
) (random-elt s1
))
989 (dotimes (i 1000 nil
)
990 (unless (member (random-elt s2
) s2
)
992 (when (/= (random-elt s2
) (random-elt s2
))
1010 (let* ((x (list 1 2 3))
1020 (deftest map-permutations
.1
1021 (let ((seq (list 1 2 3))
1024 (map-permutations (lambda (s)
1025 (unless (set-equal s seq
)
1027 (when (member s seen
:test
'equal
)
1032 (values ok
(length seen
)))
1036 (deftest proper-sequence.type
.1
1038 (typep x
'proper-sequence
))
1042 (circular-list 1 2 3 4)))
1054 (deftest sequence-of-length-p
.1
1055 (mapcar #'sequence-of-length-p
1076 (t t t t t t nil nil nil nil
))
1100 (t t t t t t nil nil nil nil
))
1103 ;; test the compiler macro
1104 (macrolet ((x (&rest args
)
1108 (length= ,@args
))))))
1116 (deftest copy-sequence
.1
1117 (let ((l (list 1 2 3))
1118 (v (vector #\a #\b #\c
)))
1119 (declare (notinline copy-sequence
))
1120 (let ((l.list
(copy-sequence 'list l
))
1121 (l.vector
(copy-sequence 'vector l
))
1122 (l.spec-v
(copy-sequence '(vector fixnum
) l
))
1123 (v.vector
(copy-sequence 'vector v
))
1124 (v.list
(copy-sequence 'list v
))
1125 (v.string
(copy-sequence 'string v
)))
1126 (list (member l
(list l.list l.vector l.spec-v
))
1127 (member v
(list v.vector v.list v.string
))
1129 (equalp l.vector
#(1 2 3))
1130 (eq 'fixnum
(array-element-type l.spec-v
))
1132 (equal v.list
'(#\a #\b #\c
))
1133 (equal "abc" v.string
))))
1134 (nil nil t t t t t t
))
1136 (deftest first-elt
.1
1143 (deftest first-elt.error
.1
1158 (deftest setf-first-elt
.1
1159 (let ((l (list 1 2 3))
1160 (s (copy-seq "foobar"))
1161 (v (vector :a
:b
:c
)))
1162 (setf (first-elt l
) -
1
1170 (deftest setf-first-elt.error
.1
1172 (multiple-value-bind (res err
)
1173 (ignore-errors (setf (first-elt l
) 4))
1174 (typep err
'type-error
)))
1186 (deftest last-elt.error
.1
1196 (circular-list 1 2 3)
1197 (list* 1 2 3 (circular-list 4 5))))
1205 (deftest setf-last-elt
.1
1206 (let ((l (list 1 2 3))
1207 (s (copy-seq "foobar"))
1208 (b (copy-seq #*010101001)))
1209 (setf (last-elt l
) '???
1217 (deftest setf-last-elt.error
.1
1219 (setf (last-elt 'foo
) 13)
1224 (deftest starts-with
.1
1225 (list (starts-with 1 '(1 2 3))
1226 (starts-with 1 #(1 2 3))
1227 (starts-with #\x
"xyz")
1228 (starts-with 2 '(1 2 3))
1229 (starts-with 3 #(1 2 3))
1231 (starts-with nil nil
))
1232 (t t t nil nil nil nil
))
1234 (deftest starts-with
.2
1235 (values (starts-with 1 '(-1 2 3) :key
'-
)
1236 (starts-with "foo" '("foo" "bar") :test
'equal
)
1237 (starts-with "f" '(#\f) :key
'string
:test
'equal
)
1238 (starts-with -
1 '(0 1 2) :key
#'1+)
1239 (starts-with "zot" '("ZOT") :test
'equal
))
1246 (deftest ends-with
.1
1247 (list (ends-with 3 '(1 2 3))
1248 (ends-with 3 #(1 2 3))
1249 (ends-with #\z
"xyz")
1250 (ends-with 2 '(1 2 3))
1251 (ends-with 1 #(1 2 3))
1253 (ends-with nil nil
))
1254 (t t t nil nil nil nil
))
1256 (deftest ends-with
.2
1257 (values (ends-with 2 '(0 13 1) :key
'1+)
1258 (ends-with "foo" (vector "bar" "foo") :test
'equal
)
1259 (ends-with "X" (vector 1 2 #\X
) :key
'string
:test
'equal
)
1260 (ends-with "foo" "foo" :test
'equal
))
1266 (deftest ends-with.error
.1
1268 (ends-with 3 (circular-list 3 3 3 1 3 3))
1273 (deftest sequences.passing-improper-lists
1274 (macrolet ((signals-error-p (form)
1279 (cut (fn &rest args
)
1281 (print`(lambda (,arg
)
1282 (apply ,fn
(list ,@(substitute arg
'_ args
))))))))
1283 (let ((circular-list (make-circular-list 5 :initial-element
:foo
))
1284 (dotted-list (list* 'a
'b
'c
'd
)))
1285 (loop for nth from
0
1291 (cut #'random-elt _
)
1293 (cut #'ends-with
:foo _
))
1295 (let ((on-circular-p (signals-error-p (funcall fn circular-list
)))
1296 (on-dotted-p (signals-error-p (funcall fn dotted-list
))))
1297 (when (or (not on-circular-p
) (not on-dotted-p
))
1299 (unless on-circular-p
1300 (let ((*print-circle
* t
))
1303 "No appropriate error signalled when passing ~S to ~Ath entry."
1304 circular-list nth
))))
1308 "No appropriate error signalled when passing ~S to ~Ath entry."
1309 dotted-list nth
)))))))))
1312 (deftest with-unique-names
.1
1313 (let ((*gensym-counter
* 0))
1314 (let ((syms (with-unique-names (foo bar quux
)
1315 (list foo bar quux
))))
1316 (list (find-if #'symbol-package syms
)
1317 (equal '("FOO0" "BAR1" "QUUX2")
1318 (mapcar #'symbol-name syms
)))))
1321 (deftest with-unique-names
.2
1322 (let ((*gensym-counter
* 0))
1323 (let ((syms (with-unique-names ((foo "_foo_") (bar -bar-
) (quux #\q
))
1324 (list foo bar quux
))))
1325 (list (find-if #'symbol-package syms
)
1326 (equal '("_foo_0" "-BAR-1" "q2")
1327 (mapcar #'symbol-name syms
)))))
1330 (deftest with-unique-names
.3
1331 (let ((*gensym-counter
* 0))
1332 (multiple-value-bind (res err
)
1336 (with-unique-names ((foo "_foo_") (bar -bar-
) (quux 42))
1337 (list foo bar quux
))))
1338 (list (find-if #'symbol-package syms
)
1339 (equal '("_foo_0" "-BAR-1" "q2")
1340 (mapcar #'symbol-name syms
))))))
1341 (typep err
'error
)))
1344 (deftest once-only
.1
1345 (macrolet ((cons1.good
(x)
1351 (list (cons1.good
(incf y
))
1353 (cons1.bad
(incf y
))
1355 ((1 .
1) 1 (2 .
3) 3))
1357 (deftest once-only
.2
1358 (macrolet ((cons1 (x)
1362 (list (cons1 (incf z
))
1365 ((1 .
1) 1 (2 .
2)))
1367 (deftest parse-body
.1
1368 (parse-body '("doc" "body") :documentation t
)
1373 (deftest parse-body
.2
1374 (parse-body '("body") :documentation t
)
1379 (deftest parse-body
.3
1380 (parse-body '("doc" "body"))
1385 (deftest parse-body
.4
1386 (parse-body '((declare (foo)) "doc" (declare (bar)) body
) :documentation t
)
1388 ((declare (foo)) (declare (bar)))
1391 (deftest parse-body
.5
1392 (parse-body '((declare (foo)) "doc" (declare (bar)) body
))
1393 ("doc" (declare (bar)) body
)
1397 (deftest parse-body
.6
1398 (multiple-value-bind (res err
)
1400 (parse-body '("foo" "bar" "quux")
1407 (deftest ensure-symbol
.1
1408 (ensure-symbol :cons
:cl
)
1412 (deftest ensure-symbol
.2
1413 (ensure-symbol "CONS" :alexandria
)
1417 (deftest ensure-symbol
.3
1418 (ensure-symbol 'foo
:keyword
)
1422 (deftest ensure-symbol
.4
1423 (ensure-symbol #\
* :alexandria
)
1427 (deftest format-symbol
.1
1428 (let ((s (format-symbol nil
"X-~D" 13)))
1429 (list (symbol-package s
)
1433 (deftest format-symbol
.2
1434 (format-symbol :keyword
"SYM-~A" :bolic
)
1437 (deftest format-symbol
.3
1438 (let ((*package
* (find-package :cl
)))
1439 (format-symbol t
"FIND-~A" 'package
))
1442 (deftest make-keyword
.1
1443 (list (make-keyword 'zot
)
1444 (make-keyword "FOO")
1448 (deftest make-gensym-list
.1
1449 (let ((*gensym-counter
* 0))
1450 (let ((syms (make-gensym-list 3 "FOO")))
1451 (list (find-if 'symbol-package syms
)
1452 (equal '("FOO0" "FOO1" "FOO2")
1453 (mapcar 'symbol-name syms
)))))
1456 (deftest make-gensym-list
.2
1457 (let ((*gensym-counter
* 0))
1458 (let ((syms (make-gensym-list 3)))
1459 (list (find-if 'symbol-package syms
)
1460 (equal '("G0" "G1" "G2")
1461 (mapcar 'symbol-name syms
)))))
1468 (declare (notinline of-type
))
1469 (let ((f (of-type 'string
)))
1470 (list (funcall f
"foo")
1475 (type= 'string
'string
)
1480 (type= 'list
'(or null cons
))
1485 (type= 'null
'(and symbol list
))
1490 (type= 'string
'(satisfies emptyp
))
1495 (type= 'string
'list
)
1500 ((test (type numbers
)
1501 `(deftest ,(format-symbol t
"CDR5.~A" type
)
1502 (let ((numbers ,numbers
))
1503 (values (mapcar (of-type ',(format-symbol t
"NEGATIVE-~A" type
)) numbers
)
1504 (mapcar (of-type ',(format-symbol t
"NON-POSITIVE-~A" type
)) numbers
)
1505 (mapcar (of-type ',(format-symbol t
"NON-NEGATIVE-~A" type
)) numbers
)
1506 (mapcar (of-type ',(format-symbol t
"POSITIVE-~A" type
)) numbers
)))
1507 (t t t nil nil nil nil
)
1508 (t t t t nil nil nil
)
1509 (nil nil nil t t t t
)
1510 (nil nil nil nil t t t
))))
1511 (test fixnum
(list most-negative-fixnum -
42 -
1 0 1 42 most-positive-fixnum
))
1512 (test integer
(list (1- most-negative-fixnum
) -
42 -
1 0 1 42 (1+ most-positive-fixnum
)))
1513 (test rational
(list (1- most-negative-fixnum
) -
42/13 -
1 0 1 42/13 (1+ most-positive-fixnum
)))
1514 (test real
(list most-negative-long-float -
42/13 -
1 0 1 42/13 most-positive-long-float
))
1515 (test float
(list most-negative-short-float -
42.02 -
1.0 0.0 1.0 42.02 most-positive-short-float
))
1516 (test short-float
(list most-negative-short-float -
42.02s0 -
1.0s0
0.0s0
1.0s0
42.02s0 most-positive-short-float
))
1517 (test single-float
(list most-negative-single-float -
42.02f0 -
1.0f0
0.0f0
1.0f0
42.02f0 most-positive-single-float
))
1518 (test double-float
(list most-negative-double-float -
42.02d0 -
1.0d0
0.0d0
1.0d0
42.02d0 most-positive-double-float
))
1519 (test long-float
(list most-negative-long-float -
42.02l0 -
1.0l0 0.0l0 1.0l0 42.02l0 most-positive-long-float
)))
1523 (declaim (notinline opaque
))
1528 (if-let (x (opaque :ok
))
1534 (if-let (x (opaque nil
))
1560 (deftest if-let.error
.1
1570 (when-let (x (opaque :ok
))
1589 (deftest when-let.error
.1
1591 (eval '(when-let x
:oops
))
1596 (deftest when-let
*.1
1603 (deftest when-let
*.2
1609 (deftest when-let
*.3
1616 (deftest when-let
*.error
.1
1618 (eval '(when-let* x
:oops
))
1623 (deftest nth-value-or
.1
1624 (multiple-value-bind (a b c
)
1633 (doplist (k v
'(a 1 b
2 c
3) (values t
(reverse keys
) (reverse values
) k v
))