1 # Commands covered: linsert
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
19 test linsert-1.1 {linsert command} {
20 linsert {1 2 3 4 5} 0 a
22 test linsert-1.2 {linsert command} {
23 linsert {1 2 3 4 5} 1 a
25 test linsert-1.3 {linsert command} {
26 linsert {1 2 3 4 5} 2 a
28 test linsert-1.4 {linsert command} {
29 linsert {1 2 3 4 5} 3 a
31 test linsert-1.5 {linsert command} {
32 linsert {1 2 3 4 5} 4 a
34 test linsert-1.6 {linsert command} {
35 linsert {1 2 3 4 5} 5 a
37 test linsert-1.7 {linsert command} {
38 linsert {1 2 3 4 5} 2 one two \{three \$four
39 } {1 2 one two \{three {$four} 3 4 5}
40 test linsert-1.8 {linsert command} {
41 linsert {\{one \$two \{three \ four \ five} 2 a b c
42 } {\{one {$two} a b c \{three { four} { five}}
43 test linsert-1.9 {linsert command} {
44 linsert {{1 2} {3 4} {5 6} {7 8}} 2 {x y} {a b}
45 } {{1 2} {3 4} {x y} {a b} {5 6} {7 8}}
46 test linsert-1.10 {linsert command} {
49 test linsert-1.11 {linsert command} {
52 test linsert-1.12 {linsert command} {
53 linsert {a b "c c" d e} 3 1
55 test linsert-1.13 {linsert command} {
56 linsert { a b c d} 0 1 2
58 test linsert-1.14 {linsert command} {
59 linsert {a b c {d e f}} 4 1 2
61 test linsert-1.15 {linsert command} {
62 linsert {a b c \{\ abc} 4 q r
64 test linsert-1.16 {linsert command} {
65 linsert {a b c \{ abc} 4 q r
67 test linsert-1.17 {linsert command} {
68 linsert {a b c} end q r
70 test linsert-1.18 {linsert command} {
73 test linsert-1.19 {linsert command} {
76 test linsert-1.20 {linsert command, use of end-int index} {
77 linsert {a b c d} end-2 e f
80 test linsert-2.1 {linsert errors} {
81 list [catch linsert msg] $msg
82 } {1 {wrong # args: should be "linsert list index ?element ...?"}}
83 test linsert-2.2 {linsert errors} {
84 list [catch {linsert a b} msg] $msg
85 } {1 {bad index "b": must be integer?[+-]integer? or end?[+-]integer?}}
86 test linsert-2.3 {linsert errors} {
87 list [catch {linsert a 12x 2} msg] $msg
88 } {1 {bad index "12x": must be integer?[+-]integer? or end?[+-]integer?}}
89 test linsert-2.4 {linsert errors} tcl {
90 list [catch {linsert \{ 12 2} msg] $msg
91 } {1 {unmatched open brace in list}}
92 test linsert-2.5 {syntax (TIP 323)} {
95 test linsert-2.6 {syntax (TIP 323)} {
99 test linsert-3.1 {linsert won't modify shared argument objects} {
101 linsert "a b c" 1 "x y"
106 test linsert-3.2 {linsert won't modify shared argument objects} {
108 set lis [format "a \"%s\" c" "b"]
109 linsert $lis 0 [string length $lis]
115 ::tcltest::cleanupTests