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