aa8388eebd7631a804f33415c8e7f311f8b050c2
[jscl.git] / tests / characters.lisp
1 ;; CHAR=, CHAR/=, etc.
2 (test (char= (code-char 127744) (code-char 127744)))
3 (test (char= #\d #\d))
4 (test (not (char= #\A #\a)))
5 (test (not (char= #\d #\x)))
6 (test (not (char= #\d #\D)))
7 (test (not (char/= #\d #\d)))
8 (test (char/= #\d #\x))
9 (test (char/= #\d #\D))
10 (test (char= #\d #\d #\d #\d))
11 (test (not (char/= #\d #\d #\d #\d)))
12 (test (not (char= #\d #\d #\x #\d)))
13 (test (not (char/= #\d #\d #\x #\d)))
14 (test (not (char= #\d #\y #\x #\c)))
15 (test (char/= #\d #\y #\x #\c))
16 (test (not (char= #\d #\c #\d)))
17 (test (not (char/= #\d #\c #\d)))
18 (test (char< #\d #\x))
19 (test (char<= #\d #\x))
20 (test (not (char< #\d #\d)))
21 (test (char<= #\d #\d))
22 (test (char< #\a #\e #\y #\z))
23 (test (char<= #\a #\e #\y #\z))
24 (test (not (char< #\a #\e #\e #\y)))
25 (test (char<= #\a #\e #\e #\y))
26 (test (char> #\e #\d))
27 (test (char>= #\e #\d))
28 (test (char> #\d #\c #\b #\a))
29 (test (char>= #\d #\c #\b #\a))
30 (test (not (char> #\d #\d #\c #\a)))
31 (test (char>= #\d #\d #\c #\a))
32 (test (not (char> #\e #\d #\b #\c #\a)))
33 (test (not (char>= #\e #\d #\b #\c #\a)))
34 ;; (char> #\z #\A) =>  implementation-dependent
35 ;; (char> #\Z #\a) =>  implementation-dependent
36 (test (char-equal #\A #\a))
37 ;; (stable-sort (list #\b #\A #\B #\a #\c #\C) #'char-lessp) =>  (#\A #\a #\b #\B #\c #\C)
38 ;; (stable-sort (list #\b #\A #\B #\a #\c #\C) #'char<) => implementation-dependent
39
40 ;; CHARACTER
41 (test (equal #\a (character #\a)))
42 (test (equal #\a (character "a")))
43 ;; (test (equal #\A (character 'a)))
44 ;; (test (equal #\a (character '\a)))
45 ;; (expected-failure (character 65.))
46 ;; (expected-failure (character 'apple))
47
48 ;; CHARACTERP
49 (test (characterp #\a))
50 (test (characterp (code-char 65)))
51 (test (char= #\A (code-char 65)))
52 (test (not (characterp 10)))
53 (test (not (characterp "a")))
54 (test (not (characterp "ab")))
55 (test (characterp (code-char 127744)))
56 ;; hyperspec examples:
57 (test (characterp #\a))
58 (test (not (characterp 'a)))
59 (test (not (characterp "a")))
60 (test (not (characterp 65.)))
61 ;; (test (characterp #\Newline))
62
63 ;; ALPHA-CHAR-P
64 (test (alpha-char-p #\a))
65 (test (not (alpha-char-p #\5)))
66 ;; (test (alpha-char-p #\Newline))
67
68 ;; ALPHANUMERICP
69 (test (alphanumericp #\Z))
70 (test (alphanumericp #\9))
71 ;; (test (not (alphanumericp #\Newline)))
72 (test (not (alphanumericp #\#)))
73
74 ;; DIGIT-CHAR
75 (test (char= #\0 (digit-char 0)))
76 (test (char= #\A (digit-char 10 11)))
77 (test (null (digit-char 10 10)))
78 (test (char= #\7 (digit-char 7)))
79 (test (null (digit-char 12)))
80 (test (char= #\C (digit-char 12 16)))  ;; not #\c
81 (test (null (digit-char 6 2)))
82 (test (char= #\1 (digit-char 1 2)))
83
84 ;; DIGIT-CHAR-P
85 (test (= 5 (digit-char-p #\5)))
86 (test (null (digit-char-p #\5 2)))
87 (test (null (digit-char-p #\A)))
88 (test (null (digit-char-p #\a)))
89 (test (= 10 (digit-char-p #\A 11)))
90 (test (= 10 (digit-char-p #\a 11)))
91 ;; TODO: does the mapcar/lambda thing work here?
92
93 ;; GRAPHIC-CHAR-P
94 (test (graphic-char-p #\G))
95 (test (graphic-char-p #\#))
96 ;; (test (graphic-char-p #\Space))
97 ;; (test (not (graphic-char-p #\Newline))
98
99 ;; STANDARD-CHAR-P
100 ;; (test (standard-char-p #\Space))
101 (test (standard-char-p #\~))
102
103 ;; CHAR-UPCASE
104 (test (char= #\A (char-upcase #\a)))
105 (test (char= #\A (char-upcase #\A)))
106 (test (char= (code-char 223) (char-upcase (code-char 223))))  ;; changes length, so you get the original back
107 (test (char= (code-char 127744) (char-upcase (code-char 127744))))  ;; no upper case
108
109 ;; CHAR-DOWNCASE
110 (test (char= #\a (char-downcase #\a)))
111 (test (char= #\a (char-downcase #\A)))
112 (test (char= (code-char 223) (char-downcase (code-char 223))))  ;; already lower case
113 (test (char= (code-char 127744) (char-downcase (code-char 127744))))  ;; no lower case
114
115 ;; UPPER-CASE-P, LOWER-CASE-P, BOTH-CASE-P
116 (test (upper-case-p #\A))
117 (test (not (upper-case-p #\a)))
118 (test (both-case-p #\a))
119 (test (not (both-case-p #\5)))
120 (test (not (lower-case-p #\5)))
121 (test (not (upper-case-p #\5)))
122 (test (not (upper-case-p (code-char 127744))))
123
124 ;; CODE-CHAR, CHAR-CODE
125 (test (char= #\A (code-char 65)))
126 (test (= 65 (char-code #\A)))
127 (test (= 127744 (char-code (code-char 127744))))
128
129 ;; CHAR-INT
130 (test (= (char-int #\A) (char-int #\A)))  ;; can be pretty much anything, as long as it's consistent
131
132 ;; CHAR-TO-STRING (not actually part of the characters dictionary)
133 (test (= 1 (string-length (char-to-string (code-char 127744)))))
134
135 ;; CHAR-CODE-LIMIT
136 (test (< 95 char-code-limit 10000000))
137
138 ;; CHAR-NAME
139 (test (string= "Space" (char-name #\ )))
140 ;; (test (string= "Space" (char-name #\Space)))
141 (test (string= "Page" (char-name (code-char 12))))  ;; #\Page
142 (test (string= "LATIN_SMALL_LETTER_A" (char-name #\a)))
143 (test (string= "LATIN_CAPITAL_LETTER_A" (char-name #\A)))
144
145 ;; NAME-CHAR
146 (test (char= #\  (name-char 'space)))  ;; should be: #\Space
147 (test (char= #\  (name-char "space")))  ;; #\Space
148 (test (char= #\  (name-char "Space")))  ;; #\Space
149 (test
150  (let ((x (char-name #\a)))
151   (or (not x) (eql (name-char x) #\a))))