1 # Commands covered: lreplace
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.
7 # Copyright (c) 1991-1993 The Regents of the University of California.
8 # Copyright (c) 1994 Sun Microsystems, Inc.
9 # Copyright (c) 1998-1999 by Scriptics Corporation.
11 # See the file "license.terms" for information on usage and redistribution
12 # of this file, and for a DISCLAIMER OF ALL WARRANTIES.
14 source [file dirname [info script]]/testing.tcl
16 test lreplace-1.1 {lreplace command} {
17 lreplace {1 2 3 4 5} 0 0 a
19 test lreplace-1.2 {lreplace command} {
20 lreplace {1 2 3 4 5} 1 1 a
22 test lreplace-1.3 {lreplace command} {
23 lreplace {1 2 3 4 5} 2 2 a
25 test lreplace-1.4 {lreplace command} {
26 lreplace {1 2 3 4 5} 3 3 a
28 test lreplace-1.5 {lreplace command} {
29 lreplace {1 2 3 4 5} 4 4 a
31 test lreplace-1.6 {lreplace command} {
32 lreplace {1 2 3 4 5} 4 5 a
34 test lreplace-1.7 {lreplace command} {
35 lreplace {1 2 3 4 5} -1 -1 a
37 test lreplace-1.8 {lreplace command} {
38 lreplace {1 2 3 4 5} 2 end a b c d
40 test lreplace-1.9 {lreplace command} {
41 lreplace {1 2 3 4 5} 0 3
43 test lreplace-1.10 {lreplace command} {
44 lreplace {1 2 3 4 5} 0 4
46 test lreplace-1.11 {lreplace command} {
47 lreplace {1 2 3 4 5} 0 1
49 test lreplace-1.12 {lreplace command} {
50 lreplace {1 2 3 4 5} 2 3
52 test lreplace-1.13 {lreplace command} {
53 lreplace {1 2 3 4 5} 3 end
55 test lreplace-1.14 {lreplace command} {
56 lreplace {1 2 3 4 5} -1 4 a b c
58 test lreplace-1.15 {lreplace command} {
59 lreplace {a b "c c" d e f} 3 3
61 test lreplace-1.16 {lreplace command} {
62 lreplace { 1 2 3 4 5} 0 0 a
64 test lreplace-1.17 {lreplace command} {
65 lreplace {1 2 3 4 "5 6"} 4 4 a
67 test lreplace-1.18 {lreplace command} {
68 lreplace {1 2 3 4 {5 6}} 4 4 a
70 test lreplace-1.19 {lreplace command} {
71 lreplace {1 2 3 4} 2 end x y z
73 test lreplace-1.20 {lreplace command} {
74 lreplace {1 2 3 4} end end a
76 test lreplace-1.21 {lreplace command} {
77 lreplace {1 2 3 4} end 3 a
79 test lreplace-1.22 {lreplace command} {
80 lreplace {1 2 3 4} end end
82 test lreplace-1.23 {lreplace command} {
83 lreplace {1 2 3 4} 2 -1 xy
85 test lreplace-1.24 {lreplace command} {
86 lreplace {1 2 3 4} end -1 z
88 test lreplace-1.25 {lreplace command} {
89 concat \"[lreplace {\}\ hello} end end]\"
91 test lreplace-1.26 {lreplace command} {
94 list [set foo [lreplace $foo end end]] \
95 [set foo [lreplace $foo end end]] \
96 [set foo [lreplace $foo end end]]
98 test lreplace-1.27 {lreplace command} -body {
101 test lreplace-1.28 {lreplace command} -body {
104 test lreplace-1.29 {lreplace command} -body {
105 lreplace x 1 1 [error foo]
106 } -returnCodes 1 -result {foo}
107 test lreplace-1.30 {lreplace command} -body {
108 lreplace {not {}alist} 0 0 [error foo]
109 } -returnCodes 1 -result {foo}
111 test lreplace-2.1 {lreplace errors} {
112 list [catch lreplace msg] $msg
113 } {1 {wrong # args: should be "lreplace list first last ?element ...?"}}
114 test lreplace-2.2 {lreplace errors} {
115 list [catch {lreplace a b} msg] $msg
116 } {1 {wrong # args: should be "lreplace list first last ?element ...?"}}
117 test lreplace-2.3 {lreplace errors} {
118 list [catch {lreplace x a 10} msg] $msg
119 } {1 {bad index "a": must be integer?[+-]integer? or end?[+-]integer?}}
120 test lreplace-2.4 {lreplace errors} {
121 list [catch {lreplace x 10 x} msg] $msg
122 } {1 {bad index "x": must be integer?[+-]integer? or end?[+-]integer?}}
123 test lreplace-2.5 {lreplace errors} {
124 list [catch {lreplace x 10 1x} msg] $msg
125 } {1 {bad index "1x": must be integer?[+-]integer? or end?[+-]integer?}}
126 test lreplace-2.6 {lreplace errors} {
127 list [catch {lreplace x 3 2} msg] $msg
129 test lreplace-2.7 {lreplace errors} {
130 list [catch {lreplace x 1 1} msg] $msg
133 test lreplace-3.1 {lreplace won't modify shared argument objects} {
135 lreplace "a b c" 1 1 "x y"
141 test lreplace-4.1 {Bug ccc2c2cc98: lreplace edge case} {
144 test lreplace-4.2 {Bug ccc2c2cc98: lreplace edge case} {
147 test lreplace-4.3 {lreplace edge case} {
150 test lreplace-4.4 {lreplace edge case} {
151 lreplace {1 2 3 4 5} 3 1
153 test lreplace-4.5 {lreplace edge case} {
154 lreplace {1 2 3 4 5} 3 0 _
156 test lreplace-4.6 {lreplace end-x: bug a4cb3f06c4} {
157 lreplace {0 1 2 3 4} 0 end-2
159 test lreplace-4.6.1 {lreplace end-x: bug a4cb3f06c4} {
160 lreplace {0 1 2 3 4} 0 end-2 a b c
162 test lreplace-4.7 {lreplace with two end-indexes: increasing} {
163 lreplace {0 1 2 3 4} end-2 end-1
165 test lreplace-4.7.1 {lreplace with two end-indexes: increasing} {
166 lreplace {0 1 2 3 4} end-2 end-1 a b c
168 test lreplace-4.8 {lreplace with two end-indexes: equal} {
169 lreplace {0 1 2 3 4} end-2 end-2
171 test lreplace-4.8.1 {lreplace with two end-indexes: equal} {
172 lreplace {0 1 2 3 4} end-2 end-2 a b c
174 test lreplace-4.9 {lreplace with two end-indexes: decreasing} {
175 lreplace {0 1 2 3 4} end-2 end-3
177 test lreplace-4.9.1 {lreplace with two end-indexes: decreasing} {
178 lreplace {0 1 2 3 4} end-2 end-3 a b c
180 test lreplace-4.10 {lreplace with two equal indexes} {
181 lreplace {0 1 2 3 4} 2 2
183 test lreplace-4.10.1 {lreplace with two equal indexes} {
184 lreplace {0 1 2 3 4} 2 2 a b c
186 test lreplace-4.11 {lreplace end index first} {
187 lreplace {0 1 2 3 4} end-2 1 a b c
189 test lreplace-4.12 {lreplace end index first} {
190 lreplace {0 1 2 3 4} end-2 2 a b c
192 test lreplace-4.13 {lreplace empty list} {
195 test lreplace-4.14 {lreplace empty list} {
199 test lreplace-5.1 {compiled lreplace: Bug 47ac84309b} {
204 test lreplace-5.2 {compiled lreplace: Bug 47ac84309b} {
212 ::tcltest::cleanupTests