os/persistentdata/persistentstorage/sqlite3api/TEST/TCL/tcldistribution/tests/cmdIL.test
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/persistentdata/persistentstorage/sqlite3api/TEST/TCL/tcldistribution/tests/cmdIL.test Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,366 @@
1.4 +# This file contains a collection of tests for the procedures in the
1.5 +# file tclCmdIL.c. Sourcing this file into Tcl runs the tests and
1.6 +# generates output for errors. No output means no errors were found.
1.7 +#
1.8 +# Copyright (c) 1997 Sun Microsystems, Inc.
1.9 +# Copyright (c) 1998-1999 by Scriptics Corporation.
1.10 +#
1.11 +# See the file "license.terms" for information on usage and redistribution
1.12 +# of this file, and for a DISCLAIMER OF ALL WARRANTIES.
1.13 +#
1.14 +# RCS: @(#) $Id: cmdIL.test,v 1.14.6.2 2007/03/10 14:57:38 dkf Exp $
1.15 +
1.16 +if {[lsearch [namespace children] ::tcltest] == -1} {
1.17 + package require tcltest
1.18 + namespace import -force ::tcltest::*
1.19 +}
1.20 +
1.21 +test cmdIL-1.1 {Tcl_LsortObjCmd procedure} {
1.22 + list [catch {lsort} msg] $msg
1.23 +} {1 {wrong # args: should be "lsort ?options? list"}}
1.24 +test cmdIL-1.2 {Tcl_LsortObjCmd procedure} {
1.25 + list [catch {lsort -foo {1 3 2 5}} msg] $msg
1.26 +} {1 {bad option "-foo": must be -ascii, -command, -decreasing, -dictionary, -increasing, -index, -integer, -real, or -unique}}
1.27 +test cmdIL-1.3 {Tcl_LsortObjCmd procedure, default options} {
1.28 + lsort {d e c b a \{ d35 d300}
1.29 +} {a b c d d300 d35 e \{}
1.30 +test cmdIL-1.4 {Tcl_LsortObjCmd procedure, -ascii option} {
1.31 + lsort -integer -ascii {d e c b a d35 d300}
1.32 +} {a b c d d300 d35 e}
1.33 +test cmdIL-1.5 {Tcl_LsortObjCmd procedure, -command option} {
1.34 + list [catch {lsort -command {1 3 2 5}} msg] $msg
1.35 +} {1 {"-command" option must be followed by comparison command}}
1.36 +test cmdIL-1.6 {Tcl_LsortObjCmd procedure, -command option} {
1.37 + proc cmp {a b} {
1.38 + expr {[string match x* $b] - [string match x* $a]}
1.39 + }
1.40 + lsort -command cmp {x1 abc x2 def x3 x4}
1.41 +} {x1 x2 x3 x4 abc def}
1.42 +test cmdIL-1.7 {Tcl_LsortObjCmd procedure, -decreasing option} {
1.43 + lsort -decreasing {d e c b a d35 d300}
1.44 +} {e d35 d300 d c b a}
1.45 +test cmdIL-1.8 {Tcl_LsortObjCmd procedure, -dictionary option} {
1.46 + lsort -dictionary {d e c b a d35 d300}
1.47 +} {a b c d d35 d300 e}
1.48 +test cmdIL-1.9 {Tcl_LsortObjCmd procedure, -dictionary option} {
1.49 + lsort -dictionary {1k 0k 10k}
1.50 +} {0k 1k 10k}
1.51 +test cmdIL-1.10 {Tcl_LsortObjCmd procedure, -increasing option} {
1.52 + lsort -decreasing -increasing {d e c b a d35 d300}
1.53 +} {a b c d d300 d35 e}
1.54 +test cmdIL-1.11 {Tcl_LsortObjCmd procedure, -index option} {
1.55 + list [catch {lsort -index {1 3 2 5}} msg] $msg
1.56 +} {1 {"-index" option must be followed by list index}}
1.57 +test cmdIL-1.12 {Tcl_LsortObjCmd procedure, -index option} {
1.58 + list [catch {lsort -index foo {1 3 2 5}} msg] $msg
1.59 +} {1 {bad index "foo": must be integer or end?-integer?}}
1.60 +test cmdIL-1.13 {Tcl_LsortObjCmd procedure, -index option} {
1.61 + lsort -index end -integer {{2 25} {10 20 50 100} {3 16 42} 1}
1.62 +} {1 {2 25} {3 16 42} {10 20 50 100}}
1.63 +test cmdIL-1.14 {Tcl_LsortObjCmd procedure, -index option} {
1.64 + lsort -index 1 -integer {{1 25 100} {3 16 42} {10 20 50}}
1.65 +} {{3 16 42} {10 20 50} {1 25 100}}
1.66 +test cmdIL-1.15 {Tcl_LsortObjCmd procedure, -integer option} {
1.67 + lsort -integer {24 6 300 18}
1.68 +} {6 18 24 300}
1.69 +test cmdIL-1.16 {Tcl_LsortObjCmd procedure, -integer option} {
1.70 + list [catch {lsort -integer {1 3 2.4}} msg] $msg
1.71 +} {1 {expected integer but got "2.4"}}
1.72 +test cmdIL-1.17 {Tcl_LsortObjCmd procedure, -real option} {
1.73 + lsort -real {24.2 6e3 150e-1}
1.74 +} {150e-1 24.2 6e3}
1.75 +test cmdIL-1.18 {Tcl_LsortObjCmd procedure, bogus list} {
1.76 + list [catch {lsort "1 2 3 \{ 4"} msg] $msg
1.77 +} {1 {unmatched open brace in list}}
1.78 +test cmdIL-1.19 {Tcl_LsortObjCmd procedure, empty list} {
1.79 + lsort {}
1.80 +} {}
1.81 +test cmdIL-1.22 {Tcl_LsortObjCmd procedure, unique sort} {
1.82 + lsort -integer -unique {3 1 2 3 1 4 3}
1.83 +} {1 2 3 4}
1.84 +test cmdIL-1.23 {Tcl_LsortObjCmd procedure, unique sort with index} {
1.85 + # lsort -unique should return the last unique item
1.86 + lsort -unique -index 0 {{a b} {c b} {a c} {d a}}
1.87 +} {{a c} {c b} {d a}}
1.88 +test cmdIL-1.24 {Tcl_LsortObjCmd procedure, order of -index and -command} {
1.89 + catch {rename 1 ""}
1.90 + proc testcmp {a b} {return [string compare $a $b]}
1.91 + set l [list [list a b] [list c d]]
1.92 + set result [list [catch {lsort -command testcmp -index 1 $l} msg] $msg]
1.93 + rename testcmp ""
1.94 + set result
1.95 +} [list 0 [list [list a b] [list c d]]]
1.96 +test cmdIL-1.25 {Tcl_LsortObjCmd procedure, order of -index and -command} {
1.97 + catch {rename 1 ""}
1.98 + proc testcmp {a b} {return [string compare $a $b]}
1.99 + set l [list [list a b] [list c d]]
1.100 + set result [list [catch {lsort -index 1 -command testcmp $l} msg] $msg]
1.101 + rename testcmp ""
1.102 + set result
1.103 +} [list 0 [list [list a b] [list c d]]]
1.104 +# Note that the required order only exists in the end-1'th element;
1.105 +# indexing using the end element or any fixed offset from the start
1.106 +# will not work...
1.107 +test cmdIL-1.26 {Tcl_LsortObjCmd procedure, offset indexing from end} {
1.108 + lsort -index end-1 {{a 1 e i} {b 2 3 f g} {c 4 5 6 d h}}
1.109 +} {{c 4 5 6 d h} {a 1 e i} {b 2 3 f g}}
1.110 +test cmdIL-1.29 {Tcl_LsortObjCmd procedure, loss of list rep during sorting} {
1.111 + set l {1 2 3}
1.112 + proc testcmp args {string length $::l}
1.113 + string length [lsort -command testcmp $l]
1.114 +} 5
1.115 +
1.116 +# Can't think of any good tests for the MergeSort and MergeLists
1.117 +# procedures, except a bunch of random lists to sort.
1.118 +
1.119 +test cmdIL-2.1 {MergeSort and MergeLists procedures} {
1.120 + set result {}
1.121 + set r 1435753299
1.122 + proc rand {} {
1.123 + global r
1.124 + set r [expr {(16807 * $r) % (0x7fffffff)}]
1.125 + }
1.126 + for {set i 0} {$i < 150} {incr i} {
1.127 + set x {}
1.128 + for {set j 0} {$j < $i} {incr j} {
1.129 + lappend x [expr {[rand] & 0xfff}]
1.130 + }
1.131 + set y [lsort -integer $x]
1.132 + set old -1
1.133 + foreach el $y {
1.134 + if {$el < $old} {
1.135 + append result "list {$x} sorted to {$y}, element $el out of order\n"
1.136 + break
1.137 + }
1.138 + set old $el
1.139 + }
1.140 + }
1.141 + set result
1.142 +} {}
1.143 +
1.144 +test cmdIL-3.1 {SortCompare procedure, skip comparisons after error} {
1.145 + set x 0
1.146 + proc cmp {a b} {
1.147 + global x
1.148 + incr x
1.149 + error "error #$x"
1.150 + }
1.151 + list [catch {lsort -integer -command cmp {48 6 28 190 16 2 3 6 1}} msg] \
1.152 + $msg $x
1.153 +} {1 {error #1} 1}
1.154 +test cmdIL-3.2 {SortCompare procedure, -index option} {
1.155 + list [catch {lsort -integer -index 2 "\\\{ {30 40 50}"} msg] $msg
1.156 +} {1 {unmatched open brace in list}}
1.157 +test cmdIL-3.3 {SortCompare procedure, -index option} {
1.158 + list [catch {lsort -integer -index 2 {{20 10} {15 30 40}}} msg] $msg
1.159 +} {1 {element 2 missing from sublist "20 10"}}
1.160 +test cmdIL-3.4 {SortCompare procedure, -index option} {
1.161 + list [catch {lsort -integer -index 2 "{a b c} \\\{"} msg] $msg
1.162 +} {1 {unmatched open brace in list}}
1.163 +test cmdIL-3.5 {SortCompare procedure, -index option} {
1.164 + list [catch {lsort -integer -index 2 {{20 10 13} {15}}} msg] $msg
1.165 +} {1 {element 2 missing from sublist "15"}}
1.166 +test cmdIL-3.6 {SortCompare procedure, -index option} {
1.167 + lsort -integer -index 2 {{1 15 30} {2 5 25} {3 25 20}}
1.168 +} {{3 25 20} {2 5 25} {1 15 30}}
1.169 +test cmdIL-3.7 {SortCompare procedure, -ascii option} {
1.170 + lsort -ascii {d e c b a d35 d300 100 20}
1.171 +} {100 20 a b c d d300 d35 e}
1.172 +test cmdIL-3.8 {SortCompare procedure, -dictionary option} {
1.173 + lsort -dictionary {d e c b a d35 d300 100 20}
1.174 +} {20 100 a b c d d35 d300 e}
1.175 +test cmdIL-3.9 {SortCompare procedure, -integer option} {
1.176 + list [catch {lsort -integer {x 3}} msg] $msg
1.177 +} {1 {expected integer but got "x"}}
1.178 +test cmdIL-3.10 {SortCompare procedure, -integer option} {
1.179 + list [catch {lsort -integer {3 q}} msg] $msg
1.180 +} {1 {expected integer but got "q"}}
1.181 +test cmdIL-3.11 {SortCompare procedure, -integer option} {
1.182 + lsort -integer {35 21 0x20 30 023 100 8}
1.183 +} {8 023 21 30 0x20 35 100}
1.184 +test cmdIL-3.12 {SortCompare procedure, -real option} {
1.185 + list [catch {lsort -real {6...4 3}} msg] $msg
1.186 +} {1 {expected floating-point number but got "6...4"}}
1.187 +test cmdIL-3.13 {SortCompare procedure, -real option} {
1.188 + list [catch {lsort -real {3 1x7}} msg] $msg
1.189 +} {1 {expected floating-point number but got "1x7"}}
1.190 +test cmdIL-3.14 {SortCompare procedure, -real option} {
1.191 + lsort -real {24 2.5e01 16.7 85e-1 10.004}
1.192 +} {85e-1 10.004 16.7 24 2.5e01}
1.193 +test cmdIL-3.15 {SortCompare procedure, -command option} {
1.194 + proc cmp {a b} {
1.195 + error "comparison error"
1.196 + }
1.197 + list [catch {lsort -command cmp {48 6}} msg] $msg $errorInfo
1.198 +} {1 {comparison error} {comparison error
1.199 + while executing
1.200 +"error "comparison error""
1.201 + (procedure "cmp" line 2)
1.202 + invoked from within
1.203 +"cmp 48 6"
1.204 + (-compare command)
1.205 + invoked from within
1.206 +"lsort -command cmp {48 6}"}}
1.207 +test cmdIL-3.16 {SortCompare procedure, -command option, long command} {
1.208 + proc cmp {dummy a b} {
1.209 + string compare $a $b
1.210 + }
1.211 + 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}}
1.212 +} {{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}}
1.213 +test cmdIL-3.17 {SortCompare procedure, -command option, non-integer result} {
1.214 + proc cmp {a b} {
1.215 + return foow
1.216 + }
1.217 + list [catch {lsort -command cmp {48 6}} msg] $msg
1.218 +} {1 {-compare command returned non-integer result}}
1.219 +test cmdIL-3.18 {SortCompare procedure, -command option} {
1.220 + proc cmp {a b} {
1.221 + expr {$b - $a}
1.222 + }
1.223 + lsort -command cmp {48 6 18 22 21 35 36}
1.224 +} {48 36 35 22 21 18 6}
1.225 +test cmdIL-3.19 {SortCompare procedure, -decreasing option} {
1.226 + lsort -decreasing -integer {35 21 0x20 30 023 100 8}
1.227 +} {100 35 0x20 30 21 023 8}
1.228 +
1.229 +test cmdIL-4.1 {DictionaryCompare procedure, numerics, leading zeros} {
1.230 + lsort -dictionary {a003b a03b}
1.231 +} {a03b a003b}
1.232 +test cmdIL-4.2 {DictionaryCompare procedure, numerics, leading zeros} {
1.233 + lsort -dictionary {a3b a03b}
1.234 +} {a3b a03b}
1.235 +test cmdIL-4.3 {DictionaryCompare procedure, numerics, leading zeros} {
1.236 + lsort -dictionary {a3b A03b}
1.237 +} {A03b a3b}
1.238 +test cmdIL-4.4 {DictionaryCompare procedure, numerics, leading zeros} {
1.239 + lsort -dictionary {a3b a03B}
1.240 +} {a3b a03B}
1.241 +test cmdIL-4.5 {DictionaryCompare procedure, numerics, leading zeros} {
1.242 + lsort -dictionary {00000 000}
1.243 +} {000 00000}
1.244 +test cmdIL-4.6 {DictionaryCompare procedure, numerics, different lengths} {
1.245 + lsort -dictionary {a321b a03210b}
1.246 +} {a321b a03210b}
1.247 +test cmdIL-4.7 {DictionaryCompare procedure, numerics, different lengths} {
1.248 + lsort -dictionary {a03210b a321b}
1.249 +} {a321b a03210b}
1.250 +test cmdIL-4.8 {DictionaryCompare procedure, numerics} {
1.251 + lsort -dictionary {48 6a 18b 22a 21aa 35 36}
1.252 +} {6a 18b 21aa 22a 35 36 48}
1.253 +test cmdIL-4.9 {DictionaryCompare procedure, numerics} {
1.254 + lsort -dictionary {a123x a123b}
1.255 +} {a123b a123x}
1.256 +test cmdIL-4.10 {DictionaryCompare procedure, numerics} {
1.257 + lsort -dictionary {a123b a123x}
1.258 +} {a123b a123x}
1.259 +test cmdIL-4.11 {DictionaryCompare procedure, numerics} {
1.260 + lsort -dictionary {a1b aab}
1.261 +} {a1b aab}
1.262 +test cmdIL-4.12 {DictionaryCompare procedure, numerics} {
1.263 + lsort -dictionary {a1b a!b}
1.264 +} {a!b a1b}
1.265 +test cmdIL-4.13 {DictionaryCompare procedure, numerics} {
1.266 + lsort -dictionary {a1b2c a1b1c}
1.267 +} {a1b1c a1b2c}
1.268 +test cmdIL-4.14 {DictionaryCompare procedure, numerics} {
1.269 + lsort -dictionary {a1b2c a1b3c}
1.270 +} {a1b2c a1b3c}
1.271 +test cmdIL-4.15 {DictionaryCompare procedure, long numbers} {
1.272 + lsort -dictionary {a7654884321988762b a7654884321988761b}
1.273 +} {a7654884321988761b a7654884321988762b}
1.274 +test cmdIL-4.16 {DictionaryCompare procedure, long numbers} {
1.275 + lsort -dictionary {a8765488432198876b a7654884321988761b}
1.276 +} {a7654884321988761b a8765488432198876b}
1.277 +test cmdIL-4.17 {DictionaryCompare procedure, case} {
1.278 + lsort -dictionary {aBCd abcc}
1.279 +} {abcc aBCd}
1.280 +test cmdIL-4.18 {DictionaryCompare procedure, case} {
1.281 + lsort -dictionary {aBCd abce}
1.282 +} {aBCd abce}
1.283 +test cmdIL-4.19 {DictionaryCompare procedure, case} {
1.284 + lsort -dictionary {abcd ABcc}
1.285 +} {ABcc abcd}
1.286 +test cmdIL-4.20 {DictionaryCompare procedure, case} {
1.287 + lsort -dictionary {abcd ABce}
1.288 +} {abcd ABce}
1.289 +test cmdIL-4.21 {DictionaryCompare procedure, case} {
1.290 + lsort -dictionary {abCD ABcd}
1.291 +} {ABcd abCD}
1.292 +test cmdIL-4.22 {DictionaryCompare procedure, case} {
1.293 + lsort -dictionary {ABcd aBCd}
1.294 +} {ABcd aBCd}
1.295 +test cmdIL-4.23 {DictionaryCompare procedure, case} {
1.296 + lsort -dictionary {ABcd AbCd}
1.297 +} {ABcd AbCd}
1.298 +test cmdIL-4.24 {DictionaryCompare procedure, international characters} {hasIsoLocale} {
1.299 + ::tcltest::set_iso8859_1_locale
1.300 + set result [lsort -dictionary "a b c A B C \xe3 \xc4"]
1.301 + ::tcltest::restore_locale
1.302 + set result
1.303 +} "A a B b C c \xe3 \xc4"
1.304 +test cmdIL-4.25 {DictionaryCompare procedure, international characters} {hasIsoLocale} {
1.305 + ::tcltest::set_iso8859_1_locale
1.306 + set result [lsort -dictionary "a23\xe3 a23\xc5 a23\xe4"]
1.307 + ::tcltest::restore_locale
1.308 + set result
1.309 +} "a23\xe3 a23\xe4 a23\xc5"
1.310 +test cmdIL-4.26 {DefaultCompare procedure, signed characters} {
1.311 + set l [lsort [list "abc\200" "abc"]]
1.312 + set viewlist {}
1.313 + foreach s $l {
1.314 + set viewelem ""
1.315 + set len [string length $s]
1.316 + for {set i 0} {$i < $len} {incr i} {
1.317 + set c [string index $s $i]
1.318 + scan $c %c d
1.319 + if {$d > 0 && $d < 128} {
1.320 + append viewelem $c
1.321 + } else {
1.322 + append viewelem "\\[format %03o $d]"
1.323 + }
1.324 + }
1.325 + lappend viewlist $viewelem
1.326 + }
1.327 + set viewlist
1.328 +} [list "abc" "abc\\200"]
1.329 +test cmdIL-4.27 {DictionaryCompare procedure, signed characters} {
1.330 + set l [lsort -dictionary [list "abc\200" "abc"]]
1.331 + set viewlist {}
1.332 + foreach s $l {
1.333 + set viewelem ""
1.334 + set len [string length $s]
1.335 + for {set i 0} {$i < $len} {incr i} {
1.336 + set c [string index $s $i]
1.337 + scan $c %c d
1.338 + if {$d > 0 && $d < 128} {
1.339 + append viewelem $c
1.340 + } else {
1.341 + append viewelem "\\[format %03o $d]"
1.342 + }
1.343 + }
1.344 + lappend viewlist $viewelem
1.345 + }
1.346 + set viewlist
1.347 +} [list "abc" "abc\\200"]
1.348 +test cmdIL-4.28 {DictionaryCompare procedure, chars between Z and a in ASCII} {
1.349 + lsort -dictionary [list AA ` c CC]
1.350 +} [list ` AA c CC]
1.351 +test cmdIL-4.29 {DictionaryCompare procedure, chars between Z and a in ASCII} {
1.352 + lsort -dictionary [list AA ` c ^ \\ CC \[ \]]
1.353 +} [list \[ \\ \] ^ ` AA c CC]
1.354 +test cmdIL-4.30 {DictionaryCompare procedure, chars between Z and a in ASCII} {
1.355 + lsort -dictionary [list AA ` c ^ _ \\ CC \[ dude \] funky]
1.356 +} [list \[ \\ \] ^ _ ` AA c CC dude funky]
1.357 +test cmdIL-4.31 {DictionaryCompare procedure, chars between Z and a in ASCII} {
1.358 + lsort -dictionary [list AA c ` CC]
1.359 +} [list ` AA c CC]
1.360 +test cmdIL-4.32 {DictionaryCompare procedure, chars between Z and a in ASCII} {
1.361 + lsort -dictionary [list AA c CC `]
1.362 +} [list ` AA c CC]
1.363 +test cmdIL-4.33 {DictionaryCompare procedure, chars between Z and a in ASCII} {
1.364 + lsort -dictionary [list AA ! c CC `]
1.365 +} [list ! ` AA c CC]
1.366 +
1.367 +# cleanup
1.368 +::tcltest::cleanupTests
1.369 +return