os/persistentdata/persistentstorage/sqlite3api/TEST/TCL/tcldistribution/tests/appendComp.test
First public contribution.
1 # Commands covered: append lappend
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-1996 Sun Microsystems, Inc.
9 # Copyright (c) 1998-1999 by Scriptics Corporation.
11 # See the file "license.terms" for information on usage and redistribution
12 # of this file, and for a DISCLAIMER OF ALL WARRANTIES.
14 # RCS: @(#) $Id: appendComp.test,v 1.5.4.1 2004/10/28 00:01:05 dgp Exp $
16 if {[lsearch [namespace children] ::tcltest] == -1} {
17 package require tcltest
18 namespace import -force ::tcltest::*
22 test appendComp-1.1 {append command} {
24 proc foo {} {append ::x 1 2 abc "long string"}
26 } {{12abclong string} {12abclong string}}
27 test appendComp-1.2 {append command} {
30 list [append x first] [append x second] [append x third] $x
33 } {first firstsecond firstsecondthird firstsecondthird}
34 test appendComp-1.3 {append command} {
42 test appendComp-2.1 {long appends} {
45 for {set i 0} {$i < 1000} {set i [expr $i+1]} {
49 set y "$y $y $y $y $y $y $y $y $y $y"
50 set y "$y $y $y $y $y $y $y $y $y $y"
51 set y "$y $y $y $y $y $y $y $y $y $y "
57 test appendComp-3.1 {append errors} {
59 list [catch {foo} msg] $msg
60 } {1 {wrong # args: should be "append varName ?value value ...?"}}
61 test appendComp-3.2 {append errors} {
66 list [catch {foo} msg] $msg
67 } {1 {can't set "x(0)": variable isn't array}}
68 test appendComp-3.3 {append errors} {
73 list [catch {foo} msg] $msg
74 } {1 {can't read "x": no such variable}}
76 test appendComp-4.1 {lappend command} {
80 lappend x 1 2 abc "long string"
83 } {{1 2 abc {long string}} {1 2 abc {long string}}}
84 test appendComp-4.2 {lappend command} {
87 list [lappend x first] [lappend x second] [lappend x third] $x
90 } {first {first second} {first second third} {first second third}}
91 test appendComp-4.3 {lappend command} {
102 test appendComp-4.4 {lappend command} {
109 test appendComp-4.5 {lappend command} {
116 test appendComp-4.6 {lappend command} {
123 test appendComp-4.7 {lappend command} {
130 test appendComp-4.8 {lappend command} {
137 test appendComp-4.9 {lappend command} {
140 list [catch {lappend x abc} msg] $msg
143 } {1 {unmatched open brace in list}}
144 test appendComp-4.10 {lappend command} {
147 list [catch {lappend x abc} msg] $msg
150 } {1 {unmatched open brace in list}}
151 test appendComp-4.11 {lappend command} {
154 list [catch {lappend x abc} msg] $msg
157 } {1 {unmatched open brace in list}}
158 test appendComp-4.12 {lappend command} {
161 list [catch {lappend x abc} msg] $msg
164 } {1 {unmatched open brace in list}}
165 test appendComp-4.13 {lappend command} {
171 } "x\\\{\\\{\\\{ abc"
172 test appendComp-4.14 {lappend command} {
179 test appendComp-4.15 {lappend command} {
186 test appendComp-4.16 {lappend command} {
193 test appendComp-4.17 {lappend command} {
194 proc foo {} { lappend x }
197 test appendComp-4.18 {lappend command} {
198 proc foo {} { lappend x {} }
201 test appendComp-4.19 {lappend command} {
202 proc foo {} { lappend x(0) }
205 test appendComp-4.20 {lappend command} {
206 proc foo {} { lappend x(0) abc }
210 proc check {var size} {
213 return "length mismatch: should have been $size, was $l"
215 for {set i 0} {$i < $size} {set i [expr $i+1]} {
216 set j [lindex $var $i]
217 if {$j != "item $i"} {
218 return "element $i should have been \"item $i\", was \"$j\""
223 test appendComp-5.1 {long lappends} {
226 for {set i 0} {$i < 300} {set i [expr $i+1]} {
232 test appendComp-6.1 {lappend errors} {
233 proc foo {} {lappend}
234 list [catch {foo} msg] $msg
235 } {1 {wrong # args: should be "lappend varName ?value value ...?"}}
236 test appendComp-6.2 {lappend errors} {
241 list [catch {foo} msg] $msg
242 } {1 {can't set "x(0)": variable isn't array}}
244 test appendComp-7.1 {lappendComp-created var and error in trace on that var} {
247 catch {rename foo ""}
249 trace variable x w foo
250 proc foo {} {global x; unset x}
252 proc foo {args} {global x; unset x}
256 list [info exists x] [catch {set x} msg] $msg
259 } {0 1 {can't read "x": no such variable}}
260 test appendComp-7.2 {lappend var triggers read trace, index var} {
263 catch {unset ::result}
264 trace variable myvar r foo
265 proc foo {args} {append ::result $args}
267 list [catch {set ::result} msg] $msg
271 test appendComp-7.3 {lappend var triggers read trace, stack var} {
273 catch {unset ::myvar}
274 catch {unset ::result}
275 trace variable ::myvar r foo
276 proc foo {args} {append ::result $args}
278 list [catch {set ::result} msg] $msg
282 test appendComp-7.4 {lappend var triggers read trace, array var} {
283 # The behavior of read triggers on lappend changed in 8.0 to
284 # not trigger them. Maybe not correct, but been there a while.
287 catch {unset ::result}
288 trace variable myvar r foo
289 proc foo {args} {append ::result $args}
291 list [catch {set ::result} msg] $msg
295 test appendComp-7.5 {lappend var triggers read trace, array var} {
296 # The behavior of read triggers on lappend changed in 8.0 to
297 # not trigger them. Maybe not correct, but been there a while.
300 catch {unset ::result}
301 trace variable myvar r foo
302 proc foo {args} {append ::result $args}
304 list [catch {set ::result} msg] $msg
308 test appendComp-7.6 {lappend var triggers read trace, array var exists} {
311 catch {unset ::result}
313 trace variable myvar r foo
314 proc foo {args} {append ::result $args}
316 list [catch {set ::result} msg] $msg
320 test appendComp-7.7 {lappend var triggers read trace, array stack var} {
322 catch {unset ::myvar}
323 catch {unset ::result}
324 trace variable ::myvar r foo
325 proc foo {args} {append ::result $args}
327 list [catch {set ::result} msg] $msg
331 test appendComp-7.8 {lappend var triggers read trace, array stack var} {
333 catch {unset ::myvar}
334 catch {unset ::result}
335 trace variable ::myvar r foo
336 proc foo {args} {append ::result $args}
337 lappend ::myvar(b) a b
338 list [catch {set ::result} msg] $msg
342 test appendComp-7.9 {append var does not trigger read trace} {
345 catch {unset ::result}
346 trace variable myvar r foo
347 proc foo {args} {append ::result $args}
354 catch {unset i x result y}
355 catch {rename foo ""}
356 catch {rename bar ""}
357 catch {rename check ""}
358 catch {rename bar {}}
361 ::tcltest::cleanupTests