Unbreak non-x86 builds
[sbcl.git] / tests / character.pure.lisp
blob8000f7cda39f466c01888b60ab0277d3276b702d
1 ;;;; various CHARACTER tests without side effects
3 ;;;; This software is part of the SBCL system. See the README file for
4 ;;;; more information.
5 ;;;;
6 ;;;; While most of SBCL is derived from the CMU CL system, the test
7 ;;;; files (like this one) were written from scratch after the fork
8 ;;;; from CMU CL.
9 ;;;;
10 ;;;; This software is in the public domain and is provided with
11 ;;;; absolutely no warranty. See the COPYING and CREDITS files for
12 ;;;; more information.
14 (cl:in-package :cl-user)
16 ;;; ANSI's specification of #'CHAR-NAME imposes these constraints.
17 ;;;
18 ;;; (Obviously, the numeric values in this test implicitly assume
19 ;;; we're using an ASCII-based character set.)
20 (dolist (i '(("Newline" 10)
21 ;; (ANSI also imposes a constraint on the "semi-standard
22 ;; character" "Linefeed", but in ASCII as interpreted by
23 ;; Unix it's shadowed by "Newline" and so doesn't exist
24 ;; as a separate character.)
25 ("Space" 32)
26 ("Tab" 9)
27 ("Page" 12)
28 ("Rubout" 127)
29 ("Return" 13)
30 ("Backspace" 8)))
31 (destructuring-bind (name code) i
32 (let ((named-char (name-char name))
33 (coded-char (code-char code)))
34 (assert (eql named-char coded-char))
35 (assert (characterp named-char))
36 (let ((coded-char-name (char-name coded-char)))
37 (assert (string= name coded-char-name))))))
39 ;;; Trivial tests for some unicode names
40 #+sb-unicode
41 (dolist (d '(("LATIN_CAPITAL_LETTER_A" 65)
42 ("LATIN_SMALL_LETTER_A" 97)
43 ("LATIN_SMALL_LETTER_CLOSED_OPEN_E" 666)
44 ("DIGRAM_FOR_GREATER_YIN" 9871)))
45 (destructuring-bind (name code) d
46 (assert (eql (code-char code) (name-char (string-downcase name))))
47 (assert (equal name (char-name (code-char code))))))
49 ;;; bug 230: CHAR= didn't check types of &REST arguments
50 (dolist (form '((code-char char-code-limit)
51 (standard-char-p "a")
52 (graphic-char-p "a")
53 (alpha-char-p "a")
54 (upper-case-p "a")
55 (lower-case-p "a")
56 (both-case-p "a")
57 (digit-char-p "a")
58 (alphanumericp "a")
59 (char= #\a "a")
60 (char/= #\a "a")
61 (char< #\a #\b "c")
62 (char-equal #\a #\a "b")
63 (digit-char -1)
64 (digit-char 4 1)
65 (digit-char 4 37)))
66 (assert-error (apply (car form) (mapcar 'eval (cdr form))) type-error))
68 ;; All of the inequality predicates when called out-of-line
69 ;; were lazy in their type-checking, and would allow junk
70 ;; if short-circuit evaluation allowed early loop termination.
71 (with-test (:name :char-inequality-&rest-arguments)
72 (dolist (f '(char= char< char<= char> char>=
73 char-equal char-lessp char-not-greaterp
74 char-greaterp char-not-lessp))
75 ;; 1 arg
76 (assert-error (funcall f 'feep) type-error)
77 ;; 2 arg
78 (assert-error (funcall f #\a 'feep) type-error)
79 (assert-error (funcall f 'feep #\a) type-error)
80 ;; 3 arg
81 (assert-error (funcall f #\a #\a 'feep) type-error)
82 (assert-error (funcall f #\a #\b 'feep) type-error)
83 (assert-error (funcall f #\b #\a 'feep) type-error)
84 ;; 4 arg
85 (assert-error (funcall f #\a #\a #\a 'feep) type-error)))
87 (dotimes (i 256)
88 (let* ((char (code-char i))
89 (graphicp (graphic-char-p char))
90 (name (char-name char)))
91 (unless graphicp
92 (assert name))))
94 (assert (null (name-char 'foo)))
96 ;;; Between 1.0.4.53 and 1.0.4.69 character untagging was broken on
97 ;;; x86-64 if the result of the VOP was allocated on the stack, failing
98 ;;; an aver in the compiler.
99 (with-test (:name :character-untagging)
100 (compile nil
101 '(lambda (c0 c1 c2 c3 c4 c5 c6 c7
102 c8 c9 ca cb cc cd ce cf)
103 (declare (type character c0 c1 c2 c3 c4 c5 c6 c7
104 c8 c9 ca cb cc cd ce cf))
105 (char< c0 c1 c2 c3 c4 c5 c6 c7
106 c8 c9 ca cb cc cd ce cf))))
108 ;;; Characters could be coerced to subtypes of CHARACTER to which they
109 ;;; don't belong. Also, character designators that are not characters
110 ;;; could be coerced to proper subtypes of CHARACTER.
111 (with-test (:name :bug-841312)
112 ;; First let's make sure that the conditions hold that make the test
113 ;; valid: #\Nak is a BASE-CHAR, which at the same time ensures that
114 ;; STANDARD-CHAR is a proper subtype of BASE-CHAR, and under
115 ;; #+SB-UNICODE the character with code 955 exists and is not a
116 ;; BASE-CHAR.
117 (assert (typep #\Nak 'base-char))
118 #+sb-unicode
119 (assert (let ((c (code-char 955)))
120 (and c (not (typep c 'base-char)))))
121 ;; Test the formerly buggy coercions:
122 (macrolet ((assert-coerce-type-error (object type)
123 `(assert-error (coerce ,object ',type)
124 type-error)))
125 (assert-coerce-type-error #\Nak standard-char)
126 (assert-coerce-type-error #\a extended-char)
127 #+sb-unicode
128 (assert-coerce-type-error (code-char 955) base-char)
129 (assert-coerce-type-error 'a standard-char)
130 (assert-coerce-type-error "a" standard-char))
131 ;; The following coercions still need to be possible:
132 (macrolet ((assert-coercion (object type)
133 `(assert (typep (coerce ,object ',type) ',type))))
134 (assert-coercion #\a standard-char)
135 (assert-coercion #\Nak base-char)
136 #+sb-unicode
137 (assert-coercion (code-char 955) character)
138 (assert-coercion 'a character)
139 (assert-coercion "a" character)))
141 (with-test (:name :bug-994487)
142 (let ((f (compile nil `(lambda (char)
143 (code-char (1+ (char-code char)))))))
144 (assert (equal `(function (t) (values (sb-kernel:character-set
145 ((1 . ,(1- char-code-limit))))
146 &optional))
147 (sb-impl::%fun-type f)))))
149 (with-test (:name (:case-insensitive-char-comparisons :eacute))
150 (assert (char-equal (code-char 201) (code-char 233))))
152 (with-test (:name (:case-insensitive-char-comparisons :exhaustive))
153 (dotimes (i char-code-limit)
154 (let* ((char (code-char i))
155 (down (char-downcase char))
156 (up (char-upcase char)))
157 (assert (char-equal char char))
158 (when (char/= char down)
159 (assert (char-equal char down)))
160 (when (char/= char up)
161 (assert (char-equal char up))))))
163 (macrolet ((frob (predicate yes)
164 `(with-test (:name (,predicate standard-char))
165 (dotimes (i 256)
166 (let ((char (code-char i)))
167 (when (typep char 'standard-char)
168 (if (find char ,yes)
169 (assert (,predicate char))
170 (assert (not (,predicate char))))))))))
171 (frob lower-case-p "abcdefghijklmnopqrstuvwxyz")
172 (frob upper-case-p "ABCDEFGHIJKLMNOPQRSTUVWXYZ")
173 (frob digit-char-p "0123456789")
174 (frob both-case-p "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")
175 (frob alphanumericp "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"))
177 (with-test (:name :name-char-short-string)
178 (name-char "")
179 (name-char "A"))