OSDN Git Service

Please enter the commit message for your changes. Lines starting
[eos/base.git] / util / src / TclTk / tcl8.6.12 / tests / cmdIL.test
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.
4 #
5 # Copyright (c) 1997 Sun Microsystems, Inc.
6 # Copyright (c) 1998-1999 by Scriptics Corporation.
7 #
8 # See the file "license.terms" for information on usage and redistribution of
9 # this file, and for a DISCLAIMER OF ALL WARRANTIES.
10
11 if {"::tcltest" ni [namespace children]} {
12     package require tcltest 2.5
13     namespace import -force ::tcltest::*
14 }
15
16 ::tcltest::loadTestedCommands
17 catch [list package require -exact Tcltest [info patchlevel]]
18
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::*
24
25 test cmdIL-1.1 {Tcl_LsortObjCmd procedure} -returnCodes error -body {
26     lsort
27 } -result {wrong # args: should be "lsort ?-option value ...? list"}
28 test cmdIL-1.2 {Tcl_LsortObjCmd procedure} -returnCodes error -body {
29     lsort -foo {1 3 2 5}
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 {
41     proc cmp {a b} {
42         expr {[string match x* $b] - [string match x* $a]}
43     }
44 } -body {
45     lsort -command cmp {x1 abc x2 def x3 x4}
46 } -result {x1 x2 x3 x4 abc def} -cleanup {
47     rename cmp ""
48 }
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}
57 } {0k 1k 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}
75 } {6 18 24 300}
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}
81 } {150e-1 24.2 6e3}
82 test cmdIL-1.18 {Tcl_LsortObjCmd procedure, bogus list} -body {
83     lsort "1 2 3 \{ 4"
84 } -returnCodes error -result {unmatched open brace in list}
85 test cmdIL-1.19 {Tcl_LsortObjCmd procedure, empty list} {
86     lsort {}
87 } {}
88 test cmdIL-1.22 {Tcl_LsortObjCmd procedure, unique sort} {
89     lsort -integer -unique {3 1 2 3 1 4 3}
90 } {1 2 3 4}
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}}
94 } {{a c} {c b} {d a}}
95 test cmdIL-1.24 {Tcl_LsortObjCmd procedure, order of -index and -command} -setup {
96     catch {rename 1 ""}
97     proc testcmp {a b} {return [string compare $a $b]}
98 } -body {
99     set l [list [list a b] [list c d]]
100     lsort -command testcmp -index 1 $l
101 } -cleanup {
102     rename testcmp ""
103 } -result [list [list a b] [list c d]]
104 test cmdIL-1.25 {Tcl_LsortObjCmd procedure, order of -index and -command} -setup {
105     catch {rename 1 ""}
106     proc testcmp {a b} {return [string compare $a $b]}
107 } -body {
108     set l [list [list a b] [list c d]]
109     lsort -index 1 -command testcmp $l
110 } -cleanup {
111     rename testcmp ""
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}
120 } {0 2 1}
121 test cmdIL-1.28 {Tcl_LsortObjCmd procedure, returning indices} {
122     lsort -indices -unique -decreasing -real {1.2 34.5 34.5 5.6}
123 } {2 3 0}
124 test cmdIL-1.29 {Tcl_LsortObjCmd procedure, loss of list rep during sorting} {
125     set l {1 2 3}
126     string length [lsort -command {apply {args {string length $::l}}} $l]
127 } 5
128 test cmdIL-1.30 {Tcl_LsortObjCmd procedure, -stride option} {
129     lsort -stride 2 {f e d c b a}
130 } {b a d c f e}
131 test cmdIL-1.31 {Tcl_LsortObjCmd procedure, -stride option} {
132     lsort -stride 3 {f e d c b a}
133 } {c b a f e d}
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 {
138     lsort -stride 1 bar
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}
150     }
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}
158
159 # Can't think of any good tests for the MergeSort and MergeLists procedures,
160 # except a bunch of random lists to sort.
161
162 test cmdIL-2.1 {MergeSort and MergeLists procedures} -setup {
163     set result {}
164     set r 1435753299
165     proc rand {} {
166         global r
167         set r [expr {(16807 * $r) % (0x7fffffff)}]
168     }
169 } -body {
170     for {set i 0} {$i < 150} {incr i} {
171         set x {}
172         for {set j 0} {$j < $i} {incr j} {
173             lappend x [expr {[rand] & 0xfff}]
174         }
175         set y [lsort -integer $x]
176         set old -1
177         foreach el $y {
178             if {$el < $old} {
179                 append result "list {$x} sorted to {$y}, element $el out of order\n"
180                 break
181             }
182             set old $el
183         }
184     }
185     string trim $result
186 } -cleanup {
187     rename rand ""
188 } -result {}
189
190 test cmdIL-3.1 {SortCompare procedure, skip comparisons after error} -body {
191     set ::x 0
192     list [catch {
193         lsort -integer -command {apply {{a b} {
194             incr ::x
195             error "error #$::x"
196         }}} {48 6 28 190 16 2 3 6 1}
197     } msg] $msg $::x
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}
228 } {a b}
229 test cmdIL-3.5.6 {SortCompare procedure, -index option} {
230     lsort -index {} [list a \{]
231 } {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 {
251     lsort -integer {x 3}
252 } -returnCodes error -result {expected integer but got "x"}
253 test cmdIL-3.10 {SortCompare procedure, -integer option} -body {
254     lsort -integer {3 q}
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 {
263     lsort -real {3 1x7}
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 {
269     proc cmp {a b} {
270         error "comparison error"
271     }
272     list [catch {lsort -command cmp {48 6}} msg] $msg $::errorInfo
273 } -cleanup {
274     rename cmp ""
275 } -result {1 {comparison error} {comparison error
276     while executing
277 "error "comparison error""
278     (procedure "cmp" line 2)
279     invoked from within
280 "cmp 48 6"
281     (-compare command)
282     invoked from within
283 "lsort -command cmp {48 6}"}}
284 test cmdIL-3.16 {SortCompare procedure, -command option, long command} -body {
285     proc cmp {dummy a b} {
286         string compare $a $b
287     }
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}}
289 } -cleanup {
290     rename cmp ""
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 {
293     proc cmp {a b} {
294         return foow
295     }
296     lsort -command cmp {48 6}
297 } -returnCodes error -cleanup {
298     rename cmp ""
299 } -result {-compare command returned non-integer result}
300 test cmdIL-3.18 {SortCompare procedure, -command option} -body {
301     proc cmp {a b} {
302         expr {$b - $a}
303     }
304     lsort -command cmp {48 6 18 22 21 35 36}
305 } -cleanup {
306     rename cmp ""
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}
311
312 test cmdIL-4.1 {DictionaryCompare procedure, numerics, leading zeros} {
313     lsort -dictionary {a003b a03b}
314 } {a03b a003b}
315 test cmdIL-4.2 {DictionaryCompare procedure, numerics, leading zeros} {
316     lsort -dictionary {a3b a03b}
317 } {a3b a03b}
318 test cmdIL-4.3 {DictionaryCompare procedure, numerics, leading zeros} {
319     lsort -dictionary {a3b A03b}
320 } {A03b a3b}
321 test cmdIL-4.4 {DictionaryCompare procedure, numerics, leading zeros} {
322     lsort -dictionary {a3b a03B}
323 } {a3b a03B}
324 test cmdIL-4.5 {DictionaryCompare procedure, numerics, leading zeros} {
325     lsort -dictionary {00000 000}
326 } {000 00000}
327 test cmdIL-4.6 {DictionaryCompare procedure, numerics, different lengths} {
328     lsort -dictionary {a321b a03210b}
329 } {a321b a03210b}
330 test cmdIL-4.7 {DictionaryCompare procedure, numerics, different lengths} {
331     lsort -dictionary {a03210b a321b}
332 } {a321b a03210b}
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}
338 } {a123b a123x}
339 test cmdIL-4.10 {DictionaryCompare procedure, numerics} {
340     lsort -dictionary {a123b a123x}
341 } {a123b a123x}
342 test cmdIL-4.11 {DictionaryCompare procedure, numerics} {
343     lsort -dictionary {a1b aab}
344 } {a1b aab}
345 test cmdIL-4.12 {DictionaryCompare procedure, numerics} {
346     lsort -dictionary {a1b a!b}
347 } {a!b a1b}
348 test cmdIL-4.13 {DictionaryCompare procedure, numerics} {
349     lsort -dictionary {a1b2c a1b1c}
350 } {a1b1c a1b2c}
351 test cmdIL-4.14 {DictionaryCompare procedure, numerics} {
352     lsort -dictionary {a1b2c a1b3c}
353 } {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}
362 } {abcc aBCd}
363 test cmdIL-4.18 {DictionaryCompare procedure, case} {
364     lsort -dictionary {aBCd abce}
365 } {aBCd abce}
366 test cmdIL-4.19 {DictionaryCompare procedure, case} {
367     lsort -dictionary {abcd ABcc}
368 } {ABcc abcd}
369 test cmdIL-4.20 {DictionaryCompare procedure, case} {
370     lsort -dictionary {abcd ABce}
371 } {abcd ABce}
372 test cmdIL-4.21 {DictionaryCompare procedure, case} {
373     lsort -dictionary {abCD ABcd}
374 } {ABcd abCD}
375 test cmdIL-4.22 {DictionaryCompare procedure, case} {
376     lsort -dictionary {ABcd aBCd}
377 } {ABcd aBCd}
378 test cmdIL-4.23 {DictionaryCompare procedure, case} {
379     lsort -dictionary {ABcd AbCd}
380 } {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
385     set result
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
391     set result
392 } "a23\xe3 a23\xe4 a23\xc5"
393 test cmdIL-4.26 {DefaultCompare procedure, signed characters} {
394     set l [lsort [list "abc\200" "abc"]]
395     set viewlist {}
396     foreach s $l {
397         set viewelem ""
398         set len [string length $s]
399         for {set i 0} {$i < $len} {incr i} {
400             set c [string index $s $i]
401             scan $c %c d
402             if {$d > 0 && $d < 128} {
403                 append viewelem $c
404             } else {
405                 append viewelem "\\[format %03o $d]"
406             }
407         }
408         lappend viewlist $viewelem
409     }
410     set viewlist
411 } [list "abc" "abc\\200"]
412 test cmdIL-4.27 {DictionaryCompare procedure, signed characters} {
413     set l [lsort -dictionary [list "abc\200" "abc"]]
414     set viewlist {}
415     foreach s $l {
416         set viewelem ""
417         set len [string length $s]
418         for {set i 0} {$i < $len} {incr i} {
419             set c [string index $s $i]
420             scan $c %c d
421             if {$d > 0 && $d < 128} {
422                 append viewelem $c
423             } else {
424                 append viewelem "\\[format %03o $d]"
425             }
426         }
427         lappend viewlist $viewelem
428     }
429     set viewlist
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]
433 } [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]
442 } [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 `]
445 } [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 `]
448 } [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
457 } {257 32 256}
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
460 } {97 32 97 0 97}
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
463 } {97 32 97 0 97}
464
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}
470     }
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}
477     }
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}
484     }
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}
491         {the {0 1 2} lazy}
492         {dogs {0 1}}
493     }
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} {
497         set n $l
498         foreach e $l {lappend n [list [expr {rand()}] $e]}
499         lindex [lsort -real -index $l $n] 1 1
500     }
501     expr {srand(1)}
502     test_lsort 0
503 } -result 0 -cleanup {
504     rename test_lsort ""
505 }
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:
513     testWithLimit \
514         -warn-on-code 0 -warn-on-alloc-error 1 \
515         -addmem [expr {$tcl_platform(pointerSize)*4000000 + $tcl_platform(pointerSize)*3*2000000}] \
516     {
517         # create list and get length (avoid too long output in interactive shells):
518         llength [set l [lrepeat 4000000 ""]]
519         # test OOM:
520         llength [lsort $l]
521     }
522     # expecting error no memory by sort
523 } -returnCodes 1 -result {no enough memory to proccess sort of 4000000 items}
524
525 # Compiled version
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 }}
531 } x
532 test cmdIL-6.3 {lassign command} -body {
533     apply {{} {
534         set x FAIL
535         list [lassign a x] $x
536     }}
537 } -result {{} a}
538 test cmdIL-6.4 {lassign command} -body {
539     apply {{} {
540         set x FAIL
541         set y FAIL
542         list [lassign a x y] $x $y
543     }}
544 } -result {{} a {}}
545 test cmdIL-6.5 {lassign command} -body {
546     apply {{} {
547         set x FAIL
548         set y FAIL
549         list [lassign {a b} x y] $x $y
550     }}
551 } -result {{} a b}
552 test cmdIL-6.6 {lassign command} -body {
553     apply {{} {
554         set x FAIL
555         set y FAIL
556         list [lassign {a b c} x y] $x $y
557     }}
558 } -result {c a b}
559 test cmdIL-6.7 {lassign command} -body {
560     apply {{} {
561         set x FAIL
562         set y FAIL
563         list [lassign {a b c d} x y] $x $y
564     }}
565 } -result {{c d} a b}
566 test cmdIL-6.8 {lassign command - list format error} -body {
567     apply {{} {
568         set x FAIL
569         set y FAIL
570         list [catch {lassign {a {b}c d} x y} msg] $msg $x $y
571     }}
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 {
574     apply {{} {
575         list [lassign {a b} x(x)] $x(x)
576     }}
577 } -result {b a}
578 test cmdIL-6.10 {lassign command - variable update error} -body {
579     apply {{} {
580         set x(x) {}
581         lassign a x
582     }}
583 } -returnCodes error -result {can't set "x": variable is array}
584 test cmdIL-6.11 {lassign command - variable update error} -body {
585     apply {{} {
586         set x(x) {}
587         set y FAIL
588         list [catch {lassign a y x} msg] $msg $y
589     }}
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
593     set x(x) {}
594     set y FAIL
595     proc getbytes {} {
596         set lines [split [memory info] "\n"]
597         lindex [lindex $lines 3] 3
598     }
599     proc stress {} {
600         global x y
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}
603         catch {lassign {} x}
604     }
605 } -constraints memory -body {
606     set end [getbytes]
607     for {set i 0} {$i < 5} {incr i} {
608         stress
609         set tmp $end
610         set end [getbytes]
611     }
612     expr {$end - $tmp}
613 } -result 0 -cleanup {
614     unset -nocomplain x y i tmp end
615     rename getbytes {}
616     rename stress {}
617 }
618 # Force non-compiled version
619 test cmdIL-6.13 {lassign command syntax} -returnCodes error -body {
620     apply {{} {
621         set lassign lassign
622         $lassign
623     }}
624 } -result {wrong # args: should be "lassign list ?varName ...?"}
625 test cmdIL-6.14 {lassign command syntax} {
626     apply {{} {
627         set lassign lassign
628         $lassign x
629     }}
630 } x
631 test cmdIL-6.15 {lassign command} -body {
632     apply {{} {
633         set lassign lassign
634         set x FAIL
635         list [$lassign a x] $x
636     }}
637 } -result {{} a}
638 test cmdIL-6.16 {lassign command} -body {
639     apply {{} {
640         set lassign lassign
641         set x FAIL
642         set y FAIL
643         list [$lassign a x y] $x $y
644     }}
645 } -result {{} a {}}
646 test cmdIL-6.17 {lassign command} -body {
647     apply {{} {
648         set lassign lassign
649         set x FAIL
650         set y FAIL
651         list [$lassign {a b} x y] $x $y
652     }}
653 } -result {{} a b}
654 test cmdIL-6.18 {lassign command} -body {
655     apply {{} {
656         set lassign lassign
657         set x FAIL
658         set y FAIL
659         list [$lassign {a b c} x y] $x $y
660     }}
661 } -result {c a b}
662 test cmdIL-6.19 {lassign command} -body {
663     apply {{} {
664         set lassign lassign
665         set x FAIL
666         set y FAIL
667         list [$lassign {a b c d} x y] $x $y
668     }}
669 } -result {{c d} a b}
670 test cmdIL-6.20 {lassign command - list format error} -body {
671     apply {{} {
672         set lassign lassign
673         set x FAIL
674         set y FAIL
675         list [catch {$lassign {a {b}c d} x y} msg] $msg $x $y
676     }}
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 {
679     apply {{} {
680         set lassign lassign
681         list [$lassign {a b} x(x)] $x(x)
682     }}
683 } -result {b a}
684 test cmdIL-6.22 {lassign command - variable update error} -body {
685     apply {{} {
686         set lassign lassign
687         set x(x) {}
688         $lassign a x
689     }}
690 } -returnCodes 1 -result {can't set "x": variable is array}
691 test cmdIL-6.23 {lassign command - variable update error} -body {
692     apply {{} {
693         set lassign lassign
694         set x(x) {}
695         set y FAIL
696         list [catch {$lassign a y x} msg] $msg $y
697     }}
698 } -result {1 {can't set "x": variable is array} a}
699 test cmdIL-6.24 {lassign command - memory leak testing} -setup {
700     set x(x) {}
701     set y FAIL
702     proc getbytes {} {
703         set lines [split [memory info] "\n"]
704         lindex [lindex $lines 3] 3
705     }
706     proc stress {} {
707         global x y
708         set lassign lassign
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}
712     }
713 } -constraints memory -body {
714     set end [getbytes]
715     for {set i 0} {$i < 5} {incr i} {
716         stress
717         set tmp $end
718         set end [getbytes]
719     }
720     expr {$end - $tmp}
721 } -result 0 -cleanup {
722     unset -nocomplain x y i tmp end
723     rename getbytes {}
724     rename stress {}
725 }
726 # Assorted shimmering problems
727 test cmdIL-6.25 {lassign command - shimmering protection} -body {
728     apply {{} {
729         set x {a b c}
730         list [lassign $x $x y] $x [set $x] $y
731     }}
732 } -result {c {a b c} a b}
733 test cmdIL-6.26 {lassign command - shimmering protection} -body {
734     apply {{} {
735         set x {a b c}
736         set lassign lassign
737         list [$lassign $x $x y] $x [set $x] $y
738     }}
739 } -result {c {a b c} a b}
740
741 test cmdIL-7.1 {lreverse command} -body {
742     lreverse
743 } -returnCodes error -result "wrong # args: should be \"lreverse list\""
744 test cmdIL-7.2 {lreverse command} -body {
745     lreverse a b
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}
752     lreverse $x
753 } {f e {c d} b a}
754 test cmdIL-7.5 {lreverse command - unshared object} {
755     lreverse [list a b {c d} e f]
756 } {f e {c d} b a}
757 test cmdIL-7.6 {lreverse command - unshared object [Bug 1672585]} {
758     lreverse [set x {1 2 3}][unset x]
759 } {3 2 1}
760 test cmdIL-7.7 {lreverse command - empty object [Bug 1876793]} {
761     lreverse [list]
762 } {}
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]
769     testobj freeallvars
770     proc K {a b} {return $a}
771 } -constraints testobj -body {
772     lreverse [K $y [unset y]]
773     lindex $x 0
774 } -cleanup {
775     unset -nocomplain x y
776     rename K {}
777 } -result 1
778
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 {
785     namespace delete my
786 } -result 1
787
788
789 # cleanup
790 ::tcltest::cleanupTests
791 return
792
793 # Local Variables:
794 # mode: tcl
795 # End: