diff options
author | Steve Bennett <steveb@workware.net.au> | 2011-11-20 22:58:50 +1000 |
---|---|---|
committer | Steve Bennett <steveb@workware.net.au> | 2011-11-25 08:07:34 +1000 |
commit | 44fb1db8b16f6a339fadd1d313fafd012d9e58a5 (patch) | |
tree | 4848b62f8189c99edccc2b4db0220999eef97af7 /tests | |
parent | 73148db333e1a74d2c1bf3fe539888f6ad93a0db (diff) | |
download | jimtcl-44fb1db8b16f6a339fadd1d313fafd012d9e58a5.zip jimtcl-44fb1db8b16f6a339fadd1d313fafd012d9e58a5.tar.gz jimtcl-44fb1db8b16f6a339fadd1d313fafd012d9e58a5.tar.bz2 |
Minor message changes to match Tcl 8.6
And import some up-to-date tests from Tcl 8.6
Signed-off-by: Steve Bennett <steveb@workware.net.au>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/jim.test | 281 | ||||
-rw-r--r-- | tests/linsert.test | 116 | ||||
-rw-r--r-- | tests/lrange.test | 85 | ||||
-rw-r--r-- | tests/lreplace.test | 133 |
4 files changed, 335 insertions, 280 deletions
diff --git a/tests/jim.test b/tests/jim.test index 4e3d02c..de675f2 100644 --- a/tests/jim.test +++ b/tests/jim.test @@ -2659,7 +2659,6 @@ test switch-10.9 {callback matches first if pat < str} lambda { ################################################################################ # Basic "for" operation. - test for-1.1 {TclCompileForCmd: missing initial command} { list [catch {for} msg] $msg } {1 {wrong # args: should be "for start test next body"}} @@ -3050,6 +3049,7 @@ test for-6.16 {Tcl_ForObjCmd: for command result} { set a } {} + ################################################################################ # INFO ################################################################################ @@ -3293,285 +3293,6 @@ test info-7.5 {info vars with temporary variables} { t1 } {a} - -################################################################################ -# linsert -################################################################################ - -test linsert-1.1 {linsert command} { - linsert {1 2 3 4 5} 0 a -} {a 1 2 3 4 5} -test linsert-1.2 {linsert command} { - linsert {1 2 3 4 5} 1 a -} {1 a 2 3 4 5} -test linsert-1.3 {linsert command} { - linsert {1 2 3 4 5} 2 a -} {1 2 a 3 4 5} -test linsert-1.4 {linsert command} { - linsert {1 2 3 4 5} 3 a -} {1 2 3 a 4 5} -test linsert-1.5 {linsert command} { - linsert {1 2 3 4 5} 4 a -} {1 2 3 4 a 5} -test linsert-1.6 {linsert command} { - linsert {1 2 3 4 5} 5 a -} {1 2 3 4 5 a} -test linsert-1.7 {linsert command} { - linsert {1 2 3 4 5} 2 one two \{three \$four -} {1 2 one two \{three {$four} 3 4 5} -test linsert-1.8 {linsert command} { - linsert {\{one \$two \{three \ four \ five} 2 a b c -} {\{one {$two} a b c \{three { four} { five}} -test linsert-1.9 {linsert command} { - linsert {{1 2} {3 4} {5 6} {7 8}} 2 {x y} {a b} -} {{1 2} {3 4} {x y} {a b} {5 6} {7 8}} -test linsert-1.10 {linsert command} { - linsert {} 2 a b c -} {a b c} -test linsert-1.11 {linsert command} { - linsert {} 2 {} -} {{}} -test linsert-1.12 {linsert command} { - linsert {a b "c c" d e} 3 1 -} {a b {c c} 1 d e} -test linsert-1.13 {linsert command} { - linsert { a b c d} 0 1 2 -} {1 2 a b c d} -test linsert-1.14 {linsert command} { - linsert {a b c {d e f}} 4 1 2 -} {a b c {d e f} 1 2} -test linsert-1.15 {linsert command} { - linsert {a b c \{\ abc} 4 q r -} {a b c \{\ q r abc} -test linsert-1.16 {linsert command} { - linsert {a b c \{ abc} 4 q r -} {a b c \{ q r abc} -test linsert-1.17 {linsert command} { - linsert {a b c} end q r -} {a b c q r} -test linsert-1.18 {linsert command} { - linsert {a} end q r -} {a q r} -test linsert-1.19 {linsert command} { - linsert {} end q r -} {q r} -test linsert-1.20 {linsert command, use of end-int index} { - linsert {a b c d} end-2 e f -} {a b e f c d} - -test linsert-2.1 {linsert errors} { - list [catch linsert msg] $msg -} {1 {wrong # args: should be "linsert list index element ?element ...?"}} -test linsert-2.2 {linsert errors} { - list [catch {linsert a b} msg] $msg -} {1 {wrong # args: should be "linsert list index element ?element ...?"}} -test linsert-2.3 {linsert errors} { - list [catch {linsert a 12x 2} msg] $msg -} {1 {bad index "12x": must be integer?[+-]integer? or end?[+-]integer?}} - -test linsert-3.1 {linsert won't modify shared argument objects} { - proc p {} { - linsert "a b c" 1 "x y" - return "a b c" - } - p -} "a b c" -test linsert-3.2 {linsert won't modify shared argument objects} { - catch {unset lis} - set lis [concat a \"b\" c] - linsert $lis 0 [string length $lis] -} "7 a b c" - -################################################################################ -# LREPLACE -################################################################################ - -test lreplace-1.1 {lreplace command} { - lreplace {1 2 3 4 5} 0 0 a -} {a 2 3 4 5} -test lreplace-1.2 {lreplace command} { - lreplace {1 2 3 4 5} 1 1 a -} {1 a 3 4 5} -test lreplace-1.3 {lreplace command} { - lreplace {1 2 3 4 5} 2 2 a -} {1 2 a 4 5} -test lreplace-1.4 {lreplace command} { - lreplace {1 2 3 4 5} 3 3 a -} {1 2 3 a 5} -test lreplace-1.5 {lreplace command} { - lreplace {1 2 3 4 5} 4 4 a -} {1 2 3 4 a} -test lreplace-1.6 {lreplace command} { - lreplace {1 2 3 4 5} 4 5 a -} {1 2 3 4 a} -test lreplace-1.7 {lreplace command} { - lreplace {1 2 3 4 5} -1 -1 a -} {a 1 2 3 4 5} -test lreplace-1.8 {lreplace command} { - lreplace {1 2 3 4 5} 2 end a b c d -} {1 2 a b c d} -test lreplace-1.9 {lreplace command} { - lreplace {1 2 3 4 5} 0 3 -} {5} -test lreplace-1.10 {lreplace command} { - lreplace {1 2 3 4 5} 0 4 -} {} -test lreplace-1.11 {lreplace command} { - lreplace {1 2 3 4 5} 0 1 -} {3 4 5} -test lreplace-1.12 {lreplace command} { - lreplace {1 2 3 4 5} 2 3 -} {1 2 5} -test lreplace-1.13 {lreplace command} { - lreplace {1 2 3 4 5} 3 end -} {1 2 3} -test lreplace-1.14 {lreplace command} { - lreplace {1 2 3 4 5} -1 4 a b c -} {a b c} -test lreplace-1.15 {lreplace command} { - lreplace {a b "c c" d e f} 3 3 -} {a b {c c} e f} -test lreplace-1.16 {lreplace command} { - lreplace { 1 2 3 4 5} 0 0 a -} {a 2 3 4 5} -test lreplace-1.17 {lreplace command} { - lreplace {1 2 3 4 "5 6"} 4 4 a -} {1 2 3 4 a} -test lreplace-1.18 {lreplace command} { - lreplace {1 2 3 4 {5 6}} 4 4 a -} {1 2 3 4 a} -test lreplace-1.19 {lreplace command} { - lreplace {1 2 3 4} 2 end x y z -} {1 2 x y z} -test lreplace-1.20 {lreplace command} { - lreplace {1 2 3 4} end end a -} {1 2 3 a} -test lreplace-1.21 {lreplace command} { - lreplace {1 2 3 4} end 3 a -} {1 2 3 a} -test lreplace-1.22 {lreplace command} { - lreplace {1 2 3 4} end end -} {1 2 3} -test lreplace-1.23 {lreplace command} { - lreplace {1 2 3 4} 2 -1 xy -} {1 2 xy 3 4} -test lreplace-1.24 {lreplace command} { - lreplace {1 2 3 4} end -1 z -} {1 2 3 z 4} -test lreplace-1.25 {lreplace command} { - concat \"[lreplace {\}\ hello} end end]\" -} {"\}\ "} -test lreplace-1.26 {lreplace command} { - catch {unset foo} - set foo {a b} - list [set foo [lreplace $foo end end]] \ - [set foo [lreplace $foo end end]] \ - [set foo [lreplace $foo end end]] -} {a {} {}} - - -test lreplace-2.1 {lreplace errors} { - list [catch lreplace msg] $msg -} {1 {wrong # args: should be "lreplace list first last ?element element ...?"}} -test lreplace-2.2 {lreplace errors} { - list [catch {lreplace a b} msg] $msg -} {1 {wrong # args: should be "lreplace list first last ?element element ...?"}} -test lreplace-2.3 {lreplace errors} { - list [catch {lreplace x a 10} msg] $msg -} {1 {bad index "a": must be integer?[+-]integer? or end?[+-]integer?}} -test lreplace-2.4 {lreplace errors} { - list [catch {lreplace x 10 x} msg] $msg -} {1 {bad index "x": must be integer?[+-]integer? or end?[+-]integer?}} -test lreplace-2.5 {lreplace errors} { - list [catch {lreplace x 10 1x} msg] $msg -} {1 {bad index "1x": must be integer?[+-]integer? or end?[+-]integer?}} -test lreplace-2.6 {lreplace errors} { - list [catch {lreplace x 3 2} msg] $msg -} {1 {list doesn't contain element 3}} -test lreplace-2.7 {lreplace errors} { - list [catch {lreplace x 1 1} msg] $msg -} {1 {list doesn't contain element 1}} - -test lreplace-3.1 {lreplace won't modify shared argument objects} { - proc p {} { - lreplace "a b c" 1 1 "x y" - return "a b c" - } - p -} "a b c" - -################################################################################ -# LRANGE -################################################################################ - -test lrange-1.1 {range of list elements} { - lrange {a b c d} 1 2 -} {b c} -test lrange-1.2 {range of list elements} { - lrange {a {bcd e {f g {}}} l14 l15 d} 1 1 -} {{bcd e {f g {}}}} -test lrange-1.3 {range of list elements} { - lrange {a {bcd e {f g {}}} l14 l15 d} 3 end -} {l15 d} -test lrange-1.4 {range of list elements} { - lrange {a {bcd e {f g {}}} l14 l15 d} 4 10000 -} {d} -test lrange-1.5 {range of list elements} { - lrange {a {bcd e {f g {}}} l14 l15 d} 4 3 -} {} -test lrange-1.6 {range of list elements} { - lrange {a {bcd e {f g {}}} l14 l15 d} 10 11 -} {} -test lrange-1.7 {range of list elements} { - lrange {a b c d e} -1 2 -} {a b c} -test lrange-1.8 {range of list elements} { - lrange {a b c d e} -2 -1 -} {} -test lrange-1.9 {range of list elements} { - lrange {a b c d e} -2 end -} {a b c d e} -test lrange-1.10 {range of list elements} { - lrange "a b\{c d" 1 2 -} "b\\{c d" -test lrange-1.11 {range of list elements} { - lrange "a b c d" end end -} d -test lrange-1.12 {range of list elements} { - lrange "a b c d" end 100000 -} d -test lrange-1.13 {range of list elements} { - lrange "a b c d" end 3 -} d -test lrange-1.14 {range of list elements} { - lrange "a b c d" end 2 -} {} -test lrange-1.15 {range of list elements} { - concat \"[lrange {a b \{\ } 0 2]" -} {"a b \{\ "} -test lrange-1.16 {list element quoting} { - lrange {[append a .b]} 0 end -} {{[append} a .b\]} - -test lrange-2.1 {error conditions} { - list [catch {lrange a b} msg] $msg -} {1 {wrong # args: should be "lrange list first last"}} -test lrange-2.2 {error conditions} { - list [catch {lrange a b 6 7} msg] $msg -} {1 {wrong # args: should be "lrange list first last"}} -test lrange-2.3 {error conditions} { - list [catch {lrange a b 6} msg] $msg -} {1 {bad index "b": must be integer?[+-]integer? or end?[+-]integer?}} -test lrange-2.4 {error conditions} { - list [catch {lrange a 0 enigma} msg] $msg -} {1 {bad index "enigma": must be integer?[+-]integer? or end?[+-]integer?}} -#test lrange-2.5 {error conditions} { -# list [catch {lrange "a \{b c" 3 4} msg] $msg -#} {1 {unmatched open brace in list}} -#test lrange-2.6 {error conditions} { -# list [catch {lrange "a b c \{ d e" 1 4} msg] $msg -#} {1 {unmatched open brace in list}} - ################################################################################ # RANGE ################################################################################ diff --git a/tests/linsert.test b/tests/linsert.test new file mode 100644 index 0000000..b528d11 --- /dev/null +++ b/tests/linsert.test @@ -0,0 +1,116 @@ +# Commands covered: linsert +# +# This file contains a collection of tests for one or more of the Tcl +# built-in commands. Sourcing this file into Tcl runs the tests and +# generates output for errors. No output means no errors were found. +# +# Copyright (c) 1991-1993 The Regents of the University of California. +# Copyright (c) 1994 Sun Microsystems, Inc. +# Copyright (c) 1998-1999 by Scriptics Corporation. +# +# See the file "license.terms" for information on usage and redistribution +# of this file, and for a DISCLAIMER OF ALL WARRANTIES. + +source [file dirname [info script]]/testing.tcl + +catch {unset lis} +catch {rename p ""} + +test linsert-1.1 {linsert command} { + linsert {1 2 3 4 5} 0 a +} {a 1 2 3 4 5} +test linsert-1.2 {linsert command} { + linsert {1 2 3 4 5} 1 a +} {1 a 2 3 4 5} +test linsert-1.3 {linsert command} { + linsert {1 2 3 4 5} 2 a +} {1 2 a 3 4 5} +test linsert-1.4 {linsert command} { + linsert {1 2 3 4 5} 3 a +} {1 2 3 a 4 5} +test linsert-1.5 {linsert command} { + linsert {1 2 3 4 5} 4 a +} {1 2 3 4 a 5} +test linsert-1.6 {linsert command} { + linsert {1 2 3 4 5} 5 a +} {1 2 3 4 5 a} +test linsert-1.7 {linsert command} { + linsert {1 2 3 4 5} 2 one two \{three \$four +} {1 2 one two \{three {$four} 3 4 5} +test linsert-1.8 {linsert command} { + linsert {\{one \$two \{three \ four \ five} 2 a b c +} {\{one {$two} a b c \{three { four} { five}} +test linsert-1.9 {linsert command} { + linsert {{1 2} {3 4} {5 6} {7 8}} 2 {x y} {a b} +} {{1 2} {3 4} {x y} {a b} {5 6} {7 8}} +test linsert-1.10 {linsert command} { + linsert {} 2 a b c +} {a b c} +test linsert-1.11 {linsert command} { + linsert {} 2 {} +} {{}} +test linsert-1.12 {linsert command} { + linsert {a b "c c" d e} 3 1 +} {a b {c c} 1 d e} +test linsert-1.13 {linsert command} { + linsert { a b c d} 0 1 2 +} {1 2 a b c d} +test linsert-1.14 {linsert command} { + linsert {a b c {d e f}} 4 1 2 +} {a b c {d e f} 1 2} +test linsert-1.15 {linsert command} { + linsert {a b c \{\ abc} 4 q r +} {a b c \{\ q r abc} +test linsert-1.16 {linsert command} { + linsert {a b c \{ abc} 4 q r +} {a b c \{ q r abc} +test linsert-1.17 {linsert command} { + linsert {a b c} end q r +} {a b c q r} +test linsert-1.18 {linsert command} { + linsert {a} end q r +} {a q r} +test linsert-1.19 {linsert command} { + linsert {} end q r +} {q r} +test linsert-1.20 {linsert command, use of end-int index} { + linsert {a b c d} end-2 e f +} {a b e f c d} + +test linsert-2.1 {linsert errors} { + list [catch linsert msg] $msg +} {1 {wrong # args: should be "linsert list index ?element ...?"}} +test linsert-2.2 {linsert errors} { + list [catch {linsert a b} msg] $msg +} {1 {bad index "b": must be integer?[+-]integer? or end?[+-]integer?}} +test linsert-2.3 {linsert errors} { + list [catch {linsert a 12x 2} msg] $msg +} {1 {bad index "12x": must be integer?[+-]integer? or end?[+-]integer?}} +test linsert-2.4 {linsert errors} tcl { + list [catch {linsert \{ 12 2} msg] $msg +} {1 {unmatched open brace in list}} +test linsert-2.5 {syntax (TIP 323)} { + linsert {a b c} 0 +} [list a b c] +test linsert-2.6 {syntax (TIP 323)} { + linsert "a\nb\nc" 0 +} [list a b c] + +test linsert-3.1 {linsert won't modify shared argument objects} { + proc p {} { + linsert "a b c" 1 "x y" + return "a b c" + } + p +} "a b c" +test linsert-3.2 {linsert won't modify shared argument objects} { + catch {unset lis} + set lis [format "a \"%s\" c" "b"] + linsert $lis 0 [string length $lis] +} "7 a b c" + +# cleanup +catch {unset lis} +catch {rename p ""} +::tcltest::cleanupTests +return diff --git a/tests/lrange.test b/tests/lrange.test new file mode 100644 index 0000000..e72421c --- /dev/null +++ b/tests/lrange.test @@ -0,0 +1,85 @@ +# Commands covered: lrange +# +# This file contains a collection of tests for one or more of the Tcl +# built-in commands. Sourcing this file into Tcl runs the tests and +# generates output for errors. No output means no errors were found. +# +# Copyright (c) 1991-1993 The Regents of the University of California. +# Copyright (c) 1994 Sun Microsystems, Inc. +# Copyright (c) 1998-1999 by Scriptics Corporation. +# +# See the file "license.terms" for information on usage and redistribution +# of this file, and for a DISCLAIMER OF ALL WARRANTIES. + +source [file dirname [info script]]/testing.tcl + +test lrange-1.1 {range of list elements} { + lrange {a b c d} 1 2 +} {b c} +test lrange-1.2 {range of list elements} { + lrange {a {bcd e {f g {}}} l14 l15 d} 1 1 +} {{bcd e {f g {}}}} +test lrange-1.3 {range of list elements} { + lrange {a {bcd e {f g {}}} l14 l15 d} 3 end +} {l15 d} +test lrange-1.4 {range of list elements} { + lrange {a {bcd e {f g {}}} l14 l15 d} 4 10000 +} {d} +test lrange-1.5 {range of list elements} { + lrange {a {bcd e {f g {}}} l14 l15 d} 4 3 +} {} +test lrange-1.6 {range of list elements} { + lrange {a {bcd e {f g {}}} l14 l15 d} 10 11 +} {} +test lrange-1.7 {range of list elements} { + lrange {a b c d e} -1 2 +} {a b c} +test lrange-1.8 {range of list elements} { + lrange {a b c d e} -2 -1 +} {} +test lrange-1.9 {range of list elements} { + lrange {a b c d e} -2 end +} {a b c d e} +test lrange-1.10 {range of list elements} { + lrange "a b\{c d" 1 2 +} "b\\{c d" +test lrange-1.11 {range of list elements} { + lrange "a b c d" end end +} d +test lrange-1.12 {range of list elements} { + lrange "a b c d" end 100000 +} d +test lrange-1.13 {range of list elements} { + lrange "a b c d" end 3 +} d +test lrange-1.14 {range of list elements} { + lrange "a b c d" end 2 +} {} +test lrange-1.15 {range of list elements} { + concat \"[lrange {a b \{\ } 0 2]" +} {"a b \{\ "} +test lrange-1.16 {list element quoting} { + lrange {[append a .b]} 0 end +} {{[append} a .b\]} +test lrange-2.1 {error conditions} { + list [catch {lrange a b} msg] $msg +} {1 {wrong # args: should be "lrange list first last"}} +test lrange-2.2 {error conditions} { + list [catch {lrange a b 6 7} msg] $msg +} {1 {wrong # args: should be "lrange list first last"}} +test lrange-2.3 {error conditions} { + list [catch {lrange a b 6} msg] $msg +} {1 {bad index "b": must be integer?[+-]integer? or end?[+-]integer?}} +test lrange-2.4 {error conditions} { + list [catch {lrange a 0 enigma} msg] $msg +} {1 {bad index "enigma": must be integer?[+-]integer? or end?[+-]integer?}} +test lrange-2.5 {error conditions} tcl { + list [catch {lrange "a \{b c" 3 4} msg] $msg +} {1 {unmatched open brace in list}} +test lrange-2.6 {error conditions} tcl { + list [catch {lrange "a b c \{ d e" 1 4} msg] $msg +} {1 {unmatched open brace in list}} + +# cleanup +::tcltest::cleanupTests +return diff --git a/tests/lreplace.test b/tests/lreplace.test new file mode 100644 index 0000000..ba77505 --- /dev/null +++ b/tests/lreplace.test @@ -0,0 +1,133 @@ +# Commands covered: lreplace +# +# This file contains a collection of tests for one or more of the Tcl +# built-in commands. Sourcing this file into Tcl runs the tests and +# generates output for errors. No output means no errors were found. +# +# Copyright (c) 1991-1993 The Regents of the University of California. +# Copyright (c) 1994 Sun Microsystems, Inc. +# Copyright (c) 1998-1999 by Scriptics Corporation. +# +# See the file "license.terms" for information on usage and redistribution +# of this file, and for a DISCLAIMER OF ALL WARRANTIES. + +source [file dirname [info script]]/testing.tcl + +test lreplace-1.1 {lreplace command} { + lreplace {1 2 3 4 5} 0 0 a +} {a 2 3 4 5} +test lreplace-1.2 {lreplace command} { + lreplace {1 2 3 4 5} 1 1 a +} {1 a 3 4 5} +test lreplace-1.3 {lreplace command} { + lreplace {1 2 3 4 5} 2 2 a +} {1 2 a 4 5} +test lreplace-1.4 {lreplace command} { + lreplace {1 2 3 4 5} 3 3 a +} {1 2 3 a 5} +test lreplace-1.5 {lreplace command} { + lreplace {1 2 3 4 5} 4 4 a +} {1 2 3 4 a} +test lreplace-1.6 {lreplace command} { + lreplace {1 2 3 4 5} 4 5 a +} {1 2 3 4 a} +test lreplace-1.7 {lreplace command} { + lreplace {1 2 3 4 5} -1 -1 a +} {a 1 2 3 4 5} +test lreplace-1.8 {lreplace command} { + lreplace {1 2 3 4 5} 2 end a b c d +} {1 2 a b c d} +test lreplace-1.9 {lreplace command} { + lreplace {1 2 3 4 5} 0 3 +} {5} +test lreplace-1.10 {lreplace command} { + lreplace {1 2 3 4 5} 0 4 +} {} +test lreplace-1.11 {lreplace command} { + lreplace {1 2 3 4 5} 0 1 +} {3 4 5} +test lreplace-1.12 {lreplace command} { + lreplace {1 2 3 4 5} 2 3 +} {1 2 5} +test lreplace-1.13 {lreplace command} { + lreplace {1 2 3 4 5} 3 end +} {1 2 3} +test lreplace-1.14 {lreplace command} { + lreplace {1 2 3 4 5} -1 4 a b c +} {a b c} +test lreplace-1.15 {lreplace command} { + lreplace {a b "c c" d e f} 3 3 +} {a b {c c} e f} +test lreplace-1.16 {lreplace command} { + lreplace { 1 2 3 4 5} 0 0 a +} {a 2 3 4 5} +test lreplace-1.17 {lreplace command} { + lreplace {1 2 3 4 "5 6"} 4 4 a +} {1 2 3 4 a} +test lreplace-1.18 {lreplace command} { + lreplace {1 2 3 4 {5 6}} 4 4 a +} {1 2 3 4 a} +test lreplace-1.19 {lreplace command} { + lreplace {1 2 3 4} 2 end x y z +} {1 2 x y z} +test lreplace-1.20 {lreplace command} { + lreplace {1 2 3 4} end end a +} {1 2 3 a} +test lreplace-1.21 {lreplace command} { + lreplace {1 2 3 4} end 3 a +} {1 2 3 a} +test lreplace-1.22 {lreplace command} { + lreplace {1 2 3 4} end end +} {1 2 3} +test lreplace-1.23 {lreplace command} { + lreplace {1 2 3 4} 2 -1 xy +} {1 2 xy 3 4} +test lreplace-1.24 {lreplace command} { + lreplace {1 2 3 4} end -1 z +} {1 2 3 z 4} +test lreplace-1.25 {lreplace command} { + concat \"[lreplace {\}\ hello} end end]\" +} {"\}\ "} +test lreplace-1.26 {lreplace command} { + catch {unset foo} + set foo {a b} + list [set foo [lreplace $foo end end]] \ + [set foo [lreplace $foo end end]] \ + [set foo [lreplace $foo end end]] +} {a {} {}} + + +test lreplace-2.1 {lreplace errors} { + list [catch lreplace msg] $msg +} {1 {wrong # args: should be "lreplace list first last ?element ...?"}} +test lreplace-2.2 {lreplace errors} { + list [catch {lreplace a b} msg] $msg +} {1 {wrong # args: should be "lreplace list first last ?element ...?"}} +test lreplace-2.3 {lreplace errors} { + list [catch {lreplace x a 10} msg] $msg +} {1 {bad index "a": must be integer?[+-]integer? or end?[+-]integer?}} +test lreplace-2.4 {lreplace errors} { + list [catch {lreplace x 10 x} msg] $msg +} {1 {bad index "x": must be integer?[+-]integer? or end?[+-]integer?}} +test lreplace-2.5 {lreplace errors} { + list [catch {lreplace x 10 1x} msg] $msg +} {1 {bad index "1x": must be integer?[+-]integer? or end?[+-]integer?}} +test lreplace-2.6 {lreplace errors} { + list [catch {lreplace x 3 2} msg] $msg +} {1 {list doesn't contain element 3}} +test lreplace-2.7 {lreplace errors} { + list [catch {lreplace x 1 1} msg] $msg +} {1 {list doesn't contain element 1}} + +test lreplace-3.1 {lreplace won't modify shared argument objects} { + proc p {} { + lreplace "a b c" 1 1 "x y" + return "a b c" + } + p +} "a b c" + +# cleanup +catch {unset foo} +::tcltest::cleanupTests +return |