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
)))
582 (deftest lastcar.error
.2
585 (lastcar (circular-list 1 2 3))
591 (deftest setf-lastcar
.1
592 (let ((l (list 1 2 3 4)))
595 (setf (lastcar l
) 42)
600 (deftest setf-lastcar
.2
601 (let ((l (circular-list 1 2 3)))
602 (multiple-value-bind (res err
)
603 (ignore-errors (setf (lastcar l
) 4))
604 (typep err
'type-error
)))
607 (deftest make-circular-list
.1
608 (let ((l (make-circular-list 3 :initial-element
:x
)))
610 (list (eq l
(nthcdr 3 l
))
617 (deftest circular-list.type
.1
618 (let* ((l1 (list 1 2 3))
619 (l2 (circular-list 1 2 3))
620 (l3 (list* 1 2 3 l2
)))
621 (list (typep l1
'circular-list
)
622 (typep l2
'circular-list
)
623 (typep l3
'circular-list
)))
626 (deftest ensure-list
.1
629 (list (ensure-list x
)
633 (deftest ensure-cons
.1
637 (values (ensure-cons x
)
669 (setp '(a :a
) :key
'character
)
673 (setp '(a :a
) :key
'character
:test
(constantly nil
))
677 (set-equal '(1 2 3) '(3 1 2))
681 (set-equal '("Xa") '("Xb")
682 :test
(lambda (a b
) (eql (char a
0) (char b
0))))
686 (set-equal '(1 2) '(4 2))
690 (set-equal '(a b c
) '(:a
:b
:c
) :key
'string
:test
'equal
)
694 (set-equal '(a d c
) '(:a
:b
:c
) :key
'string
:test
'equal
)
698 (set-equal '(a b c
) '(a b c d
))
701 (deftest map-product
.1
702 (map-product 'cons
'(2 3) '(1 4))
703 ((2 .
1) (2 .
4) (3 .
1) (3 .
4)))
705 (deftest map-product
.2
706 (map-product #'cons
'(2 3) '(1 4))
707 ((2 .
1) (2 .
4) (3 .
1) (3 .
4)))
710 (flatten '((1) 2 (((3 4))) ((((5)) 6)) 7))
713 (deftest remove-from-plist
.1
714 (let ((orig '(a 1 b
2 c
3 d
4)))
715 (list (remove-from-plist orig
'a
'c
)
716 (remove-from-plist orig
'b
'd
)
717 (remove-from-plist orig
'b
)
718 (remove-from-plist orig
'a
)
719 (remove-from-plist orig
'd
42 "zot")
720 (remove-from-plist orig
'a
'b
'c
'd
)
721 (remove-from-plist orig
'a
'b
'c
'd
'x
)
722 (equal orig
'(a 1 b
2 c
3 d
4))))
733 (mappend (compose 'list
'*) '(1 2 3) '(1 2 3))
739 (list (clamp 1.5 1 2)
746 (deftest gaussian-random
.1
749 (multiple-value-bind (g1 g2
)
750 (gaussian-random min max
)
751 (values (<= min g1 max
)
764 (iota 3 :start
0.0d0
)
768 (iota 3 :start
2 :step
3.0)
773 (declare (notinline map-iota
))
774 (values (map-iota (lambda (x) (push x all
))
803 (median '(100 0 99 1 98 2 97))
807 (median '(100 0 99 1 98 2 97 96))
811 (variance (list 1 2 3))
814 (deftest standard-deviation
.1
815 (< 0 (standard-deviation (list 1 2 3)) 1)
838 (let ((xv (vector 0 0 0))
840 (maxf (svref xv
(incf p
)) (incf p
))
851 (let ((xv (vector 10 10 10))
853 (minf (svref xv
(incf p
)) (incf p
))
860 (deftest array-index.type
)
868 (list (rotate (list 1 2 3) 0)
869 (rotate (list 1 2 3) 1)
870 (rotate (list 1 2 3) 2)
871 (rotate (list 1 2 3) 3)
872 (rotate (list 1 2 3) 4))
880 (list (rotate (vector 1 2 3 4) 0)
881 (rotate (vector 1 2 3 4))
882 (rotate (vector 1 2 3 4) 2)
883 (rotate (vector 1 2 3 4) 3)
884 (rotate (vector 1 2 3 4) 4)
885 (rotate (vector 1 2 3 4) 5))
894 (list (rotate (list 1 2 3) 0)
895 (rotate (list 1 2 3) -
1)
896 (rotate (list 1 2 3) -
2)
897 (rotate (list 1 2 3) -
3)
898 (rotate (list 1 2 3) -
4))
906 (list (rotate (vector 1 2 3 4) 0)
907 (rotate (vector 1 2 3 4) -
1)
908 (rotate (vector 1 2 3 4) -
2)
909 (rotate (vector 1 2 3 4) -
3)
910 (rotate (vector 1 2 3 4) -
4)
911 (rotate (vector 1 2 3 4) -
5))
920 (values (rotate (list 1) 17)
921 (rotate (list 1) -
5))
926 (let ((s (shuffle (iota 100))))
927 (list (equal s
(iota 100))
932 (typep x
'(integer 0 99)))
937 (let ((s (shuffle (coerce (iota 100) 'vector
))))
938 (list (equal s
(coerce (iota 100) 'vector
))
943 (typep x
'(integer 0 99)))
947 (deftest random-elt
.1
948 (let ((s1 #(1 2 3 4))
950 (list (dotimes (i 1000 nil
)
951 (unless (member (random-elt s1
) s2
)
953 (when (/= (random-elt s1
) (random-elt s1
))
955 (dotimes (i 1000 nil
)
956 (unless (member (random-elt s2
) s2
)
958 (when (/= (random-elt s2
) (random-elt s2
))
976 (let* ((x (list 1 2 3))
986 (deftest proper-sequence.type
.1
988 (typep x
'proper-sequence
))
992 (circular-list 1 2 3 4)))
1004 (deftest sequence-of-length-p
.1
1005 (mapcar #'sequence-of-length-p
1026 (t t t t t t nil nil nil nil
))
1050 (t t t t t t nil nil nil nil
))
1053 ;; test the compiler macro
1054 (macrolet ((x (&rest args
)
1058 (length= ,@args
))))))
1066 (deftest copy-sequence
.1
1067 (let ((l (list 1 2 3))
1068 (v (vector #\a #\b #\c
)))
1069 (declare (notinline copy-sequence
))
1070 (let ((l.list
(copy-sequence 'list l
))
1071 (l.vector
(copy-sequence 'vector l
))
1072 (l.spec-v
(copy-sequence '(vector fixnum
) l
))
1073 (v.vector
(copy-sequence 'vector v
))
1074 (v.list
(copy-sequence 'list v
))
1075 (v.string
(copy-sequence 'string v
)))
1076 (list (member l
(list l.list l.vector l.spec-v
))
1077 (member v
(list v.vector v.list v.string
))
1079 (equalp l.vector
#(1 2 3))
1080 (eq 'fixnum
(array-element-type l.spec-v
))
1082 (equal v.list
'(#\a #\b #\c
))
1083 (equal "abc" v.string
))))
1084 (nil nil t t t t t t
))
1086 (deftest first-elt
.1
1093 (deftest first-elt.error
.1
1108 (deftest setf-first-elt
.1
1109 (let ((l (list 1 2 3))
1110 (s (copy-seq "foobar"))
1111 (v (vector :a
:b
:c
)))
1112 (setf (first-elt l
) -
1
1120 (deftest setf-first-elt.error
.1
1122 (multiple-value-bind (res err
)
1123 (ignore-errors (setf (first-elt l
) 4))
1124 (typep err
'type-error
)))
1136 (deftest last-elt.error
.1
1146 (circular-list 1 2 3)
1147 (list* 1 2 3 (circular-list 4 5))))
1155 (deftest setf-last-elt
.1
1156 (let ((l (list 1 2 3))
1157 (s (copy-seq "foobar"))
1158 (b (copy-seq #*010101001)))
1159 (setf (last-elt l
) '???
1167 (deftest setf-last-elt.error
.1
1169 (setf (last-elt 'foo
) 13)
1174 (deftest starts-with
.1
1175 (list (starts-with 1 '(1 2 3))
1176 (starts-with 1 #(1 2 3))
1177 (starts-with #\x
"xyz")
1178 (starts-with 2 '(1 2 3))
1179 (starts-with 3 #(1 2 3))
1181 (starts-with nil nil
))
1182 (t t t nil nil nil nil
))
1184 (deftest starts-with
.2
1185 (values (starts-with 1 '(-1 2 3) :key
'-
)
1186 (starts-with "foo" '("foo" "bar") :test
'equal
)
1187 (starts-with "f" '(#\f) :key
'string
:test
'equal
)
1188 (starts-with -
1 '(0 1 2) :key
#'1+)
1189 (starts-with "zot" '("ZOT") :test
'equal
))
1196 (deftest ends-with
.1
1197 (list (ends-with 3 '(1 2 3))
1198 (ends-with 3 #(1 2 3))
1199 (ends-with #\z
"xyz")
1200 (ends-with 2 '(1 2 3))
1201 (ends-with 1 #(1 2 3))
1203 (ends-with nil nil
))
1204 (t t t nil nil nil nil
))
1206 (deftest ends-with
.2
1207 (values (ends-with 2 '(0 13 1) :key
'1+)
1208 (ends-with "foo" (vector "bar" "foo") :test
'equal
)
1209 (ends-with "X" (vector 1 2 #\X
) :key
'string
:test
'equal
)
1210 (ends-with "foo" "foo" :test
'equal
))
1216 (deftest ends-with.error
.1
1218 (ends-with 3 (circular-list 3 3 3 1 3 3))
1223 (deftest with-unique-names
.1
1224 (let ((*gensym-counter
* 0))
1225 (let ((syms (with-unique-names (foo bar quux
)
1226 (list foo bar quux
))))
1227 (list (find-if #'symbol-package syms
)
1228 (equal '("FOO0" "BAR1" "QUUX2")
1229 (mapcar #'symbol-name syms
)))))
1232 (deftest with-unique-names
.2
1233 (let ((*gensym-counter
* 0))
1234 (let ((syms (with-unique-names ((foo "_foo_") (bar -bar-
) (quux #\q
))
1235 (list foo bar quux
))))
1236 (list (find-if #'symbol-package syms
)
1237 (equal '("_foo_0" "-BAR-1" "q2")
1238 (mapcar #'symbol-name syms
)))))
1241 (deftest with-unique-names
.3
1242 (let ((*gensym-counter
* 0))
1243 (multiple-value-bind (res err
)
1247 (with-unique-names ((foo "_foo_") (bar -bar-
) (quux 42))
1248 (list foo bar quux
))))
1249 (list (find-if #'symbol-package syms
)
1250 (equal '("_foo_0" "-BAR-1" "q2")
1251 (mapcar #'symbol-name syms
))))))
1252 (typep err
'error
)))
1255 (deftest once-only
.1
1256 (macrolet ((cons1.good
(x)
1262 (list (cons1.good
(incf y
))
1264 (cons1.bad
(incf y
))
1266 ((1 .
1) 1 (2 .
3) 3))
1268 (deftest once-only
.2
1269 (macrolet ((cons1 (x)
1273 (list (cons1 (incf z
))
1276 ((1 .
1) 1 (2 .
2)))
1278 (deftest parse-body
.1
1279 (parse-body '("doc" "body") :documentation t
)
1284 (deftest parse-body
.2
1285 (parse-body '("body") :documentation t
)
1290 (deftest parse-body
.3
1291 (parse-body '("doc" "body"))
1296 (deftest parse-body
.4
1297 (parse-body '((declare (foo)) "doc" (declare (bar)) body
) :documentation t
)
1299 ((declare (foo)) (declare (bar)))
1302 (deftest parse-body
.5
1303 (parse-body '((declare (foo)) "doc" (declare (bar)) body
))
1304 ("doc" (declare (bar)) body
)
1308 (deftest parse-body
.6
1309 (multiple-value-bind (res err
)
1311 (parse-body '("foo" "bar" "quux")
1318 (deftest ensure-symbol
.1
1319 (ensure-symbol :cons
:cl
)
1323 (deftest ensure-symbol
.2
1324 (ensure-symbol "CONS" :alexandria
)
1328 (deftest ensure-symbol
.3
1329 (ensure-symbol 'foo
:keyword
)
1333 (deftest ensure-symbol
.4
1334 (ensure-symbol #\
* :alexandria
)
1338 (deftest format-symbol
.1
1339 (let ((s (format-symbol nil
"X-~D" 13)))
1340 (list (symbol-package s
)
1344 (deftest format-symbol
.2
1345 (format-symbol :keyword
"SYM-~A" :bolic
)
1348 (deftest format-symbol
.3
1349 (let ((*package
* (find-package :cl
)))
1350 (format-symbol t
"FIND-~A" 'package
))
1353 (deftest make-keyword
.1
1354 (list (make-keyword 'zot
)
1355 (make-keyword "FOO")
1359 (deftest make-gensym-list
.1
1360 (let ((*gensym-counter
* 0))
1361 (let ((syms (make-gensym-list 3 "FOO")))
1362 (list (find-if 'symbol-package syms
)
1363 (equal '("FOO0" "FOO1" "FOO2")
1364 (mapcar 'symbol-name syms
)))))
1367 (deftest make-gensym-list
.2
1368 (let ((*gensym-counter
* 0))
1369 (let ((syms (make-gensym-list 3)))
1370 (list (find-if 'symbol-package syms
)
1371 (equal '("G0" "G1" "G2")
1372 (mapcar 'symbol-name syms
)))))
1379 (declare (notinline of-type
))
1380 (let ((f (of-type 'string
)))
1381 (list (funcall f
"foo")
1386 (type= 'string
'string
)
1391 (type= 'list
'(or null cons
))
1396 (type= 'null
'(and symbol list
))
1401 (type= 'string
'(satisfies emptyp
))
1406 (type= 'string
'list
)
1411 ((test (type numbers
)
1412 `(deftest ,(format-symbol t
"CDR5.~A" type
)
1413 (let ((numbers ,numbers
))
1414 (values (mapcar (of-type ',(format-symbol t
"NEGATIVE-~A" type
)) numbers
)
1415 (mapcar (of-type ',(format-symbol t
"NON-POSITIVE-~A" type
)) numbers
)
1416 (mapcar (of-type ',(format-symbol t
"NON-NEGATIVE-~A" type
)) numbers
)
1417 (mapcar (of-type ',(format-symbol t
"POSITIVE-~A" type
)) numbers
)))
1418 (t t t nil nil nil nil
)
1419 (t t t t nil nil nil
)
1420 (nil nil nil t t t t
)
1421 (nil nil nil nil t t t
))))
1422 (test fixnum
(list most-negative-fixnum -
42 -
1 0 1 42 most-positive-fixnum
))
1423 (test integer
(list (1- most-negative-fixnum
) -
42 -
1 0 1 42 (1+ most-positive-fixnum
)))
1424 (test rational
(list (1- most-negative-fixnum
) -
42/13 -
1 0 1 42/13 (1+ most-positive-fixnum
)))
1425 (test real
(list most-negative-long-float -
42/13 -
1 0 1 42/13 most-positive-long-float
))
1426 (test float
(list most-negative-short-float -
42.02 -
1.0 0.0 1.0 42.02 most-positive-short-float
))
1427 (test short-float
(list most-negative-short-float -
42.02s0 -
1.0s0
0.0s0
1.0s0
42.02s0 most-positive-short-float
))
1428 (test single-float
(list most-negative-single-float -
42.02f0 -
1.0f0
0.0f0
1.0f0
42.02f0 most-positive-single-float
))
1429 (test double-float
(list most-negative-double-float -
42.02d0 -
1.0d0
0.0d0
1.0d0
42.02d0 most-positive-double-float
))
1430 (test long-float
(list most-negative-long-float -
42.02l0 -
1.0l0 0.0l0 1.0l0 42.02l0 most-positive-long-float
)))
1434 (declaim (notinline opaque
))
1439 (if-let (x (opaque :ok
))
1445 (if-let (x (opaque nil
))
1471 (deftest if-let.error
.1
1490 (y (prog1 x
(setf x nil
))))
1501 (deftest if-let
*.error
.1
1503 (eval '(if-let* x
:oops
:oops
))
1509 (when-let (x (opaque :ok
))
1528 (deftest when-let.error
.1
1530 (eval '(when-let x
:oops
))
1535 (deftest when-let
*.1
1542 (deftest when-let
*.2
1548 (deftest when-let
*.error
.1
1550 (eval '(when-let* x
:oops
))
1555 (deftest nth-value-or
.1
1556 (multiple-value-bind (a b c
)
1565 (doplist (k v
'(a 1 b
2 c
3) (values t
(reverse keys
) (reverse values
) k v
))