Debian Codegraph @

test-suite/tests/chars.test

raw
1 ;;;; chars.test --- Characters. -*- coding: utf-8; mode: scheme; -*-
2 ;;;; Greg J. Badros <[email protected]>
3 ;;;;
4 ;;;; Copyright (C) 2000, 2006, 2009, 2010, 2013, 2021 Free Software Foundation, Inc.
5 ;;;;
6 ;;;; This library is free software; you can redistribute it and/or
7 ;;;; modify it under the terms of the GNU Lesser General Public
8 ;;;; License as published by the Free Software Foundation; either
9 ;;;; version 3 of the License, or (at your option) any later version.
10 ;;;;
11 ;;;; This library is distributed in the hope that it will be useful,
12 ;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
13 ;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 ;;;; Lesser General Public License for more details.
15 ;;;;
16 ;;;; You should have received a copy of the GNU Lesser General Public
17 ;;;; License along with this library; if not, write to the Free Software
18 ;;;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19
20 (use-modules (test-suite lib))
21
22 (define exception:wrong-type-to-apply
23 (cons 'misc-error "^Wrong type to apply:"))
24
25 (define exception:unknown-character-name
26 (cons #t "unknown character"))
27
28
29 (with-test-prefix "basic char handling"
30
31 (with-test-prefix "evaluator"
32
33 ;; The following test makes sure that the evaluator distinguishes between
34 ;; evaluator-internal instruction codes and characters.
35 (pass-if-exception "evaluating chars"
36 exception:wrong-type-arg
37 (eval '(#\0) (interaction-environment))))
38
39 (with-test-prefix "comparisons"
40
41 ;; char=?
42 (pass-if "char=? #\\A #\\A"
43 (char=? #\A #\A))
44
45 (pass-if "char=? #\\A #\\a"
46 (not (char=? #\A #\a)))
47
48 (pass-if "char=? #\\A #\\B"
49 (not (char=? #\A #\B)))
50
51 (pass-if "char=? #\\B #\\A"
52 (not (char=? #\A #\B)))
53
54 ;; char<?
55 (pass-if "char<? #\\A #\\A"
56 (not (char<? #\A #\A)))
57
58 (pass-if "char<? #\\A #\\a"
59 (char<? #\A #\a))
60
61 (pass-if "char<? #\\A #\\B"
62 (char<? #\A #\B))
63
64 (pass-if "char<? #\\B #\\A"
65 (not (char<? #\B #\A)))
66
67 ;; char<=?
68 (pass-if "char<=? #\\A #\\A"
69 (char<=? #\A #\A))
70
71 (pass-if "char<=? #\\A #\\a"
72 (char<=? #\A #\a))
73
74 (pass-if "char<=? #\\A #\\B"
75 (char<=? #\A #\B))
76
77 (pass-if "char<=? #\\B #\\A"
78 (not (char<=? #\B #\A)))
79
80 ;; char>?
81 (pass-if "char>? #\\A #\\A"
82 (not (char>? #\A #\A)))
83
84 (pass-if "char>? #\\A #\\a"
85 (not (char>? #\A #\a)))
86
87 (pass-if "char>? #\\A #\\B"
88 (not (char>? #\A #\B)))
89
90 (pass-if "char>? #\\B #\\A"
91 (char>? #\B #\A))
92
93 ;; char>=?
94 (pass-if "char>=? #\\A #\\A"
95 (char>=? #\A #\A))
96
97 (pass-if "char>=? #\\A #\\a"
98 (not (char>=? #\A #\a)))
99
100 (pass-if "char>=? #\\A #\\B"
101 (not (char>=? #\A #\B)))
102
103 (pass-if "char>=? #\\B #\\A"
104 (char>=? #\B #\A))
105
106 ;; char-ci=?
107 (pass-if "char-ci=? #\\A #\\A"
108 (char-ci=? #\A #\A))
109
110 (pass-if "char-ci=? #\\A #\\a"
111 (char-ci=? #\A #\a))
112
113 (pass-if "char-ci=? #\\A #\\B"
114 (not (char-ci=? #\A #\B)))
115
116 (pass-if "char-ci=? #\\B #\\A"
117 (not (char-ci=? #\A #\B)))
118
119 ;; char-ci<?
120 (pass-if "char-ci<? #\\A #\\A"
121 (not (char-ci<? #\A #\A)))
122
123 (pass-if "char-ci<? #\\A #\\a"
124 (not (char-ci<? #\A #\a)))
125
126 (pass-if "char-ci<? #\\A #\\B"
127 (char-ci<? #\A #\B))
128
129 (pass-if "char-ci<? #\\B #\\A"
130 (not (char-ci<? #\B #\A)))
131
132 ;; char-ci<=?
133 (pass-if "char-ci<=? #\\A #\\A"
134 (char-ci<=? #\A #\A))
135
136 (pass-if "char-ci<=? #\\A #\\a"
137 (char-ci<=? #\A #\a))
138
139 (pass-if "char-ci<=? #\\A #\\B"
140 (char-ci<=? #\A #\B))
141
142 (pass-if "char-ci<=? #\\B #\\A"
143 (not (char-ci<=? #\B #\A)))
144
145 ;; char-ci>?
146 (pass-if "char-ci>? #\\A #\\A"
147 (not (char-ci>? #\A #\A)))
148
149 (pass-if "char-ci>? #\\A #\\a"
150 (not (char-ci>? #\A #\a)))
151
152 (pass-if "char-ci>? #\\A #\\B"
153 (not (char-ci>? #\A #\B)))
154
155 (pass-if "char-ci>? #\\B #\\A"
156 (char-ci>? #\B #\A))
157
158 ;; char-ci>=?
159 (pass-if "char-ci>=? #\\A #\\A"
160 (char-ci>=? #\A #\A))
161
162 (pass-if "char-ci>=? #\\A #\\a"
163 (char-ci>=? #\A #\a))
164
165 (pass-if "char-ci>=? #\\A #\\B"
166 (not (char-ci>=? #\A #\B)))
167
168 (pass-if "char-ci>=? #\\B #\\A"
169 (char-ci>=? #\B #\A)))
170
171 (with-test-prefix "categories"
172
173 (pass-if "char-alphabetic?"
174 (and (char-alphabetic? #\a)
175 (char-alphabetic? #\A)
176 (not (char-alphabetic? #\1))
177 (not (char-alphabetic? #\+))))
178
179 (pass-if "char-numeric?"
180 (and (not (char-numeric? #\a))
181 (not (char-numeric? #\A))
182 (char-numeric? #\1)
183 (not (char-numeric? #\+))))
184
185 (pass-if "char-whitespace?"
186 (and (not (char-whitespace? #\a))
187 (not (char-whitespace? #\A))
188 (not (char-whitespace? #\1))
189 (char-whitespace? #\space)
190 (not (char-whitespace? #\+))))
191
192 (pass-if "char-upper-case?"
193 (and (not (char-upper-case? #\a))
194 (char-upper-case? #\A)
195 (not (char-upper-case? #\1))
196 (not (char-upper-case? #\+))))
197
198 (pass-if "char-lower-case?"
199 (and (char-lower-case? #\a)
200 (not (char-lower-case? #\A))
201 (not (char-lower-case? #\1))
202 (not (char-lower-case? #\+))))
203
204 (pass-if "char-is-both? works"
205 (and
206 (not (char-is-both? #\?))
207 (not (char-is-both? #\newline))
208 (char-is-both? #\a)
209 (char-is-both? #\Z)
210 (not (char-is-both? #\1))))
211
212 (pass-if "char-general-category"
213 (and (eq? (char-general-category #\a) 'Ll)
214 (eq? (char-general-category #\A) 'Lu)
215 (eq? (char-general-category #\762) 'Lt))))
216
217 (with-test-prefix "integer"
218
219 (pass-if "char->integer"
220 (eqv? (char->integer #\A) 65))
221
222 (pass-if "integer->char"
223 (eqv? (integer->char 65) #\A))
224
225 (pass-if-exception "integer->char out of range, -1" exception:out-of-range
226 (integer->char -1))
227
228 (pass-if-exception "integer->char out of range, surrrogate"
229 exception:out-of-range
230 (integer->char #xd800))
231
232 (pass-if-exception "integer->char out of range, too big"
233 exception:out-of-range
234 (integer->char #x110000))
235
236 (pass-if-exception "octal out of range, surrrogate"
237 exception:out-of-range
238 (with-input-from-string "#\\154000" read))
239
240 (pass-if-exception "octal out of range, too big"
241 exception:out-of-range
242 (with-input-from-string "#\\4200000" read)))
243
244 (with-test-prefix "case"
245
246 (pass-if "char-upcase"
247 (eqv? (char-upcase #\a) #\A))
248
249 (pass-if "char-downcase"
250 (eqv? (char-downcase #\A) #\a))
251
252 (pass-if "char-titlecase"
253 (and (eqv? (char-titlecase #\a) #\A)
254 (eqv? (char-titlecase #\763) #\762))))
255
256 (with-test-prefix "charnames"
257
258 (pass-if "R5RS character names"
259 (and (eqv? #\space (integer->char #x20))
260 (eqv? #\newline (integer->char #x0A))))
261
262 (pass-if "R6RS character names"
263 (and (eqv? #\nul (integer->char #x00))
264 (eqv? #\alarm (integer->char #x07))
265 (eqv? #\backspace (integer->char #x08))
266 (eqv? #\tab (integer->char #x09))
267 (eqv? #\linefeed (integer->char #x0A))
268 (eqv? #\newline (integer->char #x0A))
269 (eqv? #\vtab (integer->char #x0B))
270 (eqv? #\page (integer->char #x0C))
271 (eqv? #\return (integer->char #x0D))
272 (eqv? #\esc (integer->char #x1B))
273 (eqv? #\space (integer->char #x20))
274 (eqv? #\delete (integer->char #x7F))))
275
276 (pass-if "R5RS character names are case insensitive"
277 (and (eqv? #\space #\ )
278 (eqv? #\SPACE #\ )
279 (eqv? #\Space #\ )
280 (eqv? #\newline (integer->char 10))
281 (eqv? #\NEWLINE (integer->char 10))
282 (eqv? #\Newline (integer->char 10))))
283
284 (pass-if "C0 control names are case insensitive"
285 (and (eqv? #\nul #\000)
286 (eqv? #\soh #\001)
287 (eqv? #\stx #\002)
288 (eqv? #\NUL #\000)
289 (eqv? #\SOH #\001)
290 (eqv? #\STX #\002)
291 (eqv? #\Nul #\000)
292 (eqv? #\Soh #\001)
293 (eqv? #\Stx #\002)))
294
295 (pass-if "alt charnames are case insensitive"
296 (eqv? #\null #\nul)
297 (eqv? #\NULL #\nul)
298 (eqv? #\Null #\nul))
299
300 (pass-if-exception "bad charname" exception:unknown-character-name
301 (with-input-from-string "#\\blammo" read))
302
303 (pass-if "R5RS character names are preferred write format"
304 (string=?
305 (with-output-to-string (lambda () (write #\space)))
306 "#\\space"))
307
308 (pass-if "C0 control character names are preferred write format"
309 (string=?
310 (with-output-to-string (lambda () (write #\soh)))
311 "#\\soh"))
312
313 (pass-if "combining accent is pretty-printed"
314 (let ((accent (integer->char #x030f))) ; COMBINING DOUBLE GRAVE ACCENT
315 (string=?
316 (with-output-to-string (lambda () (write accent)))
317 "#\\◌̏")))
318
319 (pass-if "combining X is pretty-printed"
320 (let ((x (integer->char #x0353))) ; COMBINING X BELOW
321 (string=?
322 (with-output-to-string (lambda () (write x)))
323 "#\\◌͓")))))