1 ;;;; -*- Mode: Lisp; Syntax: ANSI-Common-Lisp; indent-tabs-mode: nil -*-
3 ;;; --- uchars test suite.
6 (in-package :iolib-tests
)
8 (in-suite :iolib.base.uchars
)
12 (is (eql #x1234
(code-uchar #x1234
))))
14 (test code-uchar.error
.1
16 (code-uchar uchar-code-limit
)))
20 (is (eql #x1234
(uchar-code #x1234
))))
22 (test uchar-code.error
.1
24 (uchar-code uchar-code-limit
)))
28 (is (eql 49 (char-to-uchar #\
1))))
32 (is (char= #\
1 (uchar-to-char 49))))
34 (test uchar-to-char.error
.1
36 (uchar-to-char uchar-code-limit
)))
40 (is (eql (char-to-uchar #\space
) (name-uchar "Space"))))
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")))
50 (is (string-equal "Space" (uchar-name (char-to-uchar #\space
)))))
53 (is (string-equal "Non-Unicode uchar #xD800"
54 (uchar-name #xD800
))))
58 (is (eql (+ #x30
9) (digit-uchar 9))))
61 (is (loop :for i
:below
16 :always
(digit-uchar i
16))))
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
75 (digit-uchar "string")))
79 (is (eql 9 (uchar 9))))
82 (is (eql 9 (uchar (make-array 1 :element-type
'uchar
:initial-element
9)))))
85 (is (eql 65 (uchar #\A
))))
88 (is (eql 65 (uchar "A"))))
91 (is (eql 65 (uchar 'a
))))
95 (uchar uchar-code-limit
)))
103 (uchar (make-array 2 :element-type
'uchar
:initial-element
9))))
115 (is-true (ucharp 0)))
118 (is-true (ucharp (1- uchar-code-limit
))))
121 (is-false (ucharp -
1)))
124 (is-false (ucharp uchar-code-limit
)))
127 (is-false (ucharp #\a)))
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
)))
147 (is (eql t
(uchar= #x40
))))
150 (is (eql t
(uchar= #x40
#x40
))))
153 (is (eql t
(uchar= #x40
#x40
#x40
))))
156 (is (eql nil
(uchar= #x40
#x41
))))
160 (is (eql t
(uchar/= #x40
))))
163 (is (eql t
(uchar/= #x40
#x41
))))
166 (is (eql t
(uchar/= #x40
#x41
#x42
))))
169 (is (eql nil
(uchar/= #x40
#x40
))))
172 (is (eql nil
(uchar/= #x40
#x41
#x40
))))
176 (is (eql t
(uchar< #x40
))))
179 (is (eql t
(uchar< #x40
#x41
))))
182 (is (eql t
(uchar< #x40
#x41
#x42
))))
185 (is (eql nil
(uchar< #x40
#x40
))))
188 (is (eql nil
(uchar< #x40
#x41
#x40
))))
192 (is (eql t
(uchar> #x40
))))
195 (is (eql t
(uchar> #x41
#x40
))))
198 (is (eql t
(uchar> #x42
#x41
#x40
))))
201 (is (eql nil
(uchar> #x40
#x40
))))
204 (is (eql nil
(uchar> #x41
#x40
#x40
))))
208 (is (eql t
(uchar<= #x40
))))
211 (is (eql t
(uchar<= #x40
#x41
))))
214 (is (eql t
(uchar<= #x40
#x41
#x42
))))
217 (is (eql t
(uchar<= #x40
#x40
))))
220 (is (eql nil
(uchar<= #x40
#x41
#x40
))))
224 (is (eql t
(uchar>= #x40
))))
227 (is (eql t
(uchar>= #x41
#x40
))))
230 (is (eql t
(uchar>= #x42
#x41
#x40
))))
233 (is (eql t
(uchar>= #x40
#x40
))))
236 (is (eql nil
(uchar>= #x40
#x41
#x40
))))
240 (is (eql t
(uchar-equal #x40
))))
243 (is (eql t
(uchar-equal #x40
#x40
))))
246 (is (eql t
(uchar-equal #x40
#x40
#x40
))))
249 (is (eql t
(uchar-equal #x41
#x61
))))
252 (is (eql t
(uchar-equal #x41
#x61
#x41
))))
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
))))
281 (is (eql t
(uchar-lessp #x40
))))
284 (is (eql t
(uchar-lessp #x40
#x41
))))
287 (is (eql t
(uchar-lessp #x40
#x41
#x42
))))
290 (is (eql nil
(uchar-lessp #x40
#x40
))))
293 (is (eql nil
(uchar-lessp #x40
#x41
#x40
))))
296 (is (eql nil
(uchar-lessp #x41
#x61
))))
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
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
377 (alpha-uchar-p (char-to-uchar #\
5))))
379 (test alpha-uchar-p
.3
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
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
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
411 (digit-uchar-p "string")))
414 (test alphanumeric-uchar-p
.1
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
422 (alphanumeric-uchar-p "string")))
425 (test graphic-uchar-p
.1
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
433 (graphic-uchar-p "string")))
436 (test upper-case-uchar-p
.1
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
444 (upper-case-uchar-p "string")))
447 (test lower-case-uchar-p
.1
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
455 (lower-case-uchar-p "string")))
458 (test both-case-uchar-p
.1
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
466 (both-case-uchar-p "string")))
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
477 (uchar-upcase "string")))
480 (test uchar-downcase
.1
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
488 (uchar-downcase "string")))