Fix comment
[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 ;; (mapcar #'(lambda (radix)
92 ;;              (map 'list #'(lambda (x) (digit-char-p x radix))
93 ;;                   "059AaFGZ"))
94 ;;          '(2 8 10 16 36))
95
96 ;; GRAPHIC-CHAR-P
97 (test (graphic-char-p #\G))
98 (test (graphic-char-p #\#))
99 ;; (test (graphic-char-p #\Space))
100 ;; (test (not (graphic-char-p #\Newline))
101
102 ;; STANDARD-CHAR-P
103 ;; (test (standard-char-p #\Space))
104 (test (standard-char-p #\~))
105
106 ;; CHAR-UPCASE
107 (test (char= #\A (char-upcase #\a)))
108 (test (char= #\A (char-upcase #\A)))
109 (test (char= (code-char 223) (char-upcase (code-char 223))))  ;; changes length, so you get the original back
110 (test (char= (code-char 127744) (char-upcase (code-char 127744))))  ;; no upper case
111
112 ;; CHAR-DOWNCASE
113 (test (char= #\a (char-downcase #\a)))
114 (test (char= #\a (char-downcase #\A)))
115 (test (char= (code-char 223) (char-downcase (code-char 223))))  ;; already lower case
116 (test (char= (code-char 127744) (char-downcase (code-char 127744))))  ;; no lower case
117
118 ;; UPPER-CASE-P, LOWER-CASE-P, BOTH-CASE-P
119 (test (upper-case-p #\A))
120 (test (not (upper-case-p #\a)))
121 (test (both-case-p #\a))
122 (test (not (both-case-p #\5)))
123 (test (not (lower-case-p #\5)))
124 (test (not (upper-case-p #\5)))
125 (test (not (upper-case-p (code-char 127744))))
126
127 ;; CODE-CHAR, CHAR-CODE
128 (test (char= #\A (code-char 65)))
129 (test (= 65 (char-code #\A)))
130 (test (= 127744 (char-code (code-char 127744))))
131
132 ;; CHAR-INT
133 (test (= (char-int #\A) (char-int #\A)))  ;; can be pretty much anything, as long as it's consistent
134
135 (test (= 1 (length (string (code-char 127744)))))
136
137 ;; CHAR-CODE-LIMIT
138 (test (< 95 char-code-limit 10000000))
139
140 ;; CHAR-NAME
141 (test (string= "Space" (char-name #\ )))
142 ;; (test (string= "Space" (char-name #\Space)))
143 (test (string= "Page" (char-name (code-char 12))))  ;; #\Page
144 (test (string= "LATIN_SMALL_LETTER_A" (char-name #\a)))
145 (test (string= "LATIN_CAPITAL_LETTER_A" (char-name #\A)))
146
147 ;; NAME-CHAR
148 (test (char= #\  (name-char 'space)))  ;; should be: #\Space
149 (test (char= #\  (name-char "space")))  ;; #\Space
150 (test (char= #\  (name-char "Space")))  ;; #\Space
151 (test
152  (let ((x (char-name #\a)))
153   (or (not x) (eql (name-char x) #\a))))