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.
11 # See the file "license.terms" for information on usage and redistribution
12 # of this file, and for a DISCLAIMER OF ALL WARRANTIES.
14 # RCS: @(#) $Id: string.test,v 1.23.2.1 2001/04/03 22:54:38 hobbs Exp $
16 source [file dirname [info script]]/testing.tcl
18 # Some tests require the testobj command
20 test string-1.1 {error conditions} {
21 list [catch {string gorp a b} msg]
23 test string-1.2 {error conditions} {
24 list [catch {string} msg]
27 test string-2.1 {string compare, too few args} {
28 list [catch {string compare a} msg]
30 test string-2.2 {string compare, bad args} {
31 list [catch {string compare a b c} msg]
33 test string-2.3 {string compare, bad args} {
34 list [catch {string compare -length -nocase str1 str2} msg]
36 test string-2.4 {string compare, too many args} {
37 list [catch {string compare -length 10 -nocase str1 str2 str3} msg]
39 test string-2.5 {string compare with length unspecified} {
40 list [catch {string compare -length 10 10} msg]
42 test string-2.6 {string compare} {
43 string compare abcde abdef
45 test string-2.7 {string compare, shortest method name} {
48 test string-2.8 {string compare} {
49 string compare abcde abcde
51 test string-2.9 {string compare with length} {
52 string compare -length 2 abcde abxyz
54 test string-2.10 {string compare with special index} {
55 list [catch {string compare -length end-3 abcde abxyz} msg]
57 test string-2.12 {string compare, high bit} {
58 # This test will fail if the underlying comparaison
59 # is using signed chars instead of unsigned chars.
60 # (like SunOS's default memcmp thus the compat/memcmp.c)
61 string compare "\x80" "@"
62 # Nb this tests works also in utf8 space because \x80 is
63 # translated into a 2 or more bytelength but whose first byte has
66 test string-2.13 {string compare -nocase} {
67 string compare -nocase abcde abdef
69 test string-2.14 {string compare -nocase} {
70 string co -nocase abcde ABCDE
72 test string-2.15 {string compare -nocase} {
73 string compare -nocase abcde abcde
75 test string-2.16 {string compare -nocase with length} {
76 string compare -length 2 -nocase abcde Abxyz
78 test string-2.17 {string compare -nocase with length} {
79 string compare -nocase -length 3 abcde Abxyz
81 test string-2.18 {string compare -nocase with length <= 0} {
82 string compare -nocase -length -1 abcde AbCdEf
84 test string-2.19 {string compare -nocase with excessive length} {
85 string compare -nocase -length 50 AbCdEf abcde
87 test string-2.20 {string compare -len unicode} {
88 # These are strings that are 6 BYTELENGTH long, but the length
89 # shouldn't make a different because there are actually 3 CHARS long
90 string compare -len 5 \334\334\334 \334\334\374
92 test string-2.21 {string compare -nocase with special index} {
93 list [catch {string compare -nocase -length end-3 Abcde abxyz} msg]
95 test string-2.22 {string compare, null strings} {
98 test string-2.23 {string compare, null strings} {
101 test string-2.24 {string compare, null strings} {
102 string compare foo ""
104 test string-2.25 {string compare -nocase, null strings} {
105 string compare -nocase "" ""
107 test string-2.26 {string compare -nocase, null strings} {
108 string compare -nocase "" foo
110 test string-2.27 {string compare -nocase, null strings} {
111 string compare -nocase foo ""
113 test string-2.28 {string equal with length, unequal strings} {
114 string compare -length 2 abc abde
116 test string-2.29 {string equal with length, unequal strings} {
117 string compare -length 2 ab abde
119 test string-2.30 {string compare - bytes vs chars} {
120 string compare abcd\u1000\u1100\u1200x abcd\u1000\u1100\u1200y
122 test string-2.31 {string compare - embedded nulls} {
123 string compare ab\0ghi0 ab\0ghi1
125 test string-2.31 {string compare - embedded nulls, nocase} {
126 string compare -nocase ab\0ghi0 AB\0GHi1
128 # only need a few tests on equal, since it uses the same code as
129 # string compare, but just modifies the return output
130 test string-3.1 {string equal} {
131 string equal abcde abdef
133 test string-3.2 {string equal} {
134 string eq abcde ABCDE
136 test string-3.3 {string equal} {
137 string equal abcde abcde
139 test string-3.4 {string equal -nocase} utf8 {
140 string equal -nocase \u00dc\u00dc\u00dc\u00dc\u00fc\u00fc\u00fc\u00fc \u00dc\u00dc\u00dc\u00dc\u00dc\u00dc\u00dc\u00dc
142 test string-3.5 {string equal -nocase} {
143 string equal -nocase abcde abdef
145 test string-3.6 {string equal -nocase} {
146 string eq -nocase abcde ABCDE
148 test string-3.7 {string equal -nocase} {
149 string equal -nocase abcde abcde
151 test string-3.8 {string equal with length, unequal strings} {
152 string equal -length 2 abc abde
154 test string-4.1 {string first, too few args} {
155 list [catch {string first a} msg]
157 test string-4.2 {string first, bad args} {
158 list [catch {string first a b c} msg]
160 test string-4.3 {string first, too many args} {
161 list [catch {string first a b 5 d} msg]
163 test string-4.4 {string first} {
164 string first bq abcdefgbcefgbqrs
166 test string-4.5 {string first} {
167 string fir bcd abcdefgbcefgbqrs
169 test string-4.6 {string first} {
170 string f b abcdefgbcefgbqrs
172 test string-4.7 {string first} {
173 string first xxx x123xx345xxx789xxx012
175 test string-4.8 {string first} {
176 string first "" x123xx345xxx789xxx012
178 test string-4.14 {string first, start index} {
179 string first a abcabc end-4
181 test string-4.15 {string first, empty needle} {
184 test string-4.16 {string first, empty haystack} {
187 test string-4.17 {string first, needle bigger than haystack} {
190 test string-4.18 {string first, negative index} {
191 string first a aaa -4
193 test string-4.19 {string first, not found} {
197 test string-5.1 {string index} {
198 list [catch {string index} msg]
200 test string-5.2 {string index} {
201 list [catch {string index a b c} msg]
203 test string-5.3 {string index} {
206 test string-5.4 {string index} {
209 test string-5.5 {string index} {
212 test string-5.6 {string index} {
213 list [catch {string index abcde -10} msg]
215 test string-5.7 {string index} {
216 list [catch {string index a xyz} msg]
218 test string-5.8 {string index} {
221 test string-5.9 {string index} {
222 string index abc end-1
224 test string-5.17 {string index, bad integer} tcl {
225 list [catch {string index "abc" 08} msg]
227 test string-5.18 {string index, bad integer} tcl {
228 list [catch {string index "abc" end-00289} msg]
230 test string-6.1 {string is, too few args} jim {
231 list [catch {string is} msg] $msg
232 } {1 {wrong # args: should be "string is class ?-strict? str"}}
233 test string-6.2 {string is, too few args} jim {
234 list [catch {string is alpha} msg] $msg
235 } {1 {wrong # args: should be "string is class ?-strict? str"}}
236 test string-6.3 {string is, bad args} jim {
237 list [catch {string is alpha -failin str} msg] $msg
238 } {1 {wrong # args: should be "string is class ?-strict? str"}}
239 test string-6.4 {string is, too many args} jim {
240 list [catch {string is alpha -failin var -strict str more} msg] $msg
241 } {1 {wrong # args: should be "string is class ?-strict? str"}}
242 test string-6.5 {string is, class check} jim {
243 list [catch {string is bogus str} msg] $msg
244 } {1 {bad class "bogus": must be alnum, alpha, ascii, boolean, control, digit, double, graph, integer, lower, print, punct, space, upper, or xdigit}}
245 test string-6.6 {string is, ambiguous class} jim {
246 list [catch {string is al str} msg] $msg
247 } {1 {ambiguous class "al": must be alnum, alpha, ascii, boolean, control, digit, double, graph, integer, lower, print, punct, space, upper, or xdigit}}
248 test string-6.10 {string is, ok on empty} {
251 test string-6.11 {string is, -strict check against empty} {
252 string is alpha -strict {}
254 test string-6.12 {string is alnum, true} {
255 string is alnum abc123
257 test string-6.15 {string is alpha, true} {
260 test string-6.16 {string is ascii, true} {
261 string is ascii abc123
263 test string-6.17 {string is ascii, false} {
264 string is ascii 0123Ü567
266 test string-6.24 {string is digit, true} {
267 string is digit 0123456789
269 test string-6.25 {string is digit, false} {
270 list [string is digit 0123Ü567]
272 test string-6.26 {string is digit, false} {
273 list [string is digit +123567]
275 test string-6.27 {string is double, true} {
278 test string-6.28 {string is double, true} {
279 string is double [expr double(1)]
281 test string-6.29 {string is double, true} {
284 test string-6.30 {string is double, true} {
285 string is double [string compare a a]
287 test string-6.31 {string is double, true} {
288 string is double " +1.0e-1 "
290 test string-6.32 {string is double, true} {
291 string is double "\n1.0\v"
293 test string-6.33 {string is double, false} {
294 list [string is double 1abc]
296 test string-6.34 {string is double, false} {
297 list [string is double abc]
299 test string-6.35 {string is double, false} {
300 list [string is double " 1.0e4e4 "]
302 test string-6.36 {string is double, false} {
303 list [string is double "\n"]
305 test string-6.38 {string is double, false on underflow} jim {
306 list [string is double 123e-9999]
308 test string-6.39 {string is double, false} {
309 # This test is non-portable because IRIX thinks
310 # that .e1 is a valid double - this is really a bug
311 # on IRIX as .e1 should NOT be a valid double
313 list [string is double .e1]
315 test string-6.48 {string is integer, true} {
316 string is integer +1234567890
318 test string-6.49 {string is integer, true on type} {
319 string is integer [expr int(50.0)]
321 test string-6.50 {string is integer, true} {
322 string is integer [list -10]
324 test string-6.51 {string is integer, true as hex} {
325 string is integer 0xabcdef
327 test string-6.52 {string is integer, true as octal} {
328 string is integer 012345
330 test string-6.53 {string is integer, true with whitespace} {
331 string is integer " \n1234\v"
333 test string-6.54 {string is integer, false} {
334 list [string is integer 123abc]
336 test string-6.56 {string is integer, false} {
337 list [string is integer [expr double(1)]]
339 test string-6.57 {string is integer, false} {
340 list [string is integer " "]
342 test string-6.58 {string is integer, false on bad octal} jim {
343 list [string is integer 036963]
345 test string-6.59 {string is integer, false on bad octal} tcl {
346 list [string is integer 036963]
348 test string-6.60 {string is integer, false on bad hex} {
349 list [string is integer 0X345XYZ]
351 test string-6.61 {string is lower, true} {
354 test string-6.62 {string is lower, false} {
355 list [string is lower aBc]
357 test string-6.63 {string is lower, false} {
358 list [string is lower abc1]
360 test string-6.64 {string is lower, unicode false} {
361 list [string is lower abÜUE]
363 test string-6.65 {string is space, true} {
364 string is space " \t\n\v\f"
366 test string-6.66 {string is space, false} {
367 list [string is space " \t\n\v1\f"]
369 test string-6.75 {string is upper, true} {
372 test string-6.77 {string is upper, false} {
373 list [string is upper AbC]
375 test string-6.78 {string is upper, false} {
376 list [string is upper AB2C]
378 test string-6.84 {string is control} {
379 ## Control chars are in the ranges
381 list [string is control \x00\x01\x10\x1F\x7F\x80\x9F\x60]
383 test string-6.85 {string is control} tcl {
384 string is control \u0100
386 test string-6.86 {string is graph} {
387 ## graph is any print char, except space
388 list [string is gra "0123abc!@#\$ "]
390 test string-6.87 {string is print} {
391 ## basically any printable char
392 list [string is print "0123abc!@#\$ \010"]
394 test string-6.88 {string is punct} {
395 ## any graph char that isn't alnum
396 list [string is punct "_!@#\000beq0"]
398 test string-6.89 {string is xdigit} {
399 list [string is xdigit 0123456789\u0061bcdefABCDEFg]
401 test string-6.90 {string is boolean, true} {
402 list [string is boolean 0]
404 test string-6.91 {string is boolean, true} {
405 list [string is boolean false]
407 test string-6.92 {string is boolean, true} {
408 list [string is boolean no]
410 test string-6.93 {string is boolean, true} {
411 list [string is boolean off]
413 test string-6.94 {string is boolean, true} {
414 list [string is boolean 1]
416 test string-6.95 {string is boolean, true} {
417 list [string is boolean true]
419 test string-6.96 {string is boolean, true} {
420 list [string is boolean yes]
422 test string-6.97 {string is boolean, true} {
423 list [string is boolean on]
425 test string-6.98 {string is boolean, not boolean string, false} {
426 list [string is boolean a]
428 test string-6.99 {string is boolean, special character, false} {
429 list [string is boolean -]
431 test string-6.10 {string is boolean, mixed case, false} {
432 list [string is boolean True]
434 test string-7.1 {string last, too few args} {
435 list [catch {string last a} msg]
437 test string-7.2 {string last, bad args} {
438 list [catch {string last a b c} msg]
440 test string-7.3 {string last, too many args} {
441 list [catch {string last a b c d} msg]
443 test string-7.4 {string last} {
444 string la xxx xxxx123xx345x678
446 test string-7.5 {string last} {
447 string last xx xxxx123xx345x678
449 test string-7.6 {string last} {
450 string las x xxxx123xx345x678
452 test string-7.7 {string last, bad index} {
453 string last ba badbad -1
455 test string-7.13 {string last, start index} {
456 ## Constrain to last 'a' should work
457 string last ba badbad end-1
459 test string-7.14 {string last, start index} {
460 ## Constrain to last 'b' should skip last 'ba'
461 string last ba badbad end-2
463 test string-7.15 {string last, start index} {
464 string last \u00dca \u00dcad\u00dcad 0
466 test string-7.16 {string last, start index} utf8 {
467 string last \u00dca \u00dcad\u00dcad end-1
469 test string-7.17 {string last, too few args} {
472 test string-9.1 {string length} {
473 list [catch {string length} msg]
475 test string-9.2 {string length} {
476 list [catch {string length a b} msg]
478 test string-9.3 {string length} {
479 string length "a little string"
481 test string-9.4 {string length} {
485 test string-10.1 {string map, too few args} {
486 list [catch {string map} msg]
488 test string-10.2 {string map, bad args} {
489 list [catch {string map {a b} abba oops} msg]
491 test string-10.3 {string map, too many args} {
492 list [catch {string map -nocase {a b} str1 str2} msg]
494 test string-10.4 {string map} {
495 string map {a b} abba
497 test string-10.5 {string map} {
500 test string-10.6 {string map -nocase} {
501 string map -nocase {a b} Abba
503 test string-10.7 {string map} {
504 string map {abc 321 ab * a A} aabcabaababcab
506 test string-10.8 {string map -nocase} {
507 string map -nocase {aBc 321 Ab * a A} aabcabaababcab
509 test string-10.9 {string map -nocase} {
510 string map -no {abc 321 Ab * a A} aAbCaBaAbAbcAb
512 test string-10.10 {string map} {
513 list [catch {string map {a b c} abba} msg]
515 test string-10.11 {string map, nulls} {
516 string map {\x00 NULL blah \x00nix} {qwerty}
518 test string-10.12 {string map, unicode} {
519 string map [list \u00fc ue UE \u00dc] "a\u00fcueUE\000EU"
521 test string-10.13 {string map, -nocase unicode} {
522 string map -nocase [list \u00fc ue UE \u00dc] "a\u00fcueUE\000EU"
523 } aue\u00dc\u00dc\0EU
524 test string-10.14 {string map, -nocase null arguments} {
525 string map -nocase {{} abc} foo
527 test string-10.15 {string map, one pair case} {
528 string map -nocase {abc 32} aAbCaBaAbAbcAb
530 test string-10.16 {string map, one pair case} {
531 string map -nocase {ab 4321} aAbCaBaAbAbcAb
532 } {a4321C4321a43214321c4321}
533 test string-10.17 {string map, one pair case} {
534 string map {Ab 4321} aAbCaBaAbAbcAb
535 } {a4321CaBa43214321c4321}
536 test string-10.18 {string map, nulls in string} {
537 string map {a bc} ade\0ghia\0jkl
539 test string-10.19 {string map, nulls in map source} {
540 string map {\0 bc} ade\0ghia\0jkl
542 test string-10.20 {string map, nulls in map dest} {
543 string map {a A\0A} adeghiajkl
545 test string-10.21 {string map, null bytes} {
546 string map "\u0000afternull #" foo\u0000afternull\u0000123456789bar
547 } foo#\u0000123456789bar
549 test string-11.1 {string match, too few args} {
550 list [catch {string match a} msg]
552 test string-11.2 {string match, too many args} {
553 list [catch {string match a b c d} msg]
555 test string-11.3 {string match} {
558 test string-11.4 {string match} {
561 test string-11.5 {string match} {
562 string match ab*c abc
564 test string-11.6 {string match} {
565 string match ab**c abc
567 test string-11.7 {string match} {
568 string match ab* abcdef
570 test string-11.8 {string match} {
573 test string-11.9 {string match} {
574 string match *3*6*9 0123456789
576 test string-11.10 {string match} {
577 string match *3*6*9 01234567890
579 test string-11.11 {string match} {
582 test string-11.12 {string match} {
583 string match a??c abc
585 test string-11.13 {string match} {
586 string match ?1??4???8? 0123456789
588 test string-11.14 {string match} {
589 string match {[abc]bc} abc
591 test string-11.15 {string match} {
592 string match {a[abc]c} abc
594 test string-11.16 {string match} {
595 string match {a[xyz]c} abc
597 test string-11.17 {string match} {
598 string match {12[2-7]45} 12345
600 test string-11.18 {string match} {
601 string match {12[ab2-4cd]45} 12345
603 test string-11.19 {string match} {
604 string match {12[ab2-4cd]45} 12b45
606 test string-11.20 {string match} {
607 string match {12[ab2-4cd]45} 12d45
609 test string-11.21 {string match} {
610 string match {12[ab2-4cd]45} 12145
612 test string-11.22 {string match} {
613 string match {12[ab2-4cd]45} 12545
615 test string-11.23 {string match} {
616 string match {a\*b} a*b
618 test string-11.24 {string match} {
619 string match {a\*b} ab
621 test string-11.25 {string match} {
622 string match {a\*\?\[\]\\\x} "a*?\[\]\\x"
624 test string-11.26 {string match} {
627 test string-11.27 {string match} {
630 test string-11.28 {string match} {
633 test string-11.29 {string match} {
636 test string-11.30 {string match, bad args} {
637 list [catch {string match - b c} msg]
639 test string-11.31 {string match case} {
642 test string-11.32 {string match nocase} {
643 string match -nocase a A
645 test string-11.34 {string match nocase} {
646 string match -nocase a*f ABCDEf
648 test string-11.35 {string match case, false hope} {
649 # This is true because '_' lies between the A-Z and a-z ranges
650 string match {[A-z]} _
652 test string-11.36 {string match nocase range} {
653 # This is false because although '_' lies between the A-Z and a-z ranges,
654 # we lower case the end points before checking the ranges.
655 string match -nocase {[A-z]} _
657 test string-11.37 {string match nocase} {
658 string match -nocase {[A-fh-Z]} g
660 test string-11.38 {string match case, reverse range} {
661 string match {[A-fh-Z]} g
663 test string-11.39 {string match, *\ case} {
664 string match {*\abc} abc
666 test string-11.40 {string match, *special case} {
667 string match {*[ab]} abc
669 test string-11.41 {string match, *special case} {
670 string match {*[ab]*} abc
672 # I don't see why this shouldn't match. Ignored for jim
673 test string-11.42 {string match, *special case} tcl {
674 string match "*\\" "\\"
676 test string-11.43 {string match, *special case} {
677 string match "*\\\\" "\\"
679 test string-11.44 {string match, *special case} {
680 string match "*???" "12345"
682 test string-11.45 {string match, *special case} {
683 string match "*???" "12"
685 test string-11.46 {string match, *special case} {
686 string match "*\\*" "abc*"
688 test string-11.47 {string match, *special case} {
689 string match "*\\*" "*"
691 test string-11.48 {string match, *special case} {
692 string match "*\\*" "*abc"
694 test string-11.49 {string match, *special case} {
695 string match "?\\*" "a*"
697 # I don't see why this shouldn't match. Ignored for jim
698 test string-11.50 {string match, *special case} tcl {
699 string match "\\" "\\"
702 test string-11.51 {string match, nulls in pattern} {
703 string match "abc\0def" "abc\0def"
706 test string-11.52 {string match, nulls in pattern} {
707 string match "abc*\0def" "abcghi\0def"
710 test string-11.53 {string match, nulls in pattern} {
711 string match "abc\[ghi\0]def" "abc\0def"
714 test string-12.1 {string range} {
715 list [catch {string range} msg]
717 test string-12.2 {string range} {
718 list [catch {string range a 1} msg]
720 test string-12.3 {string range} {
721 list [catch {string range a 1 2 3} msg]
723 test string-12.4 {string range} {
724 string range abcdefghijklmnop 2 14
726 test string-12.5 {string range, last > length} {
727 string range abcdefghijklmnop 7 1000
729 test string-12.6 {string range} {
730 string range abcdefghijklmnop 10 end
732 test string-12.7 {string range, last < first} {
733 string range abcdefghijklmnop 10 9
735 test string-12.8 {string range, first < 0} {
736 string range abcdefghijklmnop -3 2
738 test string-12.9 {string range} {
739 string range abcdefghijklmnop -3 -2
741 test string-12.10 {string range} {
742 string range abcdefghijklmnop 1000 1010
744 test string-12.11 {string range} {
745 string range abcdefghijklmnop -100 end
747 test string-12.12 {string range} {
748 list [catch {string range abc abc 1} msg]
750 test string-12.13 {string range} {
751 list [catch {string range abc 1 eof} msg]
753 test string-12.14 {string range} {
754 string range abcdefghijklmnop end-1 end
756 test string-12.15 {string range} {
757 string range abcdefghijklmnop end 1000
759 test string-12.16 {string range} {
760 string range abcdefghijklmnop end end-1
763 test string-13.1 {string repeat} {
764 list [catch {string repeat} msg]
766 test string-13.2 {string repeat} {
767 list [catch {string repeat abc 10 oops} msg]
769 test string-13.3 {string repeat} {
772 test string-13.4 {string repeat} {
775 test string-13.5 {string repeat} {
778 test string-13.6 {string repeat} {
781 test string-13.7 {string repeat} {
782 list [catch {string repeat abc end} msg]
784 test string-13.8 {string repeat} {
785 string repeat {} -1000
787 test string-13.9 {string repeat} {
790 test string-13.10 {string repeat} {
793 test string-13.11 {string repeat} {
796 test string-13.12 {string repeat} {
797 string repeat ab\u7266cd 3
798 } ab\u7266cdab\u7266cdab\u7266cd
799 test string-13.13 {string repeat} {
803 test string-14.1 {string replace} {
804 list [catch {string replace} msg] $msg
805 } {1 {wrong # args: should be "string replace string first last ?string?"}}
806 test string-14.2 {string replace} {
807 list [catch {string replace a 1} msg] $msg
808 } {1 {wrong # args: should be "string replace string first last ?string?"}}
809 test string-14.3 {string replace} {
810 list [catch {string replace a 1 2 3 4} msg] $msg
811 } {1 {wrong # args: should be "string replace string first last ?string?"}}
812 test string-14.4 {string replace} {
814 test string-14.5 {string replace} {
815 string replace abcdefghijklmnop 2 14
817 test string-14.6 {string replace} {
818 string replace abcdefghijklmnop 7 1000
820 test string-14.7 {string replace} {
821 string replace abcdefghijklmnop 10 end
823 test string-14.8 {string replace} {
824 string replace abcdefghijklmnop 10 9
826 test string-14.9 {string replace} {
827 string replace abcdefghijklmnop -3 2
829 test string-14.10 {string replace} {
830 string replace abcdefghijklmnop -3 -2
832 test string-14.11 {string replace} {
833 string replace abcdefghijklmnop 1000 1010
835 test string-14.12 {string replace} {
836 string replace abcdefghijklmnop -100 end
838 test string-14.13 {string replace} {
839 list [catch {string replace abc abc 1} msg] $msg
840 } {1 {bad index "abc": must be integer?[+-]integer? or end?[+-]integer?}}
841 test string-14.14 {string replace} {
842 list [catch {string replace abc 1 eof} msg] $msg
843 } {1 {bad index "eof": must be integer?[+-]integer? or end?[+-]integer?}}
844 test string-14.15 {string replace} {
845 string replace abcdefghijklmnop end-10 end-2 NEW
847 test string-14.16 {string replace} {
848 string replace abcdefghijklmnop 0 end foo
850 test string-14.17 {string replace} {
851 string replace abcdefghijklmnop end end-1
854 test string-15.1 {string tolower too few args} {
855 list [catch {string tolower} msg]
857 test string-15.2 {string tolower bad args} {
858 list [catch {string tolower a b} msg]
860 test string-15.3 {string tolower too many args} {
861 list [catch {string tolower ABC 1 end oops} msg]
863 test string-15.4 {string tolower} {
864 string tolower ABCDeF
866 test string-15.5 {string tolower} {
867 string tolower "ABC XyZ"
869 test string-15.6 {string tolower} {
870 string tolower {123#$&*()}
873 test string-16.1 {string toupper} {
874 list [catch {string toupper} msg]
876 test string-16.2 {string toupper} {
877 list [catch {string toupper a b} msg]
879 test string-16.4 {string toupper} {
880 string toupper abCDEf
882 test string-16.5 {string toupper} {
883 string toupper "abc xYz"
885 test string-16.6 {string toupper} {
886 string toupper {123#$&*()}
889 test string-17.1 {string totitle} -body {
891 } -returnCodes error -match glob -result {wrong # args: should be "string totitle string*}
892 test string-17.3 {string totitle} {
893 string totitle abCDEf
895 test string-17.4 {string totitle} {
896 string totitle "abc xYz"
898 test string-17.5 {string totitle} {
899 string totitle {123#$&*()}
902 test string-18.1 {string trim} {
903 list [catch {string trim} msg]
905 test string-18.2 {string trim} {
906 list [catch {string trim a b c} msg]
908 test string-18.3 {string trim} {
911 test string-18.4 {string trim} {
912 string trim "\t\nXYZ\t\n\r\n"
914 test string-18.5 {string trim} {
915 string trim " A XYZ A "
917 test string-18.6 {string trim} {
918 string trim "XXYYZZABC XXYYZZ" ZYX
920 test string-18.7 {string trim} {
923 test string-18.8 {string trim} {
924 string trim {abcdefg} {}
926 test string-18.9 {string trim} {
929 test string-18.10 {string trim} {
932 test string-18.11 {string trim, unicode} {
933 string trim "\xe7\xe8 AB\xe7C \xe8\xe7" \xe7\xe8
936 test string-19.1 {string trimleft} {
937 list [catch {string trimleft} msg]
939 test string-19.2 {string trimleft} {
940 string trimleft " XYZ "
943 test string-20.1 {string trimright errors} {
944 list [catch {string trimright} msg]
946 test string-20.2 {string trimright errors} {
947 list [catch {string trimg a} msg]
949 test string-20.3 {string trimright} {
950 string trimright " XYZ "
952 test string-20.4 {string trimright} {
955 test string-20.5 {string trimright} {
959 # Test for 8-bit clean and utf-8 trim chars
960 test string-21.1 {string trim embedded nulls} {
961 string trim " abc\x00def "
963 test string-21.2 {string trimleft embedded nulls} {
964 string trimleft " abc\x00def "
966 test string-21.3 {string trimright embedded nulls} {
967 string trimright " abc\x00def "
969 test string-21.4 {string trim utf-8} {
970 string trim "\u00b5\u00b6abc\x00def\u00b5\u00b5" "\u00b5\u00b6"
973 test string-22.1 {string replace} {
974 string replace //test.net/path/path2?query=url?otherquery 21 end
975 } {//test.net/path/path2}
977 test string-23.1 {string cat} {
981 test string-23.2 {string cat} {
985 test string-23.3 {string cat} {
989 test string-23.4 {string cat} {
991 string cat $abc (def)
994 test string-24.1 {string byterange} {
995 list [catch {string byterange} msg]
997 test string-24.2 {string byterange} {
998 list [catch {string byterange a 1} msg]
1000 test string-24.3 {string byterange} {
1001 list [catch {string byterange a 1 2 3} msg]
1003 test string-24.4 {string byterange} {
1004 string byterange abcdefghijklmnop 2 14
1006 test string-24.5 {string byterange, last > length} {
1007 string byterange abcdefghijklmnop 7 1000
1009 test string-24.6 {string byterange} {
1010 string byterange abcdefghijklmnop 10 end
1012 test string-24.7 {string byterange, last < first} {
1013 string byterange abcdefghijklmnop 10 9
1015 test string-24.8 {string byterange, first < 0} {
1016 string byterange abcdefghijklmnop -3 2
1018 test string-24.9 {string byterange} {
1019 string byterange abcdefghijklmnop -3 -2
1021 test string-24.10 {string byterange, utf8} {
1022 string byterange \u00b5\u00b6 0 1
1024 test string-24.11 {string byterange, slice utf8 } {
1025 string byterange \u00b5\u00b6 1 2
1027 test string-24.12 {string byterange, full range} {
1028 string byterange abcdef 0 end
1030 test string-24.13 {string byterange, invalid range} -body {
1031 string byterange abcdef foo bar
1032 } -returnCodes error -result {bad index "foo": must be integer?[+-]integer? or end?[+-]integer?}