| 1 |
# Functionality covered: operation of the procedures in tclListObj.c that |
| 2 |
# implement the Tcl type manager for the list object type. |
| 3 |
# |
| 4 |
# This file contains a collection of tests for one or more of the Tcl |
| 5 |
# built-in commands. Sourcing this file into Tcl runs the tests and |
| 6 |
# generates output for errors. No output means no errors were found. |
| 7 |
# |
| 8 |
# Copyright (c) 1995-1996 Sun Microsystems, Inc. |
| 9 |
# Copyright (c) 1998-1999 by 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 |
|
| 14 |
if {"::tcltest" ni [namespace children]} { |
| 15 |
package require tcltest 2.5 |
| 16 |
namespace import -force ::tcltest::* |
| 17 |
} |
| 18 |
|
| 19 |
::tcltest::loadTestedCommands |
| 20 |
catch [list package require -exact Tcltest [info patchlevel]] |
| 21 |
|
| 22 |
testConstraint testobj [llength [info commands testobj]] |
| 23 |
|
| 24 |
catch {unset x} |
| 25 |
test listobj-1.1 {Tcl_GetListObjType} emptyTest { |
| 26 |
# Test removed; tested an internal detail |
| 27 |
# that's no longer correct, and duplicated test obj-1.1 |
| 28 |
} {} |
| 29 |
|
| 30 |
test listobj-2.1 {Tcl_SetListObj, use in lappend} { |
| 31 |
catch {unset x} |
| 32 |
list [lappend x 1 abc def] [lappend x 1 ghi jkl] $x |
| 33 |
} {{1 abc def} {1 abc def 1 ghi jkl} {1 abc def 1 ghi jkl}} |
| 34 |
test listobj-2.2 {Tcl_SetListObj, use in ObjInterpProc} { |
| 35 |
proc return_args {args} { |
| 36 |
return $args |
| 37 |
} |
| 38 |
list [return_args] [return_args x] [return_args x y] |
| 39 |
} {{} x {x y}} |
| 40 |
test listobj-2.3 {Tcl_SetListObj, zero element count} { |
| 41 |
list |
| 42 |
} {} |
| 43 |
|
| 44 |
test listobj-3.1 {Tcl_ListObjAppend, list conversion} { |
| 45 |
catch {unset x} |
| 46 |
list [lappend x 1 2 abc "long string"] $x |
| 47 |
} {{1 2 abc {long string}} {1 2 abc {long string}}} |
| 48 |
test listobj-3.2 {Tcl_ListObjAppend, list conversion} { |
| 49 |
set x "" |
| 50 |
list [lappend x first second] [lappend x third fourth] $x |
| 51 |
} {{first second} {first second third fourth} {first second third fourth}} |
| 52 |
test listobj-3.3 {Tcl_ListObjAppend, list conversion} { |
| 53 |
set x "abc def" |
| 54 |
list [lappend x first second] $x |
| 55 |
} {{abc def first second} {abc def first second}} |
| 56 |
test listobj-3.4 {Tcl_ListObjAppend, error in conversion} { |
| 57 |
set x " \{" |
| 58 |
list [catch {lappend x abc def} msg] $msg |
| 59 |
} {1 {unmatched open brace in list}} |
| 60 |
test listobj-3.5 {Tcl_ListObjAppend, force internal rep array to grow} { |
| 61 |
set x "" |
| 62 |
list [lappend x 1 1] [lappend x 2 2] [lappend x 3 3] [lappend x 4 4] \ |
| 63 |
[lappend x 5 5] [lappend x 6 6] [lappend x 7 7] [lappend x 8 8] $x |
| 64 |
} {{1 1} {1 1 2 2} {1 1 2 2 3 3} {1 1 2 2 3 3 4 4} {1 1 2 2 3 3 4 4 5 5} {1 1 2 2 3 3 4 4 5 5 6 6} {1 1 2 2 3 3 4 4 5 5 6 6 7 7} {1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8} {1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8}} |
| 65 |
|
| 66 |
test listobj-4.1 {Tcl_ListObjAppendElement, list conversion} { |
| 67 |
catch {unset x} |
| 68 |
list [lappend x 1] $x |
| 69 |
} {1 1} |
| 70 |
test listobj-4.2 {Tcl_ListObjAppendElement, list conversion} { |
| 71 |
set x "" |
| 72 |
list [lappend x first] [lappend x second] $x |
| 73 |
} {first {first second} {first second}} |
| 74 |
test listobj-4.3 {Tcl_ListObjAppendElement, list conversion} { |
| 75 |
set x "abc def" |
| 76 |
list [lappend x first] $x |
| 77 |
} {{abc def first} {abc def first}} |
| 78 |
test listobj-4.4 {Tcl_ListObjAppendElement, error in conversion} { |
| 79 |
set x " \{" |
| 80 |
list [catch {lappend x abc} msg] $msg |
| 81 |
} {1 {unmatched open brace in list}} |
| 82 |
test listobj-4.5 {Tcl_ListObjAppendElement, force internal rep array to grow} { |
| 83 |
set x "" |
| 84 |
list [lappend x 1] [lappend x 2] [lappend x 3] [lappend x 4] \ |
| 85 |
[lappend x 5] [lappend x 6] [lappend x 7] [lappend x 8] $x |
| 86 |
} {1 {1 2} {1 2 3} {1 2 3 4} {1 2 3 4 5} {1 2 3 4 5 6} {1 2 3 4 5 6 7} {1 2 3 4 5 6 7 8} {1 2 3 4 5 6 7 8}} |
| 87 |
|
| 88 |
test listobj-5.1 {Tcl_ListObjIndex, basic tests} { |
| 89 |
lindex {a b c} 0 |
| 90 |
} a |
| 91 |
test listobj-5.2 {Tcl_ListObjIndex, basic tests} { |
| 92 |
lindex a 0 |
| 93 |
} a |
| 94 |
test listobj-5.3 {Tcl_ListObjIndex, basic tests} { |
| 95 |
lindex {a {b c d} x} 1 |
| 96 |
} {b c d} |
| 97 |
test listobj-5.4 {Tcl_ListObjIndex, basic tests} { |
| 98 |
lindex {a b c} 3 |
| 99 |
} {} |
| 100 |
test listobj-5.5 {Tcl_ListObjIndex, basic tests} { |
| 101 |
lindex {a b c} 100 |
| 102 |
} {} |
| 103 |
test listobj-5.6 {Tcl_ListObjIndex, basic tests} { |
| 104 |
lindex a 100 |
| 105 |
} {} |
| 106 |
test listobj-5.7 {Tcl_ListObjIndex, basic tests} { |
| 107 |
lindex {} -1 |
| 108 |
} {} |
| 109 |
test listobj-5.8 {Tcl_ListObjIndex, error in conversion} { |
| 110 |
set x " \{" |
| 111 |
list [catch {lindex $x 0} msg] $msg |
| 112 |
} {1 {unmatched open brace in list}} |
| 113 |
|
| 114 |
test listobj-6.1 {Tcl_ListObjLength} { |
| 115 |
llength {a b c d} |
| 116 |
} 4 |
| 117 |
test listobj-6.2 {Tcl_ListObjLength} { |
| 118 |
llength {a b c {a b {c d}} d} |
| 119 |
} 5 |
| 120 |
test listobj-6.3 {Tcl_ListObjLength} { |
| 121 |
llength {} |
| 122 |
} 0 |
| 123 |
test listobj-6.4 {Tcl_ListObjLength, convert from non-list} { |
| 124 |
llength 123 |
| 125 |
} 1 |
| 126 |
test listobj-6.5 {Tcl_ListObjLength, error converting from non-list} { |
| 127 |
list [catch {llength "a b c \{"} msg] $msg |
| 128 |
} {1 {unmatched open brace in list}} |
| 129 |
test listobj-6.6 {Tcl_ListObjLength, error converting from non-list} { |
| 130 |
list [catch {llength "a {b}c"} msg] $msg |
| 131 |
} {1 {list element in braces followed by "c" instead of space}} |
| 132 |
|
| 133 |
test listobj-7.1 {Tcl_ListObjReplace, conversion from non-list} { |
| 134 |
lreplace 123 0 0 x |
| 135 |
} {x} |
| 136 |
test listobj-7.2 {Tcl_ListObjReplace, error converting from non-list} { |
| 137 |
list [catch {lreplace "a b c \{" 1 1 x} msg] $msg |
| 138 |
} {1 {unmatched open brace in list}} |
| 139 |
test listobj-7.3 {Tcl_ListObjReplace, error converting from non-list} { |
| 140 |
list [catch {lreplace "a {b}c" 1 2 x} msg] $msg |
| 141 |
} {1 {list element in braces followed by "c" instead of space}} |
| 142 |
test listobj-7.4 {Tcl_ListObjReplace, negative first element index} { |
| 143 |
lreplace {1 2 3 4 5} -1 1 a |
| 144 |
} {a 3 4 5} |
| 145 |
test listobj-7.5 {Tcl_ListObjReplace, last element index >= num elems} { |
| 146 |
lreplace {1 2 3 4 5} 3 7 a b c |
| 147 |
} {1 2 3 a b c} |
| 148 |
test listobj-7.6 {Tcl_ListObjReplace, first element index > last index} { |
| 149 |
lreplace {1 2 3 4 5} 3 1 a b c |
| 150 |
} {1 2 3 a b c 4 5} |
| 151 |
test listobj-7.7 {Tcl_ListObjReplace, no new elements} { |
| 152 |
lreplace {1 2 3 4 5} 1 1 |
| 153 |
} {1 3 4 5} |
| 154 |
test listobj-7.8 {Tcl_ListObjReplace, shrink array in place} { |
| 155 |
lreplace {1 2 3 4 5 6 7} 4 5 |
| 156 |
} {1 2 3 4 7} |
| 157 |
test listobj-7.9 {Tcl_ListObjReplace, grow array in place} { |
| 158 |
lreplace {1 2 3 4 5 6 7} 1 3 a b c d e |
| 159 |
} {1 a b c d e 5 6 7} |
| 160 |
test listobj-7.10 {Tcl_ListObjReplace, replace tail of array} { |
| 161 |
lreplace {1 2 3 4 5 6 7} 3 6 a |
| 162 |
} {1 2 3 a} |
| 163 |
test listobj-7.11 {Tcl_ListObjReplace, must grow internal array} { |
| 164 |
lreplace {1 2 3 4 5} 2 3 a b c d e f g h i j k l |
| 165 |
} {1 2 a b c d e f g h i j k l 5} |
| 166 |
test listobj-7.12 {Tcl_ListObjReplace, grow array, insert at start} { |
| 167 |
lreplace {1 2 3 4 5} -1 -1 a b c d e f g h i j k l |
| 168 |
} {a b c d e f g h i j k l 1 2 3 4 5} |
| 169 |
test listobj-7.13 {Tcl_ListObjReplace, grow array, insert at end} { |
| 170 |
lreplace {1 2 3 4 5} 4 1 a b c d e f g h i j k l |
| 171 |
} {1 2 3 4 a b c d e f g h i j k l 5} |
| 172 |
|
| 173 |
test listobj-8.1 {SetListFromAny} { |
| 174 |
lindex {0 foo\x00help 2} 1 |
| 175 |
} "foo\x00help" |
| 176 |
|
| 177 |
test listobj-9.1 {UpdateStringOfList} { |
| 178 |
string length [list foo\x00help] |
| 179 |
} 8 |
| 180 |
|
| 181 |
test listobj-10.1 {Bug [2971669]} {*}{ |
| 182 |
-constraints testobj |
| 183 |
-setup { |
| 184 |
testobj freeallvars |
| 185 |
} |
| 186 |
-body { |
| 187 |
set result {} |
| 188 |
lappend result \ |
| 189 |
[testlistobj set 1 a b c d e] \ |
| 190 |
[testlistobj replace 1 0x7fffffff 0x7fffffff f] \ |
| 191 |
[testlistobj get 1] |
| 192 |
} |
| 193 |
-cleanup { |
| 194 |
testobj freeallvars |
| 195 |
} |
| 196 |
-result {{a b c d e} {} {a b c d e f}} |
| 197 |
} |
| 198 |
test listobj-10.2 {Tcl_ListObjReplace with negative start value} testobj { |
| 199 |
testlistobj set 1 a b c d e |
| 200 |
testlistobj replace 1 -1 2 f |
| 201 |
testlistobj get 1 |
| 202 |
} {f c d e} |
| 203 |
test listobj-10.3 {Tcl_ListObjReplace with negative count value} testobj { |
| 204 |
testlistobj set 1 a b c d e |
| 205 |
testlistobj replace 1 1 -1 f |
| 206 |
testlistobj get 1 |
| 207 |
} {a f b c d e} |
| 208 |
|
| 209 |
test listobj-11.1 {Bug 3598580: Tcl_ListObjReplace refcount management} testobj { |
| 210 |
testobj bug3598580 |
| 211 |
} 123 |
| 212 |
|
| 213 |
# cleanup |
| 214 |
::tcltest::cleanupTests |
| 215 |
return |
| 216 |
|
| 217 |
# Local Variables: |
| 218 |
# mode: tcl |
| 219 |
# End: |