1 | # This file contains a collection of tests for the procedures in the |
---|
2 | # file tclCmdIL.c. Sourcing this file into Tcl runs the tests and |
---|
3 | # generates output 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 |
---|
9 | # of this file, and for a DISCLAIMER OF ALL WARRANTIES. |
---|
10 | # |
---|
11 | # RCS: @(#) $Id: cmdIL.test,v 1.38 2008/02/13 19:41:20 dgp Exp $ |
---|
12 | |
---|
13 | if {[lsearch [namespace children] ::tcltest] == -1} { |
---|
14 | package require tcltest 2 |
---|
15 | namespace import -force ::tcltest::* |
---|
16 | } |
---|
17 | |
---|
18 | # Used for constraining memory leak tests |
---|
19 | testConstraint memory [llength [info commands memory]] |
---|
20 | |
---|
21 | test cmdIL-1.1 {Tcl_LsortObjCmd procedure} { |
---|
22 | list [catch {lsort} msg] $msg |
---|
23 | } {1 {wrong # args: should be "lsort ?options? list"}} |
---|
24 | test cmdIL-1.2 {Tcl_LsortObjCmd procedure} { |
---|
25 | list [catch {lsort -foo {1 3 2 5}} msg] $msg |
---|
26 | } {1 {bad option "-foo": must be -ascii, -command, -decreasing, -dictionary, -increasing, -index, -indices, -integer, -nocase, -real, or -unique}} |
---|
27 | test cmdIL-1.3 {Tcl_LsortObjCmd procedure, default options} { |
---|
28 | lsort {d e c b a \{ d35 d300} |
---|
29 | } {a b c d d300 d35 e \{} |
---|
30 | test cmdIL-1.4 {Tcl_LsortObjCmd procedure, -ascii option} { |
---|
31 | lsort -integer -ascii {d e c b a d35 d300} |
---|
32 | } {a b c d d300 d35 e} |
---|
33 | test cmdIL-1.5 {Tcl_LsortObjCmd procedure, -command option} { |
---|
34 | list [catch {lsort -command {1 3 2 5}} msg] $msg |
---|
35 | } {1 {"-command" option must be followed by comparison command}} |
---|
36 | test cmdIL-1.6 {Tcl_LsortObjCmd procedure, -command option} -setup { |
---|
37 | proc cmp {a b} { |
---|
38 | expr {[string match x* $b] - [string match x* $a]} |
---|
39 | } |
---|
40 | } -body { |
---|
41 | lsort -command cmp {x1 abc x2 def x3 x4} |
---|
42 | } -result {x1 x2 x3 x4 abc def} -cleanup { |
---|
43 | rename cmp "" |
---|
44 | } |
---|
45 | test cmdIL-1.7 {Tcl_LsortObjCmd procedure, -decreasing option} { |
---|
46 | lsort -decreasing {d e c b a d35 d300} |
---|
47 | } {e d35 d300 d c b a} |
---|
48 | test cmdIL-1.8 {Tcl_LsortObjCmd procedure, -dictionary option} { |
---|
49 | lsort -dictionary {d e c b a d35 d300} |
---|
50 | } {a b c d d35 d300 e} |
---|
51 | test cmdIL-1.9 {Tcl_LsortObjCmd procedure, -dictionary option} { |
---|
52 | lsort -dictionary {1k 0k 10k} |
---|
53 | } {0k 1k 10k} |
---|
54 | test cmdIL-1.10 {Tcl_LsortObjCmd procedure, -increasing option} { |
---|
55 | lsort -decreasing -increasing {d e c b a d35 d300} |
---|
56 | } {a b c d d300 d35 e} |
---|
57 | test cmdIL-1.11 {Tcl_LsortObjCmd procedure, -index option} { |
---|
58 | list [catch {lsort -index {1 3 2 5}} msg] $msg |
---|
59 | } {1 {"-index" option must be followed by list index}} |
---|
60 | test cmdIL-1.12 {Tcl_LsortObjCmd procedure, -index option} { |
---|
61 | list [catch {lsort -index foo {1 3 2 5}} msg] $msg |
---|
62 | } {1 {bad index "foo": must be integer?[+-]integer? or end?[+-]integer?}} |
---|
63 | test cmdIL-1.13 {Tcl_LsortObjCmd procedure, -index option} { |
---|
64 | lsort -index end -integer {{2 25} {10 20 50 100} {3 16 42} 1} |
---|
65 | } {1 {2 25} {3 16 42} {10 20 50 100}} |
---|
66 | test cmdIL-1.14 {Tcl_LsortObjCmd procedure, -index option} { |
---|
67 | lsort -index 1 -integer {{1 25 100} {3 16 42} {10 20 50}} |
---|
68 | } {{3 16 42} {10 20 50} {1 25 100}} |
---|
69 | test cmdIL-1.15 {Tcl_LsortObjCmd procedure, -integer option} { |
---|
70 | lsort -integer {24 6 300 18} |
---|
71 | } {6 18 24 300} |
---|
72 | test cmdIL-1.16 {Tcl_LsortObjCmd procedure, -integer option} { |
---|
73 | list [catch {lsort -integer {1 3 2.4}} msg] $msg |
---|
74 | } {1 {expected integer but got "2.4"}} |
---|
75 | test cmdIL-1.17 {Tcl_LsortObjCmd procedure, -real option} { |
---|
76 | lsort -real {24.2 6e3 150e-1} |
---|
77 | } {150e-1 24.2 6e3} |
---|
78 | test cmdIL-1.18 {Tcl_LsortObjCmd procedure, bogus list} { |
---|
79 | list [catch {lsort "1 2 3 \{ 4"} msg] $msg |
---|
80 | } {1 {unmatched open brace in list}} |
---|
81 | test cmdIL-1.19 {Tcl_LsortObjCmd procedure, empty list} { |
---|
82 | lsort {} |
---|
83 | } {} |
---|
84 | test cmdIL-1.22 {Tcl_LsortObjCmd procedure, unique sort} { |
---|
85 | lsort -integer -unique {3 1 2 3 1 4 3} |
---|
86 | } {1 2 3 4} |
---|
87 | test cmdIL-1.23 {Tcl_LsortObjCmd procedure, unique sort with index} { |
---|
88 | # lsort -unique should return the last unique item |
---|
89 | lsort -unique -index 0 {{a b} {c b} {a c} {d a}} |
---|
90 | } {{a c} {c b} {d a}} |
---|
91 | test cmdIL-1.24 {Tcl_LsortObjCmd procedure, order of -index and -command} -setup { |
---|
92 | catch {rename 1 ""} |
---|
93 | proc testcmp {a b} {return [string compare $a $b]} |
---|
94 | } -body { |
---|
95 | set l [list [list a b] [list c d]] |
---|
96 | list [catch {lsort -command testcmp -index 1 $l} msg] $msg |
---|
97 | } -cleanup { |
---|
98 | rename testcmp "" |
---|
99 | } -result [list 0 [list [list a b] [list c d]]] |
---|
100 | test cmdIL-1.25 {Tcl_LsortObjCmd procedure, order of -index and -command} -setup { |
---|
101 | catch {rename 1 ""} |
---|
102 | proc testcmp {a b} {return [string compare $a $b]} |
---|
103 | } -body { |
---|
104 | set l [list [list a b] [list c d]] |
---|
105 | list [catch {lsort -index 1 -command testcmp $l} msg] $msg |
---|
106 | } -cleanup { |
---|
107 | rename testcmp "" |
---|
108 | } -result [list 0 [list [list a b] [list c d]]] |
---|
109 | # Note that the required order only exists in the end-1'th element; |
---|
110 | # indexing using the end element or any fixed offset from the start |
---|
111 | # will not work... |
---|
112 | test cmdIL-1.26 {Tcl_LsortObjCmd procedure, offset indexing from end} { |
---|
113 | lsort -index end-1 {{a 1 e i} {b 2 3 f g} {c 4 5 6 d h}} |
---|
114 | } {{c 4 5 6 d h} {a 1 e i} {b 2 3 f g}} |
---|
115 | test cmdIL-1.27 {Tcl_LsortObjCmd procedure, returning indices} { |
---|
116 | lsort -indices {a c b} |
---|
117 | } {0 2 1} |
---|
118 | test cmdIL-1.28 {Tcl_LsortObjCmd procedure, returning indices} { |
---|
119 | lsort -indices -unique -decreasing -real {1.2 34.5 34.5 5.6} |
---|
120 | } {2 3 0} |
---|
121 | test cmdIL-1.29 {Tcl_LsortObjCmd procedure, loss of list rep during sorting} { |
---|
122 | set l {1 2 3} |
---|
123 | string length [lsort -command {apply {args {string length $::l}}} $l] |
---|
124 | } 5 |
---|
125 | |
---|
126 | # Can't think of any good tests for the MergeSort and MergeLists |
---|
127 | # procedures, except a bunch of random lists to sort. |
---|
128 | |
---|
129 | test cmdIL-2.1 {MergeSort and MergeLists procedures} -setup { |
---|
130 | set result {} |
---|
131 | set r 1435753299 |
---|
132 | proc rand {} { |
---|
133 | global r |
---|
134 | set r [expr {(16807 * $r) % (0x7fffffff)}] |
---|
135 | } |
---|
136 | } -body { |
---|
137 | for {set i 0} {$i < 150} {incr i} { |
---|
138 | set x {} |
---|
139 | for {set j 0} {$j < $i} {incr j} { |
---|
140 | lappend x [expr {[rand] & 0xfff}] |
---|
141 | } |
---|
142 | set y [lsort -integer $x] |
---|
143 | set old -1 |
---|
144 | foreach el $y { |
---|
145 | if {$el < $old} { |
---|
146 | append result "list {$x} sorted to {$y}, element $el out of order\n" |
---|
147 | break |
---|
148 | } |
---|
149 | set old $el |
---|
150 | } |
---|
151 | } |
---|
152 | set result |
---|
153 | } -cleanup { |
---|
154 | rename rand "" |
---|
155 | } -result {} |
---|
156 | |
---|
157 | test cmdIL-3.1 {SortCompare procedure, skip comparisons after error} -setup { |
---|
158 | proc cmp {a b} { |
---|
159 | global x |
---|
160 | incr x |
---|
161 | error "error #$x" |
---|
162 | } |
---|
163 | } -body { |
---|
164 | set x 0 |
---|
165 | list [catch {lsort -integer -command cmp {48 6 28 190 16 2 3 6 1}} msg] \ |
---|
166 | $msg $x |
---|
167 | } -cleanup { |
---|
168 | rename cmp "" |
---|
169 | } -result {1 {error #1} 1} |
---|
170 | test cmdIL-3.2 {SortCompare procedure, -index option} { |
---|
171 | list [catch {lsort -integer -index 2 "\\\{ {30 40 50}"} msg] $msg |
---|
172 | } {1 {unmatched open brace in list}} |
---|
173 | test cmdIL-3.3 {SortCompare procedure, -index option} { |
---|
174 | list [catch {lsort -integer -index 2 {{20 10} {15 30 40}}} msg] $msg |
---|
175 | } {1 {element 2 missing from sublist "20 10"}} |
---|
176 | test cmdIL-3.4 {SortCompare procedure, -index option} { |
---|
177 | list [catch {lsort -integer -index 2 "{a b c} \\\{"} msg] $msg |
---|
178 | } {1 {expected integer but got "c"}} |
---|
179 | test cmdIL-3.4.1 {SortCompare procedure, -index option} { |
---|
180 | list [catch {lsort -integer -index 2 "{1 2 3} \\\{"} msg] $msg |
---|
181 | } {1 {unmatched open brace in list}} |
---|
182 | test cmdIL-3.5 {SortCompare procedure, -index option} { |
---|
183 | list [catch {lsort -integer -index 2 {{20 10 13} {15}}} msg] $msg |
---|
184 | } {1 {element 2 missing from sublist "15"}} |
---|
185 | test cmdIL-3.6 {SortCompare procedure, -index option} { |
---|
186 | lsort -integer -index 2 {{1 15 30} {2 5 25} {3 25 20}} |
---|
187 | } {{3 25 20} {2 5 25} {1 15 30}} |
---|
188 | test cmdIL-3.7 {SortCompare procedure, -ascii option} { |
---|
189 | lsort -ascii {d e c b a d35 d300 100 20} |
---|
190 | } {100 20 a b c d d300 d35 e} |
---|
191 | test cmdIL-3.8 {SortCompare procedure, -dictionary option} { |
---|
192 | lsort -dictionary {d e c b a d35 d300 100 20} |
---|
193 | } {20 100 a b c d d35 d300 e} |
---|
194 | test cmdIL-3.9 {SortCompare procedure, -integer option} { |
---|
195 | list [catch {lsort -integer {x 3}} msg] $msg |
---|
196 | } {1 {expected integer but got "x"}} |
---|
197 | test cmdIL-3.10 {SortCompare procedure, -integer option} { |
---|
198 | list [catch {lsort -integer {3 q}} msg] $msg |
---|
199 | } {1 {expected integer but got "q"}} |
---|
200 | test cmdIL-3.11 {SortCompare procedure, -integer option} { |
---|
201 | lsort -integer {35 21 0x20 30 0o23 100 8} |
---|
202 | } {8 0o23 21 30 0x20 35 100} |
---|
203 | test cmdIL-3.12 {SortCompare procedure, -real option} { |
---|
204 | list [catch {lsort -real {6...4 3}} msg] $msg |
---|
205 | } {1 {expected floating-point number but got "6...4"}} |
---|
206 | test cmdIL-3.13 {SortCompare procedure, -real option} { |
---|
207 | list [catch {lsort -real {3 1x7}} msg] $msg |
---|
208 | } {1 {expected floating-point number but got "1x7"}} |
---|
209 | test cmdIL-3.14 {SortCompare procedure, -real option} { |
---|
210 | lsort -real {24 2.5e01 16.7 85e-1 10.004} |
---|
211 | } {85e-1 10.004 16.7 24 2.5e01} |
---|
212 | test cmdIL-3.15 {SortCompare procedure, -command option} -body { |
---|
213 | proc cmp {a b} { |
---|
214 | error "comparison error" |
---|
215 | } |
---|
216 | list [catch {lsort -command cmp {48 6}} msg] $msg $::errorInfo |
---|
217 | } -cleanup { |
---|
218 | rename cmp "" |
---|
219 | } -result {1 {comparison error} {comparison error |
---|
220 | while executing |
---|
221 | "error "comparison error"" |
---|
222 | (procedure "cmp" line 2) |
---|
223 | invoked from within |
---|
224 | "cmp 48 6" |
---|
225 | (-compare command) |
---|
226 | invoked from within |
---|
227 | "lsort -command cmp {48 6}"}} |
---|
228 | test cmdIL-3.16 {SortCompare procedure, -command option, long command} -body { |
---|
229 | proc cmp {dummy a b} { |
---|
230 | string compare $a $b |
---|
231 | } |
---|
232 | 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}} |
---|
233 | } -cleanup { |
---|
234 | rename cmp "" |
---|
235 | } -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}} |
---|
236 | test cmdIL-3.17 {SortCompare procedure, -command option, non-integer result} -body { |
---|
237 | proc cmp {a b} { |
---|
238 | return foow |
---|
239 | } |
---|
240 | list [catch {lsort -command cmp {48 6}} msg] $msg |
---|
241 | } -cleanup { |
---|
242 | rename cmp "" |
---|
243 | } -result {1 {-compare command returned non-integer result}} |
---|
244 | test cmdIL-3.18 {SortCompare procedure, -command option} -body { |
---|
245 | proc cmp {a b} { |
---|
246 | expr {$b - $a} |
---|
247 | } |
---|
248 | lsort -command cmp {48 6 18 22 21 35 36} |
---|
249 | } -cleanup { |
---|
250 | rename cmp "" |
---|
251 | } -result {48 36 35 22 21 18 6} |
---|
252 | test cmdIL-3.19 {SortCompare procedure, -decreasing option} { |
---|
253 | lsort -decreasing -integer {35 21 0x20 30 0o23 100 8} |
---|
254 | } {100 35 0x20 30 21 0o23 8} |
---|
255 | |
---|
256 | test cmdIL-4.1 {DictionaryCompare procedure, numerics, leading zeros} { |
---|
257 | lsort -dictionary {a003b a03b} |
---|
258 | } {a03b a003b} |
---|
259 | test cmdIL-4.2 {DictionaryCompare procedure, numerics, leading zeros} { |
---|
260 | lsort -dictionary {a3b a03b} |
---|
261 | } {a3b a03b} |
---|
262 | test cmdIL-4.3 {DictionaryCompare procedure, numerics, leading zeros} { |
---|
263 | lsort -dictionary {a3b A03b} |
---|
264 | } {A03b a3b} |
---|
265 | test cmdIL-4.4 {DictionaryCompare procedure, numerics, leading zeros} { |
---|
266 | lsort -dictionary {a3b a03B} |
---|
267 | } {a3b a03B} |
---|
268 | test cmdIL-4.5 {DictionaryCompare procedure, numerics, leading zeros} { |
---|
269 | lsort -dictionary {00000 000} |
---|
270 | } {000 00000} |
---|
271 | test cmdIL-4.6 {DictionaryCompare procedure, numerics, different lengths} { |
---|
272 | lsort -dictionary {a321b a03210b} |
---|
273 | } {a321b a03210b} |
---|
274 | test cmdIL-4.7 {DictionaryCompare procedure, numerics, different lengths} { |
---|
275 | lsort -dictionary {a03210b a321b} |
---|
276 | } {a321b a03210b} |
---|
277 | test cmdIL-4.8 {DictionaryCompare procedure, numerics} { |
---|
278 | lsort -dictionary {48 6a 18b 22a 21aa 35 36} |
---|
279 | } {6a 18b 21aa 22a 35 36 48} |
---|
280 | test cmdIL-4.9 {DictionaryCompare procedure, numerics} { |
---|
281 | lsort -dictionary {a123x a123b} |
---|
282 | } {a123b a123x} |
---|
283 | test cmdIL-4.10 {DictionaryCompare procedure, numerics} { |
---|
284 | lsort -dictionary {a123b a123x} |
---|
285 | } {a123b a123x} |
---|
286 | test cmdIL-4.11 {DictionaryCompare procedure, numerics} { |
---|
287 | lsort -dictionary {a1b aab} |
---|
288 | } {a1b aab} |
---|
289 | test cmdIL-4.12 {DictionaryCompare procedure, numerics} { |
---|
290 | lsort -dictionary {a1b a!b} |
---|
291 | } {a!b a1b} |
---|
292 | test cmdIL-4.13 {DictionaryCompare procedure, numerics} { |
---|
293 | lsort -dictionary {a1b2c a1b1c} |
---|
294 | } {a1b1c a1b2c} |
---|
295 | test cmdIL-4.14 {DictionaryCompare procedure, numerics} { |
---|
296 | lsort -dictionary {a1b2c a1b3c} |
---|
297 | } {a1b2c a1b3c} |
---|
298 | test cmdIL-4.15 {DictionaryCompare procedure, long numbers} { |
---|
299 | lsort -dictionary {a7654884321988762b a7654884321988761b} |
---|
300 | } {a7654884321988761b a7654884321988762b} |
---|
301 | test cmdIL-4.16 {DictionaryCompare procedure, long numbers} { |
---|
302 | lsort -dictionary {a8765488432198876b a7654884321988761b} |
---|
303 | } {a7654884321988761b a8765488432198876b} |
---|
304 | test cmdIL-4.17 {DictionaryCompare procedure, case} { |
---|
305 | lsort -dictionary {aBCd abcc} |
---|
306 | } {abcc aBCd} |
---|
307 | test cmdIL-4.18 {DictionaryCompare procedure, case} { |
---|
308 | lsort -dictionary {aBCd abce} |
---|
309 | } {aBCd abce} |
---|
310 | test cmdIL-4.19 {DictionaryCompare procedure, case} { |
---|
311 | lsort -dictionary {abcd ABcc} |
---|
312 | } {ABcc abcd} |
---|
313 | test cmdIL-4.20 {DictionaryCompare procedure, case} { |
---|
314 | lsort -dictionary {abcd ABce} |
---|
315 | } {abcd ABce} |
---|
316 | test cmdIL-4.21 {DictionaryCompare procedure, case} { |
---|
317 | lsort -dictionary {abCD ABcd} |
---|
318 | } {ABcd abCD} |
---|
319 | test cmdIL-4.22 {DictionaryCompare procedure, case} { |
---|
320 | lsort -dictionary {ABcd aBCd} |
---|
321 | } {ABcd aBCd} |
---|
322 | test cmdIL-4.23 {DictionaryCompare procedure, case} { |
---|
323 | lsort -dictionary {ABcd AbCd} |
---|
324 | } {ABcd AbCd} |
---|
325 | test cmdIL-4.24 {DictionaryCompare procedure, international characters} {hasIsoLocale} { |
---|
326 | ::tcltest::set_iso8859_1_locale |
---|
327 | set result [lsort -dictionary "a b c A B C \xe3 \xc4"] |
---|
328 | ::tcltest::restore_locale |
---|
329 | set result |
---|
330 | } "A a B b C c \xe3 \xc4" |
---|
331 | test cmdIL-4.25 {DictionaryCompare procedure, international characters} {hasIsoLocale} { |
---|
332 | ::tcltest::set_iso8859_1_locale |
---|
333 | set result [lsort -dictionary "a23\xe3 a23\xc5 a23\xe4"] |
---|
334 | ::tcltest::restore_locale |
---|
335 | set result |
---|
336 | } "a23\xe3 a23\xe4 a23\xc5" |
---|
337 | test cmdIL-4.26 {DefaultCompare procedure, signed characters} { |
---|
338 | set l [lsort [list "abc\200" "abc"]] |
---|
339 | set viewlist {} |
---|
340 | foreach s $l { |
---|
341 | set viewelem "" |
---|
342 | set len [string length $s] |
---|
343 | for {set i 0} {$i < $len} {incr i} { |
---|
344 | set c [string index $s $i] |
---|
345 | scan $c %c d |
---|
346 | if {$d > 0 && $d < 128} { |
---|
347 | append viewelem $c |
---|
348 | } else { |
---|
349 | append viewelem "\\[format %03o $d]" |
---|
350 | } |
---|
351 | } |
---|
352 | lappend viewlist $viewelem |
---|
353 | } |
---|
354 | set viewlist |
---|
355 | } [list "abc" "abc\\200"] |
---|
356 | test cmdIL-4.27 {DictionaryCompare procedure, signed characters} { |
---|
357 | set l [lsort -dictionary [list "abc\200" "abc"]] |
---|
358 | set viewlist {} |
---|
359 | foreach s $l { |
---|
360 | set viewelem "" |
---|
361 | set len [string length $s] |
---|
362 | for {set i 0} {$i < $len} {incr i} { |
---|
363 | set c [string index $s $i] |
---|
364 | scan $c %c d |
---|
365 | if {$d > 0 && $d < 128} { |
---|
366 | append viewelem $c |
---|
367 | } else { |
---|
368 | append viewelem "\\[format %03o $d]" |
---|
369 | } |
---|
370 | } |
---|
371 | lappend viewlist $viewelem |
---|
372 | } |
---|
373 | set viewlist |
---|
374 | } [list "abc" "abc\\200"] |
---|
375 | test cmdIL-4.28 {DictionaryCompare procedure, chars between Z and a in ASCII} { |
---|
376 | lsort -dictionary [list AA ` c CC] |
---|
377 | } [list ` AA c CC] |
---|
378 | test cmdIL-4.29 {DictionaryCompare procedure, chars between Z and a in ASCII} { |
---|
379 | lsort -dictionary [list AA ` c ^ \\ CC \[ \]] |
---|
380 | } [list \[ \\ \] ^ ` AA c CC] |
---|
381 | test cmdIL-4.30 {DictionaryCompare procedure, chars between Z and a in ASCII} { |
---|
382 | lsort -dictionary [list AA ` c ^ _ \\ CC \[ dude \] funky] |
---|
383 | } [list \[ \\ \] ^ _ ` AA c CC dude funky] |
---|
384 | test cmdIL-4.31 {DictionaryCompare procedure, chars between Z and a in ASCII} { |
---|
385 | lsort -dictionary [list AA c ` CC] |
---|
386 | } [list ` AA c CC] |
---|
387 | test cmdIL-4.32 {DictionaryCompare procedure, chars between Z and a in ASCII} { |
---|
388 | lsort -dictionary [list AA c CC `] |
---|
389 | } [list ` AA c CC] |
---|
390 | test cmdIL-4.33 {DictionaryCompare procedure, chars between Z and a in ASCII} { |
---|
391 | lsort -dictionary [list AA ! c CC `] |
---|
392 | } [list ! ` AA c CC] |
---|
393 | test cmdIL-4.34 {SortCompare procedure, -ascii option with -nocase option} { |
---|
394 | lsort -ascii -nocase {d e c b a d35 d300 100 20} |
---|
395 | } {100 20 a b c d d300 d35 e} |
---|
396 | test cmdIL-4.35 {SortCompare procedure, -ascii option with -nocase option} { |
---|
397 | lsort -ascii -nocase {d E c B a D35 d300 100 20} |
---|
398 | } {100 20 a B c d d300 D35 E} |
---|
399 | |
---|
400 | test cmdIL-5.1 {lsort with list style index} { |
---|
401 | lsort -ascii -decreasing -index {0 1} { |
---|
402 | {{Jim Alpha} 20000410} |
---|
403 | {{Joe Bravo} 19990320} |
---|
404 | {{Jacky Charlie} 19390911} |
---|
405 | } |
---|
406 | } {{{Jacky Charlie} 19390911} {{Joe Bravo} 19990320} {{Jim Alpha} 20000410}} |
---|
407 | test cmdIL-5.2 {lsort with list style index} { |
---|
408 | lsort -decreasing -index {0 1} { |
---|
409 | {{Jim Alpha} 20000410} |
---|
410 | {{Joe Bravo} 19990320} |
---|
411 | {{Jacky Charlie} 19390911} |
---|
412 | } |
---|
413 | } {{{Jacky Charlie} 19390911} {{Joe Bravo} 19990320} {{Jim Alpha} 20000410}} |
---|
414 | test cmdIL-5.3 {lsort with list style index} { |
---|
415 | lsort -integer -increasing -index {1 end} { |
---|
416 | {{Jim Alpha} 20000410} |
---|
417 | {{Joe Bravo} 19990320} |
---|
418 | {{Jacky Charlie} 19390911} |
---|
419 | } |
---|
420 | } {{{Jacky Charlie} 19390911} {{Joe Bravo} 19990320} {{Jim Alpha} 20000410}} |
---|
421 | test cmdIL-5.4 {lsort with list style index} { |
---|
422 | lsort -integer -index {1 end-1} { |
---|
423 | {the {0 1 2 3 4 5} quick} |
---|
424 | {brown {0 1 2 3 4} fox} |
---|
425 | {jumps {30 31 2 33} over} |
---|
426 | {the {0 1 2} lazy} |
---|
427 | {dogs {0 1}} |
---|
428 | } |
---|
429 | } {{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}} |
---|
430 | test cmdIL-5.5 {lsort with list style index and sharing} -body { |
---|
431 | proc test_lsort {l} { |
---|
432 | set n $l |
---|
433 | foreach e $l {lappend n [list [expr {rand()}] $e]} |
---|
434 | lindex [lsort -real -index $l $n] 1 1 |
---|
435 | } |
---|
436 | expr srand(1) |
---|
437 | test_lsort 0 |
---|
438 | } -result 0 -cleanup { |
---|
439 | rename test_lsort "" |
---|
440 | } |
---|
441 | |
---|
442 | # Compiled version |
---|
443 | test cmdIL-6.1 {lassign command syntax} -body { |
---|
444 | proc testLassign {} { |
---|
445 | lassign |
---|
446 | } |
---|
447 | testLassign |
---|
448 | } -returnCodes 1 -cleanup { |
---|
449 | rename testLassign {} |
---|
450 | } -result {wrong # args: should be "lassign list varName ?varName ...?"} |
---|
451 | test cmdIL-6.2 {lassign command syntax} -body { |
---|
452 | proc testLassign {} { |
---|
453 | lassign x |
---|
454 | } |
---|
455 | testLassign |
---|
456 | } -returnCodes 1 -cleanup { |
---|
457 | rename testLassign {} |
---|
458 | } -result {wrong # args: should be "lassign list varName ?varName ...?"} |
---|
459 | test cmdIL-6.3 {lassign command} -body { |
---|
460 | proc testLassign {} { |
---|
461 | set x FAIL |
---|
462 | list [lassign a x] $x |
---|
463 | } |
---|
464 | testLassign |
---|
465 | } -result {{} a} -cleanup { |
---|
466 | rename testLassign {} |
---|
467 | } |
---|
468 | test cmdIL-6.4 {lassign command} -body { |
---|
469 | proc testLassign {} { |
---|
470 | set x FAIL |
---|
471 | set y FAIL |
---|
472 | list [lassign a x y] $x $y |
---|
473 | } |
---|
474 | testLassign |
---|
475 | } -result {{} a {}} -cleanup { |
---|
476 | rename testLassign {} |
---|
477 | } |
---|
478 | test cmdIL-6.5 {lassign command} -body { |
---|
479 | proc testLassign {} { |
---|
480 | set x FAIL |
---|
481 | set y FAIL |
---|
482 | list [lassign {a b} x y] $x $y |
---|
483 | } |
---|
484 | testLassign |
---|
485 | } -result {{} a b} -cleanup { |
---|
486 | rename testLassign {} |
---|
487 | } |
---|
488 | test cmdIL-6.6 {lassign command} -body { |
---|
489 | proc testLassign {} { |
---|
490 | set x FAIL |
---|
491 | set y FAIL |
---|
492 | list [lassign {a b c} x y] $x $y |
---|
493 | } |
---|
494 | testLassign |
---|
495 | } -result {c a b} -cleanup { |
---|
496 | rename testLassign {} |
---|
497 | } |
---|
498 | test cmdIL-6.7 {lassign command} -body { |
---|
499 | proc testLassign {} { |
---|
500 | set x FAIL |
---|
501 | set y FAIL |
---|
502 | list [lassign {a b c d} x y] $x $y |
---|
503 | } |
---|
504 | testLassign |
---|
505 | } -result {{c d} a b} -cleanup { |
---|
506 | rename testLassign {} |
---|
507 | } |
---|
508 | test cmdIL-6.8 {lassign command - list format error} -body { |
---|
509 | proc testLassign {} { |
---|
510 | set x FAIL |
---|
511 | set y FAIL |
---|
512 | list [catch {lassign {a {b}c d} x y} msg] $msg $x $y |
---|
513 | } |
---|
514 | testLassign |
---|
515 | } -result {1 {list element in braces followed by "c" instead of space} FAIL FAIL} -cleanup { |
---|
516 | rename testLassign {} |
---|
517 | } |
---|
518 | test cmdIL-6.9 {lassign command - assignment to arrays} -body { |
---|
519 | proc testLassign {} { |
---|
520 | list [lassign {a b} x(x)] $x(x) |
---|
521 | } |
---|
522 | testLassign |
---|
523 | } -result {b a} -cleanup { |
---|
524 | rename testLassign {} |
---|
525 | } |
---|
526 | test cmdIL-6.10 {lassign command - variable update error} -body { |
---|
527 | proc testLassign {} { |
---|
528 | set x(x) {} |
---|
529 | lassign a x |
---|
530 | } |
---|
531 | testLassign |
---|
532 | } -returnCodes 1 -result {can't set "x": variable is array} -cleanup { |
---|
533 | rename testLassign {} |
---|
534 | } |
---|
535 | test cmdIL-6.11 {lassign command - variable update error} -body { |
---|
536 | proc testLassign {} { |
---|
537 | set x(x) {} |
---|
538 | set y FAIL |
---|
539 | list [catch {lassign a y x} msg] $msg $y |
---|
540 | } |
---|
541 | testLassign |
---|
542 | } -result {1 {can't set "x": variable is array} a} -cleanup { |
---|
543 | rename testLassign {} |
---|
544 | } |
---|
545 | test cmdIL-6.12 {lassign command - memory leak testing} -setup { |
---|
546 | unset -nocomplain x y |
---|
547 | set x(x) {} |
---|
548 | set y FAIL |
---|
549 | proc getbytes {} { |
---|
550 | set lines [split [memory info] "\n"] |
---|
551 | lindex [lindex $lines 3] 3 |
---|
552 | } |
---|
553 | proc stress {} { |
---|
554 | global x y |
---|
555 | 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 |
---|
556 | 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} |
---|
557 | catch {lassign {} x} |
---|
558 | } |
---|
559 | } -constraints memory -body { |
---|
560 | set end [getbytes] |
---|
561 | for {set i 0} {$i < 5} {incr i} { |
---|
562 | stress |
---|
563 | set tmp $end |
---|
564 | set end [getbytes] |
---|
565 | } |
---|
566 | expr {$end - $tmp} |
---|
567 | } -result 0 -cleanup { |
---|
568 | unset -nocomplain x y i tmp end |
---|
569 | rename getbytes {} |
---|
570 | rename stress {} |
---|
571 | } |
---|
572 | # Force non-compiled version |
---|
573 | test cmdIL-6.13 {lassign command syntax} -body { |
---|
574 | proc testLassign {} { |
---|
575 | set lassign lassign |
---|
576 | $lassign |
---|
577 | } |
---|
578 | testLassign |
---|
579 | } -returnCodes 1 -cleanup { |
---|
580 | rename testLassign {} |
---|
581 | } -result {wrong # args: should be "lassign list varName ?varName ...?"} |
---|
582 | test cmdIL-6.14 {lassign command syntax} -body { |
---|
583 | proc testLassign {} { |
---|
584 | set lassign lassign |
---|
585 | $lassign x |
---|
586 | } |
---|
587 | testLassign |
---|
588 | } -returnCodes 1 -cleanup { |
---|
589 | rename testLassign {} |
---|
590 | } -result {wrong # args: should be "lassign list varName ?varName ...?"} |
---|
591 | test cmdIL-6.15 {lassign command} -body { |
---|
592 | proc testLassign {} { |
---|
593 | set lassign lassign |
---|
594 | set x FAIL |
---|
595 | list [$lassign a x] $x |
---|
596 | } |
---|
597 | testLassign |
---|
598 | } -result {{} a} -cleanup { |
---|
599 | rename testLassign {} |
---|
600 | } |
---|
601 | test cmdIL-6.16 {lassign command} -body { |
---|
602 | proc testLassign {} { |
---|
603 | set lassign lassign |
---|
604 | set x FAIL |
---|
605 | set y FAIL |
---|
606 | list [$lassign a x y] $x $y |
---|
607 | } |
---|
608 | testLassign |
---|
609 | } -result {{} a {}} -cleanup { |
---|
610 | rename testLassign {} |
---|
611 | } |
---|
612 | test cmdIL-6.17 {lassign command} -body { |
---|
613 | proc testLassign {} { |
---|
614 | set lassign lassign |
---|
615 | set x FAIL |
---|
616 | set y FAIL |
---|
617 | list [$lassign {a b} x y] $x $y |
---|
618 | } |
---|
619 | testLassign |
---|
620 | } -result {{} a b} -cleanup { |
---|
621 | rename testLassign {} |
---|
622 | } |
---|
623 | test cmdIL-6.18 {lassign command} -body { |
---|
624 | proc testLassign {} { |
---|
625 | set lassign lassign |
---|
626 | set x FAIL |
---|
627 | set y FAIL |
---|
628 | list [$lassign {a b c} x y] $x $y |
---|
629 | } |
---|
630 | testLassign |
---|
631 | } -result {c a b} -cleanup { |
---|
632 | rename testLassign {} |
---|
633 | } |
---|
634 | test cmdIL-6.19 {lassign command} -body { |
---|
635 | proc testLassign {} { |
---|
636 | set lassign lassign |
---|
637 | set x FAIL |
---|
638 | set y FAIL |
---|
639 | list [$lassign {a b c d} x y] $x $y |
---|
640 | } |
---|
641 | testLassign |
---|
642 | } -result {{c d} a b} -cleanup { |
---|
643 | rename testLassign {} |
---|
644 | } |
---|
645 | test cmdIL-6.20 {lassign command - list format error} -body { |
---|
646 | proc testLassign {} { |
---|
647 | set lassign lassign |
---|
648 | set x FAIL |
---|
649 | set y FAIL |
---|
650 | list [catch {$lassign {a {b}c d} x y} msg] $msg $x $y |
---|
651 | } |
---|
652 | testLassign |
---|
653 | } -result {1 {list element in braces followed by "c" instead of space} FAIL FAIL} -cleanup { |
---|
654 | rename testLassign {} |
---|
655 | } |
---|
656 | test cmdIL-6.21 {lassign command - assignment to arrays} -body { |
---|
657 | proc testLassign {} { |
---|
658 | set lassign lassign |
---|
659 | list [$lassign {a b} x(x)] $x(x) |
---|
660 | } |
---|
661 | testLassign |
---|
662 | } -result {b a} -cleanup { |
---|
663 | rename testLassign {} |
---|
664 | } |
---|
665 | test cmdIL-6.22 {lassign command - variable update error} -body { |
---|
666 | proc testLassign {} { |
---|
667 | set lassign lassign |
---|
668 | set x(x) {} |
---|
669 | $lassign a x |
---|
670 | } |
---|
671 | testLassign |
---|
672 | } -returnCodes 1 -result {can't set "x": variable is array} -cleanup { |
---|
673 | rename testLassign {} |
---|
674 | } |
---|
675 | test cmdIL-6.23 {lassign command - variable update error} -body { |
---|
676 | proc testLassign {} { |
---|
677 | set lassign lassign |
---|
678 | set x(x) {} |
---|
679 | set y FAIL |
---|
680 | list [catch {$lassign a y x} msg] $msg $y |
---|
681 | } |
---|
682 | testLassign |
---|
683 | } -result {1 {can't set "x": variable is array} a} -cleanup { |
---|
684 | rename testLassign {} |
---|
685 | } |
---|
686 | test cmdIL-6.24 {lassign command - memory leak testing} -setup { |
---|
687 | set x(x) {} |
---|
688 | set y FAIL |
---|
689 | proc getbytes {} { |
---|
690 | set lines [split [memory info] "\n"] |
---|
691 | lindex [lindex $lines 3] 3 |
---|
692 | } |
---|
693 | proc stress {} { |
---|
694 | global x y |
---|
695 | set lassign lassign |
---|
696 | $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 |
---|
697 | 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} |
---|
698 | catch {$lassign {} x} |
---|
699 | } |
---|
700 | } -constraints memory -body { |
---|
701 | set end [getbytes] |
---|
702 | for {set i 0} {$i < 5} {incr i} { |
---|
703 | stress |
---|
704 | set tmp $end |
---|
705 | set end [getbytes] |
---|
706 | } |
---|
707 | expr {$end - $tmp} |
---|
708 | } -result 0 -cleanup { |
---|
709 | unset -nocomplain x y i tmp end |
---|
710 | rename getbytes {} |
---|
711 | rename stress {} |
---|
712 | } |
---|
713 | # Assorted shimmering problems |
---|
714 | test cmdIL-6.25 {lassign command - shimmering protection} -body { |
---|
715 | proc testLassign {} { |
---|
716 | set x {a b c} |
---|
717 | list [lassign $x $x y] $x [set $x] $y |
---|
718 | } |
---|
719 | testLassign |
---|
720 | } -result {c {a b c} a b} -cleanup { |
---|
721 | rename testLassign {} |
---|
722 | } |
---|
723 | test cmdIL-6.26 {lassign command - shimmering protection} -body { |
---|
724 | proc testLassign {} { |
---|
725 | set x {a b c} |
---|
726 | set lassign lassign |
---|
727 | list [$lassign $x $x y] $x [set $x] $y |
---|
728 | } |
---|
729 | testLassign |
---|
730 | } -result {c {a b c} a b} -cleanup { |
---|
731 | rename testLassign {} |
---|
732 | } |
---|
733 | |
---|
734 | test cmdIL-7.1 {lreverse command} -body { |
---|
735 | lreverse |
---|
736 | } -returnCodes error -result "wrong # args: should be \"lreverse list\"" |
---|
737 | test cmdIL-7.2 {lreverse command} -body { |
---|
738 | lreverse a b |
---|
739 | } -returnCodes error -result "wrong # args: should be \"lreverse list\"" |
---|
740 | test cmdIL-7.3 {lreverse command} -body { |
---|
741 | lreverse "not \{a list" |
---|
742 | } -returnCodes error -result {unmatched open brace in list} |
---|
743 | test cmdIL-7.4 {lreverse command - shared object} { |
---|
744 | set x {a b {c d} e f} |
---|
745 | lreverse $x |
---|
746 | } {f e {c d} b a} |
---|
747 | test cmdIL-7.5 {lreverse command - unshared object} { |
---|
748 | lreverse [list a b {c d} e f] |
---|
749 | } {f e {c d} b a} |
---|
750 | test cmdIL-7.6 {lreverse command - unshared object [Bug 1672585]} { |
---|
751 | lreverse [set x {1 2 3}][unset x] |
---|
752 | } {3 2 1} |
---|
753 | test cmdIL-7.7 {lreverse command - empty object [Bug 1876793]} { |
---|
754 | lreverse [list] |
---|
755 | } {} |
---|
756 | |
---|
757 | testConstraint testobj [llength [info commands testobj]] |
---|
758 | test cmdIL-7.8 {lreverse command - shared intrep [Bug 1675044]} -setup { |
---|
759 | teststringobj set 1 {1 2 3} |
---|
760 | testobj convert 1 list |
---|
761 | testobj duplicate 1 2 |
---|
762 | variable x [teststringobj get 1] |
---|
763 | variable y [teststringobj get 2] |
---|
764 | testobj freeallvars |
---|
765 | proc K {a b} {return $a} |
---|
766 | } -constraints testobj -body { |
---|
767 | lreverse [K $y [unset y]] |
---|
768 | lindex $x 0 |
---|
769 | } -cleanup { |
---|
770 | unset -nocomplain x y |
---|
771 | rename K {} |
---|
772 | } -result 1 |
---|
773 | |
---|
774 | # cleanup |
---|
775 | ::tcltest::cleanupTests |
---|
776 | return |
---|
777 | |
---|
778 | # Local Variables: |
---|
779 | # mode: tcl |
---|
780 | # End: |
---|