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 test utf-4.4 {Tcl_NumUtfChars: #u0000} {
78 testnumutfchars [bytestring "\xC0\x80"]
80 test utf-4.5 {Tcl_NumUtfChars: zero length, calc len} {
83 test utf-4.6 {Tcl_NumUtfChars: length 1, calc len} {
84 testnumutfchars [bytestring "\xC2\xA2"] 1
86 test utf-4.7 {Tcl_NumUtfChars: long string, calc len} {
87 testnumutfchars [bytestring "abc\xC2\xA2\xe4\xb9\x8e\uA2\u4e4e"] 1
89 test utf-4.8 {Tcl_NumUtfChars: #u0000, calc len} {
90 testnumutfchars [bytestring "\xC0\x80"] 1
93 test utf-5.1 {Tcl_UtfFindFirsts} {
96 test utf-6.1 {Tcl_UtfNext} {
99 test utf-7.1 {Tcl_UtfPrev} {
102 test utf-8.1 {Tcl_UniCharAtIndex: index = 0} {
105 test utf-8.2 {Tcl_UniCharAtIndex: index = 0} {
106 string index \u4e4e\u25a 0
108 test utf-8.3 {Tcl_UniCharAtIndex: index > 0} {
111 test utf-8.4 {Tcl_UniCharAtIndex: index > 0} {
112 string index \u4e4e\u25a\uff\u543 2
115 test utf-9.1 {Tcl_UtfAtIndex: index = 0} {
116 string range abcd 0 2
118 test utf-9.2 {Tcl_UtfAtIndex: index > 0} {
119 string range \u4e4e\u25a\xff\u543klmnop 1 5
123 test utf-10.1 {Tcl_UtfBackslash: dst == NULL} {
127 test utf-10.2 {Tcl_UtfBackslash: \u subst} {
129 } [bytestring "\xc2\xa2"]
130 test utf-10.3 {Tcl_UtfBackslash: longer \u subst} {
132 } [bytestring "\xe4\xb8\xa1"]
133 test utf-10.4 {Tcl_UtfBackslash: stops at first non-hex} {
135 } "[bytestring \xd3\xa2]k"
136 test utf-10.5 {Tcl_UtfBackslash: stops after 4 hex chars} {
138 } "[bytestring \xe4\xb8\xa1]6"
139 proc bsCheck {char num} {
141 test utf-10.$errNum {backslash substitution} {
166 # prior to 8.3, this returned 8, as \8 as accepted as an
167 # octal value - but it isn't! [Bug: 3975]
185 test utf-11.1 {Tcl_UtfToUpper} {
188 test utf-11.2 {Tcl_UtfToUpper} {
191 test utf-11.3 {Tcl_UtfToUpper} {
192 string toupper \u00e3ab
194 test utf-11.4 {Tcl_UtfToUpper} {
195 string toupper \u01e3ab
198 test utf-12.1 {Tcl_UtfToLower} {
201 test utf-12.2 {Tcl_UtfToLower} {
204 test utf-12.3 {Tcl_UtfToLower} {
205 string tolower \u00c3AB
207 test utf-12.4 {Tcl_UtfToLower} {
208 string tolower \u01e2AB
212 test utf-14.1 {Tcl_UtfNcasecmp} {
213 string compare -nocase a b
215 test utf-14.2 {Tcl_UtfNcasecmp} {
216 string compare -nocase b a
218 test utf-14.3 {Tcl_UtfNcasecmp} {
219 string compare -nocase B a
221 test utf-14.4 {Tcl_UtfNcasecmp} {
222 string compare -nocase aBcB abca
225 test utf-15.1 {Tcl_UniCharToUpper, negative delta} {
228 test utf-15.2 {Tcl_UniCharToUpper, positive delta} {
229 string toupper \u0178\u00ff
231 test utf-15.3 {Tcl_UniCharToUpper, no delta} {
235 test utf-16.1 {Tcl_UniCharToLower, negative delta} {
238 test utf-16.2 {Tcl_UniCharToLower, positive delta} {
239 string tolower \u0178\u00ff
241 test utf-17.1 {Tcl_UniCharToLower, no delta} {
246 #test utf-21.1 {TclUniCharIsAlnum} {
247 # # this returns 1 with Unicode 3 compliance
248 # string is alnum \u1040\u021f
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]
255 #test utf-22.1 {TclUniCharIsWordChar} {
256 # string wordend "xyz123_bar fg" 0
258 #test utf-22.2 {TclUniCharIsWordChar} {
259 # string wordend "x\u5080z123_bar\u203c fg" 0
262 #test utf-23.1 {TclUniCharIsAlpha} {
263 # # this returns 1 with Unicode 3 compliance
264 # string is alpha \u021f
266 #test utf-23.2 {unicode alpha char in regc_locale.c} {
267 # # this returns 1 with Unicode 3 compliance
268 # regexp {^[[:alpha:]]+$} \u021f
271 #test utf-24.1 {TclUniCharIsDigit} {
272 # # this returns 1 with Unicode 3 compliance
273 # string is digit \u1040
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]
280 #test utf-24.3 {TclUniCharIsSpace} {
281 # # this returns 1 with Unicode 3 compliance
282 # string is space \u1680
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]