File: loop.test

package info (click to toggle)
tclx8.4 8.4.1-6
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,800 kB
  • sloc: ansic: 14,863; tcl: 2,090; sh: 265; makefile: 159
file content (152 lines) | stat: -rw-r--r-- 2,956 bytes parent folder | download | duplicates (9)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
#
# loop.test
#
# Tests for the loop command.
#---------------------------------------------------------------------------
# Copyright 1992-1999 Karl Lehenbauer and Mark Diekhans.
#
# Permission to use, copy, modify, and distribute this software and its
# documentation for any purpose and without fee is hereby granted, provided
# that the above copyright notice appear in all copies.  Karl Lehenbauer and
# Mark Diekhans make no representations about the suitability of this
# software for any purpose.  It is provided "as is" without express or
# implied warranty.
#------------------------------------------------------------------------------
# $Id: loop.test,v 1.2 2002/04/02 02:29:43 hobbs Exp $
#------------------------------------------------------------------------------
#

if {[cequal [info procs Test] {}]} {
    source [file join [file dirname [info script]] testlib.tcl]
}

Test loop-1.1 {loop tests} {
    set a {}
    set i 1
    loop i 1 6 {
        set a [concat $a $i]
    }
    set a
} 0 {1 2 3 4 5}

Test loop-1.2 {loop tests} {
    set a {}
    loop i 1 6 {
        if {$i == 4} {
            continue}
        set a [concat $a $i]
    }
    set a
} 0 {1 2 3 5}

Test loop-1.3 {loop tests} {
    set a {}
    loop i 1 6 {
        if $i==4 break
        set a [concat $a $i]
    }
    set a
} 0 {1 2 3}

Test loop-1.4 {loop tests} {
    loop 1 2 3
} 1 {wrong # args: loop var first limit ?incr? command}

Test loop-1.5 {loop tests} {
    loop 1 2 3 4 5 6
} 1 {wrong # args: loop var first limit ?incr? command}

Test loop-1.6 {loop tests} {
    set a {}
    loop i 1 6 {
        set a [concat $a $i]
        set i 100
    }
    set a
} 0 {1 2 3 4 5}

Test loop-1.7 {loop tests} {
    set a {}
    loop i 1 6 2 {
        set a [concat $a $i]
    }
    set a
} 0 {1 3 5}

Test loop-1.8 {loop tests} {
    set a {}
    set i 1
    loop i 6 1 -1 {
        set a [concat $a $i]
    }
    set a
} 0 {6 5 4 3 2}

Test loop-1.9 {loop tests} {
    set a {}
    loop i 6 1 -1 {
        if $i==4 {
            continue}
        set a [concat $a $i]
    }
    set a
} 0 {6 5 3 2}

Test loop-1.10 {loop tests} {
    set a {}
    loop i 6 1 -1 {
        if {$i == 4} {
            break}
        set a [concat $a $i]
    }
    set a
} 0 {6 5}

Test loop-1.11 {loop tests} {
    set j 0
    loop i 65536 65556 {
        incr j
    }
    set j
} 0 20

Test loop-1.12 {loop tests} {
    set j 0
    loop i 65556 65536 -1 {
        incr j 1
    }
    set j
} 0 20

Test loop-1.13 {loop tests} {
    set j 0
    loop i 0 655360 65536 {
        incr j 1
    }
    set j
} 0 10

Test loop-1.14 {loop tests} {
    set j 0
    loop i 655360 0 -65536 {
        incr j 1
    }
    set j
} 0 10

Test loop-1.15 {loop tests} {
    set a {}
    set i 1
    loop i 3*2 0+1 10-11 {
        set a [concat $a $i]
    }
    set a
} 0 {6 5 4 3 2}

Test loop-2.1 {loop test} {
    loop i 0 5 {error "an error"}
} 1 {an error}

# cleanup
::tcltest::cleanupTests
return