| 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 Scriptics Corporation. |
| 10 |
# Copyright (c) 2001 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 |
if {"::tcltest" ni [namespace children]} { |
| 16 |
package require tcltest 2.5 |
| 17 |
namespace import -force ::tcltest::* |
| 18 |
} |
| 19 |
|
| 20 |
::tcltest::loadTestedCommands |
| 21 |
catch [list package require -exact Tcltest [info patchlevel]] |
| 22 |
|
| 23 |
# Some tests require the testobj command |
| 24 |
|
| 25 |
testConstraint testobj [expr {[info commands testobj] ne {}}] |
| 26 |
testConstraint testindexobj [expr {[info commands testindexobj] ne {}}] |
| 27 |
testConstraint testevalex [expr {[info commands testevalex] ne {}}] |
| 28 |
testConstraint utf16 [expr {[string length \U010000] == 2}] |
| 29 |
testConstraint testbytestring [llength [info commands testbytestring]] |
| 30 |
|
| 31 |
# Used for constraining memory leak tests |
| 32 |
testConstraint memory [llength [info commands memory]] |
| 33 |
|
| 34 |
foreach noComp {0 1} { |
| 35 |
|
| 36 |
if {$noComp} { |
| 37 |
if {[info commands testevalex] eq {}} { |
| 38 |
test string-0.1.$noComp "show testevalex availability" {testevalex} {list} {} |
| 39 |
continue |
| 40 |
} |
| 41 |
interp alias {} run {} testevalex |
| 42 |
set constraints testevalex |
| 43 |
} else { |
| 44 |
interp alias {} run {} try |
| 45 |
set constraints {} |
| 46 |
} |
| 47 |
|
| 48 |
|
| 49 |
test string-1.1.$noComp {error conditions} -body { |
| 50 |
list [catch {run {string gorp a b}} msg] $msg |
| 51 |
} -result {1 {unknown or ambiguous subcommand "gorp": must be bytelength, cat, compare, equal, first, index, is, last, length, map, match, range, repeat, replace, reverse, tolower, totitle, toupper, trim, trimleft, trimright, wordend, or wordstart}} |
| 52 |
test string-1.2.$noComp {error conditions} { |
| 53 |
list [catch {run {string}} msg] $msg |
| 54 |
} {1 {wrong # args: should be "string subcommand ?arg ...?"}} |
| 55 |
|
| 56 |
test string-2.1.$noComp {string compare, not enough args} { |
| 57 |
list [catch {run {string compare a}} msg] $msg |
| 58 |
} {1 {wrong # args: should be "string compare ?-nocase? ?-length int? string1 string2"}} |
| 59 |
test string-2.2.$noComp {string compare, bad args} { |
| 60 |
list [catch {run {string compare a b c}} msg] $msg |
| 61 |
} {1 {bad option "a": must be -nocase or -length}} |
| 62 |
test string-2.3.$noComp {string compare, bad args} { |
| 63 |
list [catch {run {string compare -length -nocase str1 str2}} msg] $msg |
| 64 |
} {1 {expected integer but got "-nocase"}} |
| 65 |
test string-2.4.$noComp {string compare, too many args} { |
| 66 |
list [catch {run {string compare -length 10 -nocase str1 str2 str3}} msg] $msg |
| 67 |
} {1 {wrong # args: should be "string compare ?-nocase? ?-length int? string1 string2"}} |
| 68 |
test string-2.5.$noComp {string compare with length unspecified} { |
| 69 |
list [catch {run {string compare -length 10 10}} msg] $msg |
| 70 |
} {1 {wrong # args: should be "string compare ?-nocase? ?-length int? string1 string2"}} |
| 71 |
test string-2.6.$noComp {string compare} { |
| 72 |
run {string compare abcde abdef} |
| 73 |
} -1 |
| 74 |
test string-2.7.$noComp {string compare, shortest method name} { |
| 75 |
run {string co abcde ABCDE} |
| 76 |
} 1 |
| 77 |
test string-2.8.$noComp {string compare} { |
| 78 |
run {string compare abcde abcde} |
| 79 |
} 0 |
| 80 |
test string-2.9.$noComp {string compare with length} { |
| 81 |
run {string compare -length 2 abcde abxyz} |
| 82 |
} 0 |
| 83 |
test string-2.10.$noComp {string compare with special index} { |
| 84 |
list [catch {run {string compare -length end-3 abcde abxyz}} msg] $msg |
| 85 |
} {1 {expected integer but got "end-3"}} |
| 86 |
test string-2.11.$noComp {string compare, unicode} { |
| 87 |
run {string compare ab\u7266 ab\u7267} |
| 88 |
} -1 |
| 89 |
test string-2.12.$noComp {string compare, high bit} { |
| 90 |
# This test fails if the underlying comparison |
| 91 |
# is using signed chars instead of unsigned chars. |
| 92 |
# (like SunOS's default memcmp thus the compat/memcmp.c) |
| 93 |
run {string compare "\x80" "@"} |
| 94 |
# Nb this tests works also in utf-8 space because \x80 is |
| 95 |
# translated into a 2 or more bytelength but whose first byte has |
| 96 |
# the high bit set. |
| 97 |
} 1 |
| 98 |
test string-2.13.$noComp {string compare -nocase} { |
| 99 |
run {string compare -nocase abcde abdef} |
| 100 |
} -1 |
| 101 |
test string-2.14.$noComp {string compare -nocase} { |
| 102 |
run {string compare -nocase abcde ABCDE} |
| 103 |
} 0 |
| 104 |
test string-2.15.$noComp {string compare -nocase} { |
| 105 |
run {string compare -nocase abcde abcde} |
| 106 |
} 0 |
| 107 |
test string-2.16.$noComp {string compare -nocase with length} { |
| 108 |
run {string compare -length 2 -nocase abcde Abxyz} |
| 109 |
} 0 |
| 110 |
test string-2.17.$noComp {string compare -nocase with length} { |
| 111 |
run {string compare -nocase -length 3 abcde Abxyz} |
| 112 |
} -1 |
| 113 |
test string-2.18.$noComp {string compare -nocase with length <= 0} { |
| 114 |
run {string compare -nocase -length -1 abcde AbCdEf} |
| 115 |
} -1 |
| 116 |
test string-2.19.$noComp {string compare -nocase with excessive length} { |
| 117 |
run {string compare -nocase -length 50 AbCdEf abcde} |
| 118 |
} 1 |
| 119 |
test string-2.20.$noComp {string compare -len unicode} { |
| 120 |
# These are strings that are 6 BYTELENGTH long, but the length |
| 121 |
# shouldn't make a different because there are actually 3 CHARS long |
| 122 |
run {string compare -len 5 \334\334\334 \334\334\374} |
| 123 |
} -1 |
| 124 |
test string-2.21.$noComp {string compare -nocase with special index} { |
| 125 |
list [catch {run {string compare -nocase -length end-3 Abcde abxyz}} msg] $msg |
| 126 |
} {1 {expected integer but got "end-3"}} |
| 127 |
test string-2.22.$noComp {string compare, null strings} { |
| 128 |
run {string compare "" ""} |
| 129 |
} 0 |
| 130 |
test string-2.23.$noComp {string compare, null strings} { |
| 131 |
run {string compare "" foo} |
| 132 |
} -1 |
| 133 |
test string-2.24.$noComp {string compare, null strings} { |
| 134 |
run {string compare foo ""} |
| 135 |
} 1 |
| 136 |
test string-2.25.$noComp {string compare -nocase, null strings} { |
| 137 |
run {string compare -nocase "" ""} |
| 138 |
} 0 |
| 139 |
test string-2.26.$noComp {string compare -nocase, null strings} { |
| 140 |
run {string compare -nocase "" foo} |
| 141 |
} -1 |
| 142 |
test string-2.27.$noComp {string compare -nocase, null strings} { |
| 143 |
run {string compare -nocase foo ""} |
| 144 |
} 1 |
| 145 |
test string-2.28.$noComp {string compare with length, unequal strings, partial first string} { |
| 146 |
run {string compare -length 2 abc abde} |
| 147 |
} 0 |
| 148 |
test string-2.29.$noComp {string compare with length, unequal strings 2, full first string} { |
| 149 |
run {string compare -length 2 ab abde} |
| 150 |
} 0 |
| 151 |
test string-2.30.$noComp {string compare with NUL character vs. other ASCII} { |
| 152 |
# Be careful here, since UTF-8 rep comparison with memcmp() of |
| 153 |
# these puts chars in the wrong order |
| 154 |
run {string compare \x00 \x01} |
| 155 |
} -1 |
| 156 |
test string-2.31.$noComp {string compare, high bit} { |
| 157 |
run {string compare "a\x80" "a@"} |
| 158 |
} 1 |
| 159 |
test string-2.32.$noComp {string compare, high bit} { |
| 160 |
run {string compare "a\x00" "a\x01"} |
| 161 |
} -1 |
| 162 |
test string-2.33.$noComp {string compare, high bit} { |
| 163 |
run {string compare "\x00\x00" "\x00\x01"} |
| 164 |
} -1 |
| 165 |
test string-2.34.$noComp {string compare, binary equal} { |
| 166 |
run {string compare [binary format a100 0] [binary format a100 0]} |
| 167 |
} 0 |
| 168 |
test string-2.35.$noComp {string compare, binary neq} { |
| 169 |
run {string compare [binary format a100a 0 1] [binary format a100a 0 0]} |
| 170 |
} 1 |
| 171 |
test string-2.36.$noComp {string compare, binary neq unequal length} { |
| 172 |
run {string compare [binary format a20a 0 1] [binary format a100a 0 0]} |
| 173 |
} 1 |
| 174 |
test string-2.37.$noComp {string compare, big -length} { |
| 175 |
run {string compare -length 0x7fffffff ab abde} |
| 176 |
} -1 |
| 177 |
test string-2.38a.$noComp {string compare empty string against byte array} { |
| 178 |
# Bug edb4b065f4 |
| 179 |
run {string compare "" [binary decode hex 00]} |
| 180 |
} -1 |
| 181 |
test string-2.38b.$noComp {string compare -length empty string against byte array} { |
| 182 |
# Bug edb4b065f4 |
| 183 |
run {string compare -length 1 "" [binary decode hex 00]} |
| 184 |
} -1 |
| 185 |
test string-2.38c.$noComp {string compare -nocase empty string against byte array} { |
| 186 |
# Bug edb4b065f4 |
| 187 |
run {string compare -nocase "" [binary decode hex 00]} |
| 188 |
} -1 |
| 189 |
test string-2.38d.$noComp {string compare empty string against byte array} { |
| 190 |
# Bug edb4b065f4 |
| 191 |
run {string compare [binary decode hex 00] ""} |
| 192 |
} 1 |
| 193 |
test string-2.38e.$noComp {string compare -length empty string against byte array} { |
| 194 |
# Bug edb4b065f4 |
| 195 |
run {string compare -length 1 [binary decode hex 00] ""} |
| 196 |
} 1 |
| 197 |
test string-2.38f.$noComp {string compare -nocase empty string against byte array} { |
| 198 |
# Bug edb4b065f4 |
| 199 |
run {string compare -nocase [binary decode hex 00] ""} |
| 200 |
} 1 |
| 201 |
|
| 202 |
# only need a few tests on equal, since it uses the same code as |
| 203 |
# string compare, but just modifies the return output |
| 204 |
test string-3.1.$noComp {string equal} { |
| 205 |
run {string equal abcde abdef} |
| 206 |
} 0 |
| 207 |
test string-3.2.$noComp {string equal} { |
| 208 |
run {string e abcde ABCDE} |
| 209 |
} 0 |
| 210 |
test string-3.3.$noComp {string equal} { |
| 211 |
run {string equal abcde abcde} |
| 212 |
} 1 |
| 213 |
test string-3.4.$noComp {string equal -nocase} { |
| 214 |
run {string equal -nocase \334\334\334\334\374\374\374\374 \334\334\334\334\334\334\334\334} |
| 215 |
} 1 |
| 216 |
test string-3.5.$noComp {string equal -nocase} { |
| 217 |
run {string equal -nocase abcde abdef} |
| 218 |
} 0 |
| 219 |
test string-3.6.$noComp {string equal -nocase} { |
| 220 |
run {string eq -nocase abcde ABCDE} |
| 221 |
} 1 |
| 222 |
test string-3.7.$noComp {string equal -nocase} { |
| 223 |
run {string equal -nocase abcde abcde} |
| 224 |
} 1 |
| 225 |
test string-3.8.$noComp {string equal with length, unequal strings} { |
| 226 |
run {string equal -length 2 abc abde} |
| 227 |
} 1 |
| 228 |
test string-3.9.$noComp {string equal, not enough args} { |
| 229 |
list [catch {run {string equal a}} msg] $msg |
| 230 |
} {1 {wrong # args: should be "string equal ?-nocase? ?-length int? string1 string2"}} |
| 231 |
test string-3.10.$noComp {string equal, bad args} { |
| 232 |
list [catch {run {string equal a b c}} msg] $msg |
| 233 |
} {1 {bad option "a": must be -nocase or -length}} |
| 234 |
test string-3.11.$noComp {string equal, bad args} { |
| 235 |
list [catch {run {string equal -length -nocase str1 str2}} msg] $msg |
| 236 |
} {1 {expected integer but got "-nocase"}} |
| 237 |
test string-3.12.$noComp {string equal, too many args} { |
| 238 |
list [catch {run {string equal -length 10 -nocase str1 str2 str3}} msg] $msg |
| 239 |
} {1 {wrong # args: should be "string equal ?-nocase? ?-length int? string1 string2"}} |
| 240 |
test string-3.13.$noComp {string equal with length unspecified} { |
| 241 |
list [catch {run {string equal -length 10 10}} msg] $msg |
| 242 |
} {1 {wrong # args: should be "string equal ?-nocase? ?-length int? string1 string2"}} |
| 243 |
test string-3.14.$noComp {string equal with length} { |
| 244 |
run {string equal -length 2 abcde abxyz} |
| 245 |
} 1 |
| 246 |
test string-3.15.$noComp {string equal with special index} { |
| 247 |
list [catch {run {string equal -length end-3 abcde abxyz}} msg] $msg |
| 248 |
} {1 {expected integer but got "end-3"}} |
| 249 |
|
| 250 |
test string-3.16.$noComp {string equal, unicode} { |
| 251 |
run {string equal ab\u7266 ab\u7267} |
| 252 |
} 0 |
| 253 |
test string-3.17.$noComp {string equal, unicode} { |
| 254 |
run {string equal \xDC \xDC} |
| 255 |
} 1 |
| 256 |
test string-3.18.$noComp {string equal, unicode} { |
| 257 |
run {string equal \xDC \xFC} |
| 258 |
} 0 |
| 259 |
test string-3.19.$noComp {string equal, unicode} { |
| 260 |
run {string equal \xDC\xDC\xDC\xFC\xFC \xDC\xDC\xDC\xDC\xDC} |
| 261 |
} 0 |
| 262 |
test string-3.20.$noComp {string equal, high bit} { |
| 263 |
# This test fails if the underlying comparison |
| 264 |
# is using signed chars instead of unsigned chars. |
| 265 |
# (like SunOS's default memcmp thus the compat/memcmp.c) |
| 266 |
run {string equal "\x80" "@"} |
| 267 |
# Nb this tests works also in utf8 space because \x80 is |
| 268 |
# translated into a 2 or more bytelength but whose first byte has |
| 269 |
# the high bit set. |
| 270 |
} 0 |
| 271 |
test string-3.21.$noComp {string equal -nocase} { |
| 272 |
run {string equal -nocase abcde Abdef} |
| 273 |
} 0 |
| 274 |
test string-3.22.$noComp {string equal, -nocase unicode} { |
| 275 |
run {string equal -nocase \xDC \xDC} |
| 276 |
} 1 |
| 277 |
test string-3.23.$noComp {string equal, -nocase unicode} { |
| 278 |
run {string equal -nocase \xDC\xDC\xDC\xFC\xFC \xDC\xDC\xDC\xDC\xDC} |
| 279 |
} 1 |
| 280 |
test string-3.24.$noComp {string equal -nocase with length} { |
| 281 |
run {string equal -length 2 -nocase abcde Abxyz} |
| 282 |
} 1 |
| 283 |
test string-3.25.$noComp {string equal -nocase with length} { |
| 284 |
run {string equal -nocase -length 3 abcde Abxyz} |
| 285 |
} 0 |
| 286 |
test string-3.26.$noComp {string equal -nocase with length <= 0} { |
| 287 |
run {string equal -nocase -length -1 abcde AbCdEf} |
| 288 |
} 0 |
| 289 |
test string-3.27.$noComp {string equal -nocase with excessive length} { |
| 290 |
run {string equal -nocase -length 50 AbCdEf abcde} |
| 291 |
} 0 |
| 292 |
test string-3.28.$noComp {string equal -len unicode} { |
| 293 |
# These are strings that are 6 BYTELENGTH long, but the length |
| 294 |
# shouldn't make a different because there are actually 3 CHARS long |
| 295 |
run {string equal -len 5 \xDC\xDC\xDC \xDC\xDC\xFC} |
| 296 |
} 0 |
| 297 |
test string-3.29.$noComp {string equal -nocase with special index} { |
| 298 |
list [catch {run {string equal -nocase -length end-3 Abcde abxyz}} msg] $msg |
| 299 |
} {1 {expected integer but got "end-3"}} |
| 300 |
test string-3.30.$noComp {string equal, null strings} { |
| 301 |
run {string equal "" ""} |
| 302 |
} 1 |
| 303 |
test string-3.31.$noComp {string equal, null strings} { |
| 304 |
run {string equal "" foo} |
| 305 |
} 0 |
| 306 |
test string-3.32.$noComp {string equal, null strings} { |
| 307 |
run {string equal foo ""} |
| 308 |
} 0 |
| 309 |
test string-3.33.$noComp {string equal -nocase, null strings} { |
| 310 |
run {string equal -nocase "" ""} |
| 311 |
} 1 |
| 312 |
test string-3.34.$noComp {string equal -nocase, null strings} { |
| 313 |
run {string equal -nocase "" foo} |
| 314 |
} 0 |
| 315 |
test string-3.35.$noComp {string equal -nocase, null strings} { |
| 316 |
run {string equal -nocase foo ""} |
| 317 |
} 0 |
| 318 |
test string-3.36.$noComp {string equal with NUL character vs. other ASCII} { |
| 319 |
# Be careful here, since UTF-8 rep comparison with memcmp() of |
| 320 |
# these puts chars in the wrong order |
| 321 |
run {string equal \x00 \x01} |
| 322 |
} 0 |
| 323 |
test string-3.37.$noComp {string equal, high bit} { |
| 324 |
run {string equal "a\x80" "a@"} |
| 325 |
} 0 |
| 326 |
test string-3.38.$noComp {string equal, high bit} { |
| 327 |
run {string equal "a\x00" "a\x01"} |
| 328 |
} 0 |
| 329 |
test string-3.39.$noComp {string equal, high bit} { |
| 330 |
run {string equal "a\x00\x00" "a\x00\x01"} |
| 331 |
} 0 |
| 332 |
test string-3.40.$noComp {string equal, binary equal} { |
| 333 |
run {string equal [binary format a100 0] [binary format a100 0]} |
| 334 |
} 1 |
| 335 |
test string-3.41.$noComp {string equal, binary neq} { |
| 336 |
run {string equal [binary format a100a 0 1] [binary format a100a 0 0]} |
| 337 |
} 0 |
| 338 |
test string-3.42.$noComp {string equal, binary neq inequal length} { |
| 339 |
run {string equal [binary format a20a 0 1] [binary format a100a 0 0]} |
| 340 |
} 0 |
| 341 |
test string-3.43.$noComp {string equal, big -length} { |
| 342 |
run {string equal -length 0x7fffffff abc def} |
| 343 |
} 0 |
| 344 |
test string-3.44.$noComp {string equal, bigger -length} -body { |
| 345 |
run {string equal -length 18446744073709551616 abc def} |
| 346 |
} -returnCodes 1 -result {integer value too large to represent} |
| 347 |
test string-3.45a.$noComp {string equal empty string against byte array} { |
| 348 |
# Bug edb4b065f4 |
| 349 |
run {string equal "" [binary decode hex 00]} |
| 350 |
} 0 |
| 351 |
test string-3.45b.$noComp {string equal -length empty string against byte array} { |
| 352 |
# Bug edb4b065f4 |
| 353 |
run {string equal -length 1 "" [binary decode hex 00]} |
| 354 |
} 0 |
| 355 |
test string-3.45c.$noComp {string equal -nocase empty string against byte array} { |
| 356 |
# Bug edb4b065f4 |
| 357 |
run {string equal -nocase "" [binary decode hex 00]} |
| 358 |
} 0 |
| 359 |
test string-3.45d.$noComp {string equal empty string against byte array} { |
| 360 |
# Bug edb4b065f4 |
| 361 |
run {string equal [binary decode hex 00] ""} |
| 362 |
} 0 |
| 363 |
test string-3.45e.$noComp {string equal -length empty string against byte array} { |
| 364 |
# Bug edb4b065f4 |
| 365 |
run {string equal -length 1 [binary decode hex 00] ""} |
| 366 |
} 0 |
| 367 |
test string-3.45f.$noComp {string equal -nocase empty string against byte array} { |
| 368 |
# Bug edb4b065f4 |
| 369 |
run {string equal -nocase [binary decode hex 00] ""} |
| 370 |
} 0 |
| 371 |
|
| 372 |
|
| 373 |
test string-4.1.$noComp {string first, not enough args} { |
| 374 |
list [catch {run {string first a}} msg] $msg |
| 375 |
} {1 {wrong # args: should be "string first needleString haystackString ?startIndex?"}} |
| 376 |
test string-4.2.$noComp {string first, bad args} { |
| 377 |
list [catch {run {string first a b c}} msg] $msg |
| 378 |
} {1 {bad index "c": must be integer?[+-]integer? or end?[+-]integer?}} |
| 379 |
test string-4.3.$noComp {string first, too many args} { |
| 380 |
list [catch {run {string first a b 5 d}} msg] $msg |
| 381 |
} {1 {wrong # args: should be "string first needleString haystackString ?startIndex?"}} |
| 382 |
test string-4.4.$noComp {string first} { |
| 383 |
run {string first bq abcdefgbcefgbqrs} |
| 384 |
} 12 |
| 385 |
test string-4.5.$noComp {string first} { |
| 386 |
run {string fir bcd abcdefgbcefgbqrs} |
| 387 |
} 1 |
| 388 |
test string-4.6.$noComp {string first} { |
| 389 |
run {string f b abcdefgbcefgbqrs} |
| 390 |
} 1 |
| 391 |
test string-4.7.$noComp {string first} { |
| 392 |
run {string first xxx x123xx345xxx789xxx012} |
| 393 |
} 9 |
| 394 |
test string-4.8.$noComp {string first} { |
| 395 |
run {string first "" x123xx345xxx789xxx012} |
| 396 |
} -1 |
| 397 |
test string-4.9.$noComp {string first, unicode} { |
| 398 |
run {string first x abc\u7266x} |
| 399 |
} 4 |
| 400 |
test string-4.10.$noComp {string first, unicode} { |
| 401 |
run {string first \u7266 abc\u7266x} |
| 402 |
} 3 |
| 403 |
test string-4.11.$noComp {string first, start index} { |
| 404 |
run {string first \u7266 abc\u7266x 3} |
| 405 |
} 3 |
| 406 |
test string-4.12.$noComp {string first, start index} -body { |
| 407 |
run {string first \u7266 abc\u7266x 4} |
| 408 |
} -result -1 |
| 409 |
test string-4.13.$noComp {string first, start index} -body { |
| 410 |
run {string first \u7266 abc\u7266x end-2} |
| 411 |
} -result 3 |
| 412 |
test string-4.14.$noComp {string first, negative start index} -body { |
| 413 |
run {string first b abc -1} |
| 414 |
} -result 1 |
| 415 |
test string-4.15.$noComp {string first, ability to two-byte encoded utf-8 chars} -body { |
| 416 |
# Test for a bug in Tcl 8.3 where test for all-single-byte-encoded |
| 417 |
# strings was incorrect, leading to an index returned by [string first] |
| 418 |
# which pointed past the end of the string. |
| 419 |
set uchar \u057E ;# character with two-byte encoding in utf-8 |
| 420 |
run {string first % %#$uchar$uchar#$uchar$uchar#% 3} |
| 421 |
} -result 8 |
| 422 |
test string-4.17.$noComp {string first, corner case} -body { |
| 423 |
run {string first a aaa 4294967295} |
| 424 |
} -result 0 |
| 425 |
test string-4.18.$noComp {string first, corner case} -body { |
| 426 |
run {string first a aaa -1} |
| 427 |
} -result 0 |
| 428 |
test string-4.19.$noComp {string first, corner case} -body { |
| 429 |
run {string first a aaa end-5} |
| 430 |
} -result 0 |
| 431 |
test string-4.20.$noComp {string last, corner case} -body { |
| 432 |
run {string last a aaa 4294967295} |
| 433 |
} -result -1 |
| 434 |
test string-4.21.$noComp {string last, corner case} -body { |
| 435 |
run {string last a aaa -1} |
| 436 |
} -result -1 |
| 437 |
test string-4.22.$noComp {string last, corner case} { |
| 438 |
run {string last a aaa end-5} |
| 439 |
} -1 |
| 440 |
|
| 441 |
test string-5.1.$noComp {string index} { |
| 442 |
list [catch {run {string index}} msg] $msg |
| 443 |
} {1 {wrong # args: should be "string index string charIndex"}} |
| 444 |
test string-5.2.$noComp {string index} { |
| 445 |
list [catch {run {string index a b c}} msg] $msg |
| 446 |
} {1 {wrong # args: should be "string index string charIndex"}} |
| 447 |
test string-5.3.$noComp {string index} { |
| 448 |
run {string index abcde 0} |
| 449 |
} a |
| 450 |
test string-5.4.$noComp {string index} { |
| 451 |
run {string ind abcde 4} |
| 452 |
} e |
| 453 |
test string-5.5.$noComp {string index} { |
| 454 |
run {string index abcde 5} |
| 455 |
} {} |
| 456 |
test string-5.6.$noComp {string index} { |
| 457 |
list [catch {run {string index abcde -10}} msg] $msg |
| 458 |
} {0 {}} |
| 459 |
test string-5.7.$noComp {string index} { |
| 460 |
list [catch {run {string index a xyz}} msg] $msg |
| 461 |
} {1 {bad index "xyz": must be integer?[+-]integer? or end?[+-]integer?}} |
| 462 |
test string-5.8.$noComp {string index} { |
| 463 |
run {string index abc end} |
| 464 |
} c |
| 465 |
test string-5.9.$noComp {string index} { |
| 466 |
run {string index abc end-1} |
| 467 |
} b |
| 468 |
test string-5.10.$noComp {string index, unicode} { |
| 469 |
run {string index abc\u7266d 4} |
| 470 |
} d |
| 471 |
test string-5.11.$noComp {string index, unicode} { |
| 472 |
run {string index abc\u7266d 3} |
| 473 |
} \u7266 |
| 474 |
test string-5.12.$noComp {string index, unicode over char length, under byte length} -body { |
| 475 |
run {string index \334\374\334\374 6} |
| 476 |
} -result {} |
| 477 |
test string-5.13.$noComp {string index, bytearray object} { |
| 478 |
run {string index [binary format a5 fuz] 0} |
| 479 |
} f |
| 480 |
test string-5.14.$noComp {string index, bytearray object} { |
| 481 |
run {string index [binary format I* {0x50515253 0x52}] 3} |
| 482 |
} S |
| 483 |
test string-5.15.$noComp {string index, bytearray object} { |
| 484 |
set b [binary format I* {0x50515253 0x52}] |
| 485 |
set i1 [run {string index $b end-6}] |
| 486 |
set i2 [run {string index $b 1}] |
| 487 |
run {string compare $i1 $i2} |
| 488 |
} 0 |
| 489 |
test string-5.16.$noComp {string index, bytearray object with string obj shimmering} { |
| 490 |
set str "0123456789\x00 abcdedfghi" |
| 491 |
binary scan $str H* dump |
| 492 |
run {string compare [run {string index $str 10}] \x00} |
| 493 |
} 0 |
| 494 |
test string-5.17.$noComp {string index, bad integer} -body { |
| 495 |
list [catch {run {string index "abc" 0o8}} msg] $msg |
| 496 |
} -match glob -result {1 {*invalid octal number*}} |
| 497 |
test string-5.18.$noComp {string index, bad integer} -body { |
| 498 |
list [catch {run {string index "abc" end-0o0289}} msg] $msg |
| 499 |
} -match glob -result {1 {*invalid octal number*}} |
| 500 |
test string-5.19.$noComp {string index, bytearray object out of bounds} { |
| 501 |
run {string index [binary format I* {0x50515253 0x52}] -1} |
| 502 |
} {} |
| 503 |
test string-5.20.$noComp {string index, bytearray object out of bounds} -body { |
| 504 |
run {string index [binary format I* {0x50515253 0x52}] 20} |
| 505 |
} -result {} |
| 506 |
test string-5.22.$noComp {string index} -constraints testbytestring -body { |
| 507 |
run {list [scan [string index [testbytestring \xFF] 0] %c var] $var} |
| 508 |
} -result {1 255} |
| 509 |
|
| 510 |
proc largest_int {} { |
| 511 |
# This will give us what the largest valid int on this machine is, |
| 512 |
# so we can test for overflow properly below on >32 bit systems |
| 513 |
set int 1 |
| 514 |
set exp 7; # assume we get at least 8 bits |
| 515 |
while {wide($int) > 0} { set int [expr {wide(1) << [incr exp]}] } |
| 516 |
return [expr {$int-1}] |
| 517 |
} |
| 518 |
|
| 519 |
test string-6.1.$noComp {string is, not enough args} { |
| 520 |
list [catch {run {string is}} msg] $msg |
| 521 |
} {1 {wrong # args: should be "string is class ?-strict? ?-failindex var? str"}} |
| 522 |
test string-6.2.$noComp {string is, not enough args} { |
| 523 |
list [catch {run {string is alpha}} msg] $msg |
| 524 |
} {1 {wrong # args: should be "string is class ?-strict? ?-failindex var? str"}} |
| 525 |
test string-6.3.$noComp {string is, bad args} { |
| 526 |
list [catch {run {string is alpha -failin str}} msg] $msg |
| 527 |
} {1 {wrong # args: should be "string is alpha ?-strict? ?-failindex var? str"}} |
| 528 |
test string-6.4.$noComp {string is, too many args} { |
| 529 |
list [catch {run {string is alpha -failin var -strict str more}} msg] $msg |
| 530 |
} {1 {wrong # args: should be "string is class ?-strict? ?-failindex var? str"}} |
| 531 |
test string-6.5.$noComp {string is, class check} { |
| 532 |
list [catch {run {string is bogus str}} msg] $msg |
| 533 |
} {1 {bad class "bogus": must be alnum, alpha, ascii, control, boolean, digit, double, entier, false, graph, integer, list, lower, print, punct, space, true, upper, wideinteger, wordchar, or xdigit}} |
| 534 |
test string-6.6.$noComp {string is, ambiguous class} { |
| 535 |
list [catch {run {string is al str}} msg] $msg |
| 536 |
} {1 {ambiguous class "al": must be alnum, alpha, ascii, control, boolean, digit, double, entier, false, graph, integer, list, lower, print, punct, space, true, upper, wideinteger, wordchar, or xdigit}} |
| 537 |
test string-6.7.$noComp {string is alpha, all ok} { |
| 538 |
run {string is alpha -strict -failindex var abc} |
| 539 |
} 1 |
| 540 |
test string-6.8.$noComp {string is, error in var} { |
| 541 |
list [run {string is alpha -failindex var abc5def}] $var |
| 542 |
} {0 3} |
| 543 |
test string-6.9.$noComp {string is, var shouldn't get set} { |
| 544 |
catch {unset var} |
| 545 |
list [catch {run {string is alpha -failindex var abc; set var}} msg] $msg |
| 546 |
} {1 {can't read "var": no such variable}} |
| 547 |
test string-6.10.$noComp {string is, ok on empty} { |
| 548 |
run {string is alpha {}} |
| 549 |
} 1 |
| 550 |
test string-6.11.$noComp {string is, -strict check against empty} { |
| 551 |
run {string is alpha -strict {}} |
| 552 |
} 0 |
| 553 |
test string-6.12.$noComp {string is alnum, true} { |
| 554 |
run {string is alnum abc123} |
| 555 |
} 1 |
| 556 |
test string-6.13.$noComp {string is alnum, false} { |
| 557 |
list [run {string is alnum -failindex var abc1.23}] $var |
| 558 |
} {0 4} |
| 559 |
test string-6.14.$noComp {string is alnum, unicode} "run {string is alnum abc\xfc}" 1 |
| 560 |
test string-6.15.$noComp {string is alpha, true} { |
| 561 |
run {string is alpha abc} |
| 562 |
} 1 |
| 563 |
test string-6.16.$noComp {string is alpha, false} { |
| 564 |
list [run {string is alpha -fail var a1bcde}] $var |
| 565 |
} {0 1} |
| 566 |
test string-6.17.$noComp {string is alpha, unicode} { |
| 567 |
run {string is alpha abc\374} |
| 568 |
} 1 |
| 569 |
test string-6.18.$noComp {string is ascii, true} { |
| 570 |
run {string is ascii abc\x7Fend\x00} |
| 571 |
} 1 |
| 572 |
test string-6.19.$noComp {string is ascii, false} { |
| 573 |
list [run {string is ascii -fail var abc\x00def\x80more}] $var |
| 574 |
} {0 7} |
| 575 |
test string-6.20.$noComp {string is boolean, true} { |
| 576 |
run {string is boolean true} |
| 577 |
} 1 |
| 578 |
test string-6.21.$noComp {string is boolean, true} { |
| 579 |
run {string is boolean f} |
| 580 |
} 1 |
| 581 |
test string-6.22.$noComp {string is boolean, true based on type} { |
| 582 |
run {string is bool [run {string compare a a}]} |
| 583 |
} 1 |
| 584 |
test string-6.23.$noComp {string is boolean, false} { |
| 585 |
list [run {string is bool -fail var yada}] $var |
| 586 |
} {0 0} |
| 587 |
test string-6.24.$noComp {string is digit, true} { |
| 588 |
run {string is digit 0123456789} |
| 589 |
} 1 |
| 590 |
test string-6.25.$noComp {string is digit, false} { |
| 591 |
list [run {string is digit -fail var 0123\xDC567}] $var |
| 592 |
} {0 4} |
| 593 |
test string-6.26.$noComp {string is digit, false} { |
| 594 |
list [run {string is digit -fail var +123567}] $var |
| 595 |
} {0 0} |
| 596 |
test string-6.27.$noComp {string is double, true} { |
| 597 |
run {string is double 1} |
| 598 |
} 1 |
| 599 |
test string-6.28.$noComp {string is double, true} { |
| 600 |
run {string is double [expr {double(1)}]} |
| 601 |
} 1 |
| 602 |
test string-6.29.$noComp {string is double, true} { |
| 603 |
run {string is double 1.0} |
| 604 |
} 1 |
| 605 |
test string-6.30.$noComp {string is double, true} { |
| 606 |
run {string is double [run {string compare a a}]} |
| 607 |
} 1 |
| 608 |
test string-6.31.$noComp {string is double, true} { |
| 609 |
run {string is double " +1.0e-1 "} |
| 610 |
} 1 |
| 611 |
test string-6.32.$noComp {string is double, true} { |
| 612 |
run {string is double "\n1.0\v"} |
| 613 |
} 1 |
| 614 |
test string-6.33.$noComp {string is double, false} { |
| 615 |
list [run {string is double -fail var 1abc}] $var |
| 616 |
} {0 1} |
| 617 |
test string-6.34.$noComp {string is double, false} { |
| 618 |
list [run {string is double -fail var abc}] $var |
| 619 |
} {0 0} |
| 620 |
test string-6.35.$noComp {string is double, false} { |
| 621 |
list [run {string is double -fail var " 1.0e4e4 "}] $var |
| 622 |
} {0 8} |
| 623 |
test string-6.36.$noComp {string is double, false} { |
| 624 |
list [run {string is double -fail var "\n"}] $var |
| 625 |
} {0 0} |
| 626 |
test string-6.37.$noComp {string is double, false on int overflow} -setup { |
| 627 |
set var priorValue |
| 628 |
} -body { |
| 629 |
# Make it the largest int recognizable, with one more digit for overflow |
| 630 |
# Since bignums arrived in Tcl 8.5, the sense of this test changed. |
| 631 |
# Now integer values that exceed native limits become bignums, and |
| 632 |
# bignums can convert to doubles without error. |
| 633 |
list [run {string is double -fail var [largest_int]0}] $var |
| 634 |
} -result {1 priorValue} |
| 635 |
# string-6.38 removed, underflow on input is no longer an error. |
| 636 |
test string-6.39.$noComp {string is double, false} { |
| 637 |
# This test is non-portable because IRIX thinks |
| 638 |
# that .e1 is a valid double - this is really a bug |
| 639 |
# on IRIX as .e1 should NOT be a valid double |
| 640 |
# |
| 641 |
# Portable now. Tcl 8.5 does its own double parsing. |
| 642 |
|
| 643 |
list [run {string is double -fail var .e1}] $var |
| 644 |
} {0 0} |
| 645 |
test string-6.40.$noComp {string is false, true} { |
| 646 |
run {string is false false} |
| 647 |
} 1 |
| 648 |
test string-6.41.$noComp {string is false, true} { |
| 649 |
run {string is false FaLsE} |
| 650 |
} 1 |
| 651 |
test string-6.42.$noComp {string is false, true} { |
| 652 |
run {string is false N} |
| 653 |
} 1 |
| 654 |
test string-6.43.$noComp {string is false, true} { |
| 655 |
run {string is false 0} |
| 656 |
} 1 |
| 657 |
test string-6.44.$noComp {string is false, true} { |
| 658 |
run {string is false off} |
| 659 |
} 1 |
| 660 |
test string-6.45.$noComp {string is false, false} { |
| 661 |
list [run {string is false -fail var abc}] $var |
| 662 |
} {0 0} |
| 663 |
test string-6.46.$noComp {string is false, false} { |
| 664 |
catch {unset var} |
| 665 |
list [run {string is false -fail var Y}] $var |
| 666 |
} {0 0} |
| 667 |
test string-6.47.$noComp {string is false, false} { |
| 668 |
catch {unset var} |
| 669 |
list [run {string is false -fail var offensive}] $var |
| 670 |
} {0 0} |
| 671 |
test string-6.48.$noComp {string is integer, true} { |
| 672 |
run {string is integer +1234567890} |
| 673 |
} 1 |
| 674 |
test string-6.49.$noComp {string is integer, true on type} { |
| 675 |
run {string is integer [expr {int(50.0)}]} |
| 676 |
} 1 |
| 677 |
test string-6.50.$noComp {string is integer, true} { |
| 678 |
run {string is integer [list -10]} |
| 679 |
} 1 |
| 680 |
test string-6.51.$noComp {string is integer, true as hex} { |
| 681 |
run {string is integer 0xabcdef} |
| 682 |
} 1 |
| 683 |
test string-6.52.$noComp {string is integer, true as octal} { |
| 684 |
run {string is integer 012345} |
| 685 |
} 1 |
| 686 |
test string-6.53.$noComp {string is integer, true with whitespace} { |
| 687 |
run {string is integer " \n1234\v"} |
| 688 |
} 1 |
| 689 |
test string-6.54.$noComp {string is integer, false} { |
| 690 |
list [run {string is integer -fail var 123abc}] $var |
| 691 |
} {0 3} |
| 692 |
test string-6.55.$noComp {string is integer, false on overflow} { |
| 693 |
list [run {string is integer -fail var +[largest_int]0}] $var |
| 694 |
} {0 -1} |
| 695 |
test string-6.56.$noComp {string is integer, false} { |
| 696 |
list [run {string is integer -fail var [expr {double(1)}]}] $var |
| 697 |
} {0 1} |
| 698 |
test string-6.57.$noComp {string is integer, false} { |
| 699 |
list [run {string is integer -fail var " "}] $var |
| 700 |
} {0 0} |
| 701 |
test string-6.58.$noComp {string is integer, false on bad octal} { |
| 702 |
list [run {string is integer -fail var 0o36963}] $var |
| 703 |
} {0 4} |
| 704 |
test string-6.58.1.$noComp {string is integer, false on bad octal} { |
| 705 |
list [run {string is integer -fail var 0o36963}] $var |
| 706 |
} {0 4} |
| 707 |
test string-6.59.$noComp {string is integer, false on bad hex} { |
| 708 |
list [run {string is integer -fail var 0X345XYZ}] $var |
| 709 |
} {0 5} |
| 710 |
test string-6.60.$noComp {string is lower, true} { |
| 711 |
run {string is lower abc} |
| 712 |
} 1 |
| 713 |
test string-6.61.$noComp {string is lower, unicode true} { |
| 714 |
run {string is lower abc\xFCue} |
| 715 |
} 1 |
| 716 |
test string-6.62.$noComp {string is lower, false} { |
| 717 |
list [run {string is lower -fail var aBc}] $var |
| 718 |
} {0 1} |
| 719 |
test string-6.63.$noComp {string is lower, false} { |
| 720 |
list [run {string is lower -fail var abc1}] $var |
| 721 |
} {0 3} |
| 722 |
test string-6.64.$noComp {string is lower, unicode false} { |
| 723 |
list [run {string is lower -fail var ab\xDCUE}] $var |
| 724 |
} {0 2} |
| 725 |
test string-6.65.$noComp {string is space, true} { |
| 726 |
run {string is space " \t\n\v\f"} |
| 727 |
} 1 |
| 728 |
test string-6.66.$noComp {string is space, false} { |
| 729 |
list [run {string is space -fail var " \t\n\v1\f"}] $var |
| 730 |
} {0 4} |
| 731 |
test string-6.67.$noComp {string is true, true} { |
| 732 |
run {string is true true} |
| 733 |
} 1 |
| 734 |
test string-6.68.$noComp {string is true, true} { |
| 735 |
run {string is true TrU} |
| 736 |
} 1 |
| 737 |
test string-6.69.$noComp {string is true, true} { |
| 738 |
run {string is true ye} |
| 739 |
} 1 |
| 740 |
test string-6.70.$noComp {string is true, true} { |
| 741 |
run {string is true 1} |
| 742 |
} 1 |
| 743 |
test string-6.71.$noComp {string is true, true} { |
| 744 |
run {string is true on} |
| 745 |
} 1 |
| 746 |
test string-6.72.$noComp {string is true, false} { |
| 747 |
list [run {string is true -fail var onto}] $var |
| 748 |
} {0 0} |
| 749 |
test string-6.73.$noComp {string is true, false} { |
| 750 |
catch {unset var} |
| 751 |
list [run {string is true -fail var 25}] $var |
| 752 |
} {0 0} |
| 753 |
test string-6.74.$noComp {string is true, false} { |
| 754 |
catch {unset var} |
| 755 |
list [run {string is true -fail var no}] $var |
| 756 |
} {0 0} |
| 757 |
test string-6.75.$noComp {string is upper, true} { |
| 758 |
run {string is upper ABC} |
| 759 |
} 1 |
| 760 |
test string-6.76.$noComp {string is upper, unicode true} { |
| 761 |
run {string is upper ABC\xDCUE} |
| 762 |
} 1 |
| 763 |
test string-6.77.$noComp {string is upper, false} { |
| 764 |
list [run {string is upper -fail var AbC}] $var |
| 765 |
} {0 1} |
| 766 |
test string-6.78.$noComp {string is upper, false} { |
| 767 |
list [run {string is upper -fail var AB2C}] $var |
| 768 |
} {0 2} |
| 769 |
test string-6.79.$noComp {string is upper, unicode false} { |
| 770 |
list [run {string is upper -fail var ABC\xFCue}] $var |
| 771 |
} {0 3} |
| 772 |
test string-6.80.$noComp {string is wordchar, true} { |
| 773 |
run {string is wordchar abc_123} |
| 774 |
} 1 |
| 775 |
test string-6.81.$noComp {string is wordchar, unicode true} { |
| 776 |
run {string is wordchar abc\xFCab\xDCAB\u5001} |
| 777 |
} 1 |
| 778 |
test string-6.82.$noComp {string is wordchar, false} { |
| 779 |
list [run {string is wordchar -fail var abcd.ef}] $var |
| 780 |
} {0 4} |
| 781 |
test string-6.83.$noComp {string is wordchar, unicode false} { |
| 782 |
list [run {string is wordchar -fail var abc\x80def}] $var |
| 783 |
} {0 3} |
| 784 |
test string-6.84.$noComp {string is control} { |
| 785 |
## Control chars are in the ranges |
| 786 |
## 00..1F && 7F..9F |
| 787 |
list [run {string is control -fail var \x00\x01\x10\x1F\x7F\x80\x9F\x60}] $var |
| 788 |
} {0 7} |
| 789 |
test string-6.85.$noComp {string is control} { |
| 790 |
run {string is control \u0100} |
| 791 |
} 0 |
| 792 |
test string-6.86.$noComp {string is graph} { |
| 793 |
## graph is any print char, except space |
| 794 |
list [run {string is gra -fail var "0123abc!@#\$\u0100\UE0100\UE01EF "}] $var |
| 795 |
} {0 14} |
| 796 |
test string-6.87.$noComp {string is print} { |
| 797 |
## basically any printable char |
| 798 |
list [run {string is print -fail var "0123abc!@#\$\u0100 \UE0100\UE01EF\x10"}] $var |
| 799 |
} {0 15} |
| 800 |
test string-6.88.$noComp {string is punct} { |
| 801 |
## any graph char that isn't alnum |
| 802 |
list [run {string is punct -fail var "_!@#\xBEq0"}] $var |
| 803 |
} {0 4} |
| 804 |
test string-6.89.$noComp {string is xdigit} { |
| 805 |
list [run {string is xdigit -fail var 0123456789\x61bcdefABCDEFg}] $var |
| 806 |
} {0 22} |
| 807 |
|
| 808 |
test string-6.90.$noComp {string is integer, bad integers} { |
| 809 |
# SF bug #634856 |
| 810 |
set result "" |
| 811 |
set numbers [list 1 +1 ++1 +-1 -+1 -1 --1 "- +1"] |
| 812 |
foreach num $numbers { |
| 813 |
lappend result [run {string is int -strict $num}] |
| 814 |
} |
| 815 |
return $result |
| 816 |
} {1 1 0 0 0 1 0 0} |
| 817 |
test string-6.91.$noComp {string is double, bad doubles} { |
| 818 |
set result "" |
| 819 |
set numbers [list 1.0 +1.0 ++1.0 +-1.0 -+1.0 -1.0 --1.0 "- +1.0"] |
| 820 |
foreach num $numbers { |
| 821 |
lappend result [run {string is double -strict $num}] |
| 822 |
} |
| 823 |
return $result |
| 824 |
} {1 1 0 0 0 1 0 0} |
| 825 |
test string-6.92.$noComp {string is integer, 32-bit overflow} { |
| 826 |
# Bug 718878 |
| 827 |
set x 0x100000000 |
| 828 |
list [run {string is integer -failindex var $x}] $var |
| 829 |
} {0 -1} |
| 830 |
test string-6.93.$noComp {string is integer, 32-bit overflow} { |
| 831 |
# Bug 718878 |
| 832 |
set x 0x100000000 |
| 833 |
append x "" |
| 834 |
list [run {string is integer -failindex var $x}] $var |
| 835 |
} {0 -1} |
| 836 |
test string-6.94.$noComp {string is integer, 32-bit overflow} { |
| 837 |
# Bug 718878 |
| 838 |
set x 0x100000000 |
| 839 |
list [run {string is integer -failindex var [expr {$x}]}] $var |
| 840 |
} {0 -1} |
| 841 |
test string-6.95.$noComp {string is wideinteger, true} { |
| 842 |
run {string is wideinteger +1234567890} |
| 843 |
} 1 |
| 844 |
test string-6.96.$noComp {string is wideinteger, true on type} { |
| 845 |
run {string is wideinteger [expr {wide(50.0)}]} |
| 846 |
} 1 |
| 847 |
test string-6.97.$noComp {string is wideinteger, true} { |
| 848 |
run {string is wideinteger [list -10]} |
| 849 |
} 1 |
| 850 |
test string-6.98.$noComp {string is wideinteger, true as hex} { |
| 851 |
run {string is wideinteger 0xabcdef} |
| 852 |
} 1 |
| 853 |
test string-6.99.$noComp {string is wideinteger, true as octal} { |
| 854 |
run {string is wideinteger 0123456} |
| 855 |
} 1 |
| 856 |
test string-6.100.$noComp {string is wideinteger, true with whitespace} { |
| 857 |
run {string is wideinteger " \n1234\v"} |
| 858 |
} 1 |
| 859 |
test string-6.101.$noComp {string is wideinteger, false} { |
| 860 |
list [run {string is wideinteger -fail var 123abc}] $var |
| 861 |
} {0 3} |
| 862 |
test string-6.102.$noComp {string is wideinteger, false on overflow} { |
| 863 |
list [run {string is wideinteger -fail var +[largest_int]0}] $var |
| 864 |
} {0 -1} |
| 865 |
test string-6.103.$noComp {string is wideinteger, false} { |
| 866 |
list [run {string is wideinteger -fail var [expr {double(1)}]}] $var |
| 867 |
} {0 1} |
| 868 |
test string-6.104.$noComp {string is wideinteger, false} { |
| 869 |
list [run {string is wideinteger -fail var " "}] $var |
| 870 |
} {0 0} |
| 871 |
test string-6.105.$noComp {string is wideinteger, false on bad octal} { |
| 872 |
list [run {string is wideinteger -fail var 0o36963}] $var |
| 873 |
} {0 4} |
| 874 |
test string-6.105.1.$noComp {string is wideinteger, false on bad octal} { |
| 875 |
list [run {string is wideinteger -fail var 0o36963}] $var |
| 876 |
} {0 4} |
| 877 |
test string-6.106.$noComp {string is wideinteger, false on bad hex} { |
| 878 |
list [run {string is wideinteger -fail var 0X345XYZ}] $var |
| 879 |
} {0 5} |
| 880 |
test string-6.107.$noComp {string is integer, bad integers} { |
| 881 |
# SF bug #634856 |
| 882 |
set result "" |
| 883 |
set numbers [list 1 +1 ++1 +-1 -+1 -1 --1 "- +1"] |
| 884 |
foreach num $numbers { |
| 885 |
lappend result [run {string is wideinteger -strict $num}] |
| 886 |
} |
| 887 |
return $result |
| 888 |
} {1 1 0 0 0 1 0 0} |
| 889 |
test string-6.108.$noComp {string is double, Bug 1382287} { |
| 890 |
set x 2turtledoves |
| 891 |
run {string is double $x} |
| 892 |
run {string is double $x} |
| 893 |
} 0 |
| 894 |
test string-6.109.$noComp {string is double, Bug 1360532} { |
| 895 |
run {string is double 1\xA0} |
| 896 |
} 0 |
| 897 |
test string-6.110.$noComp {string is entier, true} { |
| 898 |
run {string is entier +1234567890} |
| 899 |
} 1 |
| 900 |
test string-6.111.$noComp {string is entier, true on type} { |
| 901 |
run {string is entier [expr {wide(50.0)}]} |
| 902 |
} 1 |
| 903 |
test string-6.112.$noComp {string is entier, true} { |
| 904 |
run {string is entier [list -10]} |
| 905 |
} 1 |
| 906 |
test string-6.113.$noComp {string is entier, true as hex} { |
| 907 |
run {string is entier 0xabcdef} |
| 908 |
} 1 |
| 909 |
test string-6.114.$noComp {string is entier, true as octal} { |
| 910 |
run {string is entier 0123456} |
| 911 |
} 1 |
| 912 |
test string-6.115.$noComp {string is entier, true with whitespace} { |
| 913 |
run {string is entier " \n1234\v"} |
| 914 |
} 1 |
| 915 |
test string-6.116.$noComp {string is entier, false} { |
| 916 |
list [run {string is entier -fail var 123abc}] $var |
| 917 |
} {0 3} |
| 918 |
test string-6.117.$noComp {string is entier, false} { |
| 919 |
list [run {string is entier -fail var 123123123123123123123123123123123123123123123123123123123123123123123123123123123123abc}] $var |
| 920 |
} {0 84} |
| 921 |
test string-6.118.$noComp {string is entier, false} { |
| 922 |
list [run {string is entier -fail var [expr {double(1)}]}] $var |
| 923 |
} {0 1} |
| 924 |
test string-6.119.$noComp {string is entier, false} { |
| 925 |
list [run {string is entier -fail var " "}] $var |
| 926 |
} {0 0} |
| 927 |
test string-6.120.$noComp {string is entier, false on bad octal} { |
| 928 |
list [run {string is entier -fail var 0o36963}] $var |
| 929 |
} {0 4} |
| 930 |
test string-6.121.1.$noComp {string is entier, false on bad octal} { |
| 931 |
list [run {string is entier -fail var 0o36963}] $var |
| 932 |
} {0 4} |
| 933 |
test string-6.122.$noComp {string is entier, false on bad hex} { |
| 934 |
list [run {string is entier -fail var 0X345XYZ}] $var |
| 935 |
} {0 5} |
| 936 |
test string-6.123.$noComp {string is entier, bad integers} { |
| 937 |
# SF bug #634856 |
| 938 |
set result "" |
| 939 |
set numbers [list 1 +1 ++1 +-1 -+1 -1 --1 "- +1"] |
| 940 |
foreach num $numbers { |
| 941 |
lappend result [run {string is entier -strict $num}] |
| 942 |
} |
| 943 |
return $result |
| 944 |
} {1 1 0 0 0 1 0 0} |
| 945 |
test string-6.124.$noComp {string is entier, true} { |
| 946 |
run {string is entier +1234567890123456789012345678901234567890} |
| 947 |
} 1 |
| 948 |
test string-6.125.$noComp {string is entier, true} { |
| 949 |
run {string is entier [list -10000000000000000000000000000000000000000000000000000000000000000000000000000000000000]} |
| 950 |
} 1 |
| 951 |
test string-6.126.$noComp {string is entier, true as hex} { |
| 952 |
run {string is entier 0xabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdef} |
| 953 |
} 1 |
| 954 |
test string-6.127.$noComp {string is entier, true as octal} { |
| 955 |
run {string is entier 0123456112341234561234565623456123456123456123456123456123456123456123456123456123456} |
| 956 |
} 1 |
| 957 |
test string-6.128.$noComp {string is entier, true with whitespace} { |
| 958 |
run {string is entier " \n12340000000000000000000000000000000000000000000000000000000000000000000000000000000000000\v"} |
| 959 |
} 1 |
| 960 |
test string-6.129.$noComp {string is entier, false on bad octal} { |
| 961 |
list [run {string is entier -fail var 0o1234561123412345612345656234561234561234561234561234561234561234561234561234561234536963}] $var |
| 962 |
} {0 87} |
| 963 |
test string-6.130.1.$noComp {string is entier, false on bad octal} { |
| 964 |
list [run {string is entier -fail var 0o1234561123412345612345656234561234561234561234561234561234561234561234561234561234536963}] $var |
| 965 |
} {0 87} |
| 966 |
test string-6.131.$noComp {string is entier, false on bad hex} { |
| 967 |
list [run {string is entier -fail var 0X12345611234123456123456562345612345612345612345612345612345612345612345612345612345345XYZ}] $var |
| 968 |
} {0 88} |
| 969 |
test string-6.139.$noComp {string is integer, bug [76ad7aeba3]} { |
| 970 |
run {string is integer 18446744073709551615} |
| 971 |
} 0 |
| 972 |
test string-6.140.$noComp {string is integer, bug [76ad7aeba3]} { |
| 973 |
run {string is integer -18446744073709551615} |
| 974 |
} 0 |
| 975 |
|
| 976 |
catch {rename largest_int {}} |
| 977 |
|
| 978 |
test string-7.1.$noComp {string last, not enough args} { |
| 979 |
list [catch {run {string last a}} msg] $msg |
| 980 |
} {1 {wrong # args: should be "string last needleString haystackString ?startIndex?"}} |
| 981 |
test string-7.2.$noComp {string last, bad args} { |
| 982 |
list [catch {run {string last a b c}} msg] $msg |
| 983 |
} {1 {bad index "c": must be integer?[+-]integer? or end?[+-]integer?}} |
| 984 |
test string-7.3.$noComp {string last, too many args} { |
| 985 |
list [catch {run {string last a b c d}} msg] $msg |
| 986 |
} {1 {wrong # args: should be "string last needleString haystackString ?startIndex?"}} |
| 987 |
test string-7.4.$noComp {string last} { |
| 988 |
run {string la xxx xxxx123xx345x678} |
| 989 |
} 1 |
| 990 |
test string-7.5.$noComp {string last} { |
| 991 |
run {string last xx xxxx123xx345x678} |
| 992 |
} 7 |
| 993 |
test string-7.6.$noComp {string last} { |
| 994 |
run {string las x xxxx123xx345x678} |
| 995 |
} 12 |
| 996 |
test string-7.7.$noComp {string last, unicode} { |
| 997 |
run {string las x xxxx12\u7266xx345x678} |
| 998 |
} 12 |
| 999 |
test string-7.8.$noComp {string last, unicode} { |
| 1000 |
run {string las \u7266 xxxx12\u7266xx345x678} |
| 1001 |
} 6 |
| 1002 |
test string-7.9.$noComp {string last, stop index} { |
| 1003 |
run {string las \u7266 xxxx12\u7266xx345x678} |
| 1004 |
} 6 |
| 1005 |
test string-7.10.$noComp {string last, unicode} { |
| 1006 |
run {string las \u7266 xxxx12\u7266xx345x678} |
| 1007 |
} 6 |
| 1008 |
test string-7.11.$noComp {string last, start index} { |
| 1009 |
run {string last \u7266 abc\u7266x 3} |
| 1010 |
} 3 |
| 1011 |
test string-7.12.$noComp {string last, start index} { |
| 1012 |
run {string last \u7266 abc\u7266x 2} |
| 1013 |
} -1 |
| 1014 |
test string-7.13.$noComp {string last, start index} { |
| 1015 |
## Constrain to last 'a' should work |
| 1016 |
run {string last ba badbad end-1} |
| 1017 |
} 3 |
| 1018 |
test string-7.14.$noComp {string last, start index} { |
| 1019 |
## Constrain to last 'b' should skip last 'ba' |
| 1020 |
run {string last ba badbad end-2} |
| 1021 |
} 0 |
| 1022 |
test string-7.15.$noComp {string last, start index} { |
| 1023 |
run {string last \334a \334ad\334ad 0} |
| 1024 |
} -1 |
| 1025 |
test string-7.16.$noComp {string last, start index} { |
| 1026 |
run {string last \334a \334ad\334ad end-1} |
| 1027 |
} 3 |
| 1028 |
|
| 1029 |
test string-8.1.$noComp {string bytelength} { |
| 1030 |
list [catch {run {string bytelength}} msg] $msg |
| 1031 |
} {1 {wrong # args: should be "string bytelength string"}} |
| 1032 |
test string-8.2.$noComp {string bytelength} { |
| 1033 |
list [catch {run {string bytelength a b}} msg] $msg |
| 1034 |
} {1 {wrong # args: should be "string bytelength string"}} |
| 1035 |
test string-8.3.$noComp {string bytelength} { |
| 1036 |
run {string bytelength "\xC7"} |
| 1037 |
} 2 |
| 1038 |
test string-8.4.$noComp {string bytelength} { |
| 1039 |
run {string b ""} |
| 1040 |
} 0 |
| 1041 |
|
| 1042 |
test string-9.1.$noComp {string length} { |
| 1043 |
list [catch {run {string length}} msg] $msg |
| 1044 |
} {1 {wrong # args: should be "string length string"}} |
| 1045 |
test string-9.2.$noComp {string length} { |
| 1046 |
list [catch {run {string length a b}} msg] $msg |
| 1047 |
} {1 {wrong # args: should be "string length string"}} |
| 1048 |
test string-9.3.$noComp {string length} { |
| 1049 |
run {string length "a little string"} |
| 1050 |
} 15 |
| 1051 |
test string-9.4.$noComp {string length} { |
| 1052 |
run {string le ""} |
| 1053 |
} 0 |
| 1054 |
test string-9.5.$noComp {string length, unicode} { |
| 1055 |
run {string le "abcd\u7266"} |
| 1056 |
} 5 |
| 1057 |
test string-9.6.$noComp {string length, bytearray object} { |
| 1058 |
run {string length [binary format a5 foo]} |
| 1059 |
} 5 |
| 1060 |
test string-9.7.$noComp {string length, bytearray object} { |
| 1061 |
run {string length [binary format I* {0x50515253 0x52}]} |
| 1062 |
} 8 |
| 1063 |
|
| 1064 |
test string-10.1.$noComp {string map, not enough args} { |
| 1065 |
list [catch {run {string map}} msg] $msg |
| 1066 |
} {1 {wrong # args: should be "string map ?-nocase? charMap string"}} |
| 1067 |
test string-10.2.$noComp {string map, bad args} { |
| 1068 |
list [catch {run {string map {a b} abba oops}} msg] $msg |
| 1069 |
} {1 {bad option "a b": must be -nocase}} |
| 1070 |
test string-10.3.$noComp {string map, too many args} { |
| 1071 |
list [catch {run {string map -nocase {a b} str1 str2}} msg] $msg |
| 1072 |
} {1 {wrong # args: should be "string map ?-nocase? charMap string"}} |
| 1073 |
test string-10.4.$noComp {string map} { |
| 1074 |
run {string map {a b} abba} |
| 1075 |
} bbbb |
| 1076 |
test string-10.5.$noComp {string map} { |
| 1077 |
run {string map {a b} a} |
| 1078 |
} b |
| 1079 |
test string-10.6.$noComp {string map -nocase} { |
| 1080 |
run {string map -nocase {a b} Abba} |
| 1081 |
} bbbb |
| 1082 |
test string-10.7.$noComp {string map} { |
| 1083 |
run {string map {abc 321 ab * a A} aabcabaababcab} |
| 1084 |
} {A321*A*321*} |
| 1085 |
test string-10.8.$noComp {string map -nocase} { |
| 1086 |
run {string map -nocase {aBc 321 Ab * a A} aabcabaababcab} |
| 1087 |
} {A321*A*321*} |
| 1088 |
test string-10.9.$noComp {string map -nocase} { |
| 1089 |
run {string map -no {abc 321 Ab * a A} aAbCaBaAbAbcAb} |
| 1090 |
} {A321*A*321*} |
| 1091 |
test string-10.10.$noComp {string map} { |
| 1092 |
list [catch {run {string map {a b c} abba}} msg] $msg |
| 1093 |
} {1 {char map list unbalanced}} |
| 1094 |
test string-10.11.$noComp {string map, nulls} { |
| 1095 |
run {string map {\x00 NULL blah \x00nix} {qwerty}} |
| 1096 |
} qwerty |
| 1097 |
test string-10.12.$noComp {string map, unicode} { |
| 1098 |
run {string map [list \374 ue UE \334] "a\374ueUE\x00EU"} |
| 1099 |
} aueue\334\x00EU |
| 1100 |
test string-10.13.$noComp {string map, -nocase unicode} { |
| 1101 |
run {string map -nocase [list \374 ue UE \334] "a\374ueUE\x00EU"} |
| 1102 |
} aue\334\334\x00EU |
| 1103 |
test string-10.14.$noComp {string map, -nocase null arguments} { |
| 1104 |
run {string map -nocase {{} abc} foo} |
| 1105 |
} foo |
| 1106 |
test string-10.15.$noComp {string map, one pair case} { |
| 1107 |
run {string map -nocase {abc 32} aAbCaBaAbAbcAb} |
| 1108 |
} a32aBaAb32Ab |
| 1109 |
test string-10.16.$noComp {string map, one pair case} { |
| 1110 |
run {string map -nocase {ab 4321} aAbCaBaAbAbcAb} |
| 1111 |
} a4321C4321a43214321c4321 |
| 1112 |
test string-10.17.$noComp {string map, one pair case} { |
| 1113 |
run {string map {Ab 4321} aAbCaBaAbAbcAb} |
| 1114 |
} a4321CaBa43214321c4321 |
| 1115 |
test string-10.18.$noComp {string map, empty argument} { |
| 1116 |
run {string map -nocase {{} abc} foo} |
| 1117 |
} foo |
| 1118 |
test string-10.19.$noComp {string map, empty arguments} { |
| 1119 |
run {string map -nocase {{} abc f bar {} def} foo} |
| 1120 |
} baroo |
| 1121 |
test string-10.20.$noComp {string map, dictionaries don't alter map ordering} { |
| 1122 |
set map {aa X a Y} |
| 1123 |
list [run {string map [dict create aa X a Y] aaa}] [run {string map $map aaa}] [dict size $map] [run {string map $map aaa}] |
| 1124 |
} {XY XY 2 XY} |
| 1125 |
test string-10.20.1.$noComp {string map, dictionaries don't alter map ordering} { |
| 1126 |
set map {a X b Y a Z} |
| 1127 |
list [run {string map [dict create a X b Y a Z] aaa}] [run {string map $map aaa}] [dict size $map] [run {string map $map aaa}] |
| 1128 |
} {ZZZ XXX 2 XXX} |
| 1129 |
test string-10.21.$noComp {string map, ABR checks} { |
| 1130 |
run {string map {longstring foob} long} |
| 1131 |
} long |
| 1132 |
test string-10.22.$noComp {string map, ABR checks} { |
| 1133 |
run {string map {long foob} long} |
| 1134 |
} foob |
| 1135 |
test string-10.23.$noComp {string map, ABR checks} { |
| 1136 |
run {string map {lon foob} long} |
| 1137 |
} foobg |
| 1138 |
test string-10.24.$noComp {string map, ABR checks} { |
| 1139 |
run {string map {lon foob} longlo} |
| 1140 |
} foobglo |
| 1141 |
test string-10.25.$noComp {string map, ABR checks} { |
| 1142 |
run {string map {lon foob} longlon} |
| 1143 |
} foobgfoob |
| 1144 |
test string-10.26.$noComp {string map, ABR checks} { |
| 1145 |
run {string map {longstring foob longstring bar} long} |
| 1146 |
} long |
| 1147 |
test string-10.27.$noComp {string map, ABR checks} { |
| 1148 |
run {string map {long foob longstring bar} long} |
| 1149 |
} foob |
| 1150 |
test string-10.28.$noComp {string map, ABR checks} { |
| 1151 |
run {string map {lon foob longstring bar} long} |
| 1152 |
} foobg |
| 1153 |
test string-10.29.$noComp {string map, ABR checks} { |
| 1154 |
run {string map {lon foob longstring bar} longlo} |
| 1155 |
} foobglo |
| 1156 |
test string-10.30.$noComp {string map, ABR checks} { |
| 1157 |
run {string map {lon foob longstring bar} longlon} |
| 1158 |
} foobgfoob |
| 1159 |
test string-10.31.$noComp {string map, nasty sharing crash from [Bug 1018562]} { |
| 1160 |
set a {a b} |
| 1161 |
run {string map $a $a} |
| 1162 |
} {b b} |
| 1163 |
|
| 1164 |
test string-11.1.$noComp {string match, not enough args} { |
| 1165 |
list [catch {run {string match a}} msg] $msg |
| 1166 |
} {1 {wrong # args: should be "string match ?-nocase? pattern string"}} |
| 1167 |
test string-11.2.$noComp {string match, too many args} { |
| 1168 |
list [catch {run {string match a b c d}} msg] $msg |
| 1169 |
} {1 {wrong # args: should be "string match ?-nocase? pattern string"}} |
| 1170 |
test string-11.3.$noComp {string match} { |
| 1171 |
run {string match abc abc} |
| 1172 |
} 1 |
| 1173 |
test string-11.4.$noComp {string match} { |
| 1174 |
run {string mat abc abd} |
| 1175 |
} 0 |
| 1176 |
test string-11.5.$noComp {string match} { |
| 1177 |
run {string match ab*c abc} |
| 1178 |
} 1 |
| 1179 |
test string-11.6.$noComp {string match} { |
| 1180 |
run {string match ab**c abc} |
| 1181 |
} 1 |
| 1182 |
test string-11.7.$noComp {string match} { |
| 1183 |
run {string match ab* abcdef} |
| 1184 |
} 1 |
| 1185 |
test string-11.8.$noComp {string match} { |
| 1186 |
run {string match *c abc} |
| 1187 |
} 1 |
| 1188 |
test string-11.9.$noComp {string match} { |
| 1189 |
run {string match *3*6*9 0123456789} |
| 1190 |
} 1 |
| 1191 |
test string-11.9.1.$noComp {string match} { |
| 1192 |
run {string match *3*6*89 0123456789} |
| 1193 |
} 1 |
| 1194 |
test string-11.9.2.$noComp {string match} { |
| 1195 |
run {string match *3*456*89 0123456789} |
| 1196 |
} 1 |
| 1197 |
test string-11.9.3.$noComp {string match} { |
| 1198 |
run {string match *3*6* 0123456789} |
| 1199 |
} 1 |
| 1200 |
test string-11.9.4.$noComp {string match} { |
| 1201 |
run {string match *3*56* 0123456789} |
| 1202 |
} 1 |
| 1203 |
test string-11.9.5.$noComp {string match} { |
| 1204 |
run {string match *3*456*** 0123456789} |
| 1205 |
} 1 |
| 1206 |
test string-11.9.6.$noComp {string match} { |
| 1207 |
run {string match **3*456** 0123456789} |
| 1208 |
} 1 |
| 1209 |
test string-11.9.7.$noComp {string match} { |
| 1210 |
run {string match *3***456* 0123456789} |
| 1211 |
} 1 |
| 1212 |
test string-11.9.8.$noComp {string match} { |
| 1213 |
run {string match *3***\[456]* 0123456789} |
| 1214 |
} 1 |
| 1215 |
test string-11.9.9.$noComp {string match} { |
| 1216 |
run {string match *3***\[4-6]* 0123456789} |
| 1217 |
} 1 |
| 1218 |
test string-11.9.10.$noComp {string match} { |
| 1219 |
run {string match *3***\[4-6] 0123456789} |
| 1220 |
} 0 |
| 1221 |
test string-11.9.11.$noComp {string match} { |
| 1222 |
run {string match *3***\[4-6] 0123456} |
| 1223 |
} 1 |
| 1224 |
test string-11.10.$noComp {string match} { |
| 1225 |
run {string match *3*6*9 01234567890} |
| 1226 |
} 0 |
| 1227 |
test string-11.10.1.$noComp {string match} { |
| 1228 |
run {string match *3*6*89 01234567890} |
| 1229 |
} 0 |
| 1230 |
test string-11.10.2.$noComp {string match} { |
| 1231 |
run {string match *3*456*89 01234567890} |
| 1232 |
} 0 |
| 1233 |
test string-11.10.3.$noComp {string match} { |
| 1234 |
run {string match **3*456*89 01234567890} |
| 1235 |
} 0 |
| 1236 |
test string-11.10.4.$noComp {string match} { |
| 1237 |
run {string match *3*456***89 01234567890} |
| 1238 |
} 0 |
| 1239 |
test string-11.11.$noComp {string match} { |
| 1240 |
run {string match a?c abc} |
| 1241 |
} 1 |
| 1242 |
test string-11.12.$noComp {string match} { |
| 1243 |
run {string match a??c abc} |
| 1244 |
} 0 |
| 1245 |
test string-11.13.$noComp {string match} { |
| 1246 |
run {string match ?1??4???8? 0123456789} |
| 1247 |
} 1 |
| 1248 |
test string-11.14.$noComp {string match} { |
| 1249 |
run {string match {[abc]bc} abc} |
| 1250 |
} 1 |
| 1251 |
test string-11.15.$noComp {string match} { |
| 1252 |
run {string match {a[abc]c} abc} |
| 1253 |
} 1 |
| 1254 |
test string-11.16.$noComp {string match} { |
| 1255 |
run {string match {a[xyz]c} abc} |
| 1256 |
} 0 |
| 1257 |
test string-11.17.$noComp {string match} { |
| 1258 |
run {string match {12[2-7]45} 12345} |
| 1259 |
} 1 |
| 1260 |
test string-11.18.$noComp {string match} { |
| 1261 |
run {string match {12[ab2-4cd]45} 12345} |
| 1262 |
} 1 |
| 1263 |
test string-11.19.$noComp {string match} { |
| 1264 |
run {string match {12[ab2-4cd]45} 12b45} |
| 1265 |
} 1 |
| 1266 |
test string-11.20.$noComp {string match} { |
| 1267 |
run {string match {12[ab2-4cd]45} 12d45} |
| 1268 |
} 1 |
| 1269 |
test string-11.21.$noComp {string match} { |
| 1270 |
run {string match {12[ab2-4cd]45} 12145} |
| 1271 |
} 0 |
| 1272 |
test string-11.22.$noComp {string match} { |
| 1273 |
run {string match {12[ab2-4cd]45} 12545} |
| 1274 |
} 0 |
| 1275 |
test string-11.23.$noComp {string match} { |
| 1276 |
run {string match {a\*b} a*b} |
| 1277 |
} 1 |
| 1278 |
test string-11.24.$noComp {string match} { |
| 1279 |
run {string match {a\*b} ab} |
| 1280 |
} 0 |
| 1281 |
test string-11.25.$noComp {string match} { |
| 1282 |
run {string match {a\*\?\[\]\\\x} "a*?\[\]\\x"} |
| 1283 |
} 1 |
| 1284 |
test string-11.26.$noComp {string match} { |
| 1285 |
run {string match ** ""} |
| 1286 |
} 1 |
| 1287 |
test string-11.27.$noComp {string match} { |
| 1288 |
run {string match *. ""} |
| 1289 |
} 0 |
| 1290 |
test string-11.28.$noComp {string match} { |
| 1291 |
run {string match "" ""} |
| 1292 |
} 1 |
| 1293 |
test string-11.29.$noComp {string match} { |
| 1294 |
run {string match \[a a} |
| 1295 |
} 1 |
| 1296 |
test string-11.30.$noComp {string match, bad args} { |
| 1297 |
list [catch {run {string match - b c}} msg] $msg |
| 1298 |
} {1 {bad option "-": must be -nocase}} |
| 1299 |
test string-11.31.$noComp {string match case} { |
| 1300 |
run {string match a A} |
| 1301 |
} 0 |
| 1302 |
test string-11.32.$noComp {string match nocase} { |
| 1303 |
run {string match -n a A} |
| 1304 |
} 1 |
| 1305 |
test string-11.33.$noComp {string match nocase} { |
| 1306 |
run {string match -nocase a\334 A\374} |
| 1307 |
} 1 |
| 1308 |
test string-11.34.$noComp {string match nocase} { |
| 1309 |
run {string match -nocase a*f ABCDEf} |
| 1310 |
} 1 |
| 1311 |
test string-11.35.$noComp {string match case, false hope} { |
| 1312 |
# This is true because '_' lies between the A-Z and a-z ranges |
| 1313 |
run {string match {[A-z]} _} |
| 1314 |
} 1 |
| 1315 |
test string-11.36.$noComp {string match nocase range} { |
| 1316 |
# This is false because although '_' lies between the A-Z and a-z ranges, |
| 1317 |
# we lower case the end points before checking the ranges. |
| 1318 |
run {string match -nocase {[A-z]} _} |
| 1319 |
} 0 |
| 1320 |
test string-11.37.$noComp {string match nocase} { |
| 1321 |
run {string match -nocase {[A-fh-Z]} g} |
| 1322 |
} 0 |
| 1323 |
test string-11.38.$noComp {string match case, reverse range} { |
| 1324 |
run {string match {[A-fh-Z]} g} |
| 1325 |
} 1 |
| 1326 |
test string-11.39.$noComp {string match, *\ case} { |
| 1327 |
run {string match {*\abc} abc} |
| 1328 |
} 1 |
| 1329 |
test string-11.39.1.$noComp {string match, *\ case} { |
| 1330 |
run {string match {*ab\c} abc} |
| 1331 |
} 1 |
| 1332 |
test string-11.39.2.$noComp {string match, *\ case} { |
| 1333 |
run {string match {*ab\*} ab*} |
| 1334 |
} 1 |
| 1335 |
test string-11.39.3.$noComp {string match, *\ case} { |
| 1336 |
run {string match {*ab\*} abc} |
| 1337 |
} 0 |
| 1338 |
test string-11.39.4.$noComp {string match, *\ case} { |
| 1339 |
run {string match {*ab\\*} {ab\c}} |
| 1340 |
} 1 |
| 1341 |
test string-11.39.5.$noComp {string match, *\ case} { |
| 1342 |
run {string match {*ab\\*} {ab\*}} |
| 1343 |
} 1 |
| 1344 |
test string-11.40.$noComp {string match, *special case} { |
| 1345 |
run {string match {*[ab]} abc} |
| 1346 |
} 0 |
| 1347 |
test string-11.41.$noComp {string match, *special case} { |
| 1348 |
run {string match {*[ab]*} abc} |
| 1349 |
} 1 |
| 1350 |
test string-11.42.$noComp {string match, *special case} { |
| 1351 |
run {string match "*\\" "\\"} |
| 1352 |
} 0 |
| 1353 |
test string-11.43.$noComp {string match, *special case} { |
| 1354 |
run {string match "*\\\\" "\\"} |
| 1355 |
} 1 |
| 1356 |
test string-11.44.$noComp {string match, *special case} { |
| 1357 |
run {string match "*???" "12345"} |
| 1358 |
} 1 |
| 1359 |
test string-11.45.$noComp {string match, *special case} { |
| 1360 |
run {string match "*???" "12"} |
| 1361 |
} 0 |
| 1362 |
test string-11.46.$noComp {string match, *special case} { |
| 1363 |
run {string match "*\\*" "abc*"} |
| 1364 |
} 1 |
| 1365 |
test string-11.47.$noComp {string match, *special case} { |
| 1366 |
run {string match "*\\*" "*"} |
| 1367 |
} 1 |
| 1368 |
test string-11.48.$noComp {string match, *special case} { |
| 1369 |
run {string match "*\\*" "*abc"} |
| 1370 |
} 0 |
| 1371 |
test string-11.49.$noComp {string match, *special case} { |
| 1372 |
run {string match "?\\*" "a*"} |
| 1373 |
} 1 |
| 1374 |
test string-11.50.$noComp {string match, *special case} { |
| 1375 |
run {string match "\\" "\\"} |
| 1376 |
} 0 |
| 1377 |
test string-11.51.$noComp {string match; *, -nocase and UTF-8} { |
| 1378 |
run {string match -nocase [binary format I 717316707] \ |
| 1379 |
[binary format I 2028036707]} |
| 1380 |
} 1 |
| 1381 |
test string-11.52.$noComp {string match, null char in string} { |
| 1382 |
set out "" |
| 1383 |
set ptn "*abc*" |
| 1384 |
foreach elem [list "\x00@abc" "@abc" "\x00@abc\x00" "blahabcblah"] { |
| 1385 |
lappend out [run {string match $ptn $elem}] |
| 1386 |
} |
| 1387 |
set out |
| 1388 |
} {1 1 1 1} |
| 1389 |
test string-11.53.$noComp {string match, null char in pattern} { |
| 1390 |
set out "" |
| 1391 |
foreach {ptn elem} [list \ |
| 1392 |
"*\x00abc\x00" "\x00abc\x00" \ |
| 1393 |
"*\x00abc\x00" "\x00abc\x00ef" \ |
| 1394 |
"*\x00abc\x00*" "\x00abc\x00ef" \ |
| 1395 |
"*\x00abc\x00" "@\x00abc\x00ef" \ |
| 1396 |
"*\x00abc\x00*" "@\x00abc\x00ef" \ |
| 1397 |
] { |
| 1398 |
lappend out [run {string match $ptn $elem}] |
| 1399 |
} |
| 1400 |
set out |
| 1401 |
} {1 0 1 0 1} |
| 1402 |
test string-11.54.$noComp {string match, failure} { |
| 1403 |
set longString "" |
| 1404 |
for {set i 0} {$i < 10} {incr i} { |
| 1405 |
append longString "abcdefghijklmnopqrstuvwxy\x00z01234567890123" |
| 1406 |
} |
| 1407 |
run {string first $longString 123} |
| 1408 |
list [run {string match *cba* $longString}] \ |
| 1409 |
[run {string match *a*l*\x00* $longString}] \ |
| 1410 |
[run {string match *a*l*\x00*123 $longString}] \ |
| 1411 |
[run {string match *a*l*\x00*123* $longString}] \ |
| 1412 |
[run {string match *a*l*\x00*cba* $longString}] \ |
| 1413 |
[run {string match *===* $longString}] |
| 1414 |
} {0 1 1 1 0 0} |
| 1415 |
test string-11.55.$noComp {string match, invalid binary optimization} { |
| 1416 |
[format string] match \u0141 [binary format c 65] |
| 1417 |
} 0 |
| 1418 |
|
| 1419 |
test string-12.1.$noComp {string range} { |
| 1420 |
list [catch {run {string range}} msg] $msg |
| 1421 |
} {1 {wrong # args: should be "string range string first last"}} |
| 1422 |
test string-12.2.$noComp {string range} { |
| 1423 |
list [catch {run {string range a 1}} msg] $msg |
| 1424 |
} {1 {wrong # args: should be "string range string first last"}} |
| 1425 |
test string-12.3.$noComp {string range} { |
| 1426 |
list [catch {run {string range a 1 2 3}} msg] $msg |
| 1427 |
} {1 {wrong # args: should be "string range string first last"}} |
| 1428 |
test string-12.4.$noComp {string range} { |
| 1429 |
run {string range abcdefghijklmnop 2 14} |
| 1430 |
} {cdefghijklmno} |
| 1431 |
test string-12.5.$noComp {string range, last > length} { |
| 1432 |
run {string range abcdefghijklmnop 7 1000} |
| 1433 |
} {hijklmnop} |
| 1434 |
test string-12.6.$noComp {string range} { |
| 1435 |
run {string range abcdefghijklmnop 10 end} |
| 1436 |
} {klmnop} |
| 1437 |
test string-12.7.$noComp {string range, last < first} { |
| 1438 |
run {string range abcdefghijklmnop 10 9} |
| 1439 |
} {} |
| 1440 |
test string-12.8.$noComp {string range, first < 0} { |
| 1441 |
run {string range abcdefghijklmnop -3 2} |
| 1442 |
} {abc} |
| 1443 |
test string-12.9.$noComp {string range} { |
| 1444 |
run {string range abcdefghijklmnop -3 -2} |
| 1445 |
} {} |
| 1446 |
test string-12.10.$noComp {string range} { |
| 1447 |
run {string range abcdefghijklmnop 1000 1010} |
| 1448 |
} {} |
| 1449 |
test string-12.11.$noComp {string range} { |
| 1450 |
run {string range abcdefghijklmnop -100 end} |
| 1451 |
} {abcdefghijklmnop} |
| 1452 |
test string-12.12.$noComp {string range} { |
| 1453 |
list [catch {run {string range abc abc 1}} msg] $msg |
| 1454 |
} {1 {bad index "abc": must be integer?[+-]integer? or end?[+-]integer?}} |
| 1455 |
test string-12.13.$noComp {string range} { |
| 1456 |
list [catch {run {string range abc 1 eof}} msg] $msg |
| 1457 |
} {1 {bad index "eof": must be integer?[+-]integer? or end?[+-]integer?}} |
| 1458 |
test string-12.14.$noComp {string range} { |
| 1459 |
run {string range abcdefghijklmnop end-1 end} |
| 1460 |
} {op} |
| 1461 |
test string-12.15.$noComp {string range} { |
| 1462 |
run {string range abcdefghijklmnop end 1000} |
| 1463 |
} {p} |
| 1464 |
test string-12.16.$noComp {string range} { |
| 1465 |
run {string range abcdefghijklmnop end end-1} |
| 1466 |
} {} |
| 1467 |
test string-12.17.$noComp {string range, unicode} { |
| 1468 |
run {string range ab\u7266cdefghijklmnop 5 5} |
| 1469 |
} e |
| 1470 |
test string-12.18.$noComp {string range, unicode} { |
| 1471 |
run {string range ab\u7266cdefghijklmnop 2 3} |
| 1472 |
} \u7266c |
| 1473 |
test string-12.19.$noComp {string range, bytearray object} { |
| 1474 |
set b [binary format I* {0x50515253 0x52}] |
| 1475 |
set r1 [run {string range $b 1 end-1}] |
| 1476 |
set r2 [run {string range $b 1 6}] |
| 1477 |
run {string equal $r1 $r2} |
| 1478 |
} 1 |
| 1479 |
test string-12.20.$noComp {string range, out of bounds indices} { |
| 1480 |
run {string range \xFF 0 1} |
| 1481 |
} \xFF |
| 1482 |
# Bug 1410553 |
| 1483 |
test string-12.21.$noComp {string range, regenerates correct reps, bug 1410553} { |
| 1484 |
set bytes "\x00 \x03 \x41" |
| 1485 |
set rxBuffer {} |
| 1486 |
foreach ch $bytes { |
| 1487 |
append rxBuffer $ch |
| 1488 |
if {$ch eq "\x03"} { |
| 1489 |
run {string length $rxBuffer} |
| 1490 |
} |
| 1491 |
} |
| 1492 |
set rxCRC [run {string range $rxBuffer end-1 end}] |
| 1493 |
binary scan [join $bytes {}] "H*" input_hex |
| 1494 |
binary scan $rxBuffer "H*" rxBuffer_hex |
| 1495 |
binary scan $rxCRC "H*" rxCRC_hex |
| 1496 |
list $input_hex $rxBuffer_hex $rxCRC_hex |
| 1497 |
} {000341 000341 0341} |
| 1498 |
test string-12.22.$noComp {string range, shimmering binary/index} { |
| 1499 |
set s 0000000001 |
| 1500 |
binary scan $s a* x |
| 1501 |
run {string range $s $s end} |
| 1502 |
} 000000001 |
| 1503 |
test string-12.23.$noComp {string range, surrogates, bug [11ae2be95dac9417]} utf16 { |
| 1504 |
run {list [string range a\U100000b 1 1] [string range a\U100000b 2 2] [string range a\U100000b 3 3]} |
| 1505 |
} [list \U100000 {} b] |
| 1506 |
|
| 1507 |
test string-13.1.$noComp {string repeat} { |
| 1508 |
list [catch {run {string repeat}} msg] $msg |
| 1509 |
} {1 {wrong # args: should be "string repeat string count"}} |
| 1510 |
test string-13.2.$noComp {string repeat} { |
| 1511 |
list [catch {run {string repeat abc 10 oops}} msg] $msg |
| 1512 |
} {1 {wrong # args: should be "string repeat string count"}} |
| 1513 |
test string-13.3.$noComp {string repeat} { |
| 1514 |
run {string repeat {} 100} |
| 1515 |
} {} |
| 1516 |
test string-13.4.$noComp {string repeat} { |
| 1517 |
run {string repeat { } 5} |
| 1518 |
} { } |
| 1519 |
test string-13.5.$noComp {string repeat} { |
| 1520 |
run {string repeat abc 3} |
| 1521 |
} {abcabcabc} |
| 1522 |
test string-13.6.$noComp {string repeat} { |
| 1523 |
run {string repeat abc -1} |
| 1524 |
} {} |
| 1525 |
test string-13.7.$noComp {string repeat} { |
| 1526 |
list [catch {run {string repeat abc end}} msg] $msg |
| 1527 |
} {1 {expected integer but got "end"}} |
| 1528 |
test string-13.8.$noComp {string repeat} { |
| 1529 |
run {string repeat {} -1000} |
| 1530 |
} {} |
| 1531 |
test string-13.9.$noComp {string repeat} { |
| 1532 |
run {string repeat {} 0} |
| 1533 |
} {} |
| 1534 |
test string-13.10.$noComp {string repeat} { |
| 1535 |
run {string repeat def 0} |
| 1536 |
} {} |
| 1537 |
test string-13.11.$noComp {string repeat} { |
| 1538 |
run {string repeat def 1} |
| 1539 |
} def |
| 1540 |
test string-13.12.$noComp {string repeat} { |
| 1541 |
run {string repeat ab\u7266cd 3} |
| 1542 |
} ab\u7266cdab\u7266cdab\u7266cd |
| 1543 |
test string-13.13.$noComp {string repeat} { |
| 1544 |
run {string repeat \x00 3} |
| 1545 |
} \x00\x00\x00 |
| 1546 |
test string-13.14.$noComp {string repeat} { |
| 1547 |
# The string range will ensure us that string repeat gets a unicode string |
| 1548 |
run {string repeat [run {string range ab\u7266cd 2 3}] 3} |
| 1549 |
} \u7266c\u7266c\u7266c |
| 1550 |
|
| 1551 |
test string-14.1.$noComp {string replace} { |
| 1552 |
list [catch {run {string replace}} msg] $msg |
| 1553 |
} {1 {wrong # args: should be "string replace string first last ?string?"}} |
| 1554 |
test string-14.2.$noComp {string replace} { |
| 1555 |
list [catch {run {string replace a 1}} msg] $msg |
| 1556 |
} {1 {wrong # args: should be "string replace string first last ?string?"}} |
| 1557 |
test string-14.3.$noComp {string replace} { |
| 1558 |
list [catch {run {string replace a 1 2 3 4}} msg] $msg |
| 1559 |
} {1 {wrong # args: should be "string replace string first last ?string?"}} |
| 1560 |
test string-14.4.$noComp {string replace} { |
| 1561 |
} {} |
| 1562 |
test string-14.5.$noComp {string replace} { |
| 1563 |
run {string replace abcdefghijklmnop 2 14} |
| 1564 |
} {abp} |
| 1565 |
test string-14.6.$noComp {string replace} -body { |
| 1566 |
run {string replace abcdefghijklmnop 7 1000} |
| 1567 |
} -result abcdefg |
| 1568 |
test string-14.7.$noComp {string replace} { |
| 1569 |
run {string replace abcdefghijklmnop 10 end} |
| 1570 |
} abcdefghij |
| 1571 |
test string-14.8.$noComp {string replace} { |
| 1572 |
run {string replace abcdefghijklmnop 10 9} |
| 1573 |
} abcdefghijklmnop |
| 1574 |
test string-14.9.$noComp {string replace} { |
| 1575 |
run {string replace abcdefghijklmnop -3 2} |
| 1576 |
} defghijklmnop |
| 1577 |
test string-14.10.$noComp {string replace} { |
| 1578 |
run {string replace abcdefghijklmnop -3 -2} |
| 1579 |
} abcdefghijklmnop |
| 1580 |
test string-14.11.$noComp {string replace} -body { |
| 1581 |
run {string replace abcdefghijklmnop 1000 1010} |
| 1582 |
} -result abcdefghijklmnop |
| 1583 |
test string-14.12.$noComp {string replace} { |
| 1584 |
run {string replace abcdefghijklmnop -100 end} |
| 1585 |
} {} |
| 1586 |
test string-14.13.$noComp {string replace} { |
| 1587 |
list [catch {run {string replace abc abc 1}} msg] $msg |
| 1588 |
} {1 {bad index "abc": must be integer?[+-]integer? or end?[+-]integer?}} |
| 1589 |
test string-14.14.$noComp {string replace} { |
| 1590 |
list [catch {run {string replace abc 1 eof}} msg] $msg |
| 1591 |
} {1 {bad index "eof": must be integer?[+-]integer? or end?[+-]integer?}} |
| 1592 |
test string-14.15.$noComp {string replace} { |
| 1593 |
run {string replace abcdefghijklmnop end-10 end-2 NEW} |
| 1594 |
} {abcdeNEWop} |
| 1595 |
test string-14.16.$noComp {string replace} { |
| 1596 |
run {string replace abcdefghijklmnop 0 end foo} |
| 1597 |
} {foo} |
| 1598 |
test string-14.17.$noComp {string replace} { |
| 1599 |
run {string replace abcdefghijklmnop end end-1} |
| 1600 |
} {abcdefghijklmnop} |
| 1601 |
test string-14.18.$noComp {string replace} { |
| 1602 |
run {string replace abcdefghijklmnop 10 9 XXX} |
| 1603 |
} {abcdefghijklmnop} |
| 1604 |
test string-14.19.$noComp {string replace} { |
| 1605 |
run {string replace {} -1 0 A} |
| 1606 |
} A |
| 1607 |
|
| 1608 |
test string-15.1.$noComp {string tolower not enough args} { |
| 1609 |
list [catch {run {string tolower}} msg] $msg |
| 1610 |
} {1 {wrong # args: should be "string tolower string ?first? ?last?"}} |
| 1611 |
test string-15.2.$noComp {string tolower bad args} { |
| 1612 |
list [catch {run {string tolower a b}} msg] $msg |
| 1613 |
} {1 {bad index "b": must be integer?[+-]integer? or end?[+-]integer?}} |
| 1614 |
test string-15.3.$noComp {string tolower too many args} { |
| 1615 |
list [catch {run {string tolower ABC 1 end oops}} msg] $msg |
| 1616 |
} {1 {wrong # args: should be "string tolower string ?first? ?last?"}} |
| 1617 |
test string-15.4.$noComp {string tolower} { |
| 1618 |
run {string tolower ABCDeF} |
| 1619 |
} {abcdef} |
| 1620 |
test string-15.5.$noComp {string tolower} { |
| 1621 |
run {string tolower "ABC XyZ"} |
| 1622 |
} {abc xyz} |
| 1623 |
test string-15.6.$noComp {string tolower} { |
| 1624 |
run {string tolower {123#$&*()}} |
| 1625 |
} {123#$&*()} |
| 1626 |
test string-15.7.$noComp {string tolower} { |
| 1627 |
run {string tolower ABC 1} |
| 1628 |
} AbC |
| 1629 |
test string-15.8.$noComp {string tolower} { |
| 1630 |
run {string tolower ABC 1 end} |
| 1631 |
} Abc |
| 1632 |
test string-15.9.$noComp {string tolower} { |
| 1633 |
run {string tolower ABC 0 end-1} |
| 1634 |
} abC |
| 1635 |
test string-15.10.$noComp {string tolower, unicode} { |
| 1636 |
run {string tolower ABCabc\xC7\xE7} |
| 1637 |
} "abcabc\xE7\xE7" |
| 1638 |
test string-15.11.$noComp {string tolower, compiled} { |
| 1639 |
lindex [run {string tolower [list A B [list C]]}] 1 |
| 1640 |
} b |
| 1641 |
|
| 1642 |
test string-16.1.$noComp {string toupper} { |
| 1643 |
list [catch {run {string toupper}} msg] $msg |
| 1644 |
} {1 {wrong # args: should be "string toupper string ?first? ?last?"}} |
| 1645 |
test string-16.2.$noComp {string toupper} { |
| 1646 |
list [catch {run {string toupper a b}} msg] $msg |
| 1647 |
} {1 {bad index "b": must be integer?[+-]integer? or end?[+-]integer?}} |
| 1648 |
test string-16.3.$noComp {string toupper} { |
| 1649 |
list [catch {run {string toupper a 1 end oops}} msg] $msg |
| 1650 |
} {1 {wrong # args: should be "string toupper string ?first? ?last?"}} |
| 1651 |
test string-16.4.$noComp {string toupper} { |
| 1652 |
run {string toupper abCDEf} |
| 1653 |
} {ABCDEF} |
| 1654 |
test string-16.5.$noComp {string toupper} { |
| 1655 |
run {string toupper "abc xYz"} |
| 1656 |
} {ABC XYZ} |
| 1657 |
test string-16.6.$noComp {string toupper} { |
| 1658 |
run {string toupper {123#$&*()}} |
| 1659 |
} {123#$&*()} |
| 1660 |
test string-16.7.$noComp {string toupper} { |
| 1661 |
run {string toupper abc 1} |
| 1662 |
} aBc |
| 1663 |
test string-16.8.$noComp {string toupper} { |
| 1664 |
run {string toupper abc 1 end} |
| 1665 |
} aBC |
| 1666 |
test string-16.9.$noComp {string toupper} { |
| 1667 |
run {string toupper abc 0 end-1} |
| 1668 |
} ABc |
| 1669 |
test string-16.10.$noComp {string toupper, unicode} { |
| 1670 |
run {string toupper ABCabc\xC7\xE7} |
| 1671 |
} "ABCABC\xC7\xC7" |
| 1672 |
test string-16.11.$noComp {string toupper, compiled} { |
| 1673 |
lindex [run {string toupper [list a b [list c]]}] 1 |
| 1674 |
} B |
| 1675 |
|
| 1676 |
test string-17.1.$noComp {string totitle} { |
| 1677 |
list [catch {run {string totitle}} msg] $msg |
| 1678 |
} {1 {wrong # args: should be "string totitle string ?first? ?last?"}} |
| 1679 |
test string-17.2.$noComp {string totitle} { |
| 1680 |
list [catch {run {string totitle a b}} msg] $msg |
| 1681 |
} {1 {bad index "b": must be integer?[+-]integer? or end?[+-]integer?}} |
| 1682 |
test string-17.3.$noComp {string totitle} { |
| 1683 |
run {string totitle abCDEf} |
| 1684 |
} {Abcdef} |
| 1685 |
test string-17.4.$noComp {string totitle} { |
| 1686 |
run {string totitle "abc xYz"} |
| 1687 |
} {Abc xyz} |
| 1688 |
test string-17.5.$noComp {string totitle} { |
| 1689 |
run {string totitle {123#$&*()}} |
| 1690 |
} {123#$&*()} |
| 1691 |
test string-17.6.$noComp {string totitle, unicode} { |
| 1692 |
run {string totitle ABCabc\xC7\xE7} |
| 1693 |
} "Abcabc\xE7\xE7" |
| 1694 |
test string-17.7.$noComp {string totitle, unicode} { |
| 1695 |
run {string totitle \u01F3BCabc\xC7\xE7} |
| 1696 |
} "\u01F2bcabc\xE7\xE7" |
| 1697 |
test string-17.8.$noComp {string totitle, compiled} { |
| 1698 |
lindex [run {string totitle [list aa bb [list cc]]}] 0 |
| 1699 |
} Aa |
| 1700 |
|
| 1701 |
test string-18.1.$noComp {string trim} { |
| 1702 |
list [catch {run {string trim}} msg] $msg |
| 1703 |
} {1 {wrong # args: should be "string trim string ?chars?"}} |
| 1704 |
test string-18.2.$noComp {string trim} { |
| 1705 |
list [catch {run {string trim a b c}} msg] $msg |
| 1706 |
} {1 {wrong # args: should be "string trim string ?chars?"}} |
| 1707 |
test string-18.3.$noComp {string trim} { |
| 1708 |
run {string trim " XYZ "} |
| 1709 |
} {XYZ} |
| 1710 |
test string-18.4.$noComp {string trim} { |
| 1711 |
run {string trim "\t\nXYZ\t\n\r\n"} |
| 1712 |
} {XYZ} |
| 1713 |
test string-18.5.$noComp {string trim} { |
| 1714 |
run {string trim " A XYZ A "} |
| 1715 |
} {A XYZ A} |
| 1716 |
test string-18.6.$noComp {string trim} { |
| 1717 |
run {string trim "XXYYZZABC XXYYZZ" ZYX} |
| 1718 |
} {ABC } |
| 1719 |
test string-18.7.$noComp {string trim} { |
| 1720 |
run {string trim " \t\r "} |
| 1721 |
} {} |
| 1722 |
test string-18.8.$noComp {string trim} { |
| 1723 |
run {string trim {abcdefg} {}} |
| 1724 |
} {abcdefg} |
| 1725 |
test string-18.9.$noComp {string trim} { |
| 1726 |
run {string trim {}} |
| 1727 |
} {} |
| 1728 |
test string-18.10.$noComp {string trim} { |
| 1729 |
run {string trim ABC DEF} |
| 1730 |
} {ABC} |
| 1731 |
test string-18.11.$noComp {string trim, unicode} { |
| 1732 |
run {string trim "\xE7\xE8 AB\xE7C \xE8\xE7" \xE7\xE8} |
| 1733 |
} " AB\xE7C " |
| 1734 |
test string-18.12.$noComp {string trim, unicode default} { |
| 1735 |
run {string trim \uFEFF\x00\x85\xA0\u1680\u180EABC\u1361\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200A\u200B\u2028\u2029\u202F\u205F\u3000} |
| 1736 |
} ABC\u1361 |
| 1737 |
|
| 1738 |
test string-19.1.$noComp {string trimleft} { |
| 1739 |
list [catch {run {string trimleft}} msg] $msg |
| 1740 |
} {1 {wrong # args: should be "string trimleft string ?chars?"}} |
| 1741 |
test string-19.2.$noComp {string trimleft} { |
| 1742 |
run {string trimleft " XYZ "} |
| 1743 |
} {XYZ } |
| 1744 |
test string-19.3.$noComp {string trimleft, unicode default} { |
| 1745 |
run {string trimleft \uFEFF\x85\xA0\x00\u1680\u180E\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200A\u200B\u2028\u2029\u202F\u205F\u3000\u1361ABC} |
| 1746 |
} \u1361ABC |
| 1747 |
|
| 1748 |
test string-20.1.$noComp {string trimright errors} { |
| 1749 |
list [catch {run {string trimright}} msg] $msg |
| 1750 |
} {1 {wrong # args: should be "string trimright string ?chars?"}} |
| 1751 |
test string-20.2.$noComp {string trimright errors} -body { |
| 1752 |
list [catch {run {string trimg a}} msg] $msg |
| 1753 |
} -result {1 {unknown or ambiguous subcommand "trimg": must be bytelength, cat, compare, equal, first, index, is, last, length, map, match, range, repeat, replace, reverse, tolower, totitle, toupper, trim, trimleft, trimright, wordend, or wordstart}} |
| 1754 |
test string-20.3.$noComp {string trimright} { |
| 1755 |
run {string trimright " XYZ "} |
| 1756 |
} { XYZ} |
| 1757 |
test string-20.4.$noComp {string trimright} { |
| 1758 |
run {string trimright " "} |
| 1759 |
} {} |
| 1760 |
test string-20.5.$noComp {string trimright} { |
| 1761 |
run {string trimright ""} |
| 1762 |
} {} |
| 1763 |
test string-20.6.$noComp {string trimright, unicode default} { |
| 1764 |
run {string trimright ABC\u1361\x85\x00\xA0\u1680\u180E\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200A\u200B\u2028\u2029\u202F\u205F\u3000} |
| 1765 |
} ABC\u1361 |
| 1766 |
test string-20.7.$noComp {string trim on not valid utf-8 sequence (consider NTS as continuation char), bug [c61818e4c9]} testbytestring { |
| 1767 |
set result {} |
| 1768 |
set a [testbytestring \xC0\x80\xA0] |
| 1769 |
set b foo$a |
| 1770 |
set m [list \x00 U \xA0 V [testbytestring \xA0] W] |
| 1771 |
lappend result [string map $m $b] |
| 1772 |
lappend result [string map $m [run {string trimright $b x}]] |
| 1773 |
lappend result [string map $m [run {string trimright $b \x00}]] |
| 1774 |
lappend result [string map $m [run {string trimleft $b fox}]] |
| 1775 |
lappend result [string map $m [run {string trimleft $b fo\x00}]] |
| 1776 |
lappend result [string map $m [run {string trim $b fox}]] |
| 1777 |
lappend result [string map $m [run {string trim $b fo\x00}]] |
| 1778 |
} [list {*}[lrepeat 3 fooUV] {*}[lrepeat 2 UV V]] |
| 1779 |
test string-20.8.$noComp {[c61818e4c9] [string trimright] fails when UtfPrev is ok} testbytestring { |
| 1780 |
set result {} |
| 1781 |
set a [testbytestring \xE8\xA0] |
| 1782 |
set b foo$a |
| 1783 |
set m [list \xE8 U \xA0 V [testbytestring \xE8] W [testbytestring \xA0] X]] |
| 1784 |
lappend result [string map $m $b] |
| 1785 |
lappend result [string map $m [run {string trimright $b x}]] |
| 1786 |
lappend result [string map $m [run {string trimright $b \xE8}]] |
| 1787 |
lappend result [string map $m [run {string trimright $b [testbytestring \xE8]}]] |
| 1788 |
lappend result [string map $m [run {string trimright $b \xA0}]] |
| 1789 |
lappend result [string map $m [run {string trimright $b [testbytestring \xA0]}]] |
| 1790 |
lappend result [string map $m [run {string trimright $b \xE8\xA0}]] |
| 1791 |
lappend result [string map $m [run {string trimright $b [testbytestring \xE8\xA0]}]] |
| 1792 |
lappend result [string map $m [run {string trimright $b \x00}]] |
| 1793 |
} [list {*}[lrepeat 4 fooUV] {*}[lrepeat 2 fooU] {*}[lrepeat 2 foo] fooUV] |
| 1794 |
|
| 1795 |
test string-21.1.$noComp {string wordend} -body { |
| 1796 |
list [catch {run {string wordend a}} msg] $msg |
| 1797 |
} -result {1 {wrong # args: should be "string wordend string index"}} |
| 1798 |
test string-21.2.$noComp {string wordend} -body { |
| 1799 |
list [catch {run {string wordend a b c}} msg] $msg |
| 1800 |
} -result {1 {wrong # args: should be "string wordend string index"}} |
| 1801 |
test string-21.3.$noComp {string wordend} -body { |
| 1802 |
list [catch {run {string wordend a gorp}} msg] $msg |
| 1803 |
} -result {1 {bad index "gorp": must be integer?[+-]integer? or end?[+-]integer?}} |
| 1804 |
test string-21.4.$noComp {string wordend} -body { |
| 1805 |
run {string wordend abc. -1} |
| 1806 |
} -result 3 |
| 1807 |
test string-21.5.$noComp {string wordend} -body { |
| 1808 |
run {string wordend abc. 100} |
| 1809 |
} -result 4 |
| 1810 |
test string-21.6.$noComp {string wordend} -body { |
| 1811 |
run {string wordend "word_one two three" 2} |
| 1812 |
} -result 8 |
| 1813 |
test string-21.7.$noComp {string wordend} -body { |
| 1814 |
run {string wordend "one .&# three" 5} |
| 1815 |
} -result 6 |
| 1816 |
test string-21.8.$noComp {string wordend} -body { |
| 1817 |
run {string worde "x.y" 0} |
| 1818 |
} -result 1 |
| 1819 |
test string-21.9.$noComp {string wordend} -body { |
| 1820 |
run {string worde "x.y" end-1} |
| 1821 |
} -result 2 |
| 1822 |
test string-21.10.$noComp {string wordend, unicode} -body { |
| 1823 |
run {string wordend "xyz\xC7de fg" 0} |
| 1824 |
} -result 6 |
| 1825 |
test string-21.11.$noComp {string wordend, unicode} -body { |
| 1826 |
run {string wordend "xyz\uC700de fg" 0} |
| 1827 |
} -result 6 |
| 1828 |
test string-21.12.$noComp {string wordend, unicode} -body { |
| 1829 |
run {string wordend "xyz\u203Fde fg" 0} |
| 1830 |
} -result 6 |
| 1831 |
test string-21.13.$noComp {string wordend, unicode} -body { |
| 1832 |
run {string wordend "xyz\u2045de fg" 0} |
| 1833 |
} -result 3 |
| 1834 |
test string-21.14.$noComp {string wordend, unicode} -body { |
| 1835 |
run {string wordend "\uC700\uC700 abc" 8} |
| 1836 |
} -result 6 |
| 1837 |
test string-21.17.$noComp {string trim, unicode} { |
| 1838 |
run {string trim "\uD83D\uDE02Hello world!\uD83D\uDE02" \uD83D\uDE02} |
| 1839 |
} "Hello world!" |
| 1840 |
test string-21.18.$noComp {string trimleft, unicode} { |
| 1841 |
run {string trimleft "\uD83D\uDE02Hello world!\uD83D\uDE02" \uD83D\uDE02} |
| 1842 |
} "Hello world!\uD83D\uDE02" |
| 1843 |
test string-21.19.$noComp {string trimright, unicode} { |
| 1844 |
run {string trimright "\uD83D\uDE02Hello world!\uD83D\uDE02" \uD83D\uDE02} |
| 1845 |
} "\uD83D\uDE02Hello world!" |
| 1846 |
test string-21.20.$noComp {string trim, unicode} { |
| 1847 |
run {string trim "\uF602Hello world!\uF602" \uD83D\uDE02} |
| 1848 |
} "\uF602Hello world!\uF602" |
| 1849 |
test string-21.21.$noComp {string trimleft, unicode} { |
| 1850 |
run {string trimleft "\uF602Hello world!\uF602" \uD83D\uDE02} |
| 1851 |
} "\uF602Hello world!\uF602" |
| 1852 |
test string-21.22.$noComp {string trimright, unicode} { |
| 1853 |
run {string trimright "\uF602Hello world!\uF602" \uD83D\uDE02} |
| 1854 |
} "\uF602Hello world!\uF602" |
| 1855 |
test string-21.23.$noComp {string trim, unicode} { |
| 1856 |
run {string trim "\uD83D\uDE02Hello world!\uD83D\uDE02" \uD93D\uDE02} |
| 1857 |
} "\uD83D\uDE02Hello world!\uD83D\uDE02" |
| 1858 |
test string-21.24.$noComp {string trimleft, unicode} { |
| 1859 |
run {string trimleft "\uD83D\uDE02Hello world!\uD83D\uDE02" \uD93D\uDE02} |
| 1860 |
} "\uD83D\uDE02Hello world!\uD83D\uDE02" |
| 1861 |
test string-21.25.$noComp {string trimright, unicode} { |
| 1862 |
run {string trimright "\uD83D\uDE02Hello world!\uD83D\uDE02" \uD93D\uDE02} |
| 1863 |
} "\uD83D\uDE02Hello world!\uD83D\uDE02" |
| 1864 |
|
| 1865 |
test string-22.1.$noComp {string wordstart} -body { |
| 1866 |
list [catch {run {string word a}} msg] $msg |
| 1867 |
} -result {1 {unknown or ambiguous subcommand "word": must be bytelength, cat, compare, equal, first, index, is, last, length, map, match, range, repeat, replace, reverse, tolower, totitle, toupper, trim, trimleft, trimright, wordend, or wordstart}} |
| 1868 |
test string-22.2.$noComp {string wordstart} -body { |
| 1869 |
list [catch {run {string wordstart a}} msg] $msg |
| 1870 |
} -result {1 {wrong # args: should be "string wordstart string index"}} |
| 1871 |
test string-22.3.$noComp {string wordstart} -body { |
| 1872 |
list [catch {run {string wordstart a b c}} msg] $msg |
| 1873 |
} -result {1 {wrong # args: should be "string wordstart string index"}} |
| 1874 |
test string-22.4.$noComp {string wordstart} -body { |
| 1875 |
list [catch {run {string wordstart a gorp}} msg] $msg |
| 1876 |
} -result {1 {bad index "gorp": must be integer?[+-]integer? or end?[+-]integer?}} |
| 1877 |
test string-22.5.$noComp {string wordstart} -body { |
| 1878 |
run {string wordstart "one two three_words" 400} |
| 1879 |
} -result 8 |
| 1880 |
test string-22.6.$noComp {string wordstart} -body { |
| 1881 |
run {string wordstart "one two three_words" 2} |
| 1882 |
} -result 0 |
| 1883 |
test string-22.7.$noComp {string wordstart} -body { |
| 1884 |
run {string wordstart "one two three_words" -2} |
| 1885 |
} -result 0 |
| 1886 |
test string-22.8.$noComp {string wordstart} -body { |
| 1887 |
run {string wordstart "one .*&^ three" 6} |
| 1888 |
} -result 6 |
| 1889 |
test string-22.9.$noComp {string wordstart} -body { |
| 1890 |
run {string wordstart "one two three" 4} |
| 1891 |
} -result 4 |
| 1892 |
test string-22.10.$noComp {string wordstart} -body { |
| 1893 |
run {string wordstart "one two three" end-5} |
| 1894 |
} -result 7 |
| 1895 |
test string-22.11.$noComp {string wordstart, unicode} -body { |
| 1896 |
run {string wordstart "one tw\xC7o three" 7} |
| 1897 |
} -result 4 |
| 1898 |
test string-22.12.$noComp {string wordstart, unicode} -body { |
| 1899 |
run {string wordstart "ab\uC700\uC700 cdef ghi" 12} |
| 1900 |
} -result 10 |
| 1901 |
test string-22.13.$noComp {string wordstart, unicode} -body { |
| 1902 |
run {string wordstart "\uC700\uC700 abc" 8} |
| 1903 |
} -result 3 |
| 1904 |
test string-22.14.$noComp {string wordstart, invalid UTF-8} -constraints testbytestring -body { |
| 1905 |
# See Bug c61818e4c9 |
| 1906 |
set demo [testbytestring "abc def\xE0\xA9ghi"] |
| 1907 |
run {string index $demo [string wordstart $demo 10]} |
| 1908 |
} -result g |
| 1909 |
|
| 1910 |
test string-23.0.$noComp {string is boolean, Bug 1187123} testindexobj { |
| 1911 |
set x 5 |
| 1912 |
catch {testindexobj $x foo bar soom} |
| 1913 |
run {string is boolean $x} |
| 1914 |
} 0 |
| 1915 |
test string-23.1.$noComp {string is command with empty string} { |
| 1916 |
set s "" |
| 1917 |
list \ |
| 1918 |
[run {string is alnum $s}] \ |
| 1919 |
[run {string is alpha $s}] \ |
| 1920 |
[run {string is ascii $s}] \ |
| 1921 |
[run {string is control $s}] \ |
| 1922 |
[run {string is boolean $s}] \ |
| 1923 |
[run {string is digit $s}] \ |
| 1924 |
[run {string is double $s}] \ |
| 1925 |
[run {string is false $s}] \ |
| 1926 |
[run {string is graph $s}] \ |
| 1927 |
[run {string is integer $s}] \ |
| 1928 |
[run {string is lower $s}] \ |
| 1929 |
[run {string is print $s}] \ |
| 1930 |
[run {string is punct $s}] \ |
| 1931 |
[run {string is space $s}] \ |
| 1932 |
[run {string is true $s}] \ |
| 1933 |
[run {string is upper $s}] \ |
| 1934 |
[run {string is wordchar $s}] \ |
| 1935 |
[run {string is xdigit $s}] \ |
| 1936 |
|
| 1937 |
} {1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1} |
| 1938 |
test string-23.2.$noComp {string is command with empty string} { |
| 1939 |
set s "" |
| 1940 |
list \ |
| 1941 |
[run {string is alnum -strict $s}] \ |
| 1942 |
[run {string is alpha -strict $s}] \ |
| 1943 |
[run {string is ascii -strict $s}] \ |
| 1944 |
[run {string is control -strict $s}] \ |
| 1945 |
[run {string is boolean -strict $s}] \ |
| 1946 |
[run {string is digit -strict $s}] \ |
| 1947 |
[run {string is double -strict $s}] \ |
| 1948 |
[run {string is false -strict $s}] \ |
| 1949 |
[run {string is graph -strict $s}] \ |
| 1950 |
[run {string is integer -strict $s}] \ |
| 1951 |
[run {string is lower -strict $s}] \ |
| 1952 |
[run {string is print -strict $s}] \ |
| 1953 |
[run {string is punct -strict $s}] \ |
| 1954 |
[run {string is space -strict $s}] \ |
| 1955 |
[run {string is true -strict $s}] \ |
| 1956 |
[run {string is upper -strict $s}] \ |
| 1957 |
[run {string is wordchar -strict $s}] \ |
| 1958 |
[run {string is xdigit -strict $s}] \ |
| 1959 |
|
| 1960 |
} {0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0} |
| 1961 |
|
| 1962 |
test string-24.1.$noComp {string reverse command} -body { |
| 1963 |
run {string reverse} |
| 1964 |
} -returnCodes error -result "wrong # args: should be \"string reverse string\"" |
| 1965 |
test string-24.2.$noComp {string reverse command} -body { |
| 1966 |
run {string reverse a b} |
| 1967 |
} -returnCodes error -result "wrong # args: should be \"string reverse string\"" |
| 1968 |
test string-24.3.$noComp {string reverse command - shared string} { |
| 1969 |
set x abcde |
| 1970 |
run {string reverse $x} |
| 1971 |
} edcba |
| 1972 |
test string-24.4.$noComp {string reverse command - unshared string} { |
| 1973 |
set x abc |
| 1974 |
set y de |
| 1975 |
run {string reverse $x$y} |
| 1976 |
} edcba |
| 1977 |
test string-24.5.$noComp {string reverse command - shared unicode string} { |
| 1978 |
set x abcde\uD0AD |
| 1979 |
run {string reverse $x} |
| 1980 |
} \uD0ADedcba |
| 1981 |
test string-24.6.$noComp {string reverse command - unshared string} { |
| 1982 |
set x abc |
| 1983 |
set y de\uD0AD |
| 1984 |
run {string reverse $x$y} |
| 1985 |
} \uD0ADedcba |
| 1986 |
test string-24.7.$noComp {string reverse command - simple case} { |
| 1987 |
run {string reverse a} |
| 1988 |
} a |
| 1989 |
test string-24.8.$noComp {string reverse command - simple case} { |
| 1990 |
run {string reverse \uD0AD} |
| 1991 |
} \uD0AD |
| 1992 |
test string-24.9.$noComp {string reverse command - simple case} { |
| 1993 |
run {string reverse {}} |
| 1994 |
} {} |
| 1995 |
test string-24.10.$noComp {string reverse command - corner case} { |
| 1996 |
set x \uBEEF\uD0AD |
| 1997 |
run {string reverse $x} |
| 1998 |
} \uD0AD\uBEEF |
| 1999 |
test string-24.11.$noComp {string reverse command - corner case} { |
| 2000 |
set x \uBEEF |
| 2001 |
set y \uD0AD |
| 2002 |
run {string reverse $x$y} |
| 2003 |
} \uD0AD\uBEEF |
| 2004 |
test string-24.12.$noComp {string reverse command - corner case} { |
| 2005 |
set x \uBEEF |
| 2006 |
set y \uD0AD |
| 2007 |
run {string is ascii [run {string reverse $x$y}]} |
| 2008 |
} 0 |
| 2009 |
test string-24.13.$noComp {string reverse command - pure Unicode string} { |
| 2010 |
run {string reverse [run {string range \uBEEF\uD0AD\uBEEF\uD0AD\uBEEF\uD0AD 1 5}]} |
| 2011 |
} \uD0AD\uBEEF\uD0AD\uBEEF\uD0AD |
| 2012 |
test string-24.14.$noComp {string reverse command - pure bytearray} { |
| 2013 |
binary scan [run {string reverse [binary format H* 010203]}] H* x |
| 2014 |
set x |
| 2015 |
} 030201 |
| 2016 |
test string-24.15.$noComp {string reverse command - pure bytearray} { |
| 2017 |
binary scan [run {tcl::string::reverse [binary format H* 010203]}] H* x |
| 2018 |
set x |
| 2019 |
} 030201 |
| 2020 |
test string-24.16.$noComp {string reverse command - surrogates} { |
| 2021 |
run {string reverse \u0444bulb\uD83D\uDE02} |
| 2022 |
} \uD83D\uDE02blub\u0444 |
| 2023 |
test string-24.17.$noComp {string reverse command - surrogates} { |
| 2024 |
run {string reverse \uD83D\uDE02hello\uD83D\uDE02} |
| 2025 |
} \uD83D\uDE02olleh\uD83D\uDE02 |
| 2026 |
test string-24.18.$noComp {string reverse command - surrogates} { |
| 2027 |
set s \u0444bulb\uD83D\uDE02 |
| 2028 |
# shim shimmery ... |
| 2029 |
string index $s 0 |
| 2030 |
run {string reverse $s} |
| 2031 |
} \uD83D\uDE02blub\u0444 |
| 2032 |
test string-24.19.$noComp {string reverse command - surrogates} { |
| 2033 |
set s \uD83D\uDE02hello\uD83D\uDE02 |
| 2034 |
# shim shimmery ... |
| 2035 |
string index $s 0 |
| 2036 |
run {string reverse $s} |
| 2037 |
} \uD83D\uDE02olleh\uD83D\uDE02 |
| 2038 |
|
| 2039 |
test string-25.1.$noComp {string is list} { |
| 2040 |
run {string is list {a b c}} |
| 2041 |
} 1 |
| 2042 |
test string-25.2.$noComp {string is list} { |
| 2043 |
run {string is list "a \{b c"} |
| 2044 |
} 0 |
| 2045 |
test string-25.3.$noComp {string is list} { |
| 2046 |
run {string is list {a {b c}d e}} |
| 2047 |
} 0 |
| 2048 |
test string-25.4.$noComp {string is list} { |
| 2049 |
run {string is list {}} |
| 2050 |
} 1 |
| 2051 |
test string-25.5.$noComp {string is list} { |
| 2052 |
run {string is list -strict {a b c}} |
| 2053 |
} 1 |
| 2054 |
test string-25.6.$noComp {string is list} { |
| 2055 |
run {string is list -strict "a \{b c"} |
| 2056 |
} 0 |
| 2057 |
test string-25.7.$noComp {string is list} { |
| 2058 |
run {string is list -strict {a {b c}d e}} |
| 2059 |
} 0 |
| 2060 |
test string-25.8.$noComp {string is list} { |
| 2061 |
run {string is list -strict {}} |
| 2062 |
} 1 |
| 2063 |
test string-25.9.$noComp {string is list} { |
| 2064 |
set x {} |
| 2065 |
list [run {string is list -failindex x {a b c}}] $x |
| 2066 |
} {1 {}} |
| 2067 |
test string-25.10.$noComp {string is list} { |
| 2068 |
set x {} |
| 2069 |
list [run {string is list -failindex x "a \{b c"}] $x |
| 2070 |
} {0 2} |
| 2071 |
test string-25.11.$noComp {string is list} { |
| 2072 |
set x {} |
| 2073 |
list [run {string is list -failindex x {a b {b c}d e}}] $x |
| 2074 |
} {0 4} |
| 2075 |
test string-25.12.$noComp {string is list} { |
| 2076 |
set x {} |
| 2077 |
list [run {string is list -failindex x {}}] $x |
| 2078 |
} {1 {}} |
| 2079 |
test string-25.13.$noComp {string is list} { |
| 2080 |
set x {} |
| 2081 |
list [run {string is list -failindex x { {b c}d e}}] $x |
| 2082 |
} {0 2} |
| 2083 |
test string-25.14.$noComp {string is list} { |
| 2084 |
set x {} |
| 2085 |
list [run {string is list -failindex x "\uABCD {b c}d e"}] $x |
| 2086 |
} {0 2} |
| 2087 |
|
| 2088 |
test string-26.1.$noComp {tcl::prefix, not enough args} -body { |
| 2089 |
tcl::prefix match a |
| 2090 |
} -returnCodes 1 -result {wrong # args: should be "tcl::prefix match ?options? table string"} |
| 2091 |
test string-26.2.$noComp {tcl::prefix, bad args} -body { |
| 2092 |
tcl::prefix match a b c |
| 2093 |
} -returnCodes 1 -result {bad option "a": must be -error, -exact, or -message} |
| 2094 |
test string-26.2.1.$noComp {tcl::prefix, empty table} -body { |
| 2095 |
tcl::prefix match {} foo |
| 2096 |
} -returnCodes 1 -result {bad option "foo": no valid options} |
| 2097 |
test string-26.3.$noComp {tcl::prefix, bad args} -body { |
| 2098 |
tcl::prefix match -error "{}x" -exact str1 str2 |
| 2099 |
} -returnCodes 1 -result {list element in braces followed by "x" instead of space} |
| 2100 |
test string-26.3.1.$noComp {tcl::prefix, bad args} -body { |
| 2101 |
tcl::prefix match -error "x" -exact str1 str2 |
| 2102 |
} -returnCodes 1 -result {error options must have an even number of elements} |
| 2103 |
test string-26.3.2.$noComp {tcl::prefix, bad args} -body { |
| 2104 |
tcl::prefix match -error str1 str2 |
| 2105 |
} -returnCodes 1 -result {missing value for -error} |
| 2106 |
test string-26.4.$noComp {tcl::prefix, bad args} -body { |
| 2107 |
tcl::prefix match -message str1 str2 |
| 2108 |
} -returnCodes 1 -result {missing value for -message} |
| 2109 |
test string-26.5.$noComp {tcl::prefix} { |
| 2110 |
tcl::prefix match {apa bepa cepa depa} cepa |
| 2111 |
} cepa |
| 2112 |
test string-26.6.$noComp {tcl::prefix} { |
| 2113 |
tcl::prefix match {apa bepa cepa depa} be |
| 2114 |
} bepa |
| 2115 |
test string-26.7.$noComp {tcl::prefix} -body { |
| 2116 |
tcl::prefix match -exact {apa bepa cepa depa} be |
| 2117 |
} -returnCodes 1 -result {bad option "be": must be apa, bepa, cepa, or depa} |
| 2118 |
test string-26.8.$noComp {tcl::prefix} -body { |
| 2119 |
tcl::prefix match -message wombat {apa bepa bear depa} be |
| 2120 |
} -returnCodes 1 -result {ambiguous wombat "be": must be apa, bepa, bear, or depa} |
| 2121 |
test string-26.9.$noComp {tcl::prefix} -body { |
| 2122 |
tcl::prefix match -error {} {apa bepa bear depa} be |
| 2123 |
} -returnCodes 0 -result {} |
| 2124 |
test string-26.10.$noComp {tcl::prefix} -body { |
| 2125 |
tcl::prefix match -error {-level 1} {apa bepa bear depa} be |
| 2126 |
} -returnCodes 2 -result {ambiguous option "be": must be apa, bepa, bear, or depa} |
| 2127 |
test string-26.10.1.$noComp {tcl::prefix} -setup { |
| 2128 |
proc _testprefix {args} { |
| 2129 |
array set opts {-a x -b y -c y} |
| 2130 |
foreach {opt val} $args { |
| 2131 |
set opt [tcl::prefix match -error {-level 1} {-a -b -c} $opt] |
| 2132 |
set opts($opt) $val |
| 2133 |
} |
| 2134 |
array get opts |
| 2135 |
} |
| 2136 |
} -body { |
| 2137 |
set a [catch {_testprefix -x u} result options] |
| 2138 |
dict get $options -errorinfo |
| 2139 |
} -cleanup { |
| 2140 |
rename _testprefix {} |
| 2141 |
} -result {bad option "-x": must be -a, -b, or -c |
| 2142 |
while executing |
| 2143 |
"_testprefix -x u"} |
| 2144 |
|
| 2145 |
# Helper for memory stress tests |
| 2146 |
# Repeat each body in a local space checking that memory does not increase |
| 2147 |
proc MemStress {args} { |
| 2148 |
set res {} |
| 2149 |
foreach body $args { |
| 2150 |
set end 0 |
| 2151 |
for {set i 0} {$i < 5} {incr i} { |
| 2152 |
proc MemStress_Body {} $body |
| 2153 |
uplevel 1 MemStress_Body |
| 2154 |
rename MemStress_Body {} |
| 2155 |
set tmp $end |
| 2156 |
set end [lindex [lindex [split [memory info] "\n"] 3] 3] |
| 2157 |
} |
| 2158 |
lappend res [expr {$end - $tmp}] |
| 2159 |
} |
| 2160 |
return $res |
| 2161 |
} |
| 2162 |
|
| 2163 |
test string-26.11.$noComp {tcl::prefix: testing for leaks} -body { |
| 2164 |
# This test is made to stress object reference management |
| 2165 |
MemStress { |
| 2166 |
set table {hejj miff gurk} |
| 2167 |
set item [lindex $table 1] |
| 2168 |
# If not careful, this can cause a circular reference |
| 2169 |
# that will cause a leak. |
| 2170 |
tcl::prefix match $table $item |
| 2171 |
} { |
| 2172 |
# A similar case with nested lists |
| 2173 |
set table2 {hejj {miff maff} gurk} |
| 2174 |
set item [lindex [lindex $table2 1] 0] |
| 2175 |
tcl::prefix match $table2 $item |
| 2176 |
} { |
| 2177 |
# A similar case with dict |
| 2178 |
set table3 {hejj {miff maff} gurk2} |
| 2179 |
set item [lindex [dict keys [lindex $table3 1]] 0] |
| 2180 |
tcl::prefix match $table3 $item |
| 2181 |
} |
| 2182 |
} -constraints memory -result {0 0 0} |
| 2183 |
|
| 2184 |
test string-26.12.$noComp {tcl::prefix: testing for leaks} -body { |
| 2185 |
# This is a memory leak test in a form that might actually happen |
| 2186 |
# in real code. The shared literal "miff" causes a connection |
| 2187 |
# between the item and the table. |
| 2188 |
MemStress { |
| 2189 |
proc stress1 {item} { |
| 2190 |
set table [list hejj miff gurk] |
| 2191 |
tcl::prefix match $table $item |
| 2192 |
} |
| 2193 |
proc stress2 {} { |
| 2194 |
stress1 miff |
| 2195 |
} |
| 2196 |
stress2 |
| 2197 |
rename stress1 {} |
| 2198 |
rename stress2 {} |
| 2199 |
} |
| 2200 |
} -constraints memory -result 0 |
| 2201 |
|
| 2202 |
test string-26.13.$noComp {tcl::prefix: testing for leaks} -body { |
| 2203 |
# This test is made to stress object reference management |
| 2204 |
MemStress { |
| 2205 |
set table [list hejj miff] |
| 2206 |
set item $table |
| 2207 |
set error $table |
| 2208 |
# Use the same objects in all places |
| 2209 |
catch { |
| 2210 |
tcl::prefix match -error $error $table $item |
| 2211 |
} |
| 2212 |
} |
| 2213 |
} -constraints memory -result {0} |
| 2214 |
|
| 2215 |
test string-27.1.$noComp {tcl::prefix all, not enough args} -body { |
| 2216 |
tcl::prefix all a |
| 2217 |
} -returnCodes 1 -result {wrong # args: should be "tcl::prefix all table string"} |
| 2218 |
test string-27.2.$noComp {tcl::prefix all, bad args} -body { |
| 2219 |
tcl::prefix all a b c |
| 2220 |
} -returnCodes 1 -result {wrong # args: should be "tcl::prefix all table string"} |
| 2221 |
test string-27.3.$noComp {tcl::prefix all, bad args} -body { |
| 2222 |
tcl::prefix all "{}x" str2 |
| 2223 |
} -returnCodes 1 -result {list element in braces followed by "x" instead of space} |
| 2224 |
test string-27.4.$noComp {tcl::prefix all} { |
| 2225 |
tcl::prefix all {apa bepa cepa depa} c |
| 2226 |
} cepa |
| 2227 |
test string-27.5.$noComp {tcl::prefix all} { |
| 2228 |
tcl::prefix all {apa bepa cepa depa} cepa |
| 2229 |
} cepa |
| 2230 |
test string-27.6.$noComp {tcl::prefix all} { |
| 2231 |
tcl::prefix all {apa bepa cepa depa} cepax |
| 2232 |
} {} |
| 2233 |
test string-27.7.$noComp {tcl::prefix all} { |
| 2234 |
tcl::prefix all {apa aska appa} a |
| 2235 |
} {apa aska appa} |
| 2236 |
test string-27.8.$noComp {tcl::prefix all} { |
| 2237 |
tcl::prefix all {apa aska appa} ap |
| 2238 |
} {apa appa} |
| 2239 |
test string-27.9.$noComp {tcl::prefix all} { |
| 2240 |
tcl::prefix all {apa aska appa} p |
| 2241 |
} {} |
| 2242 |
test string-27.10.$noComp {tcl::prefix all} { |
| 2243 |
tcl::prefix all {apa aska appa} {} |
| 2244 |
} {apa aska appa} |
| 2245 |
|
| 2246 |
test string-28.1.$noComp {tcl::prefix longest, not enough args} -body { |
| 2247 |
tcl::prefix longest a |
| 2248 |
} -returnCodes 1 -result {wrong # args: should be "tcl::prefix longest table string"} |
| 2249 |
test string-28.2.$noComp {tcl::prefix longest, bad args} -body { |
| 2250 |
tcl::prefix longest a b c |
| 2251 |
} -returnCodes 1 -result {wrong # args: should be "tcl::prefix longest table string"} |
| 2252 |
test string-28.3.$noComp {tcl::prefix longest, bad args} -body { |
| 2253 |
tcl::prefix longest "{}x" str2 |
| 2254 |
} -returnCodes 1 -result {list element in braces followed by "x" instead of space} |
| 2255 |
test string-28.4.$noComp {tcl::prefix longest} { |
| 2256 |
tcl::prefix longest {apa bepa cepa depa} c |
| 2257 |
} cepa |
| 2258 |
test string-28.5.$noComp {tcl::prefix longest} { |
| 2259 |
tcl::prefix longest {apa bepa cepa depa} cepa |
| 2260 |
} cepa |
| 2261 |
test string-28.6.$noComp {tcl::prefix longest} { |
| 2262 |
tcl::prefix longest {apa bepa cepa depa} cepax |
| 2263 |
} {} |
| 2264 |
test string-28.7.$noComp {tcl::prefix longest} { |
| 2265 |
tcl::prefix longest {apa aska appa} a |
| 2266 |
} a |
| 2267 |
test string-28.8.$noComp {tcl::prefix longest} { |
| 2268 |
tcl::prefix longest {apa aska appa} ap |
| 2269 |
} ap |
| 2270 |
test string-28.9.$noComp {tcl::prefix longest} { |
| 2271 |
tcl::prefix longest {apa bska appa} a |
| 2272 |
} ap |
| 2273 |
test string-28.10.$noComp {tcl::prefix longest} { |
| 2274 |
tcl::prefix longest {apa bska appa} {} |
| 2275 |
} {} |
| 2276 |
test string-28.11.$noComp {tcl::prefix longest} { |
| 2277 |
tcl::prefix longest {{} bska appa} {} |
| 2278 |
} {} |
| 2279 |
test string-28.12.$noComp {tcl::prefix longest} { |
| 2280 |
tcl::prefix longest {apa {} appa} {} |
| 2281 |
} {} |
| 2282 |
test string-28.13.$noComp {tcl::prefix longest} { |
| 2283 |
# Test utf-8 handling |
| 2284 |
tcl::prefix longest {ax\x90 bep ax\x91} a |
| 2285 |
} ax |
| 2286 |
|
| 2287 |
test string-29.1.$noComp {string cat, no arg} { |
| 2288 |
run {string cat} |
| 2289 |
} "" |
| 2290 |
test string-29.2.$noComp {string cat, single arg} { |
| 2291 |
set x FOO |
| 2292 |
run {string compare $x [run {string cat $x}]} |
| 2293 |
} 0 |
| 2294 |
test string-29.3.$noComp {string cat, two args} { |
| 2295 |
set x FOO |
| 2296 |
run {string compare $x$x [run {string cat $x $x}]} |
| 2297 |
} 0 |
| 2298 |
test string-29.4.$noComp {string cat, many args} { |
| 2299 |
set x FOO |
| 2300 |
set n 260 |
| 2301 |
set xx [run {string repeat $x $n}] |
| 2302 |
set vv [run {string repeat {$x} $n}] |
| 2303 |
set vvs [run {string repeat {$x } $n}] |
| 2304 |
set r1 [run {string compare $xx [subst $vv]}] |
| 2305 |
set r2 [run {string compare $xx [eval "run {string cat $vvs}"]}] |
| 2306 |
list $r1 $r2 |
| 2307 |
} {0 0} |
| 2308 |
|
| 2309 |
test string-30.1.1.$noComp {[Bug ba921a8d98]: string cat} { |
| 2310 |
run {string cat [set data [binary format a* hello]] [encoding convertto $data] [unset data]} |
| 2311 |
} hellohello |
| 2312 |
test string-30.1.2.$noComp {[Bug ba921a8d98]: inplace cat by subst (compiled to "strcat" instruction)} { |
| 2313 |
run {set x "[set data [binary format a* hello]][encoding convertto $data][unset data]"} |
| 2314 |
} hellohello |
| 2315 |
|
| 2316 |
|
| 2317 |
}; # foreach noComp {0 1} |
| 2318 |
|
| 2319 |
# cleanup |
| 2320 |
rename MemStress {} |
| 2321 |
catch {rename foo {}} |
| 2322 |
::tcltest::cleanupTests |
| 2323 |
return |
| 2324 |
|
| 2325 |
# Local Variables: |
| 2326 |
# mode: tcl |
| 2327 |
# End: |