os/persistentdata/persistentstorage/sqlite3api/TEST/TCL/tcldistribution/tests/lindex.test
Update contrib.
1 # Commands covered: lindex
3 # This file contains a collection of tests for one or more of the Tcl
4 # built-in commands. Sourcing this file into Tcl runs the tests and
5 # generates output for errors. No output means no errors were found.
7 # Copyright (c) 1991-1993 The Regents of the University of California.
8 # Copyright (c) 1994 Sun Microsystems, Inc.
9 # Copyright (c) 1998-1999 by Scriptics Corporation.
10 # Copyright (c) 2001 by Kevin B. Kenny. All rights reserved.
12 # See the file "license.terms" for information on usage and redistribution
13 # of this file, and for a DISCLAIMER OF ALL WARRANTIES.
15 # RCS: @(#) $Id: lindex.test,v 1.10 2002/04/19 13:08:56 dkf Exp $
17 if {[lsearch [namespace children] ::tcltest] == -1} {
18 package require tcltest
19 namespace import -force ::tcltest::*
25 # Tests of Tcl_LindexObjCmd, NOT COMPILED
27 test lindex-1.1 {wrong # args} {
28 list [catch {eval $lindex} result] $result
29 } "1 {wrong # args: should be \"lindex list ?index...?\"}"
31 # Indices that are lists or convertible to lists
33 test lindex-2.1 {empty index list} {
35 list [eval [list $lindex {a b c} $x]] [eval [list $lindex {a b c} $x]]
38 test lindex-2.2 {singleton index list} {
40 list [eval [list $lindex {a b c} $x]] [eval [list $lindex {a b c} $x]]
43 test lindex-2.3 {multiple indices in list} {
45 list [eval [list $lindex {{a b c} {d e f}} $x]] \
46 [eval [list $lindex {{a b c} {d e f}} $x]]
49 test lindex-2.4 {malformed index list} {
51 list [catch { eval [list $lindex {a b c} $x] } result] $result
52 } {1 bad\ index\ \"\{\":\ must\ be\ integer\ or\ end?-integer?}
54 # Indices that are integers or convertible to integers
56 test lindex-3.1 {integer -1} {
58 list [eval [list $lindex {a b c} $x]] [eval [list $lindex {a b c} $x]]
61 test lindex-3.2 {integer 0} {
62 set x [string range 00 0 0]
63 list [eval [list $lindex {a b c} $x]] [eval [list $lindex {a b c} $x]]
66 test lindex-3.3 {integer 2} {
67 set x [string range 22 0 0]
68 list [eval [list $lindex {a b c} $x]] [eval [list $lindex {a b c} $x]]
71 test lindex-3.4 {integer 3} {
72 set x [string range 33 0 0]
73 list [eval [list $lindex {a b c} $x]] [eval [list $lindex {a b c} $x]]
76 test lindex-3.5 {bad octal} {
78 list [catch { eval [list $lindex {a b c} $x] } result] $result
79 } "1 {bad index \"08\": must be integer or end?-integer? (looks like invalid octal number)}"
81 test lindex-3.6 {bad octal} {
83 list [catch { eval [list $lindex {a b c} $x] } result] $result
84 } "1 {bad index \"-09\": must be integer or end?-integer? (looks like invalid octal number)}"
86 test lindex-3.7 {indexes don't shimmer wide ints} {
87 set x [expr {(wide(1)<<31) - 2}]
88 list $x [lindex {1 2 3} $x] [incr x] [incr x]
89 } {2147483646 {} 2147483647 2147483648}
91 # Indices relative to end
93 test lindex-4.1 {index = end} {
95 list [eval [list $lindex {a b c} $x]] [eval [list $lindex {a b c} $x]]
98 test lindex-4.2 {index = end--1} {
100 list [eval [list $lindex {a b c} $x]] [eval [list $lindex {a b c} $x]]
103 test lindex-4.3 {index = end-0} {
105 list [eval [list $lindex {a b c} $x]] [eval [list $lindex {a b c} $x]]
108 test lindex-4.4 {index = end-2} {
110 list [eval [list $lindex {a b c} $x]] [eval [list $lindex {a b c} $x]]
113 test lindex-4.5 {index = end-3} {
115 list [eval [list $lindex {a b c} $x]] [eval [list $lindex {a b c} $x]]
118 test lindex-4.6 {bad octal} {
120 list [catch { eval [list $lindex {a b c} $x] } result] $result
121 } "1 {bad index \"end-08\": must be integer or end?-integer? (looks like invalid octal number)}"
123 test lindex-4.7 {bad octal} {
125 list [catch { eval [list $lindex {a b c} $x] } result] $result
126 } "1 {bad index \"end--09\": must be integer or end?-integer?}"
128 test lindex-4.8 {bad integer, not octal} {
130 list [catch { eval [list $lindex {a b c} $x] } result] $result
131 } "1 {bad index \"end-0a2\": must be integer or end?-integer?}"
133 test lindex-4.9 {incomplete end} {
135 list [eval [list $lindex {a b c} $x]] [eval [list $lindex {a b c} $x]]
138 test lindex-4.10 {incomplete end-} {
140 list [catch { eval [list $lindex {a b c} $x] } result] $result
141 } "1 {bad index \"end-\": must be integer or end?-integer?}"
143 test lindex-5.1 {bad second index} {
144 list [catch { eval [list $lindex {a b c} 0 0a2] } result] $result
145 } "1 {bad index \"0a2\": must be integer or end?-integer?}"
147 test lindex-5.2 {good second index} {
148 eval [list $lindex {{a b c} {d e f} {g h i}} 1 2]
151 test lindex-5.3 {three indices} {
152 eval [list $lindex {{{a b} {c d}} {{e f} {g h}}} 1 0 1]
154 test lindex-6.1 {error conditions in parsing list} {
155 list [catch {eval [list $lindex "a \{" 2]} msg] $msg
156 } {1 {unmatched open brace in list}}
157 test lindex-6.2 {error conditions in parsing list} {
158 list [catch {eval [list $lindex {a {b c}d e} 2]} msg] $msg
159 } {1 {list element in braces followed by "d" instead of space}}
160 test lindex-6.3 {error conditions in parsing list} {
161 list [catch {eval [list $lindex {a "b c"def ghi} 2]} msg] $msg
162 } {1 {list element in quotes followed by "def" instead of space}}
164 test lindex-7.1 {quoted elements} {
165 eval [list $lindex {a "b c" d} 1]
167 test lindex-7.2 {quoted elements} {
168 eval [list $lindex {"{}" b c} 0]
170 test lindex-7.3 {quoted elements} {
171 eval [list $lindex {ab "c d \" x" y} 1]
173 test lindex-7.4 {quoted elements} {
174 lindex {a b {c d "e} {f g"}} 2
177 test lindex-8.1 {data reuse} {
179 eval [list $lindex $x $x]
182 test lindex-8.2 {data reuse} {
184 eval [list $lindex $a $a $a]
186 test lindex-8.3 {data reuse} {
188 eval [list $lindex $a $a $a]
191 test lindex-8.4 {data reuse} {
193 eval [list $lindex $x $x]
196 test lindex-8.5 {data reuse} {
198 eval [list $lindex $x [list $x $x]]
201 test lindex-8.6 {data reuse} {
203 eval [list $lindex $x $x]
206 test lindex-8.7 {data reuse} {
208 eval [list lindex $x [list $x $x]]
211 #----------------------------------------------------------------------
213 # Compilation tests for lindex
215 test lindex-9.1 {wrong # args} {
216 list [catch {lindex} result] $result
217 } "1 {wrong # args: should be \"lindex list ?index...?\"}"
219 # Indices that are lists or convertible to lists
221 test lindex-10.1 {empty index list} {
224 list [lindex {a b c} $x] [lindex {a b c} $x]
229 test lindex-10.2 {singleton index list} {
232 list [lindex {a b c} $x] [lindex {a b c} $x]
237 test lindex-10.3 {multiple indices in list} {
240 list [lindex {{a b c} {d e f}} $x] [lindex {{a b c} {d e f}} $x]
245 test lindex-10.4 {malformed index list} {
247 list [catch { lindex {a b c} $x } result] $result
248 } {1 bad\ index\ \"\{\":\ must\ be\ integer\ or\ end?-integer?}
250 # Indices that are integers or convertible to integers
252 test lindex-11.1 {integer -1} {
255 list [lindex {a b c} $x] [lindex {a b c} $x]
260 test lindex-11.2 {integer 0} {
261 set x [string range 00 0 0]
263 list [lindex {a b c} $x] [lindex {a b c} $x]
268 test lindex-11.3 {integer 2} {
269 set x [string range 22 0 0]
271 list [lindex {a b c} $x] [lindex {a b c} $x]
276 test lindex-11.4 {integer 3} {
277 set x [string range 33 0 0]
279 list [lindex {a b c} $x] [lindex {a b c} $x]
284 test lindex-11.5 {bad octal} {
286 list [catch { lindex {a b c} $x } result] $result
287 } "1 {bad index \"08\": must be integer or end?-integer? (looks like invalid octal number)}"
289 test lindex-11.6 {bad octal} {
291 list [catch { lindex {a b c} $x } result] $result
292 } "1 {bad index \"-09\": must be integer or end?-integer? (looks like invalid octal number)}"
294 # Indices relative to end
296 test lindex-12.1 {index = end} {
299 list [lindex {a b c} $x] [lindex {a b c} $x]
304 test lindex-12.2 {index = end--1} {
307 list [lindex {a b c} $x] [lindex {a b c} $x]
312 test lindex-12.3 {index = end-0} {
315 list [lindex {a b c} $x] [lindex {a b c} $x]
320 test lindex-12.4 {index = end-2} {
323 list [lindex {a b c} $x] [lindex {a b c} $x]
328 test lindex-12.5 {index = end-3} {
331 list [lindex {a b c} $x] [lindex {a b c} $x]
336 test lindex-12.6 {bad octal} {
338 list [catch { lindex {a b c} $x } result] $result
339 } "1 {bad index \"end-08\": must be integer or end?-integer? (looks like invalid octal number)}"
341 test lindex-12.7 {bad octal} {
343 list [catch { lindex {a b c} $x } result] $result
344 } "1 {bad index \"end--09\": must be integer or end?-integer?}"
346 test lindex-12.8 {bad integer, not octal} {
348 list [catch { lindex {a b c} $x } result] $result
349 } "1 {bad index \"end-0a2\": must be integer or end?-integer?}"
351 test lindex-12.9 {incomplete end} {
354 list [lindex {a b c} $x] [lindex {a b c} $x]
359 test lindex-12.10 {incomplete end-} {
361 list [catch { lindex {a b c} $x } result] $result
362 } "1 {bad index \"end-\": must be integer or end?-integer?}"
364 test lindex-13.1 {bad second index} {
365 list [catch { lindex {a b c} 0 0a2 } result] $result
366 } "1 {bad index \"0a2\": must be integer or end?-integer?}"
368 test lindex-13.2 {good second index} {
370 lindex {{a b c} {d e f} {g h i}} 1 2
375 test lindex-13.3 {three indices} {
377 lindex {{{a b} {c d}} {{e f} {g h}}} 1 0 1
382 test lindex-14.1 {error conditions in parsing list} {
383 list [catch { lindex "a \{" 2 } msg] $msg
384 } {1 {unmatched open brace in list}}
385 test lindex-14.2 {error conditions in parsing list} {
386 list [catch { lindex {a {b c}d e} 2 } msg] $msg
387 } {1 {list element in braces followed by "d" instead of space}}
388 test lindex-14.3 {error conditions in parsing list} {
389 list [catch { lindex {a "b c"def ghi} 2 } msg] $msg
390 } {1 {list element in quotes followed by "def" instead of space}}
392 test lindex-15.1 {quoted elements} {
398 test lindex-15.2 {quoted elements} {
404 test lindex-15.3 {quoted elements} {
406 lindex {ab "c d \" x" y} 1
410 test lindex-15.4 {quoted elements} {
412 lindex {a b {c d "e} {f g"}} 2
417 test lindex-16.1 {data reuse} {
425 test lindex-16.2 {data reuse} {
432 test lindex-16.3 {data reuse} {
440 test lindex-16.4 {data reuse} {
448 test lindex-16.5 {data reuse} {
451 lindex $x [list $x $x]
456 test lindex-16.6 {data reuse} {
464 test lindex-16.7 {data reuse} {
467 lindex $x [list $x $x]
472 catch { unset lindex}
473 catch { unset minus }
476 ::tcltest::cleanupTests