Trim bootstrap jimsh
[jimtcl.git] / tests / for.test
blobd12385a6f6a56b181b2713e4223c3f012487f6a9
1 # Commands covered:  for, continue, break
3 # This file contains the original set of tests for Tcl's for command.
4 # Since the for command is now compiled, a new set of tests covering
5 # the new implementation is in the file "for.test". Sourcing this file
6 # into Tcl runs the tests and generates output for errors.
7 # 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.
12 # See the file "license.terms" for information on usage and redistribution
13 # of this file, and for a DISCLAIMER OF ALL WARRANTIES.
15 # RCS: @(#) $Id: for-old.test,v 1.5 2000/04/10 17:18:59 ericm Exp $
17 source [file dirname [info script]]/testing.tcl
19 # Check "for" and its use of continue and break.
21 catch {unset a i}
22 test for-old-1.1 {for tests} {
23     set a {}
24     for {set i 1} {$i<6} {set i [expr $i+1]} {
25         set a [concat $a $i]
26     }
27     set a
28 } {1 2 3 4 5}
29 test for-old-1.2 {for tests} {
30     set a {}
31     for {set i 1} {$i<6} {set i [expr $i+1]} {
32         if $i==4 continue
33         set a [concat $a $i]
34     }
35     set a
36 } {1 2 3 5}
37 test for-old-1.3 {for tests} {
38     set a {}
39     for {set i 1} {$i<6} {set i [expr $i+1]} {
40         if $i==4 break
41         set a [concat $a $i]
42     }
43     set a
44 } {1 2 3}
45 test for-old-1.4 {for tests} {catch {for 1 2 3} msg} 1
46 test for-old-1.5 {for tests} {
47     catch {for 1 2 3} msg
48 } {1}
49 test for-old-1.6 {for tests} {catch {for 1 2 3 4 5} msg} 1
50 test for-old-1.7 {for tests} {
51     catch {for 1 2 3 4 5} msg
52 } {1}
53 test for-old-1.8 {for tests} {
54     set a {xyz}
55     for {set i 1} {$i<6} {set i [expr $i+1]} {}
56     set a
57 } xyz
58 test for-old-1.9 {for tests} {
59     set a {}
60     for {set i 1} {$i<6} {set i [expr $i+1]; if $i==4 break} {
61         set a [concat $a $i]
62     }
63     set a
64 } {1 2 3}
66 testreport