sl@0: # Commands covered: set, unset, array sl@0: # sl@0: # This file includes the original set of tests for Tcl's set command. sl@0: # Since the set command is now compiled, a new set of tests covering sl@0: # the new implementation is in the file "set.test". Sourcing this file sl@0: # into Tcl runs the tests and generates output for errors. sl@0: # No output means no errors were found. sl@0: # sl@0: # Copyright (c) 1991-1993 The Regents of the University of California. sl@0: # Copyright (c) 1994-1997 Sun Microsystems, Inc. sl@0: # Copyright (c) 1998-1999 by Scriptics Corporation. sl@0: # sl@0: # See the file "license.terms" for information on usage and redistribution sl@0: # of this file, and for a DISCLAIMER OF ALL WARRANTIES. sl@0: # sl@0: # RCS: @(#) $Id: set-old.test,v 1.16.2.1 2003/03/27 21:46:32 msofer Exp $ sl@0: sl@0: if {[lsearch [namespace children] ::tcltest] == -1} { sl@0: package require tcltest sl@0: namespace import -force ::tcltest::* sl@0: } sl@0: sl@0: proc ignore args {} sl@0: sl@0: # Simple variable operations. sl@0: sl@0: catch {unset a} sl@0: test set-old-1.1 {basic variable setting and unsetting} { sl@0: set a 22 sl@0: } 22 sl@0: test set-old-1.2 {basic variable setting and unsetting} { sl@0: set a 123 sl@0: set a sl@0: } 123 sl@0: test set-old-1.3 {basic variable setting and unsetting} { sl@0: set a xxx sl@0: format %s $a sl@0: } xxx sl@0: test set-old-1.4 {basic variable setting and unsetting} { sl@0: set a 44 sl@0: unset a sl@0: list [catch {set a} msg] $msg sl@0: } {1 {can't read "a": no such variable}} sl@0: sl@0: # Basic array operations. sl@0: sl@0: catch {unset a} sl@0: set a(xyz) 2 sl@0: set a(44) 3 sl@0: set {a(a long name)} test sl@0: test set-old-2.1 {basic array operations} { sl@0: lsort [array names a] sl@0: } {44 {a long name} xyz} sl@0: test set-old-2.2 {basic array operations} { sl@0: set a(44) sl@0: } 3 sl@0: test set-old-2.3 {basic array operations} { sl@0: set a(xyz) sl@0: } 2 sl@0: test set-old-2.4 {basic array operations} { sl@0: set "a(a long name)" sl@0: } test sl@0: test set-old-2.5 {basic array operations} { sl@0: list [catch {set a(other)} msg] $msg sl@0: } {1 {can't read "a(other)": no such element in array}} sl@0: test set-old-2.6 {basic array operations} { sl@0: list [catch {set a} msg] $msg sl@0: } {1 {can't read "a": variable is array}} sl@0: test set-old-2.7 {basic array operations} { sl@0: format %s $a(44) sl@0: } 3 sl@0: test set-old-2.8 {basic array operations} { sl@0: format %s $a(a long name) sl@0: } test sl@0: unset a(44) sl@0: test set-old-2.9 {basic array operations} { sl@0: lsort [array names a] sl@0: } {{a long name} xyz} sl@0: test set-old-2.10 {basic array operations} { sl@0: catch {unset b} sl@0: list [catch {set b(123)} msg] $msg sl@0: } {1 {can't read "b(123)": no such variable}} sl@0: test set-old-2.11 {basic array operations} { sl@0: catch {unset b} sl@0: set b 44 sl@0: list [catch {set b(123)} msg] $msg sl@0: } {1 {can't read "b(123)": variable isn't array}} sl@0: test set-old-2.12 {basic array operations} { sl@0: list [catch {set a 14} msg] $msg sl@0: } {1 {can't set "a": variable is array}} sl@0: unset a sl@0: test set-old-2.13 {basic array operations} { sl@0: list [catch {set a(xyz)} msg] $msg sl@0: } {1 {can't read "a(xyz)": no such variable}} sl@0: sl@0: # Test the set commands, and exercise the corner cases of the code sl@0: # that parses array references into two parts. sl@0: sl@0: test set-old-3.1 {set command} { sl@0: list [catch {set} msg] $msg sl@0: } {1 {wrong # args: should be "set varName ?newValue?"}} sl@0: test set-old-3.2 {set command} { sl@0: list [catch {set x y z} msg] $msg sl@0: } {1 {wrong # args: should be "set varName ?newValue?"}} sl@0: test set-old-3.3 {set command} { sl@0: catch {unset a} sl@0: list [catch {set a} msg] $msg sl@0: } {1 {can't read "a": no such variable}} sl@0: test set-old-3.4 {set command} { sl@0: catch {unset a} sl@0: set a(14) 83 sl@0: list [catch {set a 22} msg] $msg sl@0: } {1 {can't set "a": variable is array}} sl@0: sl@0: # Test the corner-cases of parsing array names, using set and unset. sl@0: sl@0: test set-old-4.1 {parsing array names} { sl@0: catch {unset a} sl@0: set a(()) 44 sl@0: list [catch {array names a} msg] $msg sl@0: } {0 ()} sl@0: test set-old-4.2 {parsing array names} { sl@0: catch {unset a a(abcd} sl@0: set a(abcd 33 sl@0: info exists a(abcd sl@0: } 1 sl@0: test set-old-4.3 {parsing array names} { sl@0: catch {unset a a(abcd} sl@0: set a(abcd 33 sl@0: list [catch {array names a} msg] $msg sl@0: } {0 {}} sl@0: test set-old-4.4 {parsing array names} { sl@0: catch {unset a abcd)} sl@0: set abcd) 33 sl@0: info exists abcd) sl@0: } 1 sl@0: test set-old-4.5 {parsing array names} { sl@0: set a(bcd yyy sl@0: catch {unset a} sl@0: list [catch {set a(bcd} msg] $msg sl@0: } {0 yyy} sl@0: test set-old-4.6 {parsing array names} { sl@0: catch {unset a} sl@0: set a 44 sl@0: list [catch {set a(bcd test} msg] $msg sl@0: } {0 test} sl@0: sl@0: # Errors in reading variables sl@0: sl@0: test set-old-5.1 {errors in reading variables} { sl@0: catch {unset a} sl@0: list [catch {set a} msg] $msg sl@0: } {1 {can't read "a": no such variable}} sl@0: test set-old-5.2 {errors in reading variables} { sl@0: catch {unset a} sl@0: set a 44 sl@0: list [catch {set a(18)} msg] $msg sl@0: } {1 {can't read "a(18)": variable isn't array}} sl@0: test set-old-5.3 {errors in reading variables} { sl@0: catch {unset a} sl@0: set a(6) 44 sl@0: list [catch {set a(18)} msg] $msg sl@0: } {1 {can't read "a(18)": no such element in array}} sl@0: test set-old-5.4 {errors in reading variables} { sl@0: catch {unset a} sl@0: set a(6) 44 sl@0: list [catch {set a} msg] $msg sl@0: } {1 {can't read "a": variable is array}} sl@0: sl@0: # Errors and other special cases in writing variables sl@0: sl@0: test set-old-6.1 {creating array during write} { sl@0: catch {unset a} sl@0: trace var a rwu ignore sl@0: list [catch {set a(14) 186} msg] $msg [array names a] sl@0: } {0 186 14} sl@0: test set-old-6.2 {errors in writing variables} { sl@0: catch {unset a} sl@0: set a xxx sl@0: list [catch {set a(14) 186} msg] $msg sl@0: } {1 {can't set "a(14)": variable isn't array}} sl@0: test set-old-6.3 {errors in writing variables} { sl@0: catch {unset a} sl@0: set a(100) yyy sl@0: list [catch {set a 2} msg] $msg sl@0: } {1 {can't set "a": variable is array}} sl@0: test set-old-6.4 {expanding variable size} { sl@0: catch {unset a} sl@0: list [set a short] [set a "longer name"] [set a "even longer name"] \ sl@0: [set a "a much much truly longer name"] sl@0: } {short {longer name} {even longer name} {a much much truly longer name}} sl@0: sl@0: # Unset command, Tcl_UnsetVar procedures sl@0: sl@0: test set-old-7.1 {unset command} { sl@0: catch {unset a}; catch {unset b}; catch {unset c}; catch {unset d} sl@0: set a 44 sl@0: set b 55 sl@0: set c 66 sl@0: set d 77 sl@0: unset a b c sl@0: list [catch {set a(0) 0}] [catch {set b(0) 0}] [catch {set c(0) 0}] \ sl@0: [catch {set d(0) 0}] sl@0: } {0 0 0 1} sl@0: test set-old-7.2 {unset command} { sl@0: list [catch {unset} msg] $msg sl@0: } {0 {}} sl@0: # Used to return: sl@0: #{1 {wrong # args: should be "unset ?-nocomplain? ?--? ?varName varName ...?"}} sl@0: test set-old-7.3 {unset command} { sl@0: catch {unset a} sl@0: list [catch {unset a} msg] $msg sl@0: } {1 {can't unset "a": no such variable}} sl@0: test set-old-7.4 {unset command} { sl@0: catch {unset a} sl@0: set a 44 sl@0: list [catch {unset a(14)} msg] $msg sl@0: } {1 {can't unset "a(14)": variable isn't array}} sl@0: test set-old-7.5 {unset command} { sl@0: catch {unset a} sl@0: set a(0) xx sl@0: list [catch {unset a(14)} msg] $msg sl@0: } {1 {can't unset "a(14)": no such element in array}} sl@0: test set-old-7.6 {unset command} { sl@0: catch {unset a}; catch {unset b}; catch {unset c} sl@0: set a foo sl@0: set c gorp sl@0: list [catch {unset a a a(14)} msg] $msg [info exists c] sl@0: } {1 {can't unset "a": no such variable} 1} sl@0: test set-old-7.7 {unsetting globals from within procedures} { sl@0: set y 0 sl@0: proc p1 {} { sl@0: global y sl@0: set z [p2] sl@0: return [list $z [catch {set y} msg] $msg] sl@0: } sl@0: proc p2 {} {global y; unset y; list [catch {set y} msg] $msg} sl@0: p1 sl@0: } {{1 {can't read "y": no such variable}} 1 {can't read "y": no such variable}} sl@0: test set-old-7.8 {unsetting globals from within procedures} { sl@0: set y 0 sl@0: proc p1 {} { sl@0: global y sl@0: p2 sl@0: return [list [catch {set y 44} msg] $msg] sl@0: } sl@0: proc p2 {} {global y; unset y} sl@0: concat [p1] [list [catch {set y} msg] $msg] sl@0: } {0 44 0 44} sl@0: test set-old-7.9 {unsetting globals from within procedures} { sl@0: set y 0 sl@0: proc p1 {} { sl@0: global y sl@0: unset y sl@0: return [list [catch {set y 55} msg] $msg] sl@0: } sl@0: concat [p1] [list [catch {set y} msg] $msg] sl@0: } {0 55 0 55} sl@0: test set-old-7.10 {unset command} { sl@0: catch {unset a} sl@0: set a(14) 22 sl@0: unset a(14) sl@0: list [catch {set a(14)} msg] $msg [catch {array names a} msg2] $msg2 sl@0: } {1 {can't read "a(14)": no such element in array} 0 {}} sl@0: test set-old-7.11 {unset command} { sl@0: catch {unset a} sl@0: set a(14) 22 sl@0: unset a sl@0: list [catch {set a(14)} msg] $msg [catch {array names a} msg2] $msg2 sl@0: } {1 {can't read "a(14)": no such variable} 0 {}} sl@0: test set-old-7.12 {unset command, -nocomplain} { sl@0: catch {unset a} sl@0: list [info exists a] [catch {unset -nocomplain a}] [info exists a] sl@0: } {0 0 0} sl@0: test set-old-7.13 {unset command, -nocomplain} { sl@0: set -nocomplain abc sl@0: list [info exists -nocomplain] [catch {unset -nocomplain}] \ sl@0: [info exists -nocomplain] [catch {unset -- -nocomplain}] \ sl@0: [info exists -nocomplain] sl@0: } {1 0 1 0 0} sl@0: test set-old-7.14 {unset command, --} { sl@0: set -- abc sl@0: list [info exists --] [catch {unset --}] \ sl@0: [info exists --] [catch {unset -- --}] \ sl@0: [info exists --] sl@0: } {1 0 1 0 0} sl@0: test set-old-7.15 {unset command, -nocomplain} { sl@0: set -nocomplain abc sl@0: set -- abc sl@0: list [info exists -nocomplain] [catch {unset -- -nocomplain}] \ sl@0: [info exists -nocomplain] [info exists --] \ sl@0: [catch {unset -- -nocomplain}] [info exists --] \ sl@0: [catch {unset -- --}] [info exists --] sl@0: } {1 0 0 1 1 1 0 0} sl@0: test set-old-7.16 {unset command, -nocomplain} { sl@0: set -nocomplain abc sl@0: set var abc sl@0: list [info exists bogus] [catch {unset -nocomplain bogus var bogus}] \ sl@0: [info exists -nocomplain] [info exists var] \ sl@0: [catch {unset -nocomplain -nocomplain}] [info exists -nocomplain] sl@0: } {0 0 1 0 0 0} sl@0: test set-old-7.17 {unset command, -nocomplain (no abbreviation)} { sl@0: set -nocomp abc sl@0: list [info exists -nocomp] [catch {unset -nocomp}] [info exists -nocomp] sl@0: } {1 0 0} sl@0: test set-old-7.18 {unset command, -nocomplain (no abbreviation)} { sl@0: catch {unset -nocomp} sl@0: list [info exists -nocomp] [catch {unset -nocomp}] sl@0: } {0 1} sl@0: sl@0: # Array command. sl@0: sl@0: test set-old-8.1 {array command} { sl@0: list [catch {array} msg] $msg sl@0: } {1 {wrong # args: should be "array option arrayName ?arg ...?"}} sl@0: test set-old-8.2 {array command} { sl@0: list [catch {array a} msg] $msg sl@0: } {1 {wrong # args: should be "array option arrayName ?arg ...?"}} sl@0: test set-old-8.3 {array command} { sl@0: catch {unset a} sl@0: list [catch {array anymore a b} msg] $msg sl@0: } {1 {"a" isn't an array}} sl@0: test set-old-8.4 {array command} { sl@0: catch {unset a} sl@0: set a 44 sl@0: list [catch {array anymore a b} msg] $msg sl@0: } {1 {"a" isn't an array}} sl@0: test set-old-8.5 {array command} { sl@0: proc foo {} { sl@0: set a 44 sl@0: upvar 0 a x sl@0: list [catch {array anymore x b} msg] $msg sl@0: } sl@0: foo sl@0: } {1 {"x" isn't an array}} sl@0: test set-old-8.6 {array command} { sl@0: catch {unset a} sl@0: set a(22) 3 sl@0: list [catch {array gorp a} msg] $msg sl@0: } {1 {bad option "gorp": must be anymore, donesearch, exists, get, names, nextelement, set, size, startsearch, statistics, or unset}} sl@0: test set-old-8.7 {array command, anymore option} { sl@0: catch {unset a} sl@0: list [catch {array anymore a x} msg] $msg sl@0: } {1 {"a" isn't an array}} sl@0: test set-old-8.8 {array command, anymore option, array doesn't exist yet but has compiler-allocated procedure slot} { sl@0: proc foo {x} { sl@0: if {$x==1} { sl@0: return [array anymore a x] sl@0: } sl@0: set a(x) 123 sl@0: } sl@0: list [catch {foo 1} msg] $msg sl@0: } {1 {"a" isn't an array}} sl@0: test set-old-8.9 {array command, donesearch option} { sl@0: catch {unset a} sl@0: list [catch {array donesearch a x} msg] $msg sl@0: } {1 {"a" isn't an array}} sl@0: test set-old-8.10 {array command, donesearch option, array doesn't exist yet but has compiler-allocated procedure slot} { sl@0: proc foo {x} { sl@0: if {$x==1} { sl@0: return [array donesearch a x] sl@0: } sl@0: set a(x) 123 sl@0: } sl@0: list [catch {foo 1} msg] $msg sl@0: } {1 {"a" isn't an array}} sl@0: test set-old-8.11 {array command, exists option} { sl@0: list [catch {array exists a b} msg] $msg sl@0: } {1 {wrong # args: should be "array exists arrayName"}} sl@0: test set-old-8.12 {array command, exists option} { sl@0: catch {unset a} sl@0: array exists a sl@0: } {0} sl@0: test set-old-8.13 {array command, exists option} { sl@0: catch {unset a} sl@0: set a(0) 1 sl@0: array exists a sl@0: } {1} sl@0: test set-old-8.14 {array command, exists option, array doesn't exist yet but has compiler-allocated procedure slot} { sl@0: proc foo {x} { sl@0: if {$x==1} { sl@0: return [array exists a] sl@0: } sl@0: set a(x) 123 sl@0: } sl@0: list [catch {foo 1} msg] $msg sl@0: } {0 0} sl@0: test set-old-8.15 {array command, get option} { sl@0: list [catch {array get} msg] $msg sl@0: } {1 {wrong # args: should be "array option arrayName ?arg ...?"}} sl@0: test set-old-8.16 {array command, get option} { sl@0: list [catch {array get a b c} msg] $msg sl@0: } {1 {wrong # args: should be "array get arrayName ?pattern?"}} sl@0: test set-old-8.17 {array command, get option} { sl@0: catch {unset a} sl@0: array get a sl@0: } {} sl@0: test set-old-8.18 {array command, get option} { sl@0: catch {unset a} sl@0: set a(22) 3 sl@0: set {a(long name)} {} sl@0: lsort [array get a] sl@0: } {{} 22 3 {long name}} sl@0: test set-old-8.19 {array command, get option (unset variable)} { sl@0: catch {unset a} sl@0: set a(x) 3 sl@0: trace var a(y) w ignore sl@0: array get a sl@0: } {x 3} sl@0: test set-old-8.20 {array command, get option, with pattern} { sl@0: catch {unset a} sl@0: set a(x1) 3 sl@0: set a(x2) 4 sl@0: set a(x3) 5 sl@0: set a(b1) 24 sl@0: set a(b2) 25 sl@0: lsort [array get a x*] sl@0: } {3 4 5 x1 x2 x3} sl@0: test set-old-8.21 {array command, get option, array doesn't exist yet but has compiler-allocated procedure slot} { sl@0: proc foo {x} { sl@0: if {$x==1} { sl@0: return [array get a] sl@0: } sl@0: set a(x) 123 sl@0: } sl@0: list [catch {foo 1} msg] $msg sl@0: } {0 {}} sl@0: test set-old-8.22 {array command, names option} { sl@0: catch {unset a} sl@0: set a(22) 3 sl@0: list [catch {array names a 4 5} msg] $msg sl@0: } {1 {bad option "4": must be -exact, -glob, or -regexp}} sl@0: test set-old-8.23 {array command, names option} { sl@0: catch {unset a} sl@0: array names a sl@0: } {} sl@0: test set-old-8.24 {array command, names option} { sl@0: catch {unset a} sl@0: set a(22) 3; set a(Textual_name) 44; set "a(name with spaces)" xxx sl@0: list [catch {lsort [array names a]} msg] $msg sl@0: } {0 {22 Textual_name {name with spaces}}} sl@0: test set-old-8.25 {array command, names option} { sl@0: catch {unset a} sl@0: set a(22) 3; set a(33) 44; sl@0: trace var a(xxx) w ignore sl@0: list [catch {lsort [array names a]} msg] $msg sl@0: } {0 {22 33}} sl@0: test set-old-8.26 {array command, names option} { sl@0: catch {unset a} sl@0: set a(22) 3; set a(33) 44; sl@0: trace var a(xxx) w ignore sl@0: set a(xxx) value sl@0: list [catch {lsort [array names a]} msg] $msg sl@0: } {0 {22 33 xxx}} sl@0: test set-old-8.27 {array command, names option} { sl@0: catch {unset a} sl@0: set a(axy) 3 sl@0: set a(bxy) 44 sl@0: set a(no) yes sl@0: set a(xxx) value sl@0: list [lsort [array names a *xy]] [lsort [array names a]] sl@0: } {{axy bxy} {axy bxy no xxx}} sl@0: test set-old-8.28 {array command, names option, array doesn't exist yet but has compiler-allocated procedure slot} { sl@0: proc foo {x} { sl@0: if {$x==1} { sl@0: return [array names a] sl@0: } sl@0: set a(x) 123 sl@0: } sl@0: list [catch {foo 1} msg] $msg sl@0: } {0 {}} sl@0: test set-old-8.29 {array command, nextelement option} { sl@0: list [catch {array nextelement a} msg] $msg sl@0: } {1 {wrong # args: should be "array nextelement arrayName searchId"}} sl@0: test set-old-8.30 {array command, nextelement option} { sl@0: catch {unset a} sl@0: list [catch {array nextelement a b} msg] $msg sl@0: } {1 {"a" isn't an array}} sl@0: test set-old-8.31 {array command, nextelement option, array doesn't exist yet but has compiler-allocated procedure slot} { sl@0: proc foo {x} { sl@0: if {$x==1} { sl@0: return [array nextelement a b] sl@0: } sl@0: set a(x) 123 sl@0: } sl@0: list [catch {foo 1} msg] $msg sl@0: } {1 {"a" isn't an array}} sl@0: test set-old-8.32 {array command, set option} { sl@0: list [catch {array set a} msg] $msg sl@0: } {1 {wrong # args: should be "array set arrayName list"}} sl@0: test set-old-8.33 {array command, set option} { sl@0: list [catch {array set a 1 2} msg] $msg sl@0: } {1 {wrong # args: should be "array set arrayName list"}} sl@0: test set-old-8.34 {array command, set option} { sl@0: list [catch {array set a "a \{ c"} msg] $msg sl@0: } {1 {unmatched open brace in list}} sl@0: test set-old-8.35 {array command, set option} { sl@0: catch {unset a} sl@0: set a 44 sl@0: list [catch {array set a {a b c d}} msg] $msg sl@0: } {1 {can't set "a(a)": variable isn't array}} sl@0: test set-old-8.36 {array command, set option} { sl@0: catch {unset a} sl@0: set a(xx) yy sl@0: array set a {b c d e} sl@0: lsort [array get a] sl@0: } {b c d e xx yy} sl@0: test set-old-8.37 {array command, set option, array doesn't exist yet but has compiler-allocated procedure slot} { sl@0: proc foo {x} { sl@0: if {$x==1} { sl@0: return [array set a {x 0}] sl@0: } sl@0: set a(x) sl@0: } sl@0: list [catch {foo 1} msg] $msg sl@0: } {0 {}} sl@0: test set-old-8.38 {array command, set option} { sl@0: catch {unset aVaRnAmE} sl@0: array set aVaRnAmE {} sl@0: list [info exists aVaRnAmE] [catch {set aVaRnAmE} msg] $msg sl@0: } {1 1 {can't read "aVaRnAmE": variable is array}} sl@0: test set-old-8.38.1 {array command, set scalar} { sl@0: catch {unset aVaRnAmE} sl@0: set aVaRnAmE 1 sl@0: list [catch {array set aVaRnAmE {}} msg] $msg sl@0: } {1 {can't array set "aVaRnAmE": variable isn't array}} sl@0: test set-old-8.38.2 {array command, set alias} { sl@0: catch {unset aVaRnAmE} sl@0: upvar 0 aVaRnAmE anAliAs sl@0: array set anAliAs {} sl@0: list [array exists aVaRnAmE] [catch {set anAliAs} msg] $msg sl@0: } {1 1 {can't read "anAliAs": variable is array}} sl@0: test set-old-8.38.3 {array command, set element alias} { sl@0: catch {unset aVaRnAmE} sl@0: list [catch {upvar 0 aVaRnAmE(elem) elemAliAs}] \ sl@0: [catch {array set elemAliAs {}} msg] $msg sl@0: } {0 1 {can't array set "elemAliAs": variable isn't array}} sl@0: test set-old-8.38.4 {array command, empty set with populated array} { sl@0: catch {unset aVaRnAmE} sl@0: array set aVaRnAmE [list e1 v1 e2 v2] sl@0: array set aVaRnAmE {} sl@0: array set aVaRnAmE [list e3 v3] sl@0: list [lsort [array names aVaRnAmE]] [catch {set aVaRnAmE(e2)} msg] $msg sl@0: } {{e1 e2 e3} 0 v2} sl@0: test set-old-8.38.5 {array command, set with non-existent namespace} { sl@0: list [catch {array set bogusnamespace::var {}} msg] $msg sl@0: } {1 {can't set "bogusnamespace::var": parent namespace doesn't exist}} sl@0: test set-old-8.38.6 {array command, set with non-existent namespace} { sl@0: list [catch {array set bogusnamespace::var {a b}} msg] $msg sl@0: } {1 {can't set "bogusnamespace::var": parent namespace doesn't exist}} sl@0: test set-old-8.38.7 {array command, set with non-existent namespace} { sl@0: list [catch {array set bogusnamespace::var(0) {a b}} msg] $msg sl@0: } {1 {can't set "bogusnamespace::var(0)": variable isn't array}} sl@0: test set-old-8.39 {array command, size option} { sl@0: catch {unset a} sl@0: array size a sl@0: } {0} sl@0: test set-old-8.40 {array command, size option} { sl@0: list [catch {array size a 4} msg] $msg sl@0: } {1 {wrong # args: should be "array size arrayName"}} sl@0: test set-old-8.41 {array command, size option} { sl@0: catch {unset a} sl@0: array size a sl@0: } {0} sl@0: test set-old-8.42 {array command, size option} { sl@0: catch {unset a} sl@0: set a(22) 3; set a(Textual_name) 44; set "a(name with spaces)" xxx sl@0: list [catch {array size a} msg] $msg sl@0: } {0 3} sl@0: test set-old-8.43 {array command, size option} { sl@0: catch {unset a} sl@0: set a(22) 3; set a(xx) 44; set a(y) xxx sl@0: unset a(22) a(y) a(xx) sl@0: list [catch {array size a} msg] $msg sl@0: } {0 0} sl@0: test set-old-8.44 {array command, size option} { sl@0: catch {unset a} sl@0: set a(22) 3; sl@0: trace var a(33) rwu ignore sl@0: list [catch {array size a} msg] $msg sl@0: } {0 1} sl@0: test set-old-8.45 {array command, size option, array doesn't exist yet but has compiler-allocated procedure slot} { sl@0: proc foo {x} { sl@0: if {$x==1} { sl@0: return [array size a] sl@0: } sl@0: set a(x) 123 sl@0: } sl@0: list [catch {foo 1} msg] $msg sl@0: } {0 0} sl@0: test set-old-8.46 {array command, startsearch option} { sl@0: list [catch {array startsearch a b} msg] $msg sl@0: } {1 {wrong # args: should be "array startsearch arrayName"}} sl@0: test set-old-8.47 {array command, startsearch option} { sl@0: catch {unset a} sl@0: list [catch {array startsearch a} msg] $msg sl@0: } {1 {"a" isn't an array}} sl@0: test set-old-8.48 {array command, startsearch option, array doesn't exist yet but has compiler-allocated procedure slot} { sl@0: catch {rename p ""} sl@0: proc p {x} { sl@0: if {$x==1} { sl@0: return [array startsearch a] sl@0: } sl@0: set a(x) 123 sl@0: } sl@0: list [catch {p 1} msg] $msg sl@0: } {1 {"a" isn't an array}} sl@0: test set-old-8.49 {array command, statistics option} { sl@0: catch {unset a} sl@0: set a(abc) 1 sl@0: set a(def) 2 sl@0: set a(ghi) 3 sl@0: set a(jkl) 4 sl@0: set a(mno) 5 sl@0: set a(pqr) 6 sl@0: set a(stu) 7 sl@0: set a(vwx) 8 sl@0: set a(yz) 9 sl@0: array statistics a sl@0: } "9 entries in table, 4 buckets sl@0: number of buckets with 0 entries: 0 sl@0: number of buckets with 1 entries: 0 sl@0: number of buckets with 2 entries: 3 sl@0: number of buckets with 3 entries: 1 sl@0: number of buckets with 4 entries: 0 sl@0: number of buckets with 5 entries: 0 sl@0: number of buckets with 6 entries: 0 sl@0: number of buckets with 7 entries: 0 sl@0: number of buckets with 8 entries: 0 sl@0: number of buckets with 9 entries: 0 sl@0: number of buckets with 10 or more entries: 0 sl@0: average search distance for entry: 1.7" sl@0: test set-old-8.50 {array command, array names -exact on glob pattern} { sl@0: catch {unset a} sl@0: set a(1*2) 1 sl@0: list [catch {array names a -exact 1*2} msg] $msg sl@0: } {0 1*2} sl@0: test set-old-8.51 {array command, array names -glob on glob pattern} { sl@0: catch {unset a} sl@0: set a(1*2) 1 sl@0: set a(12) 1 sl@0: set a(11) 1 sl@0: list [catch {lsort [array names a -glob 1*2]} msg] $msg sl@0: } {0 {1*2 12}} sl@0: test set-old-8.52 {array command, array names -regexp on regexp pattern} { sl@0: catch {unset a} sl@0: set a(1*2) 1 sl@0: set a(12) 1 sl@0: set a(11) 1 sl@0: list [catch {lsort [array names a -regexp ^1]} msg] $msg sl@0: } {0 {1*2 11 12}} sl@0: test set-old-8.53 {array command, array names -regexp} { sl@0: catch {unset a} sl@0: set a(-glob) 1 sl@0: set a(-regexp) 1 sl@0: set a(-exact) 1 sl@0: list [catch {array names a -regexp} msg] $msg sl@0: } {0 -regexp} sl@0: test set-old-8.54 {array command, array names -exact} { sl@0: catch {unset a} sl@0: set a(-glob) 1 sl@0: set a(-regexp) 1 sl@0: set a(-exact) 1 sl@0: list [catch {array names a -exact} msg] $msg sl@0: } {0 -exact} sl@0: test set-old-8.55 {array command, array names -glob} { sl@0: catch {unset a} sl@0: set a(-glob) 1 sl@0: set a(-regexp) 1 sl@0: set a(-exact) 1 sl@0: list [catch {array names a -glob} msg] $msg sl@0: } {0 -glob} sl@0: test set-old-8.56 {array command, array statistics on a non-array} { sl@0: catch {unset a} sl@0: list [catch {array statistics a} msg] $msg sl@0: } [list 1 "\"a\" isn't an array"] sl@0: sl@0: test set-old-9.1 {ids for array enumeration} { sl@0: catch {unset a} sl@0: set a(a) 1 sl@0: list [array star a] [array star a] [array done a s-1-a; array star a] \ sl@0: [array done a s-2-a; array d a s-3-a; array start a] sl@0: } {s-1-a s-2-a s-3-a s-1-a} sl@0: test set-old-9.2 {array enumeration} { sl@0: catch {unset a} sl@0: set a(a) 1 sl@0: set a(b) 1 sl@0: set a(c) 1 sl@0: set x [array startsearch a] sl@0: lsort [list [array nextelement a $x] [array ne a $x] [array next a $x] \ sl@0: [array next a $x] [array next a $x]] sl@0: } {{} {} a b c} sl@0: test set-old-9.3 {array enumeration} { sl@0: catch {unset a} sl@0: set a(a) 1 sl@0: set a(b) 1 sl@0: set a(c) 1 sl@0: set x [array startsearch a] sl@0: set y [array startsearch a] sl@0: set z [array startsearch a] sl@0: lsort [list [array nextelement a $x] [array ne a $x] \ sl@0: [array next a $y] [array next a $z] [array next a $y] \ sl@0: [array next a $z] [array next a $y] [array next a $z] \ sl@0: [array next a $y] [array next a $z] [array next a $x] \ sl@0: [array next a $x]] sl@0: } {{} {} {} a a a b b b c c c} sl@0: test set-old-9.4 {array enumeration: stopping searches} { sl@0: catch {unset a} sl@0: set a(a) 1 sl@0: set a(b) 1 sl@0: set a(c) 1 sl@0: set x [array startsearch a] sl@0: set y [array startsearch a] sl@0: set z [array startsearch a] sl@0: lsort [list [array next a $x] [array next a $x] [array next a $y] \ sl@0: [array done a $z; array next a $x] \ sl@0: [array done a $x; array next a $y] [array next a $y]] sl@0: } {a a b b c c} sl@0: test set-old-9.5 {array enumeration: stopping searches} { sl@0: catch {unset a} sl@0: set a(a) 1 sl@0: set x [array startsearch a] sl@0: array done a $x sl@0: list [catch {array next a $x} msg] $msg sl@0: } {1 {couldn't find search "s-1-a"}} sl@0: test set-old-9.6 {array enumeration: searches automatically stopped} { sl@0: catch {unset a} sl@0: set a(a) 1 sl@0: set x [array startsearch a] sl@0: set y [array startsearch a] sl@0: set a(b) 1 sl@0: list [catch {array next a $x} msg] $msg \ sl@0: [catch {array next a $y} msg2] $msg2 sl@0: } {1 {couldn't find search "s-1-a"} 1 {couldn't find search "s-2-a"}} sl@0: test set-old-9.7 {array enumeration: searches automatically stopped} { sl@0: catch {unset a} sl@0: set a(a) 1 sl@0: set x [array startsearch a] sl@0: set y [array startsearch a] sl@0: set a(a) 2 sl@0: list [catch {array next a $x} msg] $msg \ sl@0: [catch {array next a $y} msg2] $msg2 sl@0: } {0 a 0 a} sl@0: test set-old-9.8 {array enumeration: searches automatically stopped} { sl@0: catch {unset a} sl@0: set a(a) 1 sl@0: set a(c) 2 sl@0: set x [array startsearch a] sl@0: set y [array startsearch a] sl@0: catch {unset a(c)} sl@0: list [catch {array next a $x} msg] $msg \ sl@0: [catch {array next a $y} msg2] $msg2 sl@0: } {1 {couldn't find search "s-1-a"} 1 {couldn't find search "s-2-a"}} sl@0: test set-old-9.9 {array enumeration: searches automatically stopped} { sl@0: catch {unset a} sl@0: set a(a) 1 sl@0: set x [array startsearch a] sl@0: set y [array startsearch a] sl@0: catch {unset a(c)} sl@0: list [catch {array next a $x} msg] $msg \ sl@0: [catch {array next a $y} msg2] $msg2 sl@0: } {0 a 0 a} sl@0: test set-old-9.10 {array enumeration: searches automatically stopped} { sl@0: catch {unset a} sl@0: set a(a) 1 sl@0: set x [array startsearch a] sl@0: set y [array startsearch a] sl@0: trace var a(b) r {} sl@0: list [catch {array next a $x} msg] $msg \ sl@0: [catch {array next a $y} msg2] $msg2 sl@0: } {1 {couldn't find search "s-1-a"} 1 {couldn't find search "s-2-a"}} sl@0: test set-old-9.11 {array enumeration: searches automatically stopped} { sl@0: catch {unset a} sl@0: set a(a) 1 sl@0: set x [array startsearch a] sl@0: set y [array startsearch a] sl@0: trace var a(a) r {} sl@0: list [catch {array next a $x} msg] $msg \ sl@0: [catch {array next a $y} msg2] $msg2 sl@0: } {0 a 0 a} sl@0: test set-old-9.12 {array enumeration with traced undefined elements} { sl@0: catch {unset a} sl@0: set a(a) 1 sl@0: trace var a(b) r {} sl@0: set x [array startsearch a] sl@0: lsort [list [array next a $x] [array next a $x]] sl@0: } {{} a} sl@0: sl@0: test set-old-10.1 {array enumeration errors} { sl@0: list [catch {array start} msg] $msg sl@0: } {1 {wrong # args: should be "array option arrayName ?arg ...?"}} sl@0: test set-old-10.2 {array enumeration errors} { sl@0: list [catch {array start a b} msg] $msg sl@0: } {1 {wrong # args: should be "array startsearch arrayName"}} sl@0: test set-old-10.3 {array enumeration errors} { sl@0: catch {unset a} sl@0: list [catch {array start a} msg] $msg sl@0: } {1 {"a" isn't an array}} sl@0: test set-old-10.4 {array enumeration errors} { sl@0: catch {unset a} sl@0: set a(a) 1 sl@0: set x [array startsearch a] sl@0: list [catch {array next a} msg] $msg sl@0: } {1 {wrong # args: should be "array nextelement arrayName searchId"}} sl@0: test set-old-10.5 {array enumeration errors} { sl@0: catch {unset a} sl@0: set a(a) 1 sl@0: set x [array startsearch a] sl@0: list [catch {array next a b c} msg] $msg sl@0: } {1 {wrong # args: should be "array nextelement arrayName searchId"}} sl@0: test set-old-10.6 {array enumeration errors} { sl@0: catch {unset a} sl@0: set a(a) 1 sl@0: set x [array startsearch a] sl@0: list [catch {array next a a-1-a} msg] $msg sl@0: } {1 {illegal search identifier "a-1-a"}} sl@0: test set-old-10.7 {array enumeration errors} { sl@0: catch {unset a} sl@0: set a(a) 1 sl@0: set x [array startsearch a] sl@0: list [catch {array next a sx1-a} msg] $msg sl@0: } {1 {illegal search identifier "sx1-a"}} sl@0: test set-old-10.8 {array enumeration errors} { sl@0: catch {unset a} sl@0: set a(a) 1 sl@0: set x [array startsearch a] sl@0: list [catch {array next a s--a} msg] $msg sl@0: } {1 {illegal search identifier "s--a"}} sl@0: test set-old-10.9 {array enumeration errors} { sl@0: catch {unset a} sl@0: set a(a) 1 sl@0: set x [array startsearch a] sl@0: list [catch {array next a s-1-b} msg] $msg sl@0: } {1 {search identifier "s-1-b" isn't for variable "a"}} sl@0: test set-old-10.10 {array enumeration errors} { sl@0: catch {unset a} sl@0: set a(a) 1 sl@0: set x [array startsearch a] sl@0: list [catch {array next a s-1ba} msg] $msg sl@0: } {1 {illegal search identifier "s-1ba"}} sl@0: test set-old-10.11 {array enumeration errors} { sl@0: catch {unset a} sl@0: set a(a) 1 sl@0: set x [array startsearch a] sl@0: list [catch {array next a s-2-a} msg] $msg sl@0: } {1 {couldn't find search "s-2-a"}} sl@0: test set-old-10.12 {array enumeration errors} { sl@0: list [catch {array done a} msg] $msg sl@0: } {1 {wrong # args: should be "array donesearch arrayName searchId"}} sl@0: test set-old-10.13 {array enumeration errors} { sl@0: list [catch {array done a b c} msg] $msg sl@0: } {1 {wrong # args: should be "array donesearch arrayName searchId"}} sl@0: test set-old-10.14 {array enumeration errors} { sl@0: list [catch {array done a b} msg] $msg sl@0: } {1 {illegal search identifier "b"}} sl@0: test set-old-10.15 {array enumeration errors} { sl@0: list [catch {array anymore a} msg] $msg sl@0: } {1 {wrong # args: should be "array anymore arrayName searchId"}} sl@0: test set-old-10.16 {array enumeration errors} { sl@0: list [catch {array any a b c} msg] $msg sl@0: } {1 {wrong # args: should be "array anymore arrayName searchId"}} sl@0: test set-old-10.17 {array enumeration errors} { sl@0: catch {unset a} sl@0: set a(0) 44 sl@0: list [catch {array any a bogus} msg] $msg sl@0: } {1 {illegal search identifier "bogus"}} sl@0: sl@0: # Array enumeration with "anymore" option sl@0: sl@0: test set-old-11.1 {array anymore option} { sl@0: catch {unset a} sl@0: set a(a) 1 sl@0: set a(b) 2 sl@0: set a(c) 3 sl@0: array startsearch a sl@0: lsort [list [array anymore a s-1-a] [array next a s-1-a] \ sl@0: [array anymore a s-1-a] [array next a s-1-a] \ sl@0: [array anymore a s-1-a] [array next a s-1-a] \ sl@0: [array anymore a s-1-a] [array next a s-1-a]] sl@0: } {{} 0 1 1 1 a b c} sl@0: test set-old-11.2 {array anymore option} { sl@0: catch {unset a} sl@0: set a(a) 1 sl@0: set a(b) 2 sl@0: set a(c) 3 sl@0: array startsearch a sl@0: lsort [list [array next a s-1-a] [array next a s-1-a] \ sl@0: [array anymore a s-1-a] [array next a s-1-a] \ sl@0: [array next a s-1-a] [array anymore a s-1-a]] sl@0: } {{} 0 1 a b c} sl@0: sl@0: # Special check to see that the value of a variable is handled correctly sl@0: # if it is returned as the result of a procedure (must not free the variable sl@0: # string while deleting the call frame). Errors will only be detected if sl@0: # a memory consistency checker such as Purify is being used. sl@0: sl@0: test set-old-12.1 {cleanup on procedure return} { sl@0: proc foo {} { sl@0: set x 12345 sl@0: } sl@0: foo sl@0: } 12345 sl@0: test set-old-12.2 {cleanup on procedure return} { sl@0: proc foo {} { sl@0: set x(1) 23456 sl@0: } sl@0: foo sl@0: } 23456 sl@0: sl@0: # Must delete variables when done, since these arrays get used as sl@0: # scalars by other tests. sl@0: catch {unset a} sl@0: catch {unset b} sl@0: catch {unset c} sl@0: catch {unset aVaRnAmE} sl@0: sl@0: # cleanup sl@0: ::tcltest::cleanupTests sl@0: return