1 # This file contains a collection of tests for the procedures in the file
2 # tclCmdIL.c. Sourcing this file into Tcl runs the tests and generates output
3 # for errors. No output means no errors were found.
5 # Copyright (c) 1997 Sun Microsystems, Inc.
6 # Copyright (c) 1998-1999 by Scriptics Corporation.
8 # See the file "license.terms" for information on usage and redistribution of
9 # this file, and for a DISCLAIMER OF ALL WARRANTIES.
11 if {"::tcltest" ni [namespace children]} {
12 package require tcltest 2.5
13 namespace import -force ::tcltest::*
16 ::tcltest::loadTestedCommands
17 catch [list package require -exact Tcltest [info patchlevel]]
19 # Used for constraining memory leak tests
20 testConstraint memory [llength [info commands memory]]
21 testConstraint testobj [llength [info commands testobj]]
22 source [file join [file dirname [info script]] internals.tcl]
23 namespace import -force ::tcltest::internals::*
25 test cmdIL-1.1 {Tcl_LsortObjCmd procedure} -returnCodes error -body {
27 } -result {wrong # args: should be "lsort ?-option value ...? list"}
28 test cmdIL-1.2 {Tcl_LsortObjCmd procedure} -returnCodes error -body {
30 } -result {bad option "-foo": must be -ascii, -command, -decreasing, -dictionary, -increasing, -index, -indices, -integer, -nocase, -real, -stride, or -unique}
31 test cmdIL-1.3 {Tcl_LsortObjCmd procedure, default options} {
32 lsort {d e c b a \{ d35 d300}
33 } {a b c d d300 d35 e \{}
34 test cmdIL-1.4 {Tcl_LsortObjCmd procedure, -ascii option} {
35 lsort -integer -ascii {d e c b a d35 d300}
36 } {a b c d d300 d35 e}
37 test cmdIL-1.5 {Tcl_LsortObjCmd procedure, -command option} -body {
38 lsort -command {1 3 2 5}
39 } -returnCodes error -result {"-command" option must be followed by comparison command}
40 test cmdIL-1.6 {Tcl_LsortObjCmd procedure, -command option} -setup {
42 expr {[string match x* $b] - [string match x* $a]}
45 lsort -command cmp {x1 abc x2 def x3 x4}
46 } -result {x1 x2 x3 x4 abc def} -cleanup {
49 test cmdIL-1.7 {Tcl_LsortObjCmd procedure, -decreasing option} {
50 lsort -decreasing {d e c b a d35 d300}
51 } {e d35 d300 d c b a}
52 test cmdIL-1.8 {Tcl_LsortObjCmd procedure, -dictionary option} {
53 lsort -dictionary {d e c b a d35 d300}
54 } {a b c d d35 d300 e}
55 test cmdIL-1.9 {Tcl_LsortObjCmd procedure, -dictionary option} {
56 lsort -dictionary {1k 0k 10k}
58 test cmdIL-1.10 {Tcl_LsortObjCmd procedure, -increasing option} {
59 lsort -decreasing -increasing {d e c b a d35 d300}
60 } {a b c d d300 d35 e}
61 test cmdIL-1.11 {Tcl_LsortObjCmd procedure, -index option} -body {
62 lsort -index {1 3 2 5}
63 } -returnCodes error -result {"-index" option must be followed by list index}
64 test cmdIL-1.12 {Tcl_LsortObjCmd procedure, -index option} -body {
65 lsort -index foo {1 3 2 5}
66 } -returnCodes error -result {bad index "foo": must be integer?[+-]integer? or end?[+-]integer?}
67 test cmdIL-1.13 {Tcl_LsortObjCmd procedure, -index option} {
68 lsort -index end -integer {{2 25} {10 20 50 100} {3 16 42} 1}
69 } {1 {2 25} {3 16 42} {10 20 50 100}}
70 test cmdIL-1.14 {Tcl_LsortObjCmd procedure, -index option} {
71 lsort -index 1 -integer {{1 25 100} {3 16 42} {10 20 50}}
72 } {{3 16 42} {10 20 50} {1 25 100}}
73 test cmdIL-1.15 {Tcl_LsortObjCmd procedure, -integer option} {
74 lsort -integer {24 6 300 18}
76 test cmdIL-1.16 {Tcl_LsortObjCmd procedure, -integer option} -body {
77 lsort -integer {1 3 2.4}
78 } -returnCodes error -result {expected integer but got "2.4"}
79 test cmdIL-1.17 {Tcl_LsortObjCmd procedure, -real option} {
80 lsort -real {24.2 6e3 150e-1}
82 test cmdIL-1.18 {Tcl_LsortObjCmd procedure, bogus list} -body {
84 } -returnCodes error -result {unmatched open brace in list}
85 test cmdIL-1.19 {Tcl_LsortObjCmd procedure, empty list} {
88 test cmdIL-1.22 {Tcl_LsortObjCmd procedure, unique sort} {
89 lsort -integer -unique {3 1 2 3 1 4 3}
91 test cmdIL-1.23 {Tcl_LsortObjCmd procedure, unique sort with index} {
92 # lsort -unique should return the last unique item
93 lsort -unique -index 0 {{a b} {c b} {a c} {d a}}
95 test cmdIL-1.24 {Tcl_LsortObjCmd procedure, order of -index and -command} -setup {
97 proc testcmp {a b} {return [string compare $a $b]}
99 set l [list [list a b] [list c d]]
100 lsort -command testcmp -index 1 $l
103 } -result [list [list a b] [list c d]]
104 test cmdIL-1.25 {Tcl_LsortObjCmd procedure, order of -index and -command} -setup {
106 proc testcmp {a b} {return [string compare $a $b]}
108 set l [list [list a b] [list c d]]
109 lsort -index 1 -command testcmp $l
112 } -result [list [list a b] [list c d]]
113 # Note that the required order only exists in the end-1'th element; indexing
114 # using the end element or any fixed offset from the start will not work...
115 test cmdIL-1.26 {Tcl_LsortObjCmd procedure, offset indexing from end} {
116 lsort -index end-1 {{a 1 e i} {b 2 3 f g} {c 4 5 6 d h}}
117 } {{c 4 5 6 d h} {a 1 e i} {b 2 3 f g}}
118 test cmdIL-1.27 {Tcl_LsortObjCmd procedure, returning indices} {
119 lsort -indices {a c b}
121 test cmdIL-1.28 {Tcl_LsortObjCmd procedure, returning indices} {
122 lsort -indices -unique -decreasing -real {1.2 34.5 34.5 5.6}
124 test cmdIL-1.29 {Tcl_LsortObjCmd procedure, loss of list rep during sorting} {
126 string length [lsort -command {apply {args {string length $::l}}} $l]
128 test cmdIL-1.30 {Tcl_LsortObjCmd procedure, -stride option} {
129 lsort -stride 2 {f e d c b a}
131 test cmdIL-1.31 {Tcl_LsortObjCmd procedure, -stride option} {
132 lsort -stride 3 {f e d c b a}
134 test cmdIL-1.32 {lsort -stride errors} -returnCodes error -body {
135 lsort -stride foo bar
136 } -result {expected integer but got "foo"}
137 test cmdIL-1.33 {lsort -stride errors} -returnCodes error -body {
139 } -result {stride length must be at least 2}
140 test cmdIL-1.34 {lsort -stride errors} -returnCodes error -body {
141 lsort -stride 2 {a b c}
142 } -result {list size must be a multiple of the stride length}
143 test cmdIL-1.35 {lsort -stride errors} -returnCodes error -body {
144 lsort -stride 2 -index 3 {a b c d}
145 } -result {when used with "-stride", the leading "-index" value must be within the group}
146 test cmdIL-1.36 {lsort -stride and -index: Bug 2918962} {
147 lsort -stride 2 -index {0 1} {
148 {{c o d e} 54321} {{b l a h} 94729}
149 {{b i g} 12345} {{d e m o} 34512}
151 } {{{b i g} 12345} {{d e m o} 34512} {{c o d e} 54321} {{b l a h} 94729}}
152 test cmdIL-1.41 {lsort -stride and -index} -body {
153 lsort -stride 2 -index -2 {a 2 b 1}
154 } -returnCodes error -result {index "-2" cannot select an element from any list}
155 test cmdIL-1.42 {lsort -stride and-index} -body {
156 lsort -stride 2 -index -1-1 {a 2 b 1}
157 } -returnCodes error -result {index "-1-1" cannot select an element from any list}
159 # Can't think of any good tests for the MergeSort and MergeLists procedures,
160 # except a bunch of random lists to sort.
162 test cmdIL-2.1 {MergeSort and MergeLists procedures} -setup {
167 set r [expr {(16807 * $r) % (0x7fffffff)}]
170 for {set i 0} {$i < 150} {incr i} {
172 for {set j 0} {$j < $i} {incr j} {
173 lappend x [expr {[rand] & 0xfff}]
175 set y [lsort -integer $x]
179 append result "list {$x} sorted to {$y}, element $el out of order\n"
190 test cmdIL-3.1 {SortCompare procedure, skip comparisons after error} -body {
193 lsort -integer -command {apply {{a b} {
196 }}} {48 6 28 190 16 2 3 6 1}
198 } -result {1 {error #1} 1}
199 test cmdIL-3.2 {SortCompare procedure, -index option} -body {
200 lsort -integer -index 2 "\\\{ {30 40 50}"
201 } -returnCodes error -result {unmatched open brace in list}
202 test cmdIL-3.3 {SortCompare procedure, -index option} -body {
203 lsort -integer -index 2 {{20 10} {15 30 40}}
204 } -returnCodes error -result {element 2 missing from sublist "20 10"}
205 test cmdIL-3.4 {SortCompare procedure, -index option} -body {
206 lsort -integer -index 2 "{a b c} \\\{"
207 } -returnCodes error -result {expected integer but got "c"}
208 test cmdIL-3.4.1 {SortCompare procedure, -index option} -body {
209 lsort -integer -index 2 "{1 2 3} \\\{"
210 } -returnCodes error -result {unmatched open brace in list}
211 test cmdIL-3.5 {SortCompare procedure, -index option} -body {
212 lsort -integer -index 2 {{20 10 13} {15}}
213 } -returnCodes error -result {element 2 missing from sublist "15"}
214 test cmdIL-3.5.1 {SortCompare procedure, -index option (out of range, calculated index)} -body {
215 lsort -index 1+3 {{1 . c} {2 . b} {3 . a}}
216 } -returnCodes error -result {element 4 missing from sublist "1 . c"}
217 test cmdIL-3.5.2 {SortCompare procedure, -index option (out of range, calculated index)} -body {
218 lsort -index -1-1 {{1 . c} {2 . b} {3 . a}}
219 } -returnCodes error -result {index "-1-1" cannot select an element from any list}
220 test cmdIL-3.5.3 {SortCompare procedure, -index option (out of range, calculated index)} -body {
221 lsort -index -2 {{1 . c} {2 . b} {3 . a}}
222 } -returnCodes error -result {index "-2" cannot select an element from any list}
223 test cmdIL-3.5.4 {SortCompare procedure, -index option (out of range, calculated index)} -body {
224 lsort -index end-4 {{1 . c} {2 . b} {3 . a}}
225 } -returnCodes error -result {element -2 missing from sublist "1 . c"}
226 test cmdIL-3.5.5 {SortCompare procedure, -index option} {
227 lsort -index {} {a b}
229 test cmdIL-3.5.6 {SortCompare procedure, -index option} {
230 lsort -index {} [list a \{]
232 test cmdIL-3.5.7 {SortCompare procedure, -index option (out of range, calculated index)} -body {
233 lsort -index end--1 {{1 . c} {2 . b} {3 . a}}
234 } -returnCodes error -result {index "end--1" cannot select an element from any list}
235 test cmdIL-3.5.8 {SortCompare procedure, -index option (out of range, calculated index)} -body {
236 lsort -index end+1 {{1 . c} {2 . b} {3 . a}}
237 } -returnCodes error -result {index "end+1" cannot select an element from any list}
238 test cmdIL-3.5.9 {SortCompare procedure, -index option (out of range, calculated index)} -body {
239 lsort -index end+2 {{1 . c} {2 . b} {3 . a}}
240 } -returnCodes error -result {index "end+2" cannot select an element from any list}
241 test cmdIL-3.6 {SortCompare procedure, -index option} {
242 lsort -integer -index 2 {{1 15 30} {2 5 25} {3 25 20}}
243 } {{3 25 20} {2 5 25} {1 15 30}}
244 test cmdIL-3.7 {SortCompare procedure, -ascii option} {
245 lsort -ascii {d e c b a d35 d300 100 20}
246 } {100 20 a b c d d300 d35 e}
247 test cmdIL-3.8 {SortCompare procedure, -dictionary option} {
248 lsort -dictionary {d e c b a d35 d300 100 20}
249 } {20 100 a b c d d35 d300 e}
250 test cmdIL-3.9 {SortCompare procedure, -integer option} -body {
252 } -returnCodes error -result {expected integer but got "x"}
253 test cmdIL-3.10 {SortCompare procedure, -integer option} -body {
255 } -returnCodes error -result {expected integer but got "q"}
256 test cmdIL-3.11 {SortCompare procedure, -integer option} {
257 lsort -integer {35 21 0x20 30 0o23 100 8}
258 } {8 0o23 21 30 0x20 35 100}
259 test cmdIL-3.12 {SortCompare procedure, -real option} -body {
260 lsort -real {6...4 3}
261 } -returnCodes error -result {expected floating-point number but got "6...4"}
262 test cmdIL-3.13 {SortCompare procedure, -real option} -body {
264 } -returnCodes error -result {expected floating-point number but got "1x7"}
265 test cmdIL-3.14 {SortCompare procedure, -real option} {
266 lsort -real {24 2.5e01 16.7 85e-1 10.004}
267 } {85e-1 10.004 16.7 24 2.5e01}
268 test cmdIL-3.15 {SortCompare procedure, -command option} -body {
270 error "comparison error"
272 list [catch {lsort -command cmp {48 6}} msg] $msg $::errorInfo
275 } -result {1 {comparison error} {comparison error
277 "error "comparison error""
278 (procedure "cmp" line 2)
283 "lsort -command cmp {48 6}"}}
284 test cmdIL-3.16 {SortCompare procedure, -command option, long command} -body {
285 proc cmp {dummy a b} {
288 lsort -command {cmp {this argument is very very long in order to make the dstring overflow its statically allocated space}} {{this first element is also long in order to help expand the dstring} {the second element, last but not least, is quite long also, in order to make absolutely sure that space is allocated dynamically for the dstring}}
291 } -result {{the second element, last but not least, is quite long also, in order to make absolutely sure that space is allocated dynamically for the dstring} {this first element is also long in order to help expand the dstring}}
292 test cmdIL-3.17 {SortCompare procedure, -command option, non-integer result} -body {
296 lsort -command cmp {48 6}
297 } -returnCodes error -cleanup {
299 } -result {-compare command returned non-integer result}
300 test cmdIL-3.18 {SortCompare procedure, -command option} -body {
304 lsort -command cmp {48 6 18 22 21 35 36}
307 } -result {48 36 35 22 21 18 6}
308 test cmdIL-3.19 {SortCompare procedure, -decreasing option} {
309 lsort -decreasing -integer {35 21 0x20 30 0o23 100 8}
310 } {100 35 0x20 30 21 0o23 8}
312 test cmdIL-4.1 {DictionaryCompare procedure, numerics, leading zeros} {
313 lsort -dictionary {a003b a03b}
315 test cmdIL-4.2 {DictionaryCompare procedure, numerics, leading zeros} {
316 lsort -dictionary {a3b a03b}
318 test cmdIL-4.3 {DictionaryCompare procedure, numerics, leading zeros} {
319 lsort -dictionary {a3b A03b}
321 test cmdIL-4.4 {DictionaryCompare procedure, numerics, leading zeros} {
322 lsort -dictionary {a3b a03B}
324 test cmdIL-4.5 {DictionaryCompare procedure, numerics, leading zeros} {
325 lsort -dictionary {00000 000}
327 test cmdIL-4.6 {DictionaryCompare procedure, numerics, different lengths} {
328 lsort -dictionary {a321b a03210b}
330 test cmdIL-4.7 {DictionaryCompare procedure, numerics, different lengths} {
331 lsort -dictionary {a03210b a321b}
333 test cmdIL-4.8 {DictionaryCompare procedure, numerics} {
334 lsort -dictionary {48 6a 18b 22a 21aa 35 36}
335 } {6a 18b 21aa 22a 35 36 48}
336 test cmdIL-4.9 {DictionaryCompare procedure, numerics} {
337 lsort -dictionary {a123x a123b}
339 test cmdIL-4.10 {DictionaryCompare procedure, numerics} {
340 lsort -dictionary {a123b a123x}
342 test cmdIL-4.11 {DictionaryCompare procedure, numerics} {
343 lsort -dictionary {a1b aab}
345 test cmdIL-4.12 {DictionaryCompare procedure, numerics} {
346 lsort -dictionary {a1b a!b}
348 test cmdIL-4.13 {DictionaryCompare procedure, numerics} {
349 lsort -dictionary {a1b2c a1b1c}
351 test cmdIL-4.14 {DictionaryCompare procedure, numerics} {
352 lsort -dictionary {a1b2c a1b3c}
354 test cmdIL-4.15 {DictionaryCompare procedure, long numbers} {
355 lsort -dictionary {a7654884321988762b a7654884321988761b}
356 } {a7654884321988761b a7654884321988762b}
357 test cmdIL-4.16 {DictionaryCompare procedure, long numbers} {
358 lsort -dictionary {a8765488432198876b a7654884321988761b}
359 } {a7654884321988761b a8765488432198876b}
360 test cmdIL-4.17 {DictionaryCompare procedure, case} {
361 lsort -dictionary {aBCd abcc}
363 test cmdIL-4.18 {DictionaryCompare procedure, case} {
364 lsort -dictionary {aBCd abce}
366 test cmdIL-4.19 {DictionaryCompare procedure, case} {
367 lsort -dictionary {abcd ABcc}
369 test cmdIL-4.20 {DictionaryCompare procedure, case} {
370 lsort -dictionary {abcd ABce}
372 test cmdIL-4.21 {DictionaryCompare procedure, case} {
373 lsort -dictionary {abCD ABcd}
375 test cmdIL-4.22 {DictionaryCompare procedure, case} {
376 lsort -dictionary {ABcd aBCd}
378 test cmdIL-4.23 {DictionaryCompare procedure, case} {
379 lsort -dictionary {ABcd AbCd}
381 test cmdIL-4.24 {DictionaryCompare procedure, international characters} {hasIsoLocale} {
382 ::tcltest::set_iso8859_1_locale
383 set result [lsort -dictionary "a b c A B C \xe3 \xc4"]
384 ::tcltest::restore_locale
386 } "A a B b C c \xe3 \xc4"
387 test cmdIL-4.25 {DictionaryCompare procedure, international characters} {hasIsoLocale} {
388 ::tcltest::set_iso8859_1_locale
389 set result [lsort -dictionary "a23\xe3 a23\xc5 a23\xe4"]
390 ::tcltest::restore_locale
392 } "a23\xe3 a23\xe4 a23\xc5"
393 test cmdIL-4.26 {DefaultCompare procedure, signed characters} {
394 set l [lsort [list "abc\200" "abc"]]
398 set len [string length $s]
399 for {set i 0} {$i < $len} {incr i} {
400 set c [string index $s $i]
402 if {$d > 0 && $d < 128} {
405 append viewelem "\\[format %03o $d]"
408 lappend viewlist $viewelem
411 } [list "abc" "abc\\200"]
412 test cmdIL-4.27 {DictionaryCompare procedure, signed characters} {
413 set l [lsort -dictionary [list "abc\200" "abc"]]
417 set len [string length $s]
418 for {set i 0} {$i < $len} {incr i} {
419 set c [string index $s $i]
421 if {$d > 0 && $d < 128} {
424 append viewelem "\\[format %03o $d]"
427 lappend viewlist $viewelem
430 } [list "abc" "abc\\200"]
431 test cmdIL-4.28 {DictionaryCompare procedure, chars between Z and a in ASCII} {
432 lsort -dictionary [list AA ` c CC]
434 test cmdIL-4.29 {DictionaryCompare procedure, chars between Z and a in ASCII} {
435 lsort -dictionary [list AA ` c ^ \\ CC \[ \]]
436 } [list \[ \\ \] ^ ` AA c CC]
437 test cmdIL-4.30 {DictionaryCompare procedure, chars between Z and a in ASCII} {
438 lsort -dictionary [list AA ` c ^ _ \\ CC \[ dude \] funky]
439 } [list \[ \\ \] ^ _ ` AA c CC dude funky]
440 test cmdIL-4.31 {DictionaryCompare procedure, chars between Z and a in ASCII} {
441 lsort -dictionary [list AA c ` CC]
443 test cmdIL-4.32 {DictionaryCompare procedure, chars between Z and a in ASCII} {
444 lsort -dictionary [list AA c CC `]
446 test cmdIL-4.33 {DictionaryCompare procedure, chars between Z and a in ASCII} {
447 lsort -dictionary [list AA ! c CC `]
449 test cmdIL-4.34 {SortCompare procedure, -ascii option with -nocase option} {
450 lsort -ascii -nocase {d e c b a d35 d300 100 20}
451 } {100 20 a b c d d300 d35 e}
452 test cmdIL-4.35 {SortCompare procedure, -ascii option with -nocase option} {
453 lsort -ascii -nocase {d E c B a D35 d300 100 20}
454 } {100 20 a B c d d300 D35 E}
455 test cmdIL-4.36 {SortCompare procedure, UTF-8 with -nocase option} {
456 scan [lsort -ascii -nocase [list \u101 \u100]] %c%c%c
458 test cmdIL-4.37 {SortCompare procedure, UTF-8 with -nocase option} {
459 scan [lsort -ascii -nocase [list a\u0000a a]] %c%c%c%c%c
461 test cmdIL-4.38 {SortCompare procedure, UTF-8 with -nocase option} {
462 scan [lsort -ascii -nocase [list a a\u0000a]] %c%c%c%c%c
465 test cmdIL-5.1 {lsort with list style index} {
466 lsort -ascii -decreasing -index {0 1} {
467 {{Jim Alpha} 20000410}
468 {{Joe Bravo} 19990320}
469 {{Jacky Charlie} 19390911}
471 } {{{Jacky Charlie} 19390911} {{Joe Bravo} 19990320} {{Jim Alpha} 20000410}}
472 test cmdIL-5.2 {lsort with list style index} {
473 lsort -decreasing -index {0 1} {
474 {{Jim Alpha} 20000410}
475 {{Joe Bravo} 19990320}
476 {{Jacky Charlie} 19390911}
478 } {{{Jacky Charlie} 19390911} {{Joe Bravo} 19990320} {{Jim Alpha} 20000410}}
479 test cmdIL-5.3 {lsort with list style index} {
480 lsort -integer -increasing -index {1 end} {
481 {{Jim Alpha} 20000410}
482 {{Joe Bravo} 19990320}
483 {{Jacky Charlie} 19390911}
485 } {{{Jacky Charlie} 19390911} {{Joe Bravo} 19990320} {{Jim Alpha} 20000410}}
486 test cmdIL-5.4 {lsort with list style index} {
487 lsort -integer -index {1 end-1} {
488 {the {0 1 2 3 4 5} quick}
489 {brown {0 1 2 3 4} fox}
490 {jumps {30 31 2 33} over}
494 } {{dogs {0 1}} {the {0 1 2} lazy} {jumps {30 31 2 33} over} {brown {0 1 2 3 4} fox} {the {0 1 2 3 4 5} quick}}
495 test cmdIL-5.5 {lsort with list style index and sharing} -body {
496 proc test_lsort {l} {
498 foreach e $l {lappend n [list [expr {rand()}] $e]}
499 lindex [lsort -real -index $l $n] 1 1
503 } -result 0 -cleanup {
506 test cmdIL-5.6 {lsort with multiple list-style index options} {
507 lsort -index {1 2 3} -index 0 {{a b} {c d} {b e}}
508 } {{a b} {b e} {c d}}
509 test cmdIL-5.7 {lsort memory exhaustion} -constraints {testWithLimit} -body {
510 # test it in child process (with limited address space) ca. 80MB extra memory
511 # on x64 system it would be not enough to sort 4M items (the half 2M only),
512 # warn and skip if no error (enough memory) or error by list creation:
514 -warn-on-code 0 -warn-on-alloc-error 1 \
515 -addmem [expr {$tcl_platform(pointerSize)*4000000 + $tcl_platform(pointerSize)*3*2000000}] \
517 # create list and get length (avoid too long output in interactive shells):
518 llength [set l [lrepeat 4000000 ""]]
522 # expecting error no memory by sort
523 } -returnCodes 1 -result {no enough memory to proccess sort of 4000000 items}
526 test cmdIL-6.1 {lassign command syntax} -returnCodes error -body {
527 apply {{} { lassign }}
528 } -result {wrong # args: should be "lassign list ?varName ...?"}
529 test cmdIL-6.2 {lassign command syntax} {
530 apply {{} { lassign x }}
532 test cmdIL-6.3 {lassign command} -body {
535 list [lassign a x] $x
538 test cmdIL-6.4 {lassign command} -body {
542 list [lassign a x y] $x $y
545 test cmdIL-6.5 {lassign command} -body {
549 list [lassign {a b} x y] $x $y
552 test cmdIL-6.6 {lassign command} -body {
556 list [lassign {a b c} x y] $x $y
559 test cmdIL-6.7 {lassign command} -body {
563 list [lassign {a b c d} x y] $x $y
565 } -result {{c d} a b}
566 test cmdIL-6.8 {lassign command - list format error} -body {
570 list [catch {lassign {a {b}c d} x y} msg] $msg $x $y
572 } -result {1 {list element in braces followed by "c" instead of space} FAIL FAIL}
573 test cmdIL-6.9 {lassign command - assignment to arrays} -body {
575 list [lassign {a b} x(x)] $x(x)
578 test cmdIL-6.10 {lassign command - variable update error} -body {
583 } -returnCodes error -result {can't set "x": variable is array}
584 test cmdIL-6.11 {lassign command - variable update error} -body {
588 list [catch {lassign a y x} msg] $msg $y
590 } -result {1 {can't set "x": variable is array} a}
591 test cmdIL-6.12 {lassign command - memory leak testing} -setup {
592 unset -nocomplain x y
596 set lines [split [memory info] "\n"]
597 lindex [lindex $lines 3] 3
601 lassign {} y y y y y y y y y y y y y y y y y y y y y y y y y y y y y y
602 catch {lassign {} y y y y y y y y y y y y y y y y y y y y y y y y y x}
605 } -constraints memory -body {
607 for {set i 0} {$i < 5} {incr i} {
613 } -result 0 -cleanup {
614 unset -nocomplain x y i tmp end
618 # Force non-compiled version
619 test cmdIL-6.13 {lassign command syntax} -returnCodes error -body {
624 } -result {wrong # args: should be "lassign list ?varName ...?"}
625 test cmdIL-6.14 {lassign command syntax} {
631 test cmdIL-6.15 {lassign command} -body {
635 list [$lassign a x] $x
638 test cmdIL-6.16 {lassign command} -body {
643 list [$lassign a x y] $x $y
646 test cmdIL-6.17 {lassign command} -body {
651 list [$lassign {a b} x y] $x $y
654 test cmdIL-6.18 {lassign command} -body {
659 list [$lassign {a b c} x y] $x $y
662 test cmdIL-6.19 {lassign command} -body {
667 list [$lassign {a b c d} x y] $x $y
669 } -result {{c d} a b}
670 test cmdIL-6.20 {lassign command - list format error} -body {
675 list [catch {$lassign {a {b}c d} x y} msg] $msg $x $y
677 } -result {1 {list element in braces followed by "c" instead of space} FAIL FAIL}
678 test cmdIL-6.21 {lassign command - assignment to arrays} -body {
681 list [$lassign {a b} x(x)] $x(x)
684 test cmdIL-6.22 {lassign command - variable update error} -body {
690 } -returnCodes 1 -result {can't set "x": variable is array}
691 test cmdIL-6.23 {lassign command - variable update error} -body {
696 list [catch {$lassign a y x} msg] $msg $y
698 } -result {1 {can't set "x": variable is array} a}
699 test cmdIL-6.24 {lassign command - memory leak testing} -setup {
703 set lines [split [memory info] "\n"]
704 lindex [lindex $lines 3] 3
709 $lassign {} y y y y y y y y y y y y y y y y y y y y y y y y y y y y y y
710 catch {$lassign {} y y y y y y y y y y y y y y y y y y y y y y y y y x}
711 catch {$lassign {} x}
713 } -constraints memory -body {
715 for {set i 0} {$i < 5} {incr i} {
721 } -result 0 -cleanup {
722 unset -nocomplain x y i tmp end
726 # Assorted shimmering problems
727 test cmdIL-6.25 {lassign command - shimmering protection} -body {
730 list [lassign $x $x y] $x [set $x] $y
732 } -result {c {a b c} a b}
733 test cmdIL-6.26 {lassign command - shimmering protection} -body {
737 list [$lassign $x $x y] $x [set $x] $y
739 } -result {c {a b c} a b}
741 test cmdIL-7.1 {lreverse command} -body {
743 } -returnCodes error -result "wrong # args: should be \"lreverse list\""
744 test cmdIL-7.2 {lreverse command} -body {
746 } -returnCodes error -result "wrong # args: should be \"lreverse list\""
747 test cmdIL-7.3 {lreverse command} -body {
748 lreverse "not \{a list"
749 } -returnCodes error -result {unmatched open brace in list}
750 test cmdIL-7.4 {lreverse command - shared object} {
751 set x {a b {c d} e f}
754 test cmdIL-7.5 {lreverse command - unshared object} {
755 lreverse [list a b {c d} e f]
757 test cmdIL-7.6 {lreverse command - unshared object [Bug 1672585]} {
758 lreverse [set x {1 2 3}][unset x]
760 test cmdIL-7.7 {lreverse command - empty object [Bug 1876793]} {
763 test cmdIL-7.8 {lreverse command - shared internalrep [Bug 1675044]} -setup {
764 teststringobj set 1 {1 2 3}
765 testobj convert 1 list
766 testobj duplicate 1 2
767 variable x [teststringobj get 1]
768 variable y [teststringobj get 2]
770 proc K {a b} {return $a}
771 } -constraints testobj -body {
772 lreverse [K $y [unset y]]
775 unset -nocomplain x y
779 # This belongs in info test, but adding tests there breaks tests
780 # that compute source file line numbers.
781 test info-20.6 {Bug 3587651} -setup {
782 namespace eval my {namespace eval tcl {namespace eval mathfunc {
783 proc demo x {return 42}
784 }}}} -body { namespace eval my {expr {"demo" in [info functions]}}} -cleanup {
790 ::tcltest::cleanupTests