os/persistentdata/persistentstorage/sqlite3api/TEST/TCL/tcldistribution/tests/while.test
Update contrib.
1 # Commands covered: while
3 # This file contains a collection of tests for one or more of the Tcl
4 # built-in commands. Sourcing this file into Tcl runs the tests and
5 # generates output for errors. No output means no errors were found.
7 # Copyright (c) 1996 Sun Microsystems, Inc.
8 # Copyright (c) 1998-1999 by Scriptics Corporation.
10 # See the file "license.terms" for information on usage and redistribution
11 # of this file, and for a DISCLAIMER OF ALL WARRANTIES.
13 # RCS: @(#) $Id: while.test,v 1.8 2001/12/04 15:36:29 dkf Exp $
15 if {[lsearch [namespace children] ::tcltest] == -1} {
16 package require tcltest
17 namespace import -force ::tcltest::*
20 # Basic "while" operation.
25 test while-1.1 {TclCompileWhileCmd: missing test expression} {
28 } {wrong # args: should be "while test command"}
29 test while-1.2 {TclCompileWhileCmd: error in test expression} {
31 catch {while {$i<} break} msg
33 } {syntax error in expression "$i<": premature end of expression
34 ("while" test expression)
37 test while-1.3 {TclCompileWhileCmd: error in test expression} {
38 set err [catch {while {"a"+"b"} {error "loop aborted"}} msg]
40 } {1 {can't use non-numeric string as operand of "+"}}
41 test while-1.4 {TclCompileWhileCmd: multiline test expr} {
43 while {($tcl_platform(platform) != "foobar1") && \
44 ($tcl_platform(platform) != "foobar2")} {
50 test while-1.5 {TclCompileWhileCmd: non-numeric boolean test expr} {
60 test while-1.6 {TclCompileWhileCmd: test expr is enclosed in quotes} {
64 test while-1.7 {TclCompileWhileCmd: missing command body} {
66 catch {while {$i < 5} } msg
68 } {wrong # args: should be "while test command"}
69 test while-1.8 {TclCompileWhileCmd: error compiling command body} {
71 catch {while {$i < 5} {set}} msg
73 } {wrong # args: should be "set varName ?newValue?"
78 "while {$i < 5} {set}"}
79 test while-1.9 {TclCompileWhileCmd: simple command body} {
89 test while-1.10 {TclCompileWhileCmd: command body in quotes} {
92 while {$i<6} "append a x; incr i"
95 test while-1.11 {TclCompileWhileCmd: computed command body} {
99 set x1 {append a x1; }
101 set x2 {; append a x2; incr i}
104 while {$i<6} $x1$bb$x2
107 test while-1.12 {TclCompileWhileCmd: long command body} {
113 if {$i>6 && $tcl_platform(machine)=="xxx"} {
116 catch {incr i -5} msg
118 if {$i>6 && $tcl_platform(machine)=="xxx"} {
121 catch {incr i -5} msg
123 if {$i>6 && $tcl_platform(machine)=="xxx"} {
126 catch {incr i -5} msg
128 if {$i>6 && $tcl_platform(machine)=="xxx"} {
131 catch {incr i -5} msg
133 if {$i>6 && $tcl_platform(machine)=="xxx"} {
136 catch {incr i -5} msg
143 test while-1.13 {TclCompileWhileCmd: while command result} {
145 set a [while {$i < 5} {incr i}]
148 test while-1.14 {TclCompileWhileCmd: while command result} {
150 set a [while {$i < 5} {if $i==3 break; incr i}]
154 # Check "while" and "continue".
156 test while-2.1 {continue tests} {
161 if {$i == 3} continue
166 test while-2.2 {continue tests} {
171 if {$i != 2} continue
176 test while-2.3 {continue tests, nested loops} {
184 if {$i>=3 && $a>=3} continue
185 set msg [concat $msg "$i.$a"]
189 } {2.2 2.3 3.2 4.2 5.2}
190 test while-2.4 {continue tests, long command body} {
194 if $i==2 {incr i; continue}
197 if {$i>6 && $tcl_platform(machine)=="xxx"} {
200 catch {incr i -5} msg
202 if {$i>6 && $tcl_platform(machine)=="xxx"} {
205 catch {incr i -5} msg
207 if {$i>6 && $tcl_platform(machine)=="xxx"} {
210 catch {incr i -5} msg
212 if {$i>6 && $tcl_platform(machine)=="xxx"} {
215 catch {incr i -5} msg
217 if {$i>6 && $tcl_platform(machine)=="xxx"} {
220 catch {incr i -5} msg
228 # Check "while" and "break".
230 test while-3.1 {break tests} {
240 test while-3.2 {break tests, nested loops} {
246 if {$i>=2 && $a>=2} break
247 set msg [concat $msg "$i.$a"]
253 } {1.1 1.2 2.1 3.1 4.1}
254 test while-3.3 {break tests, long command body} {
258 if $i==2 {incr i; continue}
261 if {$i>6 && $tcl_platform(machine)=="xxx"} {
264 catch {incr i -5} msg
266 if {$i>6 && $tcl_platform(machine)=="xxx"} {
269 catch {incr i -5} msg
271 if {$i>6 && $tcl_platform(machine)=="xxx"} {
274 catch {incr i -5} msg
277 if {$i>6 && $tcl_platform(machine)=="xxx"} {
280 catch {incr i -5} msg
282 if {$i>6 && $tcl_platform(machine)=="xxx"} {
285 catch {incr i -5} msg
293 # Check "while" with computed command names.
295 test while-4.1 {while and computed command names} {
303 test while-4.2 {while (not compiled): missing test expression} {
307 } {wrong # args: should be "while test command"}
308 test while-4.3 {while (not compiled): error in test expression} {
311 catch {$z {$i<} {set x 1}} msg
313 } {syntax error in expression "$i<": premature end of expression
315 "$z {$i<} {set x 1}"}
316 test while-4.4 {while (not compiled): error in test expression} {
318 set err [catch {$z {"a"+"b"} {error "loop aborted"}} msg]
320 } {1 {can't use non-numeric string as operand of "+"}}
321 test while-4.5 {while (not compiled): multiline test expr} {
324 $z {($tcl_platform(platform) != "foobar1") && \
325 ($tcl_platform(platform) != "foobar2")} {
331 test while-4.6 {while (not compiled): non-numeric boolean test expr} {
342 test while-4.7 {while (not compiled): test expr is enclosed in quotes} {
347 test while-4.8 {while (not compiled): missing command body} {
350 catch {$z {$i < 5} } msg
352 } {wrong # args: should be "while test command"}
353 test while-4.9 {while (not compiled): error compiling command body} {
356 catch {$z {$i < 5} {set}} msg
358 } {wrong # args: should be "set varName ?newValue?"
361 ("while" body line 1)
364 test while-4.10 {while (not compiled): simple command body} {
375 test while-4.11 {while (not compiled): command body in quotes} {
379 $z {$i<6} "append a x; incr i"
382 test while-4.12 {while (not compiled): computed command body} {
387 set x1 {append a x1; }
389 set x2 {; append a x2; incr i}
395 test while-4.13 {while (not compiled): long command body} {
402 if {$i>6 && $tcl_platform(machine)=="xxx"} {
405 catch {incr i -5} msg
407 if {$i>6 && $tcl_platform(machine)=="xxx"} {
410 catch {incr i -5} msg
412 if {$i>6 && $tcl_platform(machine)=="xxx"} {
415 catch {incr i -5} msg
417 if {$i>6 && $tcl_platform(machine)=="xxx"} {
420 catch {incr i -5} msg
422 if {$i>6 && $tcl_platform(machine)=="xxx"} {
425 catch {incr i -5} msg
432 test while-4.14 {while (not compiled): while command result} {
435 set a [$z {$i < 5} {incr i}]
438 test while-4.15 {while (not compiled): while command result} {
441 set a [$z {$i < 5} {if $i==3 break; incr i}]
445 # Check "break" with computed command names.
447 test while-5.1 {break and computed command names} {
456 test while-5.2 {break tests with computed command names} {
467 test while-5.3 {break tests, nested loops with computed command names} {
474 if {$i>=2 && $a>=2} $z
475 set msg [concat $msg "$i.$a"]
481 } {1.1 1.2 2.1 3.1 4.1}
482 test while-5.4 {break tests, long command body with computed command names} {
487 if $i==2 {incr i; continue}
490 if {$i>6 && $tcl_platform(machine)=="xxx"} {
493 catch {incr i -5} msg
495 if {$i>6 && $tcl_platform(machine)=="xxx"} {
498 catch {incr i -5} msg
500 if {$i>6 && $tcl_platform(machine)=="xxx"} {
503 catch {incr i -5} msg
506 if {$i>6 && $tcl_platform(machine)=="xxx"} {
509 catch {incr i -5} msg
511 if {$i>6 && $tcl_platform(machine)=="xxx"} {
514 catch {incr i -5} msg
522 # Check "continue" with computed command names.
524 test while-6.1 {continue and computed command names} {
534 test while-6.2 {continue tests} {
545 test while-6.3 {continue tests with computed command names} {
556 test while-6.4 {continue tests, nested loops with computed command names} {
565 if {$i>=3 && $a>=3} $z
566 set msg [concat $msg "$i.$a"]
570 } {2.2 2.3 3.2 4.2 5.2}
571 test while-6.5 {continue tests, long command body with computed command names} {
576 if $i==2 {incr i; continue}
579 if {$i>6 && $tcl_platform(machine)=="xxx"} {
582 catch {incr i -5} msg
584 if {$i>6 && $tcl_platform(machine)=="xxx"} {
587 catch {incr i -5} msg
589 if {$i>6 && $tcl_platform(machine)=="xxx"} {
592 catch {incr i -5} msg
594 if {$i>6 && $tcl_platform(machine)=="xxx"} {
597 catch {incr i -5} msg
599 if {$i>6 && $tcl_platform(machine)=="xxx"} {
602 catch {incr i -5} msg
610 # Test for incorrect "double evaluation" semantics
612 test while-7.1 {delayed substitution of body} {
614 while {[incr i] < 10} "
619 while {[incr i] < 10} "
628 ::tcltest::cleanupTests