tcltest: do a better job of cleanup up after tests
[jimtcl.git] / tests / parse.test
blob8b03192879f838e98ca4c1a1d65c13bfe263a953
1 source [file dirname [info script]]/testing.tcl
3 test parse-1.1 "Quoted closing bracket" {
4         set x [string length "]"]
5 } {1}
7 test parse-1.2 "Quoted opening bracket" {
8         set x [string length "\["]
9 } {1}
11 test parse-1.3 "Quoted open brace" {
12         set x [string length "\{"]
13 } {1}
15 test parse-1.4 "Quoted open brace via var" {
16         set lb \{
17         set x [string length "$lb"]
18 } {1}
20 test parse-1.5 "Braced bracket" {
21         set x [string length {]}]
22 } {1}
24 test parse-1.6 "Dict sugar" -body {
25     unset -nocomplain a
26     array set a {a 1 b 2 c 3}
27     set x $a(
28 } -returnCodes error -match glob -result "*"
30 test parse-1.8 "Dict sugar" {
31     unset -nocomplain a
32     array set a {a 1 b 2 c 3}
33     set x $a([set y b])
34 } 2
36 test parse-1.9 "Backslash newline" {
37         set x 123;\
38         set y 456
39         list $x $y
40 } {123 456}
42 test parse-1.10 "Backslash newline in quotes" {
43         set x "abc\
44 def"
45 } "abc def"
47 test parse-1.11 "Backslash newline in quotes after var" {
48         set y 1
49         set x "abc$y\
50 def"
51 } "abc1 def"
53 test parse-1.12 "Backslash newline in quotes after var" {
54         set y 1
55         set x "abc$y\
56 def"
57 } "abc1 def"
59 test parse-1.13 "Newline in quotes" {
60         set y 1
61         set x "abc
62 def"
63 } "abc\ndef"
65 test parse-1.14 "Newline in quotes after var" {
66         set y 1
67         set x "abc$y
68 def"
69 } "abc1\ndef"
71 test parse-1.15 "Space in quotes" {
72         set y 1
73         set x "abc def"
74 } "abc def"
76 test parse-1.16 "Space in quotes after var" {
77         set y 1
78         set x "abc${y} def"
79 } "abc1 def"
81 test parse-1.17 "Command and var in quotes" {
82         set y 1
83         set x "[set z 2][set y]"
84 } 21
86 test parse-1.18 "Command and var in bare context" {
87         set y 1
88         set x [set z 2][set y]
89 } 21
91 test parse-1.19 "Lone dollar sign in quotes" {
92         set y 1
93         set x "6$[set y]"
94 } 6\$1
96 test parse-1.20 "Command and var in bare context" {
97         set y 1
98         set x 6$[set y]
99 } 6\$1
101 test parse-1.21 "Comment" {
102         set y 1
103 # A comment one a line
104         set x [set y] ;# comment after semicolon
105 } 1
107 test parse-1.22 "# char" {
108         set y 1
109         append y #
110         set x "[set y]#"
111 } {1##}
113 test parse-1.23 "newline in command" {
114         set y 1
115         set z 2
116         set x [incr y
117         incr z]
118         list $x $y $z
119 } {3 2 3}
121 test parse-1.24 "semicolon in command" {
122         set x [list a; list b c; list d e f]
123 } {d e f}
125 # Note that Tcl complains about the missing brace here
126 # while Jim ignores it
127 test parse-1.25 "missing brace in var" jim {
128         unset -nocomplain a
129         set a 3
130         set brace \{
131         set x [subst \$${brace}a]
132 } 3
134 test parse-1.26 "newline in braced var" {
135         set "a\nb" var1
136         set x ${a
138 } var1
140 test parse-1.27 "backslash escape in dict sugar" {
141         unset -nocomplain a
142         set a(b\x55d) 5
143         set x $a(b\x55d)
144 } 5
146 test parse-1.28 "nested dict sugar" {
147         unset -nocomplain a b
148         set a(V) 5
149         set b(5) five
150         set x $b($a(V))
151 } five
153 set dq {"}
154 set script "set x ${dq}hello"
156 test parse-1.29 "missing quote" -constraints jim -body {
157         eval $script
158 } -returnCodes error -match glob -result {missing quote}
160 test parse-1.30 "missing quote" {
161         info complete $script
162 } 0
164 test parse-1.31 "backslash newline in bare context" {
165         list abc\
166         123
167 } {abc 123}
169 test parse-1.32 "comment as last line of script" {
170         set script {set x 3; # this is a comment}
171         eval $script
172 } 3
174 test parse-1.33 "upper case hex escapes" {
175         list \x4A \x4F \x3C
176 } {J O <}
178 test parse-1.34 "octal escapes" {
179         list \112 \117 \074
180 } {J O <}
182 test parse-1.35 "invalid hex escape" {
183         list \xZZ
184 } xZZ
186 test parse-1.36 "unicode escape" jim {
187         list \u00b5
188 } \xc2\xb5
190 test parse-1.37 "invalid unicode escape after unicode" jim {
191         list \ub5x
192 } \xc2\xb5x
194 test parse-1.38 "invalid unicode escape" {
195         list \ux
196 } ux
198 test parse-1.39 "octal escape followed by invalid" {
199         list \76x
200 } >x
202 test parse-1.40 "list containing quoted trailing backslash" jim {
203         set x "abc \"def\\"
204         lindex $x 1
205 } def\\
207 test parse-1.41 "list containing quoted newline" {
208         set x {abc "def
209 ghi"}
210         lindex $x 1
211 } def\nghi
213 test parse-1.42 "list containing missing quote" jim {
214         set x {abc "def}
215         lindex $x 1
216 } def
218 test parse-1.43 "list containing trailing backslash" {
219         set x "abc def\\"
220         lindex $x 1
221 } def\\
223 test parse-1.44 "list creation" {
224         list "a{ }d"
225 } {{a{ }d}}
227 test parse-1.45 "spaces before expr function args" {
228         expr {round  (3.2)}
229 } 3
231 test parse-1.46 "expr function missing paren" {
232         catch {expr {round 3.2}}
233 } 1
235 test parse-1.47 "backslash newline in quotes" {
236         # spaces
237         set x "abc\
238       def"
239 } "abc def"
241 test parse-1.48 "backslash newline in quotes" {
242         # tabs
243         set x "abc\
244                 def"
245 } "abc def"
247 test parse-1.49 "backslash newline in quotes" {
248         # tabs plus newline
249         set x "abc\
250                 
251 def"
252 } "abc \ndef"
254 test parse-1.50 "backslash newline in quotes" {
255         # tabs plus newline
256         set x "abc\
257 def"
258 } "abc def"
260 test parse-1.51 "special chars in dict sugar" {
261         unset -nocomplain a
262         set a(x$) 5
263         array names a
264 } {{x$}}
266 test parse-1.52 "special chars in dict sugar" {
267         set x $a(x$)
268 } 5
270 test parse-1.53 "special chars in dict sugar" {
271         unset -nocomplain a
272         set a(x\[) 5
273         array names a
274 } {{x[}}
276 test parse-1.54 "special chars in dict sugar" {
277         set x $a(x\[)
278 } 5
280 test parse-1.55 "special chars in dict sugar" {
281         unset -nocomplain a
282         set a(x\() 5
283         array names a
284 } {x(}
286 test parse-1.56 "special chars in dict sugar" {
287         set x $a(x\()
288 } 5
290 test parse-1.57 "special chars in dict sugar" {
291         unset -nocomplain a
292         set a(x() 5
293         array names a
294 } {x(}
296 test parse-1.58 "special chars in dict sugar" {
297         set x $a(x()
298 } 5
300 test parse-1.59 "special chars in dict sugar" {
301         unset -nocomplain a
302         set a(x") 5
303         lindex [array names a] 0
304 } {x"}
306 test parse-1.60 "special chars in dict sugar" {
307         set x $a(x")
308 } 5
310 test parse-1.61 "quote in command" {
311         set x [list \\" x]
312         lindex $x end
313 } x
315 test parse-1.62 "quoted orphan dollar sign" {
316         set x "x$"
317 } {x$}
319 test parse-1.63 "unquoted dollar sign" {
320         set x x$
321 } {x$}
323 test parse-1.64 "backslash in comment" {
324         set x 0
325         # comment \
326         incr x
327         incr x
328 } 1
330 test parse-1.65 "double backslash in comment" {
331         set x 0
332         # comment \\
333         incr x
334         incr x
335 } 2
338 testreport