summaryrefslogtreecommitdiffstats
path: root/tests/string.test
diff options
context:
space:
mode:
Diffstat (limited to 'tests/string.test')
-rw-r--r--tests/string.test544
1 files changed, 487 insertions, 57 deletions
diff --git a/tests/string.test b/tests/string.test
index b869206..7a7a749 100644
--- a/tests/string.test
+++ b/tests/string.test
@@ -7,11 +7,10 @@
# Copyright (c) 1991-1993 The Regents of the University of California.
# Copyright (c) 1994 Sun Microsystems, Inc.
# Copyright (c) 1998-1999 by Scriptics Corporation.
+# Copyright (c) 2001 by Kevin B. Kenny. All rights reserved.
#
# See the file "license.terms" for information on usage and redistribution
# of this file, and for a DISCLAIMER OF ALL WARRANTIES.
-#
-# RCS: @(#) $Id: string.test,v 1.29 2001/05/14 08:57:26 dkf Exp $
if {[lsearch [namespace children] ::tcltest] == -1} {
package require tcltest
@@ -20,15 +19,15 @@ if {[lsearch [namespace children] ::tcltest] == -1} {
# Some tests require the testobj command
-set ::tcltest::testConstraints(testobj) \
- [expr {[info commands testobj] != {}}]
+testConstraint testobj [expr {[info commands testobj] != {}}]
+testConstraint testindexobj [expr {[info commands testindexobj] != {}}]
test string-1.1 {error conditions} {
list [catch {string gorp a b} msg] $msg
-} {1 {bad option "gorp": must be bytelength, compare, equal, first, index, is, last, length, map, match, range, repeat, replace, tolower, toupper, totitle, trim, trimleft, trimright, wordend, or wordstart}}
+} {1 {unknown or ambiguous subcommand "gorp": must be bytelength, compare, equal, first, index, is, last, length, map, match, range, repeat, replace, reverse, tolower, totitle, toupper, trim, trimleft, trimright, wordend, or wordstart}}
test string-1.2 {error conditions} {
list [catch {string} msg] $msg
-} {1 {wrong # args: should be "string option arg ?arg ...?"}}
+} {1 {wrong # args: should be "string subcommand ?argument ...?"}}
test string-2.1 {string compare, too few args} {
list [catch {string compare a} msg] $msg
@@ -130,6 +129,18 @@ test string-2.30 {string compare with NUL character vs. other ASCII} {
# these puts chars in the wrong order
string compare \x00 \x01
} -1
+test string-2.31 {string compare, high bit} {
+ proc foo {} {string compare "a\x80" "a@"}
+ foo
+} 1
+test string-2.32 {string compare, high bit} {
+ proc foo {} {string compare "a\x00" "a\x01"}
+ foo
+} -1
+test string-2.33 {string compare, high bit} {
+ proc foo {} {string compare "\x00\x00" "\x00\x01"}
+ foo
+} -1
# only need a few tests on equal, since it uses the same code as
# string compare, but just modifies the return output
@@ -160,13 +171,13 @@ test string-3.8 {string equal with length, unequal strings} {
test string-4.1 {string first, too few args} {
list [catch {string first a} msg] $msg
-} {1 {wrong # args: should be "string first subString string ?startIndex?"}}
+} {1 {wrong # args: should be "string first needleString haystackString ?startIndex?"}}
test string-4.2 {string first, bad args} {
list [catch {string first a b c} msg] $msg
-} {1 {bad index "c": must be integer or end?-integer?}}
+} {1 {bad index "c": must be integer?[+-]integer? or end?[+-]integer?}}
test string-4.3 {string first, too many args} {
list [catch {string first a b 5 d} msg] $msg
-} {1 {wrong # args: should be "string first subString string ?startIndex?"}}
+} {1 {wrong # args: should be "string first needleString haystackString ?startIndex?"}}
test string-4.4 {string first} {
string first bq abcdefgbcefgbqrs
} 12
@@ -200,6 +211,13 @@ test string-4.13 {string first, start index} {
test string-4.14 {string first, negative start index} {
string first b abc -1
} 1
+test string-4.15 {string first, ability to two-byte encoded utf-8 chars} {
+ # Test for a bug in Tcl 8.3 where test for all-single-byte-encoded
+ # strings was incorrect, leading to an index returned by [string first]
+ # which pointed past the end of the string.
+ set uchar \u057e ;# character with two-byte encoding in utf-8
+ string first % %#$uchar$uchar#$uchar$uchar#% 3
+} 8
test string-5.1 {string index} {
list [catch {string index} msg] $msg
@@ -221,7 +239,7 @@ test string-5.6 {string index} {
} {0 {}}
test string-5.7 {string index} {
list [catch {string index a xyz} msg] $msg
-} {1 {bad index "xyz": must be integer or end?-integer?}}
+} {1 {bad index "xyz": must be integer?[+-]integer? or end?[+-]integer?}}
test string-5.8 {string index} {
string index abc end
} c
@@ -254,12 +272,12 @@ test string-5.16 {string index, bytearray object with string obj shimmering} {
binary scan $str H* dump
string compare [string index $str 10] \x00
} 0
-test string-5.17 {string index, bad integer} {
- list [catch {string index "abc" 08} msg] $msg
-} {1 {bad index "08": must be integer or end?-integer? (looks like invalid octal number)}}
-test string-5.18 {string index, bad integer} {
- list [catch {string index "abc" end-00289} msg] $msg
-} {1 {expected integer but got "-00289" (looks like invalid octal number)}}
+test string-5.17 {string index, bad integer} -body {
+ list [catch {string index "abc" 0o8} msg] $msg
+} -match glob -result {1 {*invalid octal number*}}
+test string-5.18 {string index, bad integer} -body {
+ list [catch {string index "abc" end-0o0289} msg] $msg
+} -match glob -result {1 {*invalid octal number*}}
test string-5.19 {string index, bytearray object out of bounds} {
string index [binary format I* {0x50515253 0x52}] -1
} {}
@@ -273,7 +291,7 @@ proc largest_int {} {
# so we can test for overflow properly below on >32 bit systems
set int 1
set exp 7; # assume we get at least 8 bits
- while {$int > 0} { set int [expr {1 << [incr exp]}] }
+ while {wide($int) > 0} { set int [expr {wide(1) << [incr exp]}] }
return [expr {$int-1}]
}
@@ -291,10 +309,10 @@ test string-6.4 {string is, too many args} {
} {1 {wrong # args: should be "string is class ?-strict? ?-failindex var? str"}}
test string-6.5 {string is, class check} {
list [catch {string is bogus str} msg] $msg
-} {1 {bad class "bogus": must be alnum, alpha, ascii, control, boolean, digit, double, false, graph, integer, lower, print, punct, space, true, upper, wordchar, or xdigit}}
+} {1 {bad class "bogus": must be alnum, alpha, ascii, control, boolean, digit, double, false, graph, integer, list, lower, print, punct, space, true, upper, wideinteger, wordchar, or xdigit}}
test string-6.6 {string is, ambiguous class} {
list [catch {string is al str} msg] $msg
-} {1 {ambiguous class "al": must be alnum, alpha, ascii, control, boolean, digit, double, false, graph, integer, lower, print, punct, space, true, upper, wordchar, or xdigit}}
+} {1 {ambiguous class "al": must be alnum, alpha, ascii, control, boolean, digit, double, false, graph, integer, list, lower, print, punct, space, true, upper, wideinteger, wordchar, or xdigit}}
test string-6.7 {string is alpha, all ok} {
string is alpha -strict -failindex var abc
} 1
@@ -318,7 +336,7 @@ test string-6.13 {string is alnum, false} {
list [string is alnum -failindex var abc1.23] $var
} {0 4}
test string-6.14 {string is alnum, unicode} {
- string is alnum abcü
+ string is alnum abc\u00fc
} 1
test string-6.15 {string is alpha, true} {
string is alpha abc
@@ -330,11 +348,11 @@ test string-6.17 {string is alpha, unicode} {
string is alpha abc\374
} 1
test string-6.18 {string is ascii, true} {
- string is ascii abc\u007Fend
+ string is ascii abc\u007Fend\u0000
} 1
test string-6.19 {string is ascii, false} {
- list [string is ascii -fail var abcdef\u0080more] $var
-} {0 6}
+ list [string is ascii -fail var abc\u0000def\u0080more] $var
+} {0 7}
test string-6.20 {string is boolean, true} {
string is boolean true
} 1
@@ -351,7 +369,7 @@ test string-6.24 {string is digit, true} {
string is digit 0123456789
} 1
test string-6.25 {string is digit, false} {
- list [string is digit -fail var 0123Ü567] $var
+ list [string is digit -fail var 0123\u00dc567] $var
} {0 4}
test string-6.26 {string is digit, false} {
list [string is digit -fail var +123567] $var
@@ -386,18 +404,22 @@ test string-6.35 {string is double, false} {
test string-6.36 {string is double, false} {
list [string is double -fail var "\n"] $var
} {0 0}
-test string-6.37 {string is double, false on int overflow} {
+test string-6.37 {string is double, false on int overflow} -setup {
+ set var priorValue
+} -body {
# Make it the largest int recognizable, with one more digit for overflow
+ # Since bignums arrived in Tcl 8.5, the sense of this test changed.
+ # Now integer values that exceed native limits become bignums, and
+ # bignums can convert to doubles without error.
list [string is double -fail var [largest_int]0] $var
-} {0 -1}
-test string-6.38 {string is double, false on underflow} {
- catch {unset var}
- list [string is double -fail var 123e-9999] $var
-} {0 -1}
-test string-6.39 {string is double, false} {nonPortable} {
+} -result {1 priorValue}
+# string-6.38 removed, underflow on input is no longer an error.
+test string-6.39 {string is double, false} {
# This test is non-portable because IRIX thinks
# that .e1 is a valid double - this is really a bug
# on IRIX as .e1 should NOT be a valid double
+ #
+ # Portable now. Tcl 8.5 does its own double parsing.
list [string is double -fail var .e1] $var
} {0 0}
@@ -458,8 +480,11 @@ test string-6.57 {string is integer, false} {
list [string is integer -fail var " "] $var
} {0 0}
test string-6.58 {string is integer, false on bad octal} {
- list [string is integer -fail var 036963] $var
-} {0 3}
+ list [string is integer -fail var 0o36963] $var
+} {0 4}
+test string-6.58.1 {string is integer, false on bad octal} {
+ list [string is integer -fail var 0o36963] $var
+} {0 4}
test string-6.59 {string is integer, false on bad hex} {
list [string is integer -fail var 0X345XYZ] $var
} {0 5}
@@ -467,7 +492,7 @@ test string-6.60 {string is lower, true} {
string is lower abc
} 1
test string-6.61 {string is lower, unicode true} {
- string is lower abcüue
+ string is lower abc\u00fcue
} 1
test string-6.62 {string is lower, false} {
list [string is lower -fail var aBc] $var
@@ -476,7 +501,7 @@ test string-6.63 {string is lower, false} {
list [string is lower -fail var abc1] $var
} {0 3}
test string-6.64 {string is lower, unicode false} {
- list [string is lower -fail var abÜUE] $var
+ list [string is lower -fail var ab\u00dcUE] $var
} {0 2}
test string-6.65 {string is space, true} {
string is space " \t\n\v\f"
@@ -514,7 +539,7 @@ test string-6.75 {string is upper, true} {
string is upper ABC
} 1
test string-6.76 {string is upper, unicode true} {
- string is upper ABCÜUE
+ string is upper ABC\u00dcUE
} 1
test string-6.77 {string is upper, false} {
list [string is upper -fail var AbC] $var
@@ -523,13 +548,13 @@ test string-6.78 {string is upper, false} {
list [string is upper -fail var AB2C] $var
} {0 2}
test string-6.79 {string is upper, unicode false} {
- list [string is upper -fail var ABCüue] $var
+ list [string is upper -fail var ABC\u00fcue] $var
} {0 3}
test string-6.80 {string is wordchar, true} {
string is wordchar abc_123
} 1
test string-6.81 {string is wordchar, unicode true} {
- string is wordchar abcüabÜAB\u5001
+ string is wordchar abc\u00fcab\u00dcAB\u5001
} 1
test string-6.82 {string is wordchar, false} {
list [string is wordchar -fail var abcd.ef] $var
@@ -561,17 +586,107 @@ test string-6.89 {string is xdigit} {
list [string is xdigit -fail var 0123456789\u0061bcdefABCDEFg] $var
} {0 22}
+test string-6.90 {string is integer, bad integers} {
+ # SF bug #634856
+ set result ""
+ set numbers [list 1 +1 ++1 +-1 -+1 -1 --1 "- +1"]
+ foreach num $numbers {
+ lappend result [string is int -strict $num]
+ }
+ set result
+} {1 1 0 0 0 1 0 0}
+test string-6.91 {string is double, bad doubles} {
+ set result ""
+ set numbers [list 1.0 +1.0 ++1.0 +-1.0 -+1.0 -1.0 --1.0 "- +1.0"]
+ foreach num $numbers {
+ lappend result [string is double -strict $num]
+ }
+ set result
+} {1 1 0 0 0 1 0 0}
+test string-6.92 {string is integer, 32-bit overflow} {
+ # Bug 718878
+ set x 0x100000000
+ list [string is integer -failindex var $x] $var
+} {0 -1}
+test string-6.93 {string is integer, 32-bit overflow} {
+ # Bug 718878
+ set x 0x100000000
+ append x ""
+ list [string is integer -failindex var $x] $var
+} {0 -1}
+test string-6.94 {string is integer, 32-bit overflow} {
+ # Bug 718878
+ set x 0x100000000
+ list [string is integer -failindex var [expr {$x}]] $var
+} {0 -1}
+test string-6.95 {string is wideinteger, true} {
+ string is wideinteger +1234567890
+} 1
+test string-6.96 {string is wideinteger, true on type} {
+ string is wideinteger [expr wide(50.0)]
+} 1
+test string-6.97 {string is wideinteger, true} {
+ string is wideinteger [list -10]
+} 1
+test string-6.98 {string is wideinteger, true as hex} {
+ string is wideinteger 0xabcdef
+} 1
+test string-6.99 {string is wideinteger, true as octal} {
+ string is wideinteger 0123456
+} 1
+test string-6.100 {string is wideinteger, true with whitespace} {
+ string is wideinteger " \n1234\v"
+} 1
+test string-6.101 {string is wideinteger, false} {
+ list [string is wideinteger -fail var 123abc] $var
+} {0 3}
+test string-6.102 {string is wideinteger, false on overflow} {
+ list [string is wideinteger -fail var +[largest_int]0] $var
+} {0 -1}
+test string-6.103 {string is wideinteger, false} {
+ list [string is wideinteger -fail var [expr double(1)]] $var
+} {0 1}
+test string-6.104 {string is wideinteger, false} {
+ list [string is wideinteger -fail var " "] $var
+} {0 0}
+test string-6.105 {string is wideinteger, false on bad octal} {
+ list [string is wideinteger -fail var 0o36963] $var
+} {0 4}
+test string-6.105.1 {string is wideinteger, false on bad octal} {
+ list [string is wideinteger -fail var 0o36963] $var
+} {0 4}
+test string-6.106 {string is wideinteger, false on bad hex} {
+ list [string is wideinteger -fail var 0X345XYZ] $var
+} {0 5}
+test string-6.107 {string is integer, bad integers} {
+ # SF bug #634856
+ set result ""
+ set numbers [list 1 +1 ++1 +-1 -+1 -1 --1 "- +1"]
+ foreach num $numbers {
+ lappend result [string is wideinteger -strict $num]
+ }
+ set result
+} {1 1 0 0 0 1 0 0}
+test string-6.108 {string is double, Bug 1382287} {
+ set x 2turtledoves
+ string is double $x
+ string is double $x
+} 0
+test string-6.109 {string is double, Bug 1360532} {
+ string is double 1\u00a0
+} 0
+
catch {rename largest_int {}}
test string-7.1 {string last, too few args} {
list [catch {string last a} msg] $msg
-} {1 {wrong # args: should be "string last subString string ?startIndex?"}}
+} {1 {wrong # args: should be "string last needleString haystackString ?startIndex?"}}
test string-7.2 {string last, bad args} {
list [catch {string last a b c} msg] $msg
-} {1 {bad index "c": must be integer or end?-integer?}}
+} {1 {bad index "c": must be integer?[+-]integer? or end?[+-]integer?}}
test string-7.3 {string last, too many args} {
list [catch {string last a b c d} msg] $msg
-} {1 {wrong # args: should be "string last subString string ?startIndex?"}}
+} {1 {wrong # args: should be "string last needleString haystackString ?startIndex?"}}
test string-7.4 {string last} {
string la xxx xxxx123xx345x678
} 1
@@ -700,6 +815,50 @@ test string-10.16 {string map, one pair case} {
test string-10.17 {string map, one pair case} {
string map {Ab 4321} aAbCaBaAbAbcAb
} {a4321CaBa43214321c4321}
+test string-10.18 {string map, empty argument} {
+ string map -nocase {{} abc} foo
+} foo
+test string-10.19 {string map, empty arguments} {
+ string map -nocase {{} abc f bar {} def} foo
+} baroo
+test string-10.20 {string map, dictionaries don't alter map ordering} {
+ set map {aa X a Y}
+ list [string map [dict create aa X a Y] aaa] [string map $map aaa] [dict size $map] [string map $map aaa]
+} {XY XY 2 XY}
+test string-10.21 {string map, ABR checks} {
+ string map {longstring foob} long
+} long
+test string-10.22 {string map, ABR checks} {
+ string map {long foob} long
+} foob
+test string-10.23 {string map, ABR checks} {
+ string map {lon foob} long
+} foobg
+test string-10.24 {string map, ABR checks} {
+ string map {lon foob} longlo
+} foobglo
+test string-10.25 {string map, ABR checks} {
+ string map {lon foob} longlon
+} foobgfoob
+test string-10.26 {string map, ABR checks} {
+ string map {longstring foob longstring bar} long
+} long
+test string-10.27 {string map, ABR checks} {
+ string map {long foob longstring bar} long
+} foob
+test string-10.28 {string map, ABR checks} {
+ string map {lon foob longstring bar} long
+} foobg
+test string-10.29 {string map, ABR checks} {
+ string map {lon foob longstring bar} longlo
+} foobglo
+test string-10.30 {string map, ABR checks} {
+ string map {lon foob longstring bar} longlon
+} foobgfoob
+test string-10.31 {string map, nasty sharing crash from [Bug 1018562]} {
+ set a {a b}
+ string map $a $a
+} {b b}
test string-11.1 {string match, too few args} {
list [catch {string match a} msg] $msg
@@ -728,9 +887,54 @@ test string-11.8 {string match} {
test string-11.9 {string match} {
string match *3*6*9 0123456789
} 1
+test string-11.9.1 {string match} {
+ string match *3*6*89 0123456789
+} 1
+test string-11.9.2 {string match} {
+ string match *3*456*89 0123456789
+} 1
+test string-11.9.3 {string match} {
+ string match *3*6* 0123456789
+} 1
+test string-11.9.4 {string match} {
+ string match *3*56* 0123456789
+} 1
+test string-11.9.5 {string match} {
+ string match *3*456*** 0123456789
+} 1
+test string-11.9.6 {string match} {
+ string match **3*456** 0123456789
+} 1
+test string-11.9.7 {string match} {
+ string match *3***456* 0123456789
+} 1
+test string-11.9.8 {string match} {
+ string match *3***\[456]* 0123456789
+} 1
+test string-11.9.9 {string match} {
+ string match *3***\[4-6]* 0123456789
+} 1
+test string-11.9.10 {string match} {
+ string match *3***\[4-6] 0123456789
+} 0
+test string-11.9.11 {string match} {
+ string match *3***\[4-6] 0123456
+} 1
test string-11.10 {string match} {
string match *3*6*9 01234567890
} 0
+test string-11.10.1 {string match} {
+ string match *3*6*89 01234567890
+} 0
+test string-11.10.2 {string match} {
+ string match *3*456*89 01234567890
+} 0
+test string-11.10.3 {string match} {
+ string match **3*456*89 01234567890
+} 0
+test string-11.10.4 {string match} {
+ string match *3*456***89 01234567890
+} 0
test string-11.11 {string match} {
string match a?c abc
} 1
@@ -821,6 +1025,21 @@ test string-11.38 {string match case, reverse range} {
test string-11.39 {string match, *\ case} {
string match {*\abc} abc
} 1
+test string-11.39.1 {string match, *\ case} {
+ string match {*ab\c} abc
+} 1
+test string-11.39.2 {string match, *\ case} {
+ string match {*ab\*} ab*
+} 1
+test string-11.39.3 {string match, *\ case} {
+ string match {*ab\*} abc
+} 0
+test string-11.39.4 {string match, *\ case} {
+ string match {*ab\\*} {ab\c}
+} 1
+test string-11.39.5 {string match, *\ case} {
+ string match {*ab\\*} {ab\*}
+} 1
test string-11.40 {string match, *special case} {
string match {*[ab]} abc
} 0
@@ -854,7 +1073,44 @@ test string-11.49 {string match, *special case} {
test string-11.50 {string match, *special case} {
string match "\\" "\\"
} 0
-
+test string-11.51 {string match; *, -nocase and UTF-8} {
+ string match -nocase [binary format I 717316707] \
+ [binary format I 2028036707]
+} 1
+test string-11.52 {string match, null char in string} {
+ set out ""
+ set ptn "*abc*"
+ foreach elem [list "\u0000@abc" "@abc" "\u0000@abc\u0000" "blahabcblah"] {
+ lappend out [string match $ptn $elem]
+ }
+ set out
+} {1 1 1 1}
+test string-11.53 {string match, null char in pattern} {
+ set out ""
+ foreach {ptn elem} [list \
+ "*\u0000abc\u0000" "\u0000abc\u0000" \
+ "*\u0000abc\u0000" "\u0000abc\u0000ef" \
+ "*\u0000abc\u0000*" "\u0000abc\u0000ef" \
+ "*\u0000abc\u0000" "@\u0000abc\u0000ef" \
+ "*\u0000abc\u0000*" "@\u0000abc\u0000ef" \
+ ] {
+ lappend out [string match $ptn $elem]
+ }
+ set out
+} {1 0 1 0 1}
+test string-11.54 {string match, failure} {
+ set longString ""
+ for {set i 0} {$i < 10} {incr i} {
+ append longString "abcdefghijklmnopqrstuvwxy\u0000z01234567890123"
+ }
+ string first $longString 123
+ list [string match *cba* $longString] \
+ [string match *a*l*\u0000* $longString] \
+ [string match *a*l*\u0000*123 $longString] \
+ [string match *a*l*\u0000*123* $longString] \
+ [string match *a*l*\u0000*cba* $longString] \
+ [string match *===* $longString]
+} {0 1 1 1 0 0}
test string-12.1 {string range} {
list [catch {string range} msg] $msg
@@ -872,7 +1128,7 @@ test string-12.5 {string range, last > length} {
string range abcdefghijklmnop 7 1000
} {hijklmnop}
test string-12.6 {string range} {
- string range abcdefghijklmnop 10 e
+ string range abcdefghijklmnop 10 end
} {klmnop}
test string-12.7 {string range, last < first} {
string range abcdefghijklmnop 10 9
@@ -891,15 +1147,15 @@ test string-12.11 {string range} {
} {abcdefghijklmnop}
test string-12.12 {string range} {
list [catch {string range abc abc 1} msg] $msg
-} {1 {bad index "abc": must be integer or end?-integer?}}
+} {1 {bad index "abc": must be integer?[+-]integer? or end?[+-]integer?}}
test string-12.13 {string range} {
list [catch {string range abc 1 eof} msg] $msg
-} {1 {bad index "eof": must be integer or end?-integer?}}
+} {1 {bad index "eof": must be integer?[+-]integer? or end?[+-]integer?}}
test string-12.14 {string range} {
string range abcdefghijklmnop end-1 end
} {op}
test string-12.15 {string range} {
- string range abcdefghijklmnop e 1000
+ string range abcdefghijklmnop end 1000
} {p}
test string-12.16 {string range} {
string range abcdefghijklmnop end end-1
@@ -919,6 +1175,27 @@ test string-12.19 {string range, bytearray object} {
test string-12.20 {string range, out of bounds indices} {
string range \u00ff 0 1
} \u00ff
+# Bug 1410553
+test string-12.21 {string range, regenerates correct reps, bug 1410553} {
+ set bytes "\x00 \x03 \x41"
+ set rxBuffer {}
+ foreach ch $bytes {
+ append rxBuffer $ch
+ if {$ch eq "\x03"} {
+ string length $rxBuffer
+ }
+ }
+ set rxCRC [string range $rxBuffer end-1 end]
+ binary scan [join $bytes {}] "H*" input_hex
+ binary scan $rxBuffer "H*" rxBuffer_hex
+ binary scan $rxCRC "H*" rxCRC_hex
+ list $input_hex $rxBuffer_hex $rxCRC_hex
+} {000341 000341 0341}
+test string-12.22 {string range, shimmering binary/index} {
+ set s 0000000001
+ binary scan $s a* x
+ string range $s $s end
+} 000000001
test string-13.1 {string repeat} {
list [catch {string repeat} msg] $msg
@@ -982,7 +1259,7 @@ test string-14.6 {string replace} {
string replace abcdefghijklmnop 7 1000
} {abcdefg}
test string-14.7 {string replace} {
- string replace abcdefghijklmnop 10 e
+ string replace abcdefghijklmnop 10 end
} {abcdefghij}
test string-14.8 {string replace} {
string replace abcdefghijklmnop 10 9
@@ -1001,15 +1278,15 @@ test string-14.12 {string replace} {
} {}
test string-14.13 {string replace} {
list [catch {string replace abc abc 1} msg] $msg
-} {1 {bad index "abc": must be integer or end?-integer?}}
+} {1 {bad index "abc": must be integer?[+-]integer? or end?[+-]integer?}}
test string-14.14 {string replace} {
list [catch {string replace abc 1 eof} msg] $msg
-} {1 {bad index "eof": must be integer or end?-integer?}}
+} {1 {bad index "eof": must be integer?[+-]integer? or end?[+-]integer?}}
test string-14.15 {string replace} {
string replace abcdefghijklmnop end-10 end-2 NEW
} {abcdeNEWop}
test string-14.16 {string replace} {
- string replace abcdefghijklmnop 0 e foo
+ string replace abcdefghijklmnop 0 end foo
} {foo}
test string-14.17 {string replace} {
string replace abcdefghijklmnop end end-1
@@ -1020,7 +1297,7 @@ test string-15.1 {string tolower too few args} {
} {1 {wrong # args: should be "string tolower string ?first? ?last?"}}
test string-15.2 {string tolower bad args} {
list [catch {string tolower a b} msg] $msg
-} {1 {bad index "b": must be integer or end?-integer?}}
+} {1 {bad index "b": must be integer?[+-]integer? or end?[+-]integer?}}
test string-15.3 {string tolower too many args} {
list [catch {string tolower ABC 1 end oops} msg] $msg
} {1 {wrong # args: should be "string tolower string ?first? ?last?"}}
@@ -1051,7 +1328,7 @@ test string-16.1 {string toupper} {
} {1 {wrong # args: should be "string toupper string ?first? ?last?"}}
test string-16.2 {string toupper} {
list [catch {string toupper a b} msg] $msg
-} {1 {bad index "b": must be integer or end?-integer?}}
+} {1 {bad index "b": must be integer?[+-]integer? or end?[+-]integer?}}
test string-16.3 {string toupper} {
list [catch {string toupper a 1 end oops} msg] $msg
} {1 {wrong # args: should be "string toupper string ?first? ?last?"}}
@@ -1082,7 +1359,7 @@ test string-17.1 {string totitle} {
} {1 {wrong # args: should be "string totitle string ?first? ?last?"}}
test string-17.2 {string totitle} {
list [catch {string totitle a b} msg] $msg
-} {1 {bad index "b": must be integer or end?-integer?}}
+} {1 {bad index "b": must be integer?[+-]integer? or end?[+-]integer?}}
test string-17.3 {string totitle} {
string totitle abCDEf
} {Abcdef}
@@ -1145,7 +1422,7 @@ test string-20.1 {string trimright errors} {
} {1 {wrong # args: should be "string trimright string ?chars?"}}
test string-20.2 {string trimright errors} {
list [catch {string trimg a} msg] $msg
-} {1 {bad option "trimg": must be bytelength, compare, equal, first, index, is, last, length, map, match, range, repeat, replace, tolower, toupper, totitle, trim, trimleft, trimright, wordend, or wordstart}}
+} {1 {unknown or ambiguous subcommand "trimg": must be bytelength, compare, equal, first, index, is, last, length, map, match, range, repeat, replace, reverse, tolower, totitle, toupper, trim, trimleft, trimright, wordend, or wordstart}}
test string-20.3 {string trimright} {
string trimright " XYZ "
} { XYZ}
@@ -1164,7 +1441,7 @@ test string-21.2 {string wordend} {
} {1 {wrong # args: should be "string wordend string index"}}
test string-21.3 {string wordend} {
list [catch {string wordend a gorp} msg] $msg
-} {1 {bad index "gorp": must be integer or end?-integer?}}
+} {1 {bad index "gorp": must be integer?[+-]integer? or end?[+-]integer?}}
test string-21.4 {string wordend} {
string wordend abc. -1
} 3
@@ -1201,7 +1478,7 @@ test string-21.14 {string wordend, unicode} {
test string-22.1 {string wordstart} {
list [catch {string word a} msg] $msg
-} {1 {ambiguous option "word": must be bytelength, compare, equal, first, index, is, last, length, map, match, range, repeat, replace, tolower, toupper, totitle, trim, trimleft, trimright, wordend, or wordstart}}
+} {1 {unknown or ambiguous subcommand "word": must be bytelength, compare, equal, first, index, is, last, length, map, match, range, repeat, replace, reverse, tolower, totitle, toupper, trim, trimleft, trimright, wordend, or wordstart}}
test string-22.2 {string wordstart} {
list [catch {string wordstart a} msg] $msg
} {1 {wrong # args: should be "string wordstart string index"}}
@@ -1210,7 +1487,7 @@ test string-22.3 {string wordstart} {
} {1 {wrong # args: should be "string wordstart string index"}}
test string-22.4 {string wordstart} {
list [catch {string wordstart a gorp} msg] $msg
-} {1 {bad index "gorp": must be integer or end?-integer?}}
+} {1 {bad index "gorp": must be integer?[+-]integer? or end?[+-]integer?}}
test string-22.5 {string wordstart} {
string wordstart "one two three_words" 400
} 8
@@ -1239,6 +1516,159 @@ test string-22.13 {string wordstart, unicode} {
string wordstart "\uc700\uc700 abc" 8
} 3
+test string-23.0 {string is boolean, Bug 1187123} testindexobj {
+ set x 5
+ catch {testindexobj $x foo bar soom}
+ string is boolean $x
+} 0
+test string-23.1 {string is command with empty string} {
+ set s ""
+ list \
+ [string is alnum $s] \
+ [string is alpha $s] \
+ [string is ascii $s] \
+ [string is control $s] \
+ [string is boolean $s] \
+ [string is digit $s] \
+ [string is double $s] \
+ [string is false $s] \
+ [string is graph $s] \
+ [string is integer $s] \
+ [string is lower $s] \
+ [string is print $s] \
+ [string is punct $s] \
+ [string is space $s] \
+ [string is true $s] \
+ [string is upper $s] \
+ [string is wordchar $s] \
+ [string is xdigit $s] \
+
+} {1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1}
+test string-23.2 {string is command with empty string} {
+ set s ""
+ list \
+ [string is alnum -strict $s] \
+ [string is alpha -strict $s] \
+ [string is ascii -strict $s] \
+ [string is control -strict $s] \
+ [string is boolean -strict $s] \
+ [string is digit -strict $s] \
+ [string is double -strict $s] \
+ [string is false -strict $s] \
+ [string is graph -strict $s] \
+ [string is integer -strict $s] \
+ [string is lower -strict $s] \
+ [string is print -strict $s] \
+ [string is punct -strict $s] \
+ [string is space -strict $s] \
+ [string is true -strict $s] \
+ [string is upper -strict $s] \
+ [string is wordchar -strict $s] \
+ [string is xdigit -strict $s] \
+
+} {0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0}
+
+test string-24.1 {string reverse command} -body {
+ string reverse
+} -returnCodes error -result "wrong # args: should be \"string reverse string\""
+test string-24.2 {string reverse command} -body {
+ string reverse a b
+} -returnCodes error -result "wrong # args: should be \"string reverse string\""
+test string-24.3 {string reverse command - shared string} {
+ set x abcde
+ string reverse $x
+} edcba
+test string-24.4 {string reverse command - unshared string} {
+ set x abc
+ set y de
+ string reverse $x$y
+} edcba
+test string-24.5 {string reverse command - shared unicode string} {
+ set x abcde\udead
+ string reverse $x
+} \udeadedcba
+test string-24.6 {string reverse command - unshared string} {
+ set x abc
+ set y de\udead
+ string reverse $x$y
+} \udeadedcba
+test string-24.7 {string reverse command - simple case} {
+ string reverse a
+} a
+test string-24.8 {string reverse command - simple case} {
+ string reverse \udead
+} \udead
+test string-24.9 {string reverse command - simple case} {
+ string reverse {}
+} {}
+test string-24.10 {string reverse command - corner case} {
+ set x \ubeef\udead
+ string reverse $x
+} \udead\ubeef
+test string-24.11 {string reverse command - corner case} {
+ set x \ubeef
+ set y \udead
+ string reverse $x$y
+} \udead\ubeef
+test string-24.12 {string reverse command - corner case} {
+ set x \ubeef
+ set y \udead
+ string is ascii [string reverse $x$y]
+} 0
+
+test string-25.1 {string is list} {
+ string is list {a b c}
+} 1
+test string-25.2 {string is list} {
+ string is list "a \{b c"
+} 0
+test string-25.3 {string is list} {
+ string is list {a {b c}d e}
+} 0
+test string-25.4 {string is list} {
+ string is list {}
+} 1
+test string-25.5 {string is list} {
+ string is list -strict {a b c}
+} 1
+test string-25.6 {string is list} {
+ string is list -strict "a \{b c"
+} 0
+test string-25.7 {string is list} {
+ string is list -strict {a {b c}d e}
+} 0
+test string-25.8 {string is list} {
+ string is list -strict {}
+} 1
+test string-25.9 {string is list} {
+ set x {}
+ list [string is list -failindex x {a b c}] $x
+} {1 {}}
+test string-25.10 {string is list} {
+ set x {}
+ list [string is list -failindex x "a \{b c"] $x
+} {0 2}
+test string-25.11 {string is list} {
+ set x {}
+ list [string is list -failindex x {a b {b c}d e}] $x
+} {0 4}
+test string-25.12 {string is list} {
+ set x {}
+ list [string is list -failindex x {}] $x
+} {1 {}}
+test string-25.13 {string is list} {
+ set x {}
+ list [string is list -failindex x { {b c}d e}] $x
+} {0 2}
+test string-25.14 {string is list} {
+ set x {}
+ list [string is list -failindex x "\uabcd {b c}d e"] $x
+} {0 2}
+
# cleanup
::tcltest::cleanupTests
return
+
+# Local Variables:
+# mode: tcl
+# End: