tcl: string command — 16 subcommands + 29 tests (156 total)
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Has been cancelled

Implements tcl-cmd-string covering length, index, range, compare, match
(glob * and ?), toupper, tolower, trim/trimleft/trimright, map, repeat,
first, last, is (integer/double/alpha/alnum/digit/space/upper/lower/boolean),
and cat. All 156 tcl tests pass (parse: 67, eval: 89).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-05-06 08:48:43 +00:00
parent ac013c9381
commit 9ed3e4faaf
2 changed files with 466 additions and 4 deletions

View File

@@ -205,6 +205,35 @@
"set x 5\nif {$x > 10} {set r big} elseif {$x > 3} {set r mid} else {set r small}")
"r")
"mid")
(ok "str-length" (get (run "string length hello") :result) "5")
(ok "str-length-empty" (get (run "string length {}") :result) "0")
(ok "str-index" (get (run "string index hello 1") :result) "e")
(ok "str-index-oob" (get (run "string index hello 99") :result) "")
(ok "str-range" (get (run "string range hello 1 3") :result) "ell")
(ok "str-range-clamp" (get (run "string range hello 3 99") :result) "lo")
(ok "str-compare-eq" (get (run "string compare abc abc") :result) "0")
(ok "str-compare-lt" (get (run "string compare abc abd") :result) "-1")
(ok "str-compare-gt" (get (run "string compare b a") :result) "1")
(ok "str-match-star" (get (run "string match h*o hello") :result) "1")
(ok "str-match-q" (get (run "string match h?llo hello") :result) "1")
(ok "str-match-no" (get (run "string match h*x hello") :result) "0")
(ok "str-toupper" (get (run "string toupper hello") :result) "HELLO")
(ok "str-tolower" (get (run "string tolower WORLD") :result) "world")
(ok "str-trim" (get (run "string trim { hi }") :result) "hi")
(ok "str-trimleft" (get (run "string trimleft { hi }") :result) "hi ")
(ok "str-trimright" (get (run "string trimright { hi }") :result) " hi")
(ok "str-trim-chars" (get (run "string trim {xxhelloxx} x") :result) "hello")
(ok "str-map" (get (run "string map {a X b Y} {abc}") :result) "XYc")
(ok "str-repeat" (get (run "string repeat ab 3") :result) "ababab")
(ok "str-first" (get (run "string first ll hello") :result) "2")
(ok "str-first-miss" (get (run "string first z hello") :result) "-1")
(ok "str-last" (get (run "string last l hello") :result) "3")
(ok "str-is-int" (get (run "string is integer 42") :result) "1")
(ok "str-is-not-int" (get (run "string is integer foo") :result) "0")
(ok "str-is-alpha" (get (run "string is alpha hello") :result) "1")
(ok "str-is-alpha-no" (get (run "string is alpha hello1") :result) "0")
(ok "str-is-boolean" (get (run "string is boolean true") :result) "1")
(ok "str-cat" (get (run "string cat foo bar baz") :result) "foobarbaz")
(dict
"passed"
tcl-eval-pass