1 # Commands covered: expr
3 # This file contains the original set of tests for Tcl's expr command.
4 # Since the expr command is now compiled, a new set of tests covering
5 # the new implementation are in the files "parseExpr.test and
6 # "compExpr.test". Sourcing this file into Tcl runs the tests and generates
7 # output for errors. No output means no errors were found.
9 # Copyright (c) 1991-1994 The Regents of the University of California.
10 # Copyright (c) 1994-1997 Sun Microsystems, Inc.
11 # Copyright (c) 1998-1999 by Scriptics Corporation.
13 # See the file "license.terms" for information on usage and redistribution
14 # of this file, and for a DISCLAIMER OF ALL WARRANTIES.
16 # RCS: @(#) $Id: expr-old.test,v 1.8.2.1 2002/04/18 13:10:27 msofer Exp $
18 source [file dirname [info script]]/testing.tcl
20 # Jim Tcl may have no math functions, and may not have specific math functions
21 foreach {expr constraint} {sin(0) mathfunc fmod(0,1) expr_fmod hypot(0,1) expr_hypot} {
22 if {[catch {expr $expr} msg]} {
23 testConstraint $constraint 0
25 testConstraint $constraint 1
29 # First, test all of the integer operators individually.
31 test expr-old-1.1 {integer operators} {expr -4} -4
32 test expr-old-1.2 {integer operators} {expr -(1+4)} -5
33 test expr-old-1.3 {integer operators} {expr ~3} -4
34 test expr-old-1.4 {integer operators} {expr !2} 0
35 test expr-old-1.5 {integer operators} {expr !0} 1
36 test expr-old-1.6 {integer operators} {expr 4*6} 24
37 test expr-old-1.7 {integer operators} {expr 36/12} 3
38 test expr-old-1.8 {integer operators} {expr 27/4} 6
39 test expr-old-1.9 {integer operators} {expr 27%4} 3
40 test expr-old-1.10 {integer operators} {expr 2+2} 4
41 test expr-old-1.11 {integer operators} {expr 2-6} -4
42 test expr-old-1.12 {integer operators} {expr 1<<3} 8
43 test expr-old-1.13 {integer operators} {expr 0xff>>2} 63
44 test expr-old-1.14 {integer operators} {expr -1>>2} -1
45 test expr-old-1.15 {integer operators} {expr 3>2} 1
46 test expr-old-1.16 {integer operators} {expr 2>2} 0
47 test expr-old-1.17 {integer operators} {expr 1>2} 0
48 test expr-old-1.18 {integer operators} {expr 3<2} 0
49 test expr-old-1.19 {integer operators} {expr 2<2} 0
50 test expr-old-1.20 {integer operators} {expr 1<2} 1
51 test expr-old-1.21 {integer operators} {expr 3>=2} 1
52 test expr-old-1.22 {integer operators} {expr 2>=2} 1
53 test expr-old-1.23 {integer operators} {expr 1>=2} 0
54 test expr-old-1.24 {integer operators} {expr 3<=2} 0
55 test expr-old-1.25 {integer operators} {expr 2<=2} 1
56 test expr-old-1.26 {integer operators} {expr 1<=2} 1
57 test expr-old-1.27 {integer operators} {expr 3==2} 0
58 test expr-old-1.28 {integer operators} {expr 2==2} 1
59 test expr-old-1.29 {integer operators} {expr 3!=2} 1
60 test expr-old-1.30 {integer operators} {expr 2!=2} 0
61 test expr-old-1.31 {integer operators} {expr 7&0x13} 3
62 test expr-old-1.32 {integer operators} {expr 7^0x13} 20
63 test expr-old-1.33 {integer operators} {expr 7|0x13} 23
64 test expr-old-1.34 {integer operators} {expr 0&&1} 0
65 test expr-old-1.35 {integer operators} {expr 0&&0} 0
66 test expr-old-1.36 {integer operators} {expr 1&&3} 1
67 test expr-old-1.37 {integer operators} {expr 0||1} 1
68 test expr-old-1.38 {integer operators} {expr 3||0} 1
69 test expr-old-1.39 {integer operators} {expr 0||0} 0
70 test expr-old-1.40 {integer operators} {expr 3>2?44:66} 44
71 test expr-old-1.41 {integer operators} {expr 2>3?44:66} 66
72 test expr-old-1.42 {integer operators} {expr 36/5} 7
73 test expr-old-1.43 {integer operators} {expr 36%5} 1
74 test expr-old-1.44 {integer operators} {expr -36/5} -8
75 test expr-old-1.45 {integer operators} {expr -36%5} 4
76 test expr-old-1.46 {integer operators} {expr 36/-5} -8
77 test expr-old-1.47 {integer operators} {expr 36%-5} -4
78 test expr-old-1.48 {integer operators} {expr -36/-5} 7
79 test expr-old-1.49 {integer operators} {expr -36%-5} -1
80 test expr-old-1.50 {integer operators} {expr +36} 36
81 test expr-old-1.51 {integer operators} {expr +--++36} 36
82 test expr-old-1.52 {integer operators} {expr +36%+5} 1
83 test expr-old-1.53 {integer operators} {
86 list [expr {1 && $x}] [expr {$x && 1}] \
87 [expr {0 || $x}] [expr {$x || 0}]
90 # Check the floating-point operators individually, along with
91 # automatic conversion to integers where needed.
93 test expr-old-2.1 {floating-point operators} {expr -4.2} -4.2
94 test expr-old-2.2 {floating-point operators} jim {expr -(1.1+4.2)} -5.3
95 test expr-old-2.3 {floating-point operators} {expr +5.7} 5.7
96 test expr-old-2.4 {floating-point operators} {expr +--+-62.0} -62.0
97 test expr-old-2.5 {floating-point operators} {expr !2.1} 0
98 test expr-old-2.6 {floating-point operators} {expr !0.0} 1
99 test expr-old-2.7 {floating-point operators} {expr 4.2*6.3} 26.46
100 test expr-old-2.8 {floating-point operators} {expr 36.0/12.0} 3.0
101 test expr-old-2.9 {floating-point operators} {expr 27/4.0} 6.75
102 test expr-old-2.10 {floating-point operators} {expr 2.3+2.1} 4.4
103 test expr-old-2.11 {floating-point operators} {expr 2.3-6.5} -4.2
104 test expr-old-2.12 {floating-point operators} {expr 3.1>2.1} 1
105 test expr-old-2.13 {floating-point operators} {expr {2.1 > 2.1}} 0
106 test expr-old-2.14 {floating-point operators} {expr 1.23>2.34e+1} 0
107 test expr-old-2.15 {floating-point operators} {expr 3.45<2.34} 0
108 test expr-old-2.16 {floating-point operators} {expr 0.002e3<--200e-2} 0
109 test expr-old-2.17 {floating-point operators} {expr 1.1<2.1} 1
110 test expr-old-2.18 {floating-point operators} {expr 3.1>=2.2} 1
111 test expr-old-2.19 {floating-point operators} {expr 2.345>=2.345} 1
112 test expr-old-2.20 {floating-point operators} {expr 1.1>=2.2} 0
113 test expr-old-2.21 {floating-point operators} {expr 3.0<=2.0} 0
114 test expr-old-2.22 {floating-point operators} {expr 2.2<=2.2} 1
115 test expr-old-2.23 {floating-point operators} {expr 2.2<=2.2001} 1
116 test expr-old-2.24 {floating-point operators} {expr 3.2==2.2} 0
117 test expr-old-2.25 {floating-point operators} {expr 2.2==2.2} 1
118 test expr-old-2.26 {floating-point operators} {expr 3.2!=2.2} 1
119 test expr-old-2.27 {floating-point operators} {expr 2.2!=2.2} 0
120 test expr-old-2.28 {floating-point operators} {expr 0.0&&0.0} 0
121 test expr-old-2.29 {floating-point operators} {expr 0.0&&1.3} 0
122 test expr-old-2.30 {floating-point operators} {expr 1.3&&0.0} 0
123 test expr-old-2.31 {floating-point operators} {expr 1.3&&3.3} 1
124 test expr-old-2.32 {floating-point operators} {expr 0.0||0.0} 0
125 test expr-old-2.33 {floating-point operators} {expr 0.0||1.3} 1
126 test expr-old-2.34 {floating-point operators} {expr 1.3||0.0} 1
127 test expr-old-2.35 {floating-point operators} {expr 3.3||0.0} 1
128 test expr-old-2.36 {floating-point operators} {expr 3.3>2.3?44.3:66.3} 44.3
129 test expr-old-2.37 {floating-point operators} {expr 2.3>3.3?44.3:66.3} 66.3
130 test expr-old-2.38 {floating-point operators} {
131 list [catch {expr 028.1 + 09.2} msg] $msg
134 # Operators that aren't legal on floating-point numbers
136 test expr-old-3.1 {illegal floating-point operations} {
137 list [catch {expr ~4.0} msg]
139 test expr-old-3.2 {illegal floating-point operations} {
140 list [catch {expr 27%4.0} msg]
142 test expr-old-3.3 {illegal floating-point operations} {
143 list [catch {expr 27.0%4} msg]
145 test expr-old-3.4 {illegal floating-point operations} {
146 list [catch {expr 1.0<<3} msg]
148 test expr-old-3.5 {illegal floating-point operations} {
149 list [catch {expr 3<<1.0} msg]
151 test expr-old-3.6 {illegal floating-point operations} {
152 list [catch {expr 24.0>>3} msg]
154 test expr-old-3.7 {illegal floating-point operations} {
155 list [catch {expr 24>>3.0} msg]
157 test expr-old-3.8 {illegal floating-point operations} {
158 list [catch {expr 24&3.0} msg]
160 test expr-old-3.9 {illegal floating-point operations} {
161 list [catch {expr 24.0|3} msg]
163 test expr-old-3.10 {illegal floating-point operations} {
164 list [catch {expr 24.0^3} msg]
167 # Check the string operators individually.
169 test expr-old-4.1 {string operators} {expr {"abc" > "def"}} 0
170 test expr-old-4.2 {string operators} {expr {"def" > "def"}} 0
171 test expr-old-4.3 {string operators} {expr {"g" > "def"}} 1
172 test expr-old-4.4 {string operators} {expr {"abc" < "abd"}} 1
173 test expr-old-4.5 {string operators} {expr {"abd" < "abd"}} 0
174 test expr-old-4.6 {string operators} {expr {"abe" < "abd"}} 0
175 test expr-old-4.7 {string operators} {expr {"abc" >= "def"}} 0
176 test expr-old-4.8 {string operators} {expr {"def" >= "def"}} 1
177 test expr-old-4.9 {string operators} {expr {"g" >= "def"}} 1
178 test expr-old-4.10 {string operators} {expr {"abc" <= "abd"}} 1
179 test expr-old-4.11 {string operators} {expr {"abd" <= "abd"}} 1
180 test expr-old-4.12 {string operators} {expr {"abe" <= "abd"}} 0
181 test expr-old-4.13 {string operators} {expr {"abc" == "abd"}} 0
182 test expr-old-4.14 {string operators} {expr {"abd" == "abd"}} 1
183 test expr-old-4.15 {string operators} {expr {"abc" != "abd"}} 1
184 test expr-old-4.16 {string operators} {expr {"abd" != "abd"}} 0
185 test expr-old-4.17 {string operators} {expr {"0y" < "0x12"}} 0
186 test expr-old-4.18 {string operators} {expr {"." < " "}} 0
188 # The following tests are non-portable because on some systems "+"
189 # and "-" can be parsed as numbers.
191 test expr-old-4.19 {string operators} {expr {"0" == "+"}} 0
192 test expr-old-4.20 {string operators} {expr {"0" == "-"}} 0
193 test expr-old-4.21 {string operators} {expr {1?"foo":"bar"}} foo
194 test expr-old-4.22 {string operators} {expr {0?"foo":"bar"}} bar
196 # Operators that aren't legal on string operands.
198 test expr-old-5.1 {illegal string operations} {
199 list [catch {expr {-"a"}} msg]
201 test expr-old-5.2 {illegal string operations} {
202 list [catch {expr {+"a"}} msg]
204 test expr-old-5.3 {illegal string operations} {
205 list [catch {expr {~"a"}} msg]
207 test expr-old-5.4 {illegal string operations} {
208 list [catch {expr {!"a"}} msg]
210 test expr-old-5.5 {illegal string operations} {
211 list [catch {expr {"a"*"b"}} msg]
213 test expr-old-5.6 {illegal string operations} {
214 list [catch {expr {"a"/"b"}} msg]
216 test expr-old-5.7 {illegal string operations} {
217 list [catch {expr {"a"%"b"}} msg]
219 test expr-old-5.8 {illegal string operations} {
220 list [catch {expr {"a"+"b"}} msg]
222 test expr-old-5.9 {illegal string operations} {
223 list [catch {expr {"a"-"b"}} msg]
225 test expr-old-5.10 {illegal string operations} {
226 list [catch {expr {"a"<<"b"}} msg]
228 test expr-old-5.11 {illegal string operations} {
229 list [catch {expr {"a">>"b"}} msg]
231 test expr-old-5.12 {illegal string operations} {
232 list [catch {expr {"a"&"b"}} msg]
234 test expr-old-5.13 {illegal string operations} {
235 list [catch {expr {"a"^"b"}} msg]
237 test expr-old-5.14 {illegal string operations} {
238 list [catch {expr {"a"|"b"}} msg]
240 test expr-old-5.15 {illegal string operations} {
241 list [catch {expr {"a"&&"b"}} msg]
243 test expr-old-5.16 {illegal string operations} {
244 list [catch {expr {"a"||"b"}} msg]
246 test expr-old-5.17 {illegal string operations} {
247 list [catch {expr {"a"?4:2}} msg]
250 # Check precedence pairwise.
252 test expr-old-6.1 {precedence checks} {expr -~3} 4
253 test expr-old-6.2 {precedence checks} {expr -!3} 0
254 test expr-old-6.3 {precedence checks} {expr -~0} 1
256 test expr-old-7.1 {precedence checks} {expr 2*4/6} 1
257 test expr-old-7.2 {precedence checks} {expr 24/6*3} 12
258 test expr-old-7.3 {precedence checks} {expr 24/6/2} 2
260 test expr-old-8.1 {precedence checks} {expr -2+4} 2
261 test expr-old-8.2 {precedence checks} {expr -2-4} -6
262 test expr-old-8.3 {precedence checks} {expr +2-4} -2
264 test expr-old-9.1 {precedence checks} {expr 2*3+4} 10
265 test expr-old-9.2 {precedence checks} {expr 8/2+4} 8
266 test expr-old-9.3 {precedence checks} {expr 8%3+4} 6
267 test expr-old-9.4 {precedence checks} {expr 2*3-1} 5
268 test expr-old-9.5 {precedence checks} {expr 8/2-1} 3
269 test expr-old-9.6 {precedence checks} {expr 8%3-1} 1
271 test expr-old-10.1 {precedence checks} {expr 6-3-2} 1
273 test expr-old-11.1 {precedence checks} {expr 7+1>>2} 2
274 test expr-old-11.2 {precedence checks} {expr 7+1<<2} 32
275 test expr-old-11.3 {precedence checks} {expr 7>>3-2} 3
276 test expr-old-11.4 {precedence checks} {expr 7<<3-2} 14
278 test expr-old-12.1 {precedence checks} {expr 6>>1>4} 0
279 test expr-old-12.2 {precedence checks} {expr 6>>1<2} 0
280 test expr-old-12.3 {precedence checks} {expr 6>>1>=3} 1
281 test expr-old-12.4 {precedence checks} {expr 6>>1<=2} 0
282 test expr-old-12.5 {precedence checks} {expr 6<<1>5} 1
283 test expr-old-12.6 {precedence checks} {expr 6<<1<5} 0
284 test expr-old-12.7 {precedence checks} {expr 5<=6<<1} 1
285 test expr-old-12.8 {precedence checks} {expr 5>=6<<1} 0
287 test expr-old-13.1 {precedence checks} {expr 2<3<4} 1
288 test expr-old-13.2 {precedence checks} {expr 0<4>2} 0
289 test expr-old-13.3 {precedence checks} {expr 4>2<1} 0
290 test expr-old-13.4 {precedence checks} {expr 4>3>2} 0
291 test expr-old-13.5 {precedence checks} {expr 4>3>=2} 0
292 test expr-old-13.6 {precedence checks} {expr 4>=3>2} 0
293 test expr-old-13.7 {precedence checks} {expr 4>=3>=2} 0
294 test expr-old-13.8 {precedence checks} {expr 0<=4>=2} 0
295 test expr-old-13.9 {precedence checks} {expr 4>=2<=0} 0
296 test expr-old-13.10 {precedence checks} {expr 2<=3<=4} 1
298 test expr-old-14.1 {precedence checks} {expr 1==4>3} 1
299 test expr-old-14.2 {precedence checks} {expr 0!=4>3} 1
300 test expr-old-14.3 {precedence checks} {expr 1==3<4} 1
301 test expr-old-14.4 {precedence checks} {expr 0!=3<4} 1
302 test expr-old-14.5 {precedence checks} {expr 1==4>=3} 1
303 test expr-old-14.6 {precedence checks} {expr 0!=4>=3} 1
304 test expr-old-14.7 {precedence checks} {expr 1==3<=4} 1
305 test expr-old-14.8 {precedence checks} {expr 0!=3<=4} 1
307 test expr-old-15.1 {precedence checks} {expr 1==3==3} 0
308 test expr-old-15.2 {precedence checks} {expr 3==3!=2} 1
309 test expr-old-15.3 {precedence checks} {expr 2!=3==3} 0
310 test expr-old-15.4 {precedence checks} {expr 2!=1!=1} 0
312 test expr-old-16.1 {precedence checks} {expr 2&3==2} 0
313 test expr-old-16.2 {precedence checks} {expr 1&3!=3} 0
315 test expr-old-17.1 {precedence checks} {expr 7&3^0x10} 19
316 test expr-old-17.2 {precedence checks} {expr 7^0x10&3} 7
318 test expr-old-18.1 {precedence checks} {expr 7^0x10|3} 23
319 test expr-old-18.2 {precedence checks} {expr 7|0x10^3} 23
321 test expr-old-19.1 {precedence checks} {expr 7|3&&1} 1
322 test expr-old-19.2 {precedence checks} {expr 1&&3|7} 1
323 test expr-old-19.3 {precedence checks} {expr 0&&1||1} 1
324 test expr-old-19.4 {precedence checks} {expr 1||1&&0} 1
326 test expr-old-20.1 {precedence checks} {expr 1||0?3:4} 3
327 test expr-old-20.2 {precedence checks} {expr 1?0:4||1} 0
328 test expr-old-20.3 {precedence checks} {expr 1?2:0?3:4} 2
329 test expr-old-20.4 {precedence checks} {expr 0?2:0?3:4} 4
330 test expr-old-20.5 {precedence checks} {expr 1?2?3:4:0} 3
331 test expr-old-20.6 {precedence checks} {expr 0?2?3:4:0} 0
332 test expr-old-20.7 {precedence checks} {expr 0?1?1?2:3:0?4:5:1?0?6:7:0?8:9} 7
337 test expr-old-21.1 {parenthesization} {expr (2+4)*6} 36
338 test expr-old-21.2 {parenthesization} {expr (1?0:4)||1} 1
339 test expr-old-21.3 {parenthesization} {expr +(3-4)} -1
341 # Embedded commands and variable names.
344 test expr-old-22.1 {embedded variables} {expr {2*$a}} 32
345 test expr-old-22.2 {embedded variables} {
350 test expr-old-22.3 {embedded variables} {
355 test expr-old-22.4 {embedded commands and variables} {expr {[set a] - 14}} 2
356 test expr-old-22.5 {embedded commands and variables} {
357 list [catch {expr {12 - [bad_command_name]}} msg] $msg
358 } {1 {invalid command name "bad_command_name"}}
360 # Double-quotes and things inside them.
362 test expr-old-23.1 {double quotes} {expr {"abc"}} abc
363 test expr-old-23.2 {double quotes} {
367 test expr-old-23.3 {double quotes} {
369 expr {"$b2$b2$b2.[set b2].[set b2]"}
371 test expr-old-23.4 {double quotes} {expr {"11\}\}22"}} 11}}22
372 test expr-old-23.5 {double quotes} {expr {"\*bc"}} {*bc}
373 test expr-old-23.6 {double quotes} {
374 catch {unset bogus__}
375 list [catch {expr {"$bogus__"}} msg] $msg
376 } {1 {can't read "bogus__": no such variable}}
377 test expr-old-23.7 {double quotes} {
378 list [catch {expr {"a[error Testing]bc"}} msg] $msg
380 test expr-old-23.8 {double quotes} {
381 list [catch {expr {"12398712938788234-1298379" != ""}} msg] $msg
384 # Numbers in various bases.
386 test expr-old-24.1 {numbers in different bases} {expr 0x20} 32
387 test expr-old-24.2 {numbers in different bases} {expr 0o015} 13
389 # Conversions between various data types.
391 test expr-old-25.1 {type conversions} {expr 2+2.5} 4.5
392 test expr-old-25.2 {type conversions} {expr 2.5+2} 4.5
393 test expr-old-25.3 {type conversions} {expr 2-2.5} -0.5
394 test expr-old-25.4 {type conversions} {expr 2/2.5} 0.8
395 test expr-old-25.5 {type conversions} {expr 2>2.5} 0
396 test expr-old-25.6 {type conversions} {expr 2.5>2} 1
397 test expr-old-25.7 {type conversions} {expr 2<2.5} 1
398 test expr-old-25.8 {type conversions} {expr 2>=2.5} 0
399 test expr-old-25.9 {type conversions} {expr 2<=2.5} 1
400 test expr-old-25.10 {type conversions} {expr 2==2.5} 0
401 test expr-old-25.11 {type conversions} {expr 2!=2.5} 1
402 test expr-old-25.12 {type conversions} {expr 2>"ab"} 0
403 test expr-old-25.13 {type conversions} {expr {2>" "}} 1
404 test expr-old-25.14 {type conversions} {expr {"24.1a" > 24.1}} 1
405 test expr-old-25.15 {type conversions} {expr {24.1 > "24.1a"}} 0
406 test expr-old-25.16 {type conversions} {expr 2+2.5} 4.5
407 test expr-old-25.17 {type conversions} {expr 2+2.5} 4.5
408 test expr-old-25.18 {type conversions} {expr 2.0e2} 200.0
409 test expr-old-25.19 {type conversions} {expr 2.0e30} 2e+30
410 test expr-old-25.20 {type conversions} {expr 10.0} 10.0
412 # Various error conditions.
414 test expr-old-26.1 {error conditions} {
415 list [catch {expr 2+"a"} msg]
417 test expr-old-26.2 {error conditions} {
418 list [catch {expr 2+4*} msg]
420 test expr-old-26.3 {error conditions} {
421 list [catch {expr 2+4*(} msg]
423 catch {unset _non_existent_}
424 test expr-old-26.4 {error conditions} {
425 list [catch {expr 2+$_non_existent_} msg]
428 test expr-old-26.5 {error conditions} {
429 list [catch {expr {2+$a}} msg]
431 test expr-old-26.6 {error conditions} {
432 list [catch {expr {2+[set a]}} msg]
434 test expr-old-26.7 {error conditions} {
435 list [catch {expr {2+(4}} msg]
437 test expr-old-26.8 {error conditions} {
438 list [catch {expr 2/0} msg]
440 test expr-old-26.9 {error conditions} {
441 list [catch {expr 2%0} msg]
443 test expr-old-26.10 {error conditions} {
446 test expr-old-26.11 {error conditions} {
447 list [catch {expr 2#} msg]
449 test expr-old-26.12 {error conditions} {
450 list [catch {expr a.b} msg]
452 test expr-old-26.13 {error conditions} {
453 list [catch {expr {"a"/"b"}} msg]
455 test expr-old-26.14 {error conditions} {
456 list [catch {expr 2:3} msg]
458 test expr-old-26.15 {error conditions} {
459 list [catch {expr a@b} msg]
461 test expr-old-26.16 {error conditions} {
462 list [catch {expr a[b} msg]
464 test expr-old-26.17 {error conditions} {
465 list [catch {expr a`b} msg]
467 test expr-old-26.18 {error conditions} {
468 list [catch {expr \"a\"\{b} msg]
470 test expr-old-26.19 {error conditions} {
471 list [catch {expr a} msg]
473 test expr-old-26.20 {error conditions} {
474 list [catch expr msg]
477 # Cancelled evaluation.
479 test expr-old-27.1 {cancelled evaluation} {
484 test expr-old-27.2 {cancelled evaluation} {
489 test expr-old-27.3 {cancelled evaluation} {
494 test expr-old-27.4 {cancelled evaluation} {
500 test expr-old-27.5 {cancelled evaluation} {
501 list [catch {expr {[info exists x] && $x}} msg] $msg
503 test expr-old-27.6 {cancelled evaluation} {
504 list [catch {expr {0 && [concat $x]}} msg] $msg
506 test expr-old-27.7 {cancelled evaluation} {
508 list [catch {expr {1 || 1/$one}} msg] $msg
510 test expr-old-27.8 {cancelled evaluation} {
511 list [catch {expr {1 || -"string"}} msg] $msg
513 test expr-old-27.9 {cancelled evaluation} {
514 list [catch {expr {1 || ("string" * ("x" && "y"))}} msg] $msg
516 test expr-old-27.10 {cancelled evaluation} {
518 list [catch {expr {($x > 0) ? round($x) : 0}} msg] $msg
520 test expr-old-27.11 {cancelled evaluation} {
521 list [catch {expr {0 && foo}} msg]
523 test expr-old-27.12 {cancelled evaluation} {
524 list [catch {expr {0 ? 1 : foo}} msg]
527 # Operands enclosed in braces
529 #test expr-old-29.1 {braces} {expr {{abc}}} abc
530 #test expr-old-29.2 {braces} {expr {{00010}}} 8
531 #test expr-old-29.3 {braces} {expr {{3.1200000}}} 3.12
532 #test expr-old-29.4 {braces} {expr {{a{b}{1 {2 3}}c}}} "a{b}{1 {2 3}}c"
533 #test expr-old-29.5 {braces} {
534 # list [catch {expr "\{abc"} msg] $msg
535 #} {1 {missing close-brace}}
539 test expr-old-30.1 {long values} {
540 set a "0000 1111 2222 3333 4444"
541 set a "$a | $a | $a | $a | $a"
542 set a "$a || $a || $a || $a || $a"
544 } {0000 1111 2222 3333 4444 | 0000 1111 2222 3333 4444 | 0000 1111 2222 3333 4444 | 0000 1111 2222 3333 4444 | 0000 1111 2222 3333 4444 || 0000 1111 2222 3333 4444 | 0000 1111 2222 3333 4444 | 0000 1111 2222 3333 4444 | 0000 1111 2222 3333 4444 | 0000 1111 2222 3333 4444 || 0000 1111 2222 3333 4444 | 0000 1111 2222 3333 4444 | 0000 1111 2222 3333 4444 | 0000 1111 2222 3333 4444 | 0000 1111 2222 3333 4444 || 0000 1111 2222 3333 4444 | 0000 1111 2222 3333 4444 | 0000 1111 2222 3333 4444 | 0000 1111 2222 3333 4444 | 0000 1111 2222 3333 4444 || 0000 1111 2222 3333 4444 | 0000 1111 2222 3333 4444 | 0000 1111 2222 3333 4444 | 0000 1111 2222 3333 4444 | 0000 1111 2222 3333 4444}
545 test expr-old-30.2 {long values} {
546 set a "000000000000000000000000000000"
547 set a "$a$a$a$a$a$a$a$a$a$a$a$a$a$a$a$a${a}5"
551 # Expressions spanning multiple arguments
553 test expr-old-31.1 {multiple arguments to expr command} {
556 test expr-old-31.2 {multiple arguments to expr command} {
557 list [catch {expr 2 + (3 + 4} msg]
559 test expr-old-31.3 {multiple arguments to expr command} {
560 list [catch {expr 2 + 3 +} msg]
562 test expr-old-31.4 {multiple arguments to expr command} {
563 list [catch {expr 2 + 3 )} msg]
568 test expr-old-32.1 {math functions in expressions} mathfunc {
569 format %.6g [expr acos(0.5)]
571 test expr-old-32.2 {math functions in expressions} mathfunc {
572 format %.6g [expr asin(0.5)]
574 test expr-old-32.3 {math functions in expressions} mathfunc {
575 format %.6g [expr atan(1.0)]
577 test expr-old-32.4 {math functions in expressions} mathfunc {
578 format %.6g [expr atan2(2.0, 2.0)]
580 test expr-old-32.5 {math functions in expressions} mathfunc {
581 format %.6g [expr ceil(1.999)]
583 test expr-old-32.6 {math functions in expressions} mathfunc {
584 format %.6g [expr cos(.1)]
586 test expr-old-32.7 {math functions in expressions} mathfunc {
587 format %.6g [expr cosh(.1)]
589 test expr-old-32.8 {math functions in expressions} mathfunc {
590 format %.6g [expr exp(1.0)]
592 test expr-old-32.9 {math functions in expressions} mathfunc {
593 format %.6g [expr floor(2.000)]
595 test expr-old-32.10 {math functions in expressions} mathfunc {
596 format %.6g [expr floor(2.001)]
598 test expr-old-32.11 {math functions in expressions} expr_fmod {
599 format %.6g [expr fmod(7.3, 3.2)]
601 test expr-old-32.12 {math functions in expressions} expr_hypot {
602 format %.6g [expr hypot(3.0, 4.0)]
604 test expr-old-32.13 {math functions in expressions} mathfunc {
605 format %.6g [expr log(2.8)]
607 test expr-old-32.14 {math functions in expressions} mathfunc {
608 format %.6g [expr log10(2.8)]
610 test expr-old-32.15 {math functions in expressions} mathfunc {
611 format %.6g [expr pow(2.1, 3.1)]
613 test expr-old-32.16 {math functions in expressions} mathfunc {
614 format %.6g [expr sin(.1)]
616 test expr-old-32.17 {math functions in expressions} mathfunc {
617 format %.6g [expr sinh(.1)]
619 test expr-old-32.18 {math functions in expressions} mathfunc {
620 format %.6g [expr sqrt(2.0)]
622 test expr-old-32.19 {math functions in expressions} mathfunc {
623 format %.6g [expr tan(0.8)]
625 test expr-old-32.20 {math functions in expressions} mathfunc {
626 format %.6g [expr tanh(0.8)]
628 test expr-old-32.21 {math functions in expressions} mathfunc {
629 format %.6g [expr abs(-1.8)]
631 test expr-old-32.22 {math functions in expressions} mathfunc {
634 test expr-old-32.23 {math functions in expressions} {
635 format %.6g [expr abs(-4)]
637 test expr-old-32.24 {math functions in expressions} {
638 format %.6g [expr abs(66)]
641 # The following test is different for 32-bit versus 64-bit architectures.
643 #test expr-old-32.25 {math functions in expressions} {
644 # list [catch {expr abs(0x8000000000000000)} msg] $msg
645 #} {1 {integer value too large to represent}}
647 test expr-old-32.26 {math functions in expressions} {
650 test expr-old-32.27 {math functions in expressions} {
653 test expr-old-32.28 {math functions in expressions} {
656 test expr-old-32.29 {math functions in expressions} {
659 test expr-old-32.30 {math functions in expressions} {
662 test expr-old-32.31 {math functions in expressions} {
665 test expr-old-32.32 {math functions in expressions} {
668 #test expr-old-32.33 {math functions in expressions} {
669 # list [catch {expr int(1e60)} msg] $msg
670 #} {1 {integer value too large to represent}}
671 #test expr-old-32.34 {math functions in expressions} {
672 # list [catch {expr int(-1e60)} msg] $msg
673 #} {1 {integer value too large to represent}}
674 test expr-old-32.35 {math functions in expressions} {
677 test expr-old-32.36 {math functions in expressions} {
680 test expr-old-32.37 {math functions in expressions} {
683 test expr-old-32.38 {math functions in expressions} {
686 #test expr-old-32.39 {math functions in expressions} {
687 # list [catch {expr round(1e60)} msg] $msg
688 #} {1 {integer value too large to represent}}
689 #test expr-old-32.40 {math functions in expressions} {
690 # list [catch {expr round(-1e60)} msg] $msg
691 #} {1 {integer value too large to represent}}
692 test expr-old-32.41 {math functions in expressions} mathfunc {
693 list [catch {expr pow(1.0 + 3.0 - 2, .8 * 5)} msg] $msg
696 test expr-old-32.42 {math functions in expressions} expr_hypot {
697 list [catch {expr hypot(5*.8,3)} msg] $msg
699 test expr-old-32.43 {math functions in expressions} mathfunc {
700 expr {pow(1.0 + 3.0, -2)}
702 test expr-old-32.45 {math functions in expressions} {
703 expr (0 <= rand()) && (rand() < 1)
705 test expr-old-32.46 {math functions in expressions} -body {
707 } -returnCodes error -match glob -result {*too many arguments for math function*}
708 test expr-old-32.47 {math functions in expressions} -body {
710 } -returnCodes error -match glob -result {*too few arguments for math function*}
711 } {1 {too few arguments for math function}}
712 test expr-old-32.48 {math functions in expressions} -body {
714 } -returnCodes error -match glob -result *
715 test expr-old-32.49 {math functions in expressions} -body {
717 } -returnCodes error -match glob -result *
718 test expr-old-32.50 {math functions in expressions} mathfunc {
719 for {set i 0} {$i < 10} {incr i} {
720 lappend result [expr round(sin($i) * 1000)]
723 } {0 841 909 141 -757 -959 -279 657 989 412}
724 test expr-old-32.51 {math functions in expressions} -body {
725 expr {srand([lindex "6ty" 0])}
726 } -returnCodes error -match glob -result *
728 test expr-old-33.1 {conversions and fancy args to math functions} expr_hypot {
731 test expr-old-33.2 {conversions and fancy args to math functions} expr_hypot {
732 expr hypot ( (2.0+1.0) , 4 )
734 test expr-old-33.3 {conversions and fancy args to math functions} expr_hypot {
735 expr hypot ( 3 , (3.0 + 1.0) )
737 test expr-old-33.4 {conversions and fancy args to math functions} mathfunc {
738 format %.6g [expr cos(acos(0.1))]
741 test expr-old-34.1 {errors in math functions} -body {
743 } -returnCodes error -match glob -result *
744 test expr-old-34.2 {errors in math functions} -body {
746 } -returnCodes error -match glob -result *
747 test expr-old-34.3 {errors in math functions} -body {
748 expr {hypot("a b", 2.0)}
749 } -returnCodes error -match glob -result *
750 test expr-old-34.4 {errors in math functions} -body {
751 expr {hypot(1.0 2.0)}
752 } -returnCodes error -match glob -result *
753 test expr-old-34.5 {errors in math functions} -body {
754 expr {hypot(1.0, 2.0}
755 } -returnCodes error -match glob -result *
756 test expr-old-34.6 {errors in math functions} -body {
758 } -returnCodes error -match glob -result *
759 test expr-old-34.7 {errors in math functions} -constraints expr_hypot -body {
761 } -returnCodes error -match glob -result {*too few arguments for math function*}
762 test expr-old-34.8 {errors in math functions} -constraints expr_hypot -body {
763 expr {hypot(1.0, 2.0, 3.0)}
764 } -returnCodes error -match glob -result {*too many arguments for math function*}
766 test expr-old-34.9 {errors in math functions} {
767 list [catch {expr acos(-2.0)} msg] $msg $errorCode
768 } {1 {domain error: argument not in valid range} {ARITH DOMAIN {domain error: argument not in valid range}}}
769 test expr-old-34.10 {errors in math functions} {
770 list [catch {expr pow(-3, 1000001)} msg] $msg $errorCode
771 } {1 {floating-point value too large to represent} {ARITH OVERFLOW {floating-point value too large to represent}}}
772 test expr-old-34.11 {errors in math functions} {
773 list [catch {expr pow(3, 1000001)} msg] $msg $errorCode
774 } {1 {floating-point value too large to represent} {ARITH OVERFLOW {floating-point value too large to represent}}}
775 test expr-old-34.12 {errors in math functions} {
776 list [catch {expr -14.0*exp(100000)} msg] $msg $errorCode
777 } {1 {floating-point value too large to represent} {ARITH OVERFLOW {floating-point value too large to represent}}}
778 test expr-old-34.13 {errors in math functions} {
779 list [catch {expr int(1.0e30)} msg] $msg $errorCode
780 } {1 {integer value too large to represent} {ARITH IOVERFLOW {integer value too large to represent}}}
781 test expr-old-34.14 {errors in math functions} {
782 list [catch {expr int(-1.0e30)} msg] $msg $errorCode
783 } {1 {integer value too large to represent} {ARITH IOVERFLOW {integer value too large to represent}}}
784 test expr-old-34.15 {errors in math functions} {
785 list [catch {expr round(1.0e30)} msg] $msg $errorCode
786 } {1 {integer value too large to represent} {ARITH IOVERFLOW {integer value too large to represent}}}
787 test expr-old-34.16 {errors in math functions} {
788 list [catch {expr round(-1.0e30)} msg] $msg $errorCode
789 } {1 {integer value too large to represent} {ARITH IOVERFLOW {integer value too large to represent}}}
792 test expr-old-36.1 {ExprLooksLikeInt procedure} -constraints tcl -body {
794 } -returnCodes error -match glob -result *
795 test expr-old-36.2 {ExprLooksLikeInt procedure} tcl {
797 list [catch {expr {$x+1}} msg] $msg
798 } {1 {can't use invalid octal number as operand of "+"}}
799 test expr-old-36.3 {ExprLooksLikeInt procedure} {
800 list [catch {expr 0289.1} msg] $msg
802 test expr-old-36.4 {ExprLooksLikeInt procedure} {
804 list [catch {expr {$x+1}} msg] $msg
806 test expr-old-36.5 {ExprLooksLikeInt procedure} {
808 list [catch {expr {$x+1}} msg] $msg
810 test expr-old-36.6 {ExprLooksLikeInt procedure} {
812 list [catch {expr {$x+1}} msg] $msg
814 test expr-old-36.7 {ExprLooksLikeInt procedure} tcl {
815 list [catch {expr nan} msg] $msg
816 } {1 {domain error: argument not in valid range}}
817 test expr-old-36.8 {ExprLooksLikeInt procedure} {
818 list [catch {expr 78e1} msg] $msg
820 test expr-old-36.9 {ExprLooksLikeInt procedure} {
821 list [catch {expr 24E1} msg] $msg
823 test expr-old-36.10 {ExprLooksLikeInt procedure} -constraints tcl -body {
825 } -returnCodes error -match glob -result *
827 # test for [Bug #542588]
828 # XXX: Can't rely on overflow checking
829 #test expr-old-36.11 {ExprLooksLikeInt procedure} {
830 # # define a "too large integer"; this one works also for 64bit arith
831 # set x 665802003400000000000000
832 # list [catch {expr {$x+1}} msg] $msg
833 #} {1 {can't use integer value too large to represent as operand of "+"}}
835 # Special test for Pentium arithmetic bug of 1994:
837 if {(4195835.0 - (4195835.0/3145727.0)*3145727.0) == 256.0} {
838 puts "Warning: this machine contains a defective Pentium processor"
839 puts "that performs arithmetic incorrectly. I recommend that you"
840 puts "call Intel customer service immediately at 1-800-628-8686"
841 puts "to request a replacement processor."
842 puts [expr {(4195835.0 - (4195835.0/3145727.0)*3145727.0)}]