os/persistentdata/persistentstorage/sqlite3api/TEST/TCL/tcldistribution/tests/append.test
Update contrib.
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: append.test,v 1.7.12.1 2006/10/05 11:44:04 msofer Exp $
16 if {[lsearch [namespace children] ::tcltest] == -1} {
17 package require tcltest
18 namespace import -force ::tcltest::*
22 test append-1.1 {append command} {
24 list [append x 1 2 abc "long string"] $x
25 } {{12abclong string} {12abclong string}}
26 test append-1.2 {append command} {
28 list [append x first] [append x second] [append x third] $x
29 } {first firstsecond firstsecondthird firstsecondthird}
30 test append-1.3 {append command} {
35 test append-2.1 {long appends} {
37 for {set i 0} {$i < 1000} {set i [expr $i+1]} {
41 set y "$y $y $y $y $y $y $y $y $y $y"
42 set y "$y $y $y $y $y $y $y $y $y $y"
43 set y "$y $y $y $y $y $y $y $y $y $y "
47 test append-3.1 {append errors} {
48 list [catch {append} msg] $msg
49 } {1 {wrong # args: should be "append varName ?value value ...?"}}
50 test append-3.2 {append errors} {
52 list [catch {append x(0) 44} msg] $msg
53 } {1 {can't set "x(0)": variable isn't array}}
54 test append-3.3 {append errors} {
56 list [catch {append x} msg] $msg
57 } {1 {can't read "x": no such variable}}
59 test append-4.1 {lappend command} {
61 list [lappend x 1 2 abc "long string"] $x
62 } {{1 2 abc {long string}} {1 2 abc {long string}}}
63 test append-4.2 {lappend command} {
65 list [lappend x first] [lappend x second] [lappend x third] $x
66 } {first {first second} {first second third} {first second third}}
67 test append-4.3 {lappend command} {
78 test append-4.4 {lappend command} {
82 test append-4.5 {lappend command} {
86 test append-4.6 {lappend command} {
90 test append-4.7 {lappend command} {
94 test append-4.8 {lappend command} {
98 test append-4.9 {lappend command} {
100 list [catch {lappend x abc} msg] $msg
101 } {1 {unmatched open brace in list}}
102 test append-4.10 {lappend command} {
104 list [catch {lappend x abc} msg] $msg
105 } {1 {unmatched open brace in list}}
106 test append-4.11 {lappend command} {
108 list [catch {lappend x abc} msg] $msg
109 } {1 {unmatched open brace in list}}
110 test append-4.12 {lappend command} {
112 list [catch {lappend x abc} msg] $msg
113 } {1 {unmatched open brace in list}}
114 test append-4.13 {lappend command} {
117 } "x\\\{\\\{\\\{ abc"
118 test append-4.14 {lappend command} {
122 test append-4.15 {lappend command} {
126 test append-4.16 {lappend command} {
130 test append-4.17 {lappend command} {
134 test append-4.18 {lappend command} {
138 test append-4.19 {lappend command} {
142 test append-4.20 {lappend command} {
147 test append-4.21 {lappend command} {
149 list [catch {lappend x} msg] $msg
150 } {1 {unmatched open quote in list}}
151 test append-4.22 {lappend command} {
153 list [catch {lappend x abc} msg] $msg
154 } {1 {unmatched open quote in list}}
156 proc check {var size} {
159 return "length mismatch: should have been $size, was $l"
161 for {set i 0} {$i < $size} {set i [expr $i+1]} {
162 set j [lindex $var $i]
163 if {$j != "item $i"} {
164 return "element $i should have been \"item $i\", was \"$j\""
169 test append-5.1 {long lappends} {
172 for {set i 0} {$i < 300} {set i [expr $i+1]} {
178 test append-6.1 {lappend errors} {
179 list [catch {lappend} msg] $msg
180 } {1 {wrong # args: should be "lappend varName ?value value ...?"}}
181 test append-6.2 {lappend errors} {
183 list [catch {lappend x(0) 44} msg] $msg
184 } {1 {can't set "x(0)": variable isn't array}}
186 test append-7.1 {lappend-created var and error in trace on that var} {
187 catch {rename foo ""}
189 trace variable x w foo
190 proc foo {} {global x; unset x}
192 proc foo {args} {global x; unset x}
196 list [info exists x] [catch {set x} msg] $msg
197 } {0 1 {can't read "x": no such variable}}
198 test append-7.2 {lappend var triggers read trace} {
200 catch {unset ::result}
201 trace variable myvar r foo
202 proc foo {args} {append ::result $args}
204 list [catch {set ::result} msg] $msg
206 test append-7.3 {lappend var triggers read trace, array var} {
207 # The behavior of read triggers on lappend changed in 8.0 to
208 # not trigger them, and was changed back in 8.4.
210 catch {unset ::result}
211 trace variable myvar r foo
212 proc foo {args} {append ::result $args}
214 list [catch {set ::result} msg] $msg
216 test append-7.4 {lappend var triggers read trace, array var exists} {
218 catch {unset ::result}
220 trace variable myvar r foo
221 proc foo {args} {append ::result $args}
223 list [catch {set ::result} msg] $msg
225 test append-7.5 {append var does not trigger read trace} {
227 catch {unset ::result}
228 trace variable myvar r foo
229 proc foo {args} {append ::result $args}
235 catch {unset i x result y}
236 catch {rename foo ""}
237 catch {rename check ""}
240 ::tcltest::cleanupTests