sl@0: # Commands covered: string sl@0: # sl@0: # This file contains a collection of tests for one or more of the Tcl sl@0: # built-in commands. Sourcing this file into Tcl runs the tests and sl@0: # generates output for errors. No output means no errors were found. sl@0: # sl@0: # This differs from the original string tests in that the tests call sl@0: # things in procs, which uses the compiled string code instead of sl@0: # the runtime parse string code. The tests of import should match sl@0: # their equivalent number in string.test. sl@0: # sl@0: # Copyright (c) 2001 by ActiveState Corporation. sl@0: # Copyright (c) 2001 by Kevin B. Kenny. All rights reserved. sl@0: # sl@0: # See the file "license.terms" for information on usage and redistribution sl@0: # of this file, and for a DISCLAIMER OF ALL WARRANTIES. sl@0: # sl@0: # RCS: @(#) $Id: stringComp.test,v 1.6.2.1 2004/10/28 00:01:12 dgp Exp $ sl@0: sl@0: if {[lsearch [namespace children] ::tcltest] == -1} { sl@0: package require tcltest sl@0: namespace import -force ::tcltest::* sl@0: } sl@0: sl@0: # Some tests require the testobj command sl@0: sl@0: set ::tcltest::testConstraints(testobj) \ sl@0: [expr {[info commands testobj] != {}}] sl@0: sl@0: test stringComp-1.1 {error conditions} { sl@0: proc foo {} {string gorp a b} sl@0: list [catch {foo} msg] $msg sl@0: } {1 {bad option "gorp": must be bytelength, compare, equal, first, index, is, last, length, map, match, range, repeat, replace, tolower, toupper, totitle, trim, trimleft, trimright, wordend, or wordstart}} sl@0: test stringComp-1.2 {error conditions} { sl@0: proc foo {} {string} sl@0: list [catch {foo} msg] $msg sl@0: } {1 {wrong # args: should be "string option arg ?arg ...?"}} sl@0: test stringComp-1.3 {error condition - undefined method during compile} { sl@0: # We don't want this to complain about 'never' because it may never sl@0: # be called, or string may get redefined. This must compile OK. sl@0: proc foo {str i} { sl@0: if {"yes" == "no"} { string never called but complains here } sl@0: string index $str $i sl@0: } sl@0: foo abc 0 sl@0: } a sl@0: sl@0: test stringComp-2.1 {string compare, too few args} { sl@0: proc foo {} {string compare a} sl@0: list [catch {foo} msg] $msg sl@0: } {1 {wrong # args: should be "string compare ?-nocase? ?-length int? string1 string2"}} sl@0: test stringComp-2.2 {string compare, bad args} { sl@0: proc foo {} {string compare a b c} sl@0: list [catch {foo} msg] $msg sl@0: } {1 {bad option "a": must be -nocase or -length}} sl@0: test stringComp-2.3 {string compare, bad args} { sl@0: list [catch {string compare -length -nocase str1 str2} msg] $msg sl@0: } {1 {expected integer but got "-nocase"}} sl@0: test stringComp-2.4 {string compare, too many args} { sl@0: list [catch {string compare -length 10 -nocase str1 str2 str3} msg] $msg sl@0: } {1 {wrong # args: should be "string compare ?-nocase? ?-length int? string1 string2"}} sl@0: test stringComp-2.5 {string compare with length unspecified} { sl@0: list [catch {string compare -length 10 10} msg] $msg sl@0: } {1 {wrong # args: should be "string compare ?-nocase? ?-length int? string1 string2"}} sl@0: test stringComp-2.6 {string compare} { sl@0: proc foo {} {string compare abcde abdef} sl@0: foo sl@0: } -1 sl@0: test stringComp-2.7 {string compare, shortest method name} { sl@0: proc foo {} {string c abcde ABCDE} sl@0: foo sl@0: } 1 sl@0: test stringComp-2.8 {string compare} { sl@0: proc foo {} {string compare abcde abcde} sl@0: foo sl@0: } 0 sl@0: test stringComp-2.9 {string compare with length} { sl@0: proc foo {} {string compare -length 2 abcde abxyz} sl@0: foo sl@0: } 0 sl@0: test stringComp-2.10 {string compare with special index} { sl@0: proc foo {} {string compare -length end-3 abcde abxyz} sl@0: list [catch {foo} msg] $msg sl@0: } {1 {expected integer but got "end-3"}} sl@0: test stringComp-2.11 {string compare, unicode} { sl@0: proc foo {} {string compare ab\u7266 ab\u7267} sl@0: foo sl@0: } -1 sl@0: test stringComp-2.12 {string compare, high bit} { sl@0: # This test will fail if the underlying comparaison sl@0: # is using signed chars instead of unsigned chars. sl@0: # (like SunOS's default memcmp thus the compat/memcmp.c) sl@0: proc foo {} {string compare "\x80" "@"} sl@0: foo sl@0: # Nb this tests works also in utf8 space because \x80 is sl@0: # translated into a 2 or more bytelength but whose first byte has sl@0: # the high bit set. sl@0: } 1 sl@0: test stringComp-2.13 {string compare -nocase} { sl@0: proc foo {} {string compare -nocase abcde abdef} sl@0: foo sl@0: } -1 sl@0: test stringComp-2.14 {string compare -nocase} { sl@0: proc foo {} {string c -nocase abcde ABCDE} sl@0: foo sl@0: } 0 sl@0: test stringComp-2.15 {string compare -nocase} { sl@0: proc foo {} {string compare -nocase abcde abcde} sl@0: foo sl@0: } 0 sl@0: test stringComp-2.16 {string compare -nocase with length} { sl@0: proc foo {} {string compare -length 2 -nocase abcde Abxyz} sl@0: foo sl@0: } 0 sl@0: test stringComp-2.17 {string compare -nocase with length} { sl@0: proc foo {} {string compare -nocase -length 3 abcde Abxyz} sl@0: foo sl@0: } -1 sl@0: test stringComp-2.18 {string compare -nocase with length <= 0} { sl@0: proc foo {} {string compare -nocase -length -1 abcde AbCdEf} sl@0: foo sl@0: } -1 sl@0: test stringComp-2.19 {string compare -nocase with excessive length} { sl@0: proc foo {} {string compare -nocase -length 50 AbCdEf abcde} sl@0: foo sl@0: } 1 sl@0: test stringComp-2.20 {string compare -len unicode} { sl@0: # These are strings that are 6 BYTELENGTH long, but the length sl@0: # shouldn't make a different because there are actually 3 CHARS long sl@0: proc foo {} {string compare -len 5 \334\334\334 \334\334\374} sl@0: foo sl@0: } -1 sl@0: test stringComp-2.21 {string compare -nocase with special index} { sl@0: proc foo {} {string compare -nocase -length end-3 Abcde abxyz} sl@0: list [catch {foo} msg] $msg sl@0: } {1 {expected integer but got "end-3"}} sl@0: test stringComp-2.22 {string compare, null strings} { sl@0: proc foo {} {string compare "" ""} sl@0: foo sl@0: } 0 sl@0: test stringComp-2.23 {string compare, null strings} { sl@0: proc foo {} {string compare "" foo} sl@0: foo sl@0: } -1 sl@0: test stringComp-2.24 {string compare, null strings} { sl@0: proc foo {} {string compare foo ""} sl@0: foo sl@0: } 1 sl@0: test stringComp-2.25 {string compare -nocase, null strings} { sl@0: proc foo {} {string compare -nocase "" ""} sl@0: foo sl@0: } 0 sl@0: test stringComp-2.26 {string compare -nocase, null strings} { sl@0: proc foo {} {string compare -nocase "" foo} sl@0: foo sl@0: } -1 sl@0: test stringComp-2.27 {string compare -nocase, null strings} { sl@0: proc foo {} {string compare -nocase foo ""} sl@0: foo sl@0: } 1 sl@0: test stringComp-2.28 {string compare with length, unequal strings} { sl@0: proc foo {} {string compare -length 2 abc abde} sl@0: foo sl@0: } 0 sl@0: test stringComp-2.29 {string compare with length, unequal strings} { sl@0: proc foo {} {string compare -length 2 ab abde} sl@0: foo sl@0: } 0 sl@0: test stringComp-2.30 {string compare with NUL character vs. other ASCII} { sl@0: # Be careful here, since UTF-8 rep comparison with memcmp() of sl@0: # these puts chars in the wrong order sl@0: proc foo {} {string compare \x00 \x01} sl@0: foo sl@0: } -1 sl@0: test stringComp-2.31 {string compare, high bit} { sl@0: proc foo {} {string compare "a\x80" "a@"} sl@0: foo sl@0: } 1 sl@0: test stringComp-2.32 {string compare, high bit} { sl@0: proc foo {} {string compare "a\x00" "a\x01"} sl@0: foo sl@0: } -1 sl@0: test stringComp-2.33 {string compare, high bit} { sl@0: proc foo {} {string compare "\x00\x00" "\x00\x01"} sl@0: foo sl@0: } -1 sl@0: sl@0: # only need a few tests on equal, since it uses the same code as sl@0: # string compare, but just modifies the return output sl@0: test stringComp-3.1 {string equal} { sl@0: proc foo {} {string equal abcde abdef} sl@0: foo sl@0: } 0 sl@0: test stringComp-3.2 {string equal} { sl@0: proc foo {} {string eq abcde ABCDE} sl@0: foo sl@0: } 0 sl@0: test stringComp-3.3 {string equal} { sl@0: proc foo {} {string equal abcde abcde} sl@0: foo sl@0: } 1 sl@0: test stringComp-3.4 {string equal -nocase} { sl@0: proc foo {} {string equal -nocase \334\334\334\334\374\374\374\374 \334\334\334\334\334\334\334\334} sl@0: foo sl@0: } 1 sl@0: test stringComp-3.5 {string equal -nocase} { sl@0: proc foo {} {string equal -nocase abcde abdef} sl@0: foo sl@0: } 0 sl@0: test stringComp-3.6 {string equal -nocase} { sl@0: proc foo {} {string eq -nocase abcde ABCDE} sl@0: foo sl@0: } 1 sl@0: test stringComp-3.7 {string equal -nocase} { sl@0: proc foo {} {string equal -nocase abcde abcde} sl@0: foo sl@0: } 1 sl@0: test stringComp-3.8 {string equal with length, unequal strings} { sl@0: proc foo {} {string equal -length 2 abc abde} sl@0: foo sl@0: } 1 sl@0: sl@0: test stringComp-4.1 {string first, too few args} { sl@0: proc foo {} {string first a} sl@0: list [catch {foo} msg] $msg sl@0: } {1 {wrong # args: should be "string first subString string ?startIndex?"}} sl@0: test stringComp-4.2 {string first, bad args} { sl@0: proc foo {} {string first a b c} sl@0: list [catch {foo} msg] $msg sl@0: } {1 {bad index "c": must be integer or end?-integer?}} sl@0: test stringComp-4.3 {string first, too many args} { sl@0: proc foo {} {string first a b 5 d} sl@0: list [catch {foo} msg] $msg sl@0: } {1 {wrong # args: should be "string first subString string ?startIndex?"}} sl@0: test stringComp-4.4 {string first} { sl@0: proc foo {} {string first bq abcdefgbcefgbqrs} sl@0: foo sl@0: } 12 sl@0: test stringComp-4.5 {string first} { sl@0: proc foo {} {string fir bcd abcdefgbcefgbqrs} sl@0: foo sl@0: } 1 sl@0: test stringComp-4.6 {string first} { sl@0: proc foo {} {string f b abcdefgbcefgbqrs} sl@0: foo sl@0: } 1 sl@0: test stringComp-4.7 {string first} { sl@0: proc foo {} {string first xxx x123xx345xxx789xxx012} sl@0: foo sl@0: } 9 sl@0: test stringComp-4.8 {string first} { sl@0: proc foo {} {string first "" x123xx345xxx789xxx012} sl@0: foo sl@0: } -1 sl@0: test stringComp-4.9 {string first, unicode} { sl@0: proc foo {} {string first x abc\u7266x} sl@0: foo sl@0: } 4 sl@0: test stringComp-4.10 {string first, unicode} { sl@0: proc foo {} {string first \u7266 abc\u7266x} sl@0: foo sl@0: } 3 sl@0: test stringComp-4.11 {string first, start index} { sl@0: proc foo {} {string first \u7266 abc\u7266x 3} sl@0: foo sl@0: } 3 sl@0: test stringComp-4.12 {string first, start index} { sl@0: proc foo {} {string first \u7266 abc\u7266x 4} sl@0: foo sl@0: } -1 sl@0: test stringComp-4.13 {string first, start index} { sl@0: proc foo {} {string first \u7266 abc\u7266x end-2} sl@0: foo sl@0: } 3 sl@0: test stringComp-4.14 {string first, negative start index} { sl@0: proc foo {} {string first b abc -1} sl@0: foo sl@0: } 1 sl@0: sl@0: test stringComp-5.1 {string index} { sl@0: proc foo {} {string index} sl@0: list [catch {foo} msg] $msg sl@0: } {1 {wrong # args: should be "string index string charIndex"}} sl@0: test stringComp-5.2 {string index} { sl@0: proc foo {} {string index a b c} sl@0: list [catch {foo} msg] $msg sl@0: } {1 {wrong # args: should be "string index string charIndex"}} sl@0: test stringComp-5.3 {string index} { sl@0: proc foo {} {string index abcde 0} sl@0: foo sl@0: } a sl@0: test stringComp-5.4 {string index} { sl@0: proc foo {} {string in abcde 4} sl@0: foo sl@0: } e sl@0: test stringComp-5.5 {string index} { sl@0: proc foo {} {string index abcde 5} sl@0: foo sl@0: } {} sl@0: test stringComp-5.6 {string index} { sl@0: proc foo {} {string index abcde -10} sl@0: list [catch {foo} msg] $msg sl@0: } {0 {}} sl@0: test stringComp-5.7 {string index} { sl@0: proc foo {} {string index a xyz} sl@0: list [catch {foo} msg] $msg sl@0: } {1 {bad index "xyz": must be integer or end?-integer?}} sl@0: test stringComp-5.8 {string index} { sl@0: proc foo {} {string index abc end} sl@0: foo sl@0: } c sl@0: test stringComp-5.9 {string index} { sl@0: proc foo {} {string index abc end-1} sl@0: foo sl@0: } b sl@0: test stringComp-5.10 {string index, unicode} { sl@0: proc foo {} {string index abc\u7266d 4} sl@0: foo sl@0: } d sl@0: test stringComp-5.11 {string index, unicode} { sl@0: proc foo {} {string index abc\u7266d 3} sl@0: foo sl@0: } \u7266 sl@0: test stringComp-5.12 {string index, unicode over char length, under byte length} { sl@0: proc foo {} {string index \334\374\334\374 6} sl@0: foo sl@0: } {} sl@0: test stringComp-5.13 {string index, bytearray object} { sl@0: proc foo {} {string index [binary format a5 fuz] 0} sl@0: foo sl@0: } f sl@0: test stringComp-5.14 {string index, bytearray object} { sl@0: proc foo {} {string index [binary format I* {0x50515253 0x52}] 3} sl@0: foo sl@0: } S sl@0: test stringComp-5.15 {string index, bytearray object} { sl@0: proc foo {} { sl@0: set b [binary format I* {0x50515253 0x52}] sl@0: set i1 [string index $b end-6] sl@0: set i2 [string index $b 1] sl@0: string compare $i1 $i2 sl@0: } sl@0: foo sl@0: } 0 sl@0: test stringComp-5.16 {string index, bytearray object with string obj shimmering} { sl@0: proc foo {} { sl@0: set str "0123456789\x00 abcdedfghi" sl@0: binary scan $str H* dump sl@0: string compare [string index $str 10] \x00 sl@0: } sl@0: foo sl@0: } 0 sl@0: test stringComp-5.17 {string index, bad integer} { sl@0: proc foo {} {string index "abc" 08} sl@0: list [catch {foo} msg] $msg sl@0: } {1 {bad index "08": must be integer or end?-integer? (looks like invalid octal number)}} sl@0: test stringComp-5.18 {string index, bad integer} { sl@0: proc foo {} {string index "abc" end-00289} sl@0: list [catch {foo} msg] $msg sl@0: } {1 {bad index "end-00289": must be integer or end?-integer? (looks like invalid octal number)}} sl@0: test stringComp-5.19 {string index, bytearray object out of bounds} { sl@0: proc foo {} {string index [binary format I* {0x50515253 0x52}] -1} sl@0: foo sl@0: } {} sl@0: test stringComp-5.20 {string index, bytearray object out of bounds} { sl@0: proc foo {} {string index [binary format I* {0x50515253 0x52}] 20} sl@0: foo sl@0: } {} sl@0: sl@0: sl@0: proc largest_int {} { sl@0: # This will give us what the largest valid int on this machine is, sl@0: # so we can test for overflow properly below on >32 bit systems sl@0: set int 1 sl@0: set exp 7; # assume we get at least 8 bits sl@0: while {$int > 0} { set int [expr {1 << [incr exp]}] } sl@0: return [expr {$int-1}] sl@0: } sl@0: sl@0: ## string is sl@0: ## not yet bc sl@0: sl@0: catch {rename largest_int {}} sl@0: sl@0: ## string last sl@0: ## not yet bc sl@0: sl@0: ## string length sl@0: ## not yet bc sl@0: test stringComp-8.1 {string bytelength} { sl@0: proc foo {} {string bytelength} sl@0: list [catch {foo} msg] $msg sl@0: } {1 {wrong # args: should be "string bytelength string"}} sl@0: test stringComp-8.2 {string bytelength} { sl@0: proc foo {} {string bytelength a b} sl@0: list [catch {foo} msg] $msg sl@0: } {1 {wrong # args: should be "string bytelength string"}} sl@0: test stringComp-8.3 {string bytelength} { sl@0: proc foo {} {string bytelength "\u00c7"} sl@0: foo sl@0: } 2 sl@0: test stringComp-8.4 {string bytelength} { sl@0: proc foo {} {string b ""} sl@0: foo sl@0: } 0 sl@0: sl@0: ## string length sl@0: ## sl@0: test stringComp-9.1 {string length} { sl@0: proc foo {} {string length} sl@0: list [catch {foo} msg] $msg sl@0: } {1 {wrong # args: should be "string length string"}} sl@0: test stringComp-9.2 {string length} { sl@0: proc foo {} {string length a b} sl@0: list [catch {foo} msg] $msg sl@0: } {1 {wrong # args: should be "string length string"}} sl@0: test stringComp-9.3 {string length} { sl@0: proc foo {} {string length "a little string"} sl@0: foo sl@0: } 15 sl@0: test stringComp-9.4 {string length} { sl@0: proc foo {} {string le ""} sl@0: foo sl@0: } 0 sl@0: test stringComp-9.5 {string length, unicode} { sl@0: proc foo {} {string le "abcd\u7266"} sl@0: foo sl@0: } 5 sl@0: test stringComp-9.6 {string length, bytearray object} { sl@0: proc foo {} {string length [binary format a5 foo]} sl@0: foo sl@0: } 5 sl@0: test stringComp-9.7 {string length, bytearray object} { sl@0: proc foo {} {string length [binary format I* {0x50515253 0x52}]} sl@0: foo sl@0: } 8 sl@0: sl@0: ## string map sl@0: ## not yet bc sl@0: sl@0: ## string match sl@0: ## sl@0: test stringComp-11.1 {string match, too few args} { sl@0: proc foo {} {string match a} sl@0: list [catch {foo} msg] $msg sl@0: } {1 {wrong # args: should be "string match ?-nocase? pattern string"}} sl@0: test stringComp-11.2 {string match, too many args} { sl@0: proc foo {} {string match a b c d} sl@0: list [catch {foo} msg] $msg sl@0: } {1 {wrong # args: should be "string match ?-nocase? pattern string"}} sl@0: test stringComp-11.3 {string match} { sl@0: proc foo {} {string match abc abc} sl@0: foo sl@0: } 1 sl@0: test stringComp-11.4 {string match} { sl@0: proc foo {} {string mat abc abd} sl@0: foo sl@0: } 0 sl@0: test stringComp-11.5 {string match} { sl@0: proc foo {} {string match ab*c abc} sl@0: foo sl@0: } 1 sl@0: test stringComp-11.6 {string match} { sl@0: proc foo {} {string match ab**c abc} sl@0: foo sl@0: } 1 sl@0: test stringComp-11.7 {string match} { sl@0: proc foo {} {string match ab* abcdef} sl@0: foo sl@0: } 1 sl@0: test stringComp-11.8 {string match} { sl@0: proc foo {} {string match *c abc} sl@0: foo sl@0: } 1 sl@0: test stringComp-11.9 {string match} { sl@0: proc foo {} {string match *3*6*9 0123456789} sl@0: foo sl@0: } 1 sl@0: test stringComp-11.10 {string match} { sl@0: proc foo {} {string match *3*6*9 01234567890} sl@0: foo sl@0: } 0 sl@0: test stringComp-11.11 {string match} { sl@0: proc foo {} {string match a?c abc} sl@0: foo sl@0: } 1 sl@0: test stringComp-11.12 {string match} { sl@0: proc foo {} {string match a??c abc} sl@0: foo sl@0: } 0 sl@0: test stringComp-11.13 {string match} { sl@0: proc foo {} {string match ?1??4???8? 0123456789} sl@0: foo sl@0: } 1 sl@0: test stringComp-11.14 {string match} { sl@0: proc foo {} {string match {[abc]bc} abc} sl@0: foo sl@0: } 1 sl@0: test stringComp-11.15 {string match} { sl@0: proc foo {} {string match {a[abc]c} abc} sl@0: foo sl@0: } 1 sl@0: test stringComp-11.16 {string match} { sl@0: proc foo {} {string match {a[xyz]c} abc} sl@0: foo sl@0: } 0 sl@0: test stringComp-11.17 {string match} { sl@0: proc foo {} {string match {12[2-7]45} 12345} sl@0: foo sl@0: } 1 sl@0: test stringComp-11.18 {string match} { sl@0: proc foo {} {string match {12[ab2-4cd]45} 12345} sl@0: foo sl@0: } 1 sl@0: test stringComp-11.19 {string match} { sl@0: proc foo {} {string match {12[ab2-4cd]45} 12b45} sl@0: foo sl@0: } 1 sl@0: test stringComp-11.20 {string match} { sl@0: proc foo {} {string match {12[ab2-4cd]45} 12d45} sl@0: foo sl@0: } 1 sl@0: test stringComp-11.21 {string match} { sl@0: proc foo {} {string match {12[ab2-4cd]45} 12145} sl@0: foo sl@0: } 0 sl@0: test stringComp-11.22 {string match} { sl@0: proc foo {} {string match {12[ab2-4cd]45} 12545} sl@0: foo sl@0: } 0 sl@0: test stringComp-11.23 {string match} { sl@0: proc foo {} {string match {a\*b} a*b} sl@0: foo sl@0: } 1 sl@0: test stringComp-11.24 {string match} { sl@0: proc foo {} {string match {a\*b} ab} sl@0: foo sl@0: } 0 sl@0: test stringComp-11.25 {string match} { sl@0: proc foo {} {string match {a\*\?\[\]\\\x} "a*?\[\]\\x"} sl@0: foo sl@0: } 1 sl@0: test stringComp-11.26 {string match} { sl@0: proc foo {} {string match ** ""} sl@0: foo sl@0: } 1 sl@0: test stringComp-11.27 {string match} { sl@0: proc foo {} {string match *. ""} sl@0: foo sl@0: } 0 sl@0: test stringComp-11.28 {string match} { sl@0: proc foo {} {string match "" ""} sl@0: foo sl@0: } 1 sl@0: test stringComp-11.29 {string match} { sl@0: proc foo {} {string match \[a a} sl@0: foo sl@0: } 1 sl@0: test stringComp-11.30 {string match, bad args} { sl@0: proc foo {} {string match - b c} sl@0: list [catch {foo} msg] $msg sl@0: } {1 {bad option "-": must be -nocase}} sl@0: test stringComp-11.31 {string match case} { sl@0: proc foo {} {string match a A} sl@0: foo sl@0: } 0 sl@0: test stringComp-11.32 {string match nocase} { sl@0: proc foo {} {string match -n a A} sl@0: foo sl@0: } 1 sl@0: test stringComp-11.33 {string match nocase} { sl@0: proc foo {} {string match -nocase a\334 A\374} sl@0: foo sl@0: } 1 sl@0: test stringComp-11.34 {string match nocase} { sl@0: proc foo {} {string match -nocase a*f ABCDEf} sl@0: foo sl@0: } 1 sl@0: test stringComp-11.35 {string match case, false hope} { sl@0: # This is true because '_' lies between the A-Z and a-z ranges sl@0: proc foo {} {string match {[A-z]} _} sl@0: foo sl@0: } 1 sl@0: test stringComp-11.36 {string match nocase range} { sl@0: # This is false because although '_' lies between the A-Z and a-z ranges, sl@0: # we lower case the end points before checking the ranges. sl@0: proc foo {} {string match -nocase {[A-z]} _} sl@0: foo sl@0: } 0 sl@0: test stringComp-11.37 {string match nocase} { sl@0: proc foo {} {string match -nocase {[A-fh-Z]} g} sl@0: foo sl@0: } 0 sl@0: test stringComp-11.38 {string match case, reverse range} { sl@0: proc foo {} {string match {[A-fh-Z]} g} sl@0: foo sl@0: } 1 sl@0: test stringComp-11.39 {string match, *\ case} { sl@0: proc foo {} {string match {*\abc} abc} sl@0: foo sl@0: } 1 sl@0: test stringComp-11.40 {string match, *special case} { sl@0: proc foo {} {string match {*[ab]} abc} sl@0: foo sl@0: } 0 sl@0: test stringComp-11.41 {string match, *special case} { sl@0: proc foo {} {string match {*[ab]*} abc} sl@0: foo sl@0: } 1 sl@0: test stringComp-11.42 {string match, *special case} { sl@0: proc foo {} {string match "*\\" "\\"} sl@0: foo sl@0: } 0 sl@0: test stringComp-11.43 {string match, *special case} { sl@0: proc foo {} {string match "*\\\\" "\\"} sl@0: foo sl@0: } 1 sl@0: test stringComp-11.44 {string match, *special case} { sl@0: proc foo {} {string match "*???" "12345"} sl@0: foo sl@0: } 1 sl@0: test stringComp-11.45 {string match, *special case} { sl@0: proc foo {} {string match "*???" "12"} sl@0: foo sl@0: } 0 sl@0: test stringComp-11.46 {string match, *special case} { sl@0: proc foo {} {string match "*\\*" "abc*"} sl@0: foo sl@0: } 1 sl@0: test stringComp-11.47 {string match, *special case} { sl@0: proc foo {} {string match "*\\*" "*"} sl@0: foo sl@0: } 1 sl@0: test stringComp-11.48 {string match, *special case} { sl@0: proc foo {} {string match "*\\*" "*abc"} sl@0: foo sl@0: } 0 sl@0: test stringComp-11.49 {string match, *special case} { sl@0: proc foo {} {string match "?\\*" "a*"} sl@0: foo sl@0: } 1 sl@0: test stringComp-11.50 {string match, *special case} { sl@0: proc foo {} {string match "\\" "\\"} sl@0: foo sl@0: } 0 sl@0: test stringComp-11.51 {string match; *, -nocase and UTF-8} { sl@0: proc foo {} {string match -nocase [binary format I 717316707] \ sl@0: [binary format I 2028036707]} sl@0: foo sl@0: } 1 sl@0: test stringComp-11.52 {string match, null char in string} { sl@0: proc foo {} { sl@0: set ptn "*abc*" sl@0: foreach elem [list "\u0000@abc" "@abc" "\u0000@abc\u0000" "blahabcblah"] { sl@0: lappend out [string match $ptn $elem] sl@0: } sl@0: set out sl@0: } sl@0: foo sl@0: } {1 1 1 1} sl@0: test stringComp-11.53 {string match, null char in pattern} { sl@0: proc foo {} { sl@0: set out "" sl@0: foreach {ptn elem} [list \ sl@0: "*\u0000abc\u0000" "\u0000abc\u0000" \ sl@0: "*\u0000abc\u0000" "\u0000abc\u0000ef" \ sl@0: "*\u0000abc\u0000*" "\u0000abc\u0000ef" \ sl@0: "*\u0000abc\u0000" "@\u0000abc\u0000ef" \ sl@0: "*\u0000abc\u0000*" "@\u0000abc\u0000ef" \ sl@0: ] { sl@0: lappend out [string match $ptn $elem] sl@0: } sl@0: set out sl@0: } sl@0: foo sl@0: } {1 0 1 0 1} sl@0: test stringComp-11.54 {string match, failure} { sl@0: proc foo {} { sl@0: set longString "" sl@0: for {set i 0} {$i < 10} {incr i} { sl@0: append longString "abcdefghijklmnopqrstuvwxy\u0000z01234567890123" sl@0: } sl@0: list [string match *cba* $longString] \ sl@0: [string match *a*l*\u0000* $longString] \ sl@0: [string match *a*l*\u0000*123 $longString] \ sl@0: [string match *a*l*\u0000*123* $longString] \ sl@0: [string match *a*l*\u0000*cba* $longString] \ sl@0: [string match *===* $longString] sl@0: } sl@0: foo sl@0: } {0 1 1 1 0 0} sl@0: sl@0: ## string range sl@0: ## not yet bc sl@0: sl@0: ## string repeat sl@0: ## not yet bc sl@0: sl@0: ## string replace sl@0: ## not yet bc sl@0: sl@0: ## string tolower sl@0: ## not yet bc sl@0: sl@0: ## string toupper sl@0: ## not yet bc sl@0: sl@0: ## string totitle sl@0: ## not yet bc sl@0: sl@0: ## string trim* sl@0: ## not yet bc sl@0: sl@0: ## string word* sl@0: ## not yet bc sl@0: sl@0: # cleanup sl@0: ::tcltest::cleanupTests sl@0: return