Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/tcl8.5.2/tests/string.test @ 25

Last change on this file since 25 was 25, checked in by landauf, 16 years ago

added tcl to libs

File size: 53.8 KB
Line 
1# Commands covered:  string
2#
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.
6#
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.
11#
12# See the file "license.terms" for information on usage and redistribution
13# of this file, and for a DISCLAIMER OF ALL WARRANTIES.
14#
15# RCS: @(#) $Id: string.test,v 1.71 2007/12/13 15:26:07 dgp Exp $
16
17if {[lsearch [namespace children] ::tcltest] == -1} {
18    package require tcltest
19    namespace import -force ::tcltest::*
20}
21
22# Some tests require the testobj command
23
24testConstraint testobj [expr {[info commands testobj] != {}}]
25testConstraint testindexobj [expr {[info commands testindexobj] != {}}]
26
27test string-1.1 {error conditions} {
28    list [catch {string gorp a b} msg] $msg
29} {1 {unknown or ambiguous subcommand "gorp": must be bytelength, compare, equal, first, index, is, last, length, map, match, range, repeat, replace, reverse, tolower, totitle, toupper, trim, trimleft, trimright, wordend, or wordstart}}
30test string-1.2 {error conditions} {
31    list [catch {string} msg] $msg
32} {1 {wrong # args: should be "string subcommand ?argument ...?"}}
33
34test string-2.1 {string compare, too few args} {
35    list [catch {string compare a} msg] $msg
36} {1 {wrong # args: should be "string compare ?-nocase? ?-length int? string1 string2"}}
37test string-2.2 {string compare, bad args} {
38    list [catch {string compare a b c} msg] $msg
39} {1 {bad option "a": must be -nocase or -length}}
40test string-2.3 {string compare, bad args} {
41    list [catch {string compare -length -nocase str1 str2} msg] $msg
42} {1 {expected integer but got "-nocase"}}
43test string-2.4 {string compare, too many args} {
44    list [catch {string compare -length 10 -nocase str1 str2 str3} msg] $msg
45} {1 {wrong # args: should be "string compare ?-nocase? ?-length int? string1 string2"}}
46test string-2.5 {string compare with length unspecified} {
47    list [catch {string compare -length 10 10} msg] $msg
48} {1 {wrong # args: should be "string compare ?-nocase? ?-length int? string1 string2"}}
49test string-2.6 {string compare} {
50    string compare abcde abdef
51} -1
52test string-2.7 {string compare, shortest method name} {
53    string c abcde ABCDE
54} 1
55test string-2.8 {string compare} {
56    string compare abcde abcde
57} 0
58test string-2.9 {string compare with length} {
59    string compare -length 2 abcde abxyz
60} 0
61test string-2.10 {string compare with special index} {
62    list [catch {string compare -length end-3 abcde abxyz} msg] $msg
63} {1 {expected integer but got "end-3"}}
64test string-2.11 {string compare, unicode} {
65    string compare ab\u7266 ab\u7267
66} -1
67test string-2.12 {string compare, high bit} {
68    # This test will fail if the underlying comparaison
69    # is using signed chars instead of unsigned chars.
70    # (like SunOS's default memcmp thus the compat/memcmp.c)
71    string compare "\x80" "@"
72    # Nb this tests works also in utf8 space because \x80 is
73    # translated into a 2 or more bytelength but whose first byte has
74    # the high bit set.
75} 1
76test string-2.13 {string compare -nocase} {
77    string compare -nocase abcde abdef
78} -1
79test string-2.14 {string compare -nocase} {
80    string c -nocase abcde ABCDE
81} 0
82test string-2.15 {string compare -nocase} {
83    string compare -nocase abcde abcde
84} 0
85test string-2.16 {string compare -nocase with length} {
86    string compare -length 2 -nocase abcde Abxyz
87} 0
88test string-2.17 {string compare -nocase with length} {
89    string compare -nocase -length 3 abcde Abxyz
90} -1
91test string-2.18 {string compare -nocase with length <= 0} {
92    string compare -nocase -length -1 abcde AbCdEf
93} -1
94test string-2.19 {string compare -nocase with excessive length} {
95    string compare -nocase -length 50 AbCdEf abcde
96} 1
97test string-2.20 {string compare -len unicode} {
98    # These are strings that are 6 BYTELENGTH long, but the length
99    # shouldn't make a different because there are actually 3 CHARS long
100    string compare -len 5 \334\334\334 \334\334\374
101} -1
102test string-2.21 {string compare -nocase with special index} {
103    list [catch {string compare -nocase -length end-3 Abcde abxyz} msg] $msg
104} {1 {expected integer but got "end-3"}}
105test string-2.22 {string compare, null strings} {
106    string compare "" ""
107} 0
108test string-2.23 {string compare, null strings} {
109    string compare "" foo
110} -1
111test string-2.24 {string compare, null strings} {
112    string compare foo ""
113} 1
114test string-2.25 {string compare -nocase, null strings} {
115    string compare -nocase "" ""
116} 0
117test string-2.26 {string compare -nocase, null strings} {
118    string compare -nocase "" foo
119} -1
120test string-2.27 {string compare -nocase, null strings} {
121    string compare -nocase foo ""
122} 1
123test string-2.28 {string compare with length, unequal strings} {
124    string compare -length 2 abc abde
125} 0
126test string-2.29 {string compare with length, unequal strings} {
127    string compare -length 2 ab abde
128} 0
129test string-2.30 {string compare with NUL character vs. other ASCII} {
130    # Be careful here, since UTF-8 rep comparison with memcmp() of
131    # these puts chars in the wrong order
132    string compare \x00 \x01
133} -1
134test string-2.31 {string compare, high bit} {
135    proc foo {} {string compare "a\x80" "a@"}
136    foo
137} 1
138test string-2.32 {string compare, high bit} {
139    proc foo {} {string compare "a\x00" "a\x01"}
140    foo
141} -1
142test string-2.33 {string compare, high bit} {
143    proc foo {} {string compare "\x00\x00" "\x00\x01"}
144    foo
145} -1
146
147# only need a few tests on equal, since it uses the same code as
148# string compare, but just modifies the return output
149test string-3.1 {string equal} {
150    string equal abcde abdef
151} 0
152test string-3.2 {string equal} {
153    string eq abcde ABCDE
154} 0
155test string-3.3 {string equal} {
156    string equal abcde abcde
157} 1
158test string-3.4 {string equal -nocase} {
159    string equal -nocase \334\334\334\334\374\374\374\374 \334\334\334\334\334\334\334\334
160} 1
161test string-3.5 {string equal -nocase} {
162    string equal -nocase abcde abdef
163} 0
164test string-3.6 {string equal -nocase} {
165    string eq -nocase abcde ABCDE
166} 1
167test string-3.7 {string equal -nocase} {
168    string equal -nocase abcde abcde
169} 1
170test string-3.8 {string equal with length, unequal strings} {
171    string equal -length 2 abc abde
172} 1
173
174test string-4.1 {string first, too few args} {
175    list [catch {string first a} msg] $msg
176} {1 {wrong # args: should be "string first needleString haystackString ?startIndex?"}}
177test string-4.2 {string first, bad args} {
178    list [catch {string first a b c} msg] $msg
179} {1 {bad index "c": must be integer?[+-]integer? or end?[+-]integer?}}
180test string-4.3 {string first, too many args} {
181    list [catch {string first a b 5 d} msg] $msg
182} {1 {wrong # args: should be "string first needleString haystackString ?startIndex?"}}
183test string-4.4 {string first} {
184    string first bq abcdefgbcefgbqrs
185} 12
186test string-4.5 {string first} {
187    string fir bcd abcdefgbcefgbqrs
188} 1
189test string-4.6 {string first} {
190    string f b abcdefgbcefgbqrs
191} 1
192test string-4.7 {string first} {
193    string first xxx x123xx345xxx789xxx012
194} 9
195test string-4.8 {string first} {
196    string first "" x123xx345xxx789xxx012
197} -1
198test string-4.9 {string first, unicode} {
199    string first x abc\u7266x
200} 4
201test string-4.10 {string first, unicode} {
202    string first \u7266 abc\u7266x
203} 3
204test string-4.11 {string first, start index} {
205    string first \u7266 abc\u7266x 3
206} 3
207test string-4.12 {string first, start index} {
208    string first \u7266 abc\u7266x 4
209} -1
210test string-4.13 {string first, start index} {
211    string first \u7266 abc\u7266x end-2
212} 3
213test string-4.14 {string first, negative start index} {
214    string first b abc -1
215} 1
216test string-4.15 {string first, ability to two-byte encoded utf-8 chars} {
217    # Test for a bug in Tcl 8.3 where test for all-single-byte-encoded
218    # strings was incorrect, leading to an index returned by [string first]
219    # which pointed past the end of the string.
220    set uchar \u057e    ;# character with two-byte encoding in utf-8
221    string first % %#$uchar$uchar#$uchar$uchar#% 3
222} 8
223
224test string-5.1 {string index} {
225    list [catch {string index} msg] $msg
226} {1 {wrong # args: should be "string index string charIndex"}}
227test string-5.2 {string index} {
228    list [catch {string index a b c} msg] $msg
229} {1 {wrong # args: should be "string index string charIndex"}}
230test string-5.3 {string index} {
231    string index abcde 0
232} a
233test string-5.4 {string index} {
234    string in abcde 4
235} e
236test string-5.5 {string index} {
237    string index abcde 5
238} {}
239test string-5.6 {string index} {
240    list [catch {string index abcde -10} msg] $msg
241} {0 {}}
242test string-5.7 {string index} {
243    list [catch {string index a xyz} msg] $msg
244} {1 {bad index "xyz": must be integer?[+-]integer? or end?[+-]integer?}}
245test string-5.8 {string index} {
246    string index abc end
247} c
248test string-5.9 {string index} {
249    string index abc end-1
250} b
251test string-5.10 {string index, unicode} {
252    string index abc\u7266d 4
253} d
254test string-5.11 {string index, unicode} {
255    string index abc\u7266d 3
256} \u7266
257test string-5.12 {string index, unicode over char length, under byte length} {
258    string index \334\374\334\374 6
259} {}
260test string-5.13 {string index, bytearray object} {
261    string index [binary format a5 fuz] 0
262} f
263test string-5.14 {string index, bytearray object} {
264    string index [binary format I* {0x50515253 0x52}] 3
265} S
266test string-5.15 {string index, bytearray object} {
267    set b [binary format I* {0x50515253 0x52}]
268    set i1 [string index $b end-6]
269    set i2 [string index $b 1]
270    string compare $i1 $i2
271} 0
272test string-5.16 {string index, bytearray object with string obj shimmering} {
273    set str "0123456789\x00 abcdedfghi"
274    binary scan $str H* dump
275    string compare [string index $str 10] \x00
276} 0
277test string-5.17 {string index, bad integer} -body {
278    list [catch {string index "abc" 0o8} msg] $msg
279} -match glob -result {1 {*invalid octal number*}}
280test string-5.18 {string index, bad integer} -body {
281    list [catch {string index "abc" end-0o0289} msg] $msg
282} -match glob -result {1 {*invalid octal number*}}
283test string-5.19 {string index, bytearray object out of bounds} {
284    string index [binary format I* {0x50515253 0x52}] -1
285} {}
286test string-5.20 {string index, bytearray object out of bounds} {
287    string index [binary format I* {0x50515253 0x52}] 20
288} {}
289
290
291proc largest_int {} {
292    # This will give us what the largest valid int on this machine is,
293    # so we can test for overflow properly below on >32 bit systems
294    set int 1
295    set exp 7; # assume we get at least 8 bits
296    while {wide($int) > 0} { set int [expr {wide(1) << [incr exp]}] }
297    return [expr {$int-1}]
298}
299
300test string-6.1 {string is, too few args} {
301    list [catch {string is} msg] $msg
302} {1 {wrong # args: should be "string is class ?-strict? ?-failindex var? str"}}
303test string-6.2 {string is, too few args} {
304    list [catch {string is alpha} msg] $msg
305} {1 {wrong # args: should be "string is class ?-strict? ?-failindex var? str"}}
306test string-6.3 {string is, bad args} {
307    list [catch {string is alpha -failin str} msg] $msg
308} {1 {wrong # args: should be "string is alpha ?-strict? ?-failindex var? str"}}
309test string-6.4 {string is, too many args} {
310    list [catch {string is alpha -failin var -strict str more} msg] $msg
311} {1 {wrong # args: should be "string is class ?-strict? ?-failindex var? str"}}
312test string-6.5 {string is, class check} {
313    list [catch {string is bogus str} msg] $msg
314} {1 {bad class "bogus": must be alnum, alpha, ascii, control, boolean, digit, double, false, graph, integer, list, lower, print, punct, space, true, upper, wideinteger, wordchar, or xdigit}}
315test string-6.6 {string is, ambiguous class} {
316    list [catch {string is al str} msg] $msg
317} {1 {ambiguous class "al": must be alnum, alpha, ascii, control, boolean, digit, double, false, graph, integer, list, lower, print, punct, space, true, upper, wideinteger, wordchar, or xdigit}}
318test string-6.7 {string is alpha, all ok} {
319    string is alpha -strict -failindex var abc
320} 1
321test string-6.8 {string is, error in var} {
322    list [string is alpha -failindex var abc5def] $var
323} {0 3}
324test string-6.9 {string is, var shouldn't get set} {
325    catch {unset var}
326    list [catch {string is alpha -failindex var abc; set var} msg] $msg
327} {1 {can't read "var": no such variable}}
328test string-6.10 {string is, ok on empty} {
329    string is alpha {}
330} 1
331test string-6.11 {string is, -strict check against empty} {
332    string is alpha -strict {}
333} 0
334test string-6.12 {string is alnum, true} {
335    string is alnum abc123
336} 1
337test string-6.13 {string is alnum, false} {
338    list [string is alnum -failindex var abc1.23] $var
339} {0 4}
340test string-6.14 {string is alnum, unicode} {
341    string is alnum abcü
342} 1
343test string-6.15 {string is alpha, true} {
344    string is alpha abc
345} 1
346test string-6.16 {string is alpha, false} {
347    list [string is alpha -fail var a1bcde] $var
348} {0 1}
349test string-6.17 {string is alpha, unicode} {
350    string is alpha abc\374
351} 1
352test string-6.18 {string is ascii, true} {
353    string is ascii abc\u007Fend\u0000
354} 1
355test string-6.19 {string is ascii, false} {
356    list [string is ascii -fail var abc\u0000def\u0080more] $var
357} {0 7}
358test string-6.20 {string is boolean, true} {
359    string is boolean true
360} 1
361test string-6.21 {string is boolean, true} {
362    string is boolean f
363} 1
364test string-6.22 {string is boolean, true based on type} {
365    string is bool [string compare a a]
366} 1
367test string-6.23 {string is boolean, false} {
368    list [string is bool -fail var yada] $var
369} {0 0}
370test string-6.24 {string is digit, true} {
371    string is digit 0123456789
372} 1
373test string-6.25 {string is digit, false} {
374    list [string is digit -fail var 0123Ü567] $var
375} {0 4}
376test string-6.26 {string is digit, false} {
377    list [string is digit -fail var +123567] $var
378} {0 0}
379test string-6.27 {string is double, true} {
380    string is double 1
381} 1
382test string-6.28 {string is double, true} {
383    string is double [expr double(1)]
384} 1
385test string-6.29 {string is double, true} {
386    string is double 1.0
387} 1
388test string-6.30 {string is double, true} {
389    string is double [string compare a a]
390} 1
391test string-6.31 {string is double, true} {
392    string is double "   +1.0e-1  "
393} 1
394test string-6.32 {string is double, true} {
395    string is double "\n1.0\v"
396} 1
397test string-6.33 {string is double, false} {
398    list [string is double -fail var 1abc] $var
399} {0 1}
400test string-6.34 {string is double, false} {
401    list [string is double -fail var abc] $var
402} {0 0}
403test string-6.35 {string is double, false} {
404    list [string is double -fail var "   1.0e4e4  "] $var
405} {0 8}
406test string-6.36 {string is double, false} {
407    list [string is double -fail var "\n"] $var
408} {0 0}
409test string-6.37 {string is double, false on int overflow} {
410    # Make it the largest int recognizable, with one more digit for overflow
411    # Since bignums arrived in Tcl 8.5, the sense of this test changed.
412    # Now integer values that exceed native limits become bignums, and
413    # bignums can convert to doubles without error.
414    list [string is double -fail var [largest_int]0] $var
415} {1 0}
416# string-6.38 removed, underflow on input is no longer an error.
417test string-6.39 {string is double, false} {
418    # This test is non-portable because IRIX thinks
419    # that .e1 is a valid double - this is really a bug
420    # on IRIX as .e1 should NOT be a valid double
421    #
422    # Portable now. Tcl 8.5 does its own double parsing.
423
424    list [string is double -fail var .e1] $var
425} {0 0}
426test string-6.40 {string is false, true} {
427    string is false false
428} 1
429test string-6.41 {string is false, true} {
430    string is false FaLsE
431} 1
432test string-6.42 {string is false, true} {
433    string is false N
434} 1
435test string-6.43 {string is false, true} {
436    string is false 0
437} 1
438test string-6.44 {string is false, true} {
439    string is false off
440} 1
441test string-6.45 {string is false, false} {
442    list [string is false -fail var abc] $var
443} {0 0}
444test string-6.46 {string is false, false} {
445    catch {unset var}
446    list [string is false -fail var Y] $var
447} {0 0}
448test string-6.47 {string is false, false} {
449    catch {unset var}
450    list [string is false -fail var offensive] $var
451} {0 0}
452test string-6.48 {string is integer, true} {
453    string is integer +1234567890
454} 1
455test string-6.49 {string is integer, true on type} {
456    string is integer [expr int(50.0)]
457} 1
458test string-6.50 {string is integer, true} {
459    string is integer [list -10]
460} 1
461test string-6.51 {string is integer, true as hex} {
462    string is integer 0xabcdef
463} 1
464test string-6.52 {string is integer, true as octal} {
465    string is integer 012345
466} 1
467test string-6.53 {string is integer, true with whitespace} {
468    string is integer "  \n1234\v"
469} 1
470test string-6.54 {string is integer, false} {
471    list [string is integer -fail var 123abc] $var
472} {0 3}
473test string-6.55 {string is integer, false on overflow} {
474    list [string is integer -fail var +[largest_int]0] $var
475} {0 -1}
476test string-6.56 {string is integer, false} {
477    list [string is integer -fail var [expr double(1)]] $var
478} {0 1}
479test string-6.57 {string is integer, false} {
480    list [string is integer -fail var "    "] $var
481} {0 0}
482test string-6.58 {string is integer, false on bad octal} {
483    list [string is integer -fail var 0o36963] $var
484} {0 4}
485test string-6.58.1 {string is integer, false on bad octal} {
486    list [string is integer -fail var 0o36963] $var
487} {0 4}
488test string-6.59 {string is integer, false on bad hex} {
489    list [string is integer -fail var 0X345XYZ] $var
490} {0 5}
491test string-6.60 {string is lower, true} {
492    string is lower abc
493} 1
494test string-6.61 {string is lower, unicode true} {
495    string is lower abcüue
496} 1
497test string-6.62 {string is lower, false} {
498    list [string is lower -fail var aBc] $var
499} {0 1}
500test string-6.63 {string is lower, false} {
501    list [string is lower -fail var abc1] $var
502} {0 3}
503test string-6.64 {string is lower, unicode false} {
504    list [string is lower -fail var abÜUE] $var
505} {0 2}
506test string-6.65 {string is space, true} {
507    string is space " \t\n\v\f"
508} 1
509test string-6.66 {string is space, false} {
510    list [string is space -fail var " \t\n\v1\f"] $var
511} {0 4}
512test string-6.67 {string is true, true} {
513    string is true true
514} 1
515test string-6.68 {string is true, true} {
516    string is true TrU
517} 1
518test string-6.69 {string is true, true} {
519    string is true ye
520} 1
521test string-6.70 {string is true, true} {
522    string is true 1
523} 1
524test string-6.71 {string is true, true} {
525    string is true on
526} 1
527test string-6.72 {string is true, false} {
528    list [string is true -fail var onto] $var
529} {0 0}
530test string-6.73 {string is true, false} {
531    catch {unset var}
532    list [string is true -fail var 25] $var
533} {0 0}
534test string-6.74 {string is true, false} {
535    catch {unset var}
536    list [string is true -fail var no] $var
537} {0 0}
538test string-6.75 {string is upper, true} {
539    string is upper ABC
540} 1
541test string-6.76 {string is upper, unicode true} {
542    string is upper ABCÜUE
543} 1
544test string-6.77 {string is upper, false} {
545    list [string is upper -fail var AbC] $var
546} {0 1}
547test string-6.78 {string is upper, false} {
548    list [string is upper -fail var AB2C] $var
549} {0 2}
550test string-6.79 {string is upper, unicode false} {
551    list [string is upper -fail var ABCüue] $var
552} {0 3}
553test string-6.80 {string is wordchar, true} {
554    string is wordchar abc_123
555} 1
556test string-6.81 {string is wordchar, unicode true} {
557    string is wordchar abcüabÜAB\u5001
558} 1
559test string-6.82 {string is wordchar, false} {
560    list [string is wordchar -fail var abcd.ef] $var
561} {0 4}
562test string-6.83 {string is wordchar, unicode false} {
563    list [string is wordchar -fail var abc\u0080def] $var
564} {0 3}
565test string-6.84 {string is control} {
566    ## Control chars are in the ranges
567    ## 00..1F && 7F..9F
568    list [string is control -fail var \x00\x01\x10\x1F\x7F\x80\x9F\x60] $var
569} {0 7}
570test string-6.85 {string is control} {
571    string is control \u0100
572} 0
573test string-6.86 {string is graph} {
574    ## graph is any print char, except space
575    list [string is gra -fail var "0123abc!@#\$\u0100 "] $var
576} {0 12}
577test string-6.87 {string is print} {
578    ## basically any printable char
579    list [string is print -fail var "0123abc!@#\$\u0100 \u0010"] $var
580} {0 13}
581test string-6.88 {string is punct} {
582    ## any graph char that isn't alnum
583    list [string is punct -fail var "_!@#\u00beq0"] $var
584} {0 4}
585test string-6.89 {string is xdigit} {
586    list [string is xdigit -fail var 0123456789\u0061bcdefABCDEFg] $var
587} {0 22}
588
589test string-6.90 {string is integer, bad integers} {
590    # SF bug #634856
591    set result ""
592    set numbers [list 1 +1 ++1 +-1 -+1 -1 --1 "- +1"]
593    foreach num $numbers {
594        lappend result [string is int -strict $num]
595    }
596    set result
597} {1 1 0 0 0 1 0 0}
598test string-6.91 {string is double, bad doubles} {
599    set result ""
600    set numbers [list 1.0 +1.0 ++1.0 +-1.0 -+1.0 -1.0 --1.0 "- +1.0"]
601    foreach num $numbers {
602        lappend result [string is double -strict $num]
603    }
604    set result
605} {1 1 0 0 0 1 0 0}
606test string-6.92 {string is double, 32-bit overflow} {
607    # Bug 718878
608    set x 0x100000000
609    list [string is integer -failindex var $x] $var
610} {0 -1}
611test string-6.93 {string is double, 32-bit overflow} {
612    # Bug 718878
613    set x 0x100000000
614    append x ""
615    list [string is integer -failindex var $x] $var
616} {0 -1}
617test string-6.94 {string is double, 32-bit overflow} {
618    # Bug 718878
619    set x 0x100000000
620    list [string is integer -failindex var [expr {$x}]] $var
621} {0 -1}
622test string-6.95 {string is wideinteger, true} {
623    string is wideinteger +1234567890
624} 1
625test string-6.96 {string is wideinteger, true on type} {
626    string is wideinteger [expr wide(50.0)]
627} 1
628test string-6.97 {string is wideinteger, true} {
629    string is wideinteger [list -10]
630} 1
631test string-6.98 {string is wideinteger, true as hex} {
632    string is wideinteger 0xabcdef
633} 1
634test string-6.99 {string is wideinteger, true as octal} {
635    string is wideinteger 0123456
636} 1
637test string-6.100 {string is wideinteger, true with whitespace} {
638    string is wideinteger "  \n1234\v"
639} 1
640test string-6.101 {string is wideinteger, false} {
641    list [string is wideinteger -fail var 123abc] $var
642} {0 3}
643test string-6.102 {string is wideinteger, false on overflow} {
644    list [string is wideinteger -fail var +[largest_int]0] $var
645} {0 -1}
646test string-6.103 {string is wideinteger, false} {
647    list [string is wideinteger -fail var [expr double(1)]] $var
648} {0 1}
649test string-6.104 {string is wideinteger, false} {
650    list [string is wideinteger -fail var "    "] $var
651} {0 0}
652test string-6.105 {string is wideinteger, false on bad octal} {
653    list [string is wideinteger -fail var 0o36963] $var
654} {0 4}
655test string-6.105.1 {string is wideinteger, false on bad octal} {
656    list [string is wideinteger -fail var 0o36963] $var
657} {0 4}
658test string-6.106 {string is wideinteger, false on bad hex} {
659    list [string is wideinteger -fail var 0X345XYZ] $var
660} {0 5}
661test string-6.107 {string is integer, bad integers} {
662    # SF bug #634856
663    set result ""
664    set numbers [list 1 +1 ++1 +-1 -+1 -1 --1 "- +1"]
665    foreach num $numbers {
666        lappend result [string is wideinteger -strict $num]
667    }
668    set result
669} {1 1 0 0 0 1 0 0}
670test string-6.108 {string is double, Bug 1382287} {
671    set x 2turtledoves
672    string is double $x
673    string is double $x
674} 0
675test string-6.109 {string is double, Bug 1360532} {
676    string is double 1\u00a0
677} 0
678
679catch {rename largest_int {}}
680
681test string-7.1 {string last, too few args} {
682    list [catch {string last a} msg] $msg
683} {1 {wrong # args: should be "string last needleString haystackString ?startIndex?"}}
684test string-7.2 {string last, bad args} {
685    list [catch {string last a b c} msg] $msg
686} {1 {bad index "c": must be integer?[+-]integer? or end?[+-]integer?}}
687test string-7.3 {string last, too many args} {
688    list [catch {string last a b c d} msg] $msg
689} {1 {wrong # args: should be "string last needleString haystackString ?startIndex?"}}
690test string-7.4 {string last} {
691    string la xxx xxxx123xx345x678
692} 1
693test string-7.5 {string last} {
694    string last xx xxxx123xx345x678
695} 7
696test string-7.6 {string last} {
697    string las x xxxx123xx345x678
698} 12
699test string-7.7 {string last, unicode} {
700    string las x xxxx12\u7266xx345x678
701} 12
702test string-7.8 {string last, unicode} {
703    string las \u7266 xxxx12\u7266xx345x678
704} 6
705test string-7.9 {string last, stop index} {
706    string las \u7266 xxxx12\u7266xx345x678
707} 6
708test string-7.10 {string last, unicode} {
709    string las \u7266 xxxx12\u7266xx345x678
710} 6
711test string-7.11 {string last, start index} {
712    string last \u7266 abc\u7266x 3
713} 3
714test string-7.12 {string last, start index} {
715    string last \u7266 abc\u7266x 2
716} -1
717test string-7.13 {string last, start index} {
718    ## Constrain to last 'a' should work
719    string last ba badbad end-1
720} 3
721test string-7.14 {string last, start index} {
722    ## Constrain to last 'b' should skip last 'ba'
723    string last ba badbad end-2
724} 0
725test string-7.15 {string last, start index} {
726    string last \334a \334ad\334ad 0
727} -1
728test string-7.16 {string last, start index} {
729    string last \334a \334ad\334ad end-1
730} 3
731
732test string-8.1 {string bytelength} {
733    list [catch {string bytelength} msg] $msg
734} {1 {wrong # args: should be "string bytelength string"}}
735test string-8.2 {string bytelength} {
736    list [catch {string bytelength a b} msg] $msg
737} {1 {wrong # args: should be "string bytelength string"}}
738test string-8.3 {string bytelength} {
739    string bytelength "\u00c7"
740} 2
741test string-8.4 {string bytelength} {
742    string b ""
743} 0
744
745test string-9.1 {string length} {
746    list [catch {string length} msg] $msg
747} {1 {wrong # args: should be "string length string"}}
748test string-9.2 {string length} {
749    list [catch {string length a b} msg] $msg
750} {1 {wrong # args: should be "string length string"}}
751test string-9.3 {string length} {
752    string length "a little string"
753} 15
754test string-9.4 {string length} {
755    string le ""
756} 0
757test string-9.5 {string length, unicode} {
758    string le "abcd\u7266"
759} 5
760test string-9.6 {string length, bytearray object} {
761    string length [binary format a5 foo]
762} 5
763test string-9.7 {string length, bytearray object} {
764    string length [binary format I* {0x50515253 0x52}]
765} 8
766
767test string-10.1 {string map, too few args} {
768    list [catch {string map} msg] $msg
769} {1 {wrong # args: should be "string map ?-nocase? charMap string"}}
770test string-10.2 {string map, bad args} {
771    list [catch {string map {a b} abba oops} msg] $msg
772} {1 {bad option "a b": must be -nocase}}
773test string-10.3 {string map, too many args} {
774    list [catch {string map -nocase {a b} str1 str2} msg] $msg
775} {1 {wrong # args: should be "string map ?-nocase? charMap string"}}
776test string-10.4 {string map} {
777    string map {a b} abba
778} {bbbb}
779test string-10.5 {string map} {
780    string map {a b} a
781} {b}
782test string-10.6 {string map -nocase} {
783    string map -nocase {a b} Abba
784} {bbbb}
785test string-10.7 {string map} {
786    string map {abc 321 ab * a A} aabcabaababcab
787} {A321*A*321*}
788test string-10.8 {string map -nocase} {
789    string map -nocase {aBc 321 Ab * a A} aabcabaababcab
790} {A321*A*321*}
791test string-10.9 {string map -nocase} {
792    string map -no {abc 321 Ab * a A} aAbCaBaAbAbcAb
793} {A321*A*321*}
794test string-10.10 {string map} {
795    list [catch {string map {a b c} abba} msg] $msg
796} {1 {char map list unbalanced}}
797test string-10.11 {string map, nulls} {
798    string map {\x00 NULL blah \x00nix} {qwerty}
799} {qwerty}
800test string-10.12 {string map, unicode} {
801    string map [list \374 ue UE \334] "a\374ueUE\000EU"
802} aueue\334\0EU
803test string-10.13 {string map, -nocase unicode} {
804    string map -nocase [list \374 ue UE \334] "a\374ueUE\000EU"
805} aue\334\334\0EU
806test string-10.14 {string map, -nocase null arguments} {
807    string map -nocase {{} abc} foo
808} foo
809test string-10.15 {string map, one pair case} {
810    string map -nocase {abc 32} aAbCaBaAbAbcAb
811} {a32aBaAb32Ab}
812test string-10.16 {string map, one pair case} {
813    string map -nocase {ab 4321} aAbCaBaAbAbcAb
814} {a4321C4321a43214321c4321}
815test string-10.17 {string map, one pair case} {
816    string map {Ab 4321} aAbCaBaAbAbcAb
817} {a4321CaBa43214321c4321}
818test string-10.18 {string map, empty argument} {
819    string map -nocase {{} abc} foo
820} foo
821test string-10.19 {string map, empty arguments} {
822    string map -nocase {{} abc f bar {} def} foo
823} baroo
824test string-10.20 {string map, dictionaries don't alter map ordering} {
825    set map {aa X a Y}
826    list [string map [dict create aa X a Y] aaa] [string map $map aaa] [dict size $map] [string map $map aaa]
827} {XY XY 2 XY}
828test string-10.21 {string map, ABR checks} {
829    string map {longstring foob} long
830} long
831test string-10.22 {string map, ABR checks} {
832    string map {long foob} long
833} foob
834test string-10.23 {string map, ABR checks} {
835    string map {lon foob} long
836} foobg
837test string-10.24 {string map, ABR checks} {
838    string map {lon foob} longlo
839} foobglo
840test string-10.25 {string map, ABR checks} {
841    string map {lon foob} longlon
842} foobgfoob
843test string-10.26 {string map, ABR checks} {
844    string map {longstring foob longstring bar} long
845} long
846test string-10.27 {string map, ABR checks} {
847    string map {long foob longstring bar} long
848} foob
849test string-10.28 {string map, ABR checks} {
850    string map {lon foob longstring bar} long
851} foobg
852test string-10.29 {string map, ABR checks} {
853    string map {lon foob longstring bar} longlo
854} foobglo
855test string-10.30 {string map, ABR checks} {
856    string map {lon foob longstring bar} longlon
857} foobgfoob
858test string-10.31 {string map, nasty sharing crash from [Bug 1018562]} {
859    set a {a b}
860    string map $a $a
861} {b b}
862
863test string-11.1 {string match, too few args} {
864    list [catch {string match a} msg] $msg
865} {1 {wrong # args: should be "string match ?-nocase? pattern string"}}
866test string-11.2 {string match, too many args} {
867    list [catch {string match a b c d} msg] $msg
868} {1 {wrong # args: should be "string match ?-nocase? pattern string"}}
869test string-11.3 {string match} {
870    string match abc abc
871} 1
872test string-11.4 {string match} {
873    string mat abc abd
874} 0
875test string-11.5 {string match} {
876    string match ab*c abc
877} 1
878test string-11.6 {string match} {
879    string match ab**c abc
880} 1
881test string-11.7 {string match} {
882    string match ab* abcdef
883} 1
884test string-11.8 {string match} {
885    string match *c abc
886} 1
887test string-11.9 {string match} {
888    string match *3*6*9 0123456789
889} 1
890test string-11.9.1 {string match} {
891    string match *3*6*89 0123456789
892} 1
893test string-11.9.2 {string match} {
894    string match *3*456*89 0123456789
895} 1
896test string-11.9.3 {string match} {
897    string match *3*6* 0123456789
898} 1
899test string-11.9.4 {string match} {
900    string match *3*56* 0123456789
901} 1
902test string-11.9.5 {string match} {
903    string match *3*456*** 0123456789
904} 1
905test string-11.9.6 {string match} {
906    string match **3*456** 0123456789
907} 1
908test string-11.9.7 {string match} {
909    string match *3***456* 0123456789
910} 1
911test string-11.9.8 {string match} {
912    string match *3***\[456]* 0123456789
913} 1
914test string-11.9.9 {string match} {
915    string match *3***\[4-6]* 0123456789
916} 1
917test string-11.9.10 {string match} {
918    string match *3***\[4-6] 0123456789
919} 0
920test string-11.9.11 {string match} {
921    string match *3***\[4-6] 0123456
922} 1
923test string-11.10 {string match} {
924    string match *3*6*9 01234567890
925} 0
926test string-11.10.1 {string match} {
927    string match *3*6*89 01234567890
928} 0
929test string-11.10.2 {string match} {
930    string match *3*456*89 01234567890
931} 0
932test string-11.10.3 {string match} {
933    string match **3*456*89 01234567890
934} 0
935test string-11.10.4 {string match} {
936    string match *3*456***89 01234567890
937} 0
938test string-11.11 {string match} {
939    string match a?c abc
940} 1
941test string-11.12 {string match} {
942    string match a??c abc
943} 0
944test string-11.13 {string match} {
945    string match ?1??4???8? 0123456789
946} 1
947test string-11.14 {string match} {
948    string match {[abc]bc} abc
949} 1
950test string-11.15 {string match} {
951    string match {a[abc]c} abc
952} 1
953test string-11.16 {string match} {
954    string match {a[xyz]c} abc
955} 0
956test string-11.17 {string match} {
957    string match {12[2-7]45} 12345
958} 1
959test string-11.18 {string match} {
960    string match {12[ab2-4cd]45} 12345
961} 1
962test string-11.19 {string match} {
963    string match {12[ab2-4cd]45} 12b45
964} 1
965test string-11.20 {string match} {
966    string match {12[ab2-4cd]45} 12d45
967} 1
968test string-11.21 {string match} {
969    string match {12[ab2-4cd]45} 12145
970} 0
971test string-11.22 {string match} {
972    string match {12[ab2-4cd]45} 12545
973} 0
974test string-11.23 {string match} {
975    string match {a\*b} a*b
976} 1
977test string-11.24 {string match} {
978    string match {a\*b} ab
979} 0
980test string-11.25 {string match} {
981    string match {a\*\?\[\]\\\x} "a*?\[\]\\x"
982} 1
983test string-11.26 {string match} {
984    string match ** ""
985} 1
986test string-11.27 {string match} {
987    string match *. ""
988} 0
989test string-11.28 {string match} {
990    string match "" ""
991} 1
992test string-11.29 {string match} {
993    string match \[a a
994} 1
995test string-11.30 {string match, bad args} {
996    list [catch {string match - b c} msg] $msg
997} {1 {bad option "-": must be -nocase}}
998test string-11.31 {string match case} {
999    string match a A
1000} 0
1001test string-11.32 {string match nocase} {
1002    string match -n a A
1003} 1
1004test string-11.33 {string match nocase} {
1005    string match -nocase a\334 A\374
1006} 1
1007test string-11.34 {string match nocase} {
1008    string match -nocase a*f ABCDEf
1009} 1
1010test string-11.35 {string match case, false hope} {
1011    # This is true because '_' lies between the A-Z and a-z ranges
1012    string match {[A-z]} _
1013} 1
1014test string-11.36 {string match nocase range} {
1015    # This is false because although '_' lies between the A-Z and a-z ranges,
1016    # we lower case the end points before checking the ranges.
1017    string match -nocase {[A-z]} _
1018} 0
1019test string-11.37 {string match nocase} {
1020    string match -nocase {[A-fh-Z]} g
1021} 0
1022test string-11.38 {string match case, reverse range} {
1023    string match {[A-fh-Z]} g
1024} 1
1025test string-11.39 {string match, *\ case} {
1026    string match {*\abc} abc
1027} 1
1028test string-11.39.1 {string match, *\ case} {
1029    string match {*ab\c} abc
1030} 1
1031test string-11.39.2 {string match, *\ case} {
1032    string match {*ab\*} ab*
1033} 1
1034test string-11.39.3 {string match, *\ case} {
1035    string match {*ab\*} abc
1036} 0
1037test string-11.39.4 {string match, *\ case} {
1038    string match {*ab\\*} {ab\c}
1039} 1
1040test string-11.39.5 {string match, *\ case} {
1041    string match {*ab\\*} {ab\*}
1042} 1
1043test string-11.40 {string match, *special case} {
1044    string match {*[ab]} abc
1045} 0
1046test string-11.41 {string match, *special case} {
1047    string match {*[ab]*} abc
1048} 1
1049test string-11.42 {string match, *special case} {
1050    string match "*\\" "\\"
1051} 0
1052test string-11.43 {string match, *special case} {
1053    string match "*\\\\" "\\"
1054} 1
1055test string-11.44 {string match, *special case} {
1056    string match "*???" "12345"
1057} 1
1058test string-11.45 {string match, *special case} {
1059    string match "*???" "12"
1060} 0
1061test string-11.46 {string match, *special case} {
1062    string match "*\\*" "abc*"
1063} 1
1064test string-11.47 {string match, *special case} {
1065    string match "*\\*" "*"
1066} 1
1067test string-11.48 {string match, *special case} {
1068    string match "*\\*" "*abc"
1069} 0
1070test string-11.49 {string match, *special case} {
1071    string match "?\\*" "a*"
1072} 1
1073test string-11.50 {string match, *special case} {
1074    string match "\\" "\\"
1075} 0
1076test string-11.51 {string match; *, -nocase and UTF-8} {
1077    string match -nocase [binary format I 717316707] \
1078            [binary format I 2028036707]
1079} 1
1080test string-11.52 {string match, null char in string} {
1081    set out ""
1082    set ptn "*abc*"
1083    foreach elem [list "\u0000@abc" "@abc" "\u0000@abc\u0000" "blahabcblah"] {
1084        lappend out [string match $ptn $elem]
1085    }
1086    set out
1087} {1 1 1 1}
1088test string-11.53 {string match, null char in pattern} {
1089    set out ""
1090    foreach {ptn elem} [list \
1091            "*\u0000abc\u0000"  "\u0000abc\u0000" \
1092            "*\u0000abc\u0000"  "\u0000abc\u0000ef" \
1093            "*\u0000abc\u0000*" "\u0000abc\u0000ef" \
1094            "*\u0000abc\u0000"  "@\u0000abc\u0000ef" \
1095            "*\u0000abc\u0000*"  "@\u0000abc\u0000ef" \
1096            ] {
1097        lappend out [string match $ptn $elem]
1098    }
1099    set out
1100} {1 0 1 0 1}
1101test string-11.54 {string match, failure} {
1102    set longString ""
1103    for {set i 0} {$i < 10} {incr i} {
1104        append longString "abcdefghijklmnopqrstuvwxy\u0000z01234567890123"
1105    }
1106    string first $longString 123
1107    list [string match *cba* $longString] \
1108            [string match *a*l*\u0000* $longString] \
1109            [string match *a*l*\u0000*123 $longString] \
1110            [string match *a*l*\u0000*123* $longString] \
1111            [string match *a*l*\u0000*cba* $longString] \
1112            [string match *===* $longString]
1113} {0 1 1 1 0 0}
1114
1115test string-12.1 {string range} {
1116    list [catch {string range} msg] $msg
1117} {1 {wrong # args: should be "string range string first last"}}
1118test string-12.2 {string range} {
1119    list [catch {string range a 1} msg] $msg
1120} {1 {wrong # args: should be "string range string first last"}}
1121test string-12.3 {string range} {
1122    list [catch {string range a 1 2 3} msg] $msg
1123} {1 {wrong # args: should be "string range string first last"}}
1124test string-12.4 {string range} {
1125    string range abcdefghijklmnop 2 14
1126} {cdefghijklmno}
1127test string-12.5 {string range, last > length} {
1128    string range abcdefghijklmnop 7 1000
1129} {hijklmnop}
1130test string-12.6 {string range} {
1131    string range abcdefghijklmnop 10 end
1132} {klmnop}
1133test string-12.7 {string range, last < first} {
1134    string range abcdefghijklmnop 10 9
1135} {}
1136test string-12.8 {string range, first < 0} {
1137    string range abcdefghijklmnop -3 2
1138} {abc}
1139test string-12.9 {string range} {
1140    string range abcdefghijklmnop -3 -2
1141} {}
1142test string-12.10 {string range} {
1143    string range abcdefghijklmnop 1000 1010
1144} {}
1145test string-12.11 {string range} {
1146    string range abcdefghijklmnop -100 end
1147} {abcdefghijklmnop}
1148test string-12.12 {string range} {
1149    list [catch {string range abc abc 1} msg] $msg
1150} {1 {bad index "abc": must be integer?[+-]integer? or end?[+-]integer?}}
1151test string-12.13 {string range} {
1152    list [catch {string range abc 1 eof} msg] $msg
1153} {1 {bad index "eof": must be integer?[+-]integer? or end?[+-]integer?}}
1154test string-12.14 {string range} {
1155    string range abcdefghijklmnop end-1 end
1156} {op}
1157test string-12.15 {string range} {
1158    string range abcdefghijklmnop end 1000
1159} {p}
1160test string-12.16 {string range} {
1161    string range abcdefghijklmnop end end-1
1162} {}
1163test string-12.17 {string range, unicode} {
1164    string range ab\u7266cdefghijklmnop 5 5
1165} e
1166test string-12.18 {string range, unicode} {
1167    string range ab\u7266cdefghijklmnop 2 3
1168} \u7266c
1169test string-12.19 {string range, bytearray object} {
1170    set b [binary format I* {0x50515253 0x52}]
1171    set r1 [string range $b 1 end-1]
1172    set r2 [string range $b 1 6]
1173    string equal $r1 $r2
1174} 1
1175test string-12.20 {string range, out of bounds indices} {
1176    string range \u00ff 0 1
1177} \u00ff
1178# Bug 1410553
1179test string-12.21 {string range, regenerates correct reps, bug 1410553} {
1180    set bytes "\x00 \x03 \x41"
1181    set rxBuffer {}
1182    foreach ch $bytes {
1183        append rxBuffer $ch
1184        if {$ch eq "\x03"} {
1185            string length $rxBuffer
1186        }
1187    }
1188    set rxCRC [string range $rxBuffer end-1 end]
1189    binary scan [join $bytes {}] "H*" input_hex
1190    binary scan $rxBuffer "H*" rxBuffer_hex
1191    binary scan $rxCRC "H*" rxCRC_hex
1192    list $input_hex $rxBuffer_hex $rxCRC_hex
1193} {000341 000341 0341}
1194test string-12.22 {string range, shimmering binary/index} {
1195    set s 0000000001
1196    binary scan $s a* x
1197    string range $s $s end
1198} 000000001
1199
1200test string-13.1 {string repeat} {
1201    list [catch {string repeat} msg] $msg
1202} {1 {wrong # args: should be "string repeat string count"}}
1203test string-13.2 {string repeat} {
1204    list [catch {string repeat abc 10 oops} msg] $msg
1205} {1 {wrong # args: should be "string repeat string count"}}
1206test string-13.3 {string repeat} {
1207    string repeat {} 100
1208} {}
1209test string-13.4 {string repeat} {
1210    string repeat { } 5
1211} {     }
1212test string-13.5 {string repeat} {
1213    string repeat abc 3
1214} {abcabcabc}
1215test string-13.6 {string repeat} {
1216    string repeat abc -1
1217} {}
1218test string-13.7 {string repeat} {
1219    list [catch {string repeat abc end} msg] $msg
1220} {1 {expected integer but got "end"}}
1221test string-13.8 {string repeat} {
1222    string repeat {} -1000
1223} {}
1224test string-13.9 {string repeat} {
1225    string repeat {} 0
1226} {}
1227test string-13.10 {string repeat} {
1228    string repeat def 0
1229} {}
1230test string-13.11 {string repeat} {
1231    string repeat def 1
1232} def
1233test string-13.12 {string repeat} {
1234    string repeat ab\u7266cd 3
1235} ab\u7266cdab\u7266cdab\u7266cd
1236test string-13.13 {string repeat} {
1237    string repeat \x00 3
1238} \x00\x00\x00
1239test string-13.14 {string repeat} {
1240    # The string range will ensure us that string repeat gets a unicode string
1241    string repeat [string range ab\u7266cd 2 3] 3
1242} \u7266c\u7266c\u7266c
1243
1244test string-14.1 {string replace} {
1245    list [catch {string replace} msg] $msg
1246} {1 {wrong # args: should be "string replace string first last ?string?"}}
1247test string-14.2 {string replace} {
1248    list [catch {string replace a 1} msg] $msg
1249} {1 {wrong # args: should be "string replace string first last ?string?"}}
1250test string-14.3 {string replace} {
1251    list [catch {string replace a 1 2 3 4} msg] $msg
1252} {1 {wrong # args: should be "string replace string first last ?string?"}}
1253test string-14.4 {string replace} {
1254} {}
1255test string-14.5 {string replace} {
1256    string replace abcdefghijklmnop 2 14
1257} {abp}
1258test string-14.6 {string replace} {
1259    string replace abcdefghijklmnop 7 1000
1260} {abcdefg}
1261test string-14.7 {string replace} {
1262    string replace abcdefghijklmnop 10 end
1263} {abcdefghij}
1264test string-14.8 {string replace} {
1265    string replace abcdefghijklmnop 10 9
1266} {abcdefghijklmnop}
1267test string-14.9 {string replace} {
1268    string replace abcdefghijklmnop -3 2
1269} {defghijklmnop}
1270test string-14.10 {string replace} {
1271    string replace abcdefghijklmnop -3 -2
1272} {abcdefghijklmnop}
1273test string-14.11 {string replace} {
1274    string replace abcdefghijklmnop 1000 1010
1275} {abcdefghijklmnop}
1276test string-14.12 {string replace} {
1277    string replace abcdefghijklmnop -100 end
1278} {}
1279test string-14.13 {string replace} {
1280    list [catch {string replace abc abc 1} msg] $msg
1281} {1 {bad index "abc": must be integer?[+-]integer? or end?[+-]integer?}}
1282test string-14.14 {string replace} {
1283    list [catch {string replace abc 1 eof} msg] $msg
1284} {1 {bad index "eof": must be integer?[+-]integer? or end?[+-]integer?}}
1285test string-14.15 {string replace} {
1286    string replace abcdefghijklmnop end-10 end-2 NEW
1287} {abcdeNEWop}
1288test string-14.16 {string replace} {
1289    string replace abcdefghijklmnop 0 end foo
1290} {foo}
1291test string-14.17 {string replace} {
1292    string replace abcdefghijklmnop end end-1
1293} {abcdefghijklmnop}
1294
1295test string-15.1 {string tolower too few args} {
1296    list [catch {string tolower} msg] $msg
1297} {1 {wrong # args: should be "string tolower string ?first? ?last?"}}
1298test string-15.2 {string tolower bad args} {
1299    list [catch {string tolower a b} msg] $msg
1300} {1 {bad index "b": must be integer?[+-]integer? or end?[+-]integer?}}
1301test string-15.3 {string tolower too many args} {
1302    list [catch {string tolower ABC 1 end oops} msg] $msg
1303} {1 {wrong # args: should be "string tolower string ?first? ?last?"}}
1304test string-15.4 {string tolower} {
1305    string tolower ABCDeF
1306} {abcdef}
1307test string-15.5 {string tolower} {
1308    string tolower "ABC  XyZ"
1309} {abc  xyz}
1310test string-15.6 {string tolower} {
1311    string tolower {123#$&*()}
1312} {123#$&*()}
1313test string-15.7 {string tolower} {
1314    string tolower ABC 1
1315} AbC
1316test string-15.8 {string tolower} {
1317    string tolower ABC 1 end
1318} Abc
1319test string-15.9 {string tolower} {
1320    string tolower ABC 0 end-1
1321} abC
1322test string-15.10 {string tolower, unicode} {
1323     string tolower ABCabc\xc7\xe7
1324} "abcabc\xe7\xe7"
1325
1326test string-16.1 {string toupper} {
1327    list [catch {string toupper} msg] $msg
1328} {1 {wrong # args: should be "string toupper string ?first? ?last?"}}
1329test string-16.2 {string toupper} {
1330    list [catch {string toupper a b} msg] $msg
1331} {1 {bad index "b": must be integer?[+-]integer? or end?[+-]integer?}}
1332test string-16.3 {string toupper} {
1333    list [catch {string toupper a 1 end oops} msg] $msg
1334} {1 {wrong # args: should be "string toupper string ?first? ?last?"}}
1335test string-16.4 {string toupper} {
1336    string toupper abCDEf
1337} {ABCDEF}
1338test string-16.5 {string toupper} {
1339    string toupper "abc xYz"
1340} {ABC XYZ}
1341test string-16.6 {string toupper} {
1342    string toupper {123#$&*()}
1343} {123#$&*()}
1344test string-16.7 {string toupper} {
1345    string toupper abc 1
1346} aBc
1347test string-16.8 {string toupper} {
1348    string toupper abc 1 end
1349} aBC
1350test string-16.9 {string toupper} {
1351    string toupper abc 0 end-1
1352} ABc
1353test string-16.10 {string toupper, unicode} {
1354    string toupper ABCabc\xc7\xe7
1355} "ABCABC\xc7\xc7"
1356
1357test string-17.1 {string totitle} {
1358    list [catch {string totitle} msg] $msg
1359} {1 {wrong # args: should be "string totitle string ?first? ?last?"}}
1360test string-17.2 {string totitle} {
1361    list [catch {string totitle a b} msg] $msg
1362} {1 {bad index "b": must be integer?[+-]integer? or end?[+-]integer?}}
1363test string-17.3 {string totitle} {
1364    string totitle abCDEf
1365} {Abcdef}
1366test string-17.4 {string totitle} {
1367    string totitle "abc xYz"
1368} {Abc xyz}
1369test string-17.5 {string totitle} {
1370    string totitle {123#$&*()}
1371} {123#$&*()}
1372test string-17.6 {string totitle, unicode} {
1373    string totitle ABCabc\xc7\xe7
1374} "Abcabc\xe7\xe7"
1375test string-17.7 {string totitle, unicode} {
1376    string totitle \u01f3BCabc\xc7\xe7
1377} "\u01f2bcabc\xe7\xe7"
1378
1379test string-18.1 {string trim} {
1380    list [catch {string trim} msg] $msg
1381} {1 {wrong # args: should be "string trim string ?chars?"}}
1382test string-18.2 {string trim} {
1383    list [catch {string trim a b c} msg] $msg
1384} {1 {wrong # args: should be "string trim string ?chars?"}}
1385test string-18.3 {string trim} {
1386    string trim "    XYZ      "
1387} {XYZ}
1388test string-18.4 {string trim} {
1389    string trim "\t\nXYZ\t\n\r\n"
1390} {XYZ}
1391test string-18.5 {string trim} {
1392    string trim "  A XYZ A    "
1393} {A XYZ A}
1394test string-18.6 {string trim} {
1395    string trim "XXYYZZABC XXYYZZ" ZYX
1396} {ABC }
1397test string-18.7 {string trim} {
1398    string trim "    \t\r      "
1399} {}
1400test string-18.8 {string trim} {
1401    string trim {abcdefg} {}
1402} {abcdefg}
1403test string-18.9 {string trim} {
1404    string trim {}
1405} {}
1406test string-18.10 {string trim} {
1407    string trim ABC DEF
1408} {ABC}
1409test string-18.11 {string trim, unicode} {
1410    string trim "\xe7\xe8 AB\xe7C \xe8\xe7" \xe7\xe8
1411} " AB\xe7C "
1412
1413test string-19.1 {string trimleft} {
1414    list [catch {string trimleft} msg] $msg
1415} {1 {wrong # args: should be "string trimleft string ?chars?"}}
1416test string-19.2 {string trimleft} {
1417    string trimleft "    XYZ      "
1418} {XYZ      }
1419
1420test string-20.1 {string trimright errors} {
1421    list [catch {string trimright} msg] $msg
1422} {1 {wrong # args: should be "string trimright string ?chars?"}}
1423test string-20.2 {string trimright errors} {
1424    list [catch {string trimg a} msg] $msg
1425} {1 {unknown or ambiguous subcommand "trimg": must be bytelength, compare, equal, first, index, is, last, length, map, match, range, repeat, replace, reverse, tolower, totitle, toupper, trim, trimleft, trimright, wordend, or wordstart}}
1426test string-20.3 {string trimright} {
1427    string trimright "    XYZ      "
1428} {    XYZ}
1429test string-20.4 {string trimright} {
1430    string trimright "   "
1431} {}
1432test string-20.5 {string trimright} {
1433    string trimright ""
1434} {}
1435
1436test string-21.1 {string wordend} {
1437    list [catch {string wordend a} msg] $msg
1438} {1 {wrong # args: should be "string wordend string index"}}
1439test string-21.2 {string wordend} {
1440    list [catch {string wordend a b c} msg] $msg
1441} {1 {wrong # args: should be "string wordend string index"}}
1442test string-21.3 {string wordend} {
1443    list [catch {string wordend a gorp} msg] $msg
1444} {1 {bad index "gorp": must be integer?[+-]integer? or end?[+-]integer?}}
1445test string-21.4 {string wordend} {
1446    string wordend abc. -1
1447} 3
1448test string-21.5 {string wordend} {
1449    string wordend abc. 100
1450} 4
1451test string-21.6 {string wordend} {
1452    string wordend "word_one two three" 2
1453} 8
1454test string-21.7 {string wordend} {
1455    string wordend "one .&# three" 5
1456} 6
1457test string-21.8 {string wordend} {
1458    string worde "x.y" 0
1459} 1
1460test string-21.9 {string wordend} {
1461    string worde "x.y" end-1
1462} 2
1463test string-21.10 {string wordend, unicode} {
1464    string wordend "xyz\u00c7de fg" 0
1465} 6
1466test string-21.11 {string wordend, unicode} {
1467    string wordend "xyz\uc700de fg" 0
1468} 6
1469test string-21.12 {string wordend, unicode} {
1470    string wordend "xyz\u203fde fg" 0
1471} 6
1472test string-21.13 {string wordend, unicode} {
1473    string wordend "xyz\u2045de fg" 0
1474} 3
1475test string-21.14 {string wordend, unicode} {
1476    string wordend "\uc700\uc700 abc" 8
1477} 6
1478
1479test string-22.1 {string wordstart} {
1480    list [catch {string word a} msg] $msg
1481} {1 {unknown or ambiguous subcommand "word": must be bytelength, compare, equal, first, index, is, last, length, map, match, range, repeat, replace, reverse, tolower, totitle, toupper, trim, trimleft, trimright, wordend, or wordstart}}
1482test string-22.2 {string wordstart} {
1483    list [catch {string wordstart a} msg] $msg
1484} {1 {wrong # args: should be "string wordstart string index"}}
1485test string-22.3 {string wordstart} {
1486    list [catch {string wordstart a b c} msg] $msg
1487} {1 {wrong # args: should be "string wordstart string index"}}
1488test string-22.4 {string wordstart} {
1489    list [catch {string wordstart a gorp} msg] $msg
1490} {1 {bad index "gorp": must be integer?[+-]integer? or end?[+-]integer?}}
1491test string-22.5 {string wordstart} {
1492    string wordstart "one two three_words" 400
1493} 8
1494test string-22.6 {string wordstart} {
1495    string wordstart "one two three_words" 2
1496} 0
1497test string-22.7 {string wordstart} {
1498    string wordstart "one two three_words" -2
1499} 0
1500test string-22.8 {string wordstart} {
1501    string wordstart "one .*&^ three" 6
1502} 6
1503test string-22.9 {string wordstart} {
1504    string wordstart "one two three" 4
1505} 4
1506test string-22.10 {string wordstart} {
1507    string wordstart "one two three" end-5
1508} 7
1509test string-22.11 {string wordstart, unicode} {
1510    string wordstart "one tw\u00c7o three" 7
1511} 4
1512test string-22.12 {string wordstart, unicode} {
1513    string wordstart "ab\uc700\uc700 cdef ghi" 12
1514} 10
1515test string-22.13 {string wordstart, unicode} {
1516    string wordstart "\uc700\uc700 abc" 8
1517} 3
1518
1519test string-23.0 {string is boolean, Bug 1187123} testindexobj {
1520    set x 5
1521    catch {testindexobj $x foo bar soom}
1522    string is boolean $x
1523} 0
1524test string-23.1 {string is command with empty string} {
1525    set s ""
1526    list \
1527        [string is alnum $s] \
1528        [string is alpha $s] \
1529        [string is ascii $s] \
1530        [string is control $s] \
1531        [string is boolean $s] \
1532        [string is digit $s] \
1533        [string is double $s] \
1534        [string is false $s] \
1535        [string is graph $s] \
1536        [string is integer $s] \
1537        [string is lower $s] \
1538        [string is print $s] \
1539        [string is punct $s] \
1540        [string is space $s] \
1541        [string is true $s] \
1542        [string is upper $s] \
1543        [string is wordchar $s] \
1544        [string is xdigit $s] \
1545
1546} {1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1}
1547test string-23.2 {string is command with empty string} {
1548    set s ""
1549    list \
1550        [string is alnum -strict $s] \
1551        [string is alpha -strict $s] \
1552        [string is ascii -strict $s] \
1553        [string is control -strict $s] \
1554        [string is boolean -strict $s] \
1555        [string is digit -strict $s] \
1556        [string is double -strict $s] \
1557        [string is false -strict $s] \
1558        [string is graph -strict $s] \
1559        [string is integer -strict $s] \
1560        [string is lower -strict $s] \
1561        [string is print -strict $s] \
1562        [string is punct -strict $s] \
1563        [string is space -strict $s] \
1564        [string is true -strict $s] \
1565        [string is upper -strict $s] \
1566        [string is wordchar -strict $s] \
1567        [string is xdigit -strict $s] \
1568
1569} {0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0}
1570
1571test string-24.1 {string reverse command} -body {
1572    string reverse
1573} -returnCodes error -result "wrong # args: should be \"string reverse string\""
1574test string-24.2 {string reverse command} -body {
1575    string reverse a b
1576} -returnCodes error -result "wrong # args: should be \"string reverse string\""
1577test string-24.3 {string reverse command - shared string} {
1578    set x abcde
1579    string reverse $x
1580} edcba
1581test string-24.4 {string reverse command - unshared string} {
1582    set x abc
1583    set y de
1584    string reverse $x$y
1585} edcba
1586test string-24.5 {string reverse command - shared unicode string} {
1587    set x abcde\udead
1588    string reverse $x
1589} \udeadedcba
1590test string-24.6 {string reverse command - unshared string} {
1591    set x abc
1592    set y de\udead
1593    string reverse $x$y
1594} \udeadedcba
1595test string-24.7 {string reverse command - simple case} {
1596    string reverse a
1597} a
1598test string-24.8 {string reverse command - simple case} {
1599    string reverse \udead
1600} \udead
1601test string-24.9 {string reverse command - simple case} {
1602    string reverse {}
1603} {}
1604test string-24.10 {string reverse command - corner case} {
1605    set x \ubeef\udead
1606    string reverse $x
1607} \udead\ubeef
1608test string-24.11 {string reverse command - corner case} {
1609    set x \ubeef
1610    set y \udead
1611    string reverse $x$y
1612} \udead\ubeef
1613
1614test string-25.1 {string is list} {
1615    string is list {a b c}
1616} 1
1617test string-25.2 {string is list} {
1618    string is list "a \{b c"
1619} 0
1620test string-25.3 {string is list} {
1621    string is list {a {b c}d e}
1622} 0
1623test string-25.4 {string is list} {
1624    string is list {}
1625} 1
1626test string-25.5 {string is list} {
1627    string is list -strict {a b c}
1628} 1
1629test string-25.6 {string is list} {
1630    string is list -strict "a \{b c"
1631} 0
1632test string-25.7 {string is list} {
1633    string is list -strict {a {b c}d e}
1634} 0
1635test string-25.8 {string is list} {
1636    string is list -strict {}
1637} 1
1638test string-25.9 {string is list} {
1639    set x {}
1640    list [string is list -failindex x {a b c}] $x
1641} {1 {}}
1642test string-25.10 {string is list} {
1643    set x {}
1644    list [string is list -failindex x "a \{b c"] $x
1645} {0 2}
1646test string-25.11 {string is list} {
1647    set x {}
1648    list [string is list -failindex x {a b {b c}d e}] $x
1649} {0 4}
1650test string-25.12 {string is list} {
1651    set x {}
1652    list [string is list -failindex x {}] $x
1653} {1 {}}
1654test string-25.13 {string is list} {
1655    set x {}
1656    list [string is list -failindex x {  {b c}d e}] $x
1657} {0 2}
1658test string-25.14 {string is list} {
1659    set x {}
1660    list [string is list -failindex x "\uabcd {b c}d e"] $x
1661} {0 2}
1662
1663# cleanup
1664::tcltest::cleanupTests
1665return
1666
1667# Local Variables:
1668# mode: tcl
1669# End:
Note: See TracBrowser for help on using the repository browser.