diff options
author | Steve Bennett <steveb@workware.net.au> | 2024-01-27 10:39:28 +1000 |
---|---|---|
committer | Steve Bennett <steveb@workware.net.au> | 2024-01-29 10:40:38 +1000 |
commit | adb3252e5b213579ad26f101c25461c78829569c (patch) | |
tree | a62995a5b9bdaf51025f1cf8088f7eb8100bed79 /tests | |
parent | be3f8d5371de98934ce8344e4bfafe15ba57ecca (diff) | |
download | jimtcl-adb3252e5b213579ad26f101c25461c78829569c.zip jimtcl-adb3252e5b213579ad26f101c25461c78829569c.tar.gz jimtcl-adb3252e5b213579ad26f101c25461c78829569c.tar.bz2 |
regexp: implement regsub -command
Per Tcl 8.7
Signed-off-by: Steve Bennett <steveb@workware.net.au>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/regexp.test | 43 |
1 files changed, 41 insertions, 2 deletions
diff --git a/tests/regexp.test b/tests/regexp.test index a7c8a4a..7aeb72e 100644 --- a/tests/regexp.test +++ b/tests/regexp.test @@ -365,9 +365,9 @@ test regexp-11.3 {regsub errors} { test regexp-11.4 {regsub errors} { list [catch {regsub a b c d e f} msg] $msg } {1 {wrong # args: should be "regsub ?-switch ...? exp string subSpec ?varName?"}} -test regexp-11.5 {regsub errors} jim { +test regexp-11.5 {regsub errors} -constraints jim -body { list [catch {regsub -gorp a b c} msg] $msg -} {1 {bad switch "-gorp": must be --, -all, -line, -nocase, or -start}} +} -result {1 {bad switch "-gorp": must be --, -all, -command, -line, -nocase, or -start}} test regexp-11.6 {regsub errors} { catch {regsub -nocase a( b c d} msg } 1 @@ -742,6 +742,45 @@ test regexp-22.17 {\d in set} { regexp -all -inline {[a\d]+} "a0ac\[b a\]44c\tb-1aa7" } {a0a a 44 1aa7} +test regexp-27.1 {regsub -command} { + regsub -command {.x.} {abcxdef} {string length} +} ab3ef +test regexp-27.2 {regsub -command} { + regsub -command {.x.} {abcxdefxghi} {string length} +} ab3efxghi +test regexp-27.3 {regsub -command} { + set x 0 + regsub -all -command {(.)} abcde {apply {args {string cat [incr ::x] [lindex $args 1]}}} +} 1a2b3c4d5e +test regexp-27.4 {regsub -command} -body { + regsub -command {.x.} {abcxdef} error +} -returnCodes error -result cxd +test regexp-27.5 {regsub -command} { + regsub -command {(.)(.)} {abcdef} {list ,} +} {, ab a bcdef} +test regexp-27.6 {regsub -command} { + regsub -command -all {(.)(.)} {abcdef} {list ,} +} {, ab a b, cd c d, ef e f} +test regexp-27.7 {regsub -command representation smash} { + set ::s {123=456 789} + regsub -command -all {\d+} $::s {apply {n { + expr {[llength $::s] + $n} + }}} +} {125=458 791} +test regexp-27.8 {regsub -command representation smash} { + set ::t {apply {n { + expr {[llength [lindex $::t 1 1 1]] + $n} + }}} + regsub -command -all {\d+} "123=456 789" $::t +} {131=464 797} +test regexp-27.11 {regsub -command error cases} -returnCodes error -body { + regsub -command . abc {} +} -result {command prefix must be a list of at least one element} +test regexp-27.12 {regsub -command representation smash} { + set s {list (.+)} + regsub -command $s {list list} $s +} {(.+) {list list} list} + # Tests resulting from bugs reported by users test reg-31.1 {[[:xdigit:]] behaves correctly when followed by [[:space:]]} { set str {2:::DebugWin32} |