Skip to content

Commit 20b1ff5

Browse files
committed
regexp, regsub: usage closer to Tcl 9.0
Signed-off-by: Steve Bennett <[email protected]>
1 parent 5df0c03 commit 20b1ff5

File tree

3 files changed

+37
-27
lines changed

3 files changed

+37
-27
lines changed

jim-regexp.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ int Jim_RegexpCmd(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
149149
if (*opt != '-') {
150150
break;
151151
}
152-
if (Jim_GetEnum(interp, argv[i], options, &option, "switch", JIM_ERRMSG | JIM_ENUM_ABBREV) != JIM_OK) {
152+
if (Jim_GetEnum(interp, argv[i], options, &option, "option", JIM_ERRMSG | JIM_ENUM_ABBREV) != JIM_OK) {
153153
return JIM_ERR;
154154
}
155155
if (option == OPT_END) {
@@ -381,7 +381,7 @@ int Jim_RegsubCmd(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
381381
if (*opt != '-') {
382382
break;
383383
}
384-
if (Jim_GetEnum(interp, argv[i], options, &option, "switch", JIM_ERRMSG | JIM_ENUM_ABBREV) != JIM_OK) {
384+
if (Jim_GetEnum(interp, argv[i], options, &option, "option", JIM_ERRMSG | JIM_ENUM_ABBREV) != JIM_OK) {
385385
return JIM_ERR;
386386
}
387387
if (option == OPT_END) {
@@ -642,7 +642,7 @@ int Jim_RegsubCmd(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
642642
int Jim_regexpInit(Jim_Interp *interp)
643643
{
644644
Jim_PackageProvideCheck(interp, "regexp");
645-
Jim_RegisterSimpleCmd(interp, "regexp", "?-switch ...? exp string ?matchVar? ?subMatchVar ...?", 2, -1, Jim_RegexpCmd);
646-
Jim_RegisterSimpleCmd(interp, "regsub", "?-switch ...? exp string subSpec ?varName?", 3, -1, Jim_RegsubCmd);
645+
Jim_RegisterSimpleCmd(interp, "regexp", "?-option ...? exp string ?matchVar? ?subMatchVar ...?", 2, -1, Jim_RegexpCmd);
646+
Jim_RegisterSimpleCmd(interp, "regsub", "?-option ...? exp string subSpec ?varName?", 3, -1, Jim_RegsubCmd);
647647
return JIM_OK;
648648
}

tests/regexp.test

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -193,15 +193,17 @@ test regexp-5.5 {exercise cache of compiled expressions} {
193193
regexp .*e xe
194194
} 1
195195

196-
test regexp-6.1 {regexp errors} {
196+
test regexp-6.1 {regexp errors} -body {
197197
list [catch {regexp a} msg] $msg
198-
} {1 {wrong # args: should be "regexp ?-switch ...? exp string ?matchVar? ?subMatchVar ...?"}}
199-
test regexp-6.2 {regexp errors} {
198+
} -result {1 {wrong # args: should be "regexp ?-option ...? exp string ?matchVar? ?subMatchVar ...?"}}
199+
200+
test regexp-6.2 {regexp errors} -body {
200201
list [catch {regexp -nocase a} msg] $msg
201-
} {1 {wrong # args: should be "regexp ?-switch ...? exp string ?matchVar? ?subMatchVar ...?"}}
202+
} -result {1 {wrong # args: should be "regexp ?-option ...? exp string ?matchVar? ?subMatchVar ...?"}}
203+
202204
test regexp-6.3 {regexp errors} -constraints jim -body {
203205
list [catch {regexp -gorp a} msg] $msg
204-
} -result {1 {bad switch "-gorp": must be --, -all, -expanded, -indices, -inline, -line, -nocase, or -start}}
206+
} -result {1 {bad option "-gorp": must be --, -all, -expanded, -indices, -inline, -line, -nocase, or -start}}
205207
test regexp-6.4 {regexp errors} {
206208
catch {regexp a( b} msg
207209
} 1
@@ -219,13 +221,14 @@ test regexp-6.8 {regexp errors} jim {
219221
set f1 44
220222
list [catch {regexp abc abc f1(f2)} msg] $msg
221223
} {1 {can't set "f1(f2)": variable isn't array}}
222-
test regexp-6.9 {regexp errors, -start bad int check} {
224+
225+
test regexp-6.9 {regexp errors, -start bad int check} -body {
223226
list [catch {regexp -start bogus {^$} {}} msg] $msg
224-
} {1 {bad index "bogus": must be intexpr or end?[+-]intexpr?}}
225-
test regexp-6.10 {regexp errors, -start too few args} {
226-
list [catch {regexp -all -start} msg] $msg
227-
} {1 {wrong # args: should be "regexp ?-switch ...? exp string ?matchVar? ?subMatchVar ...?"}}
227+
} -match glob -result {1 {bad index "bogus": must be int* or end\?\[+-\]int*\?}}
228228

229+
test regexp-6.10 {regexp errors, -start too few args} -body {
230+
list [catch {regexp -all -start} msg] $msg
231+
} -result {1 {wrong # args: should be "regexp ?-option ...? exp string ?matchVar? ?subMatchVar ...?"}}
229232

230233
test regexp-7.1 {basic regsub operation} {
231234
list [regsub aa+ xaxaaaxaa 111&222 foo] $foo
@@ -355,19 +358,24 @@ test regexp-10.3 {newline sensitivity in regsub} {
355358

356359
test regexp-11.1 {regsub errors} {
357360
list [catch {regsub a b} msg] $msg
358-
} {1 {wrong # args: should be "regsub ?-switch ...? exp string subSpec ?varName?"}}
361+
} {1 {wrong # args: should be "regsub ?-option ...? exp string subSpec ?varName?"}}
359362
test regexp-11.2 {regsub errors} {
360363
list [catch {regsub -nocase a b} msg] $msg
361-
} {1 {wrong # args: should be "regsub ?-switch ...? exp string subSpec ?varName?"}}
364+
} {1 {wrong # args: should be "regsub ?-option ...? exp string subSpec ?varName?"}}
362365
test regexp-11.3 {regsub errors} {
363366
list [catch {regsub -nocase -all a b} msg] $msg
364-
} {1 {wrong # args: should be "regsub ?-switch ...? exp string subSpec ?varName?"}}
367+
} {1 {wrong # args: should be "regsub ?-option ...? exp string subSpec ?varName?"}}
365368
test regexp-11.4 {regsub errors} {
366369
list [catch {regsub a b c d e f} msg] $msg
367-
} {1 {wrong # args: should be "regsub ?-switch ...? exp string subSpec ?varName?"}}
370+
} {1 {wrong # args: should be "regsub ?-option ...? exp string subSpec ?varName?"}}
368371
test regexp-11.5 {regsub errors} -constraints jim -body {
369372
list [catch {regsub -gorp a b c} msg] $msg
370-
} -result {1 {bad switch "-gorp": must be --, -all, -command, -expanded, -line, -nocase, or -start}}
373+
} -result {1 {bad option "-gorp": must be --, -all, -command, -expanded, -line, -nocase, or -start}}
374+
375+
test regexp-11.5 {regsub errors} -constraints tcl -body {
376+
list [catch {regsub -gorp a b c} msg] $msg
377+
} -result {1 {bad option "-gorp": must be -all, -command, -expanded, -line, -linestop, -lineanchor, -nocase, -start, or --}}
378+
371379
test regexp-11.6 {regsub errors} {
372380
catch {regsub -nocase a( b c d} msg
373381
} 1
@@ -376,9 +384,11 @@ test regexp-11.7 {regsub errors} jim {
376384
set f1 44
377385
list [catch {regsub -nocase aaa aaa xxx f1(f2)} msg] $msg
378386
} {1 {can't set "f1(f2)": variable isn't array}}
379-
test regexp-11.8 {regsub errors, -start bad int check} {
387+
388+
test regexp-11.8 {regsub errors, -start bad int check} -body {
380389
list [catch {regsub -start bogus pattern string rep var} msg] $msg
381-
} {1 {bad index "bogus": must be intexpr or end?[+-]intexpr?}}
390+
} -match glob -result {1 {bad index "bogus": must be int* or end\?\[+-\]int*\?}}
391+
382392
test regexp-11.9 {regsub without final variable name returns value} {
383393
regsub b abaca X
384394
} {aXaca}
@@ -394,7 +404,7 @@ test regexp-11.12 {regsub without final variable name returns value} {
394404
} {a,bcd,c,ea,bcfd,cf,e}
395405
test regexp-11.13 {regsub errors, -start too few args} {
396406
list [catch {regsub -all -nocase -nocase -start} msg] $msg
397-
} {1 {wrong # args: should be "regsub ?-switch ...? exp string subSpec ?varName?"}}
407+
} {1 {wrong # args: should be "regsub ?-option ...? exp string subSpec ?varName?"}}
398408

399409

400410
# This test crashes on the Mac unless you increase the Stack Space to about 1

tests/regexp2.test

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -507,27 +507,27 @@ test regexpComp-11.1 {regsub errors} {
507507
evalInProc {
508508
list [catch {regsub a b} msg] $msg
509509
}
510-
} {1 {wrong # args: should be "regsub ?-switch ...? exp string subSpec ?varName?"}}
510+
} {1 {wrong # args: should be "regsub ?-option ...? exp string subSpec ?varName?"}}
511511
test regexpComp-11.2 {regsub errors} {
512512
evalInProc {
513513
list [catch {regsub -nocase a b} msg] $msg
514514
}
515-
} {1 {wrong # args: should be "regsub ?-switch ...? exp string subSpec ?varName?"}}
515+
} {1 {wrong # args: should be "regsub ?-option ...? exp string subSpec ?varName?"}}
516516
test regexpComp-11.3 {regsub errors} {
517517
evalInProc {
518518
list [catch {regsub -nocase -all a b} msg] $msg
519519
}
520-
} {1 {wrong # args: should be "regsub ?-switch ...? exp string subSpec ?varName?"}}
520+
} {1 {wrong # args: should be "regsub ?-option ...? exp string subSpec ?varName?"}}
521521
test regexpComp-11.4 {regsub errors} {
522522
evalInProc {
523523
list [catch {regsub a b c d e f} msg] $msg
524524
}
525-
} {1 {wrong # args: should be "regsub ?-switch ...? exp string subSpec ?varName?"}}
525+
} {1 {wrong # args: should be "regsub ?-option ...? exp string subSpec ?varName?"}}
526526
test regexpComp-11.5 {regsub errors} {
527527
evalInProc {
528528
list [catch {regsub -gorp a b c} msg] $msg
529529
}
530-
} {1 {bad switch "-gorp": must be --, -all, -command, -expanded, -line, -nocase, or -start}}
530+
} {1 {bad option "-gorp": must be --, -all, -command, -expanded, -line, -nocase, or -start}}
531531
test regexpComp-11.6 {regsub errors} {
532532
evalInProc {
533533
list [catch {regsub -nocase a( b c d} msg] $msg

0 commit comments

Comments
 (0)