aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--jim.c4
-rw-r--r--tests/string.test50
2 files changed, 52 insertions, 2 deletions
diff --git a/jim.c b/jim.c
index edb35d6..fe6ca50 100644
--- a/jim.c
+++ b/jim.c
@@ -2673,7 +2673,7 @@ Jim_Obj *JimStringReplaceObj(Jim_Interp *interp,
return NULL;
}
- if (last <= first) {
+ if (last < first) {
return strObjPtr;
}
@@ -13401,7 +13401,7 @@ badcompareargs:
Jim_Obj *objPtr;
if (argc != 5 && argc != 6) {
- Jim_WrongNumArgs(interp, 2, argv, "string first last ?newstring?");
+ Jim_WrongNumArgs(interp, 2, argv, "string first last ?string?");
return JIM_ERR;
}
objPtr = JimStringReplaceObj(interp, argv[2], argv[3], argv[4], argc == 6 ? argv[5] : NULL);
diff --git a/tests/string.test b/tests/string.test
index 0371f74..e4d5dc5 100644
--- a/tests/string.test
+++ b/tests/string.test
@@ -727,6 +727,56 @@ test string-13.13 {string repeat} {
string repeat \x00 3
} \x00\x00\x00
+test string-14.1 {string replace} {
+ list [catch {string replace} msg] $msg
+} {1 {wrong # args: should be "string replace string first last ?string?"}}
+test string-14.2 {string replace} {
+ list [catch {string replace a 1} msg] $msg
+} {1 {wrong # args: should be "string replace string first last ?string?"}}
+test string-14.3 {string replace} {
+ list [catch {string replace a 1 2 3 4} msg] $msg
+} {1 {wrong # args: should be "string replace string first last ?string?"}}
+test string-14.4 {string replace} {
+} {}
+test string-14.5 {string replace} {
+ string replace abcdefghijklmnop 2 14
+} {abp}
+test string-14.6 {string replace} {
+ string replace abcdefghijklmnop 7 1000
+} {abcdefg}
+test string-14.7 {string replace} {
+ string replace abcdefghijklmnop 10 end
+} {abcdefghij}
+test string-14.8 {string replace} {
+ string replace abcdefghijklmnop 10 9
+} {abcdefghijklmnop}
+test string-14.9 {string replace} {
+ string replace abcdefghijklmnop -3 2
+} {defghijklmnop}
+test string-14.10 {string replace} {
+ string replace abcdefghijklmnop -3 -2
+} {abcdefghijklmnop}
+test string-14.11 {string replace} {
+ string replace abcdefghijklmnop 1000 1010
+} {abcdefghijklmnop}
+test string-14.12 {string replace} {
+ string replace abcdefghijklmnop -100 end
+} {}
+test string-14.13 {string replace} {
+ list [catch {string replace abc abc 1} msg] $msg
+} {1 {bad index "abc": must be integer?[+-]integer? or end?[+-]integer?}}
+test string-14.14 {string replace} {
+ list [catch {string replace abc 1 eof} msg] $msg
+} {1 {bad index "eof": must be integer?[+-]integer? or end?[+-]integer?}}
+test string-14.15 {string replace} {
+ string replace abcdefghijklmnop end-10 end-2 NEW
+} {abcdeNEWop}
+test string-14.16 {string replace} {
+ string replace abcdefghijklmnop 0 end foo
+} {foo}
+test string-14.17 {string replace} {
+ string replace abcdefghijklmnop end end-1
+} {abcdefghijklmnop}
test string-15.1 {string tolower too few args} {
list [catch {string tolower} msg]