107 lines
3.9 KiB
Plaintext
107 lines
3.9 KiB
Plaintext
# Commands covered: lreplace
|
|
#
|
|
# This file contains a collection of tests for one or more of the Tcl
|
|
# built-in commands. Sourcing this file into Tcl runs the tests and
|
|
# generates output for errors. No output means no errors were found.
|
|
#
|
|
# Copyright (c) 1991-1993 The Regents of the University of California.
|
|
# All rights reserved.
|
|
#
|
|
# Permission is hereby granted, without written agreement and without
|
|
# license or royalty fees, to use, copy, modify, and distribute this
|
|
# software and its documentation for any purpose, provided that the
|
|
# above copyright notice and the following two paragraphs appear in
|
|
# all copies of this software.
|
|
#
|
|
# IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
|
|
# DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
|
|
# OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
|
|
# CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
#
|
|
# THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
|
|
# INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
# AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
|
|
# ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO
|
|
# PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
|
|
#
|
|
# $Header: /user6/ouster/tcl/tests/RCS/lreplace.test,v 1.5 93/02/06 16:01:39 ouster Exp $ (Berkeley)
|
|
|
|
if {[string compare test [info procs test]] == 1} then {source defs}
|
|
|
|
test lreplace-1.1 {lreplace command} {
|
|
lreplace {1 2 3 4 5} 0 0 a
|
|
} {a 2 3 4 5}
|
|
test lreplace-1.2 {lreplace command} {
|
|
lreplace {1 2 3 4 5} 1 1 a
|
|
} {1 a 3 4 5}
|
|
test lreplace-1.3 {lreplace command} {
|
|
lreplace {1 2 3 4 5} 2 2 a
|
|
} {1 2 a 4 5}
|
|
test lreplace-1.4 {lreplace command} {
|
|
lreplace {1 2 3 4 5} 3 3 a
|
|
} {1 2 3 a 5}
|
|
test lreplace-1.5 {lreplace command} {
|
|
lreplace {1 2 3 4 5} 4 4 a
|
|
} {1 2 3 4 a}
|
|
test lreplace-1.6 {lreplace command} {
|
|
lreplace {1 2 3 4 5} 4 5 a
|
|
} {1 2 3 4 a}
|
|
test lreplace-1.7 {lreplace command} {
|
|
lreplace {1 2 3 4 5} -1 -1 a
|
|
} {a 2 3 4 5}
|
|
test lreplace-1.8 {lreplace command} {
|
|
lreplace {1 2 3 4 5} 2 end a b c d
|
|
} {1 2 a b c d}
|
|
test lreplace-1.9 {lreplace command} {
|
|
lreplace {1 2 3 4 5} 0 3
|
|
} {5}
|
|
test lreplace-1.10 {lreplace command} {
|
|
lreplace {1 2 3 4 5} 0 4
|
|
} {}
|
|
test lreplace-1.11 {lreplace command} {
|
|
lreplace {1 2 3 4 5} 0 1
|
|
} {3 4 5}
|
|
test lreplace-1.12 {lreplace command} {
|
|
lreplace {1 2 3 4 5} 2 3
|
|
} {1 2 5}
|
|
test lreplace-1.13 {lreplace command} {
|
|
lreplace {1 2 3 4 5} 3 end
|
|
} {1 2 3}
|
|
test lreplace-1.14 {lreplace command} {
|
|
lreplace {1 2 3 4 5} -1 4 a b c
|
|
} {a b c}
|
|
test lreplace-1.15 {lreplace command} {
|
|
lreplace {a b "c c" d e f} 3 3
|
|
} {a b "c c" e f}
|
|
test lreplace-1.16 {lreplace command} {
|
|
lreplace { 1 2 3 4 5} 0 0 a
|
|
} {a 2 3 4 5}
|
|
test lreplace-1.17 {lreplace command} {
|
|
lreplace {1 2 3 4 "5 6"} 4 4 a
|
|
} {1 2 3 4 a}
|
|
test lreplace-1.18 {lreplace command} {
|
|
lreplace {1 2 3 4 {5 6}} 4 4 a
|
|
} {1 2 3 4 a}
|
|
|
|
test lreplace-2.1 {lreplace errors} {
|
|
list [catch lreplace msg] $msg
|
|
} {1 {wrong # args: should be "lreplace list first last ?element element ...?"}}
|
|
test lreplace-2.2 {lreplace errors} {
|
|
list [catch {lreplace a b} msg] $msg
|
|
} {1 {wrong # args: should be "lreplace list first last ?element element ...?"}}
|
|
test lreplace-2.3 {lreplace errors} {
|
|
list [catch {lreplace x a 10} msg] $msg
|
|
} {1 {expected integer but got "a"}}
|
|
test lreplace-2.4 {lreplace errors} {
|
|
list [catch {lreplace x 10 x} msg] $msg
|
|
} {1 {bad index "x": must be integer or "end"}}
|
|
test lreplace-2.5 {lreplace errors} {
|
|
list [catch {lreplace x 10 1x} msg] $msg
|
|
} {1 {expected integer but got "1x"}}
|
|
test lreplace-2.6 {lreplace errors} {
|
|
list [catch {lreplace x 3 2} msg] $msg
|
|
} {1 {first index must not be greater than second}}
|
|
test lreplace-2.7 {lreplace errors} {
|
|
list [catch {lreplace x 1 1} msg] $msg
|
|
} {1 {list doesn't contain element 1}}
|