1 source [file dirname [info script]]/testing.tcl
3 test dict-1.1 "Basic dict" {
8 #puts "d(fruit)=$d(fruit)"
14 test dict-2.1 "Dict via reference" references {
16 dict set d fruit apple
19 # now create a dictionary reference
20 set dref [ref $d dict]
21 dict get [getref $dref] car
24 test dict-2.2 "Modify dict via reference" references {
25 # Get the value out of the refernence
29 # And put the new value back
32 dict get [getref $dref] car
35 test dict-2.3 "Modify dict via reference - one line" references {
36 # Get the value out of the refernence
38 setref $dref [dict set d car toyota]
40 dict get [getref $dref] car
43 # Sort a dictionary in key order - return a list
44 proc dictsort {dict} {
46 foreach k [lsort [dict keys $dict]] {
47 lappend result $k [dict get $dict $k]
52 set a [dict create a 1 b 2]
53 set b [dict create b 3 c 4]
54 test dict-3.1 {Merge} {
57 test dict-3.2 {Merge} {
58 dictsort [dict merge $a]
60 test dict-3.3 {Merge} {
61 dictsort [dict merge $b]
63 test dict-3.4 {Merge} {
64 dictsort [dict merge $a $b]
66 test dict-3.5 {Merge} {
67 dictsort [dict merge $b $a]
69 test dict-3.6 {Merge} {
70 dictsort [dict merge $b $a {a 5}]
72 test dict-3.7 {Merge} {
73 dictsort [dict merge {a 5} $b $a]
75 test dict-3.8 {Merge} {
76 catch {dict merge 1 $b $a}
78 test dict-3.9 {Merge} {
79 catch {dict merge $b 1 $a}
81 test dict-3.10 {Merge} {
82 catch {dict merge $b $a 1}
84 test dict-3.11 {Merge} {
88 test dict-4.1 {Dict size} {
91 test dict-4.2 {Dict size} {
95 test dict-5.1 {Dict with} {
97 set x [dict create a b c d]
106 test dict-5.2 {Dict with} {
108 set x [dict create a b c d]
118 test dict-22.1 {dict with command} {
119 list [catch {dict with} msg] $msg
120 } {1 {wrong # args: should be "dict with dictVar ?key ...? script"}}
121 test dict-22.2 {dict with command} {
122 list [catch {dict with v} msg] $msg
123 } {1 {wrong # args: should be "dict with dictVar ?key ...? script"}}
124 test dict-22.3 {dict with command} {
126 list [catch {dict with v {error "in body"}} msg] $msg
127 } {1 {can't read "v": no such variable}}
128 test dict-22.4 {dict with command} {
130 unset -nocomplain b d
131 set result [list [info exist b] [info exist d]]
133 lappend result [info exist b] [info exist d] $b $d
137 test dict-22.5 {dict with command} {
144 test dict-22.6 {dict with command} {
148 # This *won't* go into the dict...
153 test dict-22.7 {dict with command} {
160 test dict-22.8 {dict with command} {
161 set a [dict create b c]
167 test dict-22.9 {dict with command} {
174 test dict-22.10 {dict with command: result handling tricky case} {
180 # We're checking to see if we lose this break
186 test dict-22.11 {dict with command: no recursive structures [Bug 1786481]} {
187 set foo {t {t {t {inner 1}}}}
197 string range [append foo OK] end-1 end
200 test dict-23.1 {dict unset missing last level} {
206 test dict-23.2 {dict unset command} -returnCodes error -body {
211 } -result {missing value to go with key}
213 test dict-23.3 {dict unset command} -setup {
214 unset -nocomplain dictVar
216 list [info exists dictVar] [dict unset dictVar a] [info exists dictVar]
221 test dict-23.4 {dict unset command: write failure} -setup {
222 unset -nocomplain dictVar
226 } -returnCodes error -cleanup {
228 } -result {missing value to go with key}
230 test dict-24.1 {dict/list shimmering - Bug 3004007} {set l [list p 1 p 2 q 3];dict get $l q;set l} {p 1 p 2 q 3}
231 test dict-24.2 {dict/list shimmering - Bug 3004007} {set l [list p 1 p 2 q 3];dict get $l q;llength $l} 6
233 test dict-24.3 {dict/list shimmering with embedded nulls} {
234 # Must be a string containing embedded nulls that would be double quoted in string form
235 set binary_value 1\000\\
236 set dictVar [dict create value $binary_value]
240 test dict-24.4 {dict/list shimmering with lappend and foreach} {