| 1 |
# This test file covers the dictionary object type and the dict command used |
| 2 |
# to work with values of that type. |
| 3 |
# |
| 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. |
| 7 |
# |
| 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. |
| 11 |
|
| 12 |
if {"::tcltest" ni [namespace children]} { |
| 13 |
package require tcltest 2.5 |
| 14 |
namespace import -force ::tcltest::* |
| 15 |
} |
| 16 |
|
| 17 |
# Used for constraining memory leak tests |
| 18 |
testConstraint memory [llength [info commands memory]] |
| 19 |
if {[testConstraint memory]} { |
| 20 |
proc memtest script { |
| 21 |
set end [lindex [split [memory info] \n] 3 3] |
| 22 |
for {set i 0} {$i < 5} {incr i} { |
| 23 |
uplevel 1 $script |
| 24 |
set tmp $end |
| 25 |
set end [lindex [split [memory info] \n] 3 3] |
| 26 |
} |
| 27 |
expr {$end - $tmp} |
| 28 |
} |
| 29 |
} |
| 30 |
|
| 31 |
test dict-1.1 {dict command basic syntax} -returnCodes error -body { |
| 32 |
dict |
| 33 |
} -result {wrong # args: should be "dict subcommand ?arg ...?"} |
| 34 |
test dict-1.2 {dict command basic syntax} -returnCodes error -body { |
| 35 |
dict ? |
| 36 |
} -match glob -result {unknown or ambiguous subcommand "?": must be *} |
| 37 |
|
| 38 |
test dict-2.1 {dict create command} { |
| 39 |
dict create |
| 40 |
} {} |
| 41 |
test dict-2.2 {dict create command} { |
| 42 |
dict create a b |
| 43 |
} {a b} |
| 44 |
test dict-2.3 {dict create command} -body { |
| 45 |
set result {} |
| 46 |
set dict [dict create a b c d] |
| 47 |
# Can't compare directly as ordering of values is undefined |
| 48 |
foreach key {a c} { |
| 49 |
set idx [lsearch -exact $dict $key] |
| 50 |
if {$idx & 1} { |
| 51 |
error "found $key at odd index $idx in $dict" |
| 52 |
} |
| 53 |
lappend result [lindex $dict [expr {$idx+1}]] |
| 54 |
} |
| 55 |
return $result |
| 56 |
} -cleanup { |
| 57 |
unset result dict key idx |
| 58 |
} -result {b d} |
| 59 |
test dict-2.4 {dict create command} -returnCodes error -body { |
| 60 |
dict create a |
| 61 |
} -result {wrong # args: should be "dict create ?key value ...?"} |
| 62 |
test dict-2.5 {dict create command} -returnCodes error -body { |
| 63 |
dict create a b c |
| 64 |
} -result {wrong # args: should be "dict create ?key value ...?"} |
| 65 |
test dict-2.6 {dict create command - initialse refcount field!} -body { |
| 66 |
# Bug 715751 will show up in memory debuggers like purify |
| 67 |
for {set i 0} {$i<10} {incr i} { |
| 68 |
set dictv [dict create a 0] |
| 69 |
set share [dict values $dictv] |
| 70 |
list [dict incr dictv a] |
| 71 |
} |
| 72 |
} -cleanup { |
| 73 |
unset i dictv share |
| 74 |
} -result {} |
| 75 |
test dict-2.7 {dict create command - #-quoting in string rep} { |
| 76 |
dict create # #comment |
| 77 |
} {{#} #comment} |
| 78 |
test dict-2.8 {dict create command - #-quoting in string rep} -body { |
| 79 |
dict create #a x #b x |
| 80 |
} -match glob -result {{#?} x #? x} |
| 81 |
test dict-2.9 {dict create command: compilation} { |
| 82 |
apply {{} {dict create [format a] b}} |
| 83 |
} {a b} |
| 84 |
test dict-2.10 {dict create command: compilation} { |
| 85 |
apply {{} {dict create [format a] b c d}} |
| 86 |
} {a b c d} |
| 87 |
test dict-2.11 {dict create command: compilation} { |
| 88 |
apply {{} {dict create [format a] b c d a x}} |
| 89 |
} {a x c d} |
| 90 |
test dict-2.12 {dict create command: non-compilation} { |
| 91 |
dict create [format a] b |
| 92 |
} {a b} |
| 93 |
test dict-2.13 {dict create command: non-compilation} { |
| 94 |
dict create [format a] b c d |
| 95 |
} {a b c d} |
| 96 |
test dict-2.14 {dict create command: non-compilation} { |
| 97 |
dict create [format a] b c d a x |
| 98 |
} {a x c d} |
| 99 |
|
| 100 |
test dict-3.1 {dict get command} {dict get {a b} a} b |
| 101 |
test dict-3.2 {dict get command} {dict get {a b c d} a} b |
| 102 |
test dict-3.3 {dict get command} {dict get {a b c d} c} d |
| 103 |
test dict-3.4 {dict get command} -returnCodes error -body { |
| 104 |
dict get {a b c d} b |
| 105 |
} -result {key "b" not known in dictionary} |
| 106 |
test dict-3.5 {dict get command} {dict get {a {p q r s} b {u v x y}} a p} q |
| 107 |
test dict-3.6 {dict get command} {dict get {a {p q r s} b {u v x y}} a r} s |
| 108 |
test dict-3.7 {dict get command} {dict get {a {p q r s} b {u v x y}} b u} v |
| 109 |
test dict-3.8 {dict get command} {dict get {a {p q r s} b {u v x y}} b x} y |
| 110 |
test dict-3.9 {dict get command} -returnCodes error -body { |
| 111 |
dict get {a {p q r s} b {u v x y}} a z |
| 112 |
} -result {key "z" not known in dictionary} |
| 113 |
test dict-3.10 {dict get command} -returnCodes error -body { |
| 114 |
dict get {a {p q r s} b {u v x y}} c z |
| 115 |
} -result {key "c" not known in dictionary} |
| 116 |
test dict-3.11 {dict get command} {dict get [dict create a b c d] a} b |
| 117 |
test dict-3.12 {dict get command} -returnCodes error -body { |
| 118 |
dict get |
| 119 |
} -result {wrong # args: should be "dict get dictionary ?key ...?"} |
| 120 |
test dict-3.13 {dict get command} -body { |
| 121 |
set dict [dict get {a b c d}] |
| 122 |
if {$dict eq "a b c d"} { |
| 123 |
return OK |
| 124 |
} elseif {$dict eq "c d a b"} { |
| 125 |
return reordered |
| 126 |
} else { |
| 127 |
return $dict |
| 128 |
} |
| 129 |
} -cleanup { |
| 130 |
unset dict |
| 131 |
} -result OK |
| 132 |
test dict-3.14 {dict get command} -returnCodes error -body { |
| 133 |
dict get {a b c d} a c |
| 134 |
} -result {missing value to go with key} |
| 135 |
test dict-3.15 {compiled dict get error cleanliness - Bug 2431847} -body { |
| 136 |
apply {{} { |
| 137 |
dict set a(z) b c |
| 138 |
dict get $a(z) d |
| 139 |
}} |
| 140 |
} -returnCodes error -result {key "d" not known in dictionary} |
| 141 |
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} |
| 142 |
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 |
| 143 |
|
| 144 |
test dict-4.1 {dict replace command} { |
| 145 |
dict replace {a b c d} |
| 146 |
} {a b c d} |
| 147 |
test dict-4.2 {dict replace command} { |
| 148 |
dict replace {a b c d} e f |
| 149 |
} {a b c d e f} |
| 150 |
test dict-4.3 {dict replace command} { |
| 151 |
dict replace {a b c d} c f |
| 152 |
} {a b c f} |
| 153 |
test dict-4.4 {dict replace command} { |
| 154 |
dict replace {a b c d} c x a y |
| 155 |
} {a y c x} |
| 156 |
test dict-4.5 {dict replace command} -returnCodes error -body { |
| 157 |
dict replace |
| 158 |
} -result {wrong # args: should be "dict replace dictionary ?key value ...?"} |
| 159 |
test dict-4.6 {dict replace command} -returnCodes error -body { |
| 160 |
dict replace {a a} a |
| 161 |
} -result {wrong # args: should be "dict replace dictionary ?key value ...?"} |
| 162 |
test dict-4.7 {dict replace command} -returnCodes error -body { |
| 163 |
dict replace {a a a} a b |
| 164 |
} -result {missing value to go with key} |
| 165 |
test dict-4.8 {dict replace command} -returnCodes error -body { |
| 166 |
dict replace [list a a a] a b |
| 167 |
} -result {missing value to go with key} |
| 168 |
test dict-4.9 {dict replace command} {dict replace [list a a] a b} {a b} |
| 169 |
test dict-4.10 {dict replace command} {dict replace [list a a] a b a c} {a c} |
| 170 |
test dict-4.11 {dict replace command: canonicality is forced} { |
| 171 |
dict replace { a b c d } |
| 172 |
} {a b c d} |
| 173 |
test dict-4.12 {dict replace command: canonicality is forced} { |
| 174 |
dict replace {a b c d a e} |
| 175 |
} {a e c d} |
| 176 |
test dict-4.13 {dict replace command: type check is mandatory} -body { |
| 177 |
dict replace { a b c d e } |
| 178 |
} -returnCodes error -result {missing value to go with key} |
| 179 |
test dict-4.13a {dict replace command: type check is mandatory} { |
| 180 |
catch {dict replace { a b c d e }} -> opt |
| 181 |
dict get $opt -errorcode |
| 182 |
} {TCL VALUE DICTIONARY} |
| 183 |
test dict-4.14 {dict replace command: type check is mandatory} -body { |
| 184 |
dict replace { a b {}c d } |
| 185 |
} -returnCodes error -result {dict element in braces followed by "c" instead of space} |
| 186 |
test dict-4.14a {dict replace command: type check is mandatory} { |
| 187 |
catch {dict replace { a b {}c d }} -> opt |
| 188 |
dict get $opt -errorcode |
| 189 |
} {TCL VALUE DICTIONARY JUNK} |
| 190 |
test dict-4.15 {dict replace command: type check is mandatory} -body { |
| 191 |
dict replace { a b ""c d } |
| 192 |
} -returnCodes error -result {dict element in quotes followed by "c" instead of space} |
| 193 |
test dict-4.15a {dict replace command: type check is mandatory} { |
| 194 |
catch {dict replace { a b ""c d }} -> opt |
| 195 |
dict get $opt -errorcode |
| 196 |
} {TCL VALUE DICTIONARY JUNK} |
| 197 |
test dict-4.16 {dict replace command: type check is mandatory} -body { |
| 198 |
dict replace " a b \"c d " |
| 199 |
} -returnCodes error -result {unmatched open quote in dict} |
| 200 |
test dict-4.16a {dict replace command: type check is mandatory} { |
| 201 |
catch {dict replace " a b \"c d "} -> opt |
| 202 |
dict get $opt -errorcode |
| 203 |
} {TCL VALUE DICTIONARY QUOTE} |
| 204 |
test dict-4.17 {dict replace command: type check is mandatory} -body { |
| 205 |
dict replace " a b \{c d " |
| 206 |
} -returnCodes error -result {unmatched open brace in dict} |
| 207 |
test dict-4.17a {dict replace command: type check is mandatory} { |
| 208 |
catch {dict replace " a b \{c d "} -> opt |
| 209 |
dict get $opt -errorcode |
| 210 |
} {TCL VALUE DICTIONARY BRACE} |
| 211 |
test dict-4.18 {dict replace command: canonicality forcing doesn't leak} { |
| 212 |
set example { a b c d } |
| 213 |
list $example [dict replace $example] |
| 214 |
} {{ a b c d } {a b c d}} |
| 215 |
|
| 216 |
test dict-5.1 {dict remove command} {dict remove {a b c d} a} {c d} |
| 217 |
test dict-5.2 {dict remove command} {dict remove {a b c d} c} {a b} |
| 218 |
test dict-5.3 {dict remove command} {dict remove {a b c d} a c} {} |
| 219 |
test dict-5.4 {dict remove command} {dict remove {a b c d} c a} {} |
| 220 |
test dict-5.5 {dict remove command} { |
| 221 |
dict remove {a b c d} |
| 222 |
} {a b c d} |
| 223 |
test dict-5.6 {dict remove command} {dict remove {a b} c} {a b} |
| 224 |
test dict-5.7 {dict remove command} -returnCodes error -body { |
| 225 |
dict remove |
| 226 |
} -result {wrong # args: should be "dict remove dictionary ?key ...?"} |
| 227 |
test dict-5.8 {dict remove command: canonicality is forced} { |
| 228 |
dict remove { a b c d } |
| 229 |
} {a b c d} |
| 230 |
test dict-5.9 {dict remove command: canonicality is forced} { |
| 231 |
dict remove {a b c d a e} |
| 232 |
} {a e c d} |
| 233 |
test dict-5.10 {dict remove command: canonicality forced by update} { |
| 234 |
dict remove { a b c d } c |
| 235 |
} {a b} |
| 236 |
test dict-5.11 {dict remove command: type check is mandatory} -body { |
| 237 |
dict remove { a b c d e } |
| 238 |
} -returnCodes error -result {missing value to go with key} |
| 239 |
test dict-5.12 {dict remove command: type check is mandatory} -body { |
| 240 |
dict remove { a b {}c d } |
| 241 |
} -returnCodes error -result {dict element in braces followed by "c" instead of space} |
| 242 |
test dict-5.13 {dict remove command: canonicality forcing doesn't leak} { |
| 243 |
set example { a b c d } |
| 244 |
list $example [dict remove $example] |
| 245 |
} {{ a b c d } {a b c d}} |
| 246 |
|
| 247 |
test dict-6.1 {dict keys command} {dict keys {a b}} a |
| 248 |
test dict-6.2 {dict keys command} {dict keys {c d}} c |
| 249 |
test dict-6.3 {dict keys command} {lsort [dict keys {a b c d}]} {a c} |
| 250 |
test dict-6.4 {dict keys command} {dict keys {a b c d} a} a |
| 251 |
test dict-6.5 {dict keys command} {dict keys {a b c d} c} c |
| 252 |
test dict-6.6 {dict keys command} {dict keys {a b c d} e} {} |
| 253 |
test dict-6.7 {dict keys command} {lsort [dict keys {a b c d ca da} c*]} {c ca} |
| 254 |
test dict-6.8 {dict keys command} -returnCodes error -body { |
| 255 |
dict keys |
| 256 |
} -result {wrong # args: should be "dict keys dictionary ?pattern?"} |
| 257 |
test dict-6.9 {dict keys command} -returnCodes error -body { |
| 258 |
dict keys {} a b |
| 259 |
} -result {wrong # args: should be "dict keys dictionary ?pattern?"} |
| 260 |
test dict-6.10 {dict keys command} -returnCodes error -body { |
| 261 |
dict keys a |
| 262 |
} -result {missing value to go with key} |
| 263 |
|
| 264 |
test dict-7.1 {dict values command} {dict values {a b}} b |
| 265 |
test dict-7.2 {dict values command} {dict values {c d}} d |
| 266 |
test dict-7.3 {dict values command} {lsort [dict values {a b c d}]} {b d} |
| 267 |
test dict-7.4 {dict values command} {dict values {a b c d} b} b |
| 268 |
test dict-7.5 {dict values command} {dict values {a b c d} d} d |
| 269 |
test dict-7.6 {dict values command} {dict values {a b c d} e} {} |
| 270 |
test dict-7.7 {dict values command} {lsort [dict values {a b c d ca da} d*]} {d da} |
| 271 |
test dict-7.8 {dict values command} -returnCodes error -body { |
| 272 |
dict values |
| 273 |
} -result {wrong # args: should be "dict values dictionary ?pattern?"} |
| 274 |
test dict-7.9 {dict values command} -returnCodes error -body { |
| 275 |
dict values {} a b |
| 276 |
} -result {wrong # args: should be "dict values dictionary ?pattern?"} |
| 277 |
test dict-7.10 {dict values command} -returnCodes error -body { |
| 278 |
dict values a |
| 279 |
} -result {missing value to go with key} |
| 280 |
|
| 281 |
test dict-8.1 {dict size command} {dict size {}} 0 |
| 282 |
test dict-8.2 {dict size command} {dict size {a b}} 1 |
| 283 |
test dict-8.3 {dict size command} {dict size {a b c d}} 2 |
| 284 |
test dict-8.4 {dict size command} -returnCodes error -body { |
| 285 |
dict size |
| 286 |
} -result {wrong # args: should be "dict size dictionary"} |
| 287 |
test dict-8.5 {dict size command} -returnCodes error -body { |
| 288 |
dict size a b |
| 289 |
} -result {wrong # args: should be "dict size dictionary"} |
| 290 |
test dict-8.6 {dict size command} -returnCodes error -body { |
| 291 |
dict size a |
| 292 |
} -result {missing value to go with key} |
| 293 |
|
| 294 |
test dict-9.1 {dict exists command} {dict exists {a b} a} 1 |
| 295 |
test dict-9.2 {dict exists command} {dict exists {a b} b} 0 |
| 296 |
test dict-9.3 {dict exists command} {dict exists {a {b c}} a b} 1 |
| 297 |
test dict-9.4 {dict exists command} {dict exists {a {b c}} a c} 0 |
| 298 |
test dict-9.5 {dict exists command} {dict exists {a {b c}} b c} 0 |
| 299 |
test dict-9.6 {dict exists command} {dict exists {a {b c d}} a c} 0 |
| 300 |
test dict-9.7 {dict exists command} -returnCodes error -body { |
| 301 |
dict exists |
| 302 |
} -result {wrong # args: should be "dict exists dictionary key ?key ...?"} |
| 303 |
test dict-9.8 {dict exists command} -returnCodes error -body { |
| 304 |
dict exists {} |
| 305 |
} -result {wrong # args: should be "dict exists dictionary key ?key ...?"} |
| 306 |
|
| 307 |
test dict-10.1 {dict info command} -body { |
| 308 |
# Actual string returned by this command is undefined; it is |
| 309 |
# intended for human consumption and not for use by scripts. |
| 310 |
dict info {} |
| 311 |
} -match glob -result * |
| 312 |
test dict-10.2 {dict info command} -returnCodes error -body { |
| 313 |
dict info |
| 314 |
} -result {wrong # args: should be "dict info dictionary"} |
| 315 |
test dict-10.3 {dict info command} -returnCodes error -body { |
| 316 |
dict info {} x |
| 317 |
} -result {wrong # args: should be "dict info dictionary"} |
| 318 |
test dict-10.4 {dict info command} -returnCodes error -body { |
| 319 |
dict info x |
| 320 |
} -result {missing value to go with key} |
| 321 |
|
| 322 |
test dict-11.1 {dict incr command: unshared value} -body { |
| 323 |
set dictv [dict create \ |
| 324 |
a [string index "=0=" 1] \ |
| 325 |
b [expr {1+2}] \ |
| 326 |
c [expr {wide(0x80000000)+1}]] |
| 327 |
dict incr dictv a |
| 328 |
} -cleanup { |
| 329 |
unset dictv |
| 330 |
} -result {a 1 b 3 c 2147483649} |
| 331 |
test dict-11.2 {dict incr command: unshared value} -body { |
| 332 |
set dictv [dict create \ |
| 333 |
a [string index "=0=" 1] \ |
| 334 |
b [expr {1+2}] \ |
| 335 |
c [expr {wide(0x80000000)+1}]] |
| 336 |
dict incr dictv b |
| 337 |
} -cleanup { |
| 338 |
unset dictv |
| 339 |
} -result {a 0 b 4 c 2147483649} |
| 340 |
test dict-11.3 {dict incr command: unshared value} -body { |
| 341 |
set dictv [dict create \ |
| 342 |
a [string index "=0=" 1] \ |
| 343 |
b [expr {1+2}] \ |
| 344 |
c [expr {wide(0x80000000)+1}]] |
| 345 |
dict incr dictv c |
| 346 |
} -cleanup { |
| 347 |
unset dictv |
| 348 |
} -result {a 0 b 3 c 2147483650} |
| 349 |
test dict-11.4 {dict incr command: shared value} -body { |
| 350 |
set dictv [dict create a 0 b [expr {1+2}] c [expr {wide(0x80000000)+1}]] |
| 351 |
set sharing [dict values $dictv] |
| 352 |
dict incr dictv a |
| 353 |
} -cleanup { |
| 354 |
unset dictv sharing |
| 355 |
} -result {a 1 b 3 c 2147483649} |
| 356 |
test dict-11.5 {dict incr command: shared value} -body { |
| 357 |
set dictv [dict create a 0 b [expr {1+2}] c [expr {wide(0x80000000)+1}]] |
| 358 |
set sharing [dict values $dictv] |
| 359 |
dict incr dictv b |
| 360 |
} -cleanup { |
| 361 |
unset dictv sharing |
| 362 |
} -result {a 0 b 4 c 2147483649} |
| 363 |
test dict-11.6 {dict incr command: shared value} -body { |
| 364 |
set dictv [dict create a 0 b [expr {1+2}] c [expr {wide(0x80000000)+1}]] |
| 365 |
set sharing [dict values $dictv] |
| 366 |
dict incr dictv c |
| 367 |
} -cleanup { |
| 368 |
unset dictv sharing |
| 369 |
} -result {a 0 b 3 c 2147483650} |
| 370 |
test dict-11.7 {dict incr command: unknown values} -body { |
| 371 |
set dictv [dict create a 0 b [expr {1+2}] c [expr {wide(0x80000000)+1}]] |
| 372 |
dict incr dictv d |
| 373 |
} -cleanup { |
| 374 |
unset dictv |
| 375 |
} -result {a 0 b 3 c 2147483649 d 1} |
| 376 |
test dict-11.8 {dict incr command} -body { |
| 377 |
set dictv {a 1} |
| 378 |
dict incr dictv a 2 |
| 379 |
} -cleanup { |
| 380 |
unset dictv |
| 381 |
} -result {a 3} |
| 382 |
test dict-11.9 {dict incr command} -returnCodes error -body { |
| 383 |
set dictv {a dummy} |
| 384 |
dict incr dictv a |
| 385 |
} -cleanup { |
| 386 |
unset dictv |
| 387 |
} -result {expected integer but got "dummy"} |
| 388 |
test dict-11.10 {dict incr command} -returnCodes error -body { |
| 389 |
set dictv {a 1} |
| 390 |
dict incr dictv a dummy |
| 391 |
} -cleanup { |
| 392 |
unset dictv |
| 393 |
} -result {expected integer but got "dummy"} |
| 394 |
test dict-11.11 {dict incr command} -setup { |
| 395 |
unset -nocomplain dictv |
| 396 |
} -body { |
| 397 |
dict incr dictv a |
| 398 |
} -cleanup { |
| 399 |
unset dictv |
| 400 |
} -result {a 1} |
| 401 |
test dict-11.12 {dict incr command} -returnCodes error -body { |
| 402 |
set dictv a |
| 403 |
dict incr dictv a |
| 404 |
} -cleanup { |
| 405 |
unset dictv |
| 406 |
} -result {missing value to go with key} |
| 407 |
test dict-11.13 {dict incr command} -returnCodes error -body { |
| 408 |
set dictv a |
| 409 |
dict incr dictv a a a |
| 410 |
} -cleanup { |
| 411 |
unset dictv |
| 412 |
} -result {wrong # args: should be "dict incr dictVarName key ?increment?"} |
| 413 |
test dict-11.14 {dict incr command} -returnCodes error -body { |
| 414 |
set dictv a |
| 415 |
dict incr dictv |
| 416 |
} -cleanup { |
| 417 |
unset dictv |
| 418 |
} -result {wrong # args: should be "dict incr dictVarName key ?increment?"} |
| 419 |
test dict-11.15 {dict incr command: write failure} -setup { |
| 420 |
unset -nocomplain dictVar |
| 421 |
} -body { |
| 422 |
set dictVar(block) {} |
| 423 |
dict incr dictVar a |
| 424 |
} -returnCodes error -cleanup { |
| 425 |
unset dictVar |
| 426 |
} -result {can't set "dictVar": variable is array} |
| 427 |
test dict-11.16 {dict incr command: compilation} { |
| 428 |
apply {{} { |
| 429 |
set v {a 0 b 0 c 0} |
| 430 |
dict incr v a |
| 431 |
dict incr v b 1 |
| 432 |
dict incr v c 2 |
| 433 |
dict incr v d 3 |
| 434 |
list [dict get $v a] [dict get $v b] [dict get $v c] [dict get $v d] |
| 435 |
}} |
| 436 |
} {1 1 2 3} |
| 437 |
test dict-11.17 {dict incr command: compilation} { |
| 438 |
apply {{} { |
| 439 |
set dictv {a 1} |
| 440 |
dict incr dictv a 2 |
| 441 |
}} |
| 442 |
} {a 3} |
| 443 |
|
| 444 |
test dict-12.1 {dict lappend command} -body { |
| 445 |
set dictv {a a} |
| 446 |
dict lappend dictv a |
| 447 |
} -cleanup { |
| 448 |
unset dictv |
| 449 |
} -result {a a} |
| 450 |
test dict-12.2 {dict lappend command} -body { |
| 451 |
set dictv {a a} |
| 452 |
set sharing [dict values $dictv] |
| 453 |
dict lappend dictv a b |
| 454 |
} -cleanup { |
| 455 |
unset dictv sharing |
| 456 |
} -result {a {a b}} |
| 457 |
test dict-12.3 {dict lappend command} -body { |
| 458 |
set dictv {a a} |
| 459 |
dict lappend dictv a b c |
| 460 |
} -cleanup { |
| 461 |
unset dictv |
| 462 |
} -result {a {a b c}} |
| 463 |
test dict-12.2.1 {dict lappend command} -body { |
| 464 |
set dictv [dict create a [string index =a= 1]] |
| 465 |
dict lappend dictv a b |
| 466 |
} -cleanup { |
| 467 |
unset dictv |
| 468 |
} -result {a {a b}} |
| 469 |
test dict-12.4 {dict lappend command} -body { |
| 470 |
set dictv {} |
| 471 |
dict lappend dictv a x y z |
| 472 |
} -cleanup { |
| 473 |
unset dictv |
| 474 |
} -result {a {x y z}} |
| 475 |
test dict-12.5 {dict lappend command} -body { |
| 476 |
unset -nocomplain dictv |
| 477 |
dict lappend dictv a b |
| 478 |
} -cleanup { |
| 479 |
unset dictv |
| 480 |
} -result {a b} |
| 481 |
test dict-12.6 {dict lappend command} -returnCodes error -body { |
| 482 |
set dictv a |
| 483 |
dict lappend dictv a a |
| 484 |
} -cleanup { |
| 485 |
unset dictv |
| 486 |
} -result {missing value to go with key} |
| 487 |
test dict-12.7 {dict lappend command} -returnCodes error -body { |
| 488 |
dict lappend |
| 489 |
} -result {wrong # args: should be "dict lappend dictVarName key ?value ...?"} |
| 490 |
test dict-12.8 {dict lappend command} -returnCodes error -body { |
| 491 |
dict lappend dictv |
| 492 |
} -result {wrong # args: should be "dict lappend dictVarName key ?value ...?"} |
| 493 |
test dict-12.9 {dict lappend command} -returnCodes error -body { |
| 494 |
set dictv [dict create a "\{"] |
| 495 |
dict lappend dictv a a |
| 496 |
} -cleanup { |
| 497 |
unset dictv |
| 498 |
} -result {unmatched open brace in list} |
| 499 |
test dict-12.10 {dict lappend command: write failure} -setup { |
| 500 |
unset -nocomplain dictVar |
| 501 |
} -body { |
| 502 |
set dictVar(block) {} |
| 503 |
dict lappend dictVar a x |
| 504 |
} -returnCodes error -cleanup { |
| 505 |
unset dictVar |
| 506 |
} -result {can't set "dictVar": variable is array} |
| 507 |
test dict-12.11 {compiled dict append: invalidate string rep - Bug 3079830} { |
| 508 |
apply {{} {set d {a 1 b 2 c 3}; dict lappend d b 22}} |
| 509 |
} {a 1 b {2 22} c 3} |
| 510 |
|
| 511 |
test dict-13.1 {dict append command} -body { |
| 512 |
set dictv {a a} |
| 513 |
dict append dictv a |
| 514 |
} -cleanup { |
| 515 |
unset dictv |
| 516 |
} -result {a a} |
| 517 |
test dict-13.2 {dict append command} -body { |
| 518 |
set dictv {a a} |
| 519 |
set sharing [dict values $dictv] |
| 520 |
dict append dictv a b |
| 521 |
} -cleanup { |
| 522 |
unset dictv sharing |
| 523 |
} -result {a ab} |
| 524 |
test dict-13.3 {dict append command} -body { |
| 525 |
set dictv {a a} |
| 526 |
dict append dictv a b c |
| 527 |
} -cleanup { |
| 528 |
unset dictv |
| 529 |
} -result {a abc} |
| 530 |
test dict-13.2.1 {dict append command} -body { |
| 531 |
set dictv [dict create a [string index =a= 1]] |
| 532 |
dict append dictv a b |
| 533 |
} -cleanup { |
| 534 |
unset dictv |
| 535 |
} -result {a ab} |
| 536 |
test dict-13.4 {dict append command} -body { |
| 537 |
set dictv {} |
| 538 |
dict append dictv a x y z |
| 539 |
} -cleanup { |
| 540 |
unset dictv |
| 541 |
} -result {a xyz} |
| 542 |
test dict-13.5 {dict append command} -body { |
| 543 |
unset -nocomplain dictv |
| 544 |
dict append dictv a b |
| 545 |
} -cleanup { |
| 546 |
unset dictv |
| 547 |
} -result {a b} |
| 548 |
test dict-13.6 {dict append command} -returnCodes error -body { |
| 549 |
set dictv a |
| 550 |
dict append dictv a a |
| 551 |
} -cleanup { |
| 552 |
unset dictv |
| 553 |
} -result {missing value to go with key} |
| 554 |
test dict-13.7 {dict append command} -returnCodes error -body { |
| 555 |
dict append |
| 556 |
} -result {wrong # args: should be "dict append dictVarName key ?value ...?"} |
| 557 |
test dict-13.8 {dict append command} -returnCodes error -body { |
| 558 |
dict append dictv |
| 559 |
} -result {wrong # args: should be "dict append dictVarName key ?value ...?"} |
| 560 |
test dict-13.9 {dict append command: write failure} -setup { |
| 561 |
unset -nocomplain dictVar |
| 562 |
} -body { |
| 563 |
set dictVar(block) {} |
| 564 |
dict append dictVar a x |
| 565 |
} -returnCodes error -cleanup { |
| 566 |
unset dictVar |
| 567 |
} -result {can't set "dictVar": variable is array} |
| 568 |
test dict-13.10 {compiled dict append: crash case} { |
| 569 |
apply {{} {dict append dictVar a o k}} |
| 570 |
} {a ok} |
| 571 |
test dict-13.11 {compiled dict append: invalidate string rep - Bug 3079830} { |
| 572 |
apply {{} {set d {a 1 b 2 c 3}; dict append d b 22}} |
| 573 |
} {a 1 b 222 c 3} |
| 574 |
|
| 575 |
test dict-14.1 {dict for command: syntax} -returnCodes error -body { |
| 576 |
dict for |
| 577 |
} -result {wrong # args: should be "dict for {keyVarName valueVarName} dictionary script"} |
| 578 |
test dict-14.2 {dict for command: syntax} -returnCodes error -body { |
| 579 |
dict for x |
| 580 |
} -result {wrong # args: should be "dict for {keyVarName valueVarName} dictionary script"} |
| 581 |
test dict-14.3 {dict for command: syntax} -returnCodes error -body { |
| 582 |
dict for x x |
| 583 |
} -result {wrong # args: should be "dict for {keyVarName valueVarName} dictionary script"} |
| 584 |
test dict-14.4 {dict for command: syntax} -returnCodes error -body { |
| 585 |
dict for x x x x |
| 586 |
} -result {wrong # args: should be "dict for {keyVarName valueVarName} dictionary script"} |
| 587 |
test dict-14.5 {dict for command: syntax} -returnCodes error -body { |
| 588 |
dict for x x x |
| 589 |
} -result {must have exactly two variable names} |
| 590 |
test dict-14.6 {dict for command: syntax} -returnCodes error -body { |
| 591 |
dict for {x x x} x x |
| 592 |
} -result {must have exactly two variable names} |
| 593 |
test dict-14.7 {dict for command: syntax} -returnCodes error -body { |
| 594 |
dict for "\{x" x x |
| 595 |
} -result {unmatched open brace in list} |
| 596 |
test dict-14.8 {dict for command} -body { |
| 597 |
# This test confirms that [dict keys], [dict values] and [dict for] |
| 598 |
# all traverse a dictionary in the same order. |
| 599 |
set dictv {a A b B c C} |
| 600 |
set keys {} |
| 601 |
set values {} |
| 602 |
dict for {k v} $dictv { |
| 603 |
lappend keys $k |
| 604 |
lappend values $v |
| 605 |
} |
| 606 |
set result [expr { |
| 607 |
$keys eq [dict keys $dictv] && $values eq [dict values $dictv] |
| 608 |
}] |
| 609 |
expr {$result ? "YES" : [list "NO" $dictv $keys $values]} |
| 610 |
} -cleanup { |
| 611 |
unset result keys values k v dictv |
| 612 |
} -result YES |
| 613 |
test dict-14.9 {dict for command} { |
| 614 |
dict for {k v} {} { |
| 615 |
error "unexpected execution of 'dict for' body" |
| 616 |
} |
| 617 |
} {} |
| 618 |
test dict-14.10 {dict for command: script results} -body { |
| 619 |
set times 0 |
| 620 |
dict for {k v} {a a b b} { |
| 621 |
incr times |
| 622 |
continue |
| 623 |
error "shouldn't get here" |
| 624 |
} |
| 625 |
return $times |
| 626 |
} -cleanup { |
| 627 |
unset times k v |
| 628 |
} -result 2 |
| 629 |
test dict-14.11 {dict for command: script results} -body { |
| 630 |
set times 0 |
| 631 |
dict for {k v} {a a b b} { |
| 632 |
incr times |
| 633 |
break |
| 634 |
error "shouldn't get here" |
| 635 |
} |
| 636 |
return $times |
| 637 |
} -cleanup { |
| 638 |
unset times k v |
| 639 |
} -result 1 |
| 640 |
test dict-14.12 {dict for command: script results} -body { |
| 641 |
set times 0 |
| 642 |
list [catch { |
| 643 |
dict for {k v} {a a b b} { |
| 644 |
incr times |
| 645 |
error test |
| 646 |
} |
| 647 |
} msg] $msg $times $::errorInfo |
| 648 |
} -cleanup { |
| 649 |
unset times k v msg |
| 650 |
} -result {1 test 1 {test |
| 651 |
while executing |
| 652 |
"error test" |
| 653 |
("dict for" body line 3) |
| 654 |
invoked from within |
| 655 |
"dict for {k v} {a a b b} { |
| 656 |
incr times |
| 657 |
error test |
| 658 |
}"}} |
| 659 |
test dict-14.13 {dict for command: script results} { |
| 660 |
apply {{} { |
| 661 |
dict for {k v} {a b} { |
| 662 |
return ok,$k,$v |
| 663 |
error "skipped return completely" |
| 664 |
} |
| 665 |
error "return didn't go far enough" |
| 666 |
}} |
| 667 |
} ok,a,b |
| 668 |
test dict-14.14 {dict for command: handle representation loss} -body { |
| 669 |
set dictVar {a b c d e f g h} |
| 670 |
set keys {} |
| 671 |
set values {} |
| 672 |
dict for {k v} $dictVar { |
| 673 |
if {[llength $dictVar]} { |
| 674 |
lappend keys $k |
| 675 |
lappend values $v |
| 676 |
} |
| 677 |
} |
| 678 |
list [lsort $keys] [lsort $values] |
| 679 |
} -cleanup { |
| 680 |
unset dictVar keys values k v |
| 681 |
} -result {{a c e g} {b d f h}} |
| 682 |
test dict-14.15 {dict for command: keys are unique and iterated over once only} -setup { |
| 683 |
unset -nocomplain accum |
| 684 |
array set accum {} |
| 685 |
} -body { |
| 686 |
set dictVar {a1 a a2 b b1 c b2 d foo bar bar foo} |
| 687 |
dict for {k v} $dictVar { |
| 688 |
append accum($k) $v, |
| 689 |
} |
| 690 |
set result [lsort [array names accum]] |
| 691 |
lappend result : |
| 692 |
foreach k $result { |
| 693 |
catch {lappend result $accum($k)} |
| 694 |
} |
| 695 |
return $result |
| 696 |
} -cleanup { |
| 697 |
unset dictVar k v result accum |
| 698 |
} -result {a1 a2 b1 b2 bar foo : a, b, c, d, foo, bar,} |
| 699 |
test dict-14.16 {dict for command in compilation context} { |
| 700 |
apply {{} { |
| 701 |
set res {x x x x x x} |
| 702 |
dict for {k v} {a 0 b 1 c 2 d 3 e 4 f 5} { |
| 703 |
lset res $v $k |
| 704 |
continue |
| 705 |
} |
| 706 |
return $res |
| 707 |
}} |
| 708 |
} {a b c d e f} |
| 709 |
test dict-14.17 {dict for command in compilation context} { |
| 710 |
# Bug 1379349 |
| 711 |
apply {{} { |
| 712 |
set d [dict create a 1] ;# Dict must be unshared! |
| 713 |
dict for {k v} $d { |
| 714 |
dict set d $k 0 ;# Any modification will do |
| 715 |
} |
| 716 |
return $d |
| 717 |
}} |
| 718 |
} {a 0} |
| 719 |
test dict-14.18 {dict for command in compilation context} { |
| 720 |
# Bug 1382528 |
| 721 |
apply {{} { |
| 722 |
dict for {k v} {} {} ;# Note empty dict |
| 723 |
catch { error foo } ;# Note compiled [catch] |
| 724 |
}} |
| 725 |
} 1 |
| 726 |
test dict-14.19 {dict for and invalid dicts: bug 1531184} -body { |
| 727 |
di[list]ct for {k v} x {} |
| 728 |
} -returnCodes 1 -result {missing value to go with key} |
| 729 |
test dict-14.20 {dict for stack space compilation: bug 1903325} { |
| 730 |
apply {{x y args} { |
| 731 |
dict for {a b} $x {} |
| 732 |
concat "c=$y,$args" |
| 733 |
}} {} 1 2 3 |
| 734 |
} {c=1,2 3} |
| 735 |
test dict-14.21 {compiled dict for and break} { |
| 736 |
apply {{} { |
| 737 |
dict for {a b} {c d e f} { |
| 738 |
lappend result $a,$b |
| 739 |
break |
| 740 |
} |
| 741 |
return $result |
| 742 |
}} |
| 743 |
} c,d |
| 744 |
test dict-14.22 {dict for and exception range depths: Bug 3614382} { |
| 745 |
apply {{} { |
| 746 |
dict for {a b} {c d} { |
| 747 |
dict for {e f} {g h} { |
| 748 |
return 5 |
| 749 |
} |
| 750 |
} |
| 751 |
}} |
| 752 |
} 5 |
| 753 |
# There's probably a lot more tests to add here. Really ought to use a |
| 754 |
# coverage tool for this job... |
| 755 |
|
| 756 |
test dict-15.1 {dict set command} -body { |
| 757 |
set dictVar {} |
| 758 |
dict set dictVar a x |
| 759 |
} -cleanup { |
| 760 |
unset dictVar |
| 761 |
} -result {a x} |
| 762 |
test dict-15.2 {dict set command} -body { |
| 763 |
set dictvar {a {}} |
| 764 |
dict set dictvar a b x |
| 765 |
} -cleanup { |
| 766 |
unset dictvar |
| 767 |
} -result {a {b x}} |
| 768 |
test dict-15.3 {dict set command} -body { |
| 769 |
set dictvar {a {b {}}} |
| 770 |
dict set dictvar a b c x |
| 771 |
} -cleanup { |
| 772 |
unset dictvar |
| 773 |
} -result {a {b {c x}}} |
| 774 |
test dict-15.4 {dict set command} -body { |
| 775 |
set dictVar {a y} |
| 776 |
dict set dictVar a x |
| 777 |
} -cleanup { |
| 778 |
unset dictVar |
| 779 |
} -result {a x} |
| 780 |
test dict-15.5 {dict set command} -body { |
| 781 |
set dictVar {a {b y}} |
| 782 |
dict set dictVar a b x |
| 783 |
} -cleanup { |
| 784 |
unset dictVar |
| 785 |
} -result {a {b x}} |
| 786 |
test dict-15.6 {dict set command} -body { |
| 787 |
set dictVar {a {b {c y}}} |
| 788 |
dict set dictVar a b c x |
| 789 |
} -cleanup { |
| 790 |
unset dictVar |
| 791 |
} -result {a {b {c x}}} |
| 792 |
test dict-15.7 {dict set command: path creation} -body { |
| 793 |
set dictVar {} |
| 794 |
dict set dictVar a b x |
| 795 |
} -cleanup { |
| 796 |
unset dictVar |
| 797 |
} -result {a {b x}} |
| 798 |
test dict-15.8 {dict set command: creates variables} -setup { |
| 799 |
unset -nocomplain dictVar |
| 800 |
} -body { |
| 801 |
dict set dictVar a x |
| 802 |
return $dictVar |
| 803 |
} -cleanup { |
| 804 |
unset dictVar |
| 805 |
} -result {a x} |
| 806 |
test dict-15.9 {dict set command: write failure} -setup { |
| 807 |
unset -nocomplain dictVar |
| 808 |
} -body { |
| 809 |
set dictVar(block) {} |
| 810 |
dict set dictVar a x |
| 811 |
} -returnCodes error -cleanup { |
| 812 |
unset dictVar |
| 813 |
} -result {can't set "dictVar": variable is array} |
| 814 |
test dict-15.10 {dict set command: syntax} -returnCodes error -body { |
| 815 |
dict set |
| 816 |
} -result {wrong # args: should be "dict set dictVarName key ?key ...? value"} |
| 817 |
test dict-15.11 {dict set command: syntax} -returnCodes error -body { |
| 818 |
dict set a |
| 819 |
} -result {wrong # args: should be "dict set dictVarName key ?key ...? value"} |
| 820 |
test dict-15.12 {dict set command: syntax} -returnCodes error -body { |
| 821 |
dict set a a |
| 822 |
} -result {wrong # args: should be "dict set dictVarName key ?key ...? value"} |
| 823 |
test dict-15.13 {dict set command} -returnCodes error -body { |
| 824 |
set dictVar a |
| 825 |
dict set dictVar b c |
| 826 |
} -cleanup { |
| 827 |
unset dictVar |
| 828 |
} -result {missing value to go with key} |
| 829 |
|
| 830 |
test dict-16.1 {dict unset command} -body { |
| 831 |
set dictVar {a b c d} |
| 832 |
dict unset dictVar a |
| 833 |
} -cleanup { |
| 834 |
unset dictVar |
| 835 |
} -result {c d} |
| 836 |
test dict-16.2 {dict unset command} -body { |
| 837 |
set dictVar {a b c d} |
| 838 |
dict unset dictVar c |
| 839 |
} -cleanup { |
| 840 |
unset dictVar |
| 841 |
} -result {a b} |
| 842 |
test dict-16.3 {dict unset command} -body { |
| 843 |
set dictVar {a b} |
| 844 |
dict unset dictVar c |
| 845 |
} -cleanup { |
| 846 |
unset dictVar |
| 847 |
} -result {a b} |
| 848 |
test dict-16.4 {dict unset command} -body { |
| 849 |
set dictVar {a {b c d e}} |
| 850 |
dict unset dictVar a b |
| 851 |
} -cleanup { |
| 852 |
unset dictVar |
| 853 |
} -result {a {d e}} |
| 854 |
test dict-16.5 {dict unset command} -returnCodes error -body { |
| 855 |
set dictVar a |
| 856 |
dict unset dictVar a |
| 857 |
} -cleanup { |
| 858 |
unset dictVar |
| 859 |
} -result {missing value to go with key} |
| 860 |
test dict-16.6 {dict unset command} -returnCodes error -body { |
| 861 |
set dictVar {a b} |
| 862 |
dict unset dictVar c d |
| 863 |
} -cleanup { |
| 864 |
unset dictVar |
| 865 |
} -result {key "c" not known in dictionary} |
| 866 |
test dict-16.7 {dict unset command} -setup { |
| 867 |
unset -nocomplain dictVar |
| 868 |
} -body { |
| 869 |
list [info exists dictVar] [dict unset dictVar a] [info exists dictVar] |
| 870 |
} -cleanup { |
| 871 |
unset dictVar |
| 872 |
} -result {0 {} 1} |
| 873 |
test dict-16.8 {dict unset command} -returnCodes error -body { |
| 874 |
dict unset dictVar |
| 875 |
} -result {wrong # args: should be "dict unset dictVarName key ?key ...?"} |
| 876 |
test dict-16.9 {dict unset command: write failure} -setup { |
| 877 |
unset -nocomplain dictVar |
| 878 |
} -body { |
| 879 |
set dictVar(block) {} |
| 880 |
dict unset dictVar a |
| 881 |
} -returnCodes error -cleanup { |
| 882 |
unset dictVar |
| 883 |
} -result {can't set "dictVar": variable is array} |
| 884 |
# Now test with an LVT present (i.e., the bytecoded version). |
| 885 |
test dict-16.10 {dict unset command} -body { |
| 886 |
apply {{} { |
| 887 |
set dictVar {a b c d} |
| 888 |
dict unset dictVar a |
| 889 |
}} |
| 890 |
} -result {c d} |
| 891 |
test dict-16.11 {dict unset command} -body { |
| 892 |
apply {{} { |
| 893 |
set dictVar {a b c d} |
| 894 |
dict unset dictVar c |
| 895 |
}} |
| 896 |
} -result {a b} |
| 897 |
test dict-16.12 {dict unset command} -body { |
| 898 |
apply {{} { |
| 899 |
set dictVar {a b} |
| 900 |
dict unset dictVar c |
| 901 |
}} |
| 902 |
} -result {a b} |
| 903 |
test dict-16.13 {dict unset command} -body { |
| 904 |
apply {{} { |
| 905 |
set dictVar {a {b c d e}} |
| 906 |
dict unset dictVar a b |
| 907 |
}} |
| 908 |
} -result {a {d e}} |
| 909 |
test dict-16.14 {dict unset command} -returnCodes error -body { |
| 910 |
apply {{} { |
| 911 |
set dictVar a |
| 912 |
dict unset dictVar a |
| 913 |
}} |
| 914 |
} -result {missing value to go with key} |
| 915 |
test dict-16.15 {dict unset command} -returnCodes error -body { |
| 916 |
apply {{} { |
| 917 |
set dictVar {a b} |
| 918 |
dict unset dictVar c d |
| 919 |
}} |
| 920 |
} -result {key "c" not known in dictionary} |
| 921 |
test dict-16.16 {dict unset command} -body { |
| 922 |
apply {{} {list [info exists dictVar] [dict unset dictVar a] [info exists dictVar]}} |
| 923 |
} -result {0 {} 1} |
| 924 |
test dict-16.17 {dict unset command} -returnCodes error -body { |
| 925 |
apply {{} {dict unset dictVar}} |
| 926 |
} -result {wrong # args: should be "dict unset dictVarName key ?key ...?"} |
| 927 |
test dict-16.18 {dict unset command: write failure} -body { |
| 928 |
apply {{} { |
| 929 |
set dictVar(block) {} |
| 930 |
dict unset dictVar a |
| 931 |
}} |
| 932 |
} -returnCodes error -result {can't set "dictVar": variable is array} |
| 933 |
|
| 934 |
test dict-17.1 {dict filter command: key} -body { |
| 935 |
set dictVar {a1 a a2 b b1 c b2 d foo bar bar foo} |
| 936 |
dict filter $dictVar key a2 |
| 937 |
} -cleanup { |
| 938 |
unset dictVar |
| 939 |
} -result {a2 b} |
| 940 |
test dict-17.2 {dict filter command: key} -body { |
| 941 |
set dictVar {a1 a a2 b b1 c b2 d foo bar bar foo} |
| 942 |
dict size [dict filter $dictVar key *] |
| 943 |
} -cleanup { |
| 944 |
unset dictVar |
| 945 |
} -result 6 |
| 946 |
test dict-17.3 {dict filter command: key} -body { |
| 947 |
set dictVar {a1 a a2 b b1 c b2 d foo bar bar foo} |
| 948 |
dict filter $dictVar key ??? |
| 949 |
} -cleanup { |
| 950 |
unset dictVar |
| 951 |
} -result {foo bar bar foo} |
| 952 |
test dict-17.4 {dict filter command: key - no patterns} { |
| 953 |
dict filter {a b c d} key |
| 954 |
} {} |
| 955 |
test dict-17.4.1 {dict filter command: key - many patterns} { |
| 956 |
dict filter {a1 a a2 b b1 c b2 d foo bar bar foo} key a? b? |
| 957 |
} {a1 a a2 b b1 c b2 d} |
| 958 |
test dict-17.5 {dict filter command: key - bad dict} -returnCodes error -body { |
| 959 |
dict filter {a b c} key |
| 960 |
} -result {missing value to go with key} |
| 961 |
test dict-17.6 {dict filter command: value} -body { |
| 962 |
set dictVar {a1 a a2 b b1 c b2 d foo bar bar foo} |
| 963 |
dict filter $dictVar value c |
| 964 |
} -cleanup { |
| 965 |
unset dictVar |
| 966 |
} -result {b1 c} |
| 967 |
test dict-17.7 {dict filter command: value} -body { |
| 968 |
set dictVar {a1 a a2 b b1 c b2 d foo bar bar foo} |
| 969 |
dict size [dict filter $dictVar value *] |
| 970 |
} -cleanup { |
| 971 |
unset dictVar |
| 972 |
} -result 6 |
| 973 |
test dict-17.8 {dict filter command: value} -body { |
| 974 |
set dictVar {a1 a a2 b b1 c b2 d foo bar bar foo} |
| 975 |
dict filter $dictVar value ??? |
| 976 |
} -cleanup { |
| 977 |
unset dictVar |
| 978 |
} -result {foo bar bar foo} |
| 979 |
test dict-17.9 {dict filter command: value - no patterns} { |
| 980 |
dict filter {a b c d} value |
| 981 |
} {} |
| 982 |
test dict-17.9.1 {dict filter command: value - many patterns} { |
| 983 |
dict filter {a a1 b a2 c b1 foo bar bar foo d b2} value a? b? |
| 984 |
} {a a1 b a2 c b1 d b2} |
| 985 |
test dict-17.10 {dict filter command: value - bad dict} -body { |
| 986 |
dict filter {a b c} value a |
| 987 |
} -returnCodes error -result {missing value to go with key} |
| 988 |
test dict-17.11 {dict filter command: script} -body { |
| 989 |
set dictVar {a1 a a2 b b1 c b2 d foo bar bar foo} |
| 990 |
set n 0 |
| 991 |
list [dict filter $dictVar script {k v} { |
| 992 |
incr n |
| 993 |
expr {[string length $k] == [string length $v]} |
| 994 |
}] $n |
| 995 |
} -cleanup { |
| 996 |
unset dictVar n k v |
| 997 |
} -result {{foo bar bar foo} 6} |
| 998 |
test dict-17.12 {dict filter command: script} -returnCodes error -body { |
| 999 |
dict filter {a b} script {k v} { |
| 1000 |
concat $k $v |
| 1001 |
} |
| 1002 |
} -cleanup { |
| 1003 |
unset k v |
| 1004 |
} -result {expected boolean value but got "a b"} |
| 1005 |
test dict-17.13 {dict filter command: script} -body { |
| 1006 |
list [catch {dict filter {a b} script {k v} {error x}} msg] $msg \ |
| 1007 |
$::errorInfo |
| 1008 |
} -cleanup { |
| 1009 |
unset k v msg |
| 1010 |
} -result {1 x {x |
| 1011 |
while executing |
| 1012 |
"error x" |
| 1013 |
("dict filter" script line 1) |
| 1014 |
invoked from within |
| 1015 |
"dict filter {a b} script {k v} {error x}"}} |
| 1016 |
test dict-17.14 {dict filter command: script} -setup { |
| 1017 |
set n 0 |
| 1018 |
} -body { |
| 1019 |
list [dict filter {a b c d} script {k v} { |
| 1020 |
incr n |
| 1021 |
break |
| 1022 |
error boom! |
| 1023 |
}] $n |
| 1024 |
} -cleanup { |
| 1025 |
unset n k v |
| 1026 |
} -result {{} 1} |
| 1027 |
test dict-17.15 {dict filter command: script} -setup { |
| 1028 |
set n 0 |
| 1029 |
} -body { |
| 1030 |
list [dict filter {a b c d} script {k v} { |
| 1031 |
incr n |
| 1032 |
continue |
| 1033 |
error boom! |
| 1034 |
}] $n |
| 1035 |
} -cleanup { |
| 1036 |
unset n k v |
| 1037 |
} -result {{} 2} |
| 1038 |
test dict-17.16 {dict filter command: script} { |
| 1039 |
apply {{} { |
| 1040 |
dict filter {a b} script {k v} { |
| 1041 |
return ok,$k,$v |
| 1042 |
error "skipped return completely" |
| 1043 |
} |
| 1044 |
error "return didn't go far enough" |
| 1045 |
}} |
| 1046 |
} ok,a,b |
| 1047 |
test dict-17.17 {dict filter command: script} -body { |
| 1048 |
dict filter {a b} script {k k} {continue} |
| 1049 |
return $k |
| 1050 |
} -cleanup { |
| 1051 |
unset k |
| 1052 |
} -result b |
| 1053 |
test dict-17.18 {dict filter command: script} -returnCodes error -body { |
| 1054 |
dict filter {a b} script {k k} |
| 1055 |
} -result {wrong # args: should be "dict filter dictionary script {keyVarName valueVarName} filterScript"} |
| 1056 |
test dict-17.19 {dict filter command: script} -returnCodes error -body { |
| 1057 |
dict filter {a b} script k {continue} |
| 1058 |
} -result {must have exactly two variable names} |
| 1059 |
test dict-17.20 {dict filter command: script} -returnCodes error -body { |
| 1060 |
dict filter {a b} script "\{k v" {continue} |
| 1061 |
} -result {unmatched open brace in list} |
| 1062 |
test dict-17.21 {dict filter command} -returnCodes error -body { |
| 1063 |
dict filter {a b} |
| 1064 |
} -result {wrong # args: should be "dict filter dictionary filterType ?arg ...?"} |
| 1065 |
test dict-17.22 {dict filter command} -returnCodes error -body { |
| 1066 |
dict filter {a b} JUNK |
| 1067 |
} -result {bad filterType "JUNK": must be key, script, or value} |
| 1068 |
test dict-17.23 {dict filter command} -returnCodes error -body { |
| 1069 |
dict filter a key * |
| 1070 |
} -result {missing value to go with key} |
| 1071 |
|
| 1072 |
test dict-18.1 {dict-list relationship} -body { |
| 1073 |
# Test that any internal conversion between list and dict does not change |
| 1074 |
# the object |
| 1075 |
set l [list 1 2 3 4 5 6 7 8 9 0 q w e r t y] |
| 1076 |
dict values $l |
| 1077 |
return $l |
| 1078 |
} -cleanup { |
| 1079 |
unset l |
| 1080 |
} -result {1 2 3 4 5 6 7 8 9 0 q w e r t y} |
| 1081 |
test dict-18.2 {dict-list relationship} -body { |
| 1082 |
# Test that the dictionary is a valid list |
| 1083 |
set d [dict create "abc def" 0 "a\{b" 1 "c\}d" 2] |
| 1084 |
for {set t 0} {$t < 5} {incr t} { |
| 1085 |
llength $d |
| 1086 |
dict lappend d "abc def" "\}\{" |
| 1087 |
dict append d "a\{b" "\}" |
| 1088 |
dict incr d "c\}d" 1 |
| 1089 |
} |
| 1090 |
llength $d |
| 1091 |
} -cleanup { |
| 1092 |
unset d t |
| 1093 |
} -result 6 |
| 1094 |
test dict-18.3 {dict-list relationship} -body { |
| 1095 |
set ld [list a b c d c e f g] |
| 1096 |
list [string length $ld] [dict size $ld] [llength $ld] |
| 1097 |
} -cleanup { |
| 1098 |
unset ld |
| 1099 |
} -result {15 3 8} |
| 1100 |
test dict-18.4 {dict-list relationship} -body { |
| 1101 |
set ld [list a b c d c e f g] |
| 1102 |
list [llength $ld] [dict size $ld] [llength $ld] |
| 1103 |
} -cleanup { |
| 1104 |
unset ld |
| 1105 |
} -result {8 3 8} |
| 1106 |
|
| 1107 |
# This is a test for a specific bug. |
| 1108 |
# It shows a bad ref counter when running with memdebug on. |
| 1109 |
test dict-19.1 {memory bug} { |
| 1110 |
apply {{} { |
| 1111 |
set successors [dict create x {c d}] |
| 1112 |
dict set successors x a b |
| 1113 |
dict get $successors x |
| 1114 |
}} |
| 1115 |
} [dict create c d a b] |
| 1116 |
test dict-19.2 {dict: testing for leaks} -constraints memory -body { |
| 1117 |
# This test is made to stress object reference management |
| 1118 |
memtest { |
| 1119 |
apply {{} { |
| 1120 |
# A shared invalid dictionary |
| 1121 |
set apa {a {}b c d} |
| 1122 |
set bepa $apa |
| 1123 |
catch {dict replace $apa e f} |
| 1124 |
catch {dict remove $apa c d} |
| 1125 |
catch {dict incr apa a 5} |
| 1126 |
catch {dict lappend apa a 5} |
| 1127 |
catch {dict append apa a 5} |
| 1128 |
catch {dict set apa a 5} |
| 1129 |
catch {dict unset apa a} |
| 1130 |
|
| 1131 |
# A shared valid dictionary, invalid incr |
| 1132 |
set apa {a b c d} |
| 1133 |
set bepa $apa |
| 1134 |
catch {dict incr bepa a 5} |
| 1135 |
|
| 1136 |
# An error during write to an unshared object, incr |
| 1137 |
set apa {a 1 b 2} |
| 1138 |
set bepa [lrange $apa 0 end] |
| 1139 |
trace add variable bepa write {error hej} |
| 1140 |
catch {dict incr bepa a 5} |
| 1141 |
trace remove variable bepa write {error hej} |
| 1142 |
unset bepa |
| 1143 |
|
| 1144 |
# An error during write to a shared object, incr |
| 1145 |
set apa {a 1 b 2} |
| 1146 |
set bepa $apa |
| 1147 |
trace add variable bepa write {error hej} |
| 1148 |
catch {dict incr bepa a 5} |
| 1149 |
trace remove variable bepa write {error hej} |
| 1150 |
unset bepa |
| 1151 |
|
| 1152 |
# A shared valid dictionary, invalid lappend |
| 1153 |
set apa [list a {{}b} c d] |
| 1154 |
set bepa $apa |
| 1155 |
catch {dict lappend bepa a 5} |
| 1156 |
|
| 1157 |
# An error during write to an unshared object, lappend |
| 1158 |
set apa {a 1 b 2} |
| 1159 |
set bepa [lrange $apa 0 end] |
| 1160 |
trace add variable bepa write {error hej} |
| 1161 |
catch {dict lappend bepa a 5} |
| 1162 |
trace remove variable bepa write {error hej} |
| 1163 |
unset bepa |
| 1164 |
|
| 1165 |
# An error during write to a shared object, lappend |
| 1166 |
set apa {a 1 b 2} |
| 1167 |
set bepa $apa |
| 1168 |
trace add variable bepa write {error hej} |
| 1169 |
catch {dict lappend bepa a 5} |
| 1170 |
trace remove variable bepa write {error hej} |
| 1171 |
unset bepa |
| 1172 |
|
| 1173 |
# An error during write to an unshared object, append |
| 1174 |
set apa {a 1 b 2} |
| 1175 |
set bepa [lrange $apa 0 end] |
| 1176 |
trace add variable bepa write {error hej} |
| 1177 |
catch {dict append bepa a 5} |
| 1178 |
trace remove variable bepa write {error hej} |
| 1179 |
unset bepa |
| 1180 |
|
| 1181 |
# An error during write to a shared object, append |
| 1182 |
set apa {a 1 b 2} |
| 1183 |
set bepa $apa |
| 1184 |
trace add variable bepa write {error hej} |
| 1185 |
catch {dict append bepa a 5} |
| 1186 |
trace remove variable bepa write {error hej} |
| 1187 |
unset bepa |
| 1188 |
|
| 1189 |
# An error during write to an unshared object, set |
| 1190 |
set apa {a 1 b 2} |
| 1191 |
set bepa [lrange $apa 0 end] |
| 1192 |
trace add variable bepa write {error hej} |
| 1193 |
catch {dict set bepa a 5} |
| 1194 |
trace remove variable bepa write {error hej} |
| 1195 |
unset bepa |
| 1196 |
|
| 1197 |
# An error during write to a shared object, set |
| 1198 |
set apa {a 1 b 2} |
| 1199 |
set bepa $apa |
| 1200 |
trace add variable bepa write {error hej} |
| 1201 |
catch {dict set bepa a 5} |
| 1202 |
trace remove variable bepa write {error hej} |
| 1203 |
unset bepa |
| 1204 |
|
| 1205 |
# An error during write to an unshared object, unset |
| 1206 |
set apa {a 1 b 2} |
| 1207 |
set bepa [lrange $apa 0 end] |
| 1208 |
trace add variable bepa write {error hej} |
| 1209 |
catch {dict unset bepa a} |
| 1210 |
trace remove variable bepa write {error hej} |
| 1211 |
unset bepa |
| 1212 |
|
| 1213 |
# An error during write to a shared object, unset |
| 1214 |
set apa {a 1 b 2} |
| 1215 |
set bepa $apa |
| 1216 |
trace add variable bepa write {error hej} |
| 1217 |
catch {dict unset bepa a} |
| 1218 |
trace remove variable bepa write {error hej} |
| 1219 |
unset bepa |
| 1220 |
}} |
| 1221 |
} |
| 1222 |
} -result 0 |
| 1223 |
test dict-19.3 {testing for leaks - Bug 2874678} -constraints memory -body { |
| 1224 |
set d aDictVar; # Force interpreted [dict incr] |
| 1225 |
memtest { |
| 1226 |
dict incr $d aKey 0 |
| 1227 |
unset $d |
| 1228 |
} |
| 1229 |
} -cleanup { |
| 1230 |
unset d |
| 1231 |
} -result 0 |
| 1232 |
|
| 1233 |
test dict-20.1 {dict merge command} { |
| 1234 |
dict merge |
| 1235 |
} {} |
| 1236 |
test dict-20.2 {dict merge command} { |
| 1237 |
dict merge {a b c d e f} |
| 1238 |
} {a b c d e f} |
| 1239 |
test dict-20.3 {dict merge command} -body { |
| 1240 |
dict merge {a b c d e} |
| 1241 |
} -result {missing value to go with key} -returnCodes error |
| 1242 |
test dict-20.4 {dict merge command} { |
| 1243 |
dict merge {a b c d} {e f g h} |
| 1244 |
} {a b c d e f g h} |
| 1245 |
test dict-20.5 {dict merge command} -body { |
| 1246 |
dict merge {a b c d e} {e f g h} |
| 1247 |
} -result {missing value to go with key} -returnCodes error |
| 1248 |
test dict-20.6 {dict merge command} -body { |
| 1249 |
dict merge {a b c d} {e f g h i} |
| 1250 |
} -result {missing value to go with key} -returnCodes error |
| 1251 |
test dict-20.7 {dict merge command} { |
| 1252 |
dict merge {a b c d e f} {e x g h} |
| 1253 |
} {a b c d e x g h} |
| 1254 |
test dict-20.8 {dict merge command} { |
| 1255 |
dict merge {a b c d} {a x c y} |
| 1256 |
} {a x c y} |
| 1257 |
test dict-20.9 {dict merge command} { |
| 1258 |
dict merge {a b c d} {c y a x} |
| 1259 |
} {a x c y} |
| 1260 |
test dict-20.10 {dict merge command} { |
| 1261 |
dict merge {a b c d e f} {a x 1 2 3 4} {a - 1 -} |
| 1262 |
} {a - c d e f 1 - 3 4} |
| 1263 |
test dict-20.11 {dict merge command} { |
| 1264 |
apply {{} {dict merge}} |
| 1265 |
} {} |
| 1266 |
test dict-20.12 {dict merge command} { |
| 1267 |
apply {{} {dict merge {a b c d e f}}} |
| 1268 |
} {a b c d e f} |
| 1269 |
test dict-20.13 {dict merge command} -body { |
| 1270 |
apply {{} {dict merge {a b c d e}}} |
| 1271 |
} -result {missing value to go with key} -returnCodes error |
| 1272 |
test dict-20.14 {dict merge command} { |
| 1273 |
apply {{} {dict merge {a b c d} {e f g h}}} |
| 1274 |
} {a b c d e f g h} |
| 1275 |
test dict-20.15 {dict merge command} -body { |
| 1276 |
apply {{} {dict merge {a b c d e} {e f g h}}} |
| 1277 |
} -result {missing value to go with key} -returnCodes error |
| 1278 |
test dict-20.16 {dict merge command} -body { |
| 1279 |
apply {{} {dict merge {a b c d} {e f g h i}}} |
| 1280 |
} -result {missing value to go with key} -returnCodes error |
| 1281 |
test dict-20.17 {dict merge command} { |
| 1282 |
apply {{} {dict merge {a b c d e f} {e x g h}}} |
| 1283 |
} {a b c d e x g h} |
| 1284 |
test dict-20.18 {dict merge command} { |
| 1285 |
apply {{} {dict merge {a b c d} {a x c y}}} |
| 1286 |
} {a x c y} |
| 1287 |
test dict-20.19 {dict merge command} { |
| 1288 |
apply {{} {dict merge {a b c d} {c y a x}}} |
| 1289 |
} {a x c y} |
| 1290 |
test dict-20.20 {dict merge command} { |
| 1291 |
apply {{} {dict merge {a b c d e f} {a x 1 2 3 4} {a - 1 -}}} |
| 1292 |
} {a - c d e f 1 - 3 4} |
| 1293 |
test dict-20.21 {dict merge command: canonicality not forced} { |
| 1294 |
dict merge { a b c d } |
| 1295 |
} { a b c d } |
| 1296 |
test dict-20.22 {dict merge command: canonicality not forced} { |
| 1297 |
dict merge { a b c d } {} |
| 1298 |
} { a b c d } |
| 1299 |
test dict-20.23 {dict merge command: canonicality forced by update} { |
| 1300 |
dict merge { a b c d } {a b} |
| 1301 |
} {a b c d} |
| 1302 |
test dict-20.24 {dict merge command: type check is mandatory} -body { |
| 1303 |
dict merge { a b c d e } |
| 1304 |
} -returnCodes error -result {missing value to go with key} |
| 1305 |
test dict-20.25 {dict merge command: type check is mandatory} -body { |
| 1306 |
dict merge { a b {}c d } |
| 1307 |
} -returnCodes error -result {dict element in braces followed by "c" instead of space} |
| 1308 |
|
| 1309 |
test dict-21.1 {dict update command} -returnCodes 1 -body { |
| 1310 |
dict update |
| 1311 |
} -result {wrong # args: should be "dict update dictVarName key varName ?key varName ...? script"} |
| 1312 |
test dict-21.2 {dict update command} -returnCodes 1 -body { |
| 1313 |
dict update v |
| 1314 |
} -result {wrong # args: should be "dict update dictVarName key varName ?key varName ...? script"} |
| 1315 |
test dict-21.3 {dict update command} -returnCodes 1 -body { |
| 1316 |
dict update v k |
| 1317 |
} -result {wrong # args: should be "dict update dictVarName key varName ?key varName ...? script"} |
| 1318 |
test dict-21.4 {dict update command} -returnCodes 1 -body { |
| 1319 |
dict update v k v |
| 1320 |
} -result {wrong # args: should be "dict update dictVarName key varName ?key varName ...? script"} |
| 1321 |
test dict-21.5 {dict update command} -body { |
| 1322 |
set a {b c} |
| 1323 |
set result {} |
| 1324 |
set bb {} |
| 1325 |
dict update a b bb { |
| 1326 |
lappend result $a $bb |
| 1327 |
} |
| 1328 |
lappend result $a |
| 1329 |
} -cleanup { |
| 1330 |
unset a result bb |
| 1331 |
} -result {{b c} c {b c}} |
| 1332 |
test dict-21.6 {dict update command} -body { |
| 1333 |
set a {b c} |
| 1334 |
set result {} |
| 1335 |
set bb {} |
| 1336 |
dict update a b bb { |
| 1337 |
lappend result $a $bb [set bb d] |
| 1338 |
} |
| 1339 |
lappend result $a |
| 1340 |
} -cleanup { |
| 1341 |
unset a result bb |
| 1342 |
} -result {{b c} c d {b d}} |
| 1343 |
test dict-21.7 {dict update command} -body { |
| 1344 |
set a {b c} |
| 1345 |
set result {} |
| 1346 |
set bb {} |
| 1347 |
dict update a b bb { |
| 1348 |
lappend result $a $bb [unset bb] |
| 1349 |
} |
| 1350 |
lappend result $a |
| 1351 |
} -cleanup { |
| 1352 |
unset a result |
| 1353 |
} -result {{b c} c {} {}} |
| 1354 |
test dict-21.8 {dict update command} -body { |
| 1355 |
set a {b c d e} |
| 1356 |
dict update a b v1 d v2 { |
| 1357 |
lassign "$v1 $v2" v2 v1 |
| 1358 |
} |
| 1359 |
return $a |
| 1360 |
} -cleanup { |
| 1361 |
unset a v1 v2 |
| 1362 |
} -result {b e d c} |
| 1363 |
test dict-21.9 {dict update command} -body { |
| 1364 |
set a {b c d e} |
| 1365 |
dict update a b v1 d v2 {unset a} |
| 1366 |
info exist a |
| 1367 |
} -cleanup { |
| 1368 |
unset v1 v2 |
| 1369 |
} -result 0 |
| 1370 |
test dict-21.10 {dict update command} -body { |
| 1371 |
set a {b {c d}} |
| 1372 |
dict update a b v1 { |
| 1373 |
dict update v1 c v2 { |
| 1374 |
set v2 foo |
| 1375 |
} |
| 1376 |
} |
| 1377 |
return $a |
| 1378 |
} -cleanup { |
| 1379 |
unset a v1 v2 |
| 1380 |
} -result {b {c foo}} |
| 1381 |
test dict-21.11 {dict update command} -body { |
| 1382 |
set a {b c d e} |
| 1383 |
dict update a b v1 d v2 { |
| 1384 |
dict set a f g |
| 1385 |
} |
| 1386 |
return $a |
| 1387 |
} -cleanup { |
| 1388 |
unset a v1 v2 |
| 1389 |
} -result {b c d e f g} |
| 1390 |
test dict-21.12 {dict update command} -body { |
| 1391 |
set a {b c d e} |
| 1392 |
dict update a b v1 d v2 f v3 { |
| 1393 |
set v3 g |
| 1394 |
} |
| 1395 |
return $a |
| 1396 |
} -cleanup { |
| 1397 |
unset a v1 v2 v3 |
| 1398 |
} -result {b c d e f g} |
| 1399 |
test dict-21.13 {dict update command: compilation} { |
| 1400 |
apply {d { |
| 1401 |
while 1 { |
| 1402 |
dict update d a alpha b beta { |
| 1403 |
set beta $alpha |
| 1404 |
unset alpha |
| 1405 |
break |
| 1406 |
} |
| 1407 |
} |
| 1408 |
return $d |
| 1409 |
}} {a 1 c 2} |
| 1410 |
} {c 2 b 1} |
| 1411 |
test dict-21.14 {dict update command: compilation} { |
| 1412 |
apply {x { |
| 1413 |
set indices {2 3} |
| 1414 |
trace add variable aa write "string length \$indices ;#" |
| 1415 |
dict update x k aa l bb {} |
| 1416 |
}} {k 1 l 2} |
| 1417 |
} {} |
| 1418 |
test dict-21.15 {dict update command: compilation} { |
| 1419 |
apply {x { |
| 1420 |
set indices {2 3} |
| 1421 |
trace add variable aa read "string length \$indices ;#" |
| 1422 |
dict update x k aa l bb {} |
| 1423 |
}} {k 1 l 2} |
| 1424 |
} {} |
| 1425 |
test dict-21.16 {dict update command: no recursive structures [Bug 1786481]} -body { |
| 1426 |
set foo {a {b {c {d {e 1}}}}} |
| 1427 |
dict update foo a t { |
| 1428 |
dict update t b t { |
| 1429 |
dict update t c t { |
| 1430 |
dict update t d t { |
| 1431 |
dict incr t e |
| 1432 |
} |
| 1433 |
} |
| 1434 |
} |
| 1435 |
} |
| 1436 |
string range [append foo OK] end-1 end |
| 1437 |
} -cleanup { |
| 1438 |
unset foo t |
| 1439 |
} -result OK |
| 1440 |
test dict-21.17 {dict update command: no recursive structures [Bug 1786481]} { |
| 1441 |
apply {{} { |
| 1442 |
set foo {a {b {c {d {e 1}}}}} |
| 1443 |
dict update foo a t { |
| 1444 |
dict update t b t { |
| 1445 |
dict update t c t { |
| 1446 |
dict update t d t { |
| 1447 |
dict incr t e |
| 1448 |
} |
| 1449 |
} |
| 1450 |
} |
| 1451 |
} |
| 1452 |
string range [append foo OK] end-1 end |
| 1453 |
}} |
| 1454 |
} OK |
| 1455 |
|
| 1456 |
test dict-22.1 {dict with command} -body { |
| 1457 |
dict with |
| 1458 |
} -returnCodes 1 -result {wrong # args: should be "dict with dictVarName ?key ...? script"} |
| 1459 |
test dict-22.2 {dict with command} -body { |
| 1460 |
dict with v |
| 1461 |
} -returnCodes 1 -result {wrong # args: should be "dict with dictVarName ?key ...? script"} |
| 1462 |
test dict-22.3 {dict with command} -body { |
| 1463 |
unset -nocomplain v |
| 1464 |
dict with v {error "in body"} |
| 1465 |
} -returnCodes 1 -result {can't read "v": no such variable} |
| 1466 |
test dict-22.4 {dict with command} -body { |
| 1467 |
set a {b c d e} |
| 1468 |
unset -nocomplain b d |
| 1469 |
set result [list [info exist b] [info exist d]] |
| 1470 |
dict with a { |
| 1471 |
lappend result [info exist b] [info exist d] $b $d |
| 1472 |
} |
| 1473 |
return $result |
| 1474 |
} -cleanup { |
| 1475 |
unset a b d result |
| 1476 |
} -result {0 0 1 1 c e} |
| 1477 |
test dict-22.5 {dict with command} -body { |
| 1478 |
set a {b c d e} |
| 1479 |
dict with a { |
| 1480 |
lassign "$b $d" d b |
| 1481 |
} |
| 1482 |
return $a |
| 1483 |
} -cleanup { |
| 1484 |
unset a b d |
| 1485 |
} -result {b e d c} |
| 1486 |
test dict-22.6 {dict with command} -body { |
| 1487 |
set a {b c d e} |
| 1488 |
dict with a { |
| 1489 |
unset b |
| 1490 |
# This *won't* go into the dict... |
| 1491 |
set f g |
| 1492 |
} |
| 1493 |
return $a |
| 1494 |
} -cleanup { |
| 1495 |
unset a d f |
| 1496 |
} -result {d e} |
| 1497 |
test dict-22.7 {dict with command} -body { |
| 1498 |
set a {b c d e} |
| 1499 |
dict with a { |
| 1500 |
dict unset a b |
| 1501 |
} |
| 1502 |
return $a |
| 1503 |
} -cleanup { |
| 1504 |
unset a |
| 1505 |
} -result {d e b c} |
| 1506 |
test dict-22.8 {dict with command} -body { |
| 1507 |
set a [dict create b c] |
| 1508 |
dict with a { |
| 1509 |
set b $a |
| 1510 |
} |
| 1511 |
return $a |
| 1512 |
} -cleanup { |
| 1513 |
unset a b |
| 1514 |
} -result {b {b c}} |
| 1515 |
test dict-22.9 {dict with command} -body { |
| 1516 |
set a {b {c d}} |
| 1517 |
dict with a b { |
| 1518 |
set c $c$c |
| 1519 |
} |
| 1520 |
return $a |
| 1521 |
} -cleanup { |
| 1522 |
unset a c |
| 1523 |
} -result {b {c dd}} |
| 1524 |
test dict-22.10 {dict with command: result handling tricky case} -body { |
| 1525 |
set a {b {c d}} |
| 1526 |
foreach i {0 1} { |
| 1527 |
if {$i} break |
| 1528 |
dict with a b { |
| 1529 |
set a {} |
| 1530 |
# We're checking to see if we lose this break |
| 1531 |
break |
| 1532 |
} |
| 1533 |
} |
| 1534 |
list $i $a |
| 1535 |
} -cleanup { |
| 1536 |
unset a i c |
| 1537 |
} -result {0 {}} |
| 1538 |
test dict-22.11 {dict with command: no recursive structures [Bug 1786481]} -body { |
| 1539 |
set foo {t {t {t {inner 1}}}} |
| 1540 |
dict with foo { |
| 1541 |
dict with t { |
| 1542 |
dict with t { |
| 1543 |
dict with t { |
| 1544 |
incr inner |
| 1545 |
} |
| 1546 |
} |
| 1547 |
} |
| 1548 |
} |
| 1549 |
string range [append foo OK] end-1 end |
| 1550 |
} -cleanup { |
| 1551 |
unset foo t inner |
| 1552 |
} -result OK |
| 1553 |
test dict-22.12 {dict with: compiled} { |
| 1554 |
apply {{} { |
| 1555 |
set d {a 1 b 2} |
| 1556 |
list [dict with d { |
| 1557 |
set a $b |
| 1558 |
unset b |
| 1559 |
dict set d c 3 |
| 1560 |
list ok |
| 1561 |
}] $d |
| 1562 |
}} |
| 1563 |
} {ok {a 2 c 3}} |
| 1564 |
test dict-22.13 {dict with: compiled} { |
| 1565 |
apply {i { |
| 1566 |
set d($i) {a 1 b 2} |
| 1567 |
list [dict with d($i) { |
| 1568 |
set a $b |
| 1569 |
unset b |
| 1570 |
dict set d($i) c 3 |
| 1571 |
list ok |
| 1572 |
}] [array get d] |
| 1573 |
}} e |
| 1574 |
} {ok {e {a 2 c 3}}} |
| 1575 |
test dict-22.14 {dict with: compiled} { |
| 1576 |
apply {{} { |
| 1577 |
set d {a 1 b 2} |
| 1578 |
foreach x {1 2 3} { |
| 1579 |
dict with d { |
| 1580 |
incr a $b |
| 1581 |
if {$x == 2} break |
| 1582 |
} |
| 1583 |
unset a b |
| 1584 |
} |
| 1585 |
list $a $b $x $d |
| 1586 |
}} |
| 1587 |
} {5 2 2 {a 5 b 2}} |
| 1588 |
test dict-22.15 {dict with: compiled} { |
| 1589 |
apply {i { |
| 1590 |
set d($i) {a 1 b 2} |
| 1591 |
foreach x {1 2 3} { |
| 1592 |
dict with d($i) { |
| 1593 |
incr a $b |
| 1594 |
if {$x == 2} break |
| 1595 |
} |
| 1596 |
unset a b |
| 1597 |
} |
| 1598 |
list $a $b $x [array get d] |
| 1599 |
}} e |
| 1600 |
} {5 2 2 {e {a 5 b 2}}} |
| 1601 |
test dict-22.16 {dict with: compiled} { |
| 1602 |
apply {{} { |
| 1603 |
set d {p {q {a 1 b 2}}} |
| 1604 |
dict with d p q { |
| 1605 |
set a $b.$a |
| 1606 |
} |
| 1607 |
return $d |
| 1608 |
}} |
| 1609 |
} {p {q {a 2.1 b 2}}} |
| 1610 |
test dict-22.17 {dict with: compiled} { |
| 1611 |
apply {i { |
| 1612 |
set d($i) {p {q {a 1 b 2}}} |
| 1613 |
dict with d($i) p q { |
| 1614 |
set a $b.$a |
| 1615 |
} |
| 1616 |
array get d |
| 1617 |
}} e |
| 1618 |
} {e {p {q {a 2.1 b 2}}}} |
| 1619 |
test dict-22.18 {dict with: compiled} { |
| 1620 |
set ::d {a 1 b 2} |
| 1621 |
apply {{} { |
| 1622 |
dict with ::d { |
| 1623 |
set a $b.$a |
| 1624 |
} |
| 1625 |
return $::d |
| 1626 |
}} |
| 1627 |
} {a 2.1 b 2} |
| 1628 |
test dict-22.19 {dict with: compiled} { |
| 1629 |
set ::d {p {q {r {a 1 b 2}}}} |
| 1630 |
apply {{} { |
| 1631 |
dict with ::d p q r { |
| 1632 |
set a $b.$a |
| 1633 |
} |
| 1634 |
return $::d |
| 1635 |
}} |
| 1636 |
} {p {q {r {a 2.1 b 2}}}} |
| 1637 |
test dict-22.20 {dict with: compiled} { |
| 1638 |
apply {d { |
| 1639 |
dict with d { |
| 1640 |
} |
| 1641 |
return $a,$b |
| 1642 |
}} {a 1 b 2} |
| 1643 |
} 1,2 |
| 1644 |
test dict-22.21 {dict with: compiled} { |
| 1645 |
apply {d { |
| 1646 |
dict with d p q { |
| 1647 |
} |
| 1648 |
return $a,$b |
| 1649 |
}} {p {q {a 1 b 2}}} |
| 1650 |
} 1,2 |
| 1651 |
test dict-22.22 {dict with: compiled} { |
| 1652 |
set ::d {a 1 b 2} |
| 1653 |
apply {{} { |
| 1654 |
dict with ::d { |
| 1655 |
} |
| 1656 |
return $a,$b |
| 1657 |
}} |
| 1658 |
} 1,2 |
| 1659 |
test dict-22.23 {dict with: compiled} { |
| 1660 |
set ::d {p {q {a 1 b 2}}} |
| 1661 |
apply {{} { |
| 1662 |
dict with ::d p q { |
| 1663 |
} |
| 1664 |
return $a,$b |
| 1665 |
}} |
| 1666 |
} 1,2 |
| 1667 |
|
| 1668 |
proc linenumber {} { |
| 1669 |
dict get [info frame -1] line |
| 1670 |
} |
| 1671 |
test dict-23.1 {dict compilation crash: Bug 3487626} { |
| 1672 |
apply {{} {apply {n { |
| 1673 |
set e {} |
| 1674 |
set k {} |
| 1675 |
dict for {a b} {c {d {e {f g}}}} { |
| 1676 |
::tcl::dict::for {h i} $b { |
| 1677 |
dict update i e j { |
| 1678 |
::tcl::dict::update j f k { |
| 1679 |
return [expr {$n - [linenumber]}] |
| 1680 |
} |
| 1681 |
} |
| 1682 |
} |
| 1683 |
} |
| 1684 |
}} [linenumber]}} |
| 1685 |
} 5 |
| 1686 |
test dict-23.2 {dict compilation crash: Bug 3487626} { |
| 1687 |
# Something isn't quite right in line number and continuation line |
| 1688 |
# tracking; at time of writing, this test produces 7, not 5, which |
| 1689 |
# indicates that the extra newlines in the non-script argument are |
| 1690 |
# confusing things. |
| 1691 |
apply {{} {apply {n { |
| 1692 |
set e {} |
| 1693 |
set k {} |
| 1694 |
dict for {a { |
| 1695 |
b |
| 1696 |
}} {c {d {e {f g}}}} { |
| 1697 |
::tcl::dict::for {h { |
| 1698 |
i |
| 1699 |
}} ${ |
| 1700 |
b |
| 1701 |
} { |
| 1702 |
dict update { |
| 1703 |
i |
| 1704 |
} e { |
| 1705 |
j |
| 1706 |
} { |
| 1707 |
::tcl::dict::update { |
| 1708 |
j |
| 1709 |
} f k { |
| 1710 |
return [expr {$n - [linenumber]}] |
| 1711 |
} |
| 1712 |
} |
| 1713 |
} |
| 1714 |
} |
| 1715 |
}} [linenumber]}} |
| 1716 |
} 5 |
| 1717 |
rename linenumber {} |
| 1718 |
|
| 1719 |
test dict-24.1 {dict map command: syntax} -returnCodes error -body { |
| 1720 |
dict map |
| 1721 |
} -result {wrong # args: should be "dict map {keyVarName valueVarName} dictionary script"} |
| 1722 |
test dict-24.2 {dict map command: syntax} -returnCodes error -body { |
| 1723 |
dict map x |
| 1724 |
} -result {wrong # args: should be "dict map {keyVarName valueVarName} dictionary script"} |
| 1725 |
test dict-24.3 {dict map command: syntax} -returnCodes error -body { |
| 1726 |
dict map x x |
| 1727 |
} -result {wrong # args: should be "dict map {keyVarName valueVarName} dictionary script"} |
| 1728 |
test dict-24.4 {dict map command: syntax} -returnCodes error -body { |
| 1729 |
dict map x x x x |
| 1730 |
} -result {wrong # args: should be "dict map {keyVarName valueVarName} dictionary script"} |
| 1731 |
test dict-24.5 {dict map command: syntax} -returnCodes error -body { |
| 1732 |
dict map x x x |
| 1733 |
} -result {must have exactly two variable names} |
| 1734 |
test dict-24.6 {dict map command: syntax} -returnCodes error -body { |
| 1735 |
dict map {x x x} x x |
| 1736 |
} -result {must have exactly two variable names} |
| 1737 |
test dict-24.7 {dict map command: syntax} -returnCodes error -body { |
| 1738 |
dict map "\{x" x x |
| 1739 |
} -result {unmatched open brace in list} |
| 1740 |
test dict-24.8 {dict map command} -setup { |
| 1741 |
set values {} |
| 1742 |
set keys {} |
| 1743 |
} -body { |
| 1744 |
# This test confirms that [dict keys], [dict values] and [dict map] |
| 1745 |
# all traverse a dictionary in the same order. |
| 1746 |
set dictv {a A b B c C} |
| 1747 |
dict map {k v} $dictv { |
| 1748 |
lappend keys $k |
| 1749 |
lappend values $v |
| 1750 |
} |
| 1751 |
set result [expr { |
| 1752 |
$keys eq [dict keys $dictv] && $values eq [dict values $dictv] |
| 1753 |
}] |
| 1754 |
expr {$result ? "YES" : [list "NO" $dictv $keys $values]} |
| 1755 |
} -cleanup { |
| 1756 |
unset result keys values k v dictv |
| 1757 |
} -result YES |
| 1758 |
test dict-24.9 {dict map command} { |
| 1759 |
dict map {k v} {} { |
| 1760 |
error "unexpected execution of 'dict map' body" |
| 1761 |
} |
| 1762 |
} {} |
| 1763 |
test dict-24.10 {dict map command: script results} -body { |
| 1764 |
set times 0 |
| 1765 |
dict map {k v} {a a b b} { |
| 1766 |
incr times |
| 1767 |
continue |
| 1768 |
error "shouldn't get here" |
| 1769 |
} |
| 1770 |
return $times |
| 1771 |
} -cleanup { |
| 1772 |
unset times k v |
| 1773 |
} -result 2 |
| 1774 |
test dict-24.11 {dict map command: script results} -body { |
| 1775 |
set times 0 |
| 1776 |
dict map {k v} {a a b b} { |
| 1777 |
incr times |
| 1778 |
break |
| 1779 |
error "shouldn't get here" |
| 1780 |
} |
| 1781 |
return $times |
| 1782 |
} -cleanup { |
| 1783 |
unset times k v |
| 1784 |
} -result 1 |
| 1785 |
test dict-24.12 {dict map command: script results} -body { |
| 1786 |
set times 0 |
| 1787 |
list [catch { |
| 1788 |
dict map {k v} {a a b b} { |
| 1789 |
incr times |
| 1790 |
error test |
| 1791 |
} |
| 1792 |
} msg] $msg $times $::errorInfo |
| 1793 |
} -cleanup { |
| 1794 |
unset times k v msg |
| 1795 |
} -result {1 test 1 {test |
| 1796 |
while executing |
| 1797 |
"error test" |
| 1798 |
("dict map" body line 3) |
| 1799 |
invoked from within |
| 1800 |
"dict map {k v} {a a b b} { |
| 1801 |
incr times |
| 1802 |
error test |
| 1803 |
}"}} |
| 1804 |
test dict-24.13 {dict map command: script results} { |
| 1805 |
apply {{} { |
| 1806 |
dict map {k v} {a b} { |
| 1807 |
return ok,$k,$v |
| 1808 |
error "skipped return completely" |
| 1809 |
} |
| 1810 |
error "return didn't go far enough" |
| 1811 |
}} |
| 1812 |
} ok,a,b |
| 1813 |
test dict-24.14 {dict map command: handle representation loss} -setup { |
| 1814 |
set keys {} |
| 1815 |
set values {} |
| 1816 |
} -body { |
| 1817 |
set dictVar {a b c d e f g h} |
| 1818 |
list [dict size [dict map {k v} $dictVar { |
| 1819 |
if {[llength $dictVar]} { |
| 1820 |
lappend keys $k |
| 1821 |
lappend values $v |
| 1822 |
return -level 0 $k |
| 1823 |
} |
| 1824 |
}]] [lsort $keys] [lsort $values] |
| 1825 |
} -cleanup { |
| 1826 |
unset dictVar keys values k v |
| 1827 |
} -result {4 {a c e g} {b d f h}} |
| 1828 |
test dict-24.14a {dict map command: handle representation loss} -body { |
| 1829 |
apply {{} { |
| 1830 |
set dictVar {a b c d e f g h} |
| 1831 |
list [dict size [dict map {k v} $dictVar { |
| 1832 |
if {[llength $dictVar]} { |
| 1833 |
lappend keys $k |
| 1834 |
lappend values $v |
| 1835 |
return -level 0 $k |
| 1836 |
} |
| 1837 |
}]] [lsort $keys] [lsort $values] |
| 1838 |
}} |
| 1839 |
} -result {4 {a c e g} {b d f h}} |
| 1840 |
test dict-24.15 {dict map command: keys are unique and iterated over once only} -setup { |
| 1841 |
unset -nocomplain accum |
| 1842 |
array set accum {} |
| 1843 |
} -body { |
| 1844 |
set dictVar {a1 a a2 b b1 c b2 d foo bar bar foo} |
| 1845 |
dict map {k v} $dictVar { |
| 1846 |
append accum($k) $v, |
| 1847 |
} |
| 1848 |
set result [lsort [array names accum]] |
| 1849 |
lappend result : |
| 1850 |
foreach k $result { |
| 1851 |
catch {lappend result $accum($k)} |
| 1852 |
} |
| 1853 |
return $result |
| 1854 |
} -cleanup { |
| 1855 |
unset dictVar k v result accum |
| 1856 |
} -result {a1 a2 b1 b2 bar foo : a, b, c, d, foo, bar,} |
| 1857 |
test dict-24.16 {dict map command in compilation context} { |
| 1858 |
apply {{} { |
| 1859 |
set res {x x x x x x} |
| 1860 |
dict map {k v} {a 0 b 1 c 2 d 3 e 4 f 5} { |
| 1861 |
lset res $v $k |
| 1862 |
continue |
| 1863 |
} |
| 1864 |
return $res |
| 1865 |
}} |
| 1866 |
} {a b c d e f} |
| 1867 |
test dict-24.17 {dict map command in compilation context} { |
| 1868 |
# Bug 1379349 (dict for) |
| 1869 |
apply {{} { |
| 1870 |
set d [dict create a 1] ;# Dict must be unshared! |
| 1871 |
dict map {k v} $d { |
| 1872 |
dict set d $k 0 ;# Any modification will do |
| 1873 |
} |
| 1874 |
return $d |
| 1875 |
}} |
| 1876 |
} {a 0} |
| 1877 |
test dict-24.17a {dict map command in compilation context} { |
| 1878 |
# Bug 1379349 (dict for) |
| 1879 |
apply {{} { |
| 1880 |
set d [dict create a 1] ;# Dict must be unshared! |
| 1881 |
dict map {k v} $d { |
| 1882 |
dict set d $k 0 ;# Any modification will do |
| 1883 |
} |
| 1884 |
}} |
| 1885 |
} {a {a 0}} |
| 1886 |
test dict-24.18 {dict map command in compilation context} { |
| 1887 |
# Bug 1382528 (dict for) |
| 1888 |
apply {{} { |
| 1889 |
dict map {k v} {} {} ;# Note empty dict |
| 1890 |
catch { error foo } ;# Note compiled [catch] |
| 1891 |
}} |
| 1892 |
} 1 |
| 1893 |
test dict-24.19 {dict map and invalid dicts: 'dict for' bug 1531184} -body { |
| 1894 |
di[list]ct map {k v} x {} |
| 1895 |
} -returnCodes 1 -result {missing value to go with key} |
| 1896 |
test dict-24.20 {dict map stack space compilation: 'dict for' bug 1903325} { |
| 1897 |
apply {{x y args} { |
| 1898 |
dict map {a b} $x {} |
| 1899 |
concat "c=$y,$args" |
| 1900 |
}} {} 1 2 3 |
| 1901 |
} {c=1,2 3} |
| 1902 |
proc linenumber {} { |
| 1903 |
dict get [info frame -1] line |
| 1904 |
} |
| 1905 |
test dict-24.20.1 {dict compilation crash: 'dict for' bug 3487626} { |
| 1906 |
apply {{} {apply {n { |
| 1907 |
set e {} |
| 1908 |
set k {} |
| 1909 |
dict map {a b} {c {d {e {f g}}}} { |
| 1910 |
::tcl::dict::map {h i} $b { |
| 1911 |
dict update i e j { |
| 1912 |
::tcl::dict::update j f k { |
| 1913 |
return [expr {$n - [linenumber]}] |
| 1914 |
} |
| 1915 |
} |
| 1916 |
} |
| 1917 |
} |
| 1918 |
}} [linenumber]}} |
| 1919 |
} 5 |
| 1920 |
test dict-24.21 {dict compilation crash: 'dict for' bug 3487626} { |
| 1921 |
apply {{} {apply {n { |
| 1922 |
set e {} |
| 1923 |
set k {} |
| 1924 |
dict map {a { |
| 1925 |
b |
| 1926 |
}} {c {d {e {f g}}}} { |
| 1927 |
::tcl::dict::map {h { |
| 1928 |
i |
| 1929 |
}} ${ |
| 1930 |
b |
| 1931 |
} { |
| 1932 |
dict update { |
| 1933 |
i |
| 1934 |
} e { |
| 1935 |
j |
| 1936 |
} { |
| 1937 |
::tcl::dict::update { |
| 1938 |
j |
| 1939 |
} f k { |
| 1940 |
return [expr {$n - [linenumber]}] |
| 1941 |
} |
| 1942 |
} |
| 1943 |
} |
| 1944 |
} |
| 1945 |
}} [linenumber]}} |
| 1946 |
} 5 |
| 1947 |
test dict-23.3 {CompileWord OBOE} { |
| 1948 |
# segfault when buggy |
| 1949 |
apply {{} {tcl::dict::lappend foo bar \ |
| 1950 |
[format baz]}} |
| 1951 |
} {bar baz} |
| 1952 |
test dict-23.4 {CompileWord OBOE} { |
| 1953 |
apply {n { |
| 1954 |
dict set foo {*}{ |
| 1955 |
} [return [incr n -[linenumber]]] val |
| 1956 |
}} [linenumber] |
| 1957 |
} 1 |
| 1958 |
test dict-23.5 {CompileWord OBOE} { |
| 1959 |
# segfault when buggy |
| 1960 |
apply {{} {tcl::dict::incr foo \ |
| 1961 |
[format bar]}} |
| 1962 |
} {bar 1} |
| 1963 |
test dict-23.6 {CompileWord OBOE} { |
| 1964 |
apply {n { |
| 1965 |
dict get {a b} {*}{ |
| 1966 |
} [return [incr n -[linenumber]]] |
| 1967 |
}} [linenumber] |
| 1968 |
} 1 |
| 1969 |
test dict-23.7 {CompileWord OBOE} { |
| 1970 |
apply {n { |
| 1971 |
dict for {a b} [return [incr n -[linenumber]]] {*}{ |
| 1972 |
} {} |
| 1973 |
}} [linenumber] |
| 1974 |
} 2 |
| 1975 |
test dict-23.8 {CompileWord OBOE} { |
| 1976 |
apply {n { |
| 1977 |
dict update foo {*}{ |
| 1978 |
} [return [incr n -[linenumber]]] x {} |
| 1979 |
}} [linenumber] |
| 1980 |
} 1 |
| 1981 |
test dict-23.9 {CompileWord OBOE} { |
| 1982 |
apply {n { |
| 1983 |
dict exists {} {*}{ |
| 1984 |
} [return [incr n -[linenumber]]] |
| 1985 |
}} [linenumber] |
| 1986 |
} 1 |
| 1987 |
test dict-23.10 {CompileWord OBOE} { |
| 1988 |
apply {n { |
| 1989 |
dict with foo {*}{ |
| 1990 |
} [return [incr n -[linenumber]]] {} |
| 1991 |
}} [linenumber] |
| 1992 |
} 1 |
| 1993 |
test dict-23.11 {CompileWord OBOE} { |
| 1994 |
apply {n { |
| 1995 |
dict with ::foo {*}{ |
| 1996 |
} [return [incr n -[linenumber]]] {} |
| 1997 |
}} [linenumber] |
| 1998 |
} 1 |
| 1999 |
test dict-23.12 {CompileWord OBOE} { |
| 2000 |
apply {n { |
| 2001 |
dict with {*}{ |
| 2002 |
} [return [incr n -[linenumber]]] {} |
| 2003 |
}} [linenumber] |
| 2004 |
} 1 |
| 2005 |
test dict-23.13 {CompileWord OBOE} { |
| 2006 |
apply {n { |
| 2007 |
dict with {*}{ |
| 2008 |
} [return [incr n -[linenumber]]] {bar} |
| 2009 |
}} [linenumber] |
| 2010 |
} 1 |
| 2011 |
test dict-23.14 {CompileWord OBOE} { |
| 2012 |
apply {n { |
| 2013 |
dict with foo {*}{ |
| 2014 |
} [return [incr n -[linenumber]]] {bar} |
| 2015 |
}} [linenumber] |
| 2016 |
} 1 |
| 2017 |
|
| 2018 |
rename linenumber {} |
| 2019 |
test dict-24.22 {dict map results (non-compiled)} { |
| 2020 |
dict map {k v} [dict map {k v} {a 1 b 2 c 3 d 4} { list $v $k }] { |
| 2021 |
return -level 0 "$k,$v" |
| 2022 |
} |
| 2023 |
} {a {a,1 a} b {b,2 b} c {c,3 c} d {d,4 d}} |
| 2024 |
test dict-24.23 {dict map results (compiled)} { |
| 2025 |
apply {{} { |
| 2026 |
dict map {k v} [dict map {k v} {a 1 b 2 c 3 d 4} { list $v $k }] { |
| 2027 |
return -level 0 "$k,$v" |
| 2028 |
} |
| 2029 |
}} |
| 2030 |
} {a {a,1 a} b {b,2 b} c {c,3 c} d {d,4 d}} |
| 2031 |
test dict-24.23a {dict map results (compiled)} { |
| 2032 |
apply {{list} { |
| 2033 |
dict map {k v} [dict map {k v} $list { list $v $k }] { |
| 2034 |
return -level 0 "$k,$v" |
| 2035 |
} |
| 2036 |
}} {a 1 b 2 c 3 d 4} |
| 2037 |
} {a {a,1 a} b {b,2 b} c {c,3 c} d {d,4 d}} |
| 2038 |
test dict-24.24 {dict map with huge dict (non-compiled)} { |
| 2039 |
tcl::mathop::+ {*}[dict map {k v} [lsearch -all [lrepeat 100000 x] x] { |
| 2040 |
expr { $k * $v } |
| 2041 |
}] |
| 2042 |
} 166666666600000 |
| 2043 |
test dict-24.25 {dict map with huge dict (compiled)} { |
| 2044 |
apply {{n} { |
| 2045 |
tcl::mathop::+ {*}[dict map {k v} [lsearch -all [lrepeat $n y] y] { |
| 2046 |
expr { $k * $v } |
| 2047 |
}] |
| 2048 |
}} 100000 |
| 2049 |
} 166666666600000 |
| 2050 |
|
| 2051 |
test dict-25.1 {compiled dict update with low-refcount values [Bug d553228d9f]} { |
| 2052 |
# Test crashes on failure |
| 2053 |
apply {{} { |
| 2054 |
lassign {} item |
| 2055 |
dict update item item item two two {} |
| 2056 |
}} |
| 2057 |
} {} |
| 2058 |
|
| 2059 |
# cleanup |
| 2060 |
::tcltest::cleanupTests |
| 2061 |
return |
| 2062 |
|
| 2063 |
# Local Variables: |
| 2064 |
# mode: tcl |
| 2065 |
# End: |