os/persistentdata/persistentstorage/sqlite3api/TEST/TCL/tcldistribution/tests/lset.test
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/persistentdata/persistentstorage/sqlite3api/TEST/TCL/tcldistribution/tests/lset.test	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,457 @@
     1.4 +# This file is a -*- tcl -*- test script
     1.5 +
     1.6 +# Commands covered: lset
     1.7 +#
     1.8 +# This file contains a collection of tests for one or more of the Tcl
     1.9 +# built-in commands.  Sourcing this file into Tcl runs the tests and
    1.10 +# generates output for errors.  No output means no errors were found.
    1.11 +#
    1.12 +# Copyright (c) 2001 by Kevin B. Kenny.  All rights reserved.
    1.13 +#
    1.14 +# See the file "license.terms" for information on usage and redistribution
    1.15 +# of this file, and for a DISCLAIMER OF ALL WARRANTIES.
    1.16 +#
    1.17 +# RCS: @(#) $Id$
    1.18 +
    1.19 +if {[lsearch [namespace children] ::tcltest] == -1} {
    1.20 +    package require tcltest
    1.21 +    namespace import -force ::tcltest::*
    1.22 +}
    1.23 +
    1.24 +proc failTrace {name1 name2 op} {
    1.25 +    error "trace failed"
    1.26 +}
    1.27 +
    1.28 +set lset lset
    1.29 +
    1.30 +set noRead {}
    1.31 +trace add variable noRead read failTrace
    1.32 +set noWrite {a b c}
    1.33 +trace add variable noWrite write failTrace
    1.34 +
    1.35 +test lset-1.1 {lset, not compiled, arg count} {
    1.36 +    list [catch {eval $lset} msg] $msg
    1.37 +} "1 {wrong \# args: should be \"lset listVar index ?index...? value\"}"
    1.38 +
    1.39 +test lset-1.2 {lset, not compiled, no such var} {
    1.40 +    list [catch {eval [list $lset noSuchVar 0 {}]} msg] $msg
    1.41 +} "1 {can't read \"noSuchVar\": no such variable}"
    1.42 +
    1.43 +test lset-1.3 {lset, not compiled, var not readable} {
    1.44 +    list [catch {eval [list $lset noRead 0 {}]} msg] $msg
    1.45 +} "1 {can't read \"noRead\": trace failed}"
    1.46 +
    1.47 +test lset-2.1 {lset, not compiled, 3 args, second arg a plain index} {
    1.48 +    set x {0 1 2}
    1.49 +    list [eval [list $lset x 0 3]] $x
    1.50 +} {{3 1 2} {3 1 2}}
    1.51 +
    1.52 +test lset-2.2 {lset, not compiled, 3 args, second arg neither index nor list} {
    1.53 +    set x {0 1 2}
    1.54 +    list [catch {
    1.55 +	eval [list $lset x {{bad}1} 3]
    1.56 +    } msg] $msg
    1.57 +} "1 {bad index \"{bad}1\": must be integer or end?-integer?}"
    1.58 +
    1.59 +test lset-3.1 {lset, not compiled, 3 args, data duplicated} {
    1.60 +    set x {0 1 2}
    1.61 +    list [eval [list $lset x 0 $x]] $x
    1.62 +} {{{0 1 2} 1 2} {{0 1 2} 1 2}}
    1.63 +
    1.64 +test lset-3.2 {lset, not compiled, 3 args, data duplicated} {
    1.65 +    set x {0 1}
    1.66 +    set y $x
    1.67 +    list [eval [list $lset x 0 2]] $x $y
    1.68 +} {{2 1} {2 1} {0 1}}
    1.69 +
    1.70 +test lset-3.3 {lset, not compiled, 3 args, data duplicated} {
    1.71 +    set x {0 1}
    1.72 +    set y $x
    1.73 +    list [eval [list $lset x 0 $x]] $x $y
    1.74 +} {{{0 1} 1} {{0 1} 1} {0 1}}
    1.75 +
    1.76 +test lset-3.4 {lset, not compiled, 3 args, data duplicated} {
    1.77 +    set x {0 1 2}
    1.78 +    list [eval [list $lset x [list 0] $x]] $x
    1.79 +} {{{0 1 2} 1 2} {{0 1 2} 1 2}}
    1.80 +
    1.81 +test lset-3.5 {lset, not compiled, 3 args, data duplicated} {
    1.82 +    set x {0 1}
    1.83 +    set y $x
    1.84 +    list [eval [list $lset x [list 0] 2]] $x $y
    1.85 +} {{2 1} {2 1} {0 1}}
    1.86 +
    1.87 +test lset-3.6 {lset, not compiled, 3 args, data duplicated} {
    1.88 +    set x {0 1}
    1.89 +    set y $x
    1.90 +    list [eval [list $lset x [list 0] $x]] $x $y
    1.91 +} {{{0 1} 1} {{0 1} 1} {0 1}}
    1.92 +
    1.93 +test lset-4.1 {lset, not compiled, 3 args, not a list} {
    1.94 +    set a "x \{"
    1.95 +    list [catch {
    1.96 +	eval [list $lset a [list 0] y]
    1.97 +    } msg] $msg
    1.98 +} {1 {unmatched open brace in list}}
    1.99 +
   1.100 +test lset-4.2 {lset, not compiled, 3 args, bad index} {
   1.101 +    set a {x y z}
   1.102 +    list [catch {
   1.103 +	eval [list $lset a [list 2a2] w]
   1.104 +    } msg] $msg
   1.105 +} {1 {bad index "2a2": must be integer or end?-integer?}}
   1.106 +
   1.107 +test lset-4.3 {lset, not compiled, 3 args, index out of range} {
   1.108 +    set a {x y z}
   1.109 +    list [catch {
   1.110 +	eval [list $lset a [list -1] w]
   1.111 +    } msg] $msg
   1.112 +} {1 {list index out of range}}
   1.113 +
   1.114 +test lset-4.4 {lset, not compiled, 3 args, index out of range} {
   1.115 +    set a {x y z}
   1.116 +    list [catch {
   1.117 +	eval [list $lset a [list 3] w]
   1.118 +    } msg] $msg
   1.119 +} {1 {list index out of range}}
   1.120 +
   1.121 +test lset-4.5 {lset, not compiled, 3 args, index out of range} {
   1.122 +    set a {x y z}
   1.123 +    list [catch {
   1.124 +	eval [list $lset a [list end--1] w]
   1.125 +    } msg] $msg
   1.126 +} {1 {list index out of range}}
   1.127 +
   1.128 +test lset-4.6 {lset, not compiled, 3 args, index out of range} {
   1.129 +    set a {x y z}
   1.130 +    list [catch {
   1.131 +	eval [list $lset a [list end-3] w]
   1.132 +    } msg] $msg
   1.133 +} {1 {list index out of range}}
   1.134 +
   1.135 +test lset-4.7 {lset, not compiled, 3 args, not a list} {
   1.136 +    set a "x \{"
   1.137 +    list [catch {
   1.138 +	eval [list $lset a 0 y]
   1.139 +    } msg] $msg
   1.140 +} {1 {unmatched open brace in list}}
   1.141 +
   1.142 +test lset-4.8 {lset, not compiled, 3 args, bad index} {
   1.143 +    set a {x y z}
   1.144 +    list [catch {
   1.145 +	eval [list $lset a 2a2 w]
   1.146 +    } msg] $msg
   1.147 +} {1 {bad index "2a2": must be integer or end?-integer?}}
   1.148 +
   1.149 +test lset-4.9 {lset, not compiled, 3 args, index out of range} {
   1.150 +    set a {x y z}
   1.151 +    list [catch {
   1.152 +	eval [list $lset a -1 w]
   1.153 +    } msg] $msg
   1.154 +} {1 {list index out of range}}
   1.155 +
   1.156 +test lset-4.10 {lset, not compiled, 3 args, index out of range} {
   1.157 +    set a {x y z}
   1.158 +    list [catch {
   1.159 +	eval [list $lset a 3 w]
   1.160 +    } msg] $msg
   1.161 +} {1 {list index out of range}}
   1.162 +
   1.163 +test lset-4.11 {lset, not compiled, 3 args, index out of range} {
   1.164 +    set a {x y z}
   1.165 +    list [catch {
   1.166 +	eval [list $lset a end--1 w]
   1.167 +    } msg] $msg
   1.168 +} {1 {list index out of range}}
   1.169 +
   1.170 +test lset-4.12 {lset, not compiled, 3 args, index out of range} {
   1.171 +    set a {x y z}
   1.172 +    list [catch {
   1.173 +	eval [list $lset a end-3 w]
   1.174 +    } msg] $msg
   1.175 +} {1 {list index out of range}}
   1.176 +
   1.177 +test lset-5.1 {lset, not compiled, 3 args, can't set variable} {
   1.178 +    list [catch {
   1.179 +	eval [list $lset noWrite 0 d]
   1.180 +    } msg] $msg $noWrite
   1.181 +} {1 {can't set "noWrite": trace failed} {d b c}}
   1.182 +
   1.183 +test lset-5.2 {lset, not compiled, 3 args, can't set variable} {
   1.184 +    list [catch {
   1.185 +	eval [list $lset noWrite [list 0] d]
   1.186 +    } msg] $msg $noWrite
   1.187 +} {1 {can't set "noWrite": trace failed} {d b c}}
   1.188 +
   1.189 +test lset-6.1 {lset, not compiled, 3 args, 1-d list basics} {
   1.190 +    set a {x y z}
   1.191 +    list [eval [list $lset a 0 a]] $a
   1.192 +} {{a y z} {a y z}}
   1.193 +
   1.194 +test lset-6.2 {lset, not compiled, 3 args, 1-d list basics} {
   1.195 +    set a {x y z}
   1.196 +    list [eval [list $lset a [list 0] a]] $a
   1.197 +} {{a y z} {a y z}}
   1.198 +
   1.199 +test lset-6.3 {lset, not compiled, 1-d list basics} {
   1.200 +    set a {x y z}
   1.201 +    list [eval [list $lset a 2 a]] $a
   1.202 +} {{x y a} {x y a}}
   1.203 +
   1.204 +test lset-6.4 {lset, not compiled, 1-d list basics} {
   1.205 +    set a {x y z}
   1.206 +    list [eval [list $lset a [list 2] a]] $a
   1.207 +} {{x y a} {x y a}}
   1.208 +
   1.209 +test lset-6.5 {lset, not compiled, 1-d list basics} {
   1.210 +    set a {x y z}
   1.211 +    list [eval [list $lset a end a]] $a
   1.212 +} {{x y a} {x y a}}
   1.213 +
   1.214 +test lset-6.6 {lset, not compiled, 1-d list basics} {
   1.215 +    set a {x y z}
   1.216 +    list [eval [list $lset a [list end] a]] $a
   1.217 +} {{x y a} {x y a}}
   1.218 +
   1.219 +test lset-6.7 {lset, not compiled, 1-d list basics} {
   1.220 +    set a {x y z}
   1.221 +    list [eval [list $lset a end-0 a]] $a
   1.222 +} {{x y a} {x y a}}
   1.223 +
   1.224 +test lset-6.8 {lset, not compiled, 1-d list basics} {
   1.225 +    set a {x y z}
   1.226 +    list [eval [list $lset a [list end-0] a]] $a
   1.227 +} {{x y a} {x y a}}
   1.228 +
   1.229 +test lset-6.9 {lset, not compiled, 1-d list basics} {
   1.230 +    set a {x y z}
   1.231 +    list [eval [list $lset a end-2 a]] $a
   1.232 +} {{a y z} {a y z}}
   1.233 +
   1.234 +test lset-6.10 {lset, not compiled, 1-d list basics} {
   1.235 +    set a {x y z}
   1.236 +    list [eval [list $lset a [list end-2] a]] $a
   1.237 +} {{a y z} {a y z}}
   1.238 +
   1.239 +test lset-7.1 {lset, not compiled, data sharing} {
   1.240 +    set a 0
   1.241 +    list [eval [list $lset a $a {gag me}]] $a
   1.242 +} {{{gag me}} {{gag me}}}
   1.243 +
   1.244 +test lset-7.2 {lset, not compiled, data sharing} {
   1.245 +    set a [list 0]
   1.246 +    list [eval [list $lset a $a {gag me}]] $a
   1.247 +} {{{gag me}} {{gag me}}}
   1.248 +
   1.249 +test lset-7.3 {lset, not compiled, data sharing} {
   1.250 +    set a {x y}
   1.251 +    list [eval [list $lset a 0 $a]] $a
   1.252 +} {{{x y} y} {{x y} y}}
   1.253 +
   1.254 +test lset-7.4 {lset, not compiled, data sharing} {
   1.255 +    set a {x y}
   1.256 +    list [eval [list $lset a [list 0] $a]] $a
   1.257 +} {{{x y} y} {{x y} y}}
   1.258 +
   1.259 +test lset-7.5 {lset, not compiled, data sharing} {
   1.260 +    set n 0
   1.261 +    set a {x y}
   1.262 +    list [eval [list $lset a $n $n]] $a $n
   1.263 +} {{0 y} {0 y} 0}
   1.264 +
   1.265 +test lset-7.6 {lset, not compiled, data sharing} {
   1.266 +    set n [list 0]
   1.267 +    set a {x y}
   1.268 +    list [eval [list $lset a $n $n]] $a $n
   1.269 +} {{0 y} {0 y} 0}
   1.270 +
   1.271 +test lset-7.7 {lset, not compiled, data sharing} {
   1.272 +    set n 0
   1.273 +    set a [list $n $n]
   1.274 +    list [eval [list $lset a $n 1]] $a $n
   1.275 +} {{1 0} {1 0} 0}
   1.276 +
   1.277 +test lset-7.8 {lset, not compiled, data sharing} {
   1.278 +    set n [list 0]
   1.279 +    set a [list $n $n]
   1.280 +    list [eval [list $lset a $n 1]] $a $n
   1.281 +} {{1 0} {1 0} 0}
   1.282 +
   1.283 +test lset-7.9 {lset, not compiled, data sharing} {
   1.284 +    set a 0
   1.285 +    list [eval [list $lset a $a $a]] $a
   1.286 +} {0 0}
   1.287 +
   1.288 +test lset-7.10 {lset, not compiled, data sharing} {
   1.289 +    set a [list 0]
   1.290 +    list [eval [list $lset a $a $a]] $a
   1.291 +} {0 0}
   1.292 +
   1.293 +test lset-8.1 {lset, not compiled, malformed sublist} {
   1.294 +    set a [list "a \{" b]
   1.295 +    list [catch {eval [list $lset a 0 1 c]} msg] $msg
   1.296 +} {1 {unmatched open brace in list}}
   1.297 +
   1.298 +test lset-8.2 {lset, not compiled, malformed sublist} {
   1.299 +    set a [list "a \{" b]
   1.300 +    list [catch {eval [list $lset a {0 1} c]} msg] $msg
   1.301 +} {1 {unmatched open brace in list}}
   1.302 +
   1.303 +test lset-8.3 {lset, not compiled, bad second index} {
   1.304 +    set a {{b c} {d e}}
   1.305 +    list [catch {eval [list $lset a 0 2a2 f]} msg] $msg
   1.306 +} {1 {bad index "2a2": must be integer or end?-integer?}}
   1.307 +
   1.308 +test lset-8.4 {lset, not compiled, bad second index} {
   1.309 +    set a {{b c} {d e}}
   1.310 +    list [catch {eval [list $lset a {0 2a2} f]} msg] $msg
   1.311 +} {1 {bad index "2a2": must be integer or end?-integer?}}
   1.312 +
   1.313 +test lset-8.5 {lset, not compiled, second index out of range} {
   1.314 +    set a {{b c} {d e} {f g}}
   1.315 +    list [catch {eval [list $lset a 2 -1 h]} msg] $msg
   1.316 +} {1 {list index out of range}}
   1.317 +
   1.318 +test lset-8.6 {lset, not compiled, second index out of range} {
   1.319 +    set a {{b c} {d e} {f g}}
   1.320 +    list [catch {eval [list $lset a {2 -1} h]} msg] $msg
   1.321 +} {1 {list index out of range}}
   1.322 +
   1.323 +test lset-8.7 {lset, not compiled, second index out of range} {
   1.324 +    set a {{b c} {d e} {f g}}
   1.325 +    list [catch {eval [list $lset a 2 2 h]} msg] $msg
   1.326 +} {1 {list index out of range}}
   1.327 +
   1.328 +test lset-8.8 {lset, not compiled, second index out of range} {
   1.329 +    set a {{b c} {d e} {f g}}
   1.330 +    list [catch {eval [list $lset a {2 2} h]} msg] $msg
   1.331 +} {1 {list index out of range}}
   1.332 +
   1.333 +test lset-8.9 {lset, not compiled, second index out of range} {
   1.334 +    set a {{b c} {d e} {f g}}
   1.335 +    list [catch {eval [list $lset a 2 end--1 h]} msg] $msg
   1.336 +} {1 {list index out of range}}
   1.337 +
   1.338 +test lset-8.10 {lset, not compiled, second index out of range} {
   1.339 +    set a {{b c} {d e} {f g}}
   1.340 +    list [catch {eval [list $lset a {2 end--1} h]} msg] $msg
   1.341 +} {1 {list index out of range}}
   1.342 +
   1.343 +test lset-8.11 {lset, not compiled, second index out of range} {
   1.344 +    set a {{b c} {d e} {f g}}
   1.345 +    list [catch {eval [list $lset a 2 end-2 h]} msg] $msg
   1.346 +} {1 {list index out of range}}
   1.347 +
   1.348 +test lset-8.12 {lset, not compiled, second index out of range} {
   1.349 +    set a {{b c} {d e} {f g}}
   1.350 +    list [catch {eval [list $lset a {2 end-2} h]} msg] $msg
   1.351 +} {1 {list index out of range}}
   1.352 +
   1.353 +test lset-9.1 {lset, not compiled, entire variable} {
   1.354 +    set a x
   1.355 +    list [eval [list $lset a y]] $a
   1.356 +} {y y}
   1.357 +
   1.358 +test lset-9.2 {lset, not compiled, entire variable} {
   1.359 +    set a x
   1.360 +    list [eval [list $lset a {} y]] $a
   1.361 +} {y y}
   1.362 +
   1.363 +test lset-10.1 {lset, not compiled, shared data} {
   1.364 +    set row {p q}
   1.365 +    set a [list $row $row]
   1.366 +    list [eval [list $lset a 0 0 x]] $a
   1.367 +} {{{x q} {p q}} {{x q} {p q}}}
   1.368 +
   1.369 +test lset-10.2 {lset, not compiled, shared data} {
   1.370 +    set row {p q}
   1.371 +    set a [list $row $row]
   1.372 +    list [eval [list $lset a {0 0} x]] $a
   1.373 +} {{{x q} {p q}} {{x q} {p q}}}
   1.374 +
   1.375 +test lset-11.1 {lset, not compiled, 2-d basics} {
   1.376 +    set a {{b c} {d e}}
   1.377 +    list [eval [list $lset a 0 0 f]] $a
   1.378 +} {{{f c} {d e}} {{f c} {d e}}}
   1.379 +
   1.380 +test lset-11.2 {lset, not compiled, 2-d basics} {
   1.381 +    set a {{b c} {d e}}
   1.382 +    list [eval [list $lset a {0 0} f]] $a
   1.383 +} {{{f c} {d e}} {{f c} {d e}}}
   1.384 +
   1.385 +test lset-11.3 {lset, not compiled, 2-d basics} {
   1.386 +    set a {{b c} {d e}}
   1.387 +    list [eval [list $lset a 0 1 f]] $a
   1.388 +} {{{b f} {d e}} {{b f} {d e}}}
   1.389 +
   1.390 +test lset-11.4 {lset, not compiled, 2-d basics} {
   1.391 +    set a {{b c} {d e}}
   1.392 +    list [eval [list $lset a {0 1} f]] $a
   1.393 +} {{{b f} {d e}} {{b f} {d e}}}
   1.394 +
   1.395 +test lset-11.5 {lset, not compiled, 2-d basics} {
   1.396 +    set a {{b c} {d e}}
   1.397 +    list [eval [list $lset a 1 0 f]] $a
   1.398 +} {{{b c} {f e}} {{b c} {f e}}}
   1.399 +
   1.400 +test lset-11.6 {lset, not compiled, 2-d basics} {
   1.401 +    set a {{b c} {d e}}
   1.402 +    list [eval [list $lset a {1 0} f]] $a
   1.403 +} {{{b c} {f e}} {{b c} {f e}}}
   1.404 +
   1.405 +test lset-11.7 {lset, not compiled, 2-d basics} {
   1.406 +    set a {{b c} {d e}}
   1.407 +    list [eval [list $lset a 1 1 f]] $a
   1.408 +} {{{b c} {d f}} {{b c} {d f}}}
   1.409 +
   1.410 +test lset-11.8 {lset, not compiled, 2-d basics} {
   1.411 +    set a {{b c} {d e}}
   1.412 +    list [eval [list $lset a {1 1} f]] $a
   1.413 +} {{{b c} {d f}} {{b c} {d f}}}
   1.414 +
   1.415 +test lset-12.0 {lset, not compiled, typical sharing pattern} {
   1.416 +    set zero 0
   1.417 +    set row [list $zero $zero $zero $zero]
   1.418 +    set ident [list $row $row $row $row]
   1.419 +    for { set i 0 } { $i < 4 } { incr i } {
   1.420 +	eval [list $lset ident $i $i 1]
   1.421 +    }
   1.422 +    set ident
   1.423 +} {{1 0 0 0} {0 1 0 0} {0 0 1 0} {0 0 0 1}}
   1.424 +
   1.425 +test lset-13.0 {lset, not compiled, shimmering hell} {
   1.426 +    set a 0
   1.427 +    list [eval [list $lset a $a $a $a $a {gag me}]] $a
   1.428 +} {{{{{{gag me}}}}} {{{{{gag me}}}}}}
   1.429 +
   1.430 +test lset-13.1 {lset, not compiled, shimmering hell} {
   1.431 +    set a [list 0]
   1.432 +    list [eval [list $lset a $a $a $a $a {gag me}]] $a
   1.433 +} {{{{{{gag me}}}}} {{{{{gag me}}}}}}
   1.434 +
   1.435 +test lset-13.2 {lset, not compiled, shimmering hell} {
   1.436 +    set a [list 0 0 0 0]
   1.437 +    list [eval [list $lset a $a {gag me}]] $a
   1.438 +} {{{{{{gag me}}}} 0 0 0} {{{{{gag me}}}} 0 0 0}}
   1.439 +
   1.440 +test lset-14.1 {lset, not compiled, list args, is string rep preserved?} {
   1.441 +    set a { { 1 2 } { 3 4 } }
   1.442 +    catch { eval [list $lset a {1 5} 5] }
   1.443 +    list $a [lindex $a 1]
   1.444 +} "{ { 1 2 } { 3 4 } } { 3 4 }"
   1.445 +
   1.446 +test lset-14.2 {lset, not compiled, flat args, is string rep preserved?} {
   1.447 +    set a { { 1 2 } { 3 4 } }
   1.448 +    catch { eval [list $lset a 1 5 5] }
   1.449 +    list $a [lindex $a 1]
   1.450 +} "{ { 1 2 } { 3 4 } } { 3 4 }"
   1.451 +
   1.452 +catch {unset noRead}
   1.453 +catch {unset noWrite}
   1.454 +catch {rename failTrace {}}
   1.455 +catch {unset ::x}
   1.456 +catch {unset ::y}
   1.457 +
   1.458 +# cleanup
   1.459 +::tcltest::cleanupTests
   1.460 +return