Debian Codegraph @

scheme/tests/unicode.ss

raw
1
2 (library (tests unicode)
3 (export run-tests)
4 (import (ikarus))
5
6 (define-syntax test
7 (lambda (q)
8 (syntax-case q ()
9 [(_ x y)
10 #`(unless (equal? x y)
11 (syntax-error #''#,q "test failed"))])))
12
13 (define (run-unicode-tests)
14 (test (char-upcase #\i) #\I)
15 (test (char-downcase #\i) #\i)
16 (test (char-titlecase #\i) #\I)
17 (test (char-foldcase #\i) #\i)
18
19 (test (char-upcase #\xDF) #\xDF)
20 (test (char-downcase #\xDF) #\xDF)
21 (test (char-titlecase #\xDF) #\xDF)
22 (test (char-foldcase #\xDF) #\xDF)
23
24 (test (char-upcase #\x3A3) #\x3A3)
25 (test (char-downcase #\x3A3) #\x3C3)
26 (test (char-titlecase #\x3A3) #\x3A3)
27 (test (char-foldcase #\x3A3) #\x3C3)
28
29 (test (char-upcase #\x3C2) #\x3A3)
30 (test (char-downcase #\x3C2) #\x3C2)
31 (test (char-titlecase #\x3C2) #\x3A3)
32 (test (char-foldcase #\x3C2) #\x3C3)
33
34 (test (char-ci<? #\z #\Z) #f)
35 (test (char-ci<? #\Z #\z) #f)
36 (test (char-ci<? #\a #\Z) #t)
37 (test (char-ci<? #\Z #\a) #f)
38 (test (char-ci<=? #\z #\Z) #t)
39 (test (char-ci<=? #\Z #\z) #t)
40 (test (char-ci<=? #\a #\Z) #t)
41 (test (char-ci<=? #\Z #\a) #f)
42 (test (char-ci=? #\z #\a) #f)
43 (test (char-ci=? #\z #\Z) #t)
44 (test (char-ci=? #\x3C2 #\x3C3) #t)
45 (test (char-ci>? #\z #\Z) #f)
46 (test (char-ci>? #\Z #\z) #f)
47 (test (char-ci>? #\a #\Z) #f)
48 (test (char-ci>? #\Z #\a) #t)
49 (test (char-ci>=? #\Z #\z) #t)
50 (test (char-ci>=? #\z #\Z) #t)
51 (test (char-ci>=? #\z #\Z) #t)
52 (test (char-ci>=? #\a #\z) #f)
53
54 (test (char-alphabetic? #\a) #t)
55 (test (char-alphabetic? #\1) #f)
56 (test (char-numeric? #\1) #t)
57 (test (char-numeric? #\a) #f)
58 (test (char-whitespace? #\space) #t)
59 (test (char-whitespace? #\x00A0) #t)
60 (test (char-whitespace? #\a) #f)
61 (test (char-upper-case? #\a) #f)
62 (test (char-upper-case? #\A) #t)
63 (test (char-upper-case? #\x3A3) #t)
64 (test (char-lower-case? #\a) #t)
65 (test (char-lower-case? #\A) #f)
66 (test (char-lower-case? #\x3C3) #t)
67 (test (char-lower-case? #\x00AA) #t)
68 (test (char-title-case? #\a) #f)
69 (test (char-title-case? #\A) #f)
70 (test (char-title-case? #\I) #f)
71 (test (char-title-case? #\x01C5) #t)
72
73 (test (char-general-category #\a) 'Ll)
74 (test (char-general-category #\space) 'Zs)
75 (test (char-general-category #\x10FFFF) 'Cn)
76
77 (test (string-upcase "Hi") "HI")
78 (test (string-upcase "HI") "HI")
79 (test (string-downcase "Hi") "hi")
80 (test (string-downcase "hi") "hi")
81 (test (string-foldcase "Hi") "hi")
82 (test (string-foldcase "HI") "hi")
83 (test (string-foldcase "hi") "hi")
84
85 (test (string-upcase "Stra\xDF;e") "STRASSE")
86 (test (string-downcase "Stra\xDF;e") "stra\xDF;e")
87 (test (string-foldcase "Stra\xDF;e") "strasse")
88 (test (string-downcase "STRASSE") "strasse")
89
90 (test (string-downcase "\x3A3;") "\x3C3;")
91
92 (test (string-upcase "\x39E;\x391;\x39F;\x3A3;") "\x39E;\x391;\x39F;\x3A3;")
93 (test (string-downcase "\x39E;\x391;\x39F;\x3A3;") "\x3BE;\x3B1;\x3BF;\x3C2;")
94 (test (string-downcase "\x39E;\x391;\x39F;\x3A3;\x3A3;") "\x3BE;\x3B1;\x3BF;\x3C3;\x3C2;")
95 (test (string-downcase "\x39E;\x391;\x39F;\x3A3; \x3A3;") "\x3BE;\x3B1;\x3BF;\x3C2; \x3C3;")
96 (test (string-foldcase "\x39E;\x391;\x39F;\x3A3;") "\x3BE;\x3B1;\x3BF;\x3C3;")
97 (test (string-upcase "\x3BE;\x3B1;\x3BF;\x3C3;") "\x39E;\x391;\x39F;\x3A3;")
98 (test (string-upcase "\x3BE;\x3B1;\x3BF;\x3C2;") "\x39E;\x391;\x39F;\x3A3;")
99
100 (test (string-titlecase "kNock KNoCK") "Knock Knock")
101 (test (string-titlecase "who's there?") "Who's There?")
102 (test (string-titlecase "r6rs") "R6rs") ; this example appears to be wrong in R6RS (Sept 2007 version)
103 (test (string-titlecase "R6RS") "R6rs") ; this one, too
104
105 (test (string-downcase "A\x3A3;'x") "a\x3C3;'x") ; ' is a MidLetter
106
107 (test (string-ci<? "a" "Z") #t)
108 (test (string-ci<? "A" "z") #t)
109 (test (string-ci<? "Z" "a") #f)
110 (test (string-ci<? "z" "A") #f)
111 (test (string-ci<? "z" "Z") #f)
112 (test (string-ci<? "Z" "z") #f)
113 (test (string-ci>? "a" "Z") #f)
114 (test (string-ci>? "A" "z") #f)
115 (test (string-ci>? "Z" "a") #t)
116 (test (string-ci>? "z" "A") #t)
117 (test (string-ci>? "z" "Z") #f)
118 (test (string-ci>? "Z" "z") #f)
119 (test (string-ci=? "z" "Z") #t)
120 (test (string-ci=? "z" "a") #f)
121 (test (string-ci=? "Stra\xDF;e" "Strasse") #t)
122 (test (string-ci=? "Stra\xDF;e" "STRASSE") #t)
123 (test (string-ci=? "\x39E;\x391;\x39F;\x3A3;" "\x3BE;\x3B1;\x3BF;\x3C2;") #t)
124 (test (string-ci=? "\x39E;\x391;\x39F;\x3A3;" "\x3BE;\x3B1;\x3BF;\x3C3;") #t)
125 (test (string-ci<=? "a" "Z") #t)
126 (test (string-ci<=? "A" "z") #t)
127 (test (string-ci<=? "Z" "a") #f)
128 (test (string-ci<=? "z" "A") #f)
129 (test (string-ci<=? "z" "Z") #t)
130 (test (string-ci<=? "Z" "z") #t)
131 (test (string-ci>=? "a" "Z") #f)
132 (test (string-ci>=? "A" "z") #f)
133 (test (string-ci>=? "Z" "a") #t)
134 (test (string-ci>=? "z" "A") #t)
135 (test (string-ci>=? "z" "Z") #t)
136 (test (string-ci>=? "Z" "z") #t)
137
138 (test (string-normalize-nfd "\xE9;") "\x65;\x301;")
139 (test (string-normalize-nfc "\xE9;") "\xE9;")
140 (test (string-normalize-nfd "\x65;\x301;") "\x65;\x301;")
141 (test (string-normalize-nfc "\x65;\x301;") "\xE9;")
142
143 (test (string-normalize-nfkd "\xE9;") "\x65;\x301;")
144 (test (string-normalize-nfkc "\xE9;") "\xE9;")
145 (test (string-normalize-nfkd "\x65;\x301;") "\x65;\x301;")
146 (test (string-normalize-nfkc "\x65;\x301;") "\xE9;"))
147
148 (define (run-tests)
149 (run-unicode-tests))
150 )
151