0.8.7.23:
[sbcl/lichteblau.git] / tests / type.pure.lisp
blob90205bc0a094951a9ae9b761055b3b94dd3656eb
1 ;;;; This software is part of the SBCL system. See the README file for
2 ;;;; more information.
3 ;;;;
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
6 ;;;; from CMU CL.
7 ;;;;
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")
14 (locally
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
22 obj
23 (sb-kernel:specifier-type
24 type-spec)))))))
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
39 ;; CLHS.
40 arithmetic-error
41 function
42 simple-condition
43 array
44 generic-function
45 simple-error
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
53 ;; commented out.
55 ;; atom
56 hash-table
57 simple-string
58 base-char
59 integer
60 simple-type-error
61 base-string
62 keyword
63 simple-vector
64 bignum
65 list
66 simple-warning
67 bit
68 logical-pathname
69 single-float
70 bit-vector
71 long-float
72 standard-char
73 broadcast-stream
74 method
75 standard-class
76 built-in-class
77 method-combination
78 standard-generic-function
79 cell-error
80 nil
81 standard-method
82 character
83 null
84 standard-object
85 class
86 number
87 storage-condition
88 compiled-function
89 package
90 stream
91 complex
92 package-error
93 stream-error
94 concatenated-stream
95 parse-error
96 string
97 condition
98 pathname
99 string-stream
100 cons
101 print-not-readable
102 structure-class
103 control-error
104 program-error
105 structure-object
106 division-by-zero
107 random-state
108 style-warning
109 double-float
110 ratio
111 symbol
112 echo-stream
113 rational
114 synonym-stream
115 end-of-file
116 reader-error
118 error
119 readtable
120 two-way-stream
121 extended-char
122 real
123 type-error
124 file-error
125 restart
126 unbound-slot
127 file-stream
128 sequence
129 unbound-variable
130 fixnum
131 serious-condition
132 undefined-function
133 float
134 short-float
135 unsigned-byte
136 floating-point-inexact
137 signed-byte
138 vector
139 floating-point-invalid-operation
140 simple-array
141 warning
142 floating-point-overflow
143 simple-base-string
144 floating-point-underflow
145 simple-bit-vector)))
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))))
160 '(nil t))))
162 (assert (not (equal (multiple-value-list
163 (subtypep '(function (&rest t)) '(function ())))
164 '(t t))))
166 (assert (subtypep '(function)
167 '(function (&optional * &rest t))))
168 (assert (equal (multiple-value-list
169 (subtypep '(function)
170 '(function (t &rest t))))
171 '(nil 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
184 ;;; return NIL, 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))
192 '(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))))
206 ;;; bug 46c
207 (dolist (fun '(and if))
208 (assert (raises-error? (coerce fun 'function) type-error)))