aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSteve Bennett <steveb@workware.net.au>2025-08-09 13:50:57 +1000
committerSteve Bennett <steveb@workware.net.au>2025-08-13 08:05:25 +1000
commit20b1ff593a51237d3a477c869815839d6ac526ae (patch)
treecb1b5177c45bc03c0b9064f01d47e669114b5ce6
parent5df0c03bee3149519a0c04891cb51b2b3f5f2d34 (diff)
downloadjimtcl-20b1ff593a51237d3a477c869815839d6ac526ae.zip
jimtcl-20b1ff593a51237d3a477c869815839d6ac526ae.tar.gz
jimtcl-20b1ff593a51237d3a477c869815839d6ac526ae.tar.bz2
regexp, regsub: usage closer to Tcl 9.0
Signed-off-by: Steve Bennett <steveb@workware.net.au>
-rw-r--r--jim-regexp.c8
-rw-r--r--tests/regexp.test46
-rw-r--r--tests/regexp2.test10
3 files changed, 37 insertions, 27 deletions
diff --git a/jim-regexp.c b/jim-regexp.c
index f2fc688..cf06e68 100644
--- a/jim-regexp.c
+++ b/jim-regexp.c
@@ -149,7 +149,7 @@ int Jim_RegexpCmd(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
if (*opt != '-') {
break;
}
- if (Jim_GetEnum(interp, argv[i], options, &option, "switch", JIM_ERRMSG | JIM_ENUM_ABBREV) != JIM_OK) {
+ if (Jim_GetEnum(interp, argv[i], options, &option, "option", JIM_ERRMSG | JIM_ENUM_ABBREV) != JIM_OK) {
return JIM_ERR;
}
if (option == OPT_END) {
@@ -381,7 +381,7 @@ int Jim_RegsubCmd(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
if (*opt != '-') {
break;
}
- if (Jim_GetEnum(interp, argv[i], options, &option, "switch", JIM_ERRMSG | JIM_ENUM_ABBREV) != JIM_OK) {
+ if (Jim_GetEnum(interp, argv[i], options, &option, "option", JIM_ERRMSG | JIM_ENUM_ABBREV) != JIM_OK) {
return JIM_ERR;
}
if (option == OPT_END) {
@@ -642,7 +642,7 @@ cmd_error:
int Jim_regexpInit(Jim_Interp *interp)
{
Jim_PackageProvideCheck(interp, "regexp");
- Jim_RegisterSimpleCmd(interp, "regexp", "?-switch ...? exp string ?matchVar? ?subMatchVar ...?", 2, -1, Jim_RegexpCmd);
- Jim_RegisterSimpleCmd(interp, "regsub", "?-switch ...? exp string subSpec ?varName?", 3, -1, Jim_RegsubCmd);
+ Jim_RegisterSimpleCmd(interp, "regexp", "?-option ...? exp string ?matchVar? ?subMatchVar ...?", 2, -1, Jim_RegexpCmd);
+ Jim_RegisterSimpleCmd(interp, "regsub", "?-option ...? exp string subSpec ?varName?", 3, -1, Jim_RegsubCmd);
return JIM_OK;
}
diff --git a/tests/regexp.test b/tests/regexp.test
index 0d86d6b..5adcaf3 100644
--- a/tests/regexp.test
+++ b/tests/regexp.test
@@ -193,15 +193,17 @@ test regexp-5.5 {exercise cache of compiled expressions} {
regexp .*e xe
} 1
-test regexp-6.1 {regexp errors} {
+test regexp-6.1 {regexp errors} -body {
list [catch {regexp a} msg] $msg
-} {1 {wrong # args: should be "regexp ?-switch ...? exp string ?matchVar? ?subMatchVar ...?"}}
-test regexp-6.2 {regexp errors} {
+} -result {1 {wrong # args: should be "regexp ?-option ...? exp string ?matchVar? ?subMatchVar ...?"}}
+
+test regexp-6.2 {regexp errors} -body {
list [catch {regexp -nocase a} msg] $msg
-} {1 {wrong # args: should be "regexp ?-switch ...? exp string ?matchVar? ?subMatchVar ...?"}}
+} -result {1 {wrong # args: should be "regexp ?-option ...? exp string ?matchVar? ?subMatchVar ...?"}}
+
test regexp-6.3 {regexp errors} -constraints jim -body {
list [catch {regexp -gorp a} msg] $msg
-} -result {1 {bad switch "-gorp": must be --, -all, -expanded, -indices, -inline, -line, -nocase, or -start}}
+} -result {1 {bad option "-gorp": must be --, -all, -expanded, -indices, -inline, -line, -nocase, or -start}}
test regexp-6.4 {regexp errors} {
catch {regexp a( b} msg
} 1
@@ -219,13 +221,14 @@ test regexp-6.8 {regexp errors} jim {
set f1 44
list [catch {regexp abc abc f1(f2)} msg] $msg
} {1 {can't set "f1(f2)": variable isn't array}}
-test regexp-6.9 {regexp errors, -start bad int check} {
+
+test regexp-6.9 {regexp errors, -start bad int check} -body {
list [catch {regexp -start bogus {^$} {}} msg] $msg
-} {1 {bad index "bogus": must be intexpr or end?[+-]intexpr?}}
-test regexp-6.10 {regexp errors, -start too few args} {
- list [catch {regexp -all -start} msg] $msg
-} {1 {wrong # args: should be "regexp ?-switch ...? exp string ?matchVar? ?subMatchVar ...?"}}
+} -match glob -result {1 {bad index "bogus": must be int* or end\?\[+-\]int*\?}}
+test regexp-6.10 {regexp errors, -start too few args} -body {
+ list [catch {regexp -all -start} msg] $msg
+} -result {1 {wrong # args: should be "regexp ?-option ...? exp string ?matchVar? ?subMatchVar ...?"}}
test regexp-7.1 {basic regsub operation} {
list [regsub aa+ xaxaaaxaa 111&222 foo] $foo
@@ -355,19 +358,24 @@ test regexp-10.3 {newline sensitivity in regsub} {
test regexp-11.1 {regsub errors} {
list [catch {regsub a b} msg] $msg
-} {1 {wrong # args: should be "regsub ?-switch ...? exp string subSpec ?varName?"}}
+} {1 {wrong # args: should be "regsub ?-option ...? exp string subSpec ?varName?"}}
test regexp-11.2 {regsub errors} {
list [catch {regsub -nocase a b} msg] $msg
-} {1 {wrong # args: should be "regsub ?-switch ...? exp string subSpec ?varName?"}}
+} {1 {wrong # args: should be "regsub ?-option ...? exp string subSpec ?varName?"}}
test regexp-11.3 {regsub errors} {
list [catch {regsub -nocase -all a b} msg] $msg
-} {1 {wrong # args: should be "regsub ?-switch ...? exp string subSpec ?varName?"}}
+} {1 {wrong # args: should be "regsub ?-option ...? exp string subSpec ?varName?"}}
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?"}}
+} {1 {wrong # args: should be "regsub ?-option ...? exp string subSpec ?varName?"}}
test regexp-11.5 {regsub errors} -constraints jim -body {
list [catch {regsub -gorp a b c} msg] $msg
-} -result {1 {bad switch "-gorp": must be --, -all, -command, -expanded, -line, -nocase, or -start}}
+} -result {1 {bad option "-gorp": must be --, -all, -command, -expanded, -line, -nocase, or -start}}
+
+test regexp-11.5 {regsub errors} -constraints tcl -body {
+ list [catch {regsub -gorp a b c} msg] $msg
+} -result {1 {bad option "-gorp": must be -all, -command, -expanded, -line, -linestop, -lineanchor, -nocase, -start, or --}}
+
test regexp-11.6 {regsub errors} {
catch {regsub -nocase a( b c d} msg
} 1
@@ -376,9 +384,11 @@ test regexp-11.7 {regsub errors} jim {
set f1 44
list [catch {regsub -nocase aaa aaa xxx f1(f2)} msg] $msg
} {1 {can't set "f1(f2)": variable isn't array}}
-test regexp-11.8 {regsub errors, -start bad int check} {
+
+test regexp-11.8 {regsub errors, -start bad int check} -body {
list [catch {regsub -start bogus pattern string rep var} msg] $msg
-} {1 {bad index "bogus": must be intexpr or end?[+-]intexpr?}}
+} -match glob -result {1 {bad index "bogus": must be int* or end\?\[+-\]int*\?}}
+
test regexp-11.9 {regsub without final variable name returns value} {
regsub b abaca X
} {aXaca}
@@ -394,7 +404,7 @@ test regexp-11.12 {regsub without final variable name returns value} {
} {a,bcd,c,ea,bcfd,cf,e}
test regexp-11.13 {regsub errors, -start too few args} {
list [catch {regsub -all -nocase -nocase -start} msg] $msg
-} {1 {wrong # args: should be "regsub ?-switch ...? exp string subSpec ?varName?"}}
+} {1 {wrong # args: should be "regsub ?-option ...? exp string subSpec ?varName?"}}
# This test crashes on the Mac unless you increase the Stack Space to about 1
diff --git a/tests/regexp2.test b/tests/regexp2.test
index 3f357b6..b61d768 100644
--- a/tests/regexp2.test
+++ b/tests/regexp2.test
@@ -507,27 +507,27 @@ test regexpComp-11.1 {regsub errors} {
evalInProc {
list [catch {regsub a b} msg] $msg
}
-} {1 {wrong # args: should be "regsub ?-switch ...? exp string subSpec ?varName?"}}
+} {1 {wrong # args: should be "regsub ?-option ...? exp string subSpec ?varName?"}}
test regexpComp-11.2 {regsub errors} {
evalInProc {
list [catch {regsub -nocase a b} msg] $msg
}
-} {1 {wrong # args: should be "regsub ?-switch ...? exp string subSpec ?varName?"}}
+} {1 {wrong # args: should be "regsub ?-option ...? exp string subSpec ?varName?"}}
test regexpComp-11.3 {regsub errors} {
evalInProc {
list [catch {regsub -nocase -all a b} msg] $msg
}
-} {1 {wrong # args: should be "regsub ?-switch ...? exp string subSpec ?varName?"}}
+} {1 {wrong # args: should be "regsub ?-option ...? exp string subSpec ?varName?"}}
test regexpComp-11.4 {regsub errors} {
evalInProc {
list [catch {regsub a b c d e f} msg] $msg
}
-} {1 {wrong # args: should be "regsub ?-switch ...? exp string subSpec ?varName?"}}
+} {1 {wrong # args: should be "regsub ?-option ...? exp string subSpec ?varName?"}}
test regexpComp-11.5 {regsub errors} {
evalInProc {
list [catch {regsub -gorp a b c} msg] $msg
}
-} {1 {bad switch "-gorp": must be --, -all, -command, -expanded, -line, -nocase, or -start}}
+} {1 {bad option "-gorp": must be --, -all, -command, -expanded, -line, -nocase, or -start}}
test regexpComp-11.6 {regsub errors} {
evalInProc {
list [catch {regsub -nocase a( b c d} msg] $msg