Unicode-aware implementations of most of the Characters dictionary.
[jscl.git] / tests / characters.lisp
1 ;; CHAR=
2 (test (char= (code-char 127744) (code-char 127744)))
3
4 ;; TODO: char/=, char<, etc.
5
6 ;; CHARACTER
7 (test (equal #\a (character #\a)))
8 (test (equal #\a (character "a")))
9 ;; (test (equal #\A (character 'a)))
10 ;; (test (equal #\a (character '\a)))
11 ;; (expected-failure (character 65.))
12 ;; (expected-failure (character 'apple))
13
14 ;; CHARACTERP
15 (test (characterp #\a))
16 (test (characterp (code-char 65)))
17 (test (char= #\A (code-char 65)))
18 (test (not (characterp 10)))
19 (test (not (characterp "a")))
20 (test (not (characterp "ab")))
21 (test (characterp (code-char 127744)))
22 ;; hyperspec examples:
23 (test (characterp #\a))
24 (test (not (characterp 'a)))
25 (test (not (characterp "a")))
26 (test (not (characterp 65.)))
27 ;; (test (characterp #\Newline))
28
29 ;; ALPHA-CHAR-P
30 (test (alpha-char-p #\a))
31 (test (not (alpha-char-p #\5)))
32 ;; (test (alpha-char-p #\Newline))
33
34 ;; ALPHANUMERICP
35 (test (alphanumericp #\Z))
36 (test (alphanumericp #\9))
37 ;; (test (not (alphanumericp #\Newline)))
38 (test (not (alphanumericp #\#)))
39
40 ;; DIGIT-CHAR
41 (test (char= #\0 (digit-char 0)))
42 (test (char= #\A (digit-char 10 11)))
43 (test (null (digit-char 10 10)))
44 (test (char= #\7 (digit-char 7)))
45 (test (null (digit-char 12)))
46 (test (char= #\C (digit-char 12 16)))  ;; not #\c
47 (test (null (digit-char 6 2)))
48 (test (char= #\1 (digit-char 1 2)))
49
50 ;; DIGIT-CHAR-P
51 (test (= 5 (digit-char-p #\5)))
52 (test (null (digit-char-p #\5 2)))
53 (test (null (digit-char-p #\A)))
54 (test (null (digit-char-p #\a)))
55 (test (= 10 (digit-char-p #\A 11)))
56 (test (= 10 (digit-char-p #\a 11)))
57 ;; TODO: does the mapcar/lambda thing work here?
58
59 ;; GRAPHIC-CHAR-P
60 (test (graphic-char-p #\G))
61 (test (graphic-char-p #\#))
62 ;; (test (graphic-char-p #\Space))
63 ;; (test (not (graphic-char-p #\Newline))
64
65 ;; STANDARD-CHAR-P
66 ;; (test (standard-char-p #\Space))
67 (test (standard-char-p #\~))
68
69 ;; CHAR-UPCASE
70 (test (char= #\A (char-upcase #\a)))
71 (test (char= #\A (char-upcase #\A)))
72 (test (char= (code-char 223) (char-upcase (code-char 223))))  ;; changes length, so you get the original back
73 (test (char= (code-char 127744) (char-upcase (code-char 127744))))  ;; no upper case
74
75 ;; CHAR-DOWNCASE
76 (test (char= #\a (char-downcase #\a)))
77 (test (char= #\a (char-downcase #\A)))
78 (test (char= (code-char 223) (char-downcase (code-char 223))))  ;; already lower case
79 (test (char= (code-char 127744) (char-downcase (code-char 127744))))  ;; no lower case
80
81 ;; TODO: UPPER-CASE-P, LOWER-CASE-P, BOTH-CASE-P
82
83 ;; CODE-CHAR, CHAR-CODE
84 (test (char= #\A (code-char 65)))
85 (test (= 65 (char-code #\A)))
86 (test (= 127744 (char-code (code-char 127744))))
87
88 ;; CHAR-INT
89 (test (= (char-int #\A) (char-int #\A)))  ;; can be pretty much anything, as long as it's consistent
90
91 ;; CHAR-TO-STRING (not actually part of the characters dictionary)
92 (test (= 1 (string-length (char-to-string (code-char 127744)))))
93
94 ;; CHAR-CODE-LIMIT
95 (test (< 95 char-code-limit 10000000))
96
97 ;; TODO: CHAR-NAME
98
99 ;; TODO: NAME-CHAR