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