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
19 test utf-1.1 {Tcl_UniCharToUtf: 1 byte sequences} {
22 test utf-1.2 {Tcl_UniCharToUtf: 2 byte sequences} {
24 } [bytestring "\xc2\x80"]
25 test utf-1.3 {Tcl_UniCharToUtf: 2 byte sequences} {
27 } [bytestring "\xc3\xa0"]
28 test utf-1.4 {Tcl_UniCharToUtf: 3 byte sequences} {
30 } [bytestring "\xe4\xb9\x8e"]
31 test utf-1.5 {Tcl_UniCharToUtf: negative Tcl_UniChar} {
32 string length [format %c -1]
35 test utf-2.1 {Tcl_UtfToUniChar: low ascii} {
38 test utf-2.2 {Tcl_UtfToUniChar: naked trail bytes} {
39 string length [bytestring "\x82\x83\x84"]
41 test utf-2.3 {Tcl_UtfToUniChar: lead (2-byte) followed by non-trail} {
42 string length [bytestring "\xC2"]
44 test utf-2.4 {Tcl_UtfToUniChar: lead (2-byte) followed by trail} {
45 string length [bytestring "\xC2\xa2"]
47 test utf-2.5 {Tcl_UtfToUniChar: lead (3-byte) followed by non-trail} {
48 string length [bytestring "\xE2"]
50 test utf-2.6 {Tcl_UtfToUniChar: lead (3-byte) followed by 1 trail} {
51 string length [bytestring "\xE2\xA2"]
53 test utf-2.7 {Tcl_UtfToUniChar: lead (3-byte) followed by 2 trail} {
54 string length [bytestring "\xE4\xb9\x8e"]
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"]
61 test utf-3.1 {Tcl_UtfCharComplete} {
64 proc testnumutfchars {a {n ""}} {
68 test utf-4.1 {Tcl_NumUtfChars: zero length} {
71 test utf-4.2 {Tcl_NumUtfChars: length 1} {
72 testnumutfchars [bytestring "\xC2\xA2"]
74 test utf-4.3 {Tcl_NumUtfChars: long string} {
75 testnumutfchars [bytestring "abc\xC2\xA2\xe4\xb9\x8e\uA2\u4e4e"]
77 # This is an invalid utf-8 sequence. Not minimal, so should return 2
78 test utf-4.4 {Tcl_NumUtfChars: #u0000} tcl {
79 testnumutfchars [bytestring "\xC0\x80"]
81 test utf-4.5 {Tcl_NumUtfChars: zero length, calc len} {
84 test utf-4.6 {Tcl_NumUtfChars: length 1, calc len} {
85 testnumutfchars [bytestring "\xC2\xA2"] 1
87 test utf-4.7 {Tcl_NumUtfChars: long string, calc len} {
88 testnumutfchars [bytestring "abc\xC2\xA2\xe4\xb9\x8e\uA2\u4e4e"] 1
90 test utf-4.8 {Tcl_NumUtfChars: #u0000, calc len} tcl {
91 testnumutfchars [bytestring "\xC0\x80"] 1
94 test utf-5.1 {Tcl_UtfFindFirsts} {
97 test utf-6.1 {Tcl_UtfNext} {
100 test utf-7.1 {Tcl_UtfPrev} {
103 test utf-8.1 {Tcl_UniCharAtIndex: index = 0} {
106 test utf-8.2 {Tcl_UniCharAtIndex: index = 0} {
107 string index \u4e4e\u25a 0
109 test utf-8.3 {Tcl_UniCharAtIndex: index > 0} {
112 test utf-8.4 {Tcl_UniCharAtIndex: index > 0} {
113 string index \u4e4e\u25a\uff\u543 2
116 test utf-9.1 {Tcl_UtfAtIndex: index = 0} {
117 string range abcd 0 2
119 test utf-9.2 {Tcl_UtfAtIndex: index > 0} {
120 string range \u4e4e\u25a\xff\u543klmnop 1 5
124 test utf-10.1 {Tcl_UtfBackslash: dst == NULL} {
128 test utf-10.2 {Tcl_UtfBackslash: \u subst} {
130 } [bytestring "\xc2\xa2"]
131 test utf-10.3 {Tcl_UtfBackslash: longer \u subst} {
133 } [bytestring "\xe4\xb8\xa1"]
134 test utf-10.4 {Tcl_UtfBackslash: stops at first non-hex} {
136 } "[bytestring \xd3\xa2]k"
137 test utf-10.5 {Tcl_UtfBackslash: stops after 4 hex chars} {
139 } "[bytestring \xe4\xb8\xa1]6"
140 proc bsCheck {char num} {
142 test utf-10.$errNum {backslash substitution} {
167 # prior to 8.3, this returned 8, as \8 as accepted as an
168 # octal value - but it isn't! [Bug: 3975]
186 test utf-11.1 {Tcl_UtfToUpper} {
189 test utf-11.2 {Tcl_UtfToUpper} {
192 test utf-11.3 {Tcl_UtfToUpper} {
193 string toupper \u00e3ab
195 test utf-11.4 {Tcl_UtfToUpper} {
196 string toupper \u01e3ab
199 test utf-12.1 {Tcl_UtfToLower} {
202 test utf-12.2 {Tcl_UtfToLower} {
205 test utf-12.3 {Tcl_UtfToLower} {
206 string tolower \u00c3AB
208 test utf-12.4 {Tcl_UtfToLower} {
209 string tolower \u01e2AB
213 test utf-14.1 {Tcl_UtfNcasecmp} {
214 string compare -nocase a b
216 test utf-14.2 {Tcl_UtfNcasecmp} {
217 string compare -nocase b a
219 test utf-14.3 {Tcl_UtfNcasecmp} {
220 string compare -nocase B a
222 test utf-14.4 {Tcl_UtfNcasecmp} {
223 string compare -nocase aBcB abca
226 test utf-15.1 {Tcl_UniCharToUpper, negative delta} {
229 test utf-15.2 {Tcl_UniCharToUpper, positive delta} {
230 string toupper \u0178\u00ff
232 test utf-15.3 {Tcl_UniCharToUpper, no delta} {
236 test utf-16.1 {Tcl_UniCharToLower, negative delta} {
239 test utf-16.2 {Tcl_UniCharToLower, positive delta} {
240 string tolower \u0178\u00ff
242 test utf-17.1 {Tcl_UniCharToLower, no delta} {
247 #test utf-21.1 {TclUniCharIsAlnum} {
248 # # this returns 1 with Unicode 3 compliance
249 # string is alnum \u1040\u021f
251 #test utf-21.2 {unicode alnum char in regc_locale.c} {
252 # # this returns 1 with Unicode 3 compliance
253 # list [regexp {^[[:alnum:]]+$} \u1040\u021f] [regexp {^\w+$} \u1040\u021f]
256 #test utf-22.1 {TclUniCharIsWordChar} {
257 # string wordend "xyz123_bar fg" 0
259 #test utf-22.2 {TclUniCharIsWordChar} {
260 # string wordend "x\u5080z123_bar\u203c fg" 0
263 #test utf-23.1 {TclUniCharIsAlpha} {
264 # # this returns 1 with Unicode 3 compliance
265 # string is alpha \u021f
267 #test utf-23.2 {unicode alpha char in regc_locale.c} {
268 # # this returns 1 with Unicode 3 compliance
269 # regexp {^[[:alpha:]]+$} \u021f
272 #test utf-24.1 {TclUniCharIsDigit} {
273 # # this returns 1 with Unicode 3 compliance
274 # string is digit \u1040
276 #test utf-24.2 {unicode digit char in regc_locale.c} {
277 # # this returns 1 with Unicode 3 compliance
278 # list [regexp {^[[:digit:]]+$} \u1040] [regexp {^\d+$} \u1040]
281 #test utf-24.3 {TclUniCharIsSpace} {
282 # # this returns 1 with Unicode 3 compliance
283 # string is space \u1680
285 #test utf-24.4 {unicode space char in regc_locale.c} {
286 # # this returns 1 with Unicode 3 compliance
287 # list [regexp {^[[:space:]]+$} \u1680] [regexp {^\s+$} \u1680]