1 ;;;; This software is part of the SBCL system. See the README file for
4 ;;;; While most of SBCL is derived from the CMU CL system, the test
5 ;;;; files (like this one) were written from scratch after the fork
8 ;;;; This software is in the public domain and is provided with
9 ;;;; absolutely no warranty. See the COPYING and CREDITS files for
10 ;;;; more information.
12 (in-package "CL-USER")
15 (declare (notinline mapcar
))
16 (mapcar (lambda (args)
17 (destructuring-bind (obj type-spec result
) args
18 (flet ((matches-result?
(x)
19 (eq (if x t nil
) result
)))
20 (assert (matches-result?
(typep obj type-spec
)))
21 (assert (matches-result?
(sb-kernel:ctypep
23 (sb-kernel:specifier-type
25 '((nil (or null vector
) t
)
26 (nil (or number vector
) nil
)
27 (12 (or null vector
) nil
)
28 (12 (and (or number vector
) real
) t
))))
31 ;;; This test is motivated by bug #195, which previously had (THE REAL
32 ;;; #(1 2 3)) give an error which prints as "This is not a (OR
33 ;;; SINGLE-FLOAT DOUBLE-FLOAT RATIONAL)". We ideally want all of the
34 ;;; defined-by-ANSI types to unparse as themselves or at least
35 ;;; something similar (e.g. CHARACTER can unparse to BASE-CHAR, since
36 ;;; the types are equivalent in current SBCL, and EXTENDED-CHAR can
37 ;;; unparse to NIL, since there are no EXTENDED-CHARs currently).
38 (let ((standard-types '(;; from table 4-2 in section 4.2.3 in the
46 ;; so it might seem easy to change the HAIRY
47 ;; :UNPARSE method to recognize that (NOT
48 ;; CONS) should unparse as ATOM. However, we
49 ;; then lose the nice (SUBTYPEP '(NOT ATOM)
50 ;; 'CONS) => T,T behaviour that we get from
51 ;; simplifying (NOT ATOM) -> (NOT (NOT CONS))
52 ;; -> CONS. So, for now, we leave this
78 standard-generic-function
136 floating-point-inexact
139 floating-point-invalid-operation
142 floating-point-overflow
144 floating-point-underflow
146 (dolist (type standard-types
)
147 (format t
"~&~S~%" type
)
148 (assert (not (sb-kernel:unknown-type-p
(sb-kernel:specifier-type type
))))
149 (assert (atom (sb-kernel:type-specifier
(sb-kernel:specifier-type type
))))))
151 ;;; a bug underlying the reported bug #221: The SB-KERNEL type code
152 ;;; signalled an error on this expression.
153 (subtypep '(function (fixnum) (values package boolean
))
154 '(function (t) (values package boolean
)))
156 ;;; bug reported by Valtteri Vuorik
157 (compile nil
'(lambda () (member (char "foo" 0) '(#\.
#\
/) :test
#'char
=)))
158 (assert (not (equal (multiple-value-list
159 (subtypep '(function ()) '(function (&rest t
))))
162 (assert (not (equal (multiple-value-list
163 (subtypep '(function (&rest t
)) '(function ())))
166 (assert (subtypep '(function)
167 '(function (&optional
* &rest t
))))
168 (assert (equal (multiple-value-list
169 (subtypep '(function)
170 '(function (t &rest t
))))
172 (assert (and (subtypep 'function
'(function))
173 (subtypep '(function) 'function
)))
175 ;;; Absent any exciting generalizations of |R, the type RATIONAL is
176 ;;; partitioned by RATIO and INTEGER. Ensure that the type system
177 ;;; knows about this. [ the type system is permitted to return NIL,
178 ;;; NIL for these, so if future maintenance breaks these tests that
179 ;;; way, that's fine. What the SUBTYPEP calls are _not_ allowed to
180 ;;; return is NIL, T, because that's completely wrong. ]
181 (assert (subtypep '(or integer ratio
) 'rational
))
182 (assert (subtypep 'rational
'(or integer ratio
)))
183 ;;; Likewise, these are allowed to return NIL, NIL, but shouldn't
185 (assert (subtypep t
'(or real
(not real
))))
186 (assert (subtypep t
'(or keyword
(not keyword
))))
187 (assert (subtypep '(and cons
(not (cons symbol integer
)))
188 '(or (cons (not symbol
) *) (cons * (not integer
)))))
189 (assert (subtypep '(or (cons (not symbol
) *) (cons * (not integer
)))
190 '(and cons
(not (cons symbol integer
)))))
191 (assert (subtypep '(or (eql 0) (rational (0) 10))
193 (assert (subtypep '(rational 0 10)
194 '(or (eql 0) (rational (0) 10))))
195 ;;; Until sbcl-0.7.13.7, union of CONS types when the CDRs were the
196 ;;; same type gave exceedingly wrong results
197 (assert (null (subtypep '(or (cons fixnum single-float
)
198 (cons bignum single-float
))
199 '(cons single-float single-float
))))
200 (assert (subtypep '(cons integer single-float
)
201 '(or (cons fixnum single-float
) (cons bignum single-float
))))
203 (assert (not (nth-value 1 (subtypep '(and null some-unknown-type
)
204 'another-unknown-type
))))
207 (dolist (fun '(and if
))
208 (assert (raises-error?
(coerce fun
'function
) type-error
)))