OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [insight/] [tcl/] [tests/] [incr.test] - Blame information for rev 1765

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 578 markom
# Commands covered:  incr
2
#
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.
6
#
7
# Copyright (c) 1996 Sun Microsystems, Inc.
8
#
9
# See the file "license.terms" for information on usage and redistribution
10
# of this file, and for a DISCLAIMER OF ALL WARRANTIES.
11
#
12
# RCS: @(#) $Id: incr.test,v 1.1.1.1 2002-01-16 10:25:36 markom Exp $
13
 
14
if {[string compare test [info procs test]] == 1} then {source defs}
15
 
16
# Basic "incr" operation.
17
 
18
catch {unset x}
19
catch {unset i}
20
 
21
test incr-1.1 {TclCompileIncrCmd: missing variable name} {
22
    list [catch {incr} msg] $msg
23
} {1 {wrong # args: should be "incr varName ?increment?"}}
24
test incr-1.2 {TclCompileIncrCmd: simple variable name} {
25
    set i 10
26
    list [incr i] $i
27
} {11 11}
28
test incr-1.3 {TclCompileIncrCmd: error compiling variable name} {
29
    set i 10
30
    catch {incr "i"xxx} msg
31
    set msg
32
} {extra characters after close-quote}
33
test incr-1.4 {TclCompileIncrCmd: simple variable name in quotes} {
34
    set i 17
35
    list [incr "i"] $i
36
} {18 18}
37
test incr-1.5 {TclCompileIncrCmd: simple variable name in braces} {
38
    catch {unset {a simple var}}
39
    set {a simple var} 27
40
    list [incr {a simple var}] ${a simple var}
41
} {28 28}
42
test incr-1.6 {TclCompileIncrCmd: simple array variable name} {
43
    catch {unset a}
44
    set a(foo) 37
45
    list [incr a(foo)] $a(foo)
46
} {38 38}
47
test incr-1.7 {TclCompileIncrCmd: non-simple (computed) variable name} {
48
    set x "i"
49
    set i 77
50
    list [incr $x 2] $i
51
} {79 79}
52
test incr-1.8 {TclCompileIncrCmd: non-simple (computed) variable name} {
53
    set x "i"
54
    set i 77
55
    list [incr [set x] +2] $i
56
} {79 79}
57
 
58
test incr-1.9 {TclCompileIncrCmd: increment given} {
59
    set i 10
60
    list [incr i +07] $i
61
} {17 17}
62
test incr-1.10 {TclCompileIncrCmd: no increment given} {
63
    set i 10
64
    list [incr i] $i
65
} {11 11}
66
 
67
test incr-1.11 {TclCompileIncrCmd: simple global name} {
68
    proc p {} {
69
        global i
70
        set i 54
71
        incr i
72
    }
73
    p
74
} {55}
75
test incr-1.12 {TclCompileIncrCmd: simple local name} {
76
    proc p {} {
77
        set foo 100
78
        incr foo
79
    }
80
    p
81
} {101}
82
test incr-1.13 {TclCompileIncrCmd: simple but new (unknown) local name} {
83
    proc p {} {
84
        incr bar
85
    }
86
    catch {p} msg
87
    set msg
88
} {can't read "bar": no such variable}
89
test incr-1.14 {TclCompileIncrCmd: simple local name, >255 locals} {
90
    proc 260locals {} {
91
        # create 260 locals
92
        set a0 0; set a1 0; set a2 0; set a3 0; set a4 0
93
        set a5 0; set a6 0; set a7 0; set a8 0; set a9 0
94
        set b0 0; set b1 0; set b2 0; set b3 0; set b4 0
95
        set b5 0; set b6 0; set b7 0; set b8 0; set b9 0
96
        set c0 0; set c1 0; set c2 0; set c3 0; set c4 0
97
        set c5 0; set c6 0; set c7 0; set c8 0; set c9 0
98
        set d0 0; set d1 0; set d2 0; set d3 0; set d4 0
99
        set d5 0; set d6 0; set d7 0; set d8 0; set d9 0
100
        set e0 0; set e1 0; set e2 0; set e3 0; set e4 0
101
        set e5 0; set e6 0; set e7 0; set e8 0; set e9 0
102
        set f0 0; set f1 0; set f2 0; set f3 0; set f4 0
103
        set f5 0; set f6 0; set f7 0; set f8 0; set f9 0
104
        set g0 0; set g1 0; set g2 0; set g3 0; set g4 0
105
        set g5 0; set g6 0; set g7 0; set g8 0; set g9 0
106
        set h0 0; set h1 0; set h2 0; set h3 0; set h4 0
107
        set h5 0; set h6 0; set h7 0; set h8 0; set h9 0
108
        set i0 0; set i1 0; set i2 0; set i3 0; set i4 0
109
        set i5 0; set i6 0; set i7 0; set i8 0; set i9 0
110
        set j0 0; set j1 0; set j2 0; set j3 0; set j4 0
111
        set j5 0; set j6 0; set j7 0; set j8 0; set j9 0
112
        set k0 0; set k1 0; set k2 0; set k3 0; set k4 0
113
        set k5 0; set k6 0; set k7 0; set k8 0; set k9 0
114
        set l0 0; set l1 0; set l2 0; set l3 0; set l4 0
115
        set l5 0; set l6 0; set l7 0; set l8 0; set l9 0
116
        set m0 0; set m1 0; set m2 0; set m3 0; set m4 0
117
        set m5 0; set m6 0; set m7 0; set m8 0; set m9 0
118
        set n0 0; set n1 0; set n2 0; set n3 0; set n4 0
119
        set n5 0; set n6 0; set n7 0; set n8 0; set n9 0
120
        set o0 0; set o1 0; set o2 0; set o3 0; set o4 0
121
        set o5 0; set o6 0; set o7 0; set o8 0; set o9 0
122
        set p0 0; set p1 0; set p2 0; set p3 0; set p4 0
123
        set p5 0; set p6 0; set p7 0; set p8 0; set p9 0
124
        set q0 0; set q1 0; set q2 0; set q3 0; set q4 0
125
        set q5 0; set q6 0; set q7 0; set q8 0; set q9 0
126
        set r0 0; set r1 0; set r2 0; set r3 0; set r4 0
127
        set r5 0; set r6 0; set r7 0; set r8 0; set r9 0
128
        set s0 0; set s1 0; set s2 0; set s3 0; set s4 0
129
        set s5 0; set s6 0; set s7 0; set s8 0; set s9 0
130
        set t0 0; set t1 0; set t2 0; set t3 0; set t4 0
131
        set t5 0; set t6 0; set t7 0; set t8 0; set t9 0
132
        set u0 0; set u1 0; set u2 0; set u3 0; set u4 0
133
        set u5 0; set u6 0; set u7 0; set u8 0; set u9 0
134
        set v0 0; set v1 0; set v2 0; set v3 0; set v4 0
135
        set v5 0; set v6 0; set v7 0; set v8 0; set v9 0
136
        set w0 0; set w1 0; set w2 0; set w3 0; set w4 0
137
        set w5 0; set w6 0; set w7 0; set w8 0; set w9 0
138
        set x0 0; set x1 0; set x2 0; set x3 0; set x4 0
139
        set x5 0; set x6 0; set x7 0; set x8 0; set x9 0
140
        set y0 0; set y1 0; set y2 0; set y3 0; set y4 0
141
        set y5 0; set y6 0; set y7 0; set y8 0; set y9 0
142
        set z0 0; set z1 0; set z2 0; set z3 0; set z4 0
143
        set z5 0; set z6 0; set z7 0; set z8 0; set z9 0
144
        # now increment the last one (local var index > 255)
145
        incr z9
146
    }
147
    260locals
148
} {1}
149
test incr-1.15 {TclCompileIncrCmd: variable is array} {
150
    catch {unset a}
151
    set a(foo) 27
152
    set x [incr a(foo) 11]
153
    catch {unset a}
154
    set x
155
} 38
156
test incr-1.16 {TclCompileIncrCmd: variable is array, elem substitutions} {
157
    catch {unset a}
158
    set i 5
159
    set a(foo5) 27
160
    set x [incr a(foo$i) 11]
161
    catch {unset a}
162
    set x
163
} 38
164
 
165
test incr-1.17 {TclCompileIncrCmd: increment given, simple int} {
166
    set i 5
167
    incr i 123
168
} 128
169
test incr-1.18 {TclCompileIncrCmd: increment given, simple int} {
170
    set i 5
171
    incr i -100
172
} -95
173
test incr-1.19 {TclCompileIncrCmd: increment given, but erroneous} {
174
    set i 5
175
    catch {incr i [set]} msg
176
    set errorInfo
177
} {wrong # args: should be "set varName ?newValue?"
178
    while compiling
179
"set"
180
    (increment expression)
181
    while compiling
182
"incr i [set]"}
183
test incr-1.20 {TclCompileIncrCmd: increment given, in quotes} {
184
    set i 25
185
    incr i "-100"
186
} -75
187
test incr-1.21 {TclCompileIncrCmd: increment given, in braces} {
188
    set i 24
189
    incr i {126}
190
} 150
191
test incr-1.22 {TclCompileIncrCmd: increment given, large int} {
192
    set i 5
193
    incr i 200000
194
} 200005
195
test incr-1.23 {TclCompileIncrCmd: increment given, formatted int != int} {
196
    set i 25
197
    incr i 000012345     ;# an octal literal
198
} 5374
199
test incr-1.24 {TclCompileIncrCmd: increment given, formatted int != int} {
200
    set i 25
201
    catch {incr i 1a} msg
202
    set msg
203
} {expected integer but got "1a"}
204
 
205
test incr-1.25 {TclCompileIncrCmd: too many arguments} {
206
    set i 10
207
    catch {incr i 10 20} msg
208
    set msg
209
} {wrong # args: should be "incr varName ?increment?"}
210
 
211
 
212
test incr-1.26 {TclCompileIncrCmd: runtime error, bad variable name} {
213
    list [catch {incr {"foo}} msg] $msg $errorInfo
214
} {1 {can't read ""foo": no such variable} {can't read ""foo": no such variable
215
    (reading value of variable to increment)
216
    invoked from within
217
"incr {"foo}"}}
218
test incr-1.27 {TclCompileIncrCmd: runtime error, bad variable name} {
219
    list [catch {incr [set]} msg] $msg $errorInfo
220
} {1 {wrong # args: should be "set varName ?newValue?"} {wrong # args: should be "set varName ?newValue?"
221
    while compiling
222
"set"
223
    while compiling
224
"incr [set]"}}
225
test incr-1.28 {TclCompileIncrCmd: runtime error, readonly variable} {
226
    proc readonly args {error "variable is read-only"}
227
    set x 123
228
    trace var x w readonly
229
    list [catch {incr x 1} msg] $msg $errorInfo
230
} {1 {can't set "x": variable is read-only} {can't set "x": variable is read-only
231
    while executing
232
"incr x 1"}}
233
catch {unset x}
234
test incr-1.29 {TclCompileIncrCmd: runtime error, bad variable value} {
235
    set x "  -  "
236
    list [catch {incr x 1} msg] $msg
237
} {1 {expected integer but got "  -  "}}
238
 
239
# Check "incr" and computed command names.
240
 
241
test incr-2.1 {incr and computed command names} {
242
    set i 5
243
    set z incr
244
    $z i -1
245
    set i
246
} 4

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.