zlib: Don't use PASTE for INTMAX error messages
[jimtcl.git] / tests / utftcl.test
blob33b89335a912a3ab3d85c3bd65780f8584b98db1
1 # This file contains a collection of tests for tclUtf.c
2 # Sourcing this file into Tcl runs the tests and generates output for
3 # errors.  No output means no errors were found.
5 # Copyright (c) 1997 Sun Microsystems, Inc.
6 # Copyright (c) 1998-1999 by Scriptics Corporation.
8 # See the file "license.terms" for information on usage and redistribution
9 # of this file, and for a DISCLAIMER OF ALL WARRANTIES.
11 # RCS: @(#) $Id: utf.test,v 1.14 2007/05/02 01:37:28 kennykb Exp $
13 source [file dirname [info script]]/testing.tcl
15 needs constraint utf8
17 catch {unset x}
19 test utf-1.1 {Tcl_UniCharToUtf: 1 byte sequences} {
20     set x \x01
21 } [bytestring "\x01"]
22 test utf-1.2 {Tcl_UniCharToUtf: 2 byte sequences} {
23     set x "\u80"
24 } [bytestring "\xc2\x80"]
25 test utf-1.3 {Tcl_UniCharToUtf: 2 byte sequences} {
26     set x "\ue0"
27 } [bytestring "\xc3\xa0"]
28 test utf-1.4 {Tcl_UniCharToUtf: 3 byte sequences} {
29     set x "\u4e4e"
30 } [bytestring "\xe4\xb9\x8e"]
31 test utf-1.5 {Tcl_UniCharToUtf: negative Tcl_UniChar} {
32     string length [format %c -1]
33 } 1
35 test utf-2.1 {Tcl_UtfToUniChar: low ascii} {
36     string length "abc"
37 } {3}
38 test utf-2.2 {Tcl_UtfToUniChar: naked trail bytes} {
39     string length [bytestring "\x82\x83\x84"]
40 } {3}
41 test utf-2.3 {Tcl_UtfToUniChar: lead (2-byte) followed by non-trail} {
42     string length [bytestring "\xC2"]
43 } {1}
44 test utf-2.4 {Tcl_UtfToUniChar: lead (2-byte) followed by trail} {
45     string length [bytestring "\xC2\xa2"]
46 } {1}
47 test utf-2.5 {Tcl_UtfToUniChar: lead (3-byte) followed by non-trail} {
48     string length [bytestring "\xE2"]
49 } {1}
50 test utf-2.6 {Tcl_UtfToUniChar: lead (3-byte) followed by 1 trail} {
51     string length [bytestring "\xE2\xA2"]
52 } {2}
53 test utf-2.7 {Tcl_UtfToUniChar: lead (3-byte) followed by 2 trail} {
54     string length [bytestring "\xE4\xb9\x8e"]
55 } {1}
56 # Note that Tcl may or may not support utf-8 sequences >= 4 bytes
57 test utf-2.9 {Tcl_UtfToUniChar: 4-byte UTF sequence} {
58     string length [bytestring "\xF4\xA2\xA2\xA2"]
59 } {1}
61 test utf-3.1 {Tcl_UtfCharComplete} {
62 } {}
64 proc testnumutfchars {a {n ""}} {
65     string length $a
68 test utf-4.1 {Tcl_NumUtfChars: zero length} {
69     testnumutfchars ""
70 } {0}
71 test utf-4.2 {Tcl_NumUtfChars: length 1} {
72     testnumutfchars [bytestring "\xC2\xA2"]
73 } {1}
74 test utf-4.3 {Tcl_NumUtfChars: long string} {
75     testnumutfchars [bytestring "abc\xC2\xA2\xe4\xb9\x8e\uA2\u4e4e"]
76 } {7}
77 test utf-4.4 {Tcl_NumUtfChars: #u0000} {
78     testnumutfchars [bytestring "\xC0\x80"]
79 } {1}
80 test utf-4.5 {Tcl_NumUtfChars: zero length, calc len} {
81     testnumutfchars "" 1
82 } {0}
83 test utf-4.6 {Tcl_NumUtfChars: length 1, calc len} {
84     testnumutfchars [bytestring "\xC2\xA2"] 1
85 } {1}
86 test utf-4.7 {Tcl_NumUtfChars: long string, calc len} {
87     testnumutfchars [bytestring "abc\xC2\xA2\xe4\xb9\x8e\uA2\u4e4e"] 1
88 } {7}
89 test utf-4.8 {Tcl_NumUtfChars: #u0000, calc len} {
90     testnumutfchars [bytestring "\xC0\x80"] 1
91 } {1}
93 test utf-5.1 {Tcl_UtfFindFirsts} {
94 } {}
96 test utf-6.1 {Tcl_UtfNext} {
97 } {}
99 test utf-7.1 {Tcl_UtfPrev} {
100 } {}
102 test utf-8.1 {Tcl_UniCharAtIndex: index = 0} {
103     string index abcd 0
104 } {a}
105 test utf-8.2 {Tcl_UniCharAtIndex: index = 0} {
106     string index \u4e4e\u25a 0
107 } "\u4e4e"
108 test utf-8.3 {Tcl_UniCharAtIndex: index > 0} {
109     string index abcd 2
110 } {c}
111 test utf-8.4 {Tcl_UniCharAtIndex: index > 0} {
112     string index \u4e4e\u25a\uff\u543 2
113 } "\uff"
115 test utf-9.1 {Tcl_UtfAtIndex: index = 0} {
116     string range abcd 0 2
117 } {abc}
118 test utf-9.2 {Tcl_UtfAtIndex: index > 0} {
119     string range \u4e4e\u25a\xff\u543klmnop 1 5
120 } "\u25a\xff\u543kl"
123 test utf-10.1 {Tcl_UtfBackslash: dst == NULL} {
124     set x \n
125 } {
127 test utf-10.2 {Tcl_UtfBackslash: \u subst} {
128     set x \ua2
129 } [bytestring "\xc2\xa2"]
130 test utf-10.3 {Tcl_UtfBackslash: longer \u subst} {
131     set x \u4e21
132 } [bytestring "\xe4\xb8\xa1"]
133 test utf-10.4 {Tcl_UtfBackslash: stops at first non-hex} {
134     set x \u4e2k
135 } "[bytestring \xd3\xa2]k"
136 test utf-10.5 {Tcl_UtfBackslash: stops after 4 hex chars} {
137     set x \u4e216
138 } "[bytestring \xe4\xb8\xa1]6"
139 proc bsCheck {char num} {
140     global errNum
141     test utf-10.$errNum {backslash substitution} {
142         scan $char %c value
143         set value
144     } $num
145     incr errNum
147 set errNum 6
148 bsCheck \b      8
149 bsCheck \e      101
150 bsCheck \f      12
151 bsCheck \n      10
152 bsCheck \r      13
153 bsCheck \t      9
154 bsCheck \v      11
155 bsCheck \{      123
156 bsCheck \}      125
157 bsCheck \[      91
158 bsCheck \]      93
159 bsCheck \$      36
160 bsCheck \       32
161 bsCheck \;      59
162 bsCheck \\      92
163 bsCheck \Ca     67
164 bsCheck \Ma     77
165 bsCheck \CMa    67
166 # prior to 8.3, this returned 8, as \8 as accepted as an
167 # octal value - but it isn't! [Bug: 3975]
168 bsCheck \8a     56
169 bsCheck \14     12
170 bsCheck \141    97
171 bsCheck b\0     98
172 bsCheck \x      120
173 bsCheck \ua     10
174 bsCheck \uA     10
175 bsCheck \u41    65
176 bsCheck \u      117
177 bsCheck \uk     117
178 bsCheck \u41    65
179 bsCheck \ua     10
180 bsCheck \uA     10
181 bsCheck \340    224
182 bsCheck \ua1    161
183 bsCheck \u4e21  20001
185 test utf-11.1 {Tcl_UtfToUpper} {
186     string toupper {}
187 } {}
188 test utf-11.2 {Tcl_UtfToUpper} {
189     string toupper abc
190 } ABC
191 test utf-11.3 {Tcl_UtfToUpper} {
192     string toupper \u00e3ab
193 } \u00c3AB
194 test utf-11.4 {Tcl_UtfToUpper} {
195     string toupper \u01e3ab
196 } \u01e2AB
198 test utf-12.1 {Tcl_UtfToLower} {
199     string tolower {}
200 } {}
201 test utf-12.2 {Tcl_UtfToLower} {
202     string tolower ABC
203 } abc
204 test utf-12.3 {Tcl_UtfToLower} {
205     string tolower \u00c3AB
206 } \u00e3ab
207 test utf-12.4 {Tcl_UtfToLower} {
208     string tolower \u01e2AB
209 } \u01e3ab
212 test utf-14.1 {Tcl_UtfNcasecmp} {
213     string compare -nocase a b
214 } -1
215 test utf-14.2 {Tcl_UtfNcasecmp} {
216     string compare -nocase b a
217 } 1
218 test utf-14.3 {Tcl_UtfNcasecmp} {
219     string compare -nocase B a
220 } 1
221 test utf-14.4 {Tcl_UtfNcasecmp} {
222     string compare -nocase aBcB abca
223 } 1
225 test utf-15.1 {Tcl_UniCharToUpper, negative delta} {
226     string toupper aA
227 } AA
228 test utf-15.2 {Tcl_UniCharToUpper, positive delta} {
229     string toupper \u0178\u00ff
230 } \u0178\u0178
231 test utf-15.3 {Tcl_UniCharToUpper, no delta} {
232     string toupper !
233 } !
235 test utf-16.1 {Tcl_UniCharToLower, negative delta} {
236     string tolower aA
237 } aa
238 test utf-16.2 {Tcl_UniCharToLower, positive delta} {
239     string tolower \u0178\u00ff
240 } \u00ff\u00ff
241 test utf-17.1 {Tcl_UniCharToLower, no delta} {
242     string tolower !
243 } !
246 #test utf-21.1 {TclUniCharIsAlnum} {
247 #    # this returns 1 with Unicode 3 compliance
248 #    string is alnum \u1040\u021f
249 #} {1}
250 #test utf-21.2 {unicode alnum char in regc_locale.c} {
251 #    # this returns 1 with Unicode 3 compliance
252 #    list [regexp {^[[:alnum:]]+$} \u1040\u021f] [regexp {^\w+$} \u1040\u021f]
253 #} {1 1}
255 #test utf-22.1 {TclUniCharIsWordChar} {
256 #    string wordend "xyz123_bar fg" 0
257 #} 10
258 #test utf-22.2 {TclUniCharIsWordChar} {
259 #    string wordend "x\u5080z123_bar\u203c fg" 0
260 #} 10
262 #test utf-23.1 {TclUniCharIsAlpha} {
263 #    # this returns 1 with Unicode 3 compliance
264 #    string is alpha \u021f
265 #} {1}
266 #test utf-23.2 {unicode alpha char in regc_locale.c} {
267 #    # this returns 1 with Unicode 3 compliance
268 #    regexp {^[[:alpha:]]+$} \u021f
269 #} {1}
271 #test utf-24.1 {TclUniCharIsDigit} {
272 #    # this returns 1 with Unicode 3 compliance
273 #    string is digit \u1040
274 #} {1}
275 #test utf-24.2 {unicode digit char in regc_locale.c} {
276 #    # this returns 1 with Unicode 3 compliance
277 #    list [regexp {^[[:digit:]]+$} \u1040] [regexp {^\d+$} \u1040]
278 #} {1 1}
280 #test utf-24.3 {TclUniCharIsSpace} {
281 #    # this returns 1 with Unicode 3 compliance
282 #    string is space \u1680
283 #} {1}
284 #test utf-24.4 {unicode space char in regc_locale.c} {
285 #    # this returns 1 with Unicode 3 compliance
286 #    list [regexp {^[[:space:]]+$} \u1680] [regexp {^\s+$} \u1680]
287 #} {1 1}
289 testreport