9ec833d895b0f4930d819d86e665b13afb99acaf
[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 ;; TODO: char/=, char<, etc.
41
42 ;; CHARACTER
43 (test (equal #\a (character #\a)))
44 (test (equal #\a (character "a")))
45 ;; (test (equal #\A (character 'a)))
46 ;; (test (equal #\a (character '\a)))
47 ;; (expected-failure (character 65.))
48 ;; (expected-failure (character 'apple))
49
50 ;; CHARACTERP
51 (test (characterp #\a))
52 (test (characterp (code-char 65)))
53 (test (char= #\A (code-char 65)))
54 (test (not (characterp 10)))
55 (test (not (characterp "a")))
56 (test (not (characterp "ab")))
57 (test (characterp (code-char 127744)))
58 ;; hyperspec examples:
59 (test (characterp #\a))
60 (test (not (characterp 'a)))
61 (test (not (characterp "a")))
62 (test (not (characterp 65.)))
63 ;; (test (characterp #\Newline))
64
65 ;; ALPHA-CHAR-P
66 (test (alpha-char-p #\a))
67 (test (not (alpha-char-p #\5)))
68 ;; (test (alpha-char-p #\Newline))
69
70 ;; ALPHANUMERICP
71 (test (alphanumericp #\Z))
72 (test (alphanumericp #\9))
73 ;; (test (not (alphanumericp #\Newline)))
74 (test (not (alphanumericp #\#)))
75
76 ;; DIGIT-CHAR
77 (test (char= #\0 (digit-char 0)))
78 (test (char= #\A (digit-char 10 11)))
79 (test (null (digit-char 10 10)))
80 (test (char= #\7 (digit-char 7)))
81 (test (null (digit-char 12)))
82 (test (char= #\C (digit-char 12 16)))  ;; not #\c
83 (test (null (digit-char 6 2)))
84 (test (char= #\1 (digit-char 1 2)))
85
86 ;; DIGIT-CHAR-P
87 (test (= 5 (digit-char-p #\5)))
88 (test (null (digit-char-p #\5 2)))
89 (test (null (digit-char-p #\A)))
90 (test (null (digit-char-p #\a)))
91 (test (= 10 (digit-char-p #\A 11)))
92 (test (= 10 (digit-char-p #\a 11)))
93 ;; TODO: does the mapcar/lambda thing work here?
94
95 ;; GRAPHIC-CHAR-P
96 (test (graphic-char-p #\G))
97 (test (graphic-char-p #\#))
98 ;; (test (graphic-char-p #\Space))
99 ;; (test (not (graphic-char-p #\Newline))
100
101 ;; STANDARD-CHAR-P
102 ;; (test (standard-char-p #\Space))
103 (test (standard-char-p #\~))
104
105 ;; CHAR-UPCASE
106 (test (char= #\A (char-upcase #\a)))
107 (test (char= #\A (char-upcase #\A)))
108 (test (char= (code-char 223) (char-upcase (code-char 223))))  ;; changes length, so you get the original back
109 (test (char= (code-char 127744) (char-upcase (code-char 127744))))  ;; no upper case
110
111 ;; CHAR-DOWNCASE
112 (test (char= #\a (char-downcase #\a)))
113 (test (char= #\a (char-downcase #\A)))
114 (test (char= (code-char 223) (char-downcase (code-char 223))))  ;; already lower case
115 (test (char= (code-char 127744) (char-downcase (code-char 127744))))  ;; no lower case
116
117 ;; TODO: UPPER-CASE-P, LOWER-CASE-P, BOTH-CASE-P
118
119 ;; CODE-CHAR, CHAR-CODE
120 (test (char= #\A (code-char 65)))
121 (test (= 65 (char-code #\A)))
122 (test (= 127744 (char-code (code-char 127744))))
123
124 ;; CHAR-INT
125 (test (= (char-int #\A) (char-int #\A)))  ;; can be pretty much anything, as long as it's consistent
126
127 ;; CHAR-TO-STRING (not actually part of the characters dictionary)
128 (test (= 1 (string-length (char-to-string (code-char 127744)))))
129
130 ;; CHAR-CODE-LIMIT
131 (test (< 95 char-code-limit 10000000))
132
133 ;; CHAR-NAME
134 (test (string= "Space" (char-name #\ )))
135 ;; (test (string= "Space" (char-name #\Space)))
136 (test (string= "Page" (char-name (code-char 12))))  ;; #\Page
137 (test (string= "LATIN_SMALL_LETTER_A" (char-name #\a)))
138 (test (string= "LATIN_CAPITAL_LETTER_A" (char-name #\A)))
139
140 ;; NAME-CHAR
141 (test (char= #\  (name-char 'space)))  ;; should be: #\Space
142 (test (char= #\  (name-char "space")))  ;; #\Space
143 (test (char= #\  (name-char "Space")))  ;; #\Space
144 (test
145  (let ((x (char-name #\a)))
146   (or (not x) (eql (name-char x) #\a))))