os/persistentdata/persistentstorage/sqlite3api/TEST/TCL/tcldistribution/tests/lset.test
Update contrib.
1 # This file is a -*- tcl -*- test script
3 # Commands covered: lset
5 # This file contains a collection of tests for one or more of the Tcl
6 # built-in commands. Sourcing this file into Tcl runs the tests and
7 # generates output for errors. No output means no errors were found.
9 # Copyright (c) 2001 by Kevin B. Kenny. All rights reserved.
11 # See the file "license.terms" for information on usage and redistribution
12 # of this file, and for a DISCLAIMER OF ALL WARRANTIES.
16 if {[lsearch [namespace children] ::tcltest] == -1} {
17 package require tcltest
18 namespace import -force ::tcltest::*
21 proc failTrace {name1 name2 op} {
28 trace add variable noRead read failTrace
30 trace add variable noWrite write failTrace
32 test lset-1.1 {lset, not compiled, arg count} {
33 list [catch {eval $lset} msg] $msg
34 } "1 {wrong \# args: should be \"lset listVar index ?index...? value\"}"
36 test lset-1.2 {lset, not compiled, no such var} {
37 list [catch {eval [list $lset noSuchVar 0 {}]} msg] $msg
38 } "1 {can't read \"noSuchVar\": no such variable}"
40 test lset-1.3 {lset, not compiled, var not readable} {
41 list [catch {eval [list $lset noRead 0 {}]} msg] $msg
42 } "1 {can't read \"noRead\": trace failed}"
44 test lset-2.1 {lset, not compiled, 3 args, second arg a plain index} {
46 list [eval [list $lset x 0 3]] $x
49 test lset-2.2 {lset, not compiled, 3 args, second arg neither index nor list} {
52 eval [list $lset x {{bad}1} 3]
54 } "1 {bad index \"{bad}1\": must be integer or end?-integer?}"
56 test lset-3.1 {lset, not compiled, 3 args, data duplicated} {
58 list [eval [list $lset x 0 $x]] $x
59 } {{{0 1 2} 1 2} {{0 1 2} 1 2}}
61 test lset-3.2 {lset, not compiled, 3 args, data duplicated} {
64 list [eval [list $lset x 0 2]] $x $y
67 test lset-3.3 {lset, not compiled, 3 args, data duplicated} {
70 list [eval [list $lset x 0 $x]] $x $y
71 } {{{0 1} 1} {{0 1} 1} {0 1}}
73 test lset-3.4 {lset, not compiled, 3 args, data duplicated} {
75 list [eval [list $lset x [list 0] $x]] $x
76 } {{{0 1 2} 1 2} {{0 1 2} 1 2}}
78 test lset-3.5 {lset, not compiled, 3 args, data duplicated} {
81 list [eval [list $lset x [list 0] 2]] $x $y
84 test lset-3.6 {lset, not compiled, 3 args, data duplicated} {
87 list [eval [list $lset x [list 0] $x]] $x $y
88 } {{{0 1} 1} {{0 1} 1} {0 1}}
90 test lset-4.1 {lset, not compiled, 3 args, not a list} {
93 eval [list $lset a [list 0] y]
95 } {1 {unmatched open brace in list}}
97 test lset-4.2 {lset, not compiled, 3 args, bad index} {
100 eval [list $lset a [list 2a2] w]
102 } {1 {bad index "2a2": must be integer or end?-integer?}}
104 test lset-4.3 {lset, not compiled, 3 args, index out of range} {
107 eval [list $lset a [list -1] w]
109 } {1 {list index out of range}}
111 test lset-4.4 {lset, not compiled, 3 args, index out of range} {
114 eval [list $lset a [list 3] w]
116 } {1 {list index out of range}}
118 test lset-4.5 {lset, not compiled, 3 args, index out of range} {
121 eval [list $lset a [list end--1] w]
123 } {1 {list index out of range}}
125 test lset-4.6 {lset, not compiled, 3 args, index out of range} {
128 eval [list $lset a [list end-3] w]
130 } {1 {list index out of range}}
132 test lset-4.7 {lset, not compiled, 3 args, not a list} {
135 eval [list $lset a 0 y]
137 } {1 {unmatched open brace in list}}
139 test lset-4.8 {lset, not compiled, 3 args, bad index} {
142 eval [list $lset a 2a2 w]
144 } {1 {bad index "2a2": must be integer or end?-integer?}}
146 test lset-4.9 {lset, not compiled, 3 args, index out of range} {
149 eval [list $lset a -1 w]
151 } {1 {list index out of range}}
153 test lset-4.10 {lset, not compiled, 3 args, index out of range} {
156 eval [list $lset a 3 w]
158 } {1 {list index out of range}}
160 test lset-4.11 {lset, not compiled, 3 args, index out of range} {
163 eval [list $lset a end--1 w]
165 } {1 {list index out of range}}
167 test lset-4.12 {lset, not compiled, 3 args, index out of range} {
170 eval [list $lset a end-3 w]
172 } {1 {list index out of range}}
174 test lset-5.1 {lset, not compiled, 3 args, can't set variable} {
176 eval [list $lset noWrite 0 d]
178 } {1 {can't set "noWrite": trace failed} {d b c}}
180 test lset-5.2 {lset, not compiled, 3 args, can't set variable} {
182 eval [list $lset noWrite [list 0] d]
184 } {1 {can't set "noWrite": trace failed} {d b c}}
186 test lset-6.1 {lset, not compiled, 3 args, 1-d list basics} {
188 list [eval [list $lset a 0 a]] $a
191 test lset-6.2 {lset, not compiled, 3 args, 1-d list basics} {
193 list [eval [list $lset a [list 0] a]] $a
196 test lset-6.3 {lset, not compiled, 1-d list basics} {
198 list [eval [list $lset a 2 a]] $a
201 test lset-6.4 {lset, not compiled, 1-d list basics} {
203 list [eval [list $lset a [list 2] a]] $a
206 test lset-6.5 {lset, not compiled, 1-d list basics} {
208 list [eval [list $lset a end a]] $a
211 test lset-6.6 {lset, not compiled, 1-d list basics} {
213 list [eval [list $lset a [list end] a]] $a
216 test lset-6.7 {lset, not compiled, 1-d list basics} {
218 list [eval [list $lset a end-0 a]] $a
221 test lset-6.8 {lset, not compiled, 1-d list basics} {
223 list [eval [list $lset a [list end-0] a]] $a
226 test lset-6.9 {lset, not compiled, 1-d list basics} {
228 list [eval [list $lset a end-2 a]] $a
231 test lset-6.10 {lset, not compiled, 1-d list basics} {
233 list [eval [list $lset a [list end-2] a]] $a
236 test lset-7.1 {lset, not compiled, data sharing} {
238 list [eval [list $lset a $a {gag me}]] $a
239 } {{{gag me}} {{gag me}}}
241 test lset-7.2 {lset, not compiled, data sharing} {
243 list [eval [list $lset a $a {gag me}]] $a
244 } {{{gag me}} {{gag me}}}
246 test lset-7.3 {lset, not compiled, data sharing} {
248 list [eval [list $lset a 0 $a]] $a
249 } {{{x y} y} {{x y} y}}
251 test lset-7.4 {lset, not compiled, data sharing} {
253 list [eval [list $lset a [list 0] $a]] $a
254 } {{{x y} y} {{x y} y}}
256 test lset-7.5 {lset, not compiled, data sharing} {
259 list [eval [list $lset a $n $n]] $a $n
262 test lset-7.6 {lset, not compiled, data sharing} {
265 list [eval [list $lset a $n $n]] $a $n
268 test lset-7.7 {lset, not compiled, data sharing} {
271 list [eval [list $lset a $n 1]] $a $n
274 test lset-7.8 {lset, not compiled, data sharing} {
277 list [eval [list $lset a $n 1]] $a $n
280 test lset-7.9 {lset, not compiled, data sharing} {
282 list [eval [list $lset a $a $a]] $a
285 test lset-7.10 {lset, not compiled, data sharing} {
287 list [eval [list $lset a $a $a]] $a
290 test lset-8.1 {lset, not compiled, malformed sublist} {
291 set a [list "a \{" b]
292 list [catch {eval [list $lset a 0 1 c]} msg] $msg
293 } {1 {unmatched open brace in list}}
295 test lset-8.2 {lset, not compiled, malformed sublist} {
296 set a [list "a \{" b]
297 list [catch {eval [list $lset a {0 1} c]} msg] $msg
298 } {1 {unmatched open brace in list}}
300 test lset-8.3 {lset, not compiled, bad second index} {
302 list [catch {eval [list $lset a 0 2a2 f]} msg] $msg
303 } {1 {bad index "2a2": must be integer or end?-integer?}}
305 test lset-8.4 {lset, not compiled, bad second index} {
307 list [catch {eval [list $lset a {0 2a2} f]} msg] $msg
308 } {1 {bad index "2a2": must be integer or end?-integer?}}
310 test lset-8.5 {lset, not compiled, second index out of range} {
311 set a {{b c} {d e} {f g}}
312 list [catch {eval [list $lset a 2 -1 h]} msg] $msg
313 } {1 {list index out of range}}
315 test lset-8.6 {lset, not compiled, second index out of range} {
316 set a {{b c} {d e} {f g}}
317 list [catch {eval [list $lset a {2 -1} h]} msg] $msg
318 } {1 {list index out of range}}
320 test lset-8.7 {lset, not compiled, second index out of range} {
321 set a {{b c} {d e} {f g}}
322 list [catch {eval [list $lset a 2 2 h]} msg] $msg
323 } {1 {list index out of range}}
325 test lset-8.8 {lset, not compiled, second index out of range} {
326 set a {{b c} {d e} {f g}}
327 list [catch {eval [list $lset a {2 2} h]} msg] $msg
328 } {1 {list index out of range}}
330 test lset-8.9 {lset, not compiled, second index out of range} {
331 set a {{b c} {d e} {f g}}
332 list [catch {eval [list $lset a 2 end--1 h]} msg] $msg
333 } {1 {list index out of range}}
335 test lset-8.10 {lset, not compiled, second index out of range} {
336 set a {{b c} {d e} {f g}}
337 list [catch {eval [list $lset a {2 end--1} h]} msg] $msg
338 } {1 {list index out of range}}
340 test lset-8.11 {lset, not compiled, second index out of range} {
341 set a {{b c} {d e} {f g}}
342 list [catch {eval [list $lset a 2 end-2 h]} msg] $msg
343 } {1 {list index out of range}}
345 test lset-8.12 {lset, not compiled, second index out of range} {
346 set a {{b c} {d e} {f g}}
347 list [catch {eval [list $lset a {2 end-2} h]} msg] $msg
348 } {1 {list index out of range}}
350 test lset-9.1 {lset, not compiled, entire variable} {
352 list [eval [list $lset a y]] $a
355 test lset-9.2 {lset, not compiled, entire variable} {
357 list [eval [list $lset a {} y]] $a
360 test lset-10.1 {lset, not compiled, shared data} {
362 set a [list $row $row]
363 list [eval [list $lset a 0 0 x]] $a
364 } {{{x q} {p q}} {{x q} {p q}}}
366 test lset-10.2 {lset, not compiled, shared data} {
368 set a [list $row $row]
369 list [eval [list $lset a {0 0} x]] $a
370 } {{{x q} {p q}} {{x q} {p q}}}
372 test lset-11.1 {lset, not compiled, 2-d basics} {
374 list [eval [list $lset a 0 0 f]] $a
375 } {{{f c} {d e}} {{f c} {d e}}}
377 test lset-11.2 {lset, not compiled, 2-d basics} {
379 list [eval [list $lset a {0 0} f]] $a
380 } {{{f c} {d e}} {{f c} {d e}}}
382 test lset-11.3 {lset, not compiled, 2-d basics} {
384 list [eval [list $lset a 0 1 f]] $a
385 } {{{b f} {d e}} {{b f} {d e}}}
387 test lset-11.4 {lset, not compiled, 2-d basics} {
389 list [eval [list $lset a {0 1} f]] $a
390 } {{{b f} {d e}} {{b f} {d e}}}
392 test lset-11.5 {lset, not compiled, 2-d basics} {
394 list [eval [list $lset a 1 0 f]] $a
395 } {{{b c} {f e}} {{b c} {f e}}}
397 test lset-11.6 {lset, not compiled, 2-d basics} {
399 list [eval [list $lset a {1 0} f]] $a
400 } {{{b c} {f e}} {{b c} {f e}}}
402 test lset-11.7 {lset, not compiled, 2-d basics} {
404 list [eval [list $lset a 1 1 f]] $a
405 } {{{b c} {d f}} {{b c} {d f}}}
407 test lset-11.8 {lset, not compiled, 2-d basics} {
409 list [eval [list $lset a {1 1} f]] $a
410 } {{{b c} {d f}} {{b c} {d f}}}
412 test lset-12.0 {lset, not compiled, typical sharing pattern} {
414 set row [list $zero $zero $zero $zero]
415 set ident [list $row $row $row $row]
416 for { set i 0 } { $i < 4 } { incr i } {
417 eval [list $lset ident $i $i 1]
420 } {{1 0 0 0} {0 1 0 0} {0 0 1 0} {0 0 0 1}}
422 test lset-13.0 {lset, not compiled, shimmering hell} {
424 list [eval [list $lset a $a $a $a $a {gag me}]] $a
425 } {{{{{{gag me}}}}} {{{{{gag me}}}}}}
427 test lset-13.1 {lset, not compiled, shimmering hell} {
429 list [eval [list $lset a $a $a $a $a {gag me}]] $a
430 } {{{{{{gag me}}}}} {{{{{gag me}}}}}}
432 test lset-13.2 {lset, not compiled, shimmering hell} {
434 list [eval [list $lset a $a {gag me}]] $a
435 } {{{{{{gag me}}}} 0 0 0} {{{{{gag me}}}} 0 0 0}}
437 test lset-14.1 {lset, not compiled, list args, is string rep preserved?} {
438 set a { { 1 2 } { 3 4 } }
439 catch { eval [list $lset a {1 5} 5] }
440 list $a [lindex $a 1]
441 } "{ { 1 2 } { 3 4 } } { 3 4 }"
443 test lset-14.2 {lset, not compiled, flat args, is string rep preserved?} {
444 set a { { 1 2 } { 3 4 } }
445 catch { eval [list $lset a 1 5 5] }
446 list $a [lindex $a 1]
447 } "{ { 1 2 } { 3 4 } } { 3 4 }"
450 catch {unset noWrite}
451 catch {rename failTrace {}}
456 ::tcltest::cleanupTests