diff options
author | Steve Bennett <steveb@workware.net.au> | 2020-05-07 09:21:23 +1000 |
---|---|---|
committer | Steve Bennett <steveb@workware.net.au> | 2020-05-07 09:23:37 +1000 |
commit | a6c24e9c1a78da2ae9a5d5e6a110f26da40ac143 (patch) | |
tree | 87f009623110e373dceb5fc082e62147ffcf2aa1 /tests | |
parent | 659f043196f313c69e32876e3641d0865a1e49cd (diff) | |
download | jimtcl-a6c24e9c1a78da2ae9a5d5e6a110f26da40ac143.zip jimtcl-a6c24e9c1a78da2ae9a5d5e6a110f26da40ac143.tar.gz jimtcl-a6c24e9c1a78da2ae9a5d5e6a110f26da40ac143.tar.bz2 |
lsearch, switch: fix -regexp case with option-like pattern
If the pattern begins with -, the internal invocation of regexp
will treat the pattern as an option. Fix this by adding -- to the
internal invocation of regexp.
Fixes #154
Reported-by: Barry Arthur <barry.arthur@gmail.com>
Signed-off-by: Steve Bennett <steveb@workware.net.au>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/jim.test | 9 | ||||
-rw-r--r-- | tests/lsearch.test | 8 |
2 files changed, 17 insertions, 0 deletions
diff --git a/tests/jim.test b/tests/jim.test index 121e909..eaef8aa 100644 --- a/tests/jim.test +++ b/tests/jim.test @@ -2500,6 +2500,15 @@ test switch-3.7 {-exact vs. -glob vs. -regexp} { list [catch {switch -foo a b c} msg] $msg } {1 {bad option "-foo": must be -exact, -glob, -regexp, -command procname or --}} +test switch-3.8 {switch -regexp with option-like pattern} regexp { + switch -regexp -- -def { + -abc {concat first} + -def {concat second} + -ghi {concat third} + default {concat none} + } +} second + test switch-4.1 {error in executed command} { list [catch {switch a a {error "Just a test"} default {expr 1}} msg] \ $msg diff --git a/tests/lsearch.test b/tests/lsearch.test index 1eb6607..ff1342a 100644 --- a/tests/lsearch.test +++ b/tests/lsearch.test @@ -72,6 +72,14 @@ test lsearch-2.9 {search modes, -nocase} { lsearch -nocase -glob {b.x ^bc xy bcx} B* } 0 +test lsearch-2.10 {regexp with option-looking pattern} regexp { + lsearch -regexp {-abc -def -ghi} -def +} 1 + +test lsearch-2.11 {regexp with option-looking pattern, -nocase} regexp { + lsearch -nocase -regexp {-abc -def -ghi} -DEF +} 1 + test lsearch-3.1 {lsearch errors} { list [catch lsearch msg] } {1} |