1 | # 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 | # 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 | # RCS: @(#) $Id: dstring.test,v 1.8 2004/06/24 10:34:12 dkf Exp $ |
---|
15 | |
---|
16 | if {[lsearch [namespace children] ::tcltest] == -1} { |
---|
17 | package require tcltest |
---|
18 | namespace import -force ::tcltest::* |
---|
19 | } |
---|
20 | |
---|
21 | testConstraint testdstring [llength [info commands testdstring]] |
---|
22 | |
---|
23 | test dstring-1.1 {appending and retrieving} testdstring { |
---|
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} testdstring { |
---|
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} testdstring { |
---|
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} testdstring { |
---|
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} testdstring { |
---|
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} testdstring { |
---|
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} testdstring { |
---|
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} testdstring { |
---|
88 | testdstring free |
---|
89 | testdstring append " \{" -1 |
---|
90 | testdstring element abc |
---|
91 | testdstring get |
---|
92 | } " {abc" |
---|
93 | test dstring-2.6 {appending list elements} testdstring { |
---|
94 | testdstring free |
---|
95 | testdstring append " " -1 |
---|
96 | testdstring element abc |
---|
97 | testdstring get |
---|
98 | } { abc} |
---|
99 | test dstring-2.7 {appending list elements} testdstring { |
---|
100 | testdstring free |
---|
101 | testdstring append "\\ " -1 |
---|
102 | testdstring element abc |
---|
103 | testdstring get |
---|
104 | } "\\ abc" |
---|
105 | test dstring-2.8 {appending list elements} testdstring { |
---|
106 | testdstring free |
---|
107 | testdstring append "x " -1 |
---|
108 | testdstring element abc |
---|
109 | testdstring get |
---|
110 | } {x abc} |
---|
111 | test dstring-2.9 {appending list elements} testdstring { |
---|
112 | testdstring free |
---|
113 | testdstring element # |
---|
114 | testdstring get |
---|
115 | } {{#}} |
---|
116 | test dstring-2.10 {appending list elements} testdstring { |
---|
117 | testdstring free |
---|
118 | testdstring append " " -1 |
---|
119 | testdstring element # |
---|
120 | testdstring get |
---|
121 | } { {#}} |
---|
122 | test dstring-2.11 {appending list elements} testdstring { |
---|
123 | testdstring free |
---|
124 | testdstring append \t -1 |
---|
125 | testdstring element # |
---|
126 | testdstring get |
---|
127 | } \t{#} |
---|
128 | test dstring-2.12 {appending list elements} testdstring { |
---|
129 | testdstring free |
---|
130 | testdstring append x -1 |
---|
131 | testdstring element # |
---|
132 | testdstring get |
---|
133 | } {x #} |
---|
134 | test dstring-2.13 {appending list elements} testdstring { |
---|
135 | # This test shows lack of sophistication in Tcl_DStringAppendElement's |
---|
136 | # decision about whether #-quoting can be disabled. |
---|
137 | testdstring free |
---|
138 | testdstring append "x " -1 |
---|
139 | testdstring element # |
---|
140 | testdstring get |
---|
141 | } {x {#}} |
---|
142 | |
---|
143 | test dstring-3.1 {nested sublists} testdstring { |
---|
144 | testdstring free |
---|
145 | testdstring start |
---|
146 | testdstring element foo |
---|
147 | testdstring element bar |
---|
148 | testdstring end |
---|
149 | testdstring element another |
---|
150 | testdstring get |
---|
151 | } {{foo bar} another} |
---|
152 | test dstring-3.2 {nested sublists} testdstring { |
---|
153 | testdstring free |
---|
154 | testdstring start |
---|
155 | testdstring start |
---|
156 | testdstring element abc |
---|
157 | testdstring element def |
---|
158 | testdstring end |
---|
159 | testdstring end |
---|
160 | testdstring element ghi |
---|
161 | testdstring get |
---|
162 | } {{{abc def}} ghi} |
---|
163 | test dstring-3.3 {nested sublists} testdstring { |
---|
164 | testdstring free |
---|
165 | testdstring start |
---|
166 | testdstring start |
---|
167 | testdstring start |
---|
168 | testdstring element foo |
---|
169 | testdstring element foo2 |
---|
170 | testdstring end |
---|
171 | testdstring end |
---|
172 | testdstring element foo3 |
---|
173 | testdstring end |
---|
174 | testdstring element foo4 |
---|
175 | testdstring get |
---|
176 | } {{{{foo foo2}} foo3} foo4} |
---|
177 | test dstring-3.4 {nested sublists} testdstring { |
---|
178 | testdstring free |
---|
179 | testdstring element before |
---|
180 | testdstring start |
---|
181 | testdstring element during |
---|
182 | testdstring element more |
---|
183 | testdstring end |
---|
184 | testdstring element last |
---|
185 | testdstring get |
---|
186 | } {before {during more} last} |
---|
187 | test dstring-3.5 {nested sublists} testdstring { |
---|
188 | testdstring free |
---|
189 | testdstring element "\{" |
---|
190 | testdstring start |
---|
191 | testdstring element first |
---|
192 | testdstring element second |
---|
193 | testdstring end |
---|
194 | testdstring get |
---|
195 | } {\{ {first second}} |
---|
196 | test dstring-3.6 {appending list elements} testdstring { |
---|
197 | testdstring free |
---|
198 | testdstring append x -1 |
---|
199 | testdstring start |
---|
200 | testdstring element # |
---|
201 | testdstring end |
---|
202 | testdstring get |
---|
203 | } {x {{#}}} |
---|
204 | test dstring-3.7 {appending list elements} testdstring { |
---|
205 | testdstring free |
---|
206 | testdstring append x -1 |
---|
207 | testdstring start |
---|
208 | testdstring append " " -1 |
---|
209 | testdstring element # |
---|
210 | testdstring end |
---|
211 | testdstring get |
---|
212 | } {x { {#}}} |
---|
213 | test dstring-3.8 {appending list elements} testdstring { |
---|
214 | testdstring free |
---|
215 | testdstring append x -1 |
---|
216 | testdstring start |
---|
217 | testdstring append \t -1 |
---|
218 | testdstring element # |
---|
219 | testdstring end |
---|
220 | testdstring get |
---|
221 | } "x {\t{#}}" |
---|
222 | test dstring-3.9 {appending list elements} testdstring { |
---|
223 | testdstring free |
---|
224 | testdstring append x -1 |
---|
225 | testdstring start |
---|
226 | testdstring append x -1 |
---|
227 | testdstring element # |
---|
228 | testdstring end |
---|
229 | testdstring get |
---|
230 | } {x {x #}} |
---|
231 | test dstring-3.10 {appending list elements} testdstring { |
---|
232 | # This test shows lack of sophistication in Tcl_DStringAppendElement's |
---|
233 | # decision about whether #-quoting can be disabled. |
---|
234 | testdstring free |
---|
235 | testdstring append x -1 |
---|
236 | testdstring start |
---|
237 | testdstring append "x " -1 |
---|
238 | testdstring element # |
---|
239 | testdstring end |
---|
240 | testdstring get |
---|
241 | } {x {x {#}}} |
---|
242 | |
---|
243 | test dstring-4.1 {truncation} testdstring { |
---|
244 | testdstring free |
---|
245 | testdstring append "abcdefg" -1 |
---|
246 | testdstring trunc 3 |
---|
247 | list [testdstring get] [testdstring length] |
---|
248 | } {abc 3} |
---|
249 | test dstring-4.2 {truncation} testdstring { |
---|
250 | testdstring free |
---|
251 | testdstring append "xyzzy" -1 |
---|
252 | testdstring trunc 0 |
---|
253 | list [testdstring get] [testdstring length] |
---|
254 | } {{} 0} |
---|
255 | |
---|
256 | test dstring-5.1 {copying to result} testdstring { |
---|
257 | testdstring free |
---|
258 | testdstring append xyz -1 |
---|
259 | testdstring result |
---|
260 | } xyz |
---|
261 | test dstring-5.2 {copying to result} testdstring { |
---|
262 | testdstring free |
---|
263 | catch {unset a} |
---|
264 | foreach l {a b c d e f g h i j k l m n o p} { |
---|
265 | 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 |
---|
266 | } |
---|
267 | set a [testdstring result] |
---|
268 | testdstring append abc -1 |
---|
269 | list $a [testdstring get] |
---|
270 | } {{aaaaaaaaaaaaaaaaaaaaa |
---|
271 | bbbbbbbbbbbbbbbbbbbbb |
---|
272 | ccccccccccccccccccccc |
---|
273 | ddddddddddddddddddddd |
---|
274 | eeeeeeeeeeeeeeeeeeeee |
---|
275 | fffffffffffffffffffff |
---|
276 | ggggggggggggggggggggg |
---|
277 | hhhhhhhhhhhhhhhhhhhhh |
---|
278 | iiiiiiiiiiiiiiiiiiiii |
---|
279 | jjjjjjjjjjjjjjjjjjjjj |
---|
280 | kkkkkkkkkkkkkkkkkkkkk |
---|
281 | lllllllllllllllllllll |
---|
282 | mmmmmmmmmmmmmmmmmmmmm |
---|
283 | nnnnnnnnnnnnnnnnnnnnn |
---|
284 | ooooooooooooooooooooo |
---|
285 | ppppppppppppppppppppp |
---|
286 | } abc} |
---|
287 | |
---|
288 | test dstring-6.1 {Tcl_DStringGetResult} testdstring { |
---|
289 | testdstring free |
---|
290 | list [testdstring gresult staticsmall] [testdstring get] |
---|
291 | } {{} short} |
---|
292 | test dstring-6.2 {Tcl_DStringGetResult} testdstring { |
---|
293 | testdstring free |
---|
294 | foreach l {a b c d e f g h i j k l m n o p} { |
---|
295 | 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 |
---|
296 | } |
---|
297 | list [testdstring gresult staticsmall] [testdstring get] |
---|
298 | } {{} short} |
---|
299 | test dstring-6.3 {Tcl_DStringGetResult} testdstring { |
---|
300 | set result {} |
---|
301 | lappend result [testdstring gresult staticlarge] |
---|
302 | testdstring append x 1 |
---|
303 | lappend result [testdstring get] |
---|
304 | } {{} {first0 first1 first2 first3 first4 first5 first6 first7 first8 first9 |
---|
305 | second0 second1 second2 second3 second4 second5 second6 second7 second8 second9 |
---|
306 | third0 third1 third2 third3 third4 third5 third6 third7 third8 third9 |
---|
307 | fourth0 fourth1 fourth2 fourth3 fourth4 fourth5 fourth6 fourth7 fourth8 fourth9 |
---|
308 | fifth0 fifth1 fifth2 fifth3 fifth4 fifth5 fifth6 fifth7 fifth8 fifth9 |
---|
309 | sixth0 sixth1 sixth2 sixth3 sixth4 sixth5 sixth6 sixth7 sixth8 sixth9 |
---|
310 | seventh0 seventh1 seventh2 seventh3 seventh4 seventh5 seventh6 seventh7 seventh8 seventh9 |
---|
311 | x}} |
---|
312 | test dstring-6.4 {Tcl_DStringGetResult} testdstring { |
---|
313 | set result {} |
---|
314 | lappend result [testdstring gresult free] |
---|
315 | testdstring append y 1 |
---|
316 | lappend result [testdstring get] |
---|
317 | } {{} {This is a malloc-ed stringy}} |
---|
318 | test dstring-6.5 {Tcl_DStringGetResult} testdstring { |
---|
319 | set result {} |
---|
320 | lappend result [testdstring gresult special] |
---|
321 | testdstring append z 1 |
---|
322 | lappend result [testdstring get] |
---|
323 | } {{} {This is a specially-allocated stringz}} |
---|
324 | |
---|
325 | # cleanup |
---|
326 | if {[testConstraint testdstring]} { |
---|
327 | testdstring free |
---|
328 | } |
---|
329 | ::tcltest::cleanupTests |
---|
330 | return |
---|