jimregexp: remove dead code
[jimtcl.git] / tests / string.test
blob650088c32419c65904464c4a69ac44c59ac52588
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]
22 } {1}
23 test string-1.2 {error conditions} {
24     list [catch {string} msg]
25 } {1}
27 test string-2.1 {string compare, too few args} {
28     list [catch {string compare a} msg]
29 } {1}
30 test string-2.2 {string compare, bad args} {
31     list [catch {string compare a b c} msg]
32 } {1}
33 test string-2.3 {string compare, bad args} {
34     list [catch {string compare -length -nocase str1 str2} msg]
35 } {1}
36 test string-2.4 {string compare, too many args} {
37     list [catch {string compare -length 10 -nocase str1 str2 str3} msg]
38 } {1}
39 test string-2.5 {string compare with length unspecified} {
40     list [catch {string compare -length 10 10} msg]
41 } {1}
42 test string-2.6 {string compare} {
43     string compare abcde abdef
44 } -1
45 test string-2.7 {string compare, shortest method name} {
46     string c abcde ABCDE
47 } 1
48 test string-2.8 {string compare} {
49     string compare abcde abcde
50 } 0
51 test string-2.9 {string compare with length} {
52     string compare -length 2 abcde abxyz
53 } 0
54 test string-2.10 {string compare with special index} {
55     list [catch {string compare -length end-3 abcde abxyz} msg]
56 } {1}
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
64     # the high bit set.
65 } 1
66 test string-2.13 {string compare -nocase} {
67     string compare -nocase abcde abdef
68 } -1
69 test string-2.14 {string compare -nocase} {
70     string c -nocase abcde ABCDE
71 } 0
72 test string-2.15 {string compare -nocase} {
73     string compare -nocase abcde abcde
74 } 0
75 test string-2.16 {string compare -nocase with length} {
76     string compare -length 2 -nocase abcde Abxyz
77 } 0
78 test string-2.17 {string compare -nocase with length} {
79     string compare -nocase -length 3 abcde Abxyz
80 } -1
81 test string-2.18 {string compare -nocase with length <= 0} {
82     string compare -nocase -length -1 abcde AbCdEf
83 } -1
84 test string-2.19 {string compare -nocase with excessive length} {
85     string compare -nocase -length 50 AbCdEf abcde
86 } 1
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
91 } -1
92 test string-2.21 {string compare -nocase with special index} {
93     list [catch {string compare -nocase -length end-3 Abcde abxyz} msg]
94 } {1}
95 test string-2.22 {string compare, null strings} {
96     string compare "" ""
97 } 0
98 test string-2.23 {string compare, null strings} {
99     string compare "" foo
100 } -1
101 test string-2.24 {string compare, null strings} {
102     string compare foo ""
103 } 1
104 test string-2.25 {string compare -nocase, null strings} {
105     string compare -nocase "" ""
106 } 0
107 test string-2.26 {string compare -nocase, null strings} {
108     string compare -nocase "" foo
109 } -1
110 test string-2.27 {string compare -nocase, null strings} {
111     string compare -nocase foo ""
112 } 1
113 test string-2.28 {string equal with length, unequal strings} {
114     string compare -length 2 abc abde
115 } 0
116 test string-2.29 {string equal with length, unequal strings} {
117     string compare -length 2 ab abde
118 } 0
119 # only need a few tests on equal, since it uses the same code as
120 # string compare, but just modifies the return output
121 test string-3.1 {string equal} {
122     string equal abcde abdef
123 } 0
124 test string-3.2 {string equal} {
125     string eq abcde ABCDE
126 } 0
127 test string-3.3 {string equal} {
128     string equal abcde abcde
129 } 1
130 test string-3.4 {string equal -nocase} utf8 {
131     string equal -nocase \u00dc\u00dc\u00dc\u00dc\u00fc\u00fc\u00fc\u00fc \u00dc\u00dc\u00dc\u00dc\u00dc\u00dc\u00dc\u00dc
132 } 1
133 test string-3.5 {string equal -nocase} {
134     string equal -nocase abcde abdef
135 } 0
136 test string-3.6 {string equal -nocase} {
137     string eq -nocase abcde ABCDE
138 } 1
139 test string-3.7 {string equal -nocase} {
140     string equal -nocase abcde abcde
141 } 1
142 test string-3.8 {string equal with length, unequal strings} {
143     string equal -length 2 abc abde
144 } 1
145 test string-4.1 {string first, too few args} {
146     list [catch {string first a} msg]
147 } {1}
148 test string-4.2 {string first, bad args} {
149     list [catch {string first a b c} msg]
150 } {1}
151 test string-4.3 {string first, too many args} {
152     list [catch {string first a b 5 d} msg]
153 } {1}
154 test string-4.4 {string first} {
155     string first bq abcdefgbcefgbqrs
156 } 12
157 test string-4.5 {string first} {
158     string fir bcd abcdefgbcefgbqrs
159 } 1
160 test string-4.6 {string first} {
161     string f b abcdefgbcefgbqrs
162 } 1
163 test string-4.7 {string first} {
164     string first xxx x123xx345xxx789xxx012
165 } 9
166 test string-4.8 {string first} {
167     string first "" x123xx345xxx789xxx012
168 } -1
169 test string-4.14 {string first, start index} {
170     string first a abcabc end-4
171 } 3
172 test string-4.15 {string first, empty needle} {
173     string first "" b
174 } -1
175 test string-4.16 {string first, empty haystack} {
176     string first a ""
177 } -1
178 test string-4.17 {string first, needle bigger than haystack} {
179     string first aaa b
180 } -1
181 test string-4.18 {string first, negative index} {
182     string first a aaa -4
183 } 0
184 test string-4.19 {string first, not found} {
185     string first a bcd
186 } -1
188 test string-5.1 {string index} {
189     list [catch {string index} msg]
190 } {1}
191 test string-5.2 {string index} {
192     list [catch {string index a b c} msg]
193 } {1}
194 test string-5.3 {string index} {
195     string index abcde 0
196 } a
197 test string-5.4 {string index} {
198     string in abcde 4
199 } e
200 test string-5.5 {string index} {
201     string index abcde 5
202 } {}
203 test string-5.6 {string index} {
204     list [catch {string index abcde -10} msg]
205 } {0}
206 test string-5.7 {string index} {
207     list [catch {string index a xyz} msg]
208 } {1}
209 test string-5.8 {string index} {
210     string index abc end
211 } c
212 test string-5.9 {string index} {
213     string index abc end-1
214 } b
215 test string-5.17 {string index, bad integer} tcl {
216     list [catch {string index "abc" 08} msg]
217 } {1}
218 test string-5.18 {string index, bad integer} tcl {
219     list [catch {string index "abc" end-00289} msg]
220 } {1}
221 test string-6.1 {string is, too few args} jim {
222     list [catch {string is} msg] $msg
223 } {1 {wrong # args: should be "string is class ?-strict? str"}}
224 test string-6.2 {string is, too few args} jim {
225     list [catch {string is alpha} msg] $msg
226 } {1 {wrong # args: should be "string is class ?-strict? str"}}
227 test string-6.3 {string is, bad args} jim {
228     list [catch {string is alpha -failin str} msg] $msg
229 } {1 {wrong # args: should be "string is class ?-strict? str"}}
230 test string-6.4 {string is, too many args} jim {
231     list [catch {string is alpha -failin var -strict str more} msg] $msg
232 } {1 {wrong # args: should be "string is class ?-strict? str"}}
233 test string-6.5 {string is, class check} jim {
234     list [catch {string is bogus str} msg] $msg
235 } {1 {bad class "bogus": must be alnum, alpha, ascii, control, digit, double, graph, integer, lower, print, punct, space, upper, or xdigit}}
236 test string-6.6 {string is, ambiguous class} jim {
237     list [catch {string is al str} msg] $msg
238 } {1 {ambiguous class "al": must be alnum, alpha, ascii, control, digit, double, graph, integer, lower, print, punct, space, upper, or xdigit}}
239 test string-6.10 {string is, ok on empty} {
240     string is alpha {}
241 } 1
242 test string-6.11 {string is, -strict check against empty} {
243     string is alpha -strict {}
244 } 0
245 test string-6.12 {string is alnum, true} {
246     string is alnum abc123
247 } 1
248 test string-6.15 {string is alpha, true} {
249     string is alpha abc
250 } 1
251 test string-6.16 {string is ascii, true} {
252     string is ascii abc123
253 } 1
254 test string-6.17 {string is ascii, false} {
255     string is ascii 0123Ü567
256 } 0
257 test string-6.24 {string is digit, true} {
258     string is digit 0123456789
259 } 1
260 test string-6.25 {string is digit, false} {
261     list [string is digit 0123Ü567]
262 } {0}
263 test string-6.26 {string is digit, false} {
264     list [string is digit +123567]
265 } {0}
266 test string-6.27 {string is double, true} {
267     string is double 1
268 } 1
269 test string-6.28 {string is double, true} {
270     string is double [expr double(1)]
271 } 1
272 test string-6.29 {string is double, true} {
273     string is double 1.0
274 } 1
275 test string-6.30 {string is double, true} {
276     string is double [string compare a a]
277 } 1
278 test string-6.31 {string is double, true} {
279     string is double "   +1.0e-1  "
280 } 1
281 test string-6.32 {string is double, true} {
282     string is double "\n1.0\v"
283 } 1
284 test string-6.33 {string is double, false} {
285     list [string is double  1abc]
286 } {0}
287 test string-6.34 {string is double, false} {
288     list [string is double  abc]
289 } {0}
290 test string-6.35 {string is double, false} {
291     list [string is double  "   1.0e4e4  "]
292 } {0}
293 test string-6.36 {string is double, false} {
294     list [string is double  "\n"]
295 } {0}
296 test string-6.38 {string is double, false on underflow} jim {
297     list [string is double  123e-9999]
298 } {0}
299 test string-6.39 {string is double, false} {
300     # This test is non-portable because IRIX thinks 
301     # that .e1 is a valid double - this is really a bug
302     # on IRIX as .e1 should NOT be a valid double
304     list [string is double  .e1]
305 } {0}
306 test string-6.48 {string is integer, true} {
307     string is integer +1234567890
308 } 1
309 test string-6.49 {string is integer, true on type} {
310     string is integer [expr int(50.0)]
311 } 1
312 test string-6.50 {string is integer, true} {
313     string is integer [list -10]
314 } 1
315 test string-6.51 {string is integer, true as hex} {
316     string is integer 0xabcdef
317 } 1
318 test string-6.52 {string is integer, true as octal} {
319     string is integer 012345
320 } 1
321 test string-6.53 {string is integer, true with whitespace} {
322     string is integer "  \n1234\v"
323 } 1
324 test string-6.54 {string is integer, false} {
325     list [string is integer  123abc]
326 } 0
327 test string-6.56 {string is integer, false} {
328     list [string is integer  [expr double(1)]]
329 } 0
330 test string-6.57 {string is integer, false} {
331     list [string is integer  "    "]
332 } 0
333 test string-6.58 {string is integer, false on bad octal} jim {
334     list [string is integer  036963]
335 } 1
336 test string-6.59 {string is integer, false on bad octal} tcl {
337     list [string is integer  036963]
338 } 0
339 test string-6.60 {string is integer, false on bad hex} {
340     list [string is integer  0X345XYZ]
341 } 0
342 test string-6.61 {string is lower, true} {
343     string is lower abc
344 } 1
345 test string-6.62 {string is lower, false} {
346     list [string is lower  aBc]
347 } 0
348 test string-6.63 {string is lower, false} {
349     list [string is lower  abc1]
350 } 0
351 test string-6.64 {string is lower, unicode false} {
352     list [string is lower  abÜUE]
353 } 0
354 test string-6.65 {string is space, true} {
355     string is space " \t\n\v\f"
356 } 1
357 test string-6.66 {string is space, false} {
358     list [string is space  " \t\n\v1\f"]
359 } 0
360 test string-6.75 {string is upper, true} {
361     string is upper ABC
362 } 1
363 test string-6.77 {string is upper, false} {
364     list [string is upper  AbC]
365 } 0
366 test string-6.78 {string is upper, false} {
367     list [string is upper  AB2C]
368 } 0
369 test string-6.84 {string is control} {
370     ## Control chars are in the ranges
371     ## 00..1F && 7F..9F
372     list [string is control  \x00\x01\x10\x1F\x7F\x80\x9F\x60]
373 } 0
374 test string-6.85 {string is control} tcl {
375     string is control \u0100
376 } 0
377 test string-6.86 {string is graph} {
378     ## graph is any print char, except space
379     list [string is gra  "0123abc!@#\$ "]
380 } 0
381 test string-6.87 {string is print} {
382     ## basically any printable char
383     list [string is print  "0123abc!@#\$ \010"]
384 } 0
385 test string-6.88 {string is punct} {
386     ## any graph char that isn't alnum
387     list [string is punct  "_!@#\000beq0"]
388 } 0
389 test string-6.89 {string is xdigit} {
390     list [string is xdigit  0123456789\u0061bcdefABCDEFg]
391 } 0
393 test string-7.1 {string last, too few args} {
394     list [catch {string last a} msg]
395 } {1}
396 test string-7.2 {string last, bad args} {
397     list [catch {string last a b c} msg]
398 } {1}
399 test string-7.3 {string last, too many args} {
400     list [catch {string last a b c d} msg]
401 } {1}
402 test string-7.4 {string last} {
403     string la xxx xxxx123xx345x678
404 } 1
405 test string-7.5 {string last} {
406     string last xx xxxx123xx345x678
407 } 7
408 test string-7.6 {string last} {
409     string las x xxxx123xx345x678
410 } 12
411 test string-7.13 {string last, start index} {
412     ## Constrain to last 'a' should work
413     string last ba badbad end-1
414 } 3
415 test string-7.14 {string last, start index} {
416     ## Constrain to last 'b' should skip last 'ba'
417     string last ba badbad end-2
418 } 0
419 test string-7.15 {string last, start index} {
420     string last \u00dca \u00dcad\u00dcad 0
421 } -1
422 test string-7.16 {string last, start index} utf8 {
423     string last \u00dca \u00dcad\u00dcad end-1
424 } 3
425 test string-7.17 {string last, too few args} {
426     string last abc def
427 } -1
428 test string-9.1 {string length} {
429     list [catch {string length} msg]
430 } {1}
431 test string-9.2 {string length} {
432     list [catch {string length a b} msg]
433 } {1}
434 test string-9.3 {string length} {
435     string length "a little string"
436 } 15
437 test string-9.4 {string length} {
438     string le ""
439 } 0
441 test string-10.1 {string map, too few args} {
442     list [catch {string map} msg]
443 } {1}
444 test string-10.2 {string map, bad args} {
445     list [catch {string map {a b} abba oops} msg]
446 } {1}
447 test string-10.3 {string map, too many args} {
448     list [catch {string map -nocase {a b} str1 str2} msg]
449 } {1}
450 test string-10.4 {string map} {
451     string map {a b} abba
452 } {bbbb}
453 test string-10.5 {string map} {
454     string map {a b} a
455 } {b}
456 test string-10.6 {string map -nocase} {
457     string map -nocase {a b} Abba
458 } {bbbb}
459 test string-10.7 {string map} {
460     string map {abc 321 ab * a A} aabcabaababcab
461 } {A321*A*321*}
462 test string-10.8 {string map -nocase} {
463     string map -nocase {aBc 321 Ab * a A} aabcabaababcab
464 } {A321*A*321*}
465 test string-10.9 {string map -nocase} {
466     string map -no {abc 321 Ab * a A} aAbCaBaAbAbcAb
467 } {A321*A*321*}
468 test string-10.10 {string map} {
469     list [catch {string map {a b c} abba} msg]
470 } {1}
471 test string-10.11 {string map, nulls} {
472     string map {\x00 NULL blah \x00nix} {qwerty}
473 } {qwerty}
474 test string-10.12 {string map, unicode} {
475     string map [list \u00fc ue UE \u00dc] "a\u00fcueUE\000EU"
476 } aueue\u00dc\0EU
477 test string-10.13 {string map, -nocase unicode} {
478     string map -nocase [list \u00fc ue UE \u00dc] "a\u00fcueUE\000EU"
479 } aue\u00dc\u00dc\0EU
480 test string-10.14 {string map, -nocase null arguments} {
481     string map -nocase {{} abc} foo
482 } foo
483 test string-10.15 {string map, one pair case} {
484     string map -nocase {abc 32} aAbCaBaAbAbcAb
485 } {a32aBaAb32Ab}
486 test string-10.16 {string map, one pair case} {
487     string map -nocase {ab 4321} aAbCaBaAbAbcAb
488 } {a4321C4321a43214321c4321}
489 test string-10.17 {string map, one pair case} {
490     string map {Ab 4321} aAbCaBaAbAbcAb
491 } {a4321CaBa43214321c4321}
493 test string-11.1 {string match, too few args} {
494     list [catch {string match a} msg]
495 } {1}
496 test string-11.2 {string match, too many args} {
497     list [catch {string match a b c d} msg]
498 } {1}
499 test string-11.3 {string match} {
500     string match abc abc
501 } 1
502 test string-11.4 {string match} {
503     string mat abc abd
504 } 0
505 test string-11.5 {string match} {
506     string match ab*c abc
507 } 1
508 test string-11.6 {string match} {
509     string match ab**c abc
510 } 1
511 test string-11.7 {string match} {
512     string match ab* abcdef
513 } 1
514 test string-11.8 {string match} {
515     string match *c abc
516 } 1
517 test string-11.9 {string match} {
518     string match *3*6*9 0123456789
519 } 1
520 test string-11.10 {string match} {
521     string match *3*6*9 01234567890
522 } 0
523 test string-11.11 {string match} {
524     string match a?c abc
525 } 1
526 test string-11.12 {string match} {
527     string match a??c abc
528 } 0
529 test string-11.13 {string match} {
530     string match ?1??4???8? 0123456789
531 } 1
532 test string-11.14 {string match} {
533     string match {[abc]bc} abc
534 } 1
535 test string-11.15 {string match} {
536     string match {a[abc]c} abc
537 } 1
538 test string-11.16 {string match} {
539     string match {a[xyz]c} abc
540 } 0
541 test string-11.17 {string match} {
542     string match {12[2-7]45} 12345
543 } 1
544 test string-11.18 {string match} {
545     string match {12[ab2-4cd]45} 12345
546 } 1
547 test string-11.19 {string match} {
548     string match {12[ab2-4cd]45} 12b45
549 } 1
550 test string-11.20 {string match} {
551     string match {12[ab2-4cd]45} 12d45
552 } 1
553 test string-11.21 {string match} {
554     string match {12[ab2-4cd]45} 12145
555 } 0
556 test string-11.22 {string match} {
557     string match {12[ab2-4cd]45} 12545
558 } 0
559 test string-11.23 {string match} {
560     string match {a\*b} a*b
561 } 1
562 test string-11.24 {string match} {
563     string match {a\*b} ab
564 } 0
565 test string-11.25 {string match} {
566     string match {a\*\?\[\]\\\x} "a*?\[\]\\x"
567 } 1
568 test string-11.26 {string match} {
569     string match ** ""
570 } 1
571 test string-11.27 {string match} {
572     string match *. ""
573 } 0
574 test string-11.28 {string match} {
575     string match "" ""
576 } 1
577 test string-11.29 {string match} {
578     string match \[a a
579 } 1
580 test string-11.30 {string match, bad args} {
581     list [catch {string match - b c} msg]
582 } {1}
583 test string-11.31 {string match case} {
584     string match a A
585 } 0
586 test string-11.32 {string match nocase} {
587     string match -nocase a A
588 } 1
589 test string-11.34 {string match nocase} {
590     string match -nocase a*f ABCDEf
591 } 1
592 test string-11.35 {string match case, false hope} {
593     # This is true because '_' lies between the A-Z and a-z ranges
594     string match {[A-z]} _
595 } 1
596 test string-11.36 {string match nocase range} {
597     # This is false because although '_' lies between the A-Z and a-z ranges,
598     # we lower case the end points before checking the ranges.
599     string match -nocase {[A-z]} _
600 } 0
601 test string-11.37 {string match nocase} {
602     string match -nocase {[A-fh-Z]} g
603 } 0
604 test string-11.38 {string match case, reverse range} {
605     string match {[A-fh-Z]} g
606 } 1
607 test string-11.39 {string match, *\ case} {
608     string match {*\abc} abc
609 } 1
610 test string-11.40 {string match, *special case} {
611     string match {*[ab]} abc
612 } 0
613 test string-11.41 {string match, *special case} {
614     string match {*[ab]*} abc
615 } 1
616 # I don't see why this shouldn't match. Ignored for jim
617 test string-11.42 {string match, *special case} tcl {
618     string match "*\\" "\\"
619 } 0
620 test string-11.43 {string match, *special case} {
621     string match "*\\\\" "\\"
622 } 1
623 test string-11.44 {string match, *special case} {
624     string match "*???" "12345"
625 } 1
626 test string-11.45 {string match, *special case} {
627     string match "*???" "12"
628 } 0
629 test string-11.46 {string match, *special case} {
630     string match "*\\*" "abc*"
631 } 1
632 test string-11.47 {string match, *special case} {
633     string match "*\\*" "*"
634 } 1
635 test string-11.48 {string match, *special case} {
636     string match "*\\*" "*abc"
637 } 0
638 test string-11.49 {string match, *special case} {
639     string match "?\\*" "a*"
640 } 1
641 # I don't see why this shouldn't match. Ignored for jim
642 test string-11.50 {string match, *special case} tcl {
643     string match "\\" "\\"
644 } 0
647 test string-12.1 {string range} {
648     list [catch {string range} msg]
649 } {1}
650 test string-12.2 {string range} {
651     list [catch {string range a 1} msg]
652 } {1}
653 test string-12.3 {string range} {
654     list [catch {string range a 1 2 3} msg]
655 } {1}
656 test string-12.4 {string range} {
657     string range abcdefghijklmnop 2 14
658 } {cdefghijklmno}
659 test string-12.5 {string range, last > length} {
660     string range abcdefghijklmnop 7 1000
661 } {hijklmnop}
662 test string-12.6 {string range} {
663     string range abcdefghijklmnop 10 end
664 } {klmnop}
665 test string-12.7 {string range, last < first} {
666     string range abcdefghijklmnop 10 9
667 } {}
668 test string-12.8 {string range, first < 0} {
669     string range abcdefghijklmnop -3 2
670 } {abc}
671 test string-12.9 {string range} {
672     string range abcdefghijklmnop -3 -2
673 } {}
674 test string-12.10 {string range} {
675     string range abcdefghijklmnop 1000 1010
676 } {}
677 test string-12.11 {string range} {
678     string range abcdefghijklmnop -100 end
679 } {abcdefghijklmnop}
680 test string-12.12 {string range} {
681     list [catch {string range abc abc 1} msg]
682 } {1}
683 test string-12.13 {string range} {
684     list [catch {string range abc 1 eof} msg]
685 } {1}
686 test string-12.14 {string range} {
687     string range abcdefghijklmnop end-1 end
688 } {op}
689 test string-12.15 {string range} {
690     string range abcdefghijklmnop end 1000
691 } {p}
692 test string-12.16 {string range} {
693     string range abcdefghijklmnop end end-1
694 } {}
696 test string-13.1 {string repeat} {
697     list [catch {string repeat} msg]
698 } {1}
699 test string-13.2 {string repeat} {
700     list [catch {string repeat abc 10 oops} msg]
701 } {1}
702 test string-13.3 {string repeat} {
703     string repeat {} 100
704 } {}
705 test string-13.4 {string repeat} {
706     string repeat { } 5
707 } {     }
708 test string-13.5 {string repeat} {
709     string repeat abc 3
710 } {abcabcabc}
711 test string-13.6 {string repeat} {
712     string repeat abc -1
713 } {}
714 test string-13.7 {string repeat} {
715     list [catch {string repeat abc end} msg]
716 } {1}
717 test string-13.8 {string repeat} {
718     string repeat {} -1000
719 } {}
720 test string-13.9 {string repeat} {
721     string repeat {} 0
722 } {}
723 test string-13.10 {string repeat} {
724     string repeat def 0
725 } {}
726 test string-13.11 {string repeat} {
727     string repeat def 1
728 } def
729 test string-13.12 {string repeat} {
730     string repeat ab\u7266cd 3
731 } ab\u7266cdab\u7266cdab\u7266cd
732 test string-13.13 {string repeat} {
733     string repeat \x00 3
734 } \x00\x00\x00
736 test string-14.1 {string replace} {
737     list [catch {string replace} msg] $msg
738 } {1 {wrong # args: should be "string replace string first last ?string?"}}
739 test string-14.2 {string replace} {
740     list [catch {string replace a 1} msg] $msg
741 } {1 {wrong # args: should be "string replace string first last ?string?"}}
742 test string-14.3 {string replace} {
743     list [catch {string replace a 1 2 3 4} msg] $msg
744 } {1 {wrong # args: should be "string replace string first last ?string?"}}
745 test string-14.4 {string replace} {
746 } {}
747 test string-14.5 {string replace} {
748     string replace abcdefghijklmnop 2 14
749 } {abp}
750 test string-14.6 {string replace} {
751     string replace abcdefghijklmnop 7 1000
752 } {abcdefg}
753 test string-14.7 {string replace} {
754     string replace abcdefghijklmnop 10 end
755 } {abcdefghij}
756 test string-14.8 {string replace} {
757     string replace abcdefghijklmnop 10 9
758 } {abcdefghijklmnop}
759 test string-14.9 {string replace} {
760     string replace abcdefghijklmnop -3 2
761 } {defghijklmnop}
762 test string-14.10 {string replace} {
763     string replace abcdefghijklmnop -3 -2
764 } {abcdefghijklmnop}
765 test string-14.11 {string replace} {
766     string replace abcdefghijklmnop 1000 1010
767 } {abcdefghijklmnop}
768 test string-14.12 {string replace} {
769     string replace abcdefghijklmnop -100 end
770 } {}
771 test string-14.13 {string replace} {
772     list [catch {string replace abc abc 1} msg] $msg
773 } {1 {bad index "abc": must be integer?[+-]integer? or end?[+-]integer?}}
774 test string-14.14 {string replace} {
775     list [catch {string replace abc 1 eof} msg] $msg
776 } {1 {bad index "eof": must be integer?[+-]integer? or end?[+-]integer?}}
777 test string-14.15 {string replace} {
778     string replace abcdefghijklmnop end-10 end-2 NEW
779 } {abcdeNEWop}
780 test string-14.16 {string replace} {
781     string replace abcdefghijklmnop 0 end foo
782 } {foo}
783 test string-14.17 {string replace} {
784     string replace abcdefghijklmnop end end-1
785 } {abcdefghijklmnop}
787 test string-15.1 {string tolower too few args} {
788     list [catch {string tolower} msg]
789 } {1}
790 test string-15.2 {string tolower bad args} {
791     list [catch {string tolower a b} msg]
792 } {1}
793 test string-15.3 {string tolower too many args} {
794     list [catch {string tolower ABC 1 end oops} msg]
795 } {1}
796 test string-15.4 {string tolower} {
797     string tolower ABCDeF
798 } {abcdef}
799 test string-15.5 {string tolower} {
800     string tolower "ABC  XyZ"
801 } {abc  xyz}
802 test string-15.6 {string tolower} {
803     string tolower {123#$&*()}
804 } {123#$&*()}
806 test string-16.1 {string toupper} {
807     list [catch {string toupper} msg]
808 } {1}
809 test string-16.2 {string toupper} {
810     list [catch {string toupper a b} msg]
811 } {1}
812 test string-16.4 {string toupper} {
813     string toupper abCDEf
814 } {ABCDEF}
815 test string-16.5 {string toupper} {
816     string toupper "abc xYz"
817 } {ABC XYZ}
818 test string-16.6 {string toupper} {
819     string toupper {123#$&*()}
820 } {123#$&*()}
822 test string-17.1 {string totitle} -body {
823     string totitle
824 }  -returnCodes error -match glob -result {wrong # args: should be "string totitle string*}
825 test string-17.3 {string totitle} {
826     string totitle abCDEf
827 } {Abcdef}
828 test string-17.4 {string totitle} {
829     string totitle "abc xYz"
830 } {Abc xyz}
831 test string-17.5 {string totitle} {
832     string totitle {123#$&*()}
833 } {123#$&*()}
835 test string-18.1 {string trim} {
836     list [catch {string trim} msg]
837 } {1}
838 test string-18.2 {string trim} {
839     list [catch {string trim a b c} msg]
840 } {1}
841 test string-18.3 {string trim} {
842     string trim "    XYZ      "
843 } {XYZ}
844 test string-18.4 {string trim} {
845     string trim "\t\nXYZ\t\n\r\n"
846 } {XYZ}
847 test string-18.5 {string trim} {
848     string trim "  A XYZ A    "
849 } {A XYZ A}
850 test string-18.6 {string trim} {
851     string trim "XXYYZZABC XXYYZZ" ZYX
852 } {ABC }
853 test string-18.7 {string trim} {
854     string trim "    \t\r      "
855 } {}
856 test string-18.8 {string trim} {
857     string trim {abcdefg} {}
858 } {abcdefg}
859 test string-18.9 {string trim} {
860     string trim {}
861 } {}
862 test string-18.10 {string trim} {
863     string trim ABC DEF
864 } {ABC}
865 test string-18.11 {string trim, unicode} {
866     string trim "\xe7\xe8 AB\xe7C \xe8\xe7" \xe7\xe8
867 } " AB\xe7C "
869 test string-19.1 {string trimleft} {
870     list [catch {string trimleft} msg]
871 } {1}
872 test string-19.2 {string trimleft} {
873     string trimleft "    XYZ      "
874 } {XYZ      }
876 test string-20.1 {string trimright errors} {
877     list [catch {string trimright} msg]
878 } {1}
879 test string-20.2 {string trimright errors} {
880     list [catch {string trimg a} msg]
881 } {1}
882 test string-20.3 {string trimright} {
883     string trimright "    XYZ      "
884 } {    XYZ}
885 test string-20.4 {string trimright} {
886     string trimright "   "
887 } {}
888 test string-20.5 {string trimright} {
889     string trimright ""
890 } {}
892 # Test for 8-bit clean and utf-8 trim chars
893 test string-21.1 {string trim embedded nulls} {
894     string trim " abc\x00def "
895 } "abc\x00def"
896 test string-21.2 {string trimleft embedded nulls} {
897     string trimleft " abc\x00def "
898 } "abc\x00def "
899 test string-21.3 {string trimright embedded nulls} {
900     string trimright " abc\x00def "
901 } " abc\x00def"
902 test string-21.4 {string trim utf-8} {
903     string trim "\u00b5\u00b6abc\x00def\u00b5\u00b5" "\u00b5\u00b6"
904 } "abc\x00def"
906 test string-22.1 {string replace} {
907     string replace //test.net/path/path2?query=url?otherquery 21 end
908 } {//test.net/path/path2}
910 testreport