diff options
author | apnadkarni <apnmbx-wits@yahoo.com> | 2022-09-16 07:29:15 (GMT) |
---|---|---|
committer | apnadkarni <apnmbx-wits@yahoo.com> | 2022-09-16 07:29:15 (GMT) |
commit | 0c5c7cc5eb0499b1b4f2b9000364ebe52186adf5 (patch) | |
tree | 42626beb2074ecd6db7c5b40491af679a7e87d12 | |
parent | 3baa5a5c2b5a25c4d03b03cd6cfb359860d82435 (diff) | |
download | tcl-0c5c7cc5eb0499b1b4f2b9000364ebe52186adf5.zip tcl-0c5c7cc5eb0499b1b4f2b9000364ebe52186adf5.tar.gz tcl-0c5c7cc5eb0499b1b4f2b9000364ebe52186adf5.tar.bz2 |
Rename lsubst to ledit, add docs
-rw-r--r-- | doc/interp.n | 20 | ||||
-rw-r--r-- | doc/lappend.n | 2 | ||||
-rw-r--r-- | doc/lassign.n | 2 | ||||
-rw-r--r-- | doc/ledit.n | 91 | ||||
-rw-r--r-- | doc/lindex.n | 2 | ||||
-rw-r--r-- | doc/linsert.n | 2 | ||||
-rw-r--r-- | doc/list.n | 2 | ||||
-rw-r--r-- | doc/llength.n | 2 | ||||
-rw-r--r-- | doc/lmap.n | 2 | ||||
-rw-r--r-- | doc/lpop.n | 2 | ||||
-rw-r--r-- | doc/lrange.n | 2 | ||||
-rw-r--r-- | doc/lremove.n | 2 | ||||
-rw-r--r-- | doc/lrepeat.n | 2 | ||||
-rw-r--r-- | doc/lreplace.n | 2 | ||||
-rw-r--r-- | doc/lreverse.n | 2 | ||||
-rw-r--r-- | doc/lsearch.n | 2 | ||||
-rw-r--r-- | doc/lset.n | 2 | ||||
-rw-r--r-- | doc/lsort.n | 2 | ||||
-rw-r--r-- | generic/tclBasic.c | 2 | ||||
-rw-r--r-- | generic/tclCmdIL.c | 8 | ||||
-rw-r--r-- | generic/tclInt.h | 6 | ||||
-rw-r--r-- | tests/lreplace.test | 264 |
22 files changed, 257 insertions, 166 deletions
diff --git a/doc/interp.n b/doc/interp.n index 2943404..b3cc918 100644 --- a/doc/interp.n +++ b/doc/interp.n @@ -591,16 +591,16 @@ built-in commands: \fBflush\fR \fBfor\fR \fBforeach\fR \fBformat\fR \fBgets\fR \fBglobal\fR \fBif\fR \fBincr\fR \fBinfo\fR \fBinterp\fR \fBjoin\fR \fBlappend\fR -\fBlassign\fR \fBlindex\fR \fBlinsert\fR \fBlist\fR -\fBllength\fR \fBlrange\fR \fBlrepeat\fR \fBlreplace\fR -\fBlsearch\fR \fBlset\fR \fBlsort\fR \fBnamespace\fR -\fBpackage\fR \fBpid\fR \fBproc\fR \fBputs\fR -\fBread\fR \fBregexp\fR \fBregsub\fR \fBrename\fR -\fBreturn\fR \fBscan\fR \fBseek\fR \fBset\fR -\fBsplit\fR \fBstring\fR \fBsubst\fR \fBswitch\fR -\fBtell\fR \fBtime\fR \fBtrace\fR \fBunset\fR -\fBupdate\fR \fBuplevel\fR \fBupvar\fR \fBvariable\fR -\fBvwait\fR \fBwhile\fR +\fBlassign\fR \fBledit\fR \fBlindex\fR \fBlinsert\fR +\fBlist\fR \fBllength\fR \fBlrange\fR \fBlrepeat\fR +\fBlreplace\fR \fBlsearch\fR \fBlset\fR \fBlsort\fR +\fBnamespace\fR \fBpackage\fR \fBpid\fR \fBproc\fR +\fBputs\fR \fBread\fR \fBregexp\fR \fBregsub\fR +\fBrename\fR \fBreturn\fR \fBscan\fR \fBseek\fR +\fBset\fR \fBsplit\fR \fBstring\fR \fBsubst\fR +\fBswitch\fR \fBtell\fR \fBtime\fR \fBtrace\fR +\fBunset\fR \fBupdate\fR \fBuplevel\fR \fBupvar\fR +\fBvariable\fR \fBvwait\fR \fBwhile\fR .DE The following commands are hidden by \fBinterp create\fR when it creates a safe interpreter: diff --git a/doc/lappend.n b/doc/lappend.n index 89b6909..3ddb36c 100644 --- a/doc/lappend.n +++ b/doc/lappend.n @@ -49,7 +49,7 @@ Using \fBlappend\fR to build up a list of numbers. 1 2 3 4 5 .CE .SH "SEE ALSO" -list(n), lassign(n), lindex(n), linsert(n), llength(n), +list(n), lassign(n), ledit(n), lindex(n), linsert(n), llength(n), lmap(n), lpop(n), lrange(n), lremove(n), lrepeat(n), lreplace(n), lreverse(n), lsearch(n), lset(n), lsort(n) .SH KEYWORDS diff --git a/doc/lassign.n b/doc/lassign.n index 67048ba..ac53322 100644 --- a/doc/lassign.n +++ b/doc/lassign.n @@ -52,7 +52,7 @@ command in many shell languages like this: set ::argv [\fBlassign\fR $::argv argumentToReadOff] .CE .SH "SEE ALSO" -list(n), lappend(n), lindex(n), linsert(n), llength(n), +list(n), lappend(n), ledit(n), lindex(n), linsert(n), llength(n), lmap(n), lpop(n), lrange(n), lremove(n), lrepeat(n), lreplace(n), lreverse(n), lsearch(n), lset(n), lsort(n) .SH KEYWORDS diff --git a/doc/ledit.n b/doc/ledit.n new file mode 100644 index 0000000..f7704ed --- /dev/null +++ b/doc/ledit.n @@ -0,0 +1,91 @@ +'\" +'\" Copyright (c) 2022 Ashok P. Nadkarni <apnmbx-public@yahoo.com>. All rights reserved. +'\" +'\" See the file "license.terms" for information on usage and redistribution +'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES. +'\" +.TH ledit n 8.7 Tcl "Tcl Built-In Commands" +.so man.macros +.BS +'\" Note: do not modify the .SH NAME line immediately below! +.SH NAME +ledit \- Replace elements of a list stored in variable +.SH SYNOPSIS +\fBledit \fIlistVar first last \fR?\fIvalue value ...\fR? +.BE +.SH DESCRIPTION +.PP +The command fetches the list value in variable \fIlistVar\fR and replaces the +elements in the range given by indices \fIfirst\fR to \fIlast\fR (inclusive) +with the \fIvalue\fR arguments. The resulting list is then stored back in +\fIlistVar\fR and returned as the result of the command. +.PP +Arguments \fIfirst\fR and \fIlast\fR are index values specifying the first and +last elements of the range to replace. They are interpreted +the same as index values for the command \fBstring index\fR, +supporting simple index arithmetic and indices relative to the +end of the list. The index 0 refers to the first element of the +list, and \fBend\fR refers to the last element of the list. +.PP +If either \fIfirst\fR or \fIlast\fR is less than zero, it is considered to +refer to the position before the first element of the list. This allows +elements to be prepended. +.PP +If either \fIfirst\fR or \fIlast\fR indicates a position greater than the +index of the last element of the list, it is treated as if it is an +index one greater than the last element. This allows elements to be appended. +.PP +If \fIlast\fR is less than \fIfirst\fR, then any specified elements +will be inserted into the list before the element specified by \fIfirst\fR +with no elements being deleted. +.PP +The \fIvalue\fR arguments specify zero or more new elements to +be added to the list in place of those that were deleted. +Each \fIvalue\fR argument will become a separate element of +the list. If no \fIvalue\fR arguments are specified, then the elements +between \fIfirst\fR and \fIlast\fR are simply deleted. +.SH EXAMPLES +.PP +Prepend to a list. +.PP +.CS +% set lst {c d e f g} +c d e f g +% ledit lst -1 -1 a b +a b c d e f g +.CE +.PP +Append to the list. +.PP +.CS +% ledit lst end+1 end+1 h i +a b c d e f g h i +.CE +.PP +Delete third and fourth elements. +.PP +.CS +% ledit lst 2 3 +a b e f g h i +.CE +.PP +Replace two elements with three. +.PP +.CS +% ledit lst 2 3 x y z +a b x y z g h i +% set lst +a b x y z g h i +.CE +.PP +.SH "SEE ALSO" +list(n), lappend(n), lassign(n), lindex(n), linsert(n), llength(n), +lmap(n), lpop(n), lrange(n), lremove(n), lrepeat(n), lreplace(n), +lreverse(n), lsearch(n), lset(n), lsort(n), +string(n) +.SH KEYWORDS +element, list, replace +.\" Local variables: +.\" mode: nroff +.\" fill-column: 78 +.\" End: diff --git a/doc/lindex.n b/doc/lindex.n index 75fe5e8..0ba30a4 100644 --- a/doc/lindex.n +++ b/doc/lindex.n @@ -115,7 +115,7 @@ set idx 3 \fI\(-> f\fR .CE .SH "SEE ALSO" -list(n), lappend(n), lassign(n), linsert(n), llength(n), +list(n), lappend(n), lassign(n), ledit(n), linsert(n), llength(n), lmap(n), lpop(n), lrange(n), lremove(n), lrepeat(n), lreplace(n), lreverse(n), lsearch(n), lset(n), lsort(n), string(n) diff --git a/doc/linsert.n b/doc/linsert.n index 3179256..685b563 100644 --- a/doc/linsert.n +++ b/doc/linsert.n @@ -45,7 +45,7 @@ set newList [\fBlinsert\fR $midList end-1 lazy] set newerList [\fBlinsert\fR [\fBlinsert\fR $oldList end-1 quick] 1 lazy] .CE .SH "SEE ALSO" -list(n), lappend(n), lassign(n), lindex(n), llength(n), +list(n), lappend(n), lassign(n), ledit(n), lindex(n), llength(n), lmap(n), lpop(n), lrange(n), lremove(n), lrepeat(n), lreplace(n), lreverse(n), lsearch(n), lset(n), lsort(n), string(n) @@ -46,7 +46,7 @@ while \fBconcat\fR with the same arguments will return \fBa b c d e f {g h}\fR .CE .SH "SEE ALSO" -lappend(n), lassign(n), lindex(n), linsert(n), llength(n), +lappend(n), lassign(n), ledit(n), lindex(n), linsert(n), llength(n), lmap(n), lpop(n), lrange(n), lremove(n), lrepeat(n), lreplace(n), lreverse(n), lsearch(n), lset(n), lsort(n) .SH KEYWORDS diff --git a/doc/llength.n b/doc/llength.n index 26824a0..7a3e6de 100644 --- a/doc/llength.n +++ b/doc/llength.n @@ -49,7 +49,7 @@ An empty list is not necessarily an empty string: 1,0 .CE .SH "SEE ALSO" -list(n), lappend(n), lassign(n), lindex(n), linsert(n), +list(n), lappend(n), lassign(n), ledit(n), lindex(n), linsert(n), lmap(n), lpop(n), lrange(n), lremove(n), lrepeat(n), lreplace(n), lreverse(n), lsearch(n), lset(n), lsort(n) .SH KEYWORDS @@ -78,7 +78,7 @@ set prefix [\fBlmap\fR x $values {expr { .CE .SH "SEE ALSO" break(n), continue(n), for(n), foreach(n), while(n), -list(n), lappend(n), lassign(n), lindex(n), linsert(n), llength(n), +list(n), lappend(n), lassign(n), ledit(n), lindex(n), linsert(n), llength(n), lpop(n), lrange(n), lremove(n), lrepeat(n), lreplace(n), lreverse(n), lsearch(n), lset(n), lsort(n) .SH KEYWORDS @@ -86,7 +86,7 @@ The indicated value becomes the new value of \fIx\fR. \fI\(-> {{a b} {c d}} {{e f} h}\fR .CE .SH "SEE ALSO" -list(n), lappend(n), lassign(n), lindex(n), linsert(n), llength(n), +list(n), lappend(n), lassign(n), ledit(n), lindex(n), linsert(n), llength(n), lmap(n), lrange(n), lremove(n), lrepeat(n), lreplace(n), lreverse(n), lsearch(n), lset(n), lsort(n), string(n) diff --git a/doc/lrange.n b/doc/lrange.n index 0d4b261..c0434bb 100644 --- a/doc/lrange.n +++ b/doc/lrange.n @@ -71,7 +71,7 @@ elements to {elements to} .CE .SH "SEE ALSO" -list(n), lappend(n), lassign(n), lindex(n), linsert(n), llength(n), +list(n), lappend(n), lassign(n), ledit(n), lindex(n), linsert(n), llength(n), lmap(n), lpop(n), lremove(n), lrepeat(n), lreplace(n), lreverse(n), lsearch(n), lset(n), lsort(n), string(n) diff --git a/doc/lremove.n b/doc/lremove.n index 59d261b..e71f607 100644 --- a/doc/lremove.n +++ b/doc/lremove.n @@ -46,7 +46,7 @@ Removing the same element indicated in two different ways: a b d e .CE .SH "SEE ALSO" -list(n), lappend(n), lassign(n), lindex(n), linsert(n), llength(n), +list(n), lappend(n), lassign(n), ledit(n), lindex(n), linsert(n), llength(n), lmap(n), lpop(n), lrange(n), lrepeat(n), lreplace(n), lreverse(n), lsearch(n), lset(n), lsort(n) .SH KEYWORDS diff --git a/doc/lrepeat.n b/doc/lrepeat.n index 9a3fc88..de7ba54 100644 --- a/doc/lrepeat.n +++ b/doc/lrepeat.n @@ -32,7 +32,7 @@ is identical to \fBlist element ...\fR. \fI\(-> {a a} b c {a a} b c {a a} b c\fR .CE .SH "SEE ALSO" -list(n), lappend(n), lassign(n), lindex(n), linsert(n), llength(n), +list(n), lappend(n), lassign(n), ledit(n), lindex(n), linsert(n), llength(n), lmap(n), lpop(n), lrange(n), lremove(n), lreplace(n), lreverse(n), lsearch(n), lset(n), lsort(n) .SH KEYWORDS diff --git a/doc/lreplace.n b/doc/lreplace.n index bc9d7ca..6694ad7 100644 --- a/doc/lreplace.n +++ b/doc/lreplace.n @@ -95,7 +95,7 @@ a b c d e f g h i .CE .VE TIP505 .SH "SEE ALSO" -list(n), lappend(n), lassign(n), lindex(n), linsert(n), llength(n), +list(n), lappend(n), lassign(n), ledit(n), lindex(n), linsert(n), llength(n), lmap(n), lpop(n), lrange(n), lremove(n), lrepeat(n), lreverse(n), lsearch(n), lset(n), lsort(n), string(n) diff --git a/doc/lreverse.n b/doc/lreverse.n index e2e3b69..0f0b6d6 100644 --- a/doc/lreverse.n +++ b/doc/lreverse.n @@ -25,7 +25,7 @@ input list, \fIlist\fR, except with the elements in the reverse order. \fI\(-> f e {c d} b a\fR .CE .SH "SEE ALSO" -list(n), lappend(n), lassign(n), lindex(n), linsert(n), llength(n), +list(n), lappend(n), lassign(n), ledit(n), lindex(n), linsert(n), llength(n), lmap(n), lpop(n), lrange(n), lremove(n), lrepeat(n), lreplace(n), lsearch(n), lset(n), lsort(n) .SH KEYWORDS diff --git a/doc/lsearch.n b/doc/lsearch.n index c5dc98f..85b8609 100644 --- a/doc/lsearch.n +++ b/doc/lsearch.n @@ -229,7 +229,7 @@ The same thing for a flattened list: .CE .SH "SEE ALSO" foreach(n), -list(n), lappend(n), lassign(n), lindex(n), linsert(n), llength(n), +list(n), lappend(n), lassign(n), ledit(n), lindex(n), linsert(n), llength(n), lmap(n), lpop(n), lrange(n), lremove(n), lrepeat(n), lreplace(n), lreverse(n), lset(n), lsort(n), string(n) @@ -136,7 +136,7 @@ The indicated return value also becomes the new value of \fIx\fR. \fI\(-> {{a b} {c d}} {{e f} {j h}}\fR .CE .SH "SEE ALSO" -list(n), lappend(n), lassign(n), lindex(n), linsert(n), llength(n), +list(n), lappend(n), lassign(n), ledit(n), lindex(n), linsert(n), llength(n), lmap(n), lpop(n), lrange(n), lremove(n), lrepeat(n), lreplace(n), lreverse(n), lsearch(n), lsort(n) string(n) diff --git a/doc/lsort.n b/doc/lsort.n index 2018e30..ddf9ed1 100644 --- a/doc/lsort.n +++ b/doc/lsort.n @@ -264,7 +264,7 @@ More complex sorting using a comparison function: {1 dingo} {2 banana} {0x2 carrot} {3 apple} .CE .SH "SEE ALSO" -list(n), lappend(n), lassign(n), lindex(n), linsert(n), llength(n), +list(n), lappend(n), lassign(n), ledit(n), lindex(n), linsert(n), llength(n), lmap(n), lpop(n), lrange(n), lremove(n), lrepeat(n), lreplace(n), lreverse(n), lsearch(n), lset(n) .SH KEYWORDS diff --git a/generic/tclBasic.c b/generic/tclBasic.c index b013909..21503b4 100644 --- a/generic/tclBasic.c +++ b/generic/tclBasic.c @@ -324,7 +324,7 @@ static const CmdInfo builtInCmds[] = { {"lsearch", Tcl_LsearchObjCmd, NULL, NULL, CMD_IS_SAFE}, {"lset", Tcl_LsetObjCmd, TclCompileLsetCmd, NULL, CMD_IS_SAFE}, {"lsort", Tcl_LsortObjCmd, NULL, NULL, CMD_IS_SAFE}, - {"lsubst", Tcl_LsubstObjCmd, NULL, NULL, CMD_IS_SAFE}, + {"ledit", Tcl_LeditObjCmd, NULL, NULL, CMD_IS_SAFE}, {"package", Tcl_PackageObjCmd, NULL, TclNRPackageObjCmd, CMD_IS_SAFE}, {"proc", Tcl_ProcObjCmd, NULL, NULL, CMD_IS_SAFE}, {"regexp", Tcl_RegexpObjCmd, TclCompileRegexpCmd, NULL, CMD_IS_SAFE}, diff --git a/generic/tclCmdIL.c b/generic/tclCmdIL.c index 7776c78..b2e3ac8 100644 --- a/generic/tclCmdIL.c +++ b/generic/tclCmdIL.c @@ -4486,9 +4486,9 @@ Tcl_LsortObjCmd( /* *---------------------------------------------------------------------- * - * Tcl_LsubstObjCmd -- + * Tcl_LeditObjCmd -- * - * This procedure is invoked to process the "lsubst" Tcl command. See the + * This procedure is invoked to process the "ledit" Tcl command. See the * user documentation for details on what it does. * * Results: @@ -4501,7 +4501,7 @@ Tcl_LsortObjCmd( */ int -Tcl_LsubstObjCmd( +Tcl_LeditObjCmd( TCL_UNUSED(ClientData), Tcl_Interp *interp, /* Current interpreter. */ int objc, /* Number of arguments. */ @@ -4529,7 +4529,7 @@ Tcl_LsubstObjCmd( /* * TODO - refactor the index extraction into a common function shared - * by Tcl_{Lrange,Lreplace,Lsubst}ObjCmd + * by Tcl_{Lrange,Lreplace,Ledit}ObjCmd */ result = TclListObjLengthM(interp, listPtr, &listLen); diff --git a/generic/tclInt.h b/generic/tclInt.h index 155bb82..863251b 100644 --- a/generic/tclInt.h +++ b/generic/tclInt.h @@ -3686,6 +3686,9 @@ MODULE_SCOPE int Tcl_LappendObjCmd(void *clientData, MODULE_SCOPE int Tcl_LassignObjCmd(void *clientData, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[]); +MODULE_SCOPE int Tcl_LeditObjCmd(ClientData clientData, + Tcl_Interp *interp, int objc, + Tcl_Obj *const objv[]); MODULE_SCOPE int Tcl_LindexObjCmd(void *clientData, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[]); @@ -3731,9 +3734,6 @@ MODULE_SCOPE int Tcl_LsetObjCmd(void *clientData, MODULE_SCOPE int Tcl_LsortObjCmd(void *clientData, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[]); -MODULE_SCOPE int Tcl_LsubstObjCmd(ClientData clientData, - Tcl_Interp *interp, int objc, - Tcl_Obj *const objv[]); MODULE_SCOPE Tcl_Command TclInitNamespaceCmd(Tcl_Interp *interp); MODULE_SCOPE int TclNamespaceEnsembleCmd(void *dummy, Tcl_Interp *interp, int objc, diff --git a/tests/lreplace.test b/tests/lreplace.test index 4204c2f..2952899 100644 --- a/tests/lreplace.test +++ b/tests/lreplace.test @@ -236,272 +236,272 @@ apply {{} { } }} -# Essentially same tests as above but for lsubst -test lsubst-1.1 {lsubst command} { +# Essentially same tests as above but for ledit +test ledit-1.1 {ledit command} { set l {1 2 3 4 5} - list [lsubst l 0 0 a] $l + list [ledit l 0 0 a] $l } {{a 2 3 4 5} {a 2 3 4 5}} -test lsubst-1.2 {lsubst command} { +test ledit-1.2 {ledit command} { set l {1 2 3 4 5} - list [lsubst l 1 1 a] $l + list [ledit l 1 1 a] $l } {{1 a 3 4 5} {1 a 3 4 5}} -test lsubst-1.3 {lsubst command} { +test ledit-1.3 {ledit command} { set l {1 2 3 4 5} - list [lsubst l 2 2 a] $l + list [ledit l 2 2 a] $l } {{1 2 a 4 5} {1 2 a 4 5}} -test lsubst-1.4 {lsubst command} { +test ledit-1.4 {ledit command} { set l {1 2 3 4 5} - list [lsubst l 3 3 a] $l + list [ledit l 3 3 a] $l } {{1 2 3 a 5} {1 2 3 a 5}} -test lsubst-1.5 {lsubst command} { +test ledit-1.5 {ledit command} { set l {1 2 3 4 5} - list [lsubst l 4 4 a] $l + list [ledit l 4 4 a] $l } {{1 2 3 4 a} {1 2 3 4 a}} -test lsubst-1.6 {lsubst command} { +test ledit-1.6 {ledit command} { set l {1 2 3 4 5} - list [lsubst l 4 5 a] $l + list [ledit l 4 5 a] $l } {{1 2 3 4 a} {1 2 3 4 a}} -test lsubst-1.7 {lsubst command} { +test ledit-1.7 {ledit command} { set l {1 2 3 4 5} - list [lsubst l -1 -1 a] $l + list [ledit l -1 -1 a] $l } {{a 1 2 3 4 5} {a 1 2 3 4 5}} -test lsubst-1.8 {lsubst command} { +test ledit-1.8 {ledit command} { set l {1 2 3 4 5} - list [lsubst l 2 end a b c d] $l + list [ledit l 2 end a b c d] $l } {{1 2 a b c d} {1 2 a b c d}} -test lsubst-1.9 {lsubst command} { +test ledit-1.9 {ledit command} { set l {1 2 3 4 5} - list [lsubst l 0 3] $l + list [ledit l 0 3] $l } {5 5} -test lsubst-1.10 {lsubst command} { +test ledit-1.10 {ledit command} { set l {1 2 3 4 5} - list [lsubst l 0 4] $l + list [ledit l 0 4] $l } {{} {}} -test lsubst-1.11 {lsubst command} { +test ledit-1.11 {ledit command} { set l {1 2 3 4 5} - list [lsubst l 0 1] $l + list [ledit l 0 1] $l } {{3 4 5} {3 4 5}} -test lsubst-1.12 {lsubst command} { +test ledit-1.12 {ledit command} { set l {1 2 3 4 5} - list [lsubst l 2 3] $l + list [ledit l 2 3] $l } {{1 2 5} {1 2 5}} -test lsubst-1.13 {lsubst command} { +test ledit-1.13 {ledit command} { set l {1 2 3 4 5} - list [lsubst l 3 end] $l + list [ledit l 3 end] $l } {{1 2 3} {1 2 3}} -test lsubst-1.14 {lsubst command} { +test ledit-1.14 {ledit command} { set l {1 2 3 4 5} - list [lsubst l -1 4 a b c] $l + list [ledit l -1 4 a b c] $l } {{a b c} {a b c}} -test lsubst-1.15 {lsubst command} { +test ledit-1.15 {ledit command} { set l {a b "c c" d e f} - list [lsubst l 3 3] $l + list [ledit l 3 3] $l } {{a b {c c} e f} {a b {c c} e f}} -test lsubst-1.16 {lsubst command} { +test ledit-1.16 {ledit command} { set l { 1 2 3 4 5} - list [lsubst l 0 0 a] $l + list [ledit l 0 0 a] $l } {{a 2 3 4 5} {a 2 3 4 5}} -test lsubst-1.17 {lsubst command} { +test ledit-1.17 {ledit command} { set l {1 2 3 4 "5 6"} - list [lsubst l 4 4 a] $l + list [ledit l 4 4 a] $l } {{1 2 3 4 a} {1 2 3 4 a}} -test lsubst-1.18 {lsubst command} { +test ledit-1.18 {ledit command} { set l {1 2 3 4 {5 6}} - list [lsubst l 4 4 a] $l + list [ledit l 4 4 a] $l } {{1 2 3 4 a} {1 2 3 4 a}} -test lsubst-1.19 {lsubst command} { +test ledit-1.19 {ledit command} { set l {1 2 3 4} - list [lsubst l 2 end x y z] $l + list [ledit l 2 end x y z] $l } {{1 2 x y z} {1 2 x y z}} -test lsubst-1.20 {lsubst command} { +test ledit-1.20 {ledit command} { set l {1 2 3 4} - list [lsubst l end end a] $l + list [ledit l end end a] $l } {{1 2 3 a} {1 2 3 a}} -test lsubst-1.21 {lsubst command} { +test ledit-1.21 {ledit command} { set l {1 2 3 4} - list [lsubst l end 3 a] $l + list [ledit l end 3 a] $l } {{1 2 3 a} {1 2 3 a}} -test lsubst-1.22 {lsubst command} { +test ledit-1.22 {ledit command} { set l {1 2 3 4} - list [lsubst l end end] $l + list [ledit l end end] $l } {{1 2 3} {1 2 3}} -test lsubst-1.23 {lsubst command} { +test ledit-1.23 {ledit command} { set l {1 2 3 4} - list [lsubst l 2 -1 xy] $l + list [ledit l 2 -1 xy] $l } {{1 2 xy 3 4} {1 2 xy 3 4}} -test lsubst-1.24 {lsubst command} { +test ledit-1.24 {ledit command} { set l {1 2 3 4} - list [lsubst l end -1 z] $l + list [ledit l end -1 z] $l } {{1 2 3 z 4} {1 2 3 z 4}} -test lsubst-1.25 {lsubst command} { +test ledit-1.25 {ledit command} { set l {\}\ hello} - concat \"[lsubst l end end]\" $l + concat \"[ledit l end end]\" $l } {"\}\ " \}\ } -test lsubst-1.26 {lsubst command} { +test ledit-1.26 {ledit command} { catch {unset foo} set foo {a b} - list [lsubst foo end end] $foo \ - [lsubst foo end end] $foo \ - [lsubst foo end end] $foo + list [ledit foo end end] $foo \ + [ledit foo end end] $foo \ + [ledit foo end end] $foo } {a a {} {} {} {}} -test lsubst-1.27 {lsubset command} -body { +test ledit-1.27 {lsubset command} -body { set l x - list [lsubst l 1 1] $l + list [ledit l 1 1] $l } -result {x x} -test lsubst-1.28 {lsubst command} -body { +test ledit-1.28 {ledit command} -body { set l x - list [lsubst l 1 1 y] $l + list [ledit l 1 1 y] $l } -result {{x y} {x y}} -test lsubst-1.29 {lsubst command} -body { +test ledit-1.29 {ledit command} -body { set l x - lsubst l 1 1 [error foo] + ledit l 1 1 [error foo] } -returnCodes 1 -result {foo} -test lsubst-1.30 {lsubst command} -body { +test ledit-1.30 {ledit command} -body { set l {not {}alist} - lsubst l 0 0 [error foo] + ledit l 0 0 [error foo] } -returnCodes 1 -result {foo} -test lsubst-1.31 {lsubst command} -body { +test ledit-1.31 {ledit command} -body { unset -nocomplain arr set arr(x) {a b} - list [lsubst arr(x) 0 0 c] $arr(x) + list [ledit arr(x) 0 0 c] $arr(x) } -result {{c b} {c b}} -test lsubst-2.1 {lsubst errors} -body { - list [catch lsubst msg] $msg -} -result {1 {wrong # args: should be "lsubst listVar first last ?element ...?"}} -test lsubst-2.2 {lsubst errors} -body { +test ledit-2.1 {ledit errors} -body { + list [catch ledit msg] $msg +} -result {1 {wrong # args: should be "ledit listVar first last ?element ...?"}} +test ledit-2.2 {ledit errors} -body { unset -nocomplain x - list [catch {lsubst l b} msg] $msg -} -result {1 {wrong # args: should be "lsubst listVar first last ?element ...?"}} -test lsubst-2.3 {lsubst errors} -body { + list [catch {ledit l b} msg] $msg +} -result {1 {wrong # args: should be "ledit listVar first last ?element ...?"}} +test ledit-2.3 {ledit errors} -body { set x {} - list [catch {lsubst x a 10} msg] $msg + list [catch {ledit x a 10} msg] $msg } -result {1 {bad index "a": must be integer?[+-]integer? or end?[+-]integer?}} -test lsubst-2.4 {lsubst errors} -body { +test ledit-2.4 {ledit errors} -body { set l {} - list [catch {lsubst l 10 x} msg] $msg + list [catch {ledit l 10 x} msg] $msg } -result {1 {bad index "x": must be integer?[+-]integer? or end?[+-]integer?}} -test lsubst-2.5 {lsubst errors} -body { +test ledit-2.5 {ledit errors} -body { set l {} - list [catch {lsubst l 10 1x} msg] $msg + list [catch {ledit l 10 1x} msg] $msg } -result {1 {bad index "1x": must be integer?[+-]integer? or end?[+-]integer?}} -test lsubst-2.6 {lsubst errors} -body { +test ledit-2.6 {ledit errors} -body { set l x - list [catch {lsubst l 3 2} msg] $msg + list [catch {ledit l 3 2} msg] $msg } -result {0 x} -test lsubst-2.7 {lsubst errors} -body { +test ledit-2.7 {ledit errors} -body { set l x - list [catch {lsubst l 2 2} msg] $msg + list [catch {ledit l 2 2} msg] $msg } -result {0 x} -test lsubst-2.8 {lsubst errors} -body { +test ledit-2.8 {ledit errors} -body { unset -nocomplain l - lsubst l 0 0 x + ledit l 0 0 x } -returnCodes error -result {can't read "l": no such variable} -test lsubst-2.9 {lsubst errors} -body { +test ledit-2.9 {ledit errors} -body { unset -nocomplain arr - lsubst arr(x) 0 0 x + ledit arr(x) 0 0 x } -returnCodes error -result {can't read "arr(x)": no such variable} -test lsubst-2.10 {lsubst errors} -body { +test ledit-2.10 {ledit errors} -body { unset -nocomplain arr set arr(y) y - lsubst arr(x) 0 0 x + ledit arr(x) 0 0 x } -returnCodes error -result {can't read "arr(x)": no such element in array} -test lsubst-3.1 {lsubst won't modify shared argument objects} { +test ledit-3.1 {ledit won't modify shared argument objects} { proc p {} { set l "a b c" - lsubst l 1 1 "x y" + ledit l 1 1 "x y" # The literal in locals table should be unmodified return [list "a b c" $l] } p } {{a b c} {a {x y} c}} -# Following bugs were in lreplace. Make sure lsubst does not have them -test lsubst-4.1 {Bug ccc2c2cc98: lreplace edge case} { +# Following bugs were in lreplace. Make sure ledit does not have them +test ledit-4.1 {Bug ccc2c2cc98: lreplace edge case} { set l {} - list [lsubst l 1 1] $l + list [ledit l 1 1] $l } {{} {}} -test lsubst-4.2 {Bug ccc2c2cc98: lreplace edge case} { +test ledit-4.2 {Bug ccc2c2cc98: lreplace edge case} { set l { } - list [lsubst l 1 1] $l + list [ledit l 1 1] $l } {{} {}} -test lsubst-4.3 {lreplace edge case} { +test ledit-4.3 {lreplace edge case} { set l {1 2 3} - lsubst l 2 0 + ledit l 2 0 } {1 2 3} -test lsubst-4.4 {lsubst edge case} { +test ledit-4.4 {ledit edge case} { set l {1 2 3 4 5} - list [lsubst l 3 1] $l + list [ledit l 3 1] $l } {{1 2 3 4 5} {1 2 3 4 5}} test lreplace-4.5 {lreplace edge case} { lreplace {1 2 3 4 5} 3 0 _ } {1 2 3 _ 4 5} -test lsubst-4.6 {lsubst end-x: bug a4cb3f06c4} { +test ledit-4.6 {ledit end-x: bug a4cb3f06c4} { set l {0 1 2 3 4} - list [lsubst l 0 end-2] $l + list [ledit l 0 end-2] $l } {{3 4} {3 4}} -test lsubst-4.6.1 {lsubst end-x: bug a4cb3f06c4} { +test ledit-4.6.1 {ledit end-x: bug a4cb3f06c4} { set l {0 1 2 3 4} - list [lsubst l 0 end-2 a b c] $l + list [ledit l 0 end-2 a b c] $l } {{a b c 3 4} {a b c 3 4}} -test lsubst-4.7 {lsubst with two end-indexes: increasing} { +test ledit-4.7 {ledit with two end-indexes: increasing} { set l {0 1 2 3 4} - list [lsubst l end-2 end-1] $l + list [ledit l end-2 end-1] $l } {{0 1 4} {0 1 4}} -test lsubst-4.7.1 {lsubst with two end-indexes: increasing} { +test ledit-4.7.1 {ledit with two end-indexes: increasing} { set l {0 1 2 3 4} - list [lsubst l end-2 end-1 a b c] $l + list [ledit l end-2 end-1 a b c] $l } {{0 1 a b c 4} {0 1 a b c 4}} -test lsubst-4.8 {lsubst with two end-indexes: equal} { +test ledit-4.8 {ledit with two end-indexes: equal} { set l {0 1 2 3 4} - list [lsubst l end-2 end-2] $l + list [ledit l end-2 end-2] $l } {{0 1 3 4} {0 1 3 4}} -test lsubst-4.8.1 {lsubst with two end-indexes: equal} { +test ledit-4.8.1 {ledit with two end-indexes: equal} { set l {0 1 2 3 4} - list [lsubst l end-2 end-2 a b c] $l + list [ledit l end-2 end-2 a b c] $l } {{0 1 a b c 3 4} {0 1 a b c 3 4}} -test lsubst-4.9 {lsubst with two end-indexes: decreasing} { +test ledit-4.9 {ledit with two end-indexes: decreasing} { set l {0 1 2 3 4} - list [lsubst l end-2 end-3] $l + list [ledit l end-2 end-3] $l } {{0 1 2 3 4} {0 1 2 3 4}} -test lsubst-4.9.1 {lsubst with two end-indexes: decreasing} { +test ledit-4.9.1 {ledit with two end-indexes: decreasing} { set l {0 1 2 3 4} - list [lsubst l end-2 end-3 a b c] $l + list [ledit l end-2 end-3 a b c] $l } {{0 1 a b c 2 3 4} {0 1 a b c 2 3 4}} -test lsubst-4.10 {lsubst with two equal indexes} { +test ledit-4.10 {ledit with two equal indexes} { set l {0 1 2 3 4} - list [lsubst l 2 2] $l + list [ledit l 2 2] $l } {{0 1 3 4} {0 1 3 4}} -test lsubst-4.10.1 {lsubst with two equal indexes} { +test ledit-4.10.1 {ledit with two equal indexes} { set l {0 1 2 3 4} - list [lsubst l 2 2 a b c] $l + list [ledit l 2 2 a b c] $l } {{0 1 a b c 3 4} {0 1 a b c 3 4}} -test lsubst-4.11 {lsubst end index first} { +test ledit-4.11 {ledit end index first} { set l {0 1 2 3 4} - list [lsubst l end-2 1 a b c] $l + list [ledit l end-2 1 a b c] $l } {{0 1 a b c 2 3 4} {0 1 a b c 2 3 4}} -test lsubst-4.12 {lsubst end index first} { +test ledit-4.12 {ledit end index first} { set l {0 1 2 3 4} - list [lsubst l end-2 2 a b c] $l + list [ledit l end-2 2 a b c] $l } {{0 1 a b c 3 4} {0 1 a b c 3 4}} -test lsubst-4.13 {lsubst empty list} { +test ledit-4.13 {ledit empty list} { set l {} - list [lsubst l 1 1 1] $l + list [ledit l 1 1 1] $l } {1 1} -test lsubst-4.14 {lsubst empty list} { +test ledit-4.14 {ledit empty list} { set l {} - list [lsubst l 2 2 2] $l + list [ledit l 2 2 2] $l } {2 2} -test lsubst-5.1 {compiled lreplace: Bug 47ac84309b} { +test ledit-5.1 {compiled lreplace: Bug 47ac84309b} { apply {x { - lsubst x end 0 + ledit x end 0 }} {a b c} } {a b c} -test lsubst-5.2 {compiled lreplace: Bug 47ac84309b} { +test ledit-5.2 {compiled lreplace: Bug 47ac84309b} { apply {x { - lsubst x end 0 A + ledit x end 0 A }} {a b c} } {a b A c} @@ -520,10 +520,10 @@ apply {{} { foreach b $idxs { foreach i $ins { set expected [list [catch {$lreplace $ls $a $b {*}$i} m] $m] - set tester [list lsubst ls $a $b {*}$i] + set tester [list ledit ls $a $b {*}$i] set script [list catch $tester m] set script "list \[$script\] \$m" - test lsubst-6.[incr n] {lsubst battery} -body \ + test ledit-6.[incr n] {ledit battery} -body \ [list apply [list {ls} $script] $ls] -result $expected } } |