1 # This test file covers the dictionary object type and the dict command used
2 # to work with values of that type.
4 # This file contains a collection of tests for one or more of the Tcl built-in
5 # commands. Sourcing this file into Tcl runs the tests and generates output
6 # for errors. No output means no errors were found.
8 # Copyright (c) 2003-2009 Donal K. Fellows
9 # See the file "license.terms" for information on usage and redistribution of
10 # this file, and for a DISCLAIMER OF ALL WARRANTIES.
12 source [file dirname [info script]]/testing.tcl
14 # jim dicts don't preserve order, so always sort
15 # before checking results
16 proc dict-sort {dict} {
18 foreach k [lsort [dict keys $dict]] {
19 lappend result $k [dict get $dict $k]
24 test dict-1.1 {dict command basic syntax} -returnCodes error -body {
26 } -match glob -result {wrong # args: should be "dict subcommand ?arg* ...?"}
27 test dict-1.2 {dict command basic syntax} -returnCodes error -body {
29 } -match glob -result *
31 test dict-2.1 {dict create command} {
34 test dict-2.2 {dict create command} {
37 test dict-2.3 {dict create command} -body {
39 set dict [dict create a b c d]
40 # Can't compare directly as ordering of values is undefined
42 set idx [lsearch -exact $dict $key]
44 error "found $key at odd index $idx in $dict"
46 lappend result [lindex $dict [expr {$idx+1}]]
50 unset result dict key idx
52 test dict-2.4 {dict create command} -returnCodes error -body {
54 } -result {wrong # args: should be "dict create ?key value ...?"}
55 test dict-2.5 {dict create command} -returnCodes error -body {
57 } -result {wrong # args: should be "dict create ?key value ...?"}
58 test dict-2.6 {dict create command - initialse refcount field!} -body {
59 # Bug 715751 will show up in memory debuggers like purify
60 for {set i 0} {$i<10} {incr i} {
61 set dictv [dict create a 0]
63 set share [dict values $dictv]
65 set share [array get dictv]
67 list [dict incr dictv a]
72 test dict-2.7 {dict create command - #-quoting in string rep} {
73 dict create # #comment
75 test dict-2.8 {dict create command - #-quoting in string rep} -body {
77 } -match glob -result {{#?} x #? x}
79 test dict-3.1 {dict get command} {dict get {a b} a} b
80 test dict-3.2 {dict get command} {dict get {a b c d} a} b
81 test dict-3.3 {dict get command} {dict get {a b c d} c} d
82 test dict-3.4 {dict get command} -returnCodes error -body {
84 } -result {key "b" not known in dictionary}
85 test dict-3.5 {dict get command} {dict get {a {p q r s} b {u v x y}} a p} q
86 test dict-3.6 {dict get command} {dict get {a {p q r s} b {u v x y}} a r} s
87 test dict-3.7 {dict get command} {dict get {a {p q r s} b {u v x y}} b u} v
88 test dict-3.8 {dict get command} {dict get {a {p q r s} b {u v x y}} b x} y
89 test dict-3.9 {dict get command} -returnCodes error -body {
90 dict get {a {p q r s} b {u v x y}} a z
91 } -result {key "z" not known in dictionary}
92 test dict-3.10 {dict get command} -returnCodes error -body {
93 dict get {a {p q r s} b {u v x y}} c z
94 } -result {key "c" not known in dictionary}
95 test dict-3.11 {dict get command} {dict get [dict create a b c d] a} b
96 test dict-3.12 {dict get command} -returnCodes error -body {
98 } -match glob -result {wrong # args: should be "dict get dictionary ?key*?"}
99 test dict-3.13 {dict get command} -body {
100 set dict [dict get {a b c d}]
101 if {$dict eq "a b c d"} {
103 } elseif {$dict eq "c d a b"} {
111 test dict-3.14 {dict get command} -returnCodes error -body {
112 dict get {a b c d} a c
113 } -result {missing value to go with key}
114 test dict-3.15 {compiled dict get error cleanliness - Bug 2431847} -body {
120 } -returnCodes error -result {key "d" not known in dictionary}
121 test dict-3.16 {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}
122 test dict-3.17 {dict/list shimmering - Bug 3004007} {set l [list p 1 p 2 q 3];dict get $l q;llength $l} 6
123 test dict-3.18 {array set non-dict get command} -constraints jim -returnCodes error -body {
125 array set a {a b c d}
126 } -result {missing value to go with key}
128 test dict-4.1 {dict replace command} {
129 dict-sort [dict replace {a b c d}]
131 test dict-4.2 {dict replace command} {
132 dict-sort [dict replace {a b c d} e f]
134 test dict-4.3 {dict replace command} {
135 dict-sort [dict replace {a b c d} c f]
137 test dict-4.4 {dict replace command} {
138 dict-sort [dict replace {a b c d} c x a y]
140 test dict-4.5 {dict replace command} -returnCodes error -body {
142 } -result {wrong # args: should be "dict replace dictionary ?key value ...?"}
143 test dict-4.6 {dict replace command} -returnCodes error -body {
145 } -result {wrong # args: should be "dict replace dictionary ?key value ...?"}
146 test dict-4.7 {dict replace command} -returnCodes error -body {
147 dict replace {a a a} a b
148 } -result {missing value to go with key}
149 test dict-4.8 {dict replace command} -returnCodes error -body {
150 dict replace [list a a a] a b
151 } -result {missing value to go with key}
152 test dict-4.9 {dict replace command} {dict replace [list a a] a b} {a b}
153 test dict-4.10 {dict replace command} {dict replace [list a a] a b a c} {a c}
155 test dict-5.1 {dict remove command} {dict remove {a b c d} a} {c d}
156 test dict-5.2 {dict remove command} {dict remove {a b c d} c} {a b}
157 test dict-5.3 {dict remove command} {dict remove {a b c d} a c} {}
158 test dict-5.4 {dict remove command} {dict remove {a b c d} c a} {}
159 test dict-5.5 {dict remove command} {
160 dict remove {a b c d}
162 test dict-5.6 {dict remove command} {dict remove {a b} c} {a b}
163 test dict-5.7 {dict remove command} -returnCodes error -body {
165 } -result {wrong # args: should be "dict remove dictionary ?key ...?"}
167 test dict-6.1 {dict keys command} {dict keys {a b}} a
168 test dict-6.2 {dict keys command} {dict keys {c d}} c
169 test dict-6.3 {dict keys command} {lsort [dict keys {a b c d}]} {a c}
170 test dict-6.4 {dict keys command} {dict keys {a b c d} a} a
171 test dict-6.5 {dict keys command} {dict keys {a b c d} c} c
172 test dict-6.6 {dict keys command} {dict keys {a b c d} e} {}
173 test dict-6.7 {dict keys command} {lsort [dict keys {a b c d ca da} c*]} {c ca}
174 test dict-6.8 {dict keys command} -returnCodes error -body {
176 } -result {wrong # args: should be "dict keys dictionary ?pattern?"}
177 test dict-6.9 {dict keys command} -returnCodes error -body {
179 } -result {wrong # args: should be "dict keys dictionary ?pattern?"}
180 test dict-6.10 {dict keys command} -returnCodes error -body {
182 } -result {missing value to go with key}
184 test dict-7.1 {dict values command} {dict values {a b}} b
185 test dict-7.2 {dict values command} {dict values {c d}} d
186 test dict-7.3 {dict values command} {lsort [dict values {a b c d}]} {b d}
187 test dict-7.4 {dict values command} {dict values {a b c d} b} b
188 test dict-7.5 {dict values command} {dict values {a b c d} d} d
189 test dict-7.6 {dict values command} {dict values {a b c d} e} {}
190 test dict-7.7 {dict values command} {lsort [dict values {a b c d ca da} d*]} {d da}
191 test dict-7.8 {dict values command} -returnCodes error -body {
193 } -result {wrong # args: should be "dict values dictionary ?pattern?"}
194 test dict-7.9 {dict values command} -returnCodes error -body {
196 } -result {wrong # args: should be "dict values dictionary ?pattern?"}
197 test dict-7.10 {dict values command} -returnCodes error -body {
199 } -result {missing value to go with key}
200 test dict-7.11 {dict values with duplicate values} {dict values {a b c b} b} {b b}
202 test dict-8.1 {dict size command} {dict size {}} 0
203 test dict-8.2 {dict size command} {dict size {a b}} 1
204 test dict-8.3 {dict size command} {dict size {a b c d}} 2
205 test dict-8.4 {dict size command} -returnCodes error -body {
207 } -result {wrong # args: should be "dict size dictionary"}
208 test dict-8.5 {dict size command} -returnCodes error -body {
210 } -result {wrong # args: should be "dict size dictionary"}
211 test dict-8.6 {dict size command} -returnCodes error -body {
213 } -result {missing value to go with key}
215 test dict-9.1 {dict exists command} {dict exists {a b} a} 1
216 test dict-9.2 {dict exists command} {dict exists {a b} b} 0
217 test dict-9.3 {dict exists command} {dict exists {a {b c}} a b} 1
218 test dict-9.4 {dict exists command} {dict exists {a {b c}} a c} 0
219 test dict-9.5 {dict exists command} {dict exists {a {b c}} b c} 0
220 test dict-9.6 {dict exists command} -returnCodes error -body {
221 dict exists {a {b c d}} a c
222 } -result {missing value to go with key}
223 test dict-9.7 {dict exists command} -returnCodes error -body {
225 } -result {wrong # args: should be "dict exists dictionary key ?key ...?"}
226 test dict-9.8 {dict exists command} -returnCodes error -body {
228 } -result {wrong # args: should be "dict exists dictionary key ?key ...?"}
230 #test dict-10.1 {dict info command} -body {
231 # # Actual string returned by this command is undefined; it is
232 # # intended for human consumption and not for use by scripts.
234 #} -match glob -result *
235 #test dict-10.2 {dict info command} -returnCodes error -body {
237 #} -result {wrong # args: should be "dict info dictionary"}
238 #test dict-10.3 {dict info command} -returnCodes error -body {
240 #} -result {wrong # args: should be "dict info dictionary"}
241 #test dict-10.4 {dict info command} -returnCodes error -body {
243 #} -result {missing value to go with key}
245 test dict-11.1 {dict incr command: unshared value} -body {
246 set dictv [dict create \
247 a [string index "=0=" 1] \
249 c [expr {0x80000000+1}]]
254 } -result {a 1 b 3 c 2147483649}
255 test dict-11.2 {dict incr command: unshared value} -body {
256 set dictv [dict create \
257 a [string index "=0=" 1] \
259 c [expr {0x80000000+1}]]
264 } -result {a 0 b 4 c 2147483649}
265 test dict-11.3 {dict incr command: unshared value} -body {
266 set dictv [dict create \
267 a [string index "=0=" 1] \
269 c [expr {0x80000000+1}]]
274 } -result {a 0 b 3 c 2147483650}
275 test dict-11.4 {dict incr command: shared value} -body {
276 set dictv [dict create a 0 b [expr {1+2}] c [expr {0x80000000+1}]]
277 set sharing [dict values $dictv]
282 } -result {a 1 b 3 c 2147483649}
283 test dict-11.5 {dict incr command: shared value} -body {
284 set dictv [dict create a 0 b [expr {1+2}] c [expr {0x80000000+1}]]
285 set sharing [dict values $dictv]
290 } -result {a 0 b 4 c 2147483649}
291 test dict-11.6 {dict incr command: shared value} -body {
292 set dictv [dict create a 0 b [expr {1+2}] c [expr {0x80000000+1}]]
293 set sharing [dict values $dictv]
298 } -result {a 0 b 3 c 2147483650}
299 test dict-11.7 {dict incr command: unknown values} -body {
300 set dictv [dict create a 0 b [expr {1+2}] c [expr {0x80000000+1}]]
305 } -result {a 0 b 3 c 2147483649 d 1}
306 test dict-11.8 {dict incr command} -body {
313 test dict-11.9 {dict incr command} -returnCodes error -body {
319 } -result {expected integer but got "dummy"}
320 test dict-11.10 {dict incr command} -returnCodes error -body {
322 dict incr dictv a dummy
326 } -result {expected integer but got "dummy"}
327 test dict-11.11 {dict incr command} -setup {
328 unset -nocomplain dictv
335 test dict-11.12 {dict incr command} -returnCodes error -body {
341 } -result {missing value to go with key}
342 test dict-11.13 {dict incr command} -returnCodes error -body {
344 dict incr dictv a a a
348 } -result {wrong # args: should be "dict incr varName key ?increment?"}
349 test dict-11.14 {dict incr command} -returnCodes error -body {
355 } -result {wrong # args: should be "dict incr varName key ?increment?"}
356 test dict-11.15 {dict incr command: write failure} -setup {
357 unset -nocomplain dictVar
362 } -returnCodes error -cleanup {
364 } -result {missing value to go with key}
365 test dict-11.16 {dict incr command: compilation} {
372 list [dict get $v a] [dict get $v b] [dict get $v c] [dict get $v d]
375 test dict-11.17 {dict incr command: compilation} {
383 test dict-12.1 {dict lappend command} -body {
389 test dict-12.2 {dict lappend command} -body {
391 set sharing [dict values $dictv]
392 dict lappend dictv a b
397 test dict-12.3 {dict lappend command} -body {
399 dict lappend dictv a b c
403 } -result {a {a b c}}
404 test dict-12.2.1 {dict lappend command} -body {
405 set dictv [dict create a [string index =a= 1]]
406 dict lappend dictv a b
411 test dict-12.4 {dict lappend command} -body {
413 dict lappend dictv a x y z
417 } -result {a {x y z}}
418 test dict-12.5 {dict lappend command} -body {
419 unset -nocomplain dictv
420 dict lappend dictv a b
425 test dict-12.6 {dict lappend command} -returnCodes error -body {
427 dict lappend dictv a a
431 } -result {missing value to go with key}
432 test dict-12.7 {dict lappend command} -returnCodes error -body {
434 } -result {wrong # args: should be "dict lappend varName key ?value ...?"}
435 test dict-12.8 {dict lappend command} -returnCodes error -body {
437 } -result {wrong # args: should be "dict lappend varName key ?value ...?"}
438 test dict-12.9 {dict lappend command} -returnCodes error -constraints tcl -body {
439 set dictv [dict create a "\{"]
440 dict lappend dictv a a
443 } -result {unmatched open brace in list}
444 test dict-12.10 {dict lappend command: write failure} -setup {
445 unset -nocomplain dictVar
448 dict lappend dictVar a x
449 } -returnCodes error -cleanup {
451 } -result {missing value to go with key}
452 test dict-12.11 {compiled dict append: invalidate string rep - Bug 3079830} {
453 dict-sort [apply {{} {set d {a 1 b 2 c 3}; dict lappend d b 22}}]
456 test dict-13.1 {dict append command} -body {
462 test dict-13.2 {dict append command} -body {
464 set sharing [dict values $dictv]
465 dict append dictv a b
469 test dict-13.3 {dict append command} -body {
471 dict append dictv a b c
475 test dict-13.2.1 {dict append command} -body {
476 set dictv [dict create a [string index =a= 1]]
477 dict append dictv a b
481 test dict-13.4 {dict append command} -body {
483 dict append dictv a x y z
487 test dict-13.5 {dict append command} -body {
488 unset -nocomplain dictv
489 dict append dictv a b
493 test dict-13.6 {dict append command} -returnCodes error -body {
495 dict append dictv a a
498 } -result {missing value to go with key}
499 test dict-13.7 {dict append command} -returnCodes error -body {
501 } -result {wrong # args: should be "dict append varName key ?value ...?"}
502 test dict-13.8 {dict append command} -returnCodes error -body {
504 } -result {wrong # args: should be "dict append varName key ?value ...?"}
505 test dict-13.9 {dict append command: write failure} -setup {
506 unset -nocomplain dictVar
509 dict append dictVar a x
510 } -returnCodes error -cleanup {
512 } -result {missing value to go with key}
513 test dict-13.10 {compiled dict append: crash case} {
514 apply {{} {dict append dictVar a o k}}
516 test dict-13.11 {compiled dict append: invalidate string rep - Bug 3079830} {
517 dict-sort [apply {{} {set d {a 1 b 2 c 3}; dict append d b 22}}]
520 test dict-14.1 {dict for command: syntax} -returnCodes error -body {
522 } -match glob -result {wrong # args: should be *}
523 test dict-14.2 {dict for command: syntax} -returnCodes error -body {
525 } -match glob -result {wrong # args: should be *}
526 test dict-14.3 {dict for command: syntax} -returnCodes error -body {
528 } -match glob -result {wrong # args: should be *}
529 test dict-14.4 {dict for command: syntax} -returnCodes error -body {
531 } -match glob -result {wrong # args: should be *}
532 test dict-14.5 {dict for command: syntax} -returnCodes error -body {
534 } -result {must have exactly two variable names}
535 test dict-14.6 {dict for command: syntax} -returnCodes error -body {
537 } -result {must have exactly two variable names}
538 test dict-14.7 {dict for command: syntax} -returnCodes error -constraints tcl -body {
540 } -result {unmatched open brace in list}
541 test dict-14.8 {dict for command} -constraints tcl -body {
542 # This test confirms that [dict keys], [dict values] and [dict for]
543 # all traverse a dictionary in the same order.
544 # Note that Jim Tcl does *not* preserver order
545 set dictv {a A b B c C}
548 dict for {k v} $dictv {
553 $keys eq [dict keys $dictv] && $values eq [dict values $dictv]
555 expr {$result ? "YES" : [list "NO" $dictv $keys $values]}
557 unset result keys values k v dictv
559 test dict-14.9 {dict for command} {
561 error "unexpected execution of 'dict for' body"
564 test dict-14.10 {dict for command: script results} -body {
566 dict for {k v} {a a b b} {
569 error "shouldn't get here"
575 test dict-14.11 {dict for command: script results} -body {
577 dict for {k v} {a a b b} {
580 error "shouldn't get here"
586 test dict-14.12 {dict for command: script results} -body {
589 dict for {k v} {a a b b} {
597 test dict-14.13 {dict for command: script results} {
599 dict for {k v} {a b} {
601 error "skipped return completely"
603 error "return didn't go far enough"
606 test dict-14.14 {dict for command: handle representation loss} -body {
607 set dictVar {a b c d e f g h}
610 dict for {k v} $dictVar {
611 if {[llength $dictVar]} {
616 list [lsort $keys] [lsort $values]
618 unset dictVar keys values k v
619 } -result {{a c e g} {b d f h}}
620 test dict-14.15 {dict for command: keys are unique and iterated over once only} -setup {
621 unset -nocomplain accum
624 set dictVar {a1 a a2 b b1 c b2 d foo bar bar foo}
625 dict for {k v} $dictVar {
628 set result [lsort [array names accum]]
631 catch {lappend result $accum($k)}
635 unset dictVar k v result accum
636 } -result {a1 a2 b1 b2 bar foo : a, b, c, d, foo, bar,}
637 test dict-14.16 {dict for command in compilation context} {
639 set res {x x x x x x}
640 dict for {k v} {a 0 b 1 c 2 d 3 e 4 f 5} {
647 test dict-14.17 {dict for command in compilation context} {
650 set d [dict create a 1] ;# Dict must be unshared!
652 dict set d $k 0 ;# Any modification will do
657 test dict-14.18 {dict for command in compilation context} {
660 dict for {k v} {} {} ;# Note empty dict
661 catch { error foo } ;# Note compiled [catch]
664 test dict-14.19 {dict for and invalid dicts: bug 1531184} -body {
665 di[list]ct for {k v} x {}
666 } -returnCodes 1 -result {missing value to go with key}
667 test dict-14.20 {dict for stack space compilation: bug 1903325} {
673 # There's probably a lot more tests to add here. Really ought to use a
674 # coverage tool for this job...
676 test dict-15.1 {dict set command} -body {
682 test dict-15.2 {dict set command} -body {
684 dict set dictvar a b x
688 test dict-15.3 {dict set command} -body {
689 set dictvar {a {b {}}}
690 dict set dictvar a b c x
693 } -result {a {b {c x}}}
694 test dict-15.4 {dict set command} -body {
700 test dict-15.5 {dict set command} -body {
701 set dictVar {a {b y}}
702 dict set dictVar a b x
706 test dict-15.6 {dict set command} -body {
707 set dictVar {a {b {c y}}}
708 dict set dictVar a b c x
711 } -result {a {b {c x}}}
712 test dict-15.7 {dict set command: path creation} -body {
714 dict set dictVar a b x
718 test dict-15.8 {dict set command: creates variables} -setup {
719 unset -nocomplain dictVar
726 test dict-15.9 {dict set command: write failure} -setup {
727 unset -nocomplain dictVar
731 } -returnCodes error -cleanup {
733 } -result {missing value to go with key}
734 test dict-15.10 {dict set command: syntax} -returnCodes error -body {
736 } -result {wrong # args: should be "dict set varName key ?key ...? value"}
737 test dict-15.11 {dict set command: syntax} -returnCodes error -body {
739 } -result {wrong # args: should be "dict set varName key ?key ...? value"}
740 test dict-15.12 {dict set command: syntax} -returnCodes error -body {
742 } -result {wrong # args: should be "dict set varName key ?key ...? value"}
743 test dict-15.13 {dict set command} -returnCodes error -body {
748 } -result {missing value to go with key}
750 test dict-16.1 {dict unset command} -body {
751 set dictVar {a b c d}
756 test dict-16.2 {dict unset command} -body {
757 set dictVar {a b c d}
762 test dict-16.3 {dict unset command} -body {
768 test dict-16.4 {dict unset command} -body {
769 set dictVar {a {b c d e}}
770 dict unset dictVar a b
774 test dict-16.5 {dict unset command} -returnCodes error -body {
779 } -result {missing value to go with key}
780 test dict-16.6 {dict unset command} -returnCodes error -body {
782 dict unset dictVar c d
785 } -result {key "c" not known in dictionary}
786 test dict-16.7 {dict unset command} -setup {
787 unset -nocomplain dictVar
789 list [info exists dictVar] [dict unset dictVar a] [info exists dictVar]
793 test dict-16.8 {dict unset command} -returnCodes error -body {
795 } -result {wrong # args: should be "dict unset varName key ?key ...?"}
796 test dict-16.9 {dict unset command: write failure} -setup {
797 unset -nocomplain dictVar
801 } -returnCodes error -cleanup {
803 } -result {missing value to go with key}
805 #test dict-17.1 {dict filter command: key} -body {
806 # set dictVar {a1 a a2 b b1 c b2 d foo bar bar foo}
807 # dict filter $dictVar key a2
811 #test dict-17.2 {dict filter command: key} -body {
812 # set dictVar {a1 a a2 b b1 c b2 d foo bar bar foo}
813 # dict size [dict filter $dictVar key *]
817 #test dict-17.3 {dict filter command: key} -body {
818 # set dictVar {a1 a a2 b b1 c b2 d foo bar bar foo}
819 # dict filter $dictVar key ???
822 #} -result {foo bar bar foo}
823 #test dict-17.4 {dict filter command: key - no patterns} {
824 # dict filter {a b c d} key
826 #test dict-17.4.1 {dict filter command: key - many patterns} {
827 # dict filter {a1 a a2 b b1 c b2 d foo bar bar foo} key a? b?
828 #} {a1 a a2 b b1 c b2 d}
829 #test dict-17.5 {dict filter command: key - bad dict} -returnCodes error -body {
830 # dict filter {a b c} key
831 #} -result {missing value to go with key}
832 #test dict-17.6 {dict filter command: value} -body {
833 # set dictVar {a1 a a2 b b1 c b2 d foo bar bar foo}
834 # dict filter $dictVar value c
838 #test dict-17.7 {dict filter command: value} -body {
839 # set dictVar {a1 a a2 b b1 c b2 d foo bar bar foo}
840 # dict size [dict filter $dictVar value *]
844 #test dict-17.8 {dict filter command: value} -body {
845 # set dictVar {a1 a a2 b b1 c b2 d foo bar bar foo}
846 # dict filter $dictVar value ???
849 #} -result {foo bar bar foo}
850 #test dict-17.9 {dict filter command: value - no patterns} {
851 # dict filter {a b c d} value
853 #test dict-17.9.1 {dict filter command: value - many patterns} {
854 # dict filter {a a1 b a2 c b1 foo bar bar foo d b2} value a? b?
855 #} {a a1 b a2 c b1 d b2}
856 #test dict-17.10 {dict filter command: value - bad dict} -body {
857 # dict filter {a b c} value a
858 #} -returnCodes error -result {missing value to go with key}
859 #test dict-17.11 {dict filter command: script} -body {
860 # set dictVar {a1 a a2 b b1 c b2 d foo bar bar foo}
862 # list [dict filter $dictVar script {k v} {
864 # expr {[string length $k] == [string length $v]}
867 # unset dictVar n k v
868 #} -result {{foo bar bar foo} 6}
869 #test dict-17.12 {dict filter command: script} -returnCodes error -body {
870 # dict filter {a b} script {k v} {
875 #} -result {expected boolean value but got "a b"}
876 #test dict-17.13 {dict filter command: script} -body {
877 # list [catch {dict filter {a b} script {k v} {error x}} msg] $msg \
884 # ("dict filter" script line 1)
885 # invoked from within
886 #"dict filter {a b} script {k v} {error x}"}}
887 #test dict-17.14 {dict filter command: script} -setup {
890 # list [dict filter {a b c d} script {k v} {
898 #test dict-17.15 {dict filter command: script} -setup {
901 # list [dict filter {a b c d} script {k v} {
909 #test dict-17.16 {dict filter command: script} {
911 # dict filter {a b} script {k v} {
913 # error "skipped return completely"
915 # error "return didn't go far enough"
918 #test dict-17.17 {dict filter command: script} -body {
919 # dict filter {a b} script {k k} {continue}
924 #test dict-17.18 {dict filter command: script} -returnCodes error -body {
925 # dict filter {a b} script {k k}
926 #} -result {wrong # args: should be "dict filter dictionary script {keyVar valueVar} filterScript"}
927 #test dict-17.19 {dict filter command: script} -returnCodes error -body {
928 # dict filter {a b} script k {continue}
929 #} -result {must have exactly two variable names}
930 #test dict-17.20 {dict filter command: script} -returnCodes error -body {
931 # dict filter {a b} script "\{k v" {continue}
932 #} -result {unmatched open brace in list}
933 #test dict-17.21 {dict filter command} -returnCodes error -body {
935 #} -result {wrong # args: should be "dict filter dictionary filterType ?arg ...?"}
936 #test dict-17.22 {dict filter command} -returnCodes error -body {
937 # dict filter {a b} JUNK
938 #} -result {bad filterType "JUNK": must be key, script, or value}
939 #test dict-17.23 {dict filter command} -returnCodes error -body {
940 # dict filter a key *
941 #} -result {missing value to go with key}
943 test dict-18.1 {dict-list relationship} -body {
944 # Test that any internal conversion between list and dict does not change
946 set l [list 1 2 3 4 5 6 7 8 9 0 q w e r t y]
951 } -result {1 2 3 4 5 6 7 8 9 0 q w e r t y}
952 test dict-18.2 {dict-list relationship} -body {
953 # Test that the dictionary is a valid list
954 set d [dict create "abc def" 0 "a\{b" 1 "c\}d" 2]
955 for {set t 0} {$t < 5} {incr t} {
957 dict lappend d "abc def" "\}\{"
958 dict append d "a\{b" "\}"
965 test dict-18.3 {dict-list relationship} -body {
966 set ld [list a b c d c e f g]
967 list [string length $ld] [dict size $ld] [llength $ld]
971 test dict-18.4 {dict-list relationship} -body {
972 set ld [list a b c d c e f g]
973 list [llength $ld] [dict size $ld] [llength $ld]
978 test dict-20.1 {dict merge command} {
981 test dict-20.2 {dict merge command} {
982 dict-sort [dict merge {a b c d e f}]
984 test dict-20.3 {dict merge command} -body {
985 dict-sort [dict merge {a b c d e}]
986 } -result {missing value to go with key} -returnCodes error
987 test dict-20.4 {dict merge command} {
988 dict-sort [dict merge {a b c d} {e f g h}]
990 test dict-20.5 {dict merge command} -body {
991 dict-sort [dict merge {a b c d e} {e f g h}]
992 } -result {missing value to go with key} -returnCodes error
993 test dict-20.6 {dict merge command} -body {
994 dict-sort [dict merge {a b c d} {e f g h i}]
995 } -result {missing value to go with key} -returnCodes error
996 test dict-20.7 {dict merge command} {
997 dict-sort [dict merge {a b c d e f} {e x g h}]
999 test dict-20.8 {dict merge command} {
1000 dict-sort [dict merge {a b c d} {a x c y}]
1002 test dict-20.9 {dict merge command} {
1003 dict-sort [dict merge {a b c d} {c y a x}]
1005 test dict-20.10 {dict merge command} {
1006 dict-sort [dict merge {a b c d e f} {a x 1 2 3 4} {a - 1 -}]
1007 } {1 - 3 4 a - c d e f}
1009 test dict-21.1 {dict update command} -returnCodes 1 -body {
1011 } -match glob -result {wrong # args: should be "dict update varName * script"}
1012 test dict-21.2 {dict update command} -returnCodes 1 -body {
1014 } -match glob -result {wrong # args: should be "dict update varName * script"}
1015 test dict-21.3 {dict update command} -returnCodes 1 -body {
1017 } -match glob -result {wrong # args: should be "dict update varName * script"}
1018 test dict-21.4 {dict update command} -returnCodes 1 -body {
1020 } -match glob -result {wrong # args: should be "dict update varName * script"}
1021 test dict-21.5 {dict update command} -body {
1025 dict update a b bb {
1026 lappend result $a $bb
1031 } -result {{b c} c {b c}}
1032 test dict-21.6 {dict update command} -body {
1036 dict update a b bb {
1037 lappend result $a $bb [set bb d]
1042 } -result {{b c} c d {b d}}
1043 test dict-21.7 {dict update command} -body {
1047 dict update a b bb {
1048 lappend result $a $bb [unset bb]
1053 } -result {{b c} c {} {}}
1054 test dict-21.8 {dict update command} -body {
1056 dict update a b v1 d v2 {
1057 lassign "$v1 $v2" v2 v1
1063 test dict-21.9 {dict update command} -body {
1065 dict update a b v1 d v2 {unset a}
1070 test dict-21.10 {dict update command} -body {
1072 dict update a b v1 {
1073 dict update v1 c v2 {
1080 } -result {b {c foo}}
1081 test dict-21.11 {dict update command} -body {
1083 dict update a b v1 d v2 {
1089 } -result {b c d e f g}
1090 test dict-21.12 {dict update command} -body {
1092 dict update a b v1 d v2 f v3 {
1098 } -result {b c d e f g}
1099 test dict-21.13 {dict update command: compilation} {
1102 dict update d a alpha b beta {
1111 test dict-21.14 {dict update command: compilation} tcl {
1114 trace add variable aa write "string length \$indices ;#"
1115 dict update x k aa l bb {}
1118 test dict-21.15 {dict update command: compilation} tcl {
1121 trace add variable aa read "string length \$indices ;#"
1122 dict update x k aa l bb {}
1125 test dict-21.16 {dict update command: no recursive structures [Bug 1786481]} -body {
1126 set foo {a {b {c {d {e 1}}}}}
1127 dict update foo a t {
1136 string range [append foo OK] end-1 end
1140 test dict-21.17 {dict update command: no recursive structures [Bug 1786481]} {
1142 set foo {a {b {c {d {e 1}}}}}
1143 dict update foo a t {
1152 string range [append foo OK] end-1 end
1156 test dict-22.1 {dict with command} -body {
1158 } -returnCodes 1 -result {wrong # args: should be "dict with dictVar ?key ...? script"}
1159 test dict-22.2 {dict with command} -body {
1161 } -returnCodes 1 -result {wrong # args: should be "dict with dictVar ?key ...? script"}
1162 test dict-22.3 {dict with command} -body {
1164 dict with v {error "in body"}
1165 } -returnCodes 1 -result {can't read "v": no such variable}
1166 test dict-22.4 {dict with command} -body {
1168 unset -nocomplain b d
1169 set result [list [info exist b] [info exist d]]
1171 lappend result [info exist b] [info exist d] $b $d
1176 } -result {0 0 1 1 c e}
1177 test dict-22.5 {dict with command} -body {
1186 test dict-22.6 {dict with command} -body {
1190 # This *won't* go into the dict...
1197 test dict-22.7 {dict with command} -body {
1202 return [dict-sort $a]
1206 test dict-22.8 {dict with command} -body {
1207 set a [dict create b c]
1215 test dict-22.9 {dict with command} -body {
1223 } -result {b {c dd}}
1224 test dict-22.10 {dict with command: result handling tricky case} -body {
1230 # We're checking to see if we lose this break
1238 test dict-22.11 {dict with command: no recursive structures [Bug 1786481]} -body {
1239 set foo {t {t {t {inner 1}}}}
1249 string range [append foo OK] end-1 end
1254 set dictnulls {ab\0c de\0f \0ghi kl\0m}
1255 set dictgood [array get tcl_platform]
1256 set dictbad {abc def ghi}
1258 test dict-23.1 {dict info} {
1259 regexp {entries in table,.*buckets} [dict info $dictgood]
1262 test dict-23.2 {dict info usage} -body {
1264 } -returnCodes error -result {wrong # args: should be "dict info dictionary"}
1266 test dict-23.3 {dict info baddict} -body {
1268 } -returnCodes error -result {missing value to go with key}
1270 test dict-23.4 {dict with usage} -body {
1272 } -returnCodes error -result {wrong # args: should be "dict with dictVar ?key ...? script"}
1274 test dict-23.5 {dict with badvar} -constraints jim -body {
1275 dict with dictnulls {lsort [info locals]}
1276 } -returnCodes ok -result [list ab\0c de\0f \0ghi kl\0m]
1278 test dict-23.6 {dict with baddict} -body {
1279 dict with dictbad {}
1280 } -returnCodes error -result {missing value to go with key}