1 |
578 |
markom |
# Commands covered: none
|
2 |
|
|
#
|
3 |
|
|
# This file contains a collection of tests for Tcl's dynamic string
|
4 |
|
|
# library procedures. Sourcing this file into Tcl runs the tests and
|
5 |
|
|
# generates output for errors. No output means no errors were found.
|
6 |
|
|
#
|
7 |
|
|
# Copyright (c) 1993 The Regents of the University of California.
|
8 |
|
|
# Copyright (c) 1994 Sun Microsystems, Inc.
|
9 |
|
|
#
|
10 |
|
|
# See the file "license.terms" for information on usage and redistribution
|
11 |
|
|
# of this file, and for a DISCLAIMER OF ALL WARRANTIES.
|
12 |
|
|
#
|
13 |
|
|
# RCS: @(#) $Id: dstring.test,v 1.1.1.1 2002-01-16 10:25:35 markom Exp $
|
14 |
|
|
|
15 |
|
|
if {[info commands testdstring] == {}} {
|
16 |
|
|
puts "This application hasn't been compiled with the \"testdstring\""
|
17 |
|
|
puts "command, so I can't test Tcl_DStringAppend et al."
|
18 |
|
|
return
|
19 |
|
|
}
|
20 |
|
|
|
21 |
|
|
if {[string compare test [info procs test]] == 1} then {source defs}
|
22 |
|
|
|
23 |
|
|
test dstring-1.1 {appending and retrieving} {
|
24 |
|
|
testdstring free
|
25 |
|
|
testdstring append "abc" -1
|
26 |
|
|
list [testdstring get] [testdstring length]
|
27 |
|
|
} {abc 3}
|
28 |
|
|
test dstring-1.2 {appending and retrieving} {
|
29 |
|
|
testdstring free
|
30 |
|
|
testdstring append "abc" -1
|
31 |
|
|
testdstring append " xyzzy" 3
|
32 |
|
|
testdstring append " 12345" -1
|
33 |
|
|
list [testdstring get] [testdstring length]
|
34 |
|
|
} {{abc xy 12345} 12}
|
35 |
|
|
test dstring-1.3 {appending and retrieving} {
|
36 |
|
|
testdstring free
|
37 |
|
|
foreach l {a b c d e f g h i j k l m n o p} {
|
38 |
|
|
testdstring append $l$l$l$l$l$l$l$l$l$l$l$l$l$l$l$l$l$l$l$l$l\n -1
|
39 |
|
|
}
|
40 |
|
|
list [testdstring get] [testdstring length]
|
41 |
|
|
} {{aaaaaaaaaaaaaaaaaaaaa
|
42 |
|
|
bbbbbbbbbbbbbbbbbbbbb
|
43 |
|
|
ccccccccccccccccccccc
|
44 |
|
|
ddddddddddddddddddddd
|
45 |
|
|
eeeeeeeeeeeeeeeeeeeee
|
46 |
|
|
fffffffffffffffffffff
|
47 |
|
|
ggggggggggggggggggggg
|
48 |
|
|
hhhhhhhhhhhhhhhhhhhhh
|
49 |
|
|
iiiiiiiiiiiiiiiiiiiii
|
50 |
|
|
jjjjjjjjjjjjjjjjjjjjj
|
51 |
|
|
kkkkkkkkkkkkkkkkkkkkk
|
52 |
|
|
lllllllllllllllllllll
|
53 |
|
|
mmmmmmmmmmmmmmmmmmmmm
|
54 |
|
|
nnnnnnnnnnnnnnnnnnnnn
|
55 |
|
|
ooooooooooooooooooooo
|
56 |
|
|
ppppppppppppppppppppp
|
57 |
|
|
} 352}
|
58 |
|
|
|
59 |
|
|
test dstring-2.1 {appending list elements} {
|
60 |
|
|
testdstring free
|
61 |
|
|
testdstring element "abc"
|
62 |
|
|
testdstring element "d e f"
|
63 |
|
|
list [testdstring get] [testdstring length]
|
64 |
|
|
} {{abc {d e f}} 11}
|
65 |
|
|
test dstring-2.2 {appending list elements} {
|
66 |
|
|
testdstring free
|
67 |
|
|
testdstring element "x"
|
68 |
|
|
testdstring element "\{"
|
69 |
|
|
testdstring element "ab\}"
|
70 |
|
|
testdstring get
|
71 |
|
|
} {x \{ ab\}}
|
72 |
|
|
test dstring-2.3 {appending list elements} {
|
73 |
|
|
testdstring free
|
74 |
|
|
foreach l {a b c d e f g h i j k l m n o p} {
|
75 |
|
|
testdstring element $l$l$l$l$l$l$l$l$l$l$l$l$l$l$l$l$l$l$l$l$l
|
76 |
|
|
}
|
77 |
|
|
testdstring get
|
78 |
|
|
} {aaaaaaaaaaaaaaaaaaaaa bbbbbbbbbbbbbbbbbbbbb ccccccccccccccccccccc ddddddddddddddddddddd eeeeeeeeeeeeeeeeeeeee fffffffffffffffffffff ggggggggggggggggggggg hhhhhhhhhhhhhhhhhhhhh iiiiiiiiiiiiiiiiiiiii jjjjjjjjjjjjjjjjjjjjj kkkkkkkkkkkkkkkkkkkkk lllllllllllllllllllll mmmmmmmmmmmmmmmmmmmmm nnnnnnnnnnnnnnnnnnnnn ooooooooooooooooooooo ppppppppppppppppppppp}
|
79 |
|
|
test dstring-2.4 {appending list elements} {
|
80 |
|
|
testdstring free
|
81 |
|
|
testdstring append "a\{" -1
|
82 |
|
|
testdstring element abc
|
83 |
|
|
testdstring append " \{" -1
|
84 |
|
|
testdstring element xyzzy
|
85 |
|
|
testdstring get
|
86 |
|
|
} "a{ abc {xyzzy"
|
87 |
|
|
test dstring-2.5 {appending list elements} {
|
88 |
|
|
testdstring free
|
89 |
|
|
testdstring append " \{" -1
|
90 |
|
|
testdstring element abc
|
91 |
|
|
testdstring get
|
92 |
|
|
} " {abc"
|
93 |
|
|
test dstring-2.6 {appending list elements} {
|
94 |
|
|
testdstring free
|
95 |
|
|
testdstring append " " -1
|
96 |
|
|
testdstring element abc
|
97 |
|
|
testdstring get
|
98 |
|
|
} { abc}
|
99 |
|
|
test dstring-2.7 {appending list elements} {
|
100 |
|
|
testdstring free
|
101 |
|
|
testdstring append "\\ " -1
|
102 |
|
|
testdstring element abc
|
103 |
|
|
testdstring get
|
104 |
|
|
} "\\ abc"
|
105 |
|
|
test dstring-2.8 {appending list elements} {
|
106 |
|
|
testdstring free
|
107 |
|
|
testdstring append "x " -1
|
108 |
|
|
testdstring element abc
|
109 |
|
|
testdstring get
|
110 |
|
|
} {x abc}
|
111 |
|
|
|
112 |
|
|
test dstring-3.1 {nested sublists} {
|
113 |
|
|
testdstring free
|
114 |
|
|
testdstring start
|
115 |
|
|
testdstring element foo
|
116 |
|
|
testdstring element bar
|
117 |
|
|
testdstring end
|
118 |
|
|
testdstring element another
|
119 |
|
|
testdstring get
|
120 |
|
|
} {{foo bar} another}
|
121 |
|
|
test dstring-3.2 {nested sublists} {
|
122 |
|
|
testdstring free
|
123 |
|
|
testdstring start
|
124 |
|
|
testdstring start
|
125 |
|
|
testdstring element abc
|
126 |
|
|
testdstring element def
|
127 |
|
|
testdstring end
|
128 |
|
|
testdstring end
|
129 |
|
|
testdstring element ghi
|
130 |
|
|
testdstring get
|
131 |
|
|
} {{{abc def}} ghi}
|
132 |
|
|
test dstring-3.3 {nested sublists} {
|
133 |
|
|
testdstring free
|
134 |
|
|
testdstring start
|
135 |
|
|
testdstring start
|
136 |
|
|
testdstring start
|
137 |
|
|
testdstring element foo
|
138 |
|
|
testdstring element foo2
|
139 |
|
|
testdstring end
|
140 |
|
|
testdstring end
|
141 |
|
|
testdstring element foo3
|
142 |
|
|
testdstring end
|
143 |
|
|
testdstring element foo4
|
144 |
|
|
testdstring get
|
145 |
|
|
} {{{{foo foo2}} foo3} foo4}
|
146 |
|
|
test dstring-3.4 {nested sublists} {
|
147 |
|
|
testdstring free
|
148 |
|
|
testdstring element before
|
149 |
|
|
testdstring start
|
150 |
|
|
testdstring element during
|
151 |
|
|
testdstring element more
|
152 |
|
|
testdstring end
|
153 |
|
|
testdstring element last
|
154 |
|
|
testdstring get
|
155 |
|
|
} {before {during more} last}
|
156 |
|
|
test dstring-3.5 {nested sublists} {
|
157 |
|
|
testdstring free
|
158 |
|
|
testdstring element "\{"
|
159 |
|
|
testdstring start
|
160 |
|
|
testdstring element first
|
161 |
|
|
testdstring element second
|
162 |
|
|
testdstring end
|
163 |
|
|
testdstring get
|
164 |
|
|
} {\{ {first second}}
|
165 |
|
|
|
166 |
|
|
test dstring-4.1 {truncation} {
|
167 |
|
|
testdstring free
|
168 |
|
|
testdstring append "abcdefg" -1
|
169 |
|
|
testdstring trunc 3
|
170 |
|
|
list [testdstring get] [testdstring length]
|
171 |
|
|
} {abc 3}
|
172 |
|
|
test dstring-4.2 {truncation} {
|
173 |
|
|
testdstring free
|
174 |
|
|
testdstring append "xyzzy" -1
|
175 |
|
|
testdstring trunc 0
|
176 |
|
|
list [testdstring get] [testdstring length]
|
177 |
|
|
} {{} 0}
|
178 |
|
|
|
179 |
|
|
test dstring-5.1 {copying to result} {
|
180 |
|
|
testdstring free
|
181 |
|
|
testdstring append xyz -1
|
182 |
|
|
testdstring result
|
183 |
|
|
} xyz
|
184 |
|
|
test dstring-5.2 {copying to result} {
|
185 |
|
|
testdstring free
|
186 |
|
|
catch {unset a}
|
187 |
|
|
foreach l {a b c d e f g h i j k l m n o p} {
|
188 |
|
|
testdstring append $l$l$l$l$l$l$l$l$l$l$l$l$l$l$l$l$l$l$l$l$l\n -1
|
189 |
|
|
}
|
190 |
|
|
set a [testdstring result]
|
191 |
|
|
testdstring append abc -1
|
192 |
|
|
list $a [testdstring get]
|
193 |
|
|
} {{aaaaaaaaaaaaaaaaaaaaa
|
194 |
|
|
bbbbbbbbbbbbbbbbbbbbb
|
195 |
|
|
ccccccccccccccccccccc
|
196 |
|
|
ddddddddddddddddddddd
|
197 |
|
|
eeeeeeeeeeeeeeeeeeeee
|
198 |
|
|
fffffffffffffffffffff
|
199 |
|
|
ggggggggggggggggggggg
|
200 |
|
|
hhhhhhhhhhhhhhhhhhhhh
|
201 |
|
|
iiiiiiiiiiiiiiiiiiiii
|
202 |
|
|
jjjjjjjjjjjjjjjjjjjjj
|
203 |
|
|
kkkkkkkkkkkkkkkkkkkkk
|
204 |
|
|
lllllllllllllllllllll
|
205 |
|
|
mmmmmmmmmmmmmmmmmmmmm
|
206 |
|
|
nnnnnnnnnnnnnnnnnnnnn
|
207 |
|
|
ooooooooooooooooooooo
|
208 |
|
|
ppppppppppppppppppppp
|
209 |
|
|
} abc}
|
210 |
|
|
|
211 |
|
|
test dstring-6.1 {Tcl_DStringGetResult} {
|
212 |
|
|
testdstring free
|
213 |
|
|
list [testdstring gresult staticsmall] [testdstring get]
|
214 |
|
|
} {{} short}
|
215 |
|
|
test dstring-6.2 {Tcl_DStringGetResult} {
|
216 |
|
|
testdstring free
|
217 |
|
|
foreach l {a b c d e f g h i j k l m n o p} {
|
218 |
|
|
testdstring append $l$l$l$l$l$l$l$l$l$l$l$l$l$l$l$l$l$l$l$l$l\n -1
|
219 |
|
|
}
|
220 |
|
|
list [testdstring gresult staticsmall] [testdstring get]
|
221 |
|
|
} {{} short}
|
222 |
|
|
test dstring-6.3 {Tcl_DStringGetResult} {
|
223 |
|
|
set result {}
|
224 |
|
|
lappend result [testdstring gresult staticlarge]
|
225 |
|
|
testdstring append x 1
|
226 |
|
|
lappend result [testdstring get]
|
227 |
|
|
} {{} {first0 first1 first2 first3 first4 first5 first6 first7 first8 first9
|
228 |
|
|
second0 second1 second2 second3 second4 second5 second6 second7 second8 second9
|
229 |
|
|
third0 third1 third2 third3 third4 third5 third6 third7 third8 third9
|
230 |
|
|
fourth0 fourth1 fourth2 fourth3 fourth4 fourth5 fourth6 fourth7 fourth8 fourth9
|
231 |
|
|
fifth0 fifth1 fifth2 fifth3 fifth4 fifth5 fifth6 fifth7 fifth8 fifth9
|
232 |
|
|
sixth0 sixth1 sixth2 sixth3 sixth4 sixth5 sixth6 sixth7 sixth8 sixth9
|
233 |
|
|
seventh0 seventh1 seventh2 seventh3 seventh4 seventh5 seventh6 seventh7 seventh8 seventh9
|
234 |
|
|
x}}
|
235 |
|
|
test dstring-6.4 {Tcl_DStringGetResult} {
|
236 |
|
|
set result {}
|
237 |
|
|
lappend result [testdstring gresult free]
|
238 |
|
|
testdstring append y 1
|
239 |
|
|
lappend result [testdstring get]
|
240 |
|
|
} {{} {This is a malloc-ed stringy}}
|
241 |
|
|
test dstring-6.5 {Tcl_DStringGetResult} {
|
242 |
|
|
set result {}
|
243 |
|
|
lappend result [testdstring gresult special]
|
244 |
|
|
testdstring append z 1
|
245 |
|
|
lappend result [testdstring get]
|
246 |
|
|
} {{} {This is a specially-allocated stringz}}
|
247 |
|
|
|
248 |
|
|
testdstring free
|