os/persistentdata/persistentstorage/sqlite3api/TEST/TCL/tcldistribution/tests/string.test
Update contrib.
1 # Commands covered: string
3 # This file contains a collection of tests for one or more of the Tcl
4 # built-in commands. Sourcing this file into Tcl runs the tests and
5 # generates output for errors. No output means no errors were found.
7 # Copyright (c) 1991-1993 The Regents of the University of California.
8 # Copyright (c) 1994 Sun Microsystems, Inc.
9 # Copyright (c) 1998-1999 by Scriptics Corporation.
10 # Copyright (c) 2001 by Kevin B. Kenny. All rights reserved.
12 # See the file "license.terms" for information on usage and redistribution
13 # of this file, and for a DISCLAIMER OF ALL WARRANTIES.
15 # RCS: @(#) $Id: string.test,v 1.36.2.7 2006/01/23 12:11:15 msofer Exp $
17 if {[lsearch [namespace children] ::tcltest] == -1} {
18 package require tcltest
19 namespace import -force ::tcltest::*
22 # Some tests require the testobj command
24 set ::tcltest::testConstraints(testobj) \
25 [expr {[info commands testobj] != {}}]
26 set ::tcltest::testConstraints(testindexobj) \
27 [expr {[info commands testindexobj] != {}}]
29 test string-1.1 {error conditions} {
30 list [catch {string gorp a b} msg] $msg
31 } {1 {bad option "gorp": must be bytelength, compare, equal, first, index, is, last, length, map, match, range, repeat, replace, tolower, toupper, totitle, trim, trimleft, trimright, wordend, or wordstart}}
32 test string-1.2 {error conditions} {
33 list [catch {string} msg] $msg
34 } {1 {wrong # args: should be "string option arg ?arg ...?"}}
36 test string-2.1 {string compare, too few args} {
37 list [catch {string compare a} msg] $msg
38 } {1 {wrong # args: should be "string compare ?-nocase? ?-length int? string1 string2"}}
39 test string-2.2 {string compare, bad args} {
40 list [catch {string compare a b c} msg] $msg
41 } {1 {bad option "a": must be -nocase or -length}}
42 test string-2.3 {string compare, bad args} {
43 list [catch {string compare -length -nocase str1 str2} msg] $msg
44 } {1 {expected integer but got "-nocase"}}
45 test string-2.4 {string compare, too many args} {
46 list [catch {string compare -length 10 -nocase str1 str2 str3} msg] $msg
47 } {1 {wrong # args: should be "string compare ?-nocase? ?-length int? string1 string2"}}
48 test string-2.5 {string compare with length unspecified} {
49 list [catch {string compare -length 10 10} msg] $msg
50 } {1 {wrong # args: should be "string compare ?-nocase? ?-length int? string1 string2"}}
51 test string-2.6 {string compare} {
52 string compare abcde abdef
54 test string-2.7 {string compare, shortest method name} {
57 test string-2.8 {string compare} {
58 string compare abcde abcde
60 test string-2.9 {string compare with length} {
61 string compare -length 2 abcde abxyz
63 test string-2.10 {string compare with special index} {
64 list [catch {string compare -length end-3 abcde abxyz} msg] $msg
65 } {1 {expected integer but got "end-3"}}
66 test string-2.11 {string compare, unicode} {
67 string compare ab\u7266 ab\u7267
69 test string-2.12 {string compare, high bit} {
70 # This test will fail if the underlying comparaison
71 # is using signed chars instead of unsigned chars.
72 # (like SunOS's default memcmp thus the compat/memcmp.c)
73 string compare "\x80" "@"
74 # Nb this tests works also in utf8 space because \x80 is
75 # translated into a 2 or more bytelength but whose first byte has
78 test string-2.13 {string compare -nocase} {
79 string compare -nocase abcde abdef
81 test string-2.14 {string compare -nocase} {
82 string c -nocase abcde ABCDE
84 test string-2.15 {string compare -nocase} {
85 string compare -nocase abcde abcde
87 test string-2.16 {string compare -nocase with length} {
88 string compare -length 2 -nocase abcde Abxyz
90 test string-2.17 {string compare -nocase with length} {
91 string compare -nocase -length 3 abcde Abxyz
93 test string-2.18 {string compare -nocase with length <= 0} {
94 string compare -nocase -length -1 abcde AbCdEf
96 test string-2.19 {string compare -nocase with excessive length} {
97 string compare -nocase -length 50 AbCdEf abcde
99 test string-2.20 {string compare -len unicode} {
100 # These are strings that are 6 BYTELENGTH long, but the length
101 # shouldn't make a different because there are actually 3 CHARS long
102 string compare -len 5 \334\334\334 \334\334\374
104 test string-2.21 {string compare -nocase with special index} {
105 list [catch {string compare -nocase -length end-3 Abcde abxyz} msg] $msg
106 } {1 {expected integer but got "end-3"}}
107 test string-2.22 {string compare, null strings} {
110 test string-2.23 {string compare, null strings} {
111 string compare "" foo
113 test string-2.24 {string compare, null strings} {
114 string compare foo ""
116 test string-2.25 {string compare -nocase, null strings} {
117 string compare -nocase "" ""
119 test string-2.26 {string compare -nocase, null strings} {
120 string compare -nocase "" foo
122 test string-2.27 {string compare -nocase, null strings} {
123 string compare -nocase foo ""
125 test string-2.28 {string compare with length, unequal strings} {
126 string compare -length 2 abc abde
128 test string-2.29 {string compare with length, unequal strings} {
129 string compare -length 2 ab abde
131 test string-2.30 {string compare with NUL character vs. other ASCII} {
132 # Be careful here, since UTF-8 rep comparison with memcmp() of
133 # these puts chars in the wrong order
134 string compare \x00 \x01
136 test string-2.31 {string compare, high bit} {
137 proc foo {} {string compare "a\x80" "a@"}
140 test string-2.32 {string compare, high bit} {
141 proc foo {} {string compare "a\x00" "a\x01"}
144 test string-2.33 {string compare, high bit} {
145 proc foo {} {string compare "\x00\x00" "\x00\x01"}
149 # only need a few tests on equal, since it uses the same code as
150 # string compare, but just modifies the return output
151 test string-3.1 {string equal} {
152 string equal abcde abdef
154 test string-3.2 {string equal} {
155 string eq abcde ABCDE
157 test string-3.3 {string equal} {
158 string equal abcde abcde
160 test string-3.4 {string equal -nocase} {
161 string equal -nocase \334\334\334\334\374\374\374\374 \334\334\334\334\334\334\334\334
163 test string-3.5 {string equal -nocase} {
164 string equal -nocase abcde abdef
166 test string-3.6 {string equal -nocase} {
167 string eq -nocase abcde ABCDE
169 test string-3.7 {string equal -nocase} {
170 string equal -nocase abcde abcde
172 test string-3.8 {string equal with length, unequal strings} {
173 string equal -length 2 abc abde
176 test string-4.1 {string first, too few args} {
177 list [catch {string first a} msg] $msg
178 } {1 {wrong # args: should be "string first subString string ?startIndex?"}}
179 test string-4.2 {string first, bad args} {
180 list [catch {string first a b c} msg] $msg
181 } {1 {bad index "c": must be integer or end?-integer?}}
182 test string-4.3 {string first, too many args} {
183 list [catch {string first a b 5 d} msg] $msg
184 } {1 {wrong # args: should be "string first subString string ?startIndex?"}}
185 test string-4.4 {string first} {
186 string first bq abcdefgbcefgbqrs
188 test string-4.5 {string first} {
189 string fir bcd abcdefgbcefgbqrs
191 test string-4.6 {string first} {
192 string f b abcdefgbcefgbqrs
194 test string-4.7 {string first} {
195 string first xxx x123xx345xxx789xxx012
197 test string-4.8 {string first} {
198 string first "" x123xx345xxx789xxx012
200 test string-4.9 {string first, unicode} {
201 string first x abc\u7266x
203 test string-4.10 {string first, unicode} {
204 string first \u7266 abc\u7266x
206 test string-4.11 {string first, start index} {
207 string first \u7266 abc\u7266x 3
209 test string-4.12 {string first, start index} {
210 string first \u7266 abc\u7266x 4
212 test string-4.13 {string first, start index} {
213 string first \u7266 abc\u7266x end-2
215 test string-4.14 {string first, negative start index} {
216 string first b abc -1
218 test string-4.15 {string first, ability to two-byte encoded utf-8 chars} {
219 # Test for a bug in Tcl 8.3 where test for all-single-byte-encoded
220 # strings was incorrect, leading to an index returned by [string first]
221 # which pointed past the end of the string.
222 set uchar \u057e ;# character with two-byte encoding in utf-8
223 string first % %#$uchar$uchar#$uchar$uchar#% 3
226 test string-5.1 {string index} {
227 list [catch {string index} msg] $msg
228 } {1 {wrong # args: should be "string index string charIndex"}}
229 test string-5.2 {string index} {
230 list [catch {string index a b c} msg] $msg
231 } {1 {wrong # args: should be "string index string charIndex"}}
232 test string-5.3 {string index} {
235 test string-5.4 {string index} {
238 test string-5.5 {string index} {
241 test string-5.6 {string index} {
242 list [catch {string index abcde -10} msg] $msg
244 test string-5.7 {string index} {
245 list [catch {string index a xyz} msg] $msg
246 } {1 {bad index "xyz": must be integer or end?-integer?}}
247 test string-5.8 {string index} {
250 test string-5.9 {string index} {
251 string index abc end-1
253 test string-5.10 {string index, unicode} {
254 string index abc\u7266d 4
256 test string-5.11 {string index, unicode} {
257 string index abc\u7266d 3
259 test string-5.12 {string index, unicode over char length, under byte length} {
260 string index \334\374\334\374 6
262 test string-5.13 {string index, bytearray object} {
263 string index [binary format a5 fuz] 0
265 test string-5.14 {string index, bytearray object} {
266 string index [binary format I* {0x50515253 0x52}] 3
268 test string-5.15 {string index, bytearray object} {
269 set b [binary format I* {0x50515253 0x52}]
270 set i1 [string index $b end-6]
271 set i2 [string index $b 1]
272 string compare $i1 $i2
274 test string-5.16 {string index, bytearray object with string obj shimmering} {
275 set str "0123456789\x00 abcdedfghi"
276 binary scan $str H* dump
277 string compare [string index $str 10] \x00
279 test string-5.17 {string index, bad integer} {
280 list [catch {string index "abc" 08} msg] $msg
281 } {1 {bad index "08": must be integer or end?-integer? (looks like invalid octal number)}}
282 test string-5.18 {string index, bad integer} {
283 list [catch {string index "abc" end-00289} msg] $msg
284 } {1 {bad index "end-00289": must be integer or end?-integer? (looks like invalid octal number)}}
285 test string-5.19 {string index, bytearray object out of bounds} {
286 string index [binary format I* {0x50515253 0x52}] -1
288 test string-5.20 {string index, bytearray object out of bounds} {
289 string index [binary format I* {0x50515253 0x52}] 20
293 proc largest_int {} {
294 # This will give us what the largest valid int on this machine is,
295 # so we can test for overflow properly below on >32 bit systems
297 set exp 7; # assume we get at least 8 bits
298 while {$int > 0} { set int [expr {wide(1) << [incr exp]}] }
299 return [expr {$int-1}]
302 test string-6.1 {string is, too few args} {
303 list [catch {string is} msg] $msg
304 } {1 {wrong # args: should be "string is class ?-strict? ?-failindex var? str"}}
305 test string-6.2 {string is, too few args} {
306 list [catch {string is alpha} msg] $msg
307 } {1 {wrong # args: should be "string is class ?-strict? ?-failindex var? str"}}
308 test string-6.3 {string is, bad args} {
309 list [catch {string is alpha -failin str} msg] $msg
310 } {1 {wrong # args: should be "string is alpha ?-strict? ?-failindex var? str"}}
311 test string-6.4 {string is, too many args} {
312 list [catch {string is alpha -failin var -strict str more} msg] $msg
313 } {1 {wrong # args: should be "string is class ?-strict? ?-failindex var? str"}}
314 test string-6.5 {string is, class check} {
315 list [catch {string is bogus str} msg] $msg
316 } {1 {bad class "bogus": must be alnum, alpha, ascii, control, boolean, digit, double, false, graph, integer, lower, print, punct, space, true, upper, wordchar, or xdigit}}
317 test string-6.6 {string is, ambiguous class} {
318 list [catch {string is al str} msg] $msg
319 } {1 {ambiguous class "al": must be alnum, alpha, ascii, control, boolean, digit, double, false, graph, integer, lower, print, punct, space, true, upper, wordchar, or xdigit}}
320 test string-6.7 {string is alpha, all ok} {
321 string is alpha -strict -failindex var abc
323 test string-6.8 {string is, error in var} {
324 list [string is alpha -failindex var abc5def] $var
326 test string-6.9 {string is, var shouldn't get set} {
328 list [catch {string is alpha -failindex var abc; set var} msg] $msg
329 } {1 {can't read "var": no such variable}}
330 test string-6.10 {string is, ok on empty} {
333 test string-6.11 {string is, -strict check against empty} {
334 string is alpha -strict {}
336 test string-6.12 {string is alnum, true} {
337 string is alnum abc123
339 test string-6.13 {string is alnum, false} {
340 list [string is alnum -failindex var abc1.23] $var
342 test string-6.14 {string is alnum, unicode} {
345 test string-6.15 {string is alpha, true} {
348 test string-6.16 {string is alpha, false} {
349 list [string is alpha -fail var a1bcde] $var
351 test string-6.17 {string is alpha, unicode} {
352 string is alpha abc\374
354 test string-6.18 {string is ascii, true} {
355 string is ascii abc\u007Fend
357 test string-6.19 {string is ascii, false} {
358 list [string is ascii -fail var abcdef\u0080more] $var
360 test string-6.20 {string is boolean, true} {
361 string is boolean true
363 test string-6.21 {string is boolean, true} {
366 test string-6.22 {string is boolean, true based on type} {
367 string is bool [string compare a a]
369 test string-6.23 {string is boolean, false} {
370 list [string is bool -fail var yada] $var
372 test string-6.24 {string is digit, true} {
373 string is digit 0123456789
375 test string-6.25 {string is digit, false} {
376 list [string is digit -fail var 0123Ü567] $var
378 test string-6.26 {string is digit, false} {
379 list [string is digit -fail var +123567] $var
381 test string-6.27 {string is double, true} {
384 test string-6.28 {string is double, true} {
385 string is double [expr double(1)]
387 test string-6.29 {string is double, true} {
390 test string-6.30 {string is double, true} {
391 string is double [string compare a a]
393 test string-6.31 {string is double, true} {
394 string is double " +1.0e-1 "
396 test string-6.32 {string is double, true} {
397 string is double "\n1.0\v"
399 test string-6.33 {string is double, false} {
400 list [string is double -fail var 1abc] $var
402 test string-6.34 {string is double, false} {
403 list [string is double -fail var abc] $var
405 test string-6.35 {string is double, false} {
406 list [string is double -fail var " 1.0e4e4 "] $var
408 test string-6.36 {string is double, false} {
409 list [string is double -fail var "\n"] $var
411 test string-6.37 {string is double, false on int overflow} {
412 # Make it the largest int recognizable, with one more digit for overflow
413 list [string is double -fail var [largest_int]0] $var
415 test string-6.38 {string is double, false on underflow} {
417 list [string is double -fail var 123e-9999] $var
419 test string-6.39 {string is double, false} {nonPortable} {
420 # This test is non-portable because IRIX thinks
421 # that .e1 is a valid double - this is really a bug
422 # on IRIX as .e1 should NOT be a valid double
424 list [string is double -fail var .e1] $var
426 test string-6.40 {string is false, true} {
427 string is false false
429 test string-6.41 {string is false, true} {
430 string is false FaLsE
432 test string-6.42 {string is false, true} {
435 test string-6.43 {string is false, true} {
438 test string-6.44 {string is false, true} {
441 test string-6.45 {string is false, false} {
442 list [string is false -fail var abc] $var
444 test string-6.46 {string is false, false} {
446 list [string is false -fail var Y] $var
448 test string-6.47 {string is false, false} {
450 list [string is false -fail var offensive] $var
452 test string-6.48 {string is integer, true} {
453 string is integer +1234567890
455 test string-6.49 {string is integer, true on type} {
456 string is integer [expr int(50.0)]
458 test string-6.50 {string is integer, true} {
459 string is integer [list -10]
461 test string-6.51 {string is integer, true as hex} {
462 string is integer 0xabcdef
464 test string-6.52 {string is integer, true as octal} {
465 string is integer 012345
467 test string-6.53 {string is integer, true with whitespace} {
468 string is integer " \n1234\v"
470 test string-6.54 {string is integer, false} {
471 list [string is integer -fail var 123abc] $var
473 test string-6.55 {string is integer, false on overflow} {
474 list [string is integer -fail var +[largest_int]0] $var
476 test string-6.56 {string is integer, false} {
477 list [string is integer -fail var [expr double(1)]] $var
479 test string-6.57 {string is integer, false} {
480 list [string is integer -fail var " "] $var
482 test string-6.58 {string is integer, false on bad octal} {
483 list [string is integer -fail var 036963] $var
485 test string-6.59 {string is integer, false on bad hex} {
486 list [string is integer -fail var 0X345XYZ] $var
488 test string-6.60 {string is lower, true} {
491 test string-6.61 {string is lower, unicode true} {
492 string is lower abcüue
494 test string-6.62 {string is lower, false} {
495 list [string is lower -fail var aBc] $var
497 test string-6.63 {string is lower, false} {
498 list [string is lower -fail var abc1] $var
500 test string-6.64 {string is lower, unicode false} {
501 list [string is lower -fail var abÜUE] $var
503 test string-6.65 {string is space, true} {
504 string is space " \t\n\v\f"
506 test string-6.66 {string is space, false} {
507 list [string is space -fail var " \t\n\v1\f"] $var
509 test string-6.67 {string is true, true} {
512 test string-6.68 {string is true, true} {
515 test string-6.69 {string is true, true} {
518 test string-6.70 {string is true, true} {
521 test string-6.71 {string is true, true} {
524 test string-6.72 {string is true, false} {
525 list [string is true -fail var onto] $var
527 test string-6.73 {string is true, false} {
529 list [string is true -fail var 25] $var
531 test string-6.74 {string is true, false} {
533 list [string is true -fail var no] $var
535 test string-6.75 {string is upper, true} {
538 test string-6.76 {string is upper, unicode true} {
539 string is upper ABCÜUE
541 test string-6.77 {string is upper, false} {
542 list [string is upper -fail var AbC] $var
544 test string-6.78 {string is upper, false} {
545 list [string is upper -fail var AB2C] $var
547 test string-6.79 {string is upper, unicode false} {
548 list [string is upper -fail var ABCüue] $var
550 test string-6.80 {string is wordchar, true} {
551 string is wordchar abc_123
553 test string-6.81 {string is wordchar, unicode true} {
554 string is wordchar abcüabÜAB\u5001
556 test string-6.82 {string is wordchar, false} {
557 list [string is wordchar -fail var abcd.ef] $var
559 test string-6.83 {string is wordchar, unicode false} {
560 list [string is wordchar -fail var abc\u0080def] $var
562 test string-6.84 {string is control} {
563 ## Control chars are in the ranges
565 list [string is control -fail var \x00\x01\x10\x1F\x7F\x80\x9F\x60] $var
567 test string-6.85 {string is control} {
568 string is control \u0100
570 test string-6.86 {string is graph} {
571 ## graph is any print char, except space
572 list [string is gra -fail var "0123abc!@#\$\u0100 "] $var
574 test string-6.87 {string is print} {
575 ## basically any printable char
576 list [string is print -fail var "0123abc!@#\$\u0100 \u0010"] $var
578 test string-6.88 {string is punct} {
579 ## any graph char that isn't alnum
580 list [string is punct -fail var "_!@#\u00beq0"] $var
582 test string-6.89 {string is xdigit} {
583 list [string is xdigit -fail var 0123456789\u0061bcdefABCDEFg] $var
586 test string-6.90 {string is integer, bad integers} {
589 set numbers [list 1 +1 ++1 +-1 -+1 -1 --1 "- +1"]
590 foreach num $numbers {
591 lappend result [string is int -strict $num]
595 test string-6.91 {string is double, bad doubles} {
597 set numbers [list 1.0 +1.0 ++1.0 +-1.0 -+1.0 -1.0 --1.0 "- +1.0"]
598 foreach num $numbers {
599 lappend result [string is double -strict $num]
603 test string-6.92 {string is double, 32-bit overflow} {
606 list [string is integer -failindex var $x] $var
608 test string-6.93 {string is double, 32-bit overflow} {
612 list [string is integer -failindex var $x] $var
614 test string-6.94 {string is double, 32-bit overflow} {
617 list [string is integer -failindex var [expr {$x}]] $var
620 catch {rename largest_int {}}
622 test string-7.1 {string last, too few args} {
623 list [catch {string last a} msg] $msg
624 } {1 {wrong # args: should be "string last subString string ?startIndex?"}}
625 test string-7.2 {string last, bad args} {
626 list [catch {string last a b c} msg] $msg
627 } {1 {bad index "c": must be integer or end?-integer?}}
628 test string-7.3 {string last, too many args} {
629 list [catch {string last a b c d} msg] $msg
630 } {1 {wrong # args: should be "string last subString string ?startIndex?"}}
631 test string-7.4 {string last} {
632 string la xxx xxxx123xx345x678
634 test string-7.5 {string last} {
635 string last xx xxxx123xx345x678
637 test string-7.6 {string last} {
638 string las x xxxx123xx345x678
640 test string-7.7 {string last, unicode} {
641 string las x xxxx12\u7266xx345x678
643 test string-7.8 {string last, unicode} {
644 string las \u7266 xxxx12\u7266xx345x678
646 test string-7.9 {string last, stop index} {
647 string las \u7266 xxxx12\u7266xx345x678
649 test string-7.10 {string last, unicode} {
650 string las \u7266 xxxx12\u7266xx345x678
652 test string-7.11 {string last, start index} {
653 string last \u7266 abc\u7266x 3
655 test string-7.12 {string last, start index} {
656 string last \u7266 abc\u7266x 2
658 test string-7.13 {string last, start index} {
659 ## Constrain to last 'a' should work
660 string last ba badbad end-1
662 test string-7.14 {string last, start index} {
663 ## Constrain to last 'b' should skip last 'ba'
664 string last ba badbad end-2
666 test string-7.15 {string last, start index} {
667 string last \334a \334ad\334ad 0
669 test string-7.16 {string last, start index} {
670 string last \334a \334ad\334ad end-1
673 test string-8.1 {string bytelength} {
674 list [catch {string bytelength} msg] $msg
675 } {1 {wrong # args: should be "string bytelength string"}}
676 test string-8.2 {string bytelength} {
677 list [catch {string bytelength a b} msg] $msg
678 } {1 {wrong # args: should be "string bytelength string"}}
679 test string-8.3 {string bytelength} {
680 string bytelength "\u00c7"
682 test string-8.4 {string bytelength} {
686 test string-9.1 {string length} {
687 list [catch {string length} msg] $msg
688 } {1 {wrong # args: should be "string length string"}}
689 test string-9.2 {string length} {
690 list [catch {string length a b} msg] $msg
691 } {1 {wrong # args: should be "string length string"}}
692 test string-9.3 {string length} {
693 string length "a little string"
695 test string-9.4 {string length} {
698 test string-9.5 {string length, unicode} {
699 string le "abcd\u7266"
701 test string-9.6 {string length, bytearray object} {
702 string length [binary format a5 foo]
704 test string-9.7 {string length, bytearray object} {
705 string length [binary format I* {0x50515253 0x52}]
708 test string-10.1 {string map, too few args} {
709 list [catch {string map} msg] $msg
710 } {1 {wrong # args: should be "string map ?-nocase? charMap string"}}
711 test string-10.2 {string map, bad args} {
712 list [catch {string map {a b} abba oops} msg] $msg
713 } {1 {bad option "a b": must be -nocase}}
714 test string-10.3 {string map, too many args} {
715 list [catch {string map -nocase {a b} str1 str2} msg] $msg
716 } {1 {wrong # args: should be "string map ?-nocase? charMap string"}}
717 test string-10.4 {string map} {
718 string map {a b} abba
720 test string-10.5 {string map} {
723 test string-10.6 {string map -nocase} {
724 string map -nocase {a b} Abba
726 test string-10.7 {string map} {
727 string map {abc 321 ab * a A} aabcabaababcab
729 test string-10.8 {string map -nocase} {
730 string map -nocase {aBc 321 Ab * a A} aabcabaababcab
732 test string-10.9 {string map -nocase} {
733 string map -no {abc 321 Ab * a A} aAbCaBaAbAbcAb
735 test string-10.10 {string map} {
736 list [catch {string map {a b c} abba} msg] $msg
737 } {1 {char map list unbalanced}}
738 test string-10.11 {string map, nulls} {
739 string map {\x00 NULL blah \x00nix} {qwerty}
741 test string-10.12 {string map, unicode} {
742 string map [list \374 ue UE \334] "a\374ueUE\000EU"
744 test string-10.13 {string map, -nocase unicode} {
745 string map -nocase [list \374 ue UE \334] "a\374ueUE\000EU"
747 test string-10.14 {string map, -nocase null arguments} {
748 string map -nocase {{} abc} foo
750 test string-10.15 {string map, one pair case} {
751 string map -nocase {abc 32} aAbCaBaAbAbcAb
753 test string-10.16 {string map, one pair case} {
754 string map -nocase {ab 4321} aAbCaBaAbAbcAb
755 } {a4321C4321a43214321c4321}
756 test string-10.17 {string map, one pair case} {
757 string map {Ab 4321} aAbCaBaAbAbcAb
758 } {a4321CaBa43214321c4321}
759 test string-10.18 {string map, empty argument} {
760 string map -nocase {{} abc} foo
762 test string-10.19 {string map, empty arguments} {
763 string map -nocase {{} abc f bar {} def} foo
765 test string-10.20 {string map, nasty sharing crash from [Bug 1018562]} {
769 test string-10.21 {string map, ABR checks} {
770 string map {longstring foob} long
772 test string-10.22 {string map, ABR checks} {
773 string map {long foob} long
775 test string-10.23 {string map, ABR checks} {
776 string map {lon foob} long
778 test string-10.24 {string map, ABR checks} {
779 string map {lon foob} longlo
781 test string-10.25 {string map, ABR checks} {
782 string map {lon foob} longlon
784 test string-10.26 {string map, ABR checks} {
785 string map {longstring foob longstring bar} long
787 test string-10.27 {string map, ABR checks} {
788 string map {long foob longstring bar} long
790 test string-10.28 {string map, ABR checks} {
791 string map {lon foob longstring bar} long
793 test string-10.29 {string map, ABR checks} {
794 string map {lon foob longstring bar} longlo
796 test string-10.30 {string map, ABR checks} {
797 string map {lon foob longstring bar} longlon
800 test string-11.1 {string match, too few args} {
801 list [catch {string match a} msg] $msg
802 } {1 {wrong # args: should be "string match ?-nocase? pattern string"}}
803 test string-11.2 {string match, too many args} {
804 list [catch {string match a b c d} msg] $msg
805 } {1 {wrong # args: should be "string match ?-nocase? pattern string"}}
806 test string-11.3 {string match} {
809 test string-11.4 {string match} {
812 test string-11.5 {string match} {
813 string match ab*c abc
815 test string-11.6 {string match} {
816 string match ab**c abc
818 test string-11.7 {string match} {
819 string match ab* abcdef
821 test string-11.8 {string match} {
824 test string-11.9 {string match} {
825 string match *3*6*9 0123456789
827 test string-11.10 {string match} {
828 string match *3*6*9 01234567890
830 test string-11.11 {string match} {
833 test string-11.12 {string match} {
834 string match a??c abc
836 test string-11.13 {string match} {
837 string match ?1??4???8? 0123456789
839 test string-11.14 {string match} {
840 string match {[abc]bc} abc
842 test string-11.15 {string match} {
843 string match {a[abc]c} abc
845 test string-11.16 {string match} {
846 string match {a[xyz]c} abc
848 test string-11.17 {string match} {
849 string match {12[2-7]45} 12345
851 test string-11.18 {string match} {
852 string match {12[ab2-4cd]45} 12345
854 test string-11.19 {string match} {
855 string match {12[ab2-4cd]45} 12b45
857 test string-11.20 {string match} {
858 string match {12[ab2-4cd]45} 12d45
860 test string-11.21 {string match} {
861 string match {12[ab2-4cd]45} 12145
863 test string-11.22 {string match} {
864 string match {12[ab2-4cd]45} 12545
866 test string-11.23 {string match} {
867 string match {a\*b} a*b
869 test string-11.24 {string match} {
870 string match {a\*b} ab
872 test string-11.25 {string match} {
873 string match {a\*\?\[\]\\\x} "a*?\[\]\\x"
875 test string-11.26 {string match} {
878 test string-11.27 {string match} {
881 test string-11.28 {string match} {
884 test string-11.29 {string match} {
887 test string-11.30 {string match, bad args} {
888 list [catch {string match - b c} msg] $msg
889 } {1 {bad option "-": must be -nocase}}
890 test string-11.31 {string match case} {
893 test string-11.32 {string match nocase} {
896 test string-11.33 {string match nocase} {
897 string match -nocase a\334 A\374
899 test string-11.34 {string match nocase} {
900 string match -nocase a*f ABCDEf
902 test string-11.35 {string match case, false hope} {
903 # This is true because '_' lies between the A-Z and a-z ranges
904 string match {[A-z]} _
906 test string-11.36 {string match nocase range} {
907 # This is false because although '_' lies between the A-Z and a-z ranges,
908 # we lower case the end points before checking the ranges.
909 string match -nocase {[A-z]} _
911 test string-11.37 {string match nocase} {
912 string match -nocase {[A-fh-Z]} g
914 test string-11.38 {string match case, reverse range} {
915 string match {[A-fh-Z]} g
917 test string-11.39 {string match, *\ case} {
918 string match {*\abc} abc
920 test string-11.40 {string match, *special case} {
921 string match {*[ab]} abc
923 test string-11.41 {string match, *special case} {
924 string match {*[ab]*} abc
926 test string-11.42 {string match, *special case} {
927 string match "*\\" "\\"
929 test string-11.43 {string match, *special case} {
930 string match "*\\\\" "\\"
932 test string-11.44 {string match, *special case} {
933 string match "*???" "12345"
935 test string-11.45 {string match, *special case} {
936 string match "*???" "12"
938 test string-11.46 {string match, *special case} {
939 string match "*\\*" "abc*"
941 test string-11.47 {string match, *special case} {
942 string match "*\\*" "*"
944 test string-11.48 {string match, *special case} {
945 string match "*\\*" "*abc"
947 test string-11.49 {string match, *special case} {
948 string match "?\\*" "a*"
950 test string-11.50 {string match, *special case} {
951 string match "\\" "\\"
953 test string-11.51 {string match; *, -nocase and UTF-8} {
954 string match -nocase [binary format I 717316707] \
955 [binary format I 2028036707]
957 test string-11.52 {string match, null char in string} {
960 foreach elem [list "\u0000@abc" "@abc" "\u0000@abc\u0000" "blahabcblah"] {
961 lappend out [string match $ptn $elem]
965 test string-11.53 {string match, null char in pattern} {
967 foreach {ptn elem} [list \
968 "*\u0000abc\u0000" "\u0000abc\u0000" \
969 "*\u0000abc\u0000" "\u0000abc\u0000ef" \
970 "*\u0000abc\u0000*" "\u0000abc\u0000ef" \
971 "*\u0000abc\u0000" "@\u0000abc\u0000ef" \
972 "*\u0000abc\u0000*" "@\u0000abc\u0000ef" \
974 lappend out [string match $ptn $elem]
978 test string-11.54 {string match, failure} {
980 for {set i 0} {$i < 10} {incr i} {
981 append longString "abcdefghijklmnopqrstuvwxy\u0000z01234567890123"
983 string first $longString 123
984 list [string match *cba* $longString] \
985 [string match *a*l*\u0000* $longString] \
986 [string match *a*l*\u0000*123 $longString] \
987 [string match *a*l*\u0000*123* $longString] \
988 [string match *a*l*\u0000*cba* $longString] \
989 [string match *===* $longString]
992 test string-12.1 {string range} {
993 list [catch {string range} msg] $msg
994 } {1 {wrong # args: should be "string range string first last"}}
995 test string-12.2 {string range} {
996 list [catch {string range a 1} msg] $msg
997 } {1 {wrong # args: should be "string range string first last"}}
998 test string-12.3 {string range} {
999 list [catch {string range a 1 2 3} msg] $msg
1000 } {1 {wrong # args: should be "string range string first last"}}
1001 test string-12.4 {string range} {
1002 string range abcdefghijklmnop 2 14
1004 test string-12.5 {string range, last > length} {
1005 string range abcdefghijklmnop 7 1000
1007 test string-12.6 {string range} {
1008 string range abcdefghijklmnop 10 e
1010 test string-12.7 {string range, last < first} {
1011 string range abcdefghijklmnop 10 9
1013 test string-12.8 {string range, first < 0} {
1014 string range abcdefghijklmnop -3 2
1016 test string-12.9 {string range} {
1017 string range abcdefghijklmnop -3 -2
1019 test string-12.10 {string range} {
1020 string range abcdefghijklmnop 1000 1010
1022 test string-12.11 {string range} {
1023 string range abcdefghijklmnop -100 end
1024 } {abcdefghijklmnop}
1025 test string-12.12 {string range} {
1026 list [catch {string range abc abc 1} msg] $msg
1027 } {1 {bad index "abc": must be integer or end?-integer?}}
1028 test string-12.13 {string range} {
1029 list [catch {string range abc 1 eof} msg] $msg
1030 } {1 {bad index "eof": must be integer or end?-integer?}}
1031 test string-12.14 {string range} {
1032 string range abcdefghijklmnop end-1 end
1034 test string-12.15 {string range} {
1035 string range abcdefghijklmnop e 1000
1037 test string-12.16 {string range} {
1038 string range abcdefghijklmnop end end-1
1040 test string-12.17 {string range, unicode} {
1041 string range ab\u7266cdefghijklmnop 5 5
1043 test string-12.18 {string range, unicode} {
1044 string range ab\u7266cdefghijklmnop 2 3
1046 test string-12.19 {string range, bytearray object} {
1047 set b [binary format I* {0x50515253 0x52}]
1048 set r1 [string range $b 1 end-1]
1049 set r2 [string range $b 1 6]
1050 string equal $r1 $r2
1052 test string-12.20 {string range, out of bounds indices} {
1053 string range \u00ff 0 1
1055 test string-12.21 {string range, regenerates correct reps, bug 1410553} {
1056 set bytes "\x00 \x03 \x41"
1060 if {$ch eq "\x03"} {
1061 string length $rxBuffer
1064 set rxCRC [string range $rxBuffer end-1 end]
1065 binary scan [join $bytes {}] "H*" input_hex
1066 binary scan $rxBuffer "H*" rxBuffer_hex
1067 binary scan $rxCRC "H*" rxCRC_hex
1068 list $input_hex $rxBuffer_hex $rxCRC_hex
1069 } {000341 000341 0341}
1071 test string-13.1 {string repeat} {
1072 list [catch {string repeat} msg] $msg
1073 } {1 {wrong # args: should be "string repeat string count"}}
1074 test string-13.2 {string repeat} {
1075 list [catch {string repeat abc 10 oops} msg] $msg
1076 } {1 {wrong # args: should be "string repeat string count"}}
1077 test string-13.3 {string repeat} {
1078 string repeat {} 100
1080 test string-13.4 {string repeat} {
1083 test string-13.5 {string repeat} {
1086 test string-13.6 {string repeat} {
1087 string repeat abc -1
1089 test string-13.7 {string repeat} {
1090 list [catch {string repeat abc end} msg] $msg
1091 } {1 {expected integer but got "end"}}
1092 test string-13.8 {string repeat} {
1093 string repeat {} -1000
1095 test string-13.9 {string repeat} {
1098 test string-13.10 {string repeat} {
1101 test string-13.11 {string repeat} {
1104 test string-13.12 {string repeat} {
1105 string repeat ab\u7266cd 3
1106 } ab\u7266cdab\u7266cdab\u7266cd
1107 test string-13.13 {string repeat} {
1108 string repeat \x00 3
1110 test string-13.14 {string repeat} {
1111 # The string range will ensure us that string repeat gets a unicode string
1112 string repeat [string range ab\u7266cd 2 3] 3
1113 } \u7266c\u7266c\u7266c
1115 test string-14.1 {string replace} {
1116 list [catch {string replace} msg] $msg
1117 } {1 {wrong # args: should be "string replace string first last ?string?"}}
1118 test string-14.2 {string replace} {
1119 list [catch {string replace a 1} msg] $msg
1120 } {1 {wrong # args: should be "string replace string first last ?string?"}}
1121 test string-14.3 {string replace} {
1122 list [catch {string replace a 1 2 3 4} msg] $msg
1123 } {1 {wrong # args: should be "string replace string first last ?string?"}}
1124 test string-14.4 {string replace} {
1126 test string-14.5 {string replace} {
1127 string replace abcdefghijklmnop 2 14
1129 test string-14.6 {string replace} {
1130 string replace abcdefghijklmnop 7 1000
1132 test string-14.7 {string replace} {
1133 string replace abcdefghijklmnop 10 e
1135 test string-14.8 {string replace} {
1136 string replace abcdefghijklmnop 10 9
1137 } {abcdefghijklmnop}
1138 test string-14.9 {string replace} {
1139 string replace abcdefghijklmnop -3 2
1141 test string-14.10 {string replace} {
1142 string replace abcdefghijklmnop -3 -2
1143 } {abcdefghijklmnop}
1144 test string-14.11 {string replace} {
1145 string replace abcdefghijklmnop 1000 1010
1146 } {abcdefghijklmnop}
1147 test string-14.12 {string replace} {
1148 string replace abcdefghijklmnop -100 end
1150 test string-14.13 {string replace} {
1151 list [catch {string replace abc abc 1} msg] $msg
1152 } {1 {bad index "abc": must be integer or end?-integer?}}
1153 test string-14.14 {string replace} {
1154 list [catch {string replace abc 1 eof} msg] $msg
1155 } {1 {bad index "eof": must be integer or end?-integer?}}
1156 test string-14.15 {string replace} {
1157 string replace abcdefghijklmnop end-10 end-2 NEW
1159 test string-14.16 {string replace} {
1160 string replace abcdefghijklmnop 0 e foo
1162 test string-14.17 {string replace} {
1163 string replace abcdefghijklmnop end end-1
1164 } {abcdefghijklmnop}
1166 test string-15.1 {string tolower too few args} {
1167 list [catch {string tolower} msg] $msg
1168 } {1 {wrong # args: should be "string tolower string ?first? ?last?"}}
1169 test string-15.2 {string tolower bad args} {
1170 list [catch {string tolower a b} msg] $msg
1171 } {1 {bad index "b": must be integer or end?-integer?}}
1172 test string-15.3 {string tolower too many args} {
1173 list [catch {string tolower ABC 1 end oops} msg] $msg
1174 } {1 {wrong # args: should be "string tolower string ?first? ?last?"}}
1175 test string-15.4 {string tolower} {
1176 string tolower ABCDeF
1178 test string-15.5 {string tolower} {
1179 string tolower "ABC XyZ"
1181 test string-15.6 {string tolower} {
1182 string tolower {123#$&*()}
1184 test string-15.7 {string tolower} {
1185 string tolower ABC 1
1187 test string-15.8 {string tolower} {
1188 string tolower ABC 1 end
1190 test string-15.9 {string tolower} {
1191 string tolower ABC 0 end-1
1193 test string-15.10 {string tolower, unicode} {
1194 string tolower ABCabc\xc7\xe7
1197 test string-16.1 {string toupper} {
1198 list [catch {string toupper} msg] $msg
1199 } {1 {wrong # args: should be "string toupper string ?first? ?last?"}}
1200 test string-16.2 {string toupper} {
1201 list [catch {string toupper a b} msg] $msg
1202 } {1 {bad index "b": must be integer or end?-integer?}}
1203 test string-16.3 {string toupper} {
1204 list [catch {string toupper a 1 end oops} msg] $msg
1205 } {1 {wrong # args: should be "string toupper string ?first? ?last?"}}
1206 test string-16.4 {string toupper} {
1207 string toupper abCDEf
1209 test string-16.5 {string toupper} {
1210 string toupper "abc xYz"
1212 test string-16.6 {string toupper} {
1213 string toupper {123#$&*()}
1215 test string-16.7 {string toupper} {
1216 string toupper abc 1
1218 test string-16.8 {string toupper} {
1219 string toupper abc 1 end
1221 test string-16.9 {string toupper} {
1222 string toupper abc 0 end-1
1224 test string-16.10 {string toupper, unicode} {
1225 string toupper ABCabc\xc7\xe7
1228 test string-17.1 {string totitle} {
1229 list [catch {string totitle} msg] $msg
1230 } {1 {wrong # args: should be "string totitle string ?first? ?last?"}}
1231 test string-17.2 {string totitle} {
1232 list [catch {string totitle a b} msg] $msg
1233 } {1 {bad index "b": must be integer or end?-integer?}}
1234 test string-17.3 {string totitle} {
1235 string totitle abCDEf
1237 test string-17.4 {string totitle} {
1238 string totitle "abc xYz"
1240 test string-17.5 {string totitle} {
1241 string totitle {123#$&*()}
1243 test string-17.6 {string totitle, unicode} {
1244 string totitle ABCabc\xc7\xe7
1246 test string-17.7 {string totitle, unicode} {
1247 string totitle \u01f3BCabc\xc7\xe7
1248 } "\u01f2bcabc\xe7\xe7"
1250 test string-18.1 {string trim} {
1251 list [catch {string trim} msg] $msg
1252 } {1 {wrong # args: should be "string trim string ?chars?"}}
1253 test string-18.2 {string trim} {
1254 list [catch {string trim a b c} msg] $msg
1255 } {1 {wrong # args: should be "string trim string ?chars?"}}
1256 test string-18.3 {string trim} {
1259 test string-18.4 {string trim} {
1260 string trim "\t\nXYZ\t\n\r\n"
1262 test string-18.5 {string trim} {
1263 string trim " A XYZ A "
1265 test string-18.6 {string trim} {
1266 string trim "XXYYZZABC XXYYZZ" ZYX
1268 test string-18.7 {string trim} {
1269 string trim " \t\r "
1271 test string-18.8 {string trim} {
1272 string trim {abcdefg} {}
1274 test string-18.9 {string trim} {
1277 test string-18.10 {string trim} {
1280 test string-18.11 {string trim, unicode} {
1281 string trim "\xe7\xe8 AB\xe7C \xe8\xe7" \xe7\xe8
1284 test string-19.1 {string trimleft} {
1285 list [catch {string trimleft} msg] $msg
1286 } {1 {wrong # args: should be "string trimleft string ?chars?"}}
1287 test string-19.2 {string trimleft} {
1288 string trimleft " XYZ "
1291 test string-20.1 {string trimright errors} {
1292 list [catch {string trimright} msg] $msg
1293 } {1 {wrong # args: should be "string trimright string ?chars?"}}
1294 test string-20.2 {string trimright errors} {
1295 list [catch {string trimg a} msg] $msg
1296 } {1 {bad option "trimg": must be bytelength, compare, equal, first, index, is, last, length, map, match, range, repeat, replace, tolower, toupper, totitle, trim, trimleft, trimright, wordend, or wordstart}}
1297 test string-20.3 {string trimright} {
1298 string trimright " XYZ "
1300 test string-20.4 {string trimright} {
1301 string trimright " "
1303 test string-20.5 {string trimright} {
1307 test string-21.1 {string wordend} {
1308 list [catch {string wordend a} msg] $msg
1309 } {1 {wrong # args: should be "string wordend string index"}}
1310 test string-21.2 {string wordend} {
1311 list [catch {string wordend a b c} msg] $msg
1312 } {1 {wrong # args: should be "string wordend string index"}}
1313 test string-21.3 {string wordend} {
1314 list [catch {string wordend a gorp} msg] $msg
1315 } {1 {bad index "gorp": must be integer or end?-integer?}}
1316 test string-21.4 {string wordend} {
1317 string wordend abc. -1
1319 test string-21.5 {string wordend} {
1320 string wordend abc. 100
1322 test string-21.6 {string wordend} {
1323 string wordend "word_one two three" 2
1325 test string-21.7 {string wordend} {
1326 string wordend "one .&# three" 5
1328 test string-21.8 {string wordend} {
1329 string worde "x.y" 0
1331 test string-21.9 {string wordend} {
1332 string worde "x.y" end-1
1334 test string-21.10 {string wordend, unicode} {
1335 string wordend "xyz\u00c7de fg" 0
1337 test string-21.11 {string wordend, unicode} {
1338 string wordend "xyz\uc700de fg" 0
1340 test string-21.12 {string wordend, unicode} {
1341 string wordend "xyz\u203fde fg" 0
1343 test string-21.13 {string wordend, unicode} {
1344 string wordend "xyz\u2045de fg" 0
1346 test string-21.14 {string wordend, unicode} {
1347 string wordend "\uc700\uc700 abc" 8
1350 test string-22.1 {string wordstart} {
1351 list [catch {string word a} msg] $msg
1352 } {1 {ambiguous option "word": must be bytelength, compare, equal, first, index, is, last, length, map, match, range, repeat, replace, tolower, toupper, totitle, trim, trimleft, trimright, wordend, or wordstart}}
1353 test string-22.2 {string wordstart} {
1354 list [catch {string wordstart a} msg] $msg
1355 } {1 {wrong # args: should be "string wordstart string index"}}
1356 test string-22.3 {string wordstart} {
1357 list [catch {string wordstart a b c} msg] $msg
1358 } {1 {wrong # args: should be "string wordstart string index"}}
1359 test string-22.4 {string wordstart} {
1360 list [catch {string wordstart a gorp} msg] $msg
1361 } {1 {bad index "gorp": must be integer or end?-integer?}}
1362 test string-22.5 {string wordstart} {
1363 string wordstart "one two three_words" 400
1365 test string-22.6 {string wordstart} {
1366 string wordstart "one two three_words" 2
1368 test string-22.7 {string wordstart} {
1369 string wordstart "one two three_words" -2
1371 test string-22.8 {string wordstart} {
1372 string wordstart "one .*&^ three" 6
1374 test string-22.9 {string wordstart} {
1375 string wordstart "one two three" 4
1377 test string-22.10 {string wordstart} {
1378 string wordstart "one two three" end-5
1380 test string-22.11 {string wordstart, unicode} {
1381 string wordstart "one tw\u00c7o three" 7
1383 test string-22.12 {string wordstart, unicode} {
1384 string wordstart "ab\uc700\uc700 cdef ghi" 12
1386 test string-22.13 {string wordstart, unicode} {
1387 string wordstart "\uc700\uc700 abc" 8
1390 test string-23.0 {string is boolean, Bug 1187123} testindexobj {
1392 catch {testindexobj $x foo bar soom}
1393 string is boolean $x
1398 ::tcltest::cleanupTests