os/persistentdata/persistentstorage/sqlite3api/TEST/TCL/tcldistribution/tests/cmdIL.test
Update contrib.
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.
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
9 # of this file, and for a DISCLAIMER OF ALL WARRANTIES.
11 # RCS: @(#) $Id: cmdIL.test,v 1.14.6.2 2007/03/10 14:57:38 dkf Exp $
13 if {[lsearch [namespace children] ::tcltest] == -1} {
14 package require tcltest
15 namespace import -force ::tcltest::*
18 test cmdIL-1.1 {Tcl_LsortObjCmd procedure} {
19 list [catch {lsort} msg] $msg
20 } {1 {wrong # args: should be "lsort ?options? list"}}
21 test cmdIL-1.2 {Tcl_LsortObjCmd procedure} {
22 list [catch {lsort -foo {1 3 2 5}} msg] $msg
23 } {1 {bad option "-foo": must be -ascii, -command, -decreasing, -dictionary, -increasing, -index, -integer, -real, or -unique}}
24 test cmdIL-1.3 {Tcl_LsortObjCmd procedure, default options} {
25 lsort {d e c b a \{ d35 d300}
26 } {a b c d d300 d35 e \{}
27 test cmdIL-1.4 {Tcl_LsortObjCmd procedure, -ascii option} {
28 lsort -integer -ascii {d e c b a d35 d300}
29 } {a b c d d300 d35 e}
30 test cmdIL-1.5 {Tcl_LsortObjCmd procedure, -command option} {
31 list [catch {lsort -command {1 3 2 5}} msg] $msg
32 } {1 {"-command" option must be followed by comparison command}}
33 test cmdIL-1.6 {Tcl_LsortObjCmd procedure, -command option} {
35 expr {[string match x* $b] - [string match x* $a]}
37 lsort -command cmp {x1 abc x2 def x3 x4}
38 } {x1 x2 x3 x4 abc def}
39 test cmdIL-1.7 {Tcl_LsortObjCmd procedure, -decreasing option} {
40 lsort -decreasing {d e c b a d35 d300}
41 } {e d35 d300 d c b a}
42 test cmdIL-1.8 {Tcl_LsortObjCmd procedure, -dictionary option} {
43 lsort -dictionary {d e c b a d35 d300}
44 } {a b c d d35 d300 e}
45 test cmdIL-1.9 {Tcl_LsortObjCmd procedure, -dictionary option} {
46 lsort -dictionary {1k 0k 10k}
48 test cmdIL-1.10 {Tcl_LsortObjCmd procedure, -increasing option} {
49 lsort -decreasing -increasing {d e c b a d35 d300}
50 } {a b c d d300 d35 e}
51 test cmdIL-1.11 {Tcl_LsortObjCmd procedure, -index option} {
52 list [catch {lsort -index {1 3 2 5}} msg] $msg
53 } {1 {"-index" option must be followed by list index}}
54 test cmdIL-1.12 {Tcl_LsortObjCmd procedure, -index option} {
55 list [catch {lsort -index foo {1 3 2 5}} msg] $msg
56 } {1 {bad index "foo": must be integer or end?-integer?}}
57 test cmdIL-1.13 {Tcl_LsortObjCmd procedure, -index option} {
58 lsort -index end -integer {{2 25} {10 20 50 100} {3 16 42} 1}
59 } {1 {2 25} {3 16 42} {10 20 50 100}}
60 test cmdIL-1.14 {Tcl_LsortObjCmd procedure, -index option} {
61 lsort -index 1 -integer {{1 25 100} {3 16 42} {10 20 50}}
62 } {{3 16 42} {10 20 50} {1 25 100}}
63 test cmdIL-1.15 {Tcl_LsortObjCmd procedure, -integer option} {
64 lsort -integer {24 6 300 18}
66 test cmdIL-1.16 {Tcl_LsortObjCmd procedure, -integer option} {
67 list [catch {lsort -integer {1 3 2.4}} msg] $msg
68 } {1 {expected integer but got "2.4"}}
69 test cmdIL-1.17 {Tcl_LsortObjCmd procedure, -real option} {
70 lsort -real {24.2 6e3 150e-1}
72 test cmdIL-1.18 {Tcl_LsortObjCmd procedure, bogus list} {
73 list [catch {lsort "1 2 3 \{ 4"} msg] $msg
74 } {1 {unmatched open brace in list}}
75 test cmdIL-1.19 {Tcl_LsortObjCmd procedure, empty list} {
78 test cmdIL-1.22 {Tcl_LsortObjCmd procedure, unique sort} {
79 lsort -integer -unique {3 1 2 3 1 4 3}
81 test cmdIL-1.23 {Tcl_LsortObjCmd procedure, unique sort with index} {
82 # lsort -unique should return the last unique item
83 lsort -unique -index 0 {{a b} {c b} {a c} {d a}}
85 test cmdIL-1.24 {Tcl_LsortObjCmd procedure, order of -index and -command} {
87 proc testcmp {a b} {return [string compare $a $b]}
88 set l [list [list a b] [list c d]]
89 set result [list [catch {lsort -command testcmp -index 1 $l} msg] $msg]
92 } [list 0 [list [list a b] [list c d]]]
93 test cmdIL-1.25 {Tcl_LsortObjCmd procedure, order of -index and -command} {
95 proc testcmp {a b} {return [string compare $a $b]}
96 set l [list [list a b] [list c d]]
97 set result [list [catch {lsort -index 1 -command testcmp $l} msg] $msg]
100 } [list 0 [list [list a b] [list c d]]]
101 # Note that the required order only exists in the end-1'th element;
102 # indexing using the end element or any fixed offset from the start
104 test cmdIL-1.26 {Tcl_LsortObjCmd procedure, offset indexing from end} {
105 lsort -index end-1 {{a 1 e i} {b 2 3 f g} {c 4 5 6 d h}}
106 } {{c 4 5 6 d h} {a 1 e i} {b 2 3 f g}}
107 test cmdIL-1.29 {Tcl_LsortObjCmd procedure, loss of list rep during sorting} {
109 proc testcmp args {string length $::l}
110 string length [lsort -command testcmp $l]
113 # Can't think of any good tests for the MergeSort and MergeLists
114 # procedures, except a bunch of random lists to sort.
116 test cmdIL-2.1 {MergeSort and MergeLists procedures} {
121 set r [expr {(16807 * $r) % (0x7fffffff)}]
123 for {set i 0} {$i < 150} {incr i} {
125 for {set j 0} {$j < $i} {incr j} {
126 lappend x [expr {[rand] & 0xfff}]
128 set y [lsort -integer $x]
132 append result "list {$x} sorted to {$y}, element $el out of order\n"
141 test cmdIL-3.1 {SortCompare procedure, skip comparisons after error} {
148 list [catch {lsort -integer -command cmp {48 6 28 190 16 2 3 6 1}} msg] \
151 test cmdIL-3.2 {SortCompare procedure, -index option} {
152 list [catch {lsort -integer -index 2 "\\\{ {30 40 50}"} msg] $msg
153 } {1 {unmatched open brace in list}}
154 test cmdIL-3.3 {SortCompare procedure, -index option} {
155 list [catch {lsort -integer -index 2 {{20 10} {15 30 40}}} msg] $msg
156 } {1 {element 2 missing from sublist "20 10"}}
157 test cmdIL-3.4 {SortCompare procedure, -index option} {
158 list [catch {lsort -integer -index 2 "{a b c} \\\{"} msg] $msg
159 } {1 {unmatched open brace in list}}
160 test cmdIL-3.5 {SortCompare procedure, -index option} {
161 list [catch {lsort -integer -index 2 {{20 10 13} {15}}} msg] $msg
162 } {1 {element 2 missing from sublist "15"}}
163 test cmdIL-3.6 {SortCompare procedure, -index option} {
164 lsort -integer -index 2 {{1 15 30} {2 5 25} {3 25 20}}
165 } {{3 25 20} {2 5 25} {1 15 30}}
166 test cmdIL-3.7 {SortCompare procedure, -ascii option} {
167 lsort -ascii {d e c b a d35 d300 100 20}
168 } {100 20 a b c d d300 d35 e}
169 test cmdIL-3.8 {SortCompare procedure, -dictionary option} {
170 lsort -dictionary {d e c b a d35 d300 100 20}
171 } {20 100 a b c d d35 d300 e}
172 test cmdIL-3.9 {SortCompare procedure, -integer option} {
173 list [catch {lsort -integer {x 3}} msg] $msg
174 } {1 {expected integer but got "x"}}
175 test cmdIL-3.10 {SortCompare procedure, -integer option} {
176 list [catch {lsort -integer {3 q}} msg] $msg
177 } {1 {expected integer but got "q"}}
178 test cmdIL-3.11 {SortCompare procedure, -integer option} {
179 lsort -integer {35 21 0x20 30 023 100 8}
180 } {8 023 21 30 0x20 35 100}
181 test cmdIL-3.12 {SortCompare procedure, -real option} {
182 list [catch {lsort -real {6...4 3}} msg] $msg
183 } {1 {expected floating-point number but got "6...4"}}
184 test cmdIL-3.13 {SortCompare procedure, -real option} {
185 list [catch {lsort -real {3 1x7}} msg] $msg
186 } {1 {expected floating-point number but got "1x7"}}
187 test cmdIL-3.14 {SortCompare procedure, -real option} {
188 lsort -real {24 2.5e01 16.7 85e-1 10.004}
189 } {85e-1 10.004 16.7 24 2.5e01}
190 test cmdIL-3.15 {SortCompare procedure, -command option} {
192 error "comparison error"
194 list [catch {lsort -command cmp {48 6}} msg] $msg $errorInfo
195 } {1 {comparison error} {comparison error
197 "error "comparison error""
198 (procedure "cmp" line 2)
203 "lsort -command cmp {48 6}"}}
204 test cmdIL-3.16 {SortCompare procedure, -command option, long command} {
205 proc cmp {dummy a b} {
208 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}}
209 } {{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}}
210 test cmdIL-3.17 {SortCompare procedure, -command option, non-integer result} {
214 list [catch {lsort -command cmp {48 6}} msg] $msg
215 } {1 {-compare command returned non-integer result}}
216 test cmdIL-3.18 {SortCompare procedure, -command option} {
220 lsort -command cmp {48 6 18 22 21 35 36}
221 } {48 36 35 22 21 18 6}
222 test cmdIL-3.19 {SortCompare procedure, -decreasing option} {
223 lsort -decreasing -integer {35 21 0x20 30 023 100 8}
224 } {100 35 0x20 30 21 023 8}
226 test cmdIL-4.1 {DictionaryCompare procedure, numerics, leading zeros} {
227 lsort -dictionary {a003b a03b}
229 test cmdIL-4.2 {DictionaryCompare procedure, numerics, leading zeros} {
230 lsort -dictionary {a3b a03b}
232 test cmdIL-4.3 {DictionaryCompare procedure, numerics, leading zeros} {
233 lsort -dictionary {a3b A03b}
235 test cmdIL-4.4 {DictionaryCompare procedure, numerics, leading zeros} {
236 lsort -dictionary {a3b a03B}
238 test cmdIL-4.5 {DictionaryCompare procedure, numerics, leading zeros} {
239 lsort -dictionary {00000 000}
241 test cmdIL-4.6 {DictionaryCompare procedure, numerics, different lengths} {
242 lsort -dictionary {a321b a03210b}
244 test cmdIL-4.7 {DictionaryCompare procedure, numerics, different lengths} {
245 lsort -dictionary {a03210b a321b}
247 test cmdIL-4.8 {DictionaryCompare procedure, numerics} {
248 lsort -dictionary {48 6a 18b 22a 21aa 35 36}
249 } {6a 18b 21aa 22a 35 36 48}
250 test cmdIL-4.9 {DictionaryCompare procedure, numerics} {
251 lsort -dictionary {a123x a123b}
253 test cmdIL-4.10 {DictionaryCompare procedure, numerics} {
254 lsort -dictionary {a123b a123x}
256 test cmdIL-4.11 {DictionaryCompare procedure, numerics} {
257 lsort -dictionary {a1b aab}
259 test cmdIL-4.12 {DictionaryCompare procedure, numerics} {
260 lsort -dictionary {a1b a!b}
262 test cmdIL-4.13 {DictionaryCompare procedure, numerics} {
263 lsort -dictionary {a1b2c a1b1c}
265 test cmdIL-4.14 {DictionaryCompare procedure, numerics} {
266 lsort -dictionary {a1b2c a1b3c}
268 test cmdIL-4.15 {DictionaryCompare procedure, long numbers} {
269 lsort -dictionary {a7654884321988762b a7654884321988761b}
270 } {a7654884321988761b a7654884321988762b}
271 test cmdIL-4.16 {DictionaryCompare procedure, long numbers} {
272 lsort -dictionary {a8765488432198876b a7654884321988761b}
273 } {a7654884321988761b a8765488432198876b}
274 test cmdIL-4.17 {DictionaryCompare procedure, case} {
275 lsort -dictionary {aBCd abcc}
277 test cmdIL-4.18 {DictionaryCompare procedure, case} {
278 lsort -dictionary {aBCd abce}
280 test cmdIL-4.19 {DictionaryCompare procedure, case} {
281 lsort -dictionary {abcd ABcc}
283 test cmdIL-4.20 {DictionaryCompare procedure, case} {
284 lsort -dictionary {abcd ABce}
286 test cmdIL-4.21 {DictionaryCompare procedure, case} {
287 lsort -dictionary {abCD ABcd}
289 test cmdIL-4.22 {DictionaryCompare procedure, case} {
290 lsort -dictionary {ABcd aBCd}
292 test cmdIL-4.23 {DictionaryCompare procedure, case} {
293 lsort -dictionary {ABcd AbCd}
295 test cmdIL-4.24 {DictionaryCompare procedure, international characters} {hasIsoLocale} {
296 ::tcltest::set_iso8859_1_locale
297 set result [lsort -dictionary "a b c A B C \xe3 \xc4"]
298 ::tcltest::restore_locale
300 } "A a B b C c \xe3 \xc4"
301 test cmdIL-4.25 {DictionaryCompare procedure, international characters} {hasIsoLocale} {
302 ::tcltest::set_iso8859_1_locale
303 set result [lsort -dictionary "a23\xe3 a23\xc5 a23\xe4"]
304 ::tcltest::restore_locale
306 } "a23\xe3 a23\xe4 a23\xc5"
307 test cmdIL-4.26 {DefaultCompare procedure, signed characters} {
308 set l [lsort [list "abc\200" "abc"]]
312 set len [string length $s]
313 for {set i 0} {$i < $len} {incr i} {
314 set c [string index $s $i]
316 if {$d > 0 && $d < 128} {
319 append viewelem "\\[format %03o $d]"
322 lappend viewlist $viewelem
325 } [list "abc" "abc\\200"]
326 test cmdIL-4.27 {DictionaryCompare procedure, signed characters} {
327 set l [lsort -dictionary [list "abc\200" "abc"]]
331 set len [string length $s]
332 for {set i 0} {$i < $len} {incr i} {
333 set c [string index $s $i]
335 if {$d > 0 && $d < 128} {
338 append viewelem "\\[format %03o $d]"
341 lappend viewlist $viewelem
344 } [list "abc" "abc\\200"]
345 test cmdIL-4.28 {DictionaryCompare procedure, chars between Z and a in ASCII} {
346 lsort -dictionary [list AA ` c CC]
348 test cmdIL-4.29 {DictionaryCompare procedure, chars between Z and a in ASCII} {
349 lsort -dictionary [list AA ` c ^ \\ CC \[ \]]
350 } [list \[ \\ \] ^ ` AA c CC]
351 test cmdIL-4.30 {DictionaryCompare procedure, chars between Z and a in ASCII} {
352 lsort -dictionary [list AA ` c ^ _ \\ CC \[ dude \] funky]
353 } [list \[ \\ \] ^ _ ` AA c CC dude funky]
354 test cmdIL-4.31 {DictionaryCompare procedure, chars between Z and a in ASCII} {
355 lsort -dictionary [list AA c ` CC]
357 test cmdIL-4.32 {DictionaryCompare procedure, chars between Z and a in ASCII} {
358 lsort -dictionary [list AA c CC `]
360 test cmdIL-4.33 {DictionaryCompare procedure, chars between Z and a in ASCII} {
361 lsort -dictionary [list AA ! c CC `]
365 ::tcltest::cleanupTests