OSDN Git Service

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