os/persistentdata/persistentstorage/sqlite3api/TEST/TCL/tcldistribution/tests/lindex.test
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/persistentdata/persistentstorage/sqlite3api/TEST/TCL/tcldistribution/tests/lindex.test Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,477 @@
1.4 +# Commands covered: lindex
1.5 +#
1.6 +# This file contains a collection of tests for one or more of the Tcl
1.7 +# built-in commands. Sourcing this file into Tcl runs the tests and
1.8 +# generates output for errors. No output means no errors were found.
1.9 +#
1.10 +# Copyright (c) 1991-1993 The Regents of the University of California.
1.11 +# Copyright (c) 1994 Sun Microsystems, Inc.
1.12 +# Copyright (c) 1998-1999 by Scriptics Corporation.
1.13 +# Copyright (c) 2001 by Kevin B. Kenny. All rights reserved.
1.14 +#
1.15 +# See the file "license.terms" for information on usage and redistribution
1.16 +# of this file, and for a DISCLAIMER OF ALL WARRANTIES.
1.17 +#
1.18 +# RCS: @(#) $Id: lindex.test,v 1.10 2002/04/19 13:08:56 dkf Exp $
1.19 +
1.20 +if {[lsearch [namespace children] ::tcltest] == -1} {
1.21 + package require tcltest
1.22 + namespace import -force ::tcltest::*
1.23 +}
1.24 +
1.25 +set lindex lindex
1.26 +set minus -
1.27 +
1.28 +# Tests of Tcl_LindexObjCmd, NOT COMPILED
1.29 +
1.30 +test lindex-1.1 {wrong # args} {
1.31 + list [catch {eval $lindex} result] $result
1.32 +} "1 {wrong # args: should be \"lindex list ?index...?\"}"
1.33 +
1.34 +# Indices that are lists or convertible to lists
1.35 +
1.36 +test lindex-2.1 {empty index list} {
1.37 + set x {}
1.38 + list [eval [list $lindex {a b c} $x]] [eval [list $lindex {a b c} $x]]
1.39 +} {{a b c} {a b c}}
1.40 +
1.41 +test lindex-2.2 {singleton index list} {
1.42 + set x { 1 }
1.43 + list [eval [list $lindex {a b c} $x]] [eval [list $lindex {a b c} $x]]
1.44 +} {b b}
1.45 +
1.46 +test lindex-2.3 {multiple indices in list} {
1.47 + set x {1 2}
1.48 + list [eval [list $lindex {{a b c} {d e f}} $x]] \
1.49 + [eval [list $lindex {{a b c} {d e f}} $x]]
1.50 +} {f f}
1.51 +
1.52 +test lindex-2.4 {malformed index list} {
1.53 + set x \{
1.54 + list [catch { eval [list $lindex {a b c} $x] } result] $result
1.55 +} {1 bad\ index\ \"\{\":\ must\ be\ integer\ or\ end?-integer?}
1.56 +
1.57 +# Indices that are integers or convertible to integers
1.58 +
1.59 +test lindex-3.1 {integer -1} {
1.60 + set x ${minus}1
1.61 + list [eval [list $lindex {a b c} $x]] [eval [list $lindex {a b c} $x]]
1.62 +} {{} {}}
1.63 +
1.64 +test lindex-3.2 {integer 0} {
1.65 + set x [string range 00 0 0]
1.66 + list [eval [list $lindex {a b c} $x]] [eval [list $lindex {a b c} $x]]
1.67 +} {a a}
1.68 +
1.69 +test lindex-3.3 {integer 2} {
1.70 + set x [string range 22 0 0]
1.71 + list [eval [list $lindex {a b c} $x]] [eval [list $lindex {a b c} $x]]
1.72 +} {c c}
1.73 +
1.74 +test lindex-3.4 {integer 3} {
1.75 + set x [string range 33 0 0]
1.76 + list [eval [list $lindex {a b c} $x]] [eval [list $lindex {a b c} $x]]
1.77 +} {{} {}}
1.78 +
1.79 +test lindex-3.5 {bad octal} {
1.80 + set x 08
1.81 + list [catch { eval [list $lindex {a b c} $x] } result] $result
1.82 +} "1 {bad index \"08\": must be integer or end?-integer? (looks like invalid octal number)}"
1.83 +
1.84 +test lindex-3.6 {bad octal} {
1.85 + set x -09
1.86 + list [catch { eval [list $lindex {a b c} $x] } result] $result
1.87 +} "1 {bad index \"-09\": must be integer or end?-integer? (looks like invalid octal number)}"
1.88 +
1.89 +test lindex-3.7 {indexes don't shimmer wide ints} {
1.90 + set x [expr {(wide(1)<<31) - 2}]
1.91 + list $x [lindex {1 2 3} $x] [incr x] [incr x]
1.92 +} {2147483646 {} 2147483647 2147483648}
1.93 +
1.94 +# Indices relative to end
1.95 +
1.96 +test lindex-4.1 {index = end} {
1.97 + set x end
1.98 + list [eval [list $lindex {a b c} $x]] [eval [list $lindex {a b c} $x]]
1.99 +} {c c}
1.100 +
1.101 +test lindex-4.2 {index = end--1} {
1.102 + set x end--1
1.103 + list [eval [list $lindex {a b c} $x]] [eval [list $lindex {a b c} $x]]
1.104 +} {{} {}}
1.105 +
1.106 +test lindex-4.3 {index = end-0} {
1.107 + set x end-0
1.108 + list [eval [list $lindex {a b c} $x]] [eval [list $lindex {a b c} $x]]
1.109 +} {c c}
1.110 +
1.111 +test lindex-4.4 {index = end-2} {
1.112 + set x end-2
1.113 + list [eval [list $lindex {a b c} $x]] [eval [list $lindex {a b c} $x]]
1.114 +} {a a}
1.115 +
1.116 +test lindex-4.5 {index = end-3} {
1.117 + set x end-3
1.118 + list [eval [list $lindex {a b c} $x]] [eval [list $lindex {a b c} $x]]
1.119 +} {{} {}}
1.120 +
1.121 +test lindex-4.6 {bad octal} {
1.122 + set x end-08
1.123 + list [catch { eval [list $lindex {a b c} $x] } result] $result
1.124 +} "1 {bad index \"end-08\": must be integer or end?-integer? (looks like invalid octal number)}"
1.125 +
1.126 +test lindex-4.7 {bad octal} {
1.127 + set x end--09
1.128 + list [catch { eval [list $lindex {a b c} $x] } result] $result
1.129 +} "1 {bad index \"end--09\": must be integer or end?-integer?}"
1.130 +
1.131 +test lindex-4.8 {bad integer, not octal} {
1.132 + set x end-0a2
1.133 + list [catch { eval [list $lindex {a b c} $x] } result] $result
1.134 +} "1 {bad index \"end-0a2\": must be integer or end?-integer?}"
1.135 +
1.136 +test lindex-4.9 {incomplete end} {
1.137 + set x en
1.138 + list [eval [list $lindex {a b c} $x]] [eval [list $lindex {a b c} $x]]
1.139 +} {c c}
1.140 +
1.141 +test lindex-4.10 {incomplete end-} {
1.142 + set x end-
1.143 + list [catch { eval [list $lindex {a b c} $x] } result] $result
1.144 +} "1 {bad index \"end-\": must be integer or end?-integer?}"
1.145 +
1.146 +test lindex-5.1 {bad second index} {
1.147 + list [catch { eval [list $lindex {a b c} 0 0a2] } result] $result
1.148 +} "1 {bad index \"0a2\": must be integer or end?-integer?}"
1.149 +
1.150 +test lindex-5.2 {good second index} {
1.151 + eval [list $lindex {{a b c} {d e f} {g h i}} 1 2]
1.152 +} f
1.153 +
1.154 +test lindex-5.3 {three indices} {
1.155 + eval [list $lindex {{{a b} {c d}} {{e f} {g h}}} 1 0 1]
1.156 +} f
1.157 +test lindex-6.1 {error conditions in parsing list} {
1.158 + list [catch {eval [list $lindex "a \{" 2]} msg] $msg
1.159 +} {1 {unmatched open brace in list}}
1.160 +test lindex-6.2 {error conditions in parsing list} {
1.161 + list [catch {eval [list $lindex {a {b c}d e} 2]} msg] $msg
1.162 +} {1 {list element in braces followed by "d" instead of space}}
1.163 +test lindex-6.3 {error conditions in parsing list} {
1.164 + list [catch {eval [list $lindex {a "b c"def ghi} 2]} msg] $msg
1.165 +} {1 {list element in quotes followed by "def" instead of space}}
1.166 +
1.167 +test lindex-7.1 {quoted elements} {
1.168 + eval [list $lindex {a "b c" d} 1]
1.169 +} {b c}
1.170 +test lindex-7.2 {quoted elements} {
1.171 + eval [list $lindex {"{}" b c} 0]
1.172 +} {{}}
1.173 +test lindex-7.3 {quoted elements} {
1.174 + eval [list $lindex {ab "c d \" x" y} 1]
1.175 +} {c d " x}
1.176 +test lindex-7.4 {quoted elements} {
1.177 + lindex {a b {c d "e} {f g"}} 2
1.178 +} {c d "e}
1.179 +
1.180 +test lindex-8.1 {data reuse} {
1.181 + set x 0
1.182 + eval [list $lindex $x $x]
1.183 +} {0}
1.184 +
1.185 +test lindex-8.2 {data reuse} {
1.186 + set a 0
1.187 + eval [list $lindex $a $a $a]
1.188 +} 0
1.189 +test lindex-8.3 {data reuse} {
1.190 + set a 1
1.191 + eval [list $lindex $a $a $a]
1.192 +} {}
1.193 +
1.194 +test lindex-8.4 {data reuse} {
1.195 + set x [list 0 0]
1.196 + eval [list $lindex $x $x]
1.197 +} {0}
1.198 +
1.199 +test lindex-8.5 {data reuse} {
1.200 + set x 0
1.201 + eval [list $lindex $x [list $x $x]]
1.202 +} {0}
1.203 +
1.204 +test lindex-8.6 {data reuse} {
1.205 + set x [list 1 1]
1.206 + eval [list $lindex $x $x]
1.207 +} {}
1.208 +
1.209 +test lindex-8.7 {data reuse} {
1.210 + set x 1
1.211 + eval [list lindex $x [list $x $x]]
1.212 +} {}
1.213 +
1.214 +#----------------------------------------------------------------------
1.215 +
1.216 +# Compilation tests for lindex
1.217 +
1.218 +test lindex-9.1 {wrong # args} {
1.219 + list [catch {lindex} result] $result
1.220 +} "1 {wrong # args: should be \"lindex list ?index...?\"}"
1.221 +
1.222 +# Indices that are lists or convertible to lists
1.223 +
1.224 +test lindex-10.1 {empty index list} {
1.225 + set x {}
1.226 + catch {
1.227 + list [lindex {a b c} $x] [lindex {a b c} $x]
1.228 + } result
1.229 + set result
1.230 +} {{a b c} {a b c}}
1.231 +
1.232 +test lindex-10.2 {singleton index list} {
1.233 + set x { 1 }
1.234 + catch {
1.235 + list [lindex {a b c} $x] [lindex {a b c} $x]
1.236 + } result
1.237 + set result
1.238 +} {b b}
1.239 +
1.240 +test lindex-10.3 {multiple indices in list} {
1.241 + set x {1 2}
1.242 + catch {
1.243 + list [lindex {{a b c} {d e f}} $x] [lindex {{a b c} {d e f}} $x]
1.244 + } result
1.245 + set result
1.246 +} {f f}
1.247 +
1.248 +test lindex-10.4 {malformed index list} {
1.249 + set x \{
1.250 + list [catch { lindex {a b c} $x } result] $result
1.251 +} {1 bad\ index\ \"\{\":\ must\ be\ integer\ or\ end?-integer?}
1.252 +
1.253 +# Indices that are integers or convertible to integers
1.254 +
1.255 +test lindex-11.1 {integer -1} {
1.256 + set x ${minus}1
1.257 + catch {
1.258 + list [lindex {a b c} $x] [lindex {a b c} $x]
1.259 + } result
1.260 + set result
1.261 +} {{} {}}
1.262 +
1.263 +test lindex-11.2 {integer 0} {
1.264 + set x [string range 00 0 0]
1.265 + catch {
1.266 + list [lindex {a b c} $x] [lindex {a b c} $x]
1.267 + } result
1.268 + set result
1.269 +} {a a}
1.270 +
1.271 +test lindex-11.3 {integer 2} {
1.272 + set x [string range 22 0 0]
1.273 + catch {
1.274 + list [lindex {a b c} $x] [lindex {a b c} $x]
1.275 + } result
1.276 + set result
1.277 +} {c c}
1.278 +
1.279 +test lindex-11.4 {integer 3} {
1.280 + set x [string range 33 0 0]
1.281 + catch {
1.282 + list [lindex {a b c} $x] [lindex {a b c} $x]
1.283 + } result
1.284 + set result
1.285 +} {{} {}}
1.286 +
1.287 +test lindex-11.5 {bad octal} {
1.288 + set x 08
1.289 + list [catch { lindex {a b c} $x } result] $result
1.290 +} "1 {bad index \"08\": must be integer or end?-integer? (looks like invalid octal number)}"
1.291 +
1.292 +test lindex-11.6 {bad octal} {
1.293 + set x -09
1.294 + list [catch { lindex {a b c} $x } result] $result
1.295 +} "1 {bad index \"-09\": must be integer or end?-integer? (looks like invalid octal number)}"
1.296 +
1.297 +# Indices relative to end
1.298 +
1.299 +test lindex-12.1 {index = end} {
1.300 + set x end
1.301 + catch {
1.302 + list [lindex {a b c} $x] [lindex {a b c} $x]
1.303 + } result
1.304 + set result
1.305 +} {c c}
1.306 +
1.307 +test lindex-12.2 {index = end--1} {
1.308 + set x end--1
1.309 + catch {
1.310 + list [lindex {a b c} $x] [lindex {a b c} $x]
1.311 + } result
1.312 + set result
1.313 +} {{} {}}
1.314 +
1.315 +test lindex-12.3 {index = end-0} {
1.316 + set x end-0
1.317 + catch {
1.318 + list [lindex {a b c} $x] [lindex {a b c} $x]
1.319 + } result
1.320 + set result
1.321 +} {c c}
1.322 +
1.323 +test lindex-12.4 {index = end-2} {
1.324 + set x end-2
1.325 + catch {
1.326 + list [lindex {a b c} $x] [lindex {a b c} $x]
1.327 + } result
1.328 + set result
1.329 +} {a a}
1.330 +
1.331 +test lindex-12.5 {index = end-3} {
1.332 + set x end-3
1.333 + catch {
1.334 + list [lindex {a b c} $x] [lindex {a b c} $x]
1.335 + } result
1.336 + set result
1.337 +} {{} {}}
1.338 +
1.339 +test lindex-12.6 {bad octal} {
1.340 + set x end-08
1.341 + list [catch { lindex {a b c} $x } result] $result
1.342 +} "1 {bad index \"end-08\": must be integer or end?-integer? (looks like invalid octal number)}"
1.343 +
1.344 +test lindex-12.7 {bad octal} {
1.345 + set x end--09
1.346 + list [catch { lindex {a b c} $x } result] $result
1.347 +} "1 {bad index \"end--09\": must be integer or end?-integer?}"
1.348 +
1.349 +test lindex-12.8 {bad integer, not octal} {
1.350 + set x end-0a2
1.351 + list [catch { lindex {a b c} $x } result] $result
1.352 +} "1 {bad index \"end-0a2\": must be integer or end?-integer?}"
1.353 +
1.354 +test lindex-12.9 {incomplete end} {
1.355 + set x en
1.356 + catch {
1.357 + list [lindex {a b c} $x] [lindex {a b c} $x]
1.358 + } result
1.359 + set result
1.360 +} {c c}
1.361 +
1.362 +test lindex-12.10 {incomplete end-} {
1.363 + set x end-
1.364 + list [catch { lindex {a b c} $x } result] $result
1.365 +} "1 {bad index \"end-\": must be integer or end?-integer?}"
1.366 +
1.367 +test lindex-13.1 {bad second index} {
1.368 + list [catch { lindex {a b c} 0 0a2 } result] $result
1.369 +} "1 {bad index \"0a2\": must be integer or end?-integer?}"
1.370 +
1.371 +test lindex-13.2 {good second index} {
1.372 + catch {
1.373 + lindex {{a b c} {d e f} {g h i}} 1 2
1.374 + } result
1.375 + set result
1.376 +} f
1.377 +
1.378 +test lindex-13.3 {three indices} {
1.379 + catch {
1.380 + lindex {{{a b} {c d}} {{e f} {g h}}} 1 0 1
1.381 + } result
1.382 + set result
1.383 +} f
1.384 +
1.385 +test lindex-14.1 {error conditions in parsing list} {
1.386 + list [catch { lindex "a \{" 2 } msg] $msg
1.387 +} {1 {unmatched open brace in list}}
1.388 +test lindex-14.2 {error conditions in parsing list} {
1.389 + list [catch { lindex {a {b c}d e} 2 } msg] $msg
1.390 +} {1 {list element in braces followed by "d" instead of space}}
1.391 +test lindex-14.3 {error conditions in parsing list} {
1.392 + list [catch { lindex {a "b c"def ghi} 2 } msg] $msg
1.393 +} {1 {list element in quotes followed by "def" instead of space}}
1.394 +
1.395 +test lindex-15.1 {quoted elements} {
1.396 + catch {
1.397 + lindex {a "b c" d} 1
1.398 + } result
1.399 + set result
1.400 +} {b c}
1.401 +test lindex-15.2 {quoted elements} {
1.402 + catch {
1.403 + lindex {"{}" b c} 0
1.404 + } result
1.405 + set result
1.406 +} {{}}
1.407 +test lindex-15.3 {quoted elements} {
1.408 + catch {
1.409 + lindex {ab "c d \" x" y} 1
1.410 + } result
1.411 + set result
1.412 +} {c d " x}
1.413 +test lindex-15.4 {quoted elements} {
1.414 + catch {
1.415 + lindex {a b {c d "e} {f g"}} 2
1.416 + } result
1.417 + set result
1.418 +} {c d "e}
1.419 +
1.420 +test lindex-16.1 {data reuse} {
1.421 + set x 0
1.422 + catch {
1.423 + lindex $x $x
1.424 + } result
1.425 + set result
1.426 +} {0}
1.427 +
1.428 +test lindex-16.2 {data reuse} {
1.429 + set a 0
1.430 + catch {
1.431 + lindex $a $a $a
1.432 + } result
1.433 + set result
1.434 +} 0
1.435 +test lindex-16.3 {data reuse} {
1.436 + set a 1
1.437 + catch {
1.438 + lindex $a $a $a
1.439 + } result
1.440 + set result
1.441 +} {}
1.442 +
1.443 +test lindex-16.4 {data reuse} {
1.444 + set x [list 0 0]
1.445 + catch {
1.446 + lindex $x $x
1.447 + } result
1.448 + set result
1.449 +} {0}
1.450 +
1.451 +test lindex-16.5 {data reuse} {
1.452 + set x 0
1.453 + catch {
1.454 + lindex $x [list $x $x]
1.455 + } result
1.456 + set result
1.457 +} {0}
1.458 +
1.459 +test lindex-16.6 {data reuse} {
1.460 + set x [list 1 1]
1.461 + catch {
1.462 + lindex $x $x
1.463 + } result
1.464 + set result
1.465 +} {}
1.466 +
1.467 +test lindex-16.7 {data reuse} {
1.468 + set x 1
1.469 + catch {
1.470 + lindex $x [list $x $x]
1.471 + } result
1.472 + set result
1.473 +} {}
1.474 +
1.475 +catch { unset lindex}
1.476 +catch { unset minus }
1.477 +
1.478 +# cleanup
1.479 +::tcltest::cleanupTests
1.480 +return