Fix dependency of types.lisp
[iolib.git] / tests / uchars.lisp
blob5e5fdc7d076fd6e6498c78426bcf7566ff1e2f16
1 ;;;; -*- Mode: Lisp; Syntax: ANSI-Common-Lisp; indent-tabs-mode: nil -*-
2 ;;;
3 ;;; --- uchars test suite.
4 ;;;
6 (in-package :iolib-tests)
8 (in-suite :iolib.base.uchars)
9 \f
11 (test code-uchar.1
12 (is (eql #x1234 (code-uchar #x1234))))
14 (test code-uchar.error.1
15 (signals type-error
16 (code-uchar uchar-code-limit)))
19 (test uchar-code.1
20 (is (eql #x1234 (uchar-code #x1234))))
22 (test uchar-code.error.1
23 (signals type-error
24 (uchar-code uchar-code-limit)))
27 (test char-to-uchar.1
28 (is (eql 49 (char-to-uchar #\1))))
31 (test uchar-to-char.1
32 (is (char= #\1 (uchar-to-char 49))))
34 (test uchar-to-char.error.1
35 (signals type-error
36 (uchar-to-char uchar-code-limit)))
39 (test name-uchar.1
40 (is (eql (char-to-uchar #\space) (name-uchar "Space"))))
42 (test name-uchar.2
43 (is (eql #xD800 (name-uchar "Non-Unicode uchar #xD800"))))
45 (test name-uchar.error.1
46 (is-false (name-uchar "This is not a uchar name")))
49 (test uchar-name.1
50 (is (string-equal "Space" (uchar-name (char-to-uchar #\space)))))
52 (test uchar-name.2
53 (is (string-equal "Non-Unicode uchar #xD800"
54 (uchar-name #xD800))))
57 (test digit-uchar.1
58 (is (eql (+ #x30 9) (digit-uchar 9))))
60 (test digit-uchar.2
61 (is (loop :for i :below 16 :always (digit-uchar i 16))))
63 (test digit-uchar.3
64 (is-true
65 (loop :for i :from 0 :to 255
66 :always (eql (digit-uchar i)
67 (if-let (char (digit-char i))
68 (char-to-uchar char))))))
70 (test digit-uchar.error.1
71 (is-false (digit-uchar 16 16)))
73 (test digit-uchar.error.2
74 (signals type-error
75 (digit-uchar "string")))
78 (test uchar.1
79 (is (eql 9 (uchar 9))))
81 (test uchar.2
82 (is (eql 9 (uchar (make-array 1 :element-type 'uchar :initial-element 9)))))
84 (test uchar.3
85 (is (eql 65 (uchar #\A))))
87 (test uchar.4
88 (is (eql 65 (uchar "A"))))
90 (test uchar.5
91 (is (eql 65 (uchar 'a))))
93 (test uchar.error.1
94 (signals type-error
95 (uchar uchar-code-limit)))
97 (test uchar.error.2
98 (signals type-error
99 (uchar -1)))
101 (test uchar.error.3
102 (signals type-error
103 (uchar (make-array 2 :element-type 'uchar :initial-element 9))))
105 (test uchar.error.4
106 (signals type-error
107 (uchar "FOO")))
109 (test uchar.error.5
110 (signals type-error
111 (uchar 'nil)))
114 (test ucharp.1
115 (is-true (ucharp 0)))
117 (test ucharp.2
118 (is-true (ucharp (1- uchar-code-limit))))
120 (test ucharp.3
121 (is-false (ucharp -1)))
123 (test ucharp.4
124 (is-false (ucharp uchar-code-limit)))
126 (test ucharp.5
127 (is-false (ucharp #\a)))
129 (test ucharp.6
130 (is-false (ucharp "string")))
133 (test unicode-uchar-p.1
134 (is-true (unicode-uchar-p #xD7FF)))
136 (test unicode-uchar-p.2
137 (is-true (unicode-uchar-p #xDE00)))
139 (test unicode-uchar-p.1
140 (is-false (unicode-uchar-p #xD800)))
142 (test unicode-uchar-p.2
143 (is-false (unicode-uchar-p #xDFFF)))
146 (test uchar=.1
147 (is (eql t (uchar= #x40))))
149 (test uchar=.2
150 (is (eql t (uchar= #x40 #x40))))
152 (test uchar=.3
153 (is (eql t (uchar= #x40 #x40 #x40))))
155 (test uchar=.4
156 (is (eql nil (uchar= #x40 #x41))))
159 (test uchar/=.1
160 (is (eql t (uchar/= #x40))))
162 (test uchar/=.2
163 (is (eql t (uchar/= #x40 #x41))))
165 (test uchar/=.3
166 (is (eql t (uchar/= #x40 #x41 #x42))))
168 (test uchar/=.4
169 (is (eql nil (uchar/= #x40 #x40))))
171 (test uchar/=.5
172 (is (eql nil (uchar/= #x40 #x41 #x40))))
175 (test uchar<.1
176 (is (eql t (uchar< #x40))))
178 (test uchar<.2
179 (is (eql t (uchar< #x40 #x41))))
181 (test uchar<.3
182 (is (eql t (uchar< #x40 #x41 #x42))))
184 (test uchar<.4
185 (is (eql nil (uchar< #x40 #x40))))
187 (test uchar<.5
188 (is (eql nil (uchar< #x40 #x41 #x40))))
191 (test uchar>.1
192 (is (eql t (uchar> #x40))))
194 (test uchar>.2
195 (is (eql t (uchar> #x41 #x40))))
197 (test uchar>.3
198 (is (eql t (uchar> #x42 #x41 #x40))))
200 (test uchar>.4
201 (is (eql nil (uchar> #x40 #x40))))
203 (test uchar>.5
204 (is (eql nil (uchar> #x41 #x40 #x40))))
207 (test uchar<=.1
208 (is (eql t (uchar<= #x40))))
210 (test uchar<=.2
211 (is (eql t (uchar<= #x40 #x41))))
213 (test uchar<=.3
214 (is (eql t (uchar<= #x40 #x41 #x42))))
216 (test uchar<=.4
217 (is (eql t (uchar<= #x40 #x40))))
219 (test uchar<=.5
220 (is (eql nil (uchar<= #x40 #x41 #x40))))
223 (test uchar>=.1
224 (is (eql t (uchar>= #x40))))
226 (test uchar>=.2
227 (is (eql t (uchar>= #x41 #x40))))
229 (test uchar>=.3
230 (is (eql t (uchar>= #x42 #x41 #x40))))
232 (test uchar>=.4
233 (is (eql t (uchar>= #x40 #x40))))
235 (test uchar>=.5
236 (is (eql nil (uchar>= #x40 #x41 #x40))))
239 (test uchar-equal.1
240 (is (eql t (uchar-equal #x40))))
242 (test uchar-equal.2
243 (is (eql t (uchar-equal #x40 #x40))))
245 (test uchar-equal.3
246 (is (eql t (uchar-equal #x40 #x40 #x40))))
248 (test uchar-equal.4
249 (is (eql t (uchar-equal #x41 #x61))))
251 (test uchar-equal.5
252 (is (eql t (uchar-equal #x41 #x61 #x41))))
254 (test uchar-equal.6
255 (is (eql nil (uchar-equal #x40 #x41))))
258 (test uchar-not-equal.1
259 (is (eql t (uchar-not-equal #x40))))
261 (test uchar-not-equal.2
262 (is (eql t (uchar-not-equal #x40 #x41))))
264 (test uchar-not-equal.3
265 (is (eql t (uchar-not-equal #x40 #x41 #x42))))
267 (test uchar-not-equal.4
268 (is (eql nil (uchar-not-equal #x40 #x40))))
270 (test uchar-not-equal.5
271 (is (eql nil (uchar-not-equal #x40 #x41 #x40))))
273 (test uchar-not-equal.6
274 (is (eql nil (uchar-not-equal #x41 #x61))))
276 (test uchar-not-equal.7
277 (is (eql nil (uchar-not-equal #x41 #x61 #x41))))
280 (test uchar-lessp.1
281 (is (eql t (uchar-lessp #x40))))
283 (test uchar-lessp.2
284 (is (eql t (uchar-lessp #x40 #x41))))
286 (test uchar-lessp.3
287 (is (eql t (uchar-lessp #x40 #x41 #x42))))
289 (test uchar-lessp.4
290 (is (eql nil (uchar-lessp #x40 #x40))))
292 (test uchar-lessp.5
293 (is (eql nil (uchar-lessp #x40 #x41 #x40))))
295 (test uchar-lessp.6
296 (is (eql nil (uchar-lessp #x41 #x61))))
298 (test uchar-lessp.7
299 (is (eql nil (uchar-lessp #x41 #x61 #x62))))
302 (test uchar-greaterp.1
303 (is (eql t (uchar-greaterp #x40))))
305 (test uchar-greaterp.2
306 (is (eql t (uchar-greaterp #x41 #x40))))
308 (test uchar-greaterp.3
309 (is (eql t (uchar-greaterp #x42 #x41 #x40))))
311 (test uchar-greaterp.4
312 (is (eql nil (uchar-greaterp #x40 #x40))))
314 (test uchar-greaterp.5
315 (is (eql nil (uchar-greaterp #x41 #x40 #x40))))
317 (test uchar-greaterp.6
318 (is (eql nil (uchar-greaterp #x61 #x41))))
320 (test uchar-greaterp.7
321 (is (eql nil (uchar-greaterp #x62 #x61 #x41))))
324 (test uchar-not-greaterp.1
325 (is (eql t (uchar-not-greaterp #x40))))
327 (test uchar-not-greaterp.2
328 (is (eql t (uchar-not-greaterp #x40 #x41))))
330 (test uchar-not-greaterp.3
331 (is (eql t (uchar-not-greaterp #x40 #x41 #x42))))
333 (test uchar-not-greaterp.4
334 (is (eql t (uchar-not-greaterp #x40 #x40))))
336 (test uchar-not-greaterp.5
337 (is (eql nil (uchar-not-greaterp #x40 #x41 #x40))))
339 (test uchar-not-greaterp.6
340 (is (eql t (uchar-not-greaterp #x41 #x61))))
342 (test uchar-not-greaterp.7
343 (is (eql t (uchar-not-greaterp #x41 #x61 #x62))))
346 (test uchar-not-lessp.1
347 (is (eql t (uchar-not-lessp #x40))))
349 (test uchar-not-lessp.2
350 (is (eql t (uchar-not-lessp #x41 #x40))))
352 (test uchar-not-lessp.3
353 (is (eql t (uchar-not-lessp #x42 #x41 #x40))))
355 (test uchar-not-lessp.4
356 (is (eql t (uchar-not-lessp #x40 #x40))))
358 (test uchar-not-lessp.5
359 (is (eql t (uchar-not-lessp #x61 #x41))))
361 (test uchar-not-lessp.6
362 (is (eql t (uchar-not-lessp #x62 #x61 #x41))))
364 (test uchar-not-lessp.7
365 (is (eql nil (uchar-not-lessp #x40 #x41 #x40))))
368 (test alpha-uchar-p.1
369 (is-true
370 (and (loop :for r :from (char-to-uchar #\a) :to (char-to-uchar #\z)
371 :always (alpha-uchar-p r))
372 (loop :for r :from (char-to-uchar #\A) :to (char-to-uchar #\Z)
373 :always (alpha-uchar-p r)))))
375 (test alpha-uchar-p.2
376 (is-false
377 (alpha-uchar-p (char-to-uchar #\5))))
379 (test alpha-uchar-p.3
380 (is-true
381 (loop :for i :from 0 :to 255
382 :always (eql (alpha-uchar-p i)
383 (alpha-char-p (code-char i))))))
385 (test alpha-uchar-p.error.1
386 (signals type-error
387 (alpha-uchar-p "string")))
390 (test digit-uchar-p.1
391 (is (eql 9 (digit-uchar-p (+ #x30 9)))))
393 (test digit-uchar-p.2
394 (is (loop :for i :below 10 :always (eql i (digit-uchar-p (+ i #x30) 10)))))
396 (test digit-uchar-p.3
397 (is (loop :for i :from 10 :below 36
398 :always (eql i (digit-uchar-p (+ i #x57) 36)))))
400 (test digit-uchar-p.4
401 (is-true
402 (loop :for i :from 0 :to 255
403 :always (eql (digit-uchar-p i)
404 (digit-char-p (code-char i))))))
406 (test digit-uchar.error.1
407 (is-false (digit-uchar-p 16 16)))
409 (test digit-uchar.error.2
410 (signals type-error
411 (digit-uchar-p "string")))
414 (test alphanumeric-uchar-p.1
415 (is-true
416 (loop :for i :from 0 :to 255
417 :always (eql (alphanumeric-uchar-p i)
418 (alphanumericp (code-char i))))))
420 (test alphanumeric-uchar-p.error.1
421 (signals type-error
422 (alphanumeric-uchar-p "string")))
425 (test graphic-uchar-p.1
426 (is-true
427 (loop :for i :from 0 :to 255
428 :always (eql (graphic-uchar-p i)
429 (graphic-char-p (code-char i))))))
431 (test graphic-uchar-p.error.1
432 (signals type-error
433 (graphic-uchar-p "string")))
436 (test upper-case-uchar-p.1
437 (is-true
438 (loop :for i :from 0 :to 255
439 :always (eql (upper-case-uchar-p i)
440 (upper-case-p (code-char i))))))
442 (test upper-case-uchar-p.error.1
443 (signals type-error
444 (upper-case-uchar-p "string")))
447 (test lower-case-uchar-p.1
448 (is-true
449 (loop :for i :from 0 :to 255
450 :always (eql (lower-case-uchar-p i)
451 (lower-case-p (code-char i))))))
453 (test lower-case-uchar-p.error.1
454 (signals type-error
455 (lower-case-uchar-p "string")))
458 (test both-case-uchar-p.1
459 (is-true
460 (loop :for i :from 0 :to 255
461 :always (eql (both-case-uchar-p i)
462 (both-case-p (code-char i))))))
464 (test both-case-uchar-p.error.1
465 (signals type-error
466 (both-case-uchar-p "string")))
469 (test uchar-upcase.1
470 (is-true
471 (loop :for i :from 0 :to 255
472 :always (eql (uchar-upcase i)
473 (char-to-uchar (char-upcase (code-char i)))))))
475 (test uchar-upcase.error.1
476 (signals type-error
477 (uchar-upcase "string")))
480 (test uchar-downcase.1
481 (is-true
482 (loop :for i :from 0 :to 255
483 :always (eql (uchar-downcase i)
484 (char-to-uchar (char-downcase (code-char i)))))))
486 (test uchar-downcase.error.1
487 (signals type-error
488 (uchar-downcase "string")))