sl@0
|
1 |
# Commands covered: linsert
|
sl@0
|
2 |
#
|
sl@0
|
3 |
# This file contains a collection of tests for one or more of the Tcl
|
sl@0
|
4 |
# built-in commands. Sourcing this file into Tcl runs the tests and
|
sl@0
|
5 |
# generates output for errors. No output means no errors were found.
|
sl@0
|
6 |
#
|
sl@0
|
7 |
# Copyright (c) 1991-1993 The Regents of the University of California.
|
sl@0
|
8 |
# Copyright (c) 1994 Sun Microsystems, Inc.
|
sl@0
|
9 |
# Copyright (c) 1998-1999 by Scriptics Corporation.
|
sl@0
|
10 |
#
|
sl@0
|
11 |
# See the file "license.terms" for information on usage and redistribution
|
sl@0
|
12 |
# of this file, and for a DISCLAIMER OF ALL WARRANTIES.
|
sl@0
|
13 |
#
|
sl@0
|
14 |
# RCS: @(#) $Id: linsert.test,v 1.8 2000/04/10 17:19:01 ericm Exp $
|
sl@0
|
15 |
|
sl@0
|
16 |
if {[lsearch [namespace children] ::tcltest] == -1} {
|
sl@0
|
17 |
package require tcltest
|
sl@0
|
18 |
namespace import -force ::tcltest::*
|
sl@0
|
19 |
}
|
sl@0
|
20 |
|
sl@0
|
21 |
catch {unset lis}
|
sl@0
|
22 |
catch {rename p ""}
|
sl@0
|
23 |
|
sl@0
|
24 |
test linsert-1.1 {linsert command} {
|
sl@0
|
25 |
linsert {1 2 3 4 5} 0 a
|
sl@0
|
26 |
} {a 1 2 3 4 5}
|
sl@0
|
27 |
test linsert-1.2 {linsert command} {
|
sl@0
|
28 |
linsert {1 2 3 4 5} 1 a
|
sl@0
|
29 |
} {1 a 2 3 4 5}
|
sl@0
|
30 |
test linsert-1.3 {linsert command} {
|
sl@0
|
31 |
linsert {1 2 3 4 5} 2 a
|
sl@0
|
32 |
} {1 2 a 3 4 5}
|
sl@0
|
33 |
test linsert-1.4 {linsert command} {
|
sl@0
|
34 |
linsert {1 2 3 4 5} 3 a
|
sl@0
|
35 |
} {1 2 3 a 4 5}
|
sl@0
|
36 |
test linsert-1.5 {linsert command} {
|
sl@0
|
37 |
linsert {1 2 3 4 5} 4 a
|
sl@0
|
38 |
} {1 2 3 4 a 5}
|
sl@0
|
39 |
test linsert-1.6 {linsert command} {
|
sl@0
|
40 |
linsert {1 2 3 4 5} 5 a
|
sl@0
|
41 |
} {1 2 3 4 5 a}
|
sl@0
|
42 |
test linsert-1.7 {linsert command} {
|
sl@0
|
43 |
linsert {1 2 3 4 5} 2 one two \{three \$four
|
sl@0
|
44 |
} {1 2 one two \{three {$four} 3 4 5}
|
sl@0
|
45 |
test linsert-1.8 {linsert command} {
|
sl@0
|
46 |
linsert {\{one \$two \{three \ four \ five} 2 a b c
|
sl@0
|
47 |
} {\{one {$two} a b c \{three { four} { five}}
|
sl@0
|
48 |
test linsert-1.9 {linsert command} {
|
sl@0
|
49 |
linsert {{1 2} {3 4} {5 6} {7 8}} 2 {x y} {a b}
|
sl@0
|
50 |
} {{1 2} {3 4} {x y} {a b} {5 6} {7 8}}
|
sl@0
|
51 |
test linsert-1.10 {linsert command} {
|
sl@0
|
52 |
linsert {} 2 a b c
|
sl@0
|
53 |
} {a b c}
|
sl@0
|
54 |
test linsert-1.11 {linsert command} {
|
sl@0
|
55 |
linsert {} 2 {}
|
sl@0
|
56 |
} {{}}
|
sl@0
|
57 |
test linsert-1.12 {linsert command} {
|
sl@0
|
58 |
linsert {a b "c c" d e} 3 1
|
sl@0
|
59 |
} {a b {c c} 1 d e}
|
sl@0
|
60 |
test linsert-1.13 {linsert command} {
|
sl@0
|
61 |
linsert { a b c d} 0 1 2
|
sl@0
|
62 |
} {1 2 a b c d}
|
sl@0
|
63 |
test linsert-1.14 {linsert command} {
|
sl@0
|
64 |
linsert {a b c {d e f}} 4 1 2
|
sl@0
|
65 |
} {a b c {d e f} 1 2}
|
sl@0
|
66 |
test linsert-1.15 {linsert command} {
|
sl@0
|
67 |
linsert {a b c \{\ abc} 4 q r
|
sl@0
|
68 |
} {a b c \{\ q r abc}
|
sl@0
|
69 |
test linsert-1.16 {linsert command} {
|
sl@0
|
70 |
linsert {a b c \{ abc} 4 q r
|
sl@0
|
71 |
} {a b c \{ q r abc}
|
sl@0
|
72 |
test linsert-1.17 {linsert command} {
|
sl@0
|
73 |
linsert {a b c} end q r
|
sl@0
|
74 |
} {a b c q r}
|
sl@0
|
75 |
test linsert-1.18 {linsert command} {
|
sl@0
|
76 |
linsert {a} end q r
|
sl@0
|
77 |
} {a q r}
|
sl@0
|
78 |
test linsert-1.19 {linsert command} {
|
sl@0
|
79 |
linsert {} end q r
|
sl@0
|
80 |
} {q r}
|
sl@0
|
81 |
test linsert-1.20 {linsert command, use of end-int index} {
|
sl@0
|
82 |
linsert {a b c d} end-2 e f
|
sl@0
|
83 |
} {a b e f c d}
|
sl@0
|
84 |
|
sl@0
|
85 |
test linsert-2.1 {linsert errors} {
|
sl@0
|
86 |
list [catch linsert msg] $msg
|
sl@0
|
87 |
} {1 {wrong # args: should be "linsert list index element ?element ...?"}}
|
sl@0
|
88 |
test linsert-2.2 {linsert errors} {
|
sl@0
|
89 |
list [catch {linsert a b} msg] $msg
|
sl@0
|
90 |
} {1 {wrong # args: should be "linsert list index element ?element ...?"}}
|
sl@0
|
91 |
test linsert-2.3 {linsert errors} {
|
sl@0
|
92 |
list [catch {linsert a 12x 2} msg] $msg
|
sl@0
|
93 |
} {1 {bad index "12x": must be integer or end?-integer?}}
|
sl@0
|
94 |
test linsert-2.4 {linsert errors} {
|
sl@0
|
95 |
list [catch {linsert \{ 12 2} msg] $msg
|
sl@0
|
96 |
} {1 {unmatched open brace in list}}
|
sl@0
|
97 |
|
sl@0
|
98 |
test linsert-3.1 {linsert won't modify shared argument objects} {
|
sl@0
|
99 |
proc p {} {
|
sl@0
|
100 |
linsert "a b c" 1 "x y"
|
sl@0
|
101 |
return "a b c"
|
sl@0
|
102 |
}
|
sl@0
|
103 |
p
|
sl@0
|
104 |
} "a b c"
|
sl@0
|
105 |
test linsert-3.2 {linsert won't modify shared argument objects} {
|
sl@0
|
106 |
catch {unset lis}
|
sl@0
|
107 |
set lis [format "a \"%s\" c" "b"]
|
sl@0
|
108 |
linsert $lis 0 [string length $lis]
|
sl@0
|
109 |
} "7 a b c"
|
sl@0
|
110 |
|
sl@0
|
111 |
# cleanup
|
sl@0
|
112 |
catch {unset lis}
|
sl@0
|
113 |
catch {rename p ""}
|
sl@0
|
114 |
::tcltest::cleanupTests
|
sl@0
|
115 |
return
|