zlib: Don't use PASTE for INTMAX error messages
[jimtcl.git] / tests / lreplace.test
blobba77505d4dfad37137c42d1b6717b0ceab1ea4ba
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
18 } {a 2 3 4 5}
19 test lreplace-1.2 {lreplace command} {
20     lreplace {1 2 3 4 5} 1 1 a
21 } {1 a 3 4 5}
22 test lreplace-1.3 {lreplace command} {
23     lreplace {1 2 3 4 5} 2 2 a
24 } {1 2 a 4 5}
25 test lreplace-1.4 {lreplace command} {
26     lreplace {1 2 3 4 5} 3 3 a
27 } {1 2 3 a 5}
28 test lreplace-1.5 {lreplace command} {
29     lreplace {1 2 3 4 5} 4 4 a
30 } {1 2 3 4 a}
31 test lreplace-1.6 {lreplace command} {
32     lreplace {1 2 3 4 5} 4 5 a
33 } {1 2 3 4 a}
34 test lreplace-1.7 {lreplace command} {
35     lreplace {1 2 3 4 5} -1 -1 a
36 } {a 1 2 3 4 5}
37 test lreplace-1.8 {lreplace command} {
38     lreplace {1 2 3 4 5} 2 end a b c d
39 } {1 2 a b c d}
40 test lreplace-1.9 {lreplace command} {
41     lreplace {1 2 3 4 5} 0 3
42 } {5}
43 test lreplace-1.10 {lreplace command} {
44     lreplace {1 2 3 4 5} 0 4
45 } {}
46 test lreplace-1.11 {lreplace command} {
47     lreplace {1 2 3 4 5} 0 1
48 } {3 4 5}
49 test lreplace-1.12 {lreplace command} {
50     lreplace {1 2 3 4 5} 2 3
51 } {1 2 5}
52 test lreplace-1.13 {lreplace command} {
53     lreplace {1 2 3 4 5} 3 end
54 } {1 2 3}
55 test lreplace-1.14 {lreplace command} {
56     lreplace {1 2 3 4 5} -1 4 a b c
57 } {a b c}
58 test lreplace-1.15 {lreplace command} {
59     lreplace {a b "c c" d e f} 3 3
60 } {a b {c c} e f}
61 test lreplace-1.16 {lreplace command} {
62     lreplace { 1 2 3 4 5} 0 0 a
63 } {a 2 3 4 5}
64 test lreplace-1.17 {lreplace command} {
65     lreplace {1 2 3 4 "5 6"} 4 4 a
66 } {1 2 3 4 a}
67 test lreplace-1.18 {lreplace command} {
68     lreplace {1 2 3 4 {5 6}} 4 4 a
69 } {1 2 3 4 a}
70 test lreplace-1.19 {lreplace command} {
71     lreplace {1 2 3 4} 2 end x y z
72 } {1 2 x y z}
73 test lreplace-1.20 {lreplace command} {
74     lreplace {1 2 3 4} end end a
75 } {1 2 3 a}
76 test lreplace-1.21 {lreplace command} {
77     lreplace {1 2 3 4} end 3 a
78 } {1 2 3 a}
79 test lreplace-1.22 {lreplace command} {
80     lreplace {1 2 3 4} end end
81 } {1 2 3}
82 test lreplace-1.23 {lreplace command} {
83     lreplace {1 2 3 4} 2 -1 xy
84 } {1 2 xy 3 4}
85 test lreplace-1.24 {lreplace command} {
86     lreplace {1 2 3 4} end -1 z
87 } {1 2 3 z 4}
88 test lreplace-1.25 {lreplace command} {
89     concat \"[lreplace {\}\     hello} end end]\"
90 } {"\}\ "}
91 test lreplace-1.26 {lreplace command} {
92     catch {unset foo}
93     set foo {a b}
94     list [set foo [lreplace $foo end end]] \
95         [set foo [lreplace $foo end end]] \
96         [set foo [lreplace $foo end end]]
97 } {a {} {}}
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} {
123     proc p {} {
124         lreplace "a b c" 1 1 "x y"
125         return "a b c"
126     }
127     p
128 } "a b c"
130 # cleanup
131 catch {unset foo}
132 ::tcltest::cleanupTests
133 return