sl@0
|
1 |
# This file contains a collection of tests for the procedures in the
|
sl@0
|
2 |
# file tclCompExpr.c. Sourcing this file into Tcl runs the tests and
|
sl@0
|
3 |
# generates output for errors. No output means no errors were found.
|
sl@0
|
4 |
#
|
sl@0
|
5 |
# Copyright (c) 1997 Sun Microsystems, Inc.
|
sl@0
|
6 |
# Copyright (c) 1998-1999 by Scriptics Corporation.
|
sl@0
|
7 |
#
|
sl@0
|
8 |
# See the file "license.terms" for information on usage and redistribution
|
sl@0
|
9 |
# of this file, and for a DISCLAIMER OF ALL WARRANTIES.
|
sl@0
|
10 |
#
|
sl@0
|
11 |
# RCS: @(#) $Id: compExpr.test,v 1.6 2001/12/06 10:59:17 dkf Exp $
|
sl@0
|
12 |
|
sl@0
|
13 |
if {[lsearch [namespace children] ::tcltest] == -1} {
|
sl@0
|
14 |
package require tcltest
|
sl@0
|
15 |
namespace import -force ::tcltest::*
|
sl@0
|
16 |
}
|
sl@0
|
17 |
|
sl@0
|
18 |
if {([catch {expr T1()} msg] == 1) && ($msg == {unknown math function "T1"})} {
|
sl@0
|
19 |
set gotT1 0
|
sl@0
|
20 |
puts "This application hasn't been compiled with the \"T1\" and"
|
sl@0
|
21 |
puts "\"T2\" math functions, so I'll skip some of the expr tests."
|
sl@0
|
22 |
} else {
|
sl@0
|
23 |
set gotT1 1
|
sl@0
|
24 |
}
|
sl@0
|
25 |
|
sl@0
|
26 |
catch {unset a}
|
sl@0
|
27 |
|
sl@0
|
28 |
test compExpr-1.1 {TclCompileExpr procedure, successful expr parse and compile} {
|
sl@0
|
29 |
expr 1+2
|
sl@0
|
30 |
} 3
|
sl@0
|
31 |
test compExpr-1.2 {TclCompileExpr procedure, error parsing expr} {
|
sl@0
|
32 |
list [catch {expr 1+2+} msg] $msg
|
sl@0
|
33 |
} {1 {syntax error in expression "1+2+": premature end of expression}}
|
sl@0
|
34 |
test compExpr-1.3 {TclCompileExpr procedure, error compiling expr} {
|
sl@0
|
35 |
list [catch {expr "foo(123)"} msg] $msg
|
sl@0
|
36 |
} {1 {unknown math function "foo"}}
|
sl@0
|
37 |
test compExpr-1.4 {TclCompileExpr procedure, expr has no operators} {
|
sl@0
|
38 |
set a {000123}
|
sl@0
|
39 |
expr {$a}
|
sl@0
|
40 |
} 83
|
sl@0
|
41 |
|
sl@0
|
42 |
test compExpr-2.1 {CompileSubExpr procedure, TCL_TOKEN_WORD parse token} {
|
sl@0
|
43 |
catch {unset a}
|
sl@0
|
44 |
set a 27
|
sl@0
|
45 |
expr {"foo$a" < "bar"}
|
sl@0
|
46 |
} 0
|
sl@0
|
47 |
test compExpr-2.2 {CompileSubExpr procedure, error compiling TCL_TOKEN_WORD parse token} {
|
sl@0
|
48 |
list [catch {expr {"00[expr 1+]" + 17}} msg] $msg
|
sl@0
|
49 |
} {1 {syntax error in expression "1+": premature end of expression}}
|
sl@0
|
50 |
test compExpr-2.3 {CompileSubExpr procedure, TCL_TOKEN_TEXT parse token} {
|
sl@0
|
51 |
expr {{12345}}
|
sl@0
|
52 |
} 12345
|
sl@0
|
53 |
test compExpr-2.4 {CompileSubExpr procedure, empty TCL_TOKEN_TEXT parse token} {
|
sl@0
|
54 |
expr {{}}
|
sl@0
|
55 |
} {}
|
sl@0
|
56 |
test compExpr-2.5 {CompileSubExpr procedure, TCL_TOKEN_BS parse token} {
|
sl@0
|
57 |
expr "\{ \\
|
sl@0
|
58 |
+123 \}"
|
sl@0
|
59 |
} 123
|
sl@0
|
60 |
test compExpr-2.6 {CompileSubExpr procedure, TCL_TOKEN_COMMAND parse token} {
|
sl@0
|
61 |
expr {[info tclversion] != ""}
|
sl@0
|
62 |
} 1
|
sl@0
|
63 |
test compExpr-2.7 {CompileSubExpr procedure, TCL_TOKEN_COMMAND parse token} {
|
sl@0
|
64 |
expr {[]}
|
sl@0
|
65 |
} {}
|
sl@0
|
66 |
test compExpr-2.8 {CompileSubExpr procedure, error in TCL_TOKEN_COMMAND parse token} {
|
sl@0
|
67 |
list [catch {expr {[foo "bar"xxx] + 17}} msg] $msg
|
sl@0
|
68 |
} {1 {extra characters after close-quote}}
|
sl@0
|
69 |
test compExpr-2.9 {CompileSubExpr procedure, TCL_TOKEN_VARIABLE parse token} {
|
sl@0
|
70 |
catch {unset a}
|
sl@0
|
71 |
set a 123
|
sl@0
|
72 |
expr {$a*2}
|
sl@0
|
73 |
} 246
|
sl@0
|
74 |
test compExpr-2.10 {CompileSubExpr procedure, TCL_TOKEN_VARIABLE parse token} {
|
sl@0
|
75 |
catch {unset a}
|
sl@0
|
76 |
catch {unset b}
|
sl@0
|
77 |
set a(george) martha
|
sl@0
|
78 |
set b geo
|
sl@0
|
79 |
expr {$a(${b}rge)}
|
sl@0
|
80 |
} martha
|
sl@0
|
81 |
test compExpr-2.11 {CompileSubExpr procedure, error in TCL_TOKEN_VARIABLE parse token} {
|
sl@0
|
82 |
catch {unset a}
|
sl@0
|
83 |
list [catch {expr {$a + 17}} msg] $msg
|
sl@0
|
84 |
} {1 {can't read "a": no such variable}}
|
sl@0
|
85 |
test compExpr-2.12 {CompileSubExpr procedure, TCL_TOKEN_SUB_EXPR parse token} {
|
sl@0
|
86 |
expr {27||3? 3<<(1+4) : 4&&9}
|
sl@0
|
87 |
} 96
|
sl@0
|
88 |
test compExpr-2.13 {CompileSubExpr procedure, error in TCL_TOKEN_SUB_EXPR parse token} {
|
sl@0
|
89 |
catch {unset a}
|
sl@0
|
90 |
set a 15
|
sl@0
|
91 |
list [catch {expr {27 || "$a[expr 1+]00"}} msg] $msg
|
sl@0
|
92 |
} {1 {syntax error in expression "1+": premature end of expression}}
|
sl@0
|
93 |
test compExpr-2.14 {CompileSubExpr procedure, TCL_TOKEN_OPERATOR token, op found} {
|
sl@0
|
94 |
expr {5*6}
|
sl@0
|
95 |
} 30
|
sl@0
|
96 |
test compExpr-2.15 {CompileSubExpr procedure, TCL_TOKEN_OPERATOR token, math function found} {
|
sl@0
|
97 |
format %.6g [expr {sin(2.0)}]
|
sl@0
|
98 |
} 0.909297
|
sl@0
|
99 |
test compExpr-2.16 {CompileSubExpr procedure, TCL_TOKEN_OPERATOR token, math function not found} {
|
sl@0
|
100 |
list [catch {expr {fred(2.0)}} msg] $msg
|
sl@0
|
101 |
} {1 {unknown math function "fred"}}
|
sl@0
|
102 |
test compExpr-2.17 {CompileSubExpr procedure, TCL_TOKEN_OPERATOR token, normal operator} {
|
sl@0
|
103 |
expr {4*2}
|
sl@0
|
104 |
} 8
|
sl@0
|
105 |
test compExpr-2.18 {CompileSubExpr procedure, TCL_TOKEN_OPERATOR token, normal operator} {
|
sl@0
|
106 |
expr {4/2}
|
sl@0
|
107 |
} 2
|
sl@0
|
108 |
test compExpr-2.19 {CompileSubExpr procedure, TCL_TOKEN_OPERATOR token, normal operator} {
|
sl@0
|
109 |
expr {4%2}
|
sl@0
|
110 |
} 0
|
sl@0
|
111 |
test compExpr-2.20 {CompileSubExpr procedure, TCL_TOKEN_OPERATOR token, normal operator} {
|
sl@0
|
112 |
expr {4<<2}
|
sl@0
|
113 |
} 16
|
sl@0
|
114 |
test compExpr-2.21 {CompileSubExpr procedure, TCL_TOKEN_OPERATOR token, normal operator} {
|
sl@0
|
115 |
expr {4>>2}
|
sl@0
|
116 |
} 1
|
sl@0
|
117 |
test compExpr-2.22 {CompileSubExpr procedure, TCL_TOKEN_OPERATOR token, normal operator} {
|
sl@0
|
118 |
expr {4<2}
|
sl@0
|
119 |
} 0
|
sl@0
|
120 |
test compExpr-2.23 {CompileSubExpr procedure, TCL_TOKEN_OPERATOR token, normal operator} {
|
sl@0
|
121 |
expr {4>2}
|
sl@0
|
122 |
} 1
|
sl@0
|
123 |
test compExpr-2.24 {CompileSubExpr procedure, TCL_TOKEN_OPERATOR token, normal operator} {
|
sl@0
|
124 |
expr {4<=2}
|
sl@0
|
125 |
} 0
|
sl@0
|
126 |
test compExpr-2.25 {CompileSubExpr procedure, TCL_TOKEN_OPERATOR token, normal operator} {
|
sl@0
|
127 |
expr {4>=2}
|
sl@0
|
128 |
} 1
|
sl@0
|
129 |
test compExpr-2.26 {CompileSubExpr procedure, TCL_TOKEN_OPERATOR token, normal operator} {
|
sl@0
|
130 |
expr {4==2}
|
sl@0
|
131 |
} 0
|
sl@0
|
132 |
test compExpr-2.27 {CompileSubExpr procedure, TCL_TOKEN_OPERATOR token, normal operator} {
|
sl@0
|
133 |
expr {4!=2}
|
sl@0
|
134 |
} 1
|
sl@0
|
135 |
test compExpr-2.28 {CompileSubExpr procedure, TCL_TOKEN_OPERATOR token, normal operator} {
|
sl@0
|
136 |
expr {4&2}
|
sl@0
|
137 |
} 0
|
sl@0
|
138 |
test compExpr-2.29 {CompileSubExpr procedure, TCL_TOKEN_OPERATOR token, normal operator} {
|
sl@0
|
139 |
expr {4^2}
|
sl@0
|
140 |
} 6
|
sl@0
|
141 |
test compExpr-2.30 {CompileSubExpr procedure, TCL_TOKEN_OPERATOR token, normal operator} {
|
sl@0
|
142 |
expr {4|2}
|
sl@0
|
143 |
} 6
|
sl@0
|
144 |
test compExpr-2.31 {CompileSubExpr procedure, TCL_TOKEN_OPERATOR token, normal operator, 1 operand} {
|
sl@0
|
145 |
expr {!4}
|
sl@0
|
146 |
} 0
|
sl@0
|
147 |
test compExpr-2.32 {CompileSubExpr procedure, TCL_TOKEN_OPERATOR token, normal operator, 1 operand} {
|
sl@0
|
148 |
expr {~4}
|
sl@0
|
149 |
} -5
|
sl@0
|
150 |
test compExpr-2.33 {CompileSubExpr procedure, TCL_TOKEN_OPERATOR token, normal operator, comparison} {
|
sl@0
|
151 |
catch {unset a}
|
sl@0
|
152 |
set a 15
|
sl@0
|
153 |
expr {$a==15} ;# compiled out-of-line to runtime call on Tcl_ExprObjCmd
|
sl@0
|
154 |
} 1
|
sl@0
|
155 |
test compExpr-2.34 {CompileSubExpr procedure, TCL_TOKEN_OPERATOR token, special operator} {
|
sl@0
|
156 |
expr {+2}
|
sl@0
|
157 |
} 2
|
sl@0
|
158 |
test compExpr-2.35 {CompileSubExpr procedure, TCL_TOKEN_OPERATOR token, error in special operator} {
|
sl@0
|
159 |
list [catch {expr {+[expr 1+]}} msg] $msg
|
sl@0
|
160 |
} {1 {syntax error in expression "1+": premature end of expression}}
|
sl@0
|
161 |
test compExpr-2.36 {CompileSubExpr procedure, TCL_TOKEN_OPERATOR token, special operator} {
|
sl@0
|
162 |
expr {4+2}
|
sl@0
|
163 |
} 6
|
sl@0
|
164 |
test compExpr-2.37 {CompileSubExpr procedure, TCL_TOKEN_OPERATOR token, error in special operator} {
|
sl@0
|
165 |
list [catch {expr {[expr 1+]+5}} msg] $msg
|
sl@0
|
166 |
} {1 {syntax error in expression "1+": premature end of expression}}
|
sl@0
|
167 |
test compExpr-2.38 {CompileSubExpr procedure, TCL_TOKEN_OPERATOR token, error in special operator} {
|
sl@0
|
168 |
list [catch {expr {5+[expr 1+]}} msg] $msg
|
sl@0
|
169 |
} {1 {syntax error in expression "1+": premature end of expression}}
|
sl@0
|
170 |
test compExpr-2.39 {CompileSubExpr procedure, TCL_TOKEN_OPERATOR token, special operator} {
|
sl@0
|
171 |
expr {-2}
|
sl@0
|
172 |
} -2
|
sl@0
|
173 |
test compExpr-2.40 {CompileSubExpr procedure, TCL_TOKEN_OPERATOR token, special operator} {
|
sl@0
|
174 |
expr {4-2}
|
sl@0
|
175 |
} 2
|
sl@0
|
176 |
test compExpr-2.41 {CompileSubExpr procedure, TCL_TOKEN_OPERATOR token, special operator} {
|
sl@0
|
177 |
catch {unset a}
|
sl@0
|
178 |
set a true
|
sl@0
|
179 |
expr {0||$a}
|
sl@0
|
180 |
} 1
|
sl@0
|
181 |
test compExpr-2.42 {CompileSubExpr procedure, error in TCL_TOKEN_SUB_EXPR parse token} {
|
sl@0
|
182 |
catch {unset a}
|
sl@0
|
183 |
set a 15
|
sl@0
|
184 |
list [catch {expr {27 || "$a[expr 1+]00"}} msg] $msg
|
sl@0
|
185 |
} {1 {syntax error in expression "1+": premature end of expression}}
|
sl@0
|
186 |
test compExpr-2.43 {CompileSubExpr procedure, TCL_TOKEN_OPERATOR token, special operator} {
|
sl@0
|
187 |
catch {unset a}
|
sl@0
|
188 |
set a false
|
sl@0
|
189 |
expr {3&&$a}
|
sl@0
|
190 |
} 0
|
sl@0
|
191 |
test compExpr-2.44 {CompileSubExpr procedure, TCL_TOKEN_OPERATOR token, special operator} {
|
sl@0
|
192 |
catch {unset a}
|
sl@0
|
193 |
set a false
|
sl@0
|
194 |
expr {$a||1? 1 : 0}
|
sl@0
|
195 |
} 1
|
sl@0
|
196 |
test compExpr-2.45 {CompileSubExpr procedure, error in TCL_TOKEN_SUB_EXPR parse token} {
|
sl@0
|
197 |
catch {unset a}
|
sl@0
|
198 |
set a 15
|
sl@0
|
199 |
list [catch {expr {1? 54 : "$a[expr 1+]00"}} msg] $msg
|
sl@0
|
200 |
} {1 {syntax error in expression "1+": premature end of expression}}
|
sl@0
|
201 |
|
sl@0
|
202 |
test compExpr-3.1 {CompileLandOrLorExpr procedure, numeric 1st operand} {
|
sl@0
|
203 |
catch {unset a}
|
sl@0
|
204 |
set a 2
|
sl@0
|
205 |
expr {[set a]||0}
|
sl@0
|
206 |
} 1
|
sl@0
|
207 |
test compExpr-3.2 {CompileLandOrLorExpr procedure, nonnumeric 1st operand} {
|
sl@0
|
208 |
catch {unset a}
|
sl@0
|
209 |
set a no
|
sl@0
|
210 |
expr {$a&&1}
|
sl@0
|
211 |
} 0
|
sl@0
|
212 |
test compExpr-3.3 {CompileSubExpr procedure, error in 1st operand} {
|
sl@0
|
213 |
list [catch {expr {[expr *2]||0}} msg] $msg
|
sl@0
|
214 |
} {1 {syntax error in expression "*2": unexpected operator *}}
|
sl@0
|
215 |
test compExpr-3.4 {CompileLandOrLorExpr procedure, result is 1 or 0} {
|
sl@0
|
216 |
catch {unset a}
|
sl@0
|
217 |
catch {unset b}
|
sl@0
|
218 |
set a no
|
sl@0
|
219 |
set b true
|
sl@0
|
220 |
expr {$a || $b}
|
sl@0
|
221 |
} 1
|
sl@0
|
222 |
test compExpr-3.5 {CompileLandOrLorExpr procedure, short-circuit semantics} {
|
sl@0
|
223 |
catch {unset a}
|
sl@0
|
224 |
set a yes
|
sl@0
|
225 |
expr {$a || [exit]}
|
sl@0
|
226 |
} 1
|
sl@0
|
227 |
test compExpr-3.6 {CompileLandOrLorExpr procedure, short-circuit semantics} {
|
sl@0
|
228 |
catch {unset a}
|
sl@0
|
229 |
set a no
|
sl@0
|
230 |
expr {$a && [exit]}
|
sl@0
|
231 |
} 0
|
sl@0
|
232 |
test compExpr-3.7 {CompileLandOrLorExpr procedure, numeric 2nd operand} {
|
sl@0
|
233 |
catch {unset a}
|
sl@0
|
234 |
set a 2
|
sl@0
|
235 |
expr {0||[set a]}
|
sl@0
|
236 |
} 1
|
sl@0
|
237 |
test compExpr-3.8 {CompileLandOrLorExpr procedure, nonnumeric 2nd operand} {
|
sl@0
|
238 |
catch {unset a}
|
sl@0
|
239 |
set a no
|
sl@0
|
240 |
expr {1&&$a}
|
sl@0
|
241 |
} 0
|
sl@0
|
242 |
test compExpr-3.9 {CompileLandOrLorExpr procedure, error in 2nd operand} {
|
sl@0
|
243 |
list [catch {expr {0||[expr %2]}} msg] $msg
|
sl@0
|
244 |
} {1 {syntax error in expression "%2": unexpected operator %}}
|
sl@0
|
245 |
test compExpr-3.10 {CompileLandOrLorExpr procedure, long lor/land arm} {
|
sl@0
|
246 |
set a "abcdefghijkl"
|
sl@0
|
247 |
set i 7
|
sl@0
|
248 |
expr {[string compare [format %c $i] [string index $a $i]]&&[string compare [format %c $i] [string index $a $i]]&&[string compare [format %c $i] [string index $a $i]]&&[string compare [format %c $i] [string index $a $i]]&&[string compare [format %c $i] [string index $a $i]]&&[string compare [format %c $i] [string index $a $i]]&&[string compare [format %c $i] [string index $a $i]]&&[string compare [format %c $i] [string index $a $i]]&&[string compare [format %c $i] [string index $a $i]]&&[string compare [format %c $i] [string index $a $i]]&&[string compare [format %c $i] [string index $a $i]]&&[string compare [format %c $i] [string index $a $i]]&&[string compare [format %c $i] [string index $a $i]]&&[string compare [format %c $i] [string index $a $i]]&&[string compare [format %c $i] [string index $a $i]]&&[string compare [format %c $i] [string index $a $i]]&&[string compare [format %c $i] [string index $a $i]]&&[string compare [format %c $i] [string index $a $i]] || [string compare [format %c $i] [string index $a $i]]&&[string compare [format %c $i] [string index $a $i]]&&[string compare [format %c $i] [string index $a $i]]&&[string compare [format %c $i] [string index $a $i]]&&[string compare [format %c $i] [string index $a $i]]&&[string compare [format %c $i] [string index $a $i]]&&[string compare [format %c $i] [string index $a $i]]&&[string compare [format %c $i] [string index $a $i]]&&[string compare [format %c $i] [string index $a $i]]&&[string compare [format %c $i] [string index $a $i]]&&[string compare [format %c $i] [string index $a $i]]&&[string compare [format %c $i] [string index $a $i]]&&[string compare [format %c $i] [string index $a $i]]&&[string compare [format %c $i] [string index $a $i]]&&[string compare [format %c $i] [string index $a $i]]&&[string compare [format %c $i] [string index $a $i]]&&[string compare [format %c $i] [string index $a $i]]&&[string compare [format %c $i] [string index $a $i]] || [string compare [format %c $i] [string index $a $i]]&&[string compare [format %c $i] [string index $a $i]]&&[string compare [format %c $i] [string index $a $i]]&&[string compare [format %c $i] [string index $a $i]]&&[string compare [format %c $i] [string index $a $i]]&&[string compare [format %c $i] [string index $a $i]]&&[string compare [format %c $i] [string index $a $i]]&&[string compare [format %c $i] [string index $a $i]]&&[string compare [format %c $i] [string index $a $i]]&&[string compare [format %c $i] [string index $a $i]]&&[string compare [format %c $i] [string index $a $i]]&&[string compare [format %c $i] [string index $a $i]]&&[string compare [format %c $i] [string index $a $i]]&&[string compare [format %c $i] [string index $a $i]]&&[string compare [format %c $i] [string index $a $i]]&&[string compare [format %c $i] [string index $a $i]]&&[string compare [format %c $i] [string index $a $i]]&&[string compare [format %c $i] [string index $a $i]] || [string compare [format %c $i] [string index $a $i]]&&[string compare [format %c $i] [string index $a $i]]&&[string compare [format %c $i] [string index $a $i]]&&[string compare [format %c $i] [string index $a $i]]&&[string compare [format %c $i] [string index $a $i]]&&[string compare [format %c $i] [string index $a $i]]&&[string compare [format %c $i] [string index $a $i]]&&[string compare [format %c $i] [string index $a $i]]&&[string compare [format %c $i] [string index $a $i]]&&[string compare [format %c $i] [string index $a $i]]&&[string compare [format %c $i] [string index $a $i]]&&[string compare [format %c $i] [string index $a $i]]&&[string compare [format %c $i] [string index $a $i]]&&[string compare [format %c $i] [string index $a $i]]&&[string compare [format %c $i] [string index $a $i]]&&[string compare [format %c $i] [string index $a $i]]&&[string compare [format %c $i] [string index $a $i]]&&[string compare [format %c $i] [string index $a $i]]}
|
sl@0
|
249 |
} 1
|
sl@0
|
250 |
|
sl@0
|
251 |
test compExpr-4.1 {CompileCondExpr procedure, simple test} {
|
sl@0
|
252 |
catch {unset a}
|
sl@0
|
253 |
set a 2
|
sl@0
|
254 |
expr {($a > 1)? "ok" : "nope"}
|
sl@0
|
255 |
} ok
|
sl@0
|
256 |
test compExpr-4.2 {CompileCondExpr procedure, complex test, convert to numeric} {
|
sl@0
|
257 |
catch {unset a}
|
sl@0
|
258 |
set a no
|
sl@0
|
259 |
expr {[set a]? 27 : -54}
|
sl@0
|
260 |
} -54
|
sl@0
|
261 |
test compExpr-4.3 {CompileCondExpr procedure, error in test} {
|
sl@0
|
262 |
list [catch {expr {[expr *2]? +1 : -1}} msg] $msg
|
sl@0
|
263 |
} {1 {syntax error in expression "*2": unexpected operator *}}
|
sl@0
|
264 |
test compExpr-4.4 {CompileCondExpr procedure, simple "true" clause} {
|
sl@0
|
265 |
catch {unset a}
|
sl@0
|
266 |
set a no
|
sl@0
|
267 |
expr {1? (27-2) : -54}
|
sl@0
|
268 |
} 25
|
sl@0
|
269 |
test compExpr-4.5 {CompileCondExpr procedure, convert "true" clause to numeric} {
|
sl@0
|
270 |
catch {unset a}
|
sl@0
|
271 |
set a no
|
sl@0
|
272 |
expr {1? $a : -54}
|
sl@0
|
273 |
} no
|
sl@0
|
274 |
test compExpr-4.6 {CompileCondExpr procedure, error in "true" clause} {
|
sl@0
|
275 |
list [catch {expr {1? [expr *2] : -127}} msg] $msg
|
sl@0
|
276 |
} {1 {syntax error in expression "*2": unexpected operator *}}
|
sl@0
|
277 |
test compExpr-4.7 {CompileCondExpr procedure, simple "false" clause} {
|
sl@0
|
278 |
catch {unset a}
|
sl@0
|
279 |
set a no
|
sl@0
|
280 |
expr {(2-2)? -3.14159 : "nope"}
|
sl@0
|
281 |
} nope
|
sl@0
|
282 |
test compExpr-4.8 {CompileCondExpr procedure, convert "false" clause to numeric} {
|
sl@0
|
283 |
catch {unset a}
|
sl@0
|
284 |
set a 00123
|
sl@0
|
285 |
expr {0? 42 : $a}
|
sl@0
|
286 |
} 83
|
sl@0
|
287 |
test compExpr-4.9 {CompileCondExpr procedure, error in "false" clause} {
|
sl@0
|
288 |
list [catch {expr {1? 15 : [expr *2]}} msg] $msg
|
sl@0
|
289 |
} {1 {syntax error in expression "*2": unexpected operator *}}
|
sl@0
|
290 |
|
sl@0
|
291 |
test compExpr-5.1 {CompileMathFuncCall procedure, math function found} {
|
sl@0
|
292 |
format %.6g [expr atan2(1.0, 2.0)]
|
sl@0
|
293 |
} 0.463648
|
sl@0
|
294 |
test compExpr-5.2 {CompileMathFuncCall procedure, math function not found} {
|
sl@0
|
295 |
list [catch {expr {do_it()}} msg] $msg
|
sl@0
|
296 |
} {1 {unknown math function "do_it"}}
|
sl@0
|
297 |
if $gotT1 {
|
sl@0
|
298 |
test compExpr-5.3 {CompileMathFuncCall: call registered math function} {
|
sl@0
|
299 |
expr 3*T1()-1
|
sl@0
|
300 |
} 368
|
sl@0
|
301 |
test compExpr-5.4 {CompileMathFuncCall: call registered math function} {
|
sl@0
|
302 |
expr T2()*3
|
sl@0
|
303 |
} 1035
|
sl@0
|
304 |
}
|
sl@0
|
305 |
test compExpr-5.5 {CompileMathFuncCall procedure, too few arguments} {
|
sl@0
|
306 |
list [catch {expr {atan2(1.0)}} msg] $msg
|
sl@0
|
307 |
} {1 {too few arguments for math function}}
|
sl@0
|
308 |
test compExpr-5.6 {CompileMathFuncCall procedure, complex argument} {
|
sl@0
|
309 |
format %.6g [expr pow(2.1, 27.5-(24.4*(5%2)))]
|
sl@0
|
310 |
} 9.97424
|
sl@0
|
311 |
test compExpr-5.7 {CompileMathFuncCall procedure, error in argument} {
|
sl@0
|
312 |
list [catch {expr {sinh(2.*)}} msg] $msg
|
sl@0
|
313 |
} {1 {syntax error in expression "sinh(2.*)": unexpected close parenthesis}}
|
sl@0
|
314 |
test compExpr-5.8 {CompileMathFuncCall procedure, too many arguments} {
|
sl@0
|
315 |
list [catch {expr {sinh(2.0, 3.0)}} msg] $msg
|
sl@0
|
316 |
} {1 {too many arguments for math function}}
|
sl@0
|
317 |
test compExpr-5.9 {CompileMathFuncCall procedure, too many arguments} {
|
sl@0
|
318 |
list [catch {expr {0 <= rand(5.2)}} msg] $msg
|
sl@0
|
319 |
} {1 {too many arguments for math function}}
|
sl@0
|
320 |
|
sl@0
|
321 |
test compExpr-6.1 {LogSyntaxError procedure, error in expr longer than 60 chars} {
|
sl@0
|
322 |
list [catch {expr {(+0123456)*(+0123456)*(+0123456)*(+0123456)*(+0123456)*(+0123456)*(+0123456)/} -1 foo 3} msg] $msg
|
sl@0
|
323 |
} {1 {syntax error in expression "(+0123456)*(+0123456)*(+0123456)*(+0123456)*(+0123456)*(+012...": extra tokens at end of expression}}
|
sl@0
|
324 |
|
sl@0
|
325 |
# cleanup
|
sl@0
|
326 |
catch {unset a}
|
sl@0
|
327 |
catch {unset b}
|
sl@0
|
328 |
::tcltest::cleanupTests
|
sl@0
|
329 |
return
|