os/persistentdata/persistentstorage/sqlite3api/TEST/TCL/tcldistribution/tests/parseOld.test
Update contrib.
1 # Commands covered: set (plus basic command syntax). Also tests the
2 # procedures in the file tclOldParse.c. This set of tests is an old
3 # one that predates the new parser in Tcl 8.1.
5 # This file contains a collection of tests for one or more of the Tcl
6 # built-in commands. Sourcing this file into Tcl runs the tests and
7 # generates output for errors. No output means no errors were found.
9 # Copyright (c) 1991-1993 The Regents of the University of California.
10 # Copyright (c) 1994-1996 Sun Microsystems, Inc.
11 # Copyright (c) 1998-1999 by Scriptics Corporation.
13 # See the file "license.terms" for information on usage and redistribution
14 # of this file, and for a DISCLAIMER OF ALL WARRANTIES.
16 # RCS: @(#) $Id: parseOld.test,v 1.11.2.1 2003/03/27 13:49:22 dkf Exp $
18 if {[lsearch [namespace children] ::tcltest] == -1} {
19 package require tcltest
20 namespace import -force ::tcltest::*
23 tcltest::testConstraint testwordend \
24 [string equal "testwordend" [info commands testwordend]]
26 # Save the argv value for restoration later
29 proc fourArgs {a b c d} {
30 global arg1 arg2 arg3 arg4
42 # Basic argument parsing.
44 test parseOld-1.1 {basic argument parsing} {
47 list $arg1 $arg2 $arg3 $arg4
49 test parseOld-1.2 {basic argument parsing} {
51 eval "fourArgs 123\v4\f56\r7890"
52 list $arg1 $arg2 $arg3 $arg4
57 test parseOld-2.1 {quotes and variable-substitution} {
61 test parseOld-2.2 {quotes and variable-substitution} {
66 test parseOld-2.3 {quotes and variable-substitution} {
67 set argv "xy[format xabc]"
70 test parseOld-2.4 {quotes and variable-substitution} {
74 test parseOld-2.5 {quotes and variable-substitution} {
79 test parseOld-2.6 {quotes and variable-substitution} {
86 test parseOld-3.1 {braces} {
90 test parseOld-3.2 {braces} {
93 set b [string index $argv 1]
96 test parseOld-3.3 {braces} {
97 set argv {a[format xyz] b}
100 test parseOld-3.4 {braces} {
104 test parseOld-3.5 {braces} {
108 test parseOld-3.6 {braces} {
112 test parseOld-3.7 {braces} {
113 set a [format "last]"]
117 # Command substitution.
119 test parseOld-4.1 {command substitution} {
123 test parseOld-4.2 {command substitution} {
124 set a a[format xyz]b[format q]
127 test parseOld-4.3 {command substitution} {
135 test parseOld-4.4 {command substitution} {
137 if [catch {expr int($a)}] {set a foo}
141 # Variable substitution.
143 test parseOld-5.1 {variable substitution} {
148 test parseOld-5.2 {variable substitution} {
153 test parseOld-5.3 {variable substitution} {
158 test parseOld-5.4 {variable substitution} {
163 test parseOld-5.5 {variable substitution} {catch {$_non_existent_} msg} 1
164 test parseOld-5.6 {variable substitution} {
165 catch {$_non_existent_} msg
167 } {can't read "_non_existent_": no such variable}
168 test parseOld-5.7 {array variable substitution} {
174 test parseOld-5.8 {array variable substitution} {
180 test parseOld-5.9 {array variable substitution} {
181 catch {unset a}; catch {unset qqq}
183 set $a([format x]\ y [format z]) foo
186 test parseOld-5.10 {array variable substitution} {
188 list [catch {set b $a(22)} msg] $msg
189 } {1 {can't read "a(22)": no such variable}}
190 test parseOld-5.11 {array variable substitution} {
194 test parseOld-5.12 {empty array name support} {
195 list [catch {set b a$()} msg] $msg
196 } {1 {can't read "()": no such variable}}
198 test parseOld-5.13 {array variable substitution} {
200 set long {This is a very long variable, long enough to cause storage \
201 allocation to occur in Tcl_ParseVar. If that storage isn't getting \
202 freed up correctly, then a core leak will occur when this test is \
203 run. This text is probably beginning to sound like drivel, but I've \
204 run out of things to say and I need more characters still.}
207 list $b [array names a]
208 } {777 {{This is a very long variable, long enough to cause storage \
209 allocation to occur in Tcl_ParseVar. If that storage isn't getting \
210 freed up correctly, then a core leak will occur when this test is \
211 run. This text is probably beginning to sound like drivel, but I've \
212 run out of things to say and I need more characters still.}}}
213 test parseOld-5.14 {array variable substitution} {
214 catch {unset a}; catch {unset b}; catch {unset a1}
220 catch {unset a}; catch {unset a1}
222 test parseOld-7.1 {backslash substitution} {
226 test parseOld-7.2 {backslash substitution} {
230 test parseOld-7.3 {backslash substitution} {
235 test parseOld-7.4 {backslash substitution} {
240 test parseOld-7.5 {backslash substitution} {
243 set error [catch {if {24 < \
244 35} {set a 22} {set \
248 test parseOld-7.6 {backslash substitution} {
251 test parseOld-7.7 {backslash substitution} {
254 test parseOld-7.8 {backslash substitution} {
255 eval "concat x\\\n a"
257 test parseOld-7.9 {backslash substitution} {
260 test parseOld-7.10 {backslash substitution} {
261 eval "list a b\\\nc d"
263 test parseOld-7.11 {backslash substitution} {
264 eval "list a \"b c\"\\\nd e"
266 test parseOld-7.12 {backslash substitution} {
268 } [bytestring "\xc2\xa2"]
269 test parseOld-7.13 {backslash substitution} {
271 } [bytestring "\xe4\xb8\xa1"]
272 test parseOld-7.14 {backslash substitution} {
274 } [bytestring "\xd3\xa2k"]
278 test parseOld-8.1 {semi-colons} {
283 test parseOld-8.2 {semi-colons} {
288 test parseOld-8.3 {semi-colons} {
289 getArgs a b ; set b 1
292 test parseOld-8.4 {semi-colons} {
293 getArgs a b ; set b 1
297 # The following checks are to ensure that the interpreter's result
298 # gets re-initialized by Tcl_Eval in all the right places.
300 test parseOld-9.1 {result initialization} {concat abc} abc
301 test parseOld-9.2 {result initialization} {concat abc; proc foo {} {}} {}
302 test parseOld-9.3 {result initialization} {concat abc; proc foo {} $a} {}
303 test parseOld-9.4 {result initialization} {proc foo {} [concat abc]} {}
304 test parseOld-9.5 {result initialization} {concat abc; } abc
305 test parseOld-9.6 {result initialization} {
309 test parseOld-9.7 {result initialization} {} {}
310 test parseOld-9.8 {result initialization} {concat abc; ; ;} abc
314 test parseOld-10.1 {syntax errors} {catch "set a \{bcd" msg} 1
315 test parseOld-10.2 {syntax errors} {
316 catch "set a \{bcd" msg
318 } {missing close-brace}
319 test parseOld-10.3 {syntax errors} {catch {set a "bcd} msg} 1
320 test parseOld-10.4 {syntax errors} {
321 catch {set a "bcd} msg
324 #" Emacs formatting >:^(
325 test parseOld-10.5 {syntax errors} {catch {set a "bcd"xy} msg} 1
326 test parseOld-10.6 {syntax errors} {
327 catch {set a "bcd"xy} msg
329 } {extra characters after close-quote}
330 test parseOld-10.7 {syntax errors} {catch "set a {bcd}xy" msg} 1
331 test parseOld-10.8 {syntax errors} {
332 catch "set a {bcd}xy" msg
334 } {extra characters after close-brace}
335 test parseOld-10.9 {syntax errors} {catch {set a [format abc} msg} 1
336 test parseOld-10.10 {syntax errors} {
337 catch {set a [format abc} msg
339 } {missing close-bracket}
340 test parseOld-10.11 {syntax errors} {catch gorp-a-lot msg} 1
341 test parseOld-10.12 {syntax errors} {
344 } {invalid command name "gorp-a-lot"}
345 test parseOld-10.13 {syntax errors} {
351 # The next test will fail on the Mac, 'cause the MSL uses a fixed sized
352 # buffer for %d conversions (LAME!). I won't leave the test out, however,
353 # since MetroWerks may some day fix this.
355 test parseOld-10.14 {syntax errors} {
356 list [catch {eval \$x[format "%01000d" 0](} msg] $msg $errorInfo
357 } {1 {missing )} {missing )
359 "$x0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000..."
362 "eval \$x[format "%01000d" 0]("}}
363 test parseOld-10.15 {syntax errors, missplaced braces} {
365 proc misplaced_end_brace {} {
367 set when [expr ${what}size - [set off$what]}]
370 } {extra characters after close-brace}
371 test parseOld-10.16 {syntax errors, missplaced braces} {
375 set when [expr ${what}size - [set off$what]}]
378 } {extra characters after close-brace}
379 test parseOld-10.17 {syntax errors, unusual spacing} {
380 list [catch {return [ [1]]} msg] $msg
381 } {1 {invalid command name "1"}}
382 # Long values (stressing storage management)
384 set a {1111 2222 3333 4444 5555 6666 7777 8888 9999 aaaa bbbb cccc dddd eeee ffff gggg hhhh iiii jjjj kkkk llll mmmm nnnn oooo pppp qqqq rrrr ssss tttt uuuu vvvv wwww xxxx yyyy zzzz AAAA BBBB CCCC DDDD EEEE FFFF GGGG HHHH}
386 test parseOld-11.1 {long values} {
389 test parseOld-11.2 {long values} {
392 test parseOld-11.3 {long values} {
393 set b "1111 2222 3333 4444 5555 6666 7777 8888 9999 aaaa bbbb cccc dddd eeee ffff gggg hhhh iiii jjjj kkkk llll mmmm nnnn oooo pppp qqqq rrrr ssss tttt uuuu vvvv wwww xxxx yyyy zzzz AAAA BBBB CCCC DDDD EEEE FFFF GGGG HHHH"
396 test parseOld-11.4 {long values} {
400 test parseOld-11.5 {long values} {
404 test parseOld-11.6 {long values} {
405 set b [concat 1111 2222 3333 4444 5555 6666 7777 8888 9999 aaaa bbbb cccc dddd eeee ffff gggg hhhh iiii jjjj kkkk llll mmmm nnnn oooo pppp qqqq rrrr ssss tttt uuuu vvvv wwww xxxx yyyy zzzz AAAA BBBB CCCC DDDD EEEE FFFF GGGG HHHH]
408 test parseOld-11.7 {long values} {
409 set b [concat 1111 2222 3333 4444 5555 6666 7777 8888 9999 aaaa bbbb cccc dddd eeee ffff gggg hhhh iiii jjjj kkkk llll mmmm nnnn oooo pppp qqqq rrrr ssss tttt uuuu vvvv wwww xxxx yyyy zzzz AAAA BBBB CCCC DDDD EEEE FFFF GGGG HHHH]
412 test parseOld-11.8 {long values} {
415 test parseOld-11.9 {long values} {
416 set a [concat 0000 1111 2222 3333 4444 5555 6666 7777 8888 9999 aaaa bbbb cccc dddd eeee ffff gggg hhhh iiii jjjj kkkk llll mmmm nnnn oooo pppp qqqq rrrr ssss tttt uuuu vvvv wwww xxxx yyyy zzzz AAAA BBBB CCCC DDDD EEEE FFFF GGGG HHHH IIII JJJJ KKKK LLLL MMMM NNNN OOOO PPPP QQQQ RRRR SSSS TTTT UUUU VVVV WWWW XXXX YYYY ZZZZ]
420 foreach j [concat 0000 1111 2222 3333 4444 5555 6666 7777 8888 9999 aaaa bbbb cccc dddd eeee ffff gggg hhhh iiii jjjj kkkk llll mmmm nnnn oooo pppp qqqq rrrr ssss tttt uuuu vvvv wwww xxxx yyyy zzzz AAAA BBBB CCCC DDDD EEEE FFFF GGGG HHHH IIII JJJJ KKKK LLLL MMMM NNNN OOOO PPPP QQQQ RRRR SSSS TTTT UUUU VVVV WWWW XXXX YYYY ZZZZ] {
421 set test [string index 0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ $i]
422 set test $test$test$test$test
423 test parseOld-11.10-[incr i] {long values} {
427 test parseOld-11.11 {test buffer overflow in backslashes in braces} {
428 expr {"a" == {xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy\101\101\101\101\101\101\101\101\101\101\101\101\101\101\101\101\101\101\101\101\101\101\101\101\101\101}}
431 test parseOld-12.1 {comments} {
436 test parseOld-12.2 {comments} {
438 eval " # set a new\nset a new"
441 test parseOld-12.3 {comments} {
443 eval " # set a new\\\nset a new"
446 test parseOld-12.4 {comments} {
448 eval " # set a new\\\\\nset a new"
452 test parseOld-13.1 {comments at the end of a bracketed script} {
459 test parseOld-14.1 {TclWordEnd procedure} {testwordend} {
460 testwordend " \n abc"
462 test parseOld-14.2 {TclWordEnd procedure} {testwordend} {
465 test parseOld-14.3 {TclWordEnd procedure} {testwordend} {
468 test parseOld-14.4 {TclWordEnd procedure} {testwordend} {
471 #" Emacs formatting >:^(
472 test parseOld-14.5 {TclWordEnd procedure} {testwordend} {
475 test parseOld-14.6 {TclWordEnd procedure} {testwordend} {
476 testwordend {{a{}b{}\}} xyz}
478 test parseOld-14.7 {TclWordEnd procedure} {testwordend} {
479 testwordend {abc[this is a]def ghi}
481 test parseOld-14.8 {TclWordEnd procedure} {testwordend} {
482 testwordend "puts\\\n\n "
484 test parseOld-14.9 {TclWordEnd procedure} {testwordend} {
485 testwordend "puts\\\n "
487 test parseOld-14.10 {TclWordEnd procedure} {testwordend} {
488 testwordend "puts\\\n xyz"
490 test parseOld-14.11 {TclWordEnd procedure} {testwordend} {
491 testwordend {a$x.$y(a long index) foo}
493 test parseOld-14.12 {TclWordEnd procedure} {testwordend} {
494 testwordend {abc; def}
496 test parseOld-14.13 {TclWordEnd procedure} {testwordend} {
497 testwordend {abc def}
499 test parseOld-14.14 {TclWordEnd procedure} {testwordend} {
500 testwordend {abc def}
502 test parseOld-14.15 {TclWordEnd procedure} {testwordend} {
503 testwordend "abc\ndef"
505 test parseOld-14.16 {TclWordEnd procedure} {testwordend} {
508 test parseOld-14.17 {TclWordEnd procedure} {testwordend} {
509 testwordend "a\000bc"
511 test parseOld-14.18 {TclWordEnd procedure} {testwordend} {
512 testwordend \[a\000\]
514 test parseOld-14.19 {TclWordEnd procedure} {testwordend} {
515 testwordend \"a\000\"
517 #" Emacs formatting >:^(
518 test parseOld-14.20 {TclWordEnd procedure} {testwordend} {
521 test parseOld-14.21 {TclWordEnd procedure} {testwordend} {
525 test parseOld-15.1 {TclScriptEnd procedure} {
526 info complete {puts [
528 #this is a comment ]}
530 test parseOld-15.2 {TclScriptEnd procedure} {
531 info complete "abc\\\n"
533 test parseOld-15.3 {TclScriptEnd procedure} {
534 info complete "abc\\\\\n"
536 test parseOld-15.4 {TclScriptEnd procedure} {
537 info complete "xyz \[abc \{abc\]"
539 test parseOld-15.5 {TclScriptEnd procedure} {
540 info complete "xyz \[abc"
545 ::tcltest::cleanupTests