tcl: dict commands — 13 subcommands (+24 tests, 206 total)
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 13s

Implements tcl-cmd-dict with create/get/set/unset/exists/keys/values/
size/for/update/merge/incr/append subcommands, plus helpers
tcl-dict-to-pairs, tcl-dict-from-pairs, tcl-dict-get, tcl-dict-set-pair,
tcl-dict-unset-key. Registers "dict" in make-default-tcl-interp.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-05-06 09:00:13 +00:00
parent 0dbf9b9f73
commit 263d9aae68
2 changed files with 305 additions and 1 deletions

View File

@@ -261,6 +261,31 @@
(ok "join-sep" (get (run "join {a b c} -") :result) "a-b-c")
(ok "join-default" (get (run "join {a b c}") :result) "a b c")
(ok "list-var" (get (run "set L {x y z}\nllength $L") :result) "3")
; --- dict command tests ---
(ok "dict-create" (get (run "dict create a 1 b 2") :result) "a 1 b 2")
(ok "dict-create-empty" (get (run "dict create") :result) "")
(ok "dict-get" (get (run "dict get {a 1 b 2} a") :result) "1")
(ok "dict-get-b" (get (run "dict get {a 1 b 2} b") :result) "2")
(ok "dict-exists-yes" (get (run "dict exists {a 1 b 2} a") :result) "1")
(ok "dict-exists-no" (get (run "dict exists {a 1 b 2} z") :result) "0")
(ok "dict-set-new" (get (run "set d {}\ndict set d x 42") :result) "x 42")
(ok "dict-set-update" (get (run "set d {a 1 b 2}\ndict set d a 99") :result) "a 99 b 2")
(ok "dict-set-stored" (tcl-var-get (run "set d {a 1}\ndict set d b 2") "d") "a 1 b 2")
(ok "dict-unset" (get (run "set d {a 1 b 2}\ndict unset d a") :result) "b 2")
(ok "dict-unset-stored" (tcl-var-get (run "set d {a 1 b 2}\ndict unset d a") "d") "b 2")
(ok "dict-keys" (get (run "dict keys {a 1 b 2}") :result) "a b")
(ok "dict-keys-pattern" (get (run "dict keys {abc 1 abd 2 xyz 3} ab*") :result) "abc abd")
(ok "dict-values" (get (run "dict values {a 1 b 2}") :result) "1 2")
(ok "dict-size" (get (run "dict size {a 1 b 2 c 3}") :result) "3")
(ok "dict-size-empty" (get (run "dict size {}") :result) "0")
(ok "dict-for" (tcl-var-get (run "set acc {}\ndict for {k v} {a 1 b 2} {append acc $k$v}") "acc") "a1b2")
(ok "dict-merge-disjoint" (get (run "dict merge {a 1} {b 2}") :result) "a 1 b 2")
(ok "dict-merge-overlap" (get (run "dict merge {a 1 b 2} {b 99}") :result) "a 1 b 99")
(ok "dict-incr-existing" (get (run "set d {x 5}\ndict incr d x") :result) "x 6")
(ok "dict-incr-delta" (get (run "set d {x 5}\ndict incr d x 3") :result) "x 8")
(ok "dict-incr-missing" (get (run "set d {}\ndict incr d n") :result) "n 1")
(ok "dict-append" (get (run "set d {x hello}\ndict append d x _hi") :result) "x hello_hi")
(ok "dict-append-new" (get (run "set d {}\ndict append d k val") :result) "k val")
(dict
"passed"
tcl-eval-pass