os/persistentdata/persistentstorage/sqlite3api/TEST/TCL/tcldistribution/tests/string.test
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/persistentdata/persistentstorage/sqlite3api/TEST/TCL/tcldistribution/tests/string.test Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,1399 @@
1.4 +# Commands covered: string
1.5 +#
1.6 +# This file contains a collection of tests for one or more of the Tcl
1.7 +# built-in commands. Sourcing this file into Tcl runs the tests and
1.8 +# generates output for errors. No output means no errors were found.
1.9 +#
1.10 +# Copyright (c) 1991-1993 The Regents of the University of California.
1.11 +# Copyright (c) 1994 Sun Microsystems, Inc.
1.12 +# Copyright (c) 1998-1999 by Scriptics Corporation.
1.13 +# Copyright (c) 2001 by Kevin B. Kenny. All rights reserved.
1.14 +#
1.15 +# See the file "license.terms" for information on usage and redistribution
1.16 +# of this file, and for a DISCLAIMER OF ALL WARRANTIES.
1.17 +#
1.18 +# RCS: @(#) $Id: string.test,v 1.36.2.7 2006/01/23 12:11:15 msofer Exp $
1.19 +
1.20 +if {[lsearch [namespace children] ::tcltest] == -1} {
1.21 + package require tcltest
1.22 + namespace import -force ::tcltest::*
1.23 +}
1.24 +
1.25 +# Some tests require the testobj command
1.26 +
1.27 +set ::tcltest::testConstraints(testobj) \
1.28 + [expr {[info commands testobj] != {}}]
1.29 +set ::tcltest::testConstraints(testindexobj) \
1.30 + [expr {[info commands testindexobj] != {}}]
1.31 +
1.32 +test string-1.1 {error conditions} {
1.33 + list [catch {string gorp a b} msg] $msg
1.34 +} {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}}
1.35 +test string-1.2 {error conditions} {
1.36 + list [catch {string} msg] $msg
1.37 +} {1 {wrong # args: should be "string option arg ?arg ...?"}}
1.38 +
1.39 +test string-2.1 {string compare, too few args} {
1.40 + list [catch {string compare a} msg] $msg
1.41 +} {1 {wrong # args: should be "string compare ?-nocase? ?-length int? string1 string2"}}
1.42 +test string-2.2 {string compare, bad args} {
1.43 + list [catch {string compare a b c} msg] $msg
1.44 +} {1 {bad option "a": must be -nocase or -length}}
1.45 +test string-2.3 {string compare, bad args} {
1.46 + list [catch {string compare -length -nocase str1 str2} msg] $msg
1.47 +} {1 {expected integer but got "-nocase"}}
1.48 +test string-2.4 {string compare, too many args} {
1.49 + list [catch {string compare -length 10 -nocase str1 str2 str3} msg] $msg
1.50 +} {1 {wrong # args: should be "string compare ?-nocase? ?-length int? string1 string2"}}
1.51 +test string-2.5 {string compare with length unspecified} {
1.52 + list [catch {string compare -length 10 10} msg] $msg
1.53 +} {1 {wrong # args: should be "string compare ?-nocase? ?-length int? string1 string2"}}
1.54 +test string-2.6 {string compare} {
1.55 + string compare abcde abdef
1.56 +} -1
1.57 +test string-2.7 {string compare, shortest method name} {
1.58 + string c abcde ABCDE
1.59 +} 1
1.60 +test string-2.8 {string compare} {
1.61 + string compare abcde abcde
1.62 +} 0
1.63 +test string-2.9 {string compare with length} {
1.64 + string compare -length 2 abcde abxyz
1.65 +} 0
1.66 +test string-2.10 {string compare with special index} {
1.67 + list [catch {string compare -length end-3 abcde abxyz} msg] $msg
1.68 +} {1 {expected integer but got "end-3"}}
1.69 +test string-2.11 {string compare, unicode} {
1.70 + string compare ab\u7266 ab\u7267
1.71 +} -1
1.72 +test string-2.12 {string compare, high bit} {
1.73 + # This test will fail if the underlying comparaison
1.74 + # is using signed chars instead of unsigned chars.
1.75 + # (like SunOS's default memcmp thus the compat/memcmp.c)
1.76 + string compare "\x80" "@"
1.77 + # Nb this tests works also in utf8 space because \x80 is
1.78 + # translated into a 2 or more bytelength but whose first byte has
1.79 + # the high bit set.
1.80 +} 1
1.81 +test string-2.13 {string compare -nocase} {
1.82 + string compare -nocase abcde abdef
1.83 +} -1
1.84 +test string-2.14 {string compare -nocase} {
1.85 + string c -nocase abcde ABCDE
1.86 +} 0
1.87 +test string-2.15 {string compare -nocase} {
1.88 + string compare -nocase abcde abcde
1.89 +} 0
1.90 +test string-2.16 {string compare -nocase with length} {
1.91 + string compare -length 2 -nocase abcde Abxyz
1.92 +} 0
1.93 +test string-2.17 {string compare -nocase with length} {
1.94 + string compare -nocase -length 3 abcde Abxyz
1.95 +} -1
1.96 +test string-2.18 {string compare -nocase with length <= 0} {
1.97 + string compare -nocase -length -1 abcde AbCdEf
1.98 +} -1
1.99 +test string-2.19 {string compare -nocase with excessive length} {
1.100 + string compare -nocase -length 50 AbCdEf abcde
1.101 +} 1
1.102 +test string-2.20 {string compare -len unicode} {
1.103 + # These are strings that are 6 BYTELENGTH long, but the length
1.104 + # shouldn't make a different because there are actually 3 CHARS long
1.105 + string compare -len 5 \334\334\334 \334\334\374
1.106 +} -1
1.107 +test string-2.21 {string compare -nocase with special index} {
1.108 + list [catch {string compare -nocase -length end-3 Abcde abxyz} msg] $msg
1.109 +} {1 {expected integer but got "end-3"}}
1.110 +test string-2.22 {string compare, null strings} {
1.111 + string compare "" ""
1.112 +} 0
1.113 +test string-2.23 {string compare, null strings} {
1.114 + string compare "" foo
1.115 +} -1
1.116 +test string-2.24 {string compare, null strings} {
1.117 + string compare foo ""
1.118 +} 1
1.119 +test string-2.25 {string compare -nocase, null strings} {
1.120 + string compare -nocase "" ""
1.121 +} 0
1.122 +test string-2.26 {string compare -nocase, null strings} {
1.123 + string compare -nocase "" foo
1.124 +} -1
1.125 +test string-2.27 {string compare -nocase, null strings} {
1.126 + string compare -nocase foo ""
1.127 +} 1
1.128 +test string-2.28 {string compare with length, unequal strings} {
1.129 + string compare -length 2 abc abde
1.130 +} 0
1.131 +test string-2.29 {string compare with length, unequal strings} {
1.132 + string compare -length 2 ab abde
1.133 +} 0
1.134 +test string-2.30 {string compare with NUL character vs. other ASCII} {
1.135 + # Be careful here, since UTF-8 rep comparison with memcmp() of
1.136 + # these puts chars in the wrong order
1.137 + string compare \x00 \x01
1.138 +} -1
1.139 +test string-2.31 {string compare, high bit} {
1.140 + proc foo {} {string compare "a\x80" "a@"}
1.141 + foo
1.142 +} 1
1.143 +test string-2.32 {string compare, high bit} {
1.144 + proc foo {} {string compare "a\x00" "a\x01"}
1.145 + foo
1.146 +} -1
1.147 +test string-2.33 {string compare, high bit} {
1.148 + proc foo {} {string compare "\x00\x00" "\x00\x01"}
1.149 + foo
1.150 +} -1
1.151 +
1.152 +# only need a few tests on equal, since it uses the same code as
1.153 +# string compare, but just modifies the return output
1.154 +test string-3.1 {string equal} {
1.155 + string equal abcde abdef
1.156 +} 0
1.157 +test string-3.2 {string equal} {
1.158 + string eq abcde ABCDE
1.159 +} 0
1.160 +test string-3.3 {string equal} {
1.161 + string equal abcde abcde
1.162 +} 1
1.163 +test string-3.4 {string equal -nocase} {
1.164 + string equal -nocase \334\334\334\334\374\374\374\374 \334\334\334\334\334\334\334\334
1.165 +} 1
1.166 +test string-3.5 {string equal -nocase} {
1.167 + string equal -nocase abcde abdef
1.168 +} 0
1.169 +test string-3.6 {string equal -nocase} {
1.170 + string eq -nocase abcde ABCDE
1.171 +} 1
1.172 +test string-3.7 {string equal -nocase} {
1.173 + string equal -nocase abcde abcde
1.174 +} 1
1.175 +test string-3.8 {string equal with length, unequal strings} {
1.176 + string equal -length 2 abc abde
1.177 +} 1
1.178 +
1.179 +test string-4.1 {string first, too few args} {
1.180 + list [catch {string first a} msg] $msg
1.181 +} {1 {wrong # args: should be "string first subString string ?startIndex?"}}
1.182 +test string-4.2 {string first, bad args} {
1.183 + list [catch {string first a b c} msg] $msg
1.184 +} {1 {bad index "c": must be integer or end?-integer?}}
1.185 +test string-4.3 {string first, too many args} {
1.186 + list [catch {string first a b 5 d} msg] $msg
1.187 +} {1 {wrong # args: should be "string first subString string ?startIndex?"}}
1.188 +test string-4.4 {string first} {
1.189 + string first bq abcdefgbcefgbqrs
1.190 +} 12
1.191 +test string-4.5 {string first} {
1.192 + string fir bcd abcdefgbcefgbqrs
1.193 +} 1
1.194 +test string-4.6 {string first} {
1.195 + string f b abcdefgbcefgbqrs
1.196 +} 1
1.197 +test string-4.7 {string first} {
1.198 + string first xxx x123xx345xxx789xxx012
1.199 +} 9
1.200 +test string-4.8 {string first} {
1.201 + string first "" x123xx345xxx789xxx012
1.202 +} -1
1.203 +test string-4.9 {string first, unicode} {
1.204 + string first x abc\u7266x
1.205 +} 4
1.206 +test string-4.10 {string first, unicode} {
1.207 + string first \u7266 abc\u7266x
1.208 +} 3
1.209 +test string-4.11 {string first, start index} {
1.210 + string first \u7266 abc\u7266x 3
1.211 +} 3
1.212 +test string-4.12 {string first, start index} {
1.213 + string first \u7266 abc\u7266x 4
1.214 +} -1
1.215 +test string-4.13 {string first, start index} {
1.216 + string first \u7266 abc\u7266x end-2
1.217 +} 3
1.218 +test string-4.14 {string first, negative start index} {
1.219 + string first b abc -1
1.220 +} 1
1.221 +test string-4.15 {string first, ability to two-byte encoded utf-8 chars} {
1.222 + # Test for a bug in Tcl 8.3 where test for all-single-byte-encoded
1.223 + # strings was incorrect, leading to an index returned by [string first]
1.224 + # which pointed past the end of the string.
1.225 + set uchar \u057e ;# character with two-byte encoding in utf-8
1.226 + string first % %#$uchar$uchar#$uchar$uchar#% 3
1.227 +} 8
1.228 +
1.229 +test string-5.1 {string index} {
1.230 + list [catch {string index} msg] $msg
1.231 +} {1 {wrong # args: should be "string index string charIndex"}}
1.232 +test string-5.2 {string index} {
1.233 + list [catch {string index a b c} msg] $msg
1.234 +} {1 {wrong # args: should be "string index string charIndex"}}
1.235 +test string-5.3 {string index} {
1.236 + string index abcde 0
1.237 +} a
1.238 +test string-5.4 {string index} {
1.239 + string in abcde 4
1.240 +} e
1.241 +test string-5.5 {string index} {
1.242 + string index abcde 5
1.243 +} {}
1.244 +test string-5.6 {string index} {
1.245 + list [catch {string index abcde -10} msg] $msg
1.246 +} {0 {}}
1.247 +test string-5.7 {string index} {
1.248 + list [catch {string index a xyz} msg] $msg
1.249 +} {1 {bad index "xyz": must be integer or end?-integer?}}
1.250 +test string-5.8 {string index} {
1.251 + string index abc end
1.252 +} c
1.253 +test string-5.9 {string index} {
1.254 + string index abc end-1
1.255 +} b
1.256 +test string-5.10 {string index, unicode} {
1.257 + string index abc\u7266d 4
1.258 +} d
1.259 +test string-5.11 {string index, unicode} {
1.260 + string index abc\u7266d 3
1.261 +} \u7266
1.262 +test string-5.12 {string index, unicode over char length, under byte length} {
1.263 + string index \334\374\334\374 6
1.264 +} {}
1.265 +test string-5.13 {string index, bytearray object} {
1.266 + string index [binary format a5 fuz] 0
1.267 +} f
1.268 +test string-5.14 {string index, bytearray object} {
1.269 + string index [binary format I* {0x50515253 0x52}] 3
1.270 +} S
1.271 +test string-5.15 {string index, bytearray object} {
1.272 + set b [binary format I* {0x50515253 0x52}]
1.273 + set i1 [string index $b end-6]
1.274 + set i2 [string index $b 1]
1.275 + string compare $i1 $i2
1.276 +} 0
1.277 +test string-5.16 {string index, bytearray object with string obj shimmering} {
1.278 + set str "0123456789\x00 abcdedfghi"
1.279 + binary scan $str H* dump
1.280 + string compare [string index $str 10] \x00
1.281 +} 0
1.282 +test string-5.17 {string index, bad integer} {
1.283 + list [catch {string index "abc" 08} msg] $msg
1.284 +} {1 {bad index "08": must be integer or end?-integer? (looks like invalid octal number)}}
1.285 +test string-5.18 {string index, bad integer} {
1.286 + list [catch {string index "abc" end-00289} msg] $msg
1.287 +} {1 {bad index "end-00289": must be integer or end?-integer? (looks like invalid octal number)}}
1.288 +test string-5.19 {string index, bytearray object out of bounds} {
1.289 + string index [binary format I* {0x50515253 0x52}] -1
1.290 +} {}
1.291 +test string-5.20 {string index, bytearray object out of bounds} {
1.292 + string index [binary format I* {0x50515253 0x52}] 20
1.293 +} {}
1.294 +
1.295 +
1.296 +proc largest_int {} {
1.297 + # This will give us what the largest valid int on this machine is,
1.298 + # so we can test for overflow properly below on >32 bit systems
1.299 + set int 1
1.300 + set exp 7; # assume we get at least 8 bits
1.301 + while {$int > 0} { set int [expr {wide(1) << [incr exp]}] }
1.302 + return [expr {$int-1}]
1.303 +}
1.304 +
1.305 +test string-6.1 {string is, too few args} {
1.306 + list [catch {string is} msg] $msg
1.307 +} {1 {wrong # args: should be "string is class ?-strict? ?-failindex var? str"}}
1.308 +test string-6.2 {string is, too few args} {
1.309 + list [catch {string is alpha} msg] $msg
1.310 +} {1 {wrong # args: should be "string is class ?-strict? ?-failindex var? str"}}
1.311 +test string-6.3 {string is, bad args} {
1.312 + list [catch {string is alpha -failin str} msg] $msg
1.313 +} {1 {wrong # args: should be "string is alpha ?-strict? ?-failindex var? str"}}
1.314 +test string-6.4 {string is, too many args} {
1.315 + list [catch {string is alpha -failin var -strict str more} msg] $msg
1.316 +} {1 {wrong # args: should be "string is class ?-strict? ?-failindex var? str"}}
1.317 +test string-6.5 {string is, class check} {
1.318 + list [catch {string is bogus str} msg] $msg
1.319 +} {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}}
1.320 +test string-6.6 {string is, ambiguous class} {
1.321 + list [catch {string is al str} msg] $msg
1.322 +} {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}}
1.323 +test string-6.7 {string is alpha, all ok} {
1.324 + string is alpha -strict -failindex var abc
1.325 +} 1
1.326 +test string-6.8 {string is, error in var} {
1.327 + list [string is alpha -failindex var abc5def] $var
1.328 +} {0 3}
1.329 +test string-6.9 {string is, var shouldn't get set} {
1.330 + catch {unset var}
1.331 + list [catch {string is alpha -failindex var abc; set var} msg] $msg
1.332 +} {1 {can't read "var": no such variable}}
1.333 +test string-6.10 {string is, ok on empty} {
1.334 + string is alpha {}
1.335 +} 1
1.336 +test string-6.11 {string is, -strict check against empty} {
1.337 + string is alpha -strict {}
1.338 +} 0
1.339 +test string-6.12 {string is alnum, true} {
1.340 + string is alnum abc123
1.341 +} 1
1.342 +test string-6.13 {string is alnum, false} {
1.343 + list [string is alnum -failindex var abc1.23] $var
1.344 +} {0 4}
1.345 +test string-6.14 {string is alnum, unicode} {
1.346 + string is alnum abcü
1.347 +} 1
1.348 +test string-6.15 {string is alpha, true} {
1.349 + string is alpha abc
1.350 +} 1
1.351 +test string-6.16 {string is alpha, false} {
1.352 + list [string is alpha -fail var a1bcde] $var
1.353 +} {0 1}
1.354 +test string-6.17 {string is alpha, unicode} {
1.355 + string is alpha abc\374
1.356 +} 1
1.357 +test string-6.18 {string is ascii, true} {
1.358 + string is ascii abc\u007Fend
1.359 +} 1
1.360 +test string-6.19 {string is ascii, false} {
1.361 + list [string is ascii -fail var abcdef\u0080more] $var
1.362 +} {0 6}
1.363 +test string-6.20 {string is boolean, true} {
1.364 + string is boolean true
1.365 +} 1
1.366 +test string-6.21 {string is boolean, true} {
1.367 + string is boolean f
1.368 +} 1
1.369 +test string-6.22 {string is boolean, true based on type} {
1.370 + string is bool [string compare a a]
1.371 +} 1
1.372 +test string-6.23 {string is boolean, false} {
1.373 + list [string is bool -fail var yada] $var
1.374 +} {0 0}
1.375 +test string-6.24 {string is digit, true} {
1.376 + string is digit 0123456789
1.377 +} 1
1.378 +test string-6.25 {string is digit, false} {
1.379 + list [string is digit -fail var 0123Ü567] $var
1.380 +} {0 4}
1.381 +test string-6.26 {string is digit, false} {
1.382 + list [string is digit -fail var +123567] $var
1.383 +} {0 0}
1.384 +test string-6.27 {string is double, true} {
1.385 + string is double 1
1.386 +} 1
1.387 +test string-6.28 {string is double, true} {
1.388 + string is double [expr double(1)]
1.389 +} 1
1.390 +test string-6.29 {string is double, true} {
1.391 + string is double 1.0
1.392 +} 1
1.393 +test string-6.30 {string is double, true} {
1.394 + string is double [string compare a a]
1.395 +} 1
1.396 +test string-6.31 {string is double, true} {
1.397 + string is double " +1.0e-1 "
1.398 +} 1
1.399 +test string-6.32 {string is double, true} {
1.400 + string is double "\n1.0\v"
1.401 +} 1
1.402 +test string-6.33 {string is double, false} {
1.403 + list [string is double -fail var 1abc] $var
1.404 +} {0 1}
1.405 +test string-6.34 {string is double, false} {
1.406 + list [string is double -fail var abc] $var
1.407 +} {0 0}
1.408 +test string-6.35 {string is double, false} {
1.409 + list [string is double -fail var " 1.0e4e4 "] $var
1.410 +} {0 8}
1.411 +test string-6.36 {string is double, false} {
1.412 + list [string is double -fail var "\n"] $var
1.413 +} {0 0}
1.414 +test string-6.37 {string is double, false on int overflow} {
1.415 + # Make it the largest int recognizable, with one more digit for overflow
1.416 + list [string is double -fail var [largest_int]0] $var
1.417 +} {0 -1}
1.418 +test string-6.38 {string is double, false on underflow} {
1.419 + catch {unset var}
1.420 + list [string is double -fail var 123e-9999] $var
1.421 +} {0 -1}
1.422 +test string-6.39 {string is double, false} {nonPortable} {
1.423 + # This test is non-portable because IRIX thinks
1.424 + # that .e1 is a valid double - this is really a bug
1.425 + # on IRIX as .e1 should NOT be a valid double
1.426 +
1.427 + list [string is double -fail var .e1] $var
1.428 +} {0 0}
1.429 +test string-6.40 {string is false, true} {
1.430 + string is false false
1.431 +} 1
1.432 +test string-6.41 {string is false, true} {
1.433 + string is false FaLsE
1.434 +} 1
1.435 +test string-6.42 {string is false, true} {
1.436 + string is false N
1.437 +} 1
1.438 +test string-6.43 {string is false, true} {
1.439 + string is false 0
1.440 +} 1
1.441 +test string-6.44 {string is false, true} {
1.442 + string is false off
1.443 +} 1
1.444 +test string-6.45 {string is false, false} {
1.445 + list [string is false -fail var abc] $var
1.446 +} {0 0}
1.447 +test string-6.46 {string is false, false} {
1.448 + catch {unset var}
1.449 + list [string is false -fail var Y] $var
1.450 +} {0 0}
1.451 +test string-6.47 {string is false, false} {
1.452 + catch {unset var}
1.453 + list [string is false -fail var offensive] $var
1.454 +} {0 0}
1.455 +test string-6.48 {string is integer, true} {
1.456 + string is integer +1234567890
1.457 +} 1
1.458 +test string-6.49 {string is integer, true on type} {
1.459 + string is integer [expr int(50.0)]
1.460 +} 1
1.461 +test string-6.50 {string is integer, true} {
1.462 + string is integer [list -10]
1.463 +} 1
1.464 +test string-6.51 {string is integer, true as hex} {
1.465 + string is integer 0xabcdef
1.466 +} 1
1.467 +test string-6.52 {string is integer, true as octal} {
1.468 + string is integer 012345
1.469 +} 1
1.470 +test string-6.53 {string is integer, true with whitespace} {
1.471 + string is integer " \n1234\v"
1.472 +} 1
1.473 +test string-6.54 {string is integer, false} {
1.474 + list [string is integer -fail var 123abc] $var
1.475 +} {0 3}
1.476 +test string-6.55 {string is integer, false on overflow} {
1.477 + list [string is integer -fail var +[largest_int]0] $var
1.478 +} {0 -1}
1.479 +test string-6.56 {string is integer, false} {
1.480 + list [string is integer -fail var [expr double(1)]] $var
1.481 +} {0 1}
1.482 +test string-6.57 {string is integer, false} {
1.483 + list [string is integer -fail var " "] $var
1.484 +} {0 0}
1.485 +test string-6.58 {string is integer, false on bad octal} {
1.486 + list [string is integer -fail var 036963] $var
1.487 +} {0 3}
1.488 +test string-6.59 {string is integer, false on bad hex} {
1.489 + list [string is integer -fail var 0X345XYZ] $var
1.490 +} {0 5}
1.491 +test string-6.60 {string is lower, true} {
1.492 + string is lower abc
1.493 +} 1
1.494 +test string-6.61 {string is lower, unicode true} {
1.495 + string is lower abcüue
1.496 +} 1
1.497 +test string-6.62 {string is lower, false} {
1.498 + list [string is lower -fail var aBc] $var
1.499 +} {0 1}
1.500 +test string-6.63 {string is lower, false} {
1.501 + list [string is lower -fail var abc1] $var
1.502 +} {0 3}
1.503 +test string-6.64 {string is lower, unicode false} {
1.504 + list [string is lower -fail var abÜUE] $var
1.505 +} {0 2}
1.506 +test string-6.65 {string is space, true} {
1.507 + string is space " \t\n\v\f"
1.508 +} 1
1.509 +test string-6.66 {string is space, false} {
1.510 + list [string is space -fail var " \t\n\v1\f"] $var
1.511 +} {0 4}
1.512 +test string-6.67 {string is true, true} {
1.513 + string is true true
1.514 +} 1
1.515 +test string-6.68 {string is true, true} {
1.516 + string is true TrU
1.517 +} 1
1.518 +test string-6.69 {string is true, true} {
1.519 + string is true ye
1.520 +} 1
1.521 +test string-6.70 {string is true, true} {
1.522 + string is true 1
1.523 +} 1
1.524 +test string-6.71 {string is true, true} {
1.525 + string is true on
1.526 +} 1
1.527 +test string-6.72 {string is true, false} {
1.528 + list [string is true -fail var onto] $var
1.529 +} {0 0}
1.530 +test string-6.73 {string is true, false} {
1.531 + catch {unset var}
1.532 + list [string is true -fail var 25] $var
1.533 +} {0 0}
1.534 +test string-6.74 {string is true, false} {
1.535 + catch {unset var}
1.536 + list [string is true -fail var no] $var
1.537 +} {0 0}
1.538 +test string-6.75 {string is upper, true} {
1.539 + string is upper ABC
1.540 +} 1
1.541 +test string-6.76 {string is upper, unicode true} {
1.542 + string is upper ABCÜUE
1.543 +} 1
1.544 +test string-6.77 {string is upper, false} {
1.545 + list [string is upper -fail var AbC] $var
1.546 +} {0 1}
1.547 +test string-6.78 {string is upper, false} {
1.548 + list [string is upper -fail var AB2C] $var
1.549 +} {0 2}
1.550 +test string-6.79 {string is upper, unicode false} {
1.551 + list [string is upper -fail var ABCüue] $var
1.552 +} {0 3}
1.553 +test string-6.80 {string is wordchar, true} {
1.554 + string is wordchar abc_123
1.555 +} 1
1.556 +test string-6.81 {string is wordchar, unicode true} {
1.557 + string is wordchar abcüabÜAB\u5001
1.558 +} 1
1.559 +test string-6.82 {string is wordchar, false} {
1.560 + list [string is wordchar -fail var abcd.ef] $var
1.561 +} {0 4}
1.562 +test string-6.83 {string is wordchar, unicode false} {
1.563 + list [string is wordchar -fail var abc\u0080def] $var
1.564 +} {0 3}
1.565 +test string-6.84 {string is control} {
1.566 + ## Control chars are in the ranges
1.567 + ## 00..1F && 7F..9F
1.568 + list [string is control -fail var \x00\x01\x10\x1F\x7F\x80\x9F\x60] $var
1.569 +} {0 7}
1.570 +test string-6.85 {string is control} {
1.571 + string is control \u0100
1.572 +} 0
1.573 +test string-6.86 {string is graph} {
1.574 + ## graph is any print char, except space
1.575 + list [string is gra -fail var "0123abc!@#\$\u0100 "] $var
1.576 +} {0 12}
1.577 +test string-6.87 {string is print} {
1.578 + ## basically any printable char
1.579 + list [string is print -fail var "0123abc!@#\$\u0100 \u0010"] $var
1.580 +} {0 13}
1.581 +test string-6.88 {string is punct} {
1.582 + ## any graph char that isn't alnum
1.583 + list [string is punct -fail var "_!@#\u00beq0"] $var
1.584 +} {0 4}
1.585 +test string-6.89 {string is xdigit} {
1.586 + list [string is xdigit -fail var 0123456789\u0061bcdefABCDEFg] $var
1.587 +} {0 22}
1.588 +
1.589 +test string-6.90 {string is integer, bad integers} {
1.590 + # SF bug #634856
1.591 + set result ""
1.592 + set numbers [list 1 +1 ++1 +-1 -+1 -1 --1 "- +1"]
1.593 + foreach num $numbers {
1.594 + lappend result [string is int -strict $num]
1.595 + }
1.596 + set result
1.597 +} {1 1 0 0 0 1 0 0}
1.598 +test string-6.91 {string is double, bad doubles} {
1.599 + set result ""
1.600 + set numbers [list 1.0 +1.0 ++1.0 +-1.0 -+1.0 -1.0 --1.0 "- +1.0"]
1.601 + foreach num $numbers {
1.602 + lappend result [string is double -strict $num]
1.603 + }
1.604 + set result
1.605 +} {1 1 0 0 0 1 0 0}
1.606 +test string-6.92 {string is double, 32-bit overflow} {
1.607 + # Bug 718878
1.608 + set x 0x100000000
1.609 + list [string is integer -failindex var $x] $var
1.610 +} {0 -1}
1.611 +test string-6.93 {string is double, 32-bit overflow} {
1.612 + # Bug 718878
1.613 + set x 0x100000000
1.614 + append x ""
1.615 + list [string is integer -failindex var $x] $var
1.616 +} {0 -1}
1.617 +test string-6.94 {string is double, 32-bit overflow} {
1.618 + # Bug 718878
1.619 + set x 0x100000000
1.620 + list [string is integer -failindex var [expr {$x}]] $var
1.621 +} {0 -1}
1.622 +
1.623 +catch {rename largest_int {}}
1.624 +
1.625 +test string-7.1 {string last, too few args} {
1.626 + list [catch {string last a} msg] $msg
1.627 +} {1 {wrong # args: should be "string last subString string ?startIndex?"}}
1.628 +test string-7.2 {string last, bad args} {
1.629 + list [catch {string last a b c} msg] $msg
1.630 +} {1 {bad index "c": must be integer or end?-integer?}}
1.631 +test string-7.3 {string last, too many args} {
1.632 + list [catch {string last a b c d} msg] $msg
1.633 +} {1 {wrong # args: should be "string last subString string ?startIndex?"}}
1.634 +test string-7.4 {string last} {
1.635 + string la xxx xxxx123xx345x678
1.636 +} 1
1.637 +test string-7.5 {string last} {
1.638 + string last xx xxxx123xx345x678
1.639 +} 7
1.640 +test string-7.6 {string last} {
1.641 + string las x xxxx123xx345x678
1.642 +} 12
1.643 +test string-7.7 {string last, unicode} {
1.644 + string las x xxxx12\u7266xx345x678
1.645 +} 12
1.646 +test string-7.8 {string last, unicode} {
1.647 + string las \u7266 xxxx12\u7266xx345x678
1.648 +} 6
1.649 +test string-7.9 {string last, stop index} {
1.650 + string las \u7266 xxxx12\u7266xx345x678
1.651 +} 6
1.652 +test string-7.10 {string last, unicode} {
1.653 + string las \u7266 xxxx12\u7266xx345x678
1.654 +} 6
1.655 +test string-7.11 {string last, start index} {
1.656 + string last \u7266 abc\u7266x 3
1.657 +} 3
1.658 +test string-7.12 {string last, start index} {
1.659 + string last \u7266 abc\u7266x 2
1.660 +} -1
1.661 +test string-7.13 {string last, start index} {
1.662 + ## Constrain to last 'a' should work
1.663 + string last ba badbad end-1
1.664 +} 3
1.665 +test string-7.14 {string last, start index} {
1.666 + ## Constrain to last 'b' should skip last 'ba'
1.667 + string last ba badbad end-2
1.668 +} 0
1.669 +test string-7.15 {string last, start index} {
1.670 + string last \334a \334ad\334ad 0
1.671 +} -1
1.672 +test string-7.16 {string last, start index} {
1.673 + string last \334a \334ad\334ad end-1
1.674 +} 3
1.675 +
1.676 +test string-8.1 {string bytelength} {
1.677 + list [catch {string bytelength} msg] $msg
1.678 +} {1 {wrong # args: should be "string bytelength string"}}
1.679 +test string-8.2 {string bytelength} {
1.680 + list [catch {string bytelength a b} msg] $msg
1.681 +} {1 {wrong # args: should be "string bytelength string"}}
1.682 +test string-8.3 {string bytelength} {
1.683 + string bytelength "\u00c7"
1.684 +} 2
1.685 +test string-8.4 {string bytelength} {
1.686 + string b ""
1.687 +} 0
1.688 +
1.689 +test string-9.1 {string length} {
1.690 + list [catch {string length} msg] $msg
1.691 +} {1 {wrong # args: should be "string length string"}}
1.692 +test string-9.2 {string length} {
1.693 + list [catch {string length a b} msg] $msg
1.694 +} {1 {wrong # args: should be "string length string"}}
1.695 +test string-9.3 {string length} {
1.696 + string length "a little string"
1.697 +} 15
1.698 +test string-9.4 {string length} {
1.699 + string le ""
1.700 +} 0
1.701 +test string-9.5 {string length, unicode} {
1.702 + string le "abcd\u7266"
1.703 +} 5
1.704 +test string-9.6 {string length, bytearray object} {
1.705 + string length [binary format a5 foo]
1.706 +} 5
1.707 +test string-9.7 {string length, bytearray object} {
1.708 + string length [binary format I* {0x50515253 0x52}]
1.709 +} 8
1.710 +
1.711 +test string-10.1 {string map, too few args} {
1.712 + list [catch {string map} msg] $msg
1.713 +} {1 {wrong # args: should be "string map ?-nocase? charMap string"}}
1.714 +test string-10.2 {string map, bad args} {
1.715 + list [catch {string map {a b} abba oops} msg] $msg
1.716 +} {1 {bad option "a b": must be -nocase}}
1.717 +test string-10.3 {string map, too many args} {
1.718 + list [catch {string map -nocase {a b} str1 str2} msg] $msg
1.719 +} {1 {wrong # args: should be "string map ?-nocase? charMap string"}}
1.720 +test string-10.4 {string map} {
1.721 + string map {a b} abba
1.722 +} {bbbb}
1.723 +test string-10.5 {string map} {
1.724 + string map {a b} a
1.725 +} {b}
1.726 +test string-10.6 {string map -nocase} {
1.727 + string map -nocase {a b} Abba
1.728 +} {bbbb}
1.729 +test string-10.7 {string map} {
1.730 + string map {abc 321 ab * a A} aabcabaababcab
1.731 +} {A321*A*321*}
1.732 +test string-10.8 {string map -nocase} {
1.733 + string map -nocase {aBc 321 Ab * a A} aabcabaababcab
1.734 +} {A321*A*321*}
1.735 +test string-10.9 {string map -nocase} {
1.736 + string map -no {abc 321 Ab * a A} aAbCaBaAbAbcAb
1.737 +} {A321*A*321*}
1.738 +test string-10.10 {string map} {
1.739 + list [catch {string map {a b c} abba} msg] $msg
1.740 +} {1 {char map list unbalanced}}
1.741 +test string-10.11 {string map, nulls} {
1.742 + string map {\x00 NULL blah \x00nix} {qwerty}
1.743 +} {qwerty}
1.744 +test string-10.12 {string map, unicode} {
1.745 + string map [list \374 ue UE \334] "a\374ueUE\000EU"
1.746 +} aueue\334\0EU
1.747 +test string-10.13 {string map, -nocase unicode} {
1.748 + string map -nocase [list \374 ue UE \334] "a\374ueUE\000EU"
1.749 +} aue\334\334\0EU
1.750 +test string-10.14 {string map, -nocase null arguments} {
1.751 + string map -nocase {{} abc} foo
1.752 +} foo
1.753 +test string-10.15 {string map, one pair case} {
1.754 + string map -nocase {abc 32} aAbCaBaAbAbcAb
1.755 +} {a32aBaAb32Ab}
1.756 +test string-10.16 {string map, one pair case} {
1.757 + string map -nocase {ab 4321} aAbCaBaAbAbcAb
1.758 +} {a4321C4321a43214321c4321}
1.759 +test string-10.17 {string map, one pair case} {
1.760 + string map {Ab 4321} aAbCaBaAbAbcAb
1.761 +} {a4321CaBa43214321c4321}
1.762 +test string-10.18 {string map, empty argument} {
1.763 + string map -nocase {{} abc} foo
1.764 +} foo
1.765 +test string-10.19 {string map, empty arguments} {
1.766 + string map -nocase {{} abc f bar {} def} foo
1.767 +} baroo
1.768 +test string-10.20 {string map, nasty sharing crash from [Bug 1018562]} {
1.769 + set a {a b}
1.770 + string map $a $a
1.771 +} {b b}
1.772 +test string-10.21 {string map, ABR checks} {
1.773 + string map {longstring foob} long
1.774 +} long
1.775 +test string-10.22 {string map, ABR checks} {
1.776 + string map {long foob} long
1.777 +} foob
1.778 +test string-10.23 {string map, ABR checks} {
1.779 + string map {lon foob} long
1.780 +} foobg
1.781 +test string-10.24 {string map, ABR checks} {
1.782 + string map {lon foob} longlo
1.783 +} foobglo
1.784 +test string-10.25 {string map, ABR checks} {
1.785 + string map {lon foob} longlon
1.786 +} foobgfoob
1.787 +test string-10.26 {string map, ABR checks} {
1.788 + string map {longstring foob longstring bar} long
1.789 +} long
1.790 +test string-10.27 {string map, ABR checks} {
1.791 + string map {long foob longstring bar} long
1.792 +} foob
1.793 +test string-10.28 {string map, ABR checks} {
1.794 + string map {lon foob longstring bar} long
1.795 +} foobg
1.796 +test string-10.29 {string map, ABR checks} {
1.797 + string map {lon foob longstring bar} longlo
1.798 +} foobglo
1.799 +test string-10.30 {string map, ABR checks} {
1.800 + string map {lon foob longstring bar} longlon
1.801 +} foobgfoob
1.802 +
1.803 +test string-11.1 {string match, too few args} {
1.804 + list [catch {string match a} msg] $msg
1.805 +} {1 {wrong # args: should be "string match ?-nocase? pattern string"}}
1.806 +test string-11.2 {string match, too many args} {
1.807 + list [catch {string match a b c d} msg] $msg
1.808 +} {1 {wrong # args: should be "string match ?-nocase? pattern string"}}
1.809 +test string-11.3 {string match} {
1.810 + string match abc abc
1.811 +} 1
1.812 +test string-11.4 {string match} {
1.813 + string mat abc abd
1.814 +} 0
1.815 +test string-11.5 {string match} {
1.816 + string match ab*c abc
1.817 +} 1
1.818 +test string-11.6 {string match} {
1.819 + string match ab**c abc
1.820 +} 1
1.821 +test string-11.7 {string match} {
1.822 + string match ab* abcdef
1.823 +} 1
1.824 +test string-11.8 {string match} {
1.825 + string match *c abc
1.826 +} 1
1.827 +test string-11.9 {string match} {
1.828 + string match *3*6*9 0123456789
1.829 +} 1
1.830 +test string-11.10 {string match} {
1.831 + string match *3*6*9 01234567890
1.832 +} 0
1.833 +test string-11.11 {string match} {
1.834 + string match a?c abc
1.835 +} 1
1.836 +test string-11.12 {string match} {
1.837 + string match a??c abc
1.838 +} 0
1.839 +test string-11.13 {string match} {
1.840 + string match ?1??4???8? 0123456789
1.841 +} 1
1.842 +test string-11.14 {string match} {
1.843 + string match {[abc]bc} abc
1.844 +} 1
1.845 +test string-11.15 {string match} {
1.846 + string match {a[abc]c} abc
1.847 +} 1
1.848 +test string-11.16 {string match} {
1.849 + string match {a[xyz]c} abc
1.850 +} 0
1.851 +test string-11.17 {string match} {
1.852 + string match {12[2-7]45} 12345
1.853 +} 1
1.854 +test string-11.18 {string match} {
1.855 + string match {12[ab2-4cd]45} 12345
1.856 +} 1
1.857 +test string-11.19 {string match} {
1.858 + string match {12[ab2-4cd]45} 12b45
1.859 +} 1
1.860 +test string-11.20 {string match} {
1.861 + string match {12[ab2-4cd]45} 12d45
1.862 +} 1
1.863 +test string-11.21 {string match} {
1.864 + string match {12[ab2-4cd]45} 12145
1.865 +} 0
1.866 +test string-11.22 {string match} {
1.867 + string match {12[ab2-4cd]45} 12545
1.868 +} 0
1.869 +test string-11.23 {string match} {
1.870 + string match {a\*b} a*b
1.871 +} 1
1.872 +test string-11.24 {string match} {
1.873 + string match {a\*b} ab
1.874 +} 0
1.875 +test string-11.25 {string match} {
1.876 + string match {a\*\?\[\]\\\x} "a*?\[\]\\x"
1.877 +} 1
1.878 +test string-11.26 {string match} {
1.879 + string match ** ""
1.880 +} 1
1.881 +test string-11.27 {string match} {
1.882 + string match *. ""
1.883 +} 0
1.884 +test string-11.28 {string match} {
1.885 + string match "" ""
1.886 +} 1
1.887 +test string-11.29 {string match} {
1.888 + string match \[a a
1.889 +} 1
1.890 +test string-11.30 {string match, bad args} {
1.891 + list [catch {string match - b c} msg] $msg
1.892 +} {1 {bad option "-": must be -nocase}}
1.893 +test string-11.31 {string match case} {
1.894 + string match a A
1.895 +} 0
1.896 +test string-11.32 {string match nocase} {
1.897 + string match -n a A
1.898 +} 1
1.899 +test string-11.33 {string match nocase} {
1.900 + string match -nocase a\334 A\374
1.901 +} 1
1.902 +test string-11.34 {string match nocase} {
1.903 + string match -nocase a*f ABCDEf
1.904 +} 1
1.905 +test string-11.35 {string match case, false hope} {
1.906 + # This is true because '_' lies between the A-Z and a-z ranges
1.907 + string match {[A-z]} _
1.908 +} 1
1.909 +test string-11.36 {string match nocase range} {
1.910 + # This is false because although '_' lies between the A-Z and a-z ranges,
1.911 + # we lower case the end points before checking the ranges.
1.912 + string match -nocase {[A-z]} _
1.913 +} 0
1.914 +test string-11.37 {string match nocase} {
1.915 + string match -nocase {[A-fh-Z]} g
1.916 +} 0
1.917 +test string-11.38 {string match case, reverse range} {
1.918 + string match {[A-fh-Z]} g
1.919 +} 1
1.920 +test string-11.39 {string match, *\ case} {
1.921 + string match {*\abc} abc
1.922 +} 1
1.923 +test string-11.40 {string match, *special case} {
1.924 + string match {*[ab]} abc
1.925 +} 0
1.926 +test string-11.41 {string match, *special case} {
1.927 + string match {*[ab]*} abc
1.928 +} 1
1.929 +test string-11.42 {string match, *special case} {
1.930 + string match "*\\" "\\"
1.931 +} 0
1.932 +test string-11.43 {string match, *special case} {
1.933 + string match "*\\\\" "\\"
1.934 +} 1
1.935 +test string-11.44 {string match, *special case} {
1.936 + string match "*???" "12345"
1.937 +} 1
1.938 +test string-11.45 {string match, *special case} {
1.939 + string match "*???" "12"
1.940 +} 0
1.941 +test string-11.46 {string match, *special case} {
1.942 + string match "*\\*" "abc*"
1.943 +} 1
1.944 +test string-11.47 {string match, *special case} {
1.945 + string match "*\\*" "*"
1.946 +} 1
1.947 +test string-11.48 {string match, *special case} {
1.948 + string match "*\\*" "*abc"
1.949 +} 0
1.950 +test string-11.49 {string match, *special case} {
1.951 + string match "?\\*" "a*"
1.952 +} 1
1.953 +test string-11.50 {string match, *special case} {
1.954 + string match "\\" "\\"
1.955 +} 0
1.956 +test string-11.51 {string match; *, -nocase and UTF-8} {
1.957 + string match -nocase [binary format I 717316707] \
1.958 + [binary format I 2028036707]
1.959 +} 1
1.960 +test string-11.52 {string match, null char in string} {
1.961 + set out ""
1.962 + set ptn "*abc*"
1.963 + foreach elem [list "\u0000@abc" "@abc" "\u0000@abc\u0000" "blahabcblah"] {
1.964 + lappend out [string match $ptn $elem]
1.965 + }
1.966 + set out
1.967 +} {1 1 1 1}
1.968 +test string-11.53 {string match, null char in pattern} {
1.969 + set out ""
1.970 + foreach {ptn elem} [list \
1.971 + "*\u0000abc\u0000" "\u0000abc\u0000" \
1.972 + "*\u0000abc\u0000" "\u0000abc\u0000ef" \
1.973 + "*\u0000abc\u0000*" "\u0000abc\u0000ef" \
1.974 + "*\u0000abc\u0000" "@\u0000abc\u0000ef" \
1.975 + "*\u0000abc\u0000*" "@\u0000abc\u0000ef" \
1.976 + ] {
1.977 + lappend out [string match $ptn $elem]
1.978 + }
1.979 + set out
1.980 +} {1 0 1 0 1}
1.981 +test string-11.54 {string match, failure} {
1.982 + set longString ""
1.983 + for {set i 0} {$i < 10} {incr i} {
1.984 + append longString "abcdefghijklmnopqrstuvwxy\u0000z01234567890123"
1.985 + }
1.986 + string first $longString 123
1.987 + list [string match *cba* $longString] \
1.988 + [string match *a*l*\u0000* $longString] \
1.989 + [string match *a*l*\u0000*123 $longString] \
1.990 + [string match *a*l*\u0000*123* $longString] \
1.991 + [string match *a*l*\u0000*cba* $longString] \
1.992 + [string match *===* $longString]
1.993 +} {0 1 1 1 0 0}
1.994 +
1.995 +test string-12.1 {string range} {
1.996 + list [catch {string range} msg] $msg
1.997 +} {1 {wrong # args: should be "string range string first last"}}
1.998 +test string-12.2 {string range} {
1.999 + list [catch {string range a 1} msg] $msg
1.1000 +} {1 {wrong # args: should be "string range string first last"}}
1.1001 +test string-12.3 {string range} {
1.1002 + list [catch {string range a 1 2 3} msg] $msg
1.1003 +} {1 {wrong # args: should be "string range string first last"}}
1.1004 +test string-12.4 {string range} {
1.1005 + string range abcdefghijklmnop 2 14
1.1006 +} {cdefghijklmno}
1.1007 +test string-12.5 {string range, last > length} {
1.1008 + string range abcdefghijklmnop 7 1000
1.1009 +} {hijklmnop}
1.1010 +test string-12.6 {string range} {
1.1011 + string range abcdefghijklmnop 10 e
1.1012 +} {klmnop}
1.1013 +test string-12.7 {string range, last < first} {
1.1014 + string range abcdefghijklmnop 10 9
1.1015 +} {}
1.1016 +test string-12.8 {string range, first < 0} {
1.1017 + string range abcdefghijklmnop -3 2
1.1018 +} {abc}
1.1019 +test string-12.9 {string range} {
1.1020 + string range abcdefghijklmnop -3 -2
1.1021 +} {}
1.1022 +test string-12.10 {string range} {
1.1023 + string range abcdefghijklmnop 1000 1010
1.1024 +} {}
1.1025 +test string-12.11 {string range} {
1.1026 + string range abcdefghijklmnop -100 end
1.1027 +} {abcdefghijklmnop}
1.1028 +test string-12.12 {string range} {
1.1029 + list [catch {string range abc abc 1} msg] $msg
1.1030 +} {1 {bad index "abc": must be integer or end?-integer?}}
1.1031 +test string-12.13 {string range} {
1.1032 + list [catch {string range abc 1 eof} msg] $msg
1.1033 +} {1 {bad index "eof": must be integer or end?-integer?}}
1.1034 +test string-12.14 {string range} {
1.1035 + string range abcdefghijklmnop end-1 end
1.1036 +} {op}
1.1037 +test string-12.15 {string range} {
1.1038 + string range abcdefghijklmnop e 1000
1.1039 +} {p}
1.1040 +test string-12.16 {string range} {
1.1041 + string range abcdefghijklmnop end end-1
1.1042 +} {}
1.1043 +test string-12.17 {string range, unicode} {
1.1044 + string range ab\u7266cdefghijklmnop 5 5
1.1045 +} e
1.1046 +test string-12.18 {string range, unicode} {
1.1047 + string range ab\u7266cdefghijklmnop 2 3
1.1048 +} \u7266c
1.1049 +test string-12.19 {string range, bytearray object} {
1.1050 + set b [binary format I* {0x50515253 0x52}]
1.1051 + set r1 [string range $b 1 end-1]
1.1052 + set r2 [string range $b 1 6]
1.1053 + string equal $r1 $r2
1.1054 +} 1
1.1055 +test string-12.20 {string range, out of bounds indices} {
1.1056 + string range \u00ff 0 1
1.1057 +} \u00ff
1.1058 +test string-12.21 {string range, regenerates correct reps, bug 1410553} {
1.1059 + set bytes "\x00 \x03 \x41"
1.1060 + set rxBuffer {}
1.1061 + foreach ch $bytes {
1.1062 + append rxBuffer $ch
1.1063 + if {$ch eq "\x03"} {
1.1064 + string length $rxBuffer
1.1065 + }
1.1066 + }
1.1067 + set rxCRC [string range $rxBuffer end-1 end]
1.1068 + binary scan [join $bytes {}] "H*" input_hex
1.1069 + binary scan $rxBuffer "H*" rxBuffer_hex
1.1070 + binary scan $rxCRC "H*" rxCRC_hex
1.1071 + list $input_hex $rxBuffer_hex $rxCRC_hex
1.1072 +} {000341 000341 0341}
1.1073 +
1.1074 +test string-13.1 {string repeat} {
1.1075 + list [catch {string repeat} msg] $msg
1.1076 +} {1 {wrong # args: should be "string repeat string count"}}
1.1077 +test string-13.2 {string repeat} {
1.1078 + list [catch {string repeat abc 10 oops} msg] $msg
1.1079 +} {1 {wrong # args: should be "string repeat string count"}}
1.1080 +test string-13.3 {string repeat} {
1.1081 + string repeat {} 100
1.1082 +} {}
1.1083 +test string-13.4 {string repeat} {
1.1084 + string repeat { } 5
1.1085 +} { }
1.1086 +test string-13.5 {string repeat} {
1.1087 + string repeat abc 3
1.1088 +} {abcabcabc}
1.1089 +test string-13.6 {string repeat} {
1.1090 + string repeat abc -1
1.1091 +} {}
1.1092 +test string-13.7 {string repeat} {
1.1093 + list [catch {string repeat abc end} msg] $msg
1.1094 +} {1 {expected integer but got "end"}}
1.1095 +test string-13.8 {string repeat} {
1.1096 + string repeat {} -1000
1.1097 +} {}
1.1098 +test string-13.9 {string repeat} {
1.1099 + string repeat {} 0
1.1100 +} {}
1.1101 +test string-13.10 {string repeat} {
1.1102 + string repeat def 0
1.1103 +} {}
1.1104 +test string-13.11 {string repeat} {
1.1105 + string repeat def 1
1.1106 +} def
1.1107 +test string-13.12 {string repeat} {
1.1108 + string repeat ab\u7266cd 3
1.1109 +} ab\u7266cdab\u7266cdab\u7266cd
1.1110 +test string-13.13 {string repeat} {
1.1111 + string repeat \x00 3
1.1112 +} \x00\x00\x00
1.1113 +test string-13.14 {string repeat} {
1.1114 + # The string range will ensure us that string repeat gets a unicode string
1.1115 + string repeat [string range ab\u7266cd 2 3] 3
1.1116 +} \u7266c\u7266c\u7266c
1.1117 +
1.1118 +test string-14.1 {string replace} {
1.1119 + list [catch {string replace} msg] $msg
1.1120 +} {1 {wrong # args: should be "string replace string first last ?string?"}}
1.1121 +test string-14.2 {string replace} {
1.1122 + list [catch {string replace a 1} msg] $msg
1.1123 +} {1 {wrong # args: should be "string replace string first last ?string?"}}
1.1124 +test string-14.3 {string replace} {
1.1125 + list [catch {string replace a 1 2 3 4} msg] $msg
1.1126 +} {1 {wrong # args: should be "string replace string first last ?string?"}}
1.1127 +test string-14.4 {string replace} {
1.1128 +} {}
1.1129 +test string-14.5 {string replace} {
1.1130 + string replace abcdefghijklmnop 2 14
1.1131 +} {abp}
1.1132 +test string-14.6 {string replace} {
1.1133 + string replace abcdefghijklmnop 7 1000
1.1134 +} {abcdefg}
1.1135 +test string-14.7 {string replace} {
1.1136 + string replace abcdefghijklmnop 10 e
1.1137 +} {abcdefghij}
1.1138 +test string-14.8 {string replace} {
1.1139 + string replace abcdefghijklmnop 10 9
1.1140 +} {abcdefghijklmnop}
1.1141 +test string-14.9 {string replace} {
1.1142 + string replace abcdefghijklmnop -3 2
1.1143 +} {defghijklmnop}
1.1144 +test string-14.10 {string replace} {
1.1145 + string replace abcdefghijklmnop -3 -2
1.1146 +} {abcdefghijklmnop}
1.1147 +test string-14.11 {string replace} {
1.1148 + string replace abcdefghijklmnop 1000 1010
1.1149 +} {abcdefghijklmnop}
1.1150 +test string-14.12 {string replace} {
1.1151 + string replace abcdefghijklmnop -100 end
1.1152 +} {}
1.1153 +test string-14.13 {string replace} {
1.1154 + list [catch {string replace abc abc 1} msg] $msg
1.1155 +} {1 {bad index "abc": must be integer or end?-integer?}}
1.1156 +test string-14.14 {string replace} {
1.1157 + list [catch {string replace abc 1 eof} msg] $msg
1.1158 +} {1 {bad index "eof": must be integer or end?-integer?}}
1.1159 +test string-14.15 {string replace} {
1.1160 + string replace abcdefghijklmnop end-10 end-2 NEW
1.1161 +} {abcdeNEWop}
1.1162 +test string-14.16 {string replace} {
1.1163 + string replace abcdefghijklmnop 0 e foo
1.1164 +} {foo}
1.1165 +test string-14.17 {string replace} {
1.1166 + string replace abcdefghijklmnop end end-1
1.1167 +} {abcdefghijklmnop}
1.1168 +
1.1169 +test string-15.1 {string tolower too few args} {
1.1170 + list [catch {string tolower} msg] $msg
1.1171 +} {1 {wrong # args: should be "string tolower string ?first? ?last?"}}
1.1172 +test string-15.2 {string tolower bad args} {
1.1173 + list [catch {string tolower a b} msg] $msg
1.1174 +} {1 {bad index "b": must be integer or end?-integer?}}
1.1175 +test string-15.3 {string tolower too many args} {
1.1176 + list [catch {string tolower ABC 1 end oops} msg] $msg
1.1177 +} {1 {wrong # args: should be "string tolower string ?first? ?last?"}}
1.1178 +test string-15.4 {string tolower} {
1.1179 + string tolower ABCDeF
1.1180 +} {abcdef}
1.1181 +test string-15.5 {string tolower} {
1.1182 + string tolower "ABC XyZ"
1.1183 +} {abc xyz}
1.1184 +test string-15.6 {string tolower} {
1.1185 + string tolower {123#$&*()}
1.1186 +} {123#$&*()}
1.1187 +test string-15.7 {string tolower} {
1.1188 + string tolower ABC 1
1.1189 +} AbC
1.1190 +test string-15.8 {string tolower} {
1.1191 + string tolower ABC 1 end
1.1192 +} Abc
1.1193 +test string-15.9 {string tolower} {
1.1194 + string tolower ABC 0 end-1
1.1195 +} abC
1.1196 +test string-15.10 {string tolower, unicode} {
1.1197 + string tolower ABCabc\xc7\xe7
1.1198 +} "abcabc\xe7\xe7"
1.1199 +
1.1200 +test string-16.1 {string toupper} {
1.1201 + list [catch {string toupper} msg] $msg
1.1202 +} {1 {wrong # args: should be "string toupper string ?first? ?last?"}}
1.1203 +test string-16.2 {string toupper} {
1.1204 + list [catch {string toupper a b} msg] $msg
1.1205 +} {1 {bad index "b": must be integer or end?-integer?}}
1.1206 +test string-16.3 {string toupper} {
1.1207 + list [catch {string toupper a 1 end oops} msg] $msg
1.1208 +} {1 {wrong # args: should be "string toupper string ?first? ?last?"}}
1.1209 +test string-16.4 {string toupper} {
1.1210 + string toupper abCDEf
1.1211 +} {ABCDEF}
1.1212 +test string-16.5 {string toupper} {
1.1213 + string toupper "abc xYz"
1.1214 +} {ABC XYZ}
1.1215 +test string-16.6 {string toupper} {
1.1216 + string toupper {123#$&*()}
1.1217 +} {123#$&*()}
1.1218 +test string-16.7 {string toupper} {
1.1219 + string toupper abc 1
1.1220 +} aBc
1.1221 +test string-16.8 {string toupper} {
1.1222 + string toupper abc 1 end
1.1223 +} aBC
1.1224 +test string-16.9 {string toupper} {
1.1225 + string toupper abc 0 end-1
1.1226 +} ABc
1.1227 +test string-16.10 {string toupper, unicode} {
1.1228 + string toupper ABCabc\xc7\xe7
1.1229 +} "ABCABC\xc7\xc7"
1.1230 +
1.1231 +test string-17.1 {string totitle} {
1.1232 + list [catch {string totitle} msg] $msg
1.1233 +} {1 {wrong # args: should be "string totitle string ?first? ?last?"}}
1.1234 +test string-17.2 {string totitle} {
1.1235 + list [catch {string totitle a b} msg] $msg
1.1236 +} {1 {bad index "b": must be integer or end?-integer?}}
1.1237 +test string-17.3 {string totitle} {
1.1238 + string totitle abCDEf
1.1239 +} {Abcdef}
1.1240 +test string-17.4 {string totitle} {
1.1241 + string totitle "abc xYz"
1.1242 +} {Abc xyz}
1.1243 +test string-17.5 {string totitle} {
1.1244 + string totitle {123#$&*()}
1.1245 +} {123#$&*()}
1.1246 +test string-17.6 {string totitle, unicode} {
1.1247 + string totitle ABCabc\xc7\xe7
1.1248 +} "Abcabc\xe7\xe7"
1.1249 +test string-17.7 {string totitle, unicode} {
1.1250 + string totitle \u01f3BCabc\xc7\xe7
1.1251 +} "\u01f2bcabc\xe7\xe7"
1.1252 +
1.1253 +test string-18.1 {string trim} {
1.1254 + list [catch {string trim} msg] $msg
1.1255 +} {1 {wrong # args: should be "string trim string ?chars?"}}
1.1256 +test string-18.2 {string trim} {
1.1257 + list [catch {string trim a b c} msg] $msg
1.1258 +} {1 {wrong # args: should be "string trim string ?chars?"}}
1.1259 +test string-18.3 {string trim} {
1.1260 + string trim " XYZ "
1.1261 +} {XYZ}
1.1262 +test string-18.4 {string trim} {
1.1263 + string trim "\t\nXYZ\t\n\r\n"
1.1264 +} {XYZ}
1.1265 +test string-18.5 {string trim} {
1.1266 + string trim " A XYZ A "
1.1267 +} {A XYZ A}
1.1268 +test string-18.6 {string trim} {
1.1269 + string trim "XXYYZZABC XXYYZZ" ZYX
1.1270 +} {ABC }
1.1271 +test string-18.7 {string trim} {
1.1272 + string trim " \t\r "
1.1273 +} {}
1.1274 +test string-18.8 {string trim} {
1.1275 + string trim {abcdefg} {}
1.1276 +} {abcdefg}
1.1277 +test string-18.9 {string trim} {
1.1278 + string trim {}
1.1279 +} {}
1.1280 +test string-18.10 {string trim} {
1.1281 + string trim ABC DEF
1.1282 +} {ABC}
1.1283 +test string-18.11 {string trim, unicode} {
1.1284 + string trim "\xe7\xe8 AB\xe7C \xe8\xe7" \xe7\xe8
1.1285 +} " AB\xe7C "
1.1286 +
1.1287 +test string-19.1 {string trimleft} {
1.1288 + list [catch {string trimleft} msg] $msg
1.1289 +} {1 {wrong # args: should be "string trimleft string ?chars?"}}
1.1290 +test string-19.2 {string trimleft} {
1.1291 + string trimleft " XYZ "
1.1292 +} {XYZ }
1.1293 +
1.1294 +test string-20.1 {string trimright errors} {
1.1295 + list [catch {string trimright} msg] $msg
1.1296 +} {1 {wrong # args: should be "string trimright string ?chars?"}}
1.1297 +test string-20.2 {string trimright errors} {
1.1298 + list [catch {string trimg a} msg] $msg
1.1299 +} {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}}
1.1300 +test string-20.3 {string trimright} {
1.1301 + string trimright " XYZ "
1.1302 +} { XYZ}
1.1303 +test string-20.4 {string trimright} {
1.1304 + string trimright " "
1.1305 +} {}
1.1306 +test string-20.5 {string trimright} {
1.1307 + string trimright ""
1.1308 +} {}
1.1309 +
1.1310 +test string-21.1 {string wordend} {
1.1311 + list [catch {string wordend a} msg] $msg
1.1312 +} {1 {wrong # args: should be "string wordend string index"}}
1.1313 +test string-21.2 {string wordend} {
1.1314 + list [catch {string wordend a b c} msg] $msg
1.1315 +} {1 {wrong # args: should be "string wordend string index"}}
1.1316 +test string-21.3 {string wordend} {
1.1317 + list [catch {string wordend a gorp} msg] $msg
1.1318 +} {1 {bad index "gorp": must be integer or end?-integer?}}
1.1319 +test string-21.4 {string wordend} {
1.1320 + string wordend abc. -1
1.1321 +} 3
1.1322 +test string-21.5 {string wordend} {
1.1323 + string wordend abc. 100
1.1324 +} 4
1.1325 +test string-21.6 {string wordend} {
1.1326 + string wordend "word_one two three" 2
1.1327 +} 8
1.1328 +test string-21.7 {string wordend} {
1.1329 + string wordend "one .&# three" 5
1.1330 +} 6
1.1331 +test string-21.8 {string wordend} {
1.1332 + string worde "x.y" 0
1.1333 +} 1
1.1334 +test string-21.9 {string wordend} {
1.1335 + string worde "x.y" end-1
1.1336 +} 2
1.1337 +test string-21.10 {string wordend, unicode} {
1.1338 + string wordend "xyz\u00c7de fg" 0
1.1339 +} 6
1.1340 +test string-21.11 {string wordend, unicode} {
1.1341 + string wordend "xyz\uc700de fg" 0
1.1342 +} 6
1.1343 +test string-21.12 {string wordend, unicode} {
1.1344 + string wordend "xyz\u203fde fg" 0
1.1345 +} 6
1.1346 +test string-21.13 {string wordend, unicode} {
1.1347 + string wordend "xyz\u2045de fg" 0
1.1348 +} 3
1.1349 +test string-21.14 {string wordend, unicode} {
1.1350 + string wordend "\uc700\uc700 abc" 8
1.1351 +} 6
1.1352 +
1.1353 +test string-22.1 {string wordstart} {
1.1354 + list [catch {string word a} msg] $msg
1.1355 +} {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}}
1.1356 +test string-22.2 {string wordstart} {
1.1357 + list [catch {string wordstart a} msg] $msg
1.1358 +} {1 {wrong # args: should be "string wordstart string index"}}
1.1359 +test string-22.3 {string wordstart} {
1.1360 + list [catch {string wordstart a b c} msg] $msg
1.1361 +} {1 {wrong # args: should be "string wordstart string index"}}
1.1362 +test string-22.4 {string wordstart} {
1.1363 + list [catch {string wordstart a gorp} msg] $msg
1.1364 +} {1 {bad index "gorp": must be integer or end?-integer?}}
1.1365 +test string-22.5 {string wordstart} {
1.1366 + string wordstart "one two three_words" 400
1.1367 +} 8
1.1368 +test string-22.6 {string wordstart} {
1.1369 + string wordstart "one two three_words" 2
1.1370 +} 0
1.1371 +test string-22.7 {string wordstart} {
1.1372 + string wordstart "one two three_words" -2
1.1373 +} 0
1.1374 +test string-22.8 {string wordstart} {
1.1375 + string wordstart "one .*&^ three" 6
1.1376 +} 6
1.1377 +test string-22.9 {string wordstart} {
1.1378 + string wordstart "one two three" 4
1.1379 +} 4
1.1380 +test string-22.10 {string wordstart} {
1.1381 + string wordstart "one two three" end-5
1.1382 +} 7
1.1383 +test string-22.11 {string wordstart, unicode} {
1.1384 + string wordstart "one tw\u00c7o three" 7
1.1385 +} 4
1.1386 +test string-22.12 {string wordstart, unicode} {
1.1387 + string wordstart "ab\uc700\uc700 cdef ghi" 12
1.1388 +} 10
1.1389 +test string-22.13 {string wordstart, unicode} {
1.1390 + string wordstart "\uc700\uc700 abc" 8
1.1391 +} 3
1.1392 +
1.1393 +test string-23.0 {string is boolean, Bug 1187123} testindexobj {
1.1394 + set x 5
1.1395 + catch {testindexobj $x foo bar soom}
1.1396 + string is boolean $x
1.1397 +} 0
1.1398 +
1.1399 +
1.1400 +# cleanup
1.1401 +::tcltest::cleanupTests
1.1402 +return