From ba67de24f09cd22ab6f3ac3a0b89e3a62a1bfbc1 Mon Sep 17 00:00:00 2001 From: Didier Raboud Date: Tue, 28 Nov 2017 16:59:36 +0100 Subject: Import jimtcl_0.77+dfsg0.orig.tar.xz [dgit import orig jimtcl_0.77+dfsg0.orig.tar.xz] --- tests/array.test | 88 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100644 tests/array.test (limited to 'tests/array.test') diff --git a/tests/array.test b/tests/array.test new file mode 100644 index 0000000..ba88147 --- /dev/null +++ b/tests/array.test @@ -0,0 +1,88 @@ +source [file dirname [info script]]/testing.tcl + +needs cmd array + +unset -nocomplain a +array set a { + 1 one + 2 two + 22 "twenty two" + 3 three +} + +test array-1.1 "array exists - true" { + array exists a +} {1} + +test array-1.2 "array exists - false" { + array exists b +} {0} + +test array-1.3 "array size" { + array size a +} {4} + +test array-1.4 "array size - nonexistant" { + array size b +} {0} + +test array-1.5 "array get" { + set result {} + foreach {name value} [array get a] { + lappend result $name $value + } + lsort $result +} {1 2 22 3 one three {twenty two} two} + +test array-1.6 "array get - pattern" { + set result {} + foreach {name value} [array get a 2*] { + lappend result $name $value + } + lsort $result +} {2 22 {twenty two} two} + +test array-1.7 "array names" { + lsort [array names a] +} {1 2 22 3} + +test array-1.8 "array get - pattern" { + lsort [array names a 2*] +} {2 22} + +#set b $a +array set b [array get a] + +test array-1.9 "array set - replace" { + array set b {22 twenty-two} + set b(22) +} {twenty-two} + +test array-1.10 "array unset - pattern" { + array unset b 2* + lsort [array names b] +} {1 3} + +test array-1.11 "array unset - all" { + array unset b + list [array size b] [array exists b] +} {0 0} + +test array-1.12 "array set to invalid variable" -body { + unset -nocomplain a b + set a 1 + array set a(1) {b c} +} -returnCodes error -result {can't set "a(1)": variable isn't array} + +test array-1.13 "unset missing array element" -body { + unset -nocomplain a + set a(1) one + unset a(2) +} -returnCodes error -result {can't unset "a(2)": no such element in array} + +test array-1.14 "access array via unset var" -body { + unset -nocomplain b + expr {$a($b) + 4} +} -returnCodes error -result {can't read "b": no such variable} + +testreport -- cgit v1.2.3