1 source [file dirname [info script]]/testing.tcl
13 test array-1.1 "array exists - true" {
17 test array-1.2 "array exists - false" {
21 test array-1.3 "array size" {
25 test array-1.4 "array size - nonexistant" {
29 test array-1.5 "array get" {
31 foreach {name value} [array get a] {
32 lappend result $name $value
35 } {1 2 22 3 one three {twenty two} two}
37 test array-1.6 "array get - pattern" {
39 foreach {name value} [array get a 2*] {
40 lappend result $name $value
43 } {2 22 {twenty two} two}
45 test array-1.7 "array names" {
49 test array-1.8 "array get - pattern" {
50 lsort [array names a 2*]
54 array set b [array get a]
56 test array-1.9 "array set - replace" {
57 array set b {22 twenty-two}
61 test array-1.10 "array unset - pattern" {
66 test array-1.11 "array unset - all" {
68 list [array size b] [array exists b]
71 test array-1.12 "array set to invalid variable" -body {
75 } -returnCodes error -result {can't set "a(1)": variable isn't array}
77 test array-1.13 "unset missing array element" -body {
81 } -returnCodes error -result {can't unset "a(2)": no such element in array}
83 test array-1.14 "access array via unset var" -body {
86 } -returnCodes error -result {can't read "b": no such variable}
88 test array-1.15 "array unset non-variable" -body {
89 array unset nonvariable 4
92 test array-1.16 "array names non-variable" -body {
93 array names nonvariable
96 test array-1.17 "array get non-variable" -body {
100 # This seems like incorrect behaviour, but it matches tclsh
101 test array-1.18 "array size non-array" -body {
106 # This seems like incorrect behaviour, but it matches tclsh
107 test array-1.19 "array unset non-array" -body {
112 test array-1.20 "array stat" -body {
113 set output [array stat a]
114 regexp "1 entries in table.*number of buckets with 1 entries: 1" $output
117 test array-1.21 "array stat non-array" -body {
118 array stat badvariable
119 } -returnCodes error -result {"badvariable" isn't an array}
121 test array-1.22 "array set non-even args" -body {
127 } -returnCodes error -result {list must have an even number of elements}
129 test array-1.23 "array exists non-array" -body {