1 # Commands covered: lreplace
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.
7 # Copyright (c) 1991-1993 The Regents of the University of California.
8 # Copyright (c) 1994 Sun Microsystems, Inc.
9 # Copyright (c) 1998-1999 by Scriptics Corporation.
11 # See the file "license.terms" for information on usage and redistribution
12 # of this file, and for a DISCLAIMER OF ALL WARRANTIES.
14 source [file dirname [info script]]/testing.tcl
16 test lreplace-1.1 {lreplace command} {
17 lreplace {1 2 3 4 5} 0 0 a
19 test lreplace-1.2 {lreplace command} {
20 lreplace {1 2 3 4 5} 1 1 a
22 test lreplace-1.3 {lreplace command} {
23 lreplace {1 2 3 4 5} 2 2 a
25 test lreplace-1.4 {lreplace command} {
26 lreplace {1 2 3 4 5} 3 3 a
28 test lreplace-1.5 {lreplace command} {
29 lreplace {1 2 3 4 5} 4 4 a
31 test lreplace-1.6 {lreplace command} {
32 lreplace {1 2 3 4 5} 4 5 a
34 test lreplace-1.7 {lreplace command} {
35 lreplace {1 2 3 4 5} -1 -1 a
37 test lreplace-1.8 {lreplace command} {
38 lreplace {1 2 3 4 5} 2 end a b c d
40 test lreplace-1.9 {lreplace command} {
41 lreplace {1 2 3 4 5} 0 3
43 test lreplace-1.10 {lreplace command} {
44 lreplace {1 2 3 4 5} 0 4
46 test lreplace-1.11 {lreplace command} {
47 lreplace {1 2 3 4 5} 0 1
49 test lreplace-1.12 {lreplace command} {
50 lreplace {1 2 3 4 5} 2 3
52 test lreplace-1.13 {lreplace command} {
53 lreplace {1 2 3 4 5} 3 end
55 test lreplace-1.14 {lreplace command} {
56 lreplace {1 2 3 4 5} -1 4 a b c
58 test lreplace-1.15 {lreplace command} {
59 lreplace {a b "c c" d e f} 3 3
61 test lreplace-1.16 {lreplace command} {
62 lreplace { 1 2 3 4 5} 0 0 a
64 test lreplace-1.17 {lreplace command} {
65 lreplace {1 2 3 4 "5 6"} 4 4 a
67 test lreplace-1.18 {lreplace command} {
68 lreplace {1 2 3 4 {5 6}} 4 4 a
70 test lreplace-1.19 {lreplace command} {
71 lreplace {1 2 3 4} 2 end x y z
73 test lreplace-1.20 {lreplace command} {
74 lreplace {1 2 3 4} end end a
76 test lreplace-1.21 {lreplace command} {
77 lreplace {1 2 3 4} end 3 a
79 test lreplace-1.22 {lreplace command} {
80 lreplace {1 2 3 4} end end
82 test lreplace-1.23 {lreplace command} {
83 lreplace {1 2 3 4} 2 -1 xy
85 test lreplace-1.24 {lreplace command} {
86 lreplace {1 2 3 4} end -1 z
88 test lreplace-1.25 {lreplace command} {
89 concat \"[lreplace {\}\ hello} end end]\"
91 test lreplace-1.26 {lreplace command} {
94 list [set foo [lreplace $foo end end]] \
95 [set foo [lreplace $foo end end]] \
96 [set foo [lreplace $foo end end]]
100 test lreplace-2.1 {lreplace errors} {
101 list [catch lreplace msg] $msg
102 } {1 {wrong # args: should be "lreplace list first last ?element ...?"}}
103 test lreplace-2.2 {lreplace errors} {
104 list [catch {lreplace a b} msg] $msg
105 } {1 {wrong # args: should be "lreplace list first last ?element ...?"}}
106 test lreplace-2.3 {lreplace errors} {
107 list [catch {lreplace x a 10} msg] $msg
108 } {1 {bad index "a": must be integer?[+-]integer? or end?[+-]integer?}}
109 test lreplace-2.4 {lreplace errors} {
110 list [catch {lreplace x 10 x} msg] $msg
111 } {1 {bad index "x": must be integer?[+-]integer? or end?[+-]integer?}}
112 test lreplace-2.5 {lreplace errors} {
113 list [catch {lreplace x 10 1x} msg] $msg
114 } {1 {bad index "1x": must be integer?[+-]integer? or end?[+-]integer?}}
115 test lreplace-2.6 {lreplace errors} {
116 list [catch {lreplace x 3 2} msg] $msg
117 } {1 {list doesn't contain element 3}}
118 test lreplace-2.7 {lreplace errors} {
119 list [catch {lreplace x 1 1} msg] $msg
120 } {1 {list doesn't contain element 1}}
122 test lreplace-3.1 {lreplace won't modify shared argument objects} {
124 lreplace "a b c" 1 1 "x y"
132 ::tcltest::cleanupTests