| 1 |
578 |
markom |
# Commands covered: lreplace
|
| 2 |
|
|
#
|
| 3 |
|
|
# This file contains a collection of tests for one or more of the Tcl
|
| 4 |
|
|
# built-in commands. Sourcing this file into Tcl runs the tests and
|
| 5 |
|
|
# generates output for errors. No output means no errors were found.
|
| 6 |
|
|
#
|
| 7 |
|
|
# Copyright (c) 1991-1993 The Regents of the University of California.
|
| 8 |
|
|
# Copyright (c) 1994 Sun Microsystems, Inc.
|
| 9 |
|
|
#
|
| 10 |
|
|
# See the file "license.terms" for information on usage and redistribution
|
| 11 |
|
|
# of this file, and for a DISCLAIMER OF ALL WARRANTIES.
|
| 12 |
|
|
#
|
| 13 |
|
|
# RCS: @(#) $Id: lreplace.test,v 1.1.1.1 2002-01-16 10:25:36 markom Exp $
|
| 14 |
|
|
|
| 15 |
|
|
if {[string compare test [info procs test]] == 1} then {source defs}
|
| 16 |
|
|
|
| 17 |
|
|
test lreplace-1.1 {lreplace command} {
|
| 18 |
|
|
lreplace {1 2 3 4 5} 0 0 a
|
| 19 |
|
|
} {a 2 3 4 5}
|
| 20 |
|
|
test lreplace-1.2 {lreplace command} {
|
| 21 |
|
|
lreplace {1 2 3 4 5} 1 1 a
|
| 22 |
|
|
} {1 a 3 4 5}
|
| 23 |
|
|
test lreplace-1.3 {lreplace command} {
|
| 24 |
|
|
lreplace {1 2 3 4 5} 2 2 a
|
| 25 |
|
|
} {1 2 a 4 5}
|
| 26 |
|
|
test lreplace-1.4 {lreplace command} {
|
| 27 |
|
|
lreplace {1 2 3 4 5} 3 3 a
|
| 28 |
|
|
} {1 2 3 a 5}
|
| 29 |
|
|
test lreplace-1.5 {lreplace command} {
|
| 30 |
|
|
lreplace {1 2 3 4 5} 4 4 a
|
| 31 |
|
|
} {1 2 3 4 a}
|
| 32 |
|
|
test lreplace-1.6 {lreplace command} {
|
| 33 |
|
|
lreplace {1 2 3 4 5} 4 5 a
|
| 34 |
|
|
} {1 2 3 4 a}
|
| 35 |
|
|
test lreplace-1.7 {lreplace command} {
|
| 36 |
|
|
lreplace {1 2 3 4 5} -1 -1 a
|
| 37 |
|
|
} {a 1 2 3 4 5}
|
| 38 |
|
|
test lreplace-1.8 {lreplace command} {
|
| 39 |
|
|
lreplace {1 2 3 4 5} 2 end a b c d
|
| 40 |
|
|
} {1 2 a b c d}
|
| 41 |
|
|
test lreplace-1.9 {lreplace command} {
|
| 42 |
|
|
lreplace {1 2 3 4 5} 0 3
|
| 43 |
|
|
} {5}
|
| 44 |
|
|
test lreplace-1.10 {lreplace command} {
|
| 45 |
|
|
lreplace {1 2 3 4 5} 0 4
|
| 46 |
|
|
} {}
|
| 47 |
|
|
test lreplace-1.11 {lreplace command} {
|
| 48 |
|
|
lreplace {1 2 3 4 5} 0 1
|
| 49 |
|
|
} {3 4 5}
|
| 50 |
|
|
test lreplace-1.12 {lreplace command} {
|
| 51 |
|
|
lreplace {1 2 3 4 5} 2 3
|
| 52 |
|
|
} {1 2 5}
|
| 53 |
|
|
test lreplace-1.13 {lreplace command} {
|
| 54 |
|
|
lreplace {1 2 3 4 5} 3 end
|
| 55 |
|
|
} {1 2 3}
|
| 56 |
|
|
test lreplace-1.14 {lreplace command} {
|
| 57 |
|
|
lreplace {1 2 3 4 5} -1 4 a b c
|
| 58 |
|
|
} {a b c}
|
| 59 |
|
|
test lreplace-1.15 {lreplace command} {
|
| 60 |
|
|
lreplace {a b "c c" d e f} 3 3
|
| 61 |
|
|
} {a b {c c} e f}
|
| 62 |
|
|
test lreplace-1.16 {lreplace command} {
|
| 63 |
|
|
lreplace { 1 2 3 4 5} 0 0 a
|
| 64 |
|
|
} {a 2 3 4 5}
|
| 65 |
|
|
test lreplace-1.17 {lreplace command} {
|
| 66 |
|
|
lreplace {1 2 3 4 "5 6"} 4 4 a
|
| 67 |
|
|
} {1 2 3 4 a}
|
| 68 |
|
|
test lreplace-1.18 {lreplace command} {
|
| 69 |
|
|
lreplace {1 2 3 4 {5 6}} 4 4 a
|
| 70 |
|
|
} {1 2 3 4 a}
|
| 71 |
|
|
test lreplace-1.19 {lreplace command} {
|
| 72 |
|
|
lreplace {1 2 3 4} 2 end x y z
|
| 73 |
|
|
} {1 2 x y z}
|
| 74 |
|
|
test lreplace-1.20 {lreplace command} {
|
| 75 |
|
|
lreplace {1 2 3 4} end end a
|
| 76 |
|
|
} {1 2 3 a}
|
| 77 |
|
|
test lreplace-1.21 {lreplace command} {
|
| 78 |
|
|
lreplace {1 2 3 4} end 3 a
|
| 79 |
|
|
} {1 2 3 a}
|
| 80 |
|
|
test lreplace-1.22 {lreplace command} {
|
| 81 |
|
|
lreplace {1 2 3 4} end end
|
| 82 |
|
|
} {1 2 3}
|
| 83 |
|
|
test lreplace-1.23 {lreplace command} {
|
| 84 |
|
|
lreplace {1 2 3 4} 2 -1 xy
|
| 85 |
|
|
} {1 2 xy 3 4}
|
| 86 |
|
|
test lreplace-1.24 {lreplace command} {
|
| 87 |
|
|
lreplace {1 2 3 4} end -1 z
|
| 88 |
|
|
} {1 2 3 z 4}
|
| 89 |
|
|
test lreplace-1.25 {lreplace command} {
|
| 90 |
|
|
concat \"[lreplace {\}\ hello} end end]\"
|
| 91 |
|
|
} {"\}\ "}
|
| 92 |
|
|
test lreplace-1.26 {lreplace command} {
|
| 93 |
|
|
catch {unset foo}
|
| 94 |
|
|
set foo {a b}
|
| 95 |
|
|
list [set foo [lreplace $foo end end]] \
|
| 96 |
|
|
[set foo [lreplace $foo end end]] \
|
| 97 |
|
|
[set foo [lreplace $foo end end]]
|
| 98 |
|
|
} {a {} {}}
|
| 99 |
|
|
|
| 100 |
|
|
|
| 101 |
|
|
test lreplace-2.1 {lreplace errors} {
|
| 102 |
|
|
list [catch lreplace msg] $msg
|
| 103 |
|
|
} {1 {wrong # args: should be "lreplace list first last ?element element ...?"}}
|
| 104 |
|
|
test lreplace-2.2 {lreplace errors} {
|
| 105 |
|
|
list [catch {lreplace a b} msg] $msg
|
| 106 |
|
|
} {1 {wrong # args: should be "lreplace list first last ?element element ...?"}}
|
| 107 |
|
|
test lreplace-2.3 {lreplace errors} {
|
| 108 |
|
|
list [catch {lreplace x a 10} msg] $msg
|
| 109 |
|
|
} {1 {bad index "a": must be integer or "end"}}
|
| 110 |
|
|
test lreplace-2.4 {lreplace errors} {
|
| 111 |
|
|
list [catch {lreplace x 10 x} msg] $msg
|
| 112 |
|
|
} {1 {bad index "x": must be integer or "end"}}
|
| 113 |
|
|
test lreplace-2.5 {lreplace errors} {
|
| 114 |
|
|
list [catch {lreplace x 10 1x} msg] $msg
|
| 115 |
|
|
} {1 {bad index "1x": must be integer or "end"}}
|
| 116 |
|
|
test lreplace-2.6 {lreplace errors} {
|
| 117 |
|
|
list [catch {lreplace x 3 2} msg] $msg
|
| 118 |
|
|
} {1 {list doesn't contain element 3}}
|
| 119 |
|
|
test lreplace-2.7 {lreplace errors} {
|
| 120 |
|
|
list [catch {lreplace x 1 1} msg] $msg
|
| 121 |
|
|
} {1 {list doesn't contain element 1}}
|
| 122 |
|
|
|
| 123 |
|
|
test lreplace-3.1 {lreplace won't modify shared argument objects} {
|
| 124 |
|
|
proc p {} {
|
| 125 |
|
|
lreplace "a b c" 1 1 "x y"
|
| 126 |
|
|
return "a b c"
|
| 127 |
|
|
}
|
| 128 |
|
|
p
|
| 129 |
|
|
} "a b c"
|
| 130 |
|
|
|
| 131 |
|
|
catch {unset foo}
|