Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/tcl8.5.2/tests/expr-old.test @ 47

Last change on this file since 47 was 25, checked in by landauf, 17 years ago

added tcl to libs

File size: 46.2 KB
RevLine 
[25]1# Commands covered: expr
2#
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.
8#
9# Copyright (c) 1991-1994 The Regents of the University of California.
10# Copyright (c) 1994-1997 Sun Microsystems, Inc.
11# Copyright (c) 1998-2000 by Scriptics Corporation.
12#
13# See the file "license.terms" for information on usage and redistribution
14# of this file, and for a DISCLAIMER OF ALL WARRANTIES.
15#
16# RCS: @(#) $Id: expr-old.test,v 1.40 2007/12/13 15:26:06 dgp Exp $
17
18if {[lsearch [namespace children] ::tcltest] == -1} {
19    package require tcltest 2.1
20    namespace import -force ::tcltest::*
21}
22
23testConstraint testexprlong   [llength [info commands testexprlong]]
24testConstraint testexprdouble [llength [info commands testexprdouble]]
25testConstraint testexprstring [llength [info commands testexprstring]]
26testConstraint longIs32bit    [expr {int(0x80000000) < 0}]
27
28if {[catch {expr T1()} msg] && $msg eq {invalid command name "tcl::mathfunc::T1"}} {
29    testConstraint testmathfunctions 0
30} else {
31    testConstraint testmathfunctions 1
32}
33
34# Big test for correct ordering of data in [expr]
35
36proc testIEEE {} {
37    variable ieeeValues
38    binary scan [binary format dd -1.0 1.0] c* c
39    switch -exact -- $c {
40        {0 0 0 0 0 0 -16 -65 0 0 0 0 0 0 -16 63} {
41            # little endian
42            binary scan \x00\x00\x00\x00\x00\x00\xf0\xff d \
43                ieeeValues(-Infinity)
44            binary scan \x00\x00\x00\x00\x00\x00\xf0\xbf d \
45                ieeeValues(-Normal)
46            binary scan \x00\x00\x00\x00\x00\x00\x08\x80 d \
47                ieeeValues(-Subnormal)
48            binary scan \x00\x00\x00\x00\x00\x00\x00\x80 d \
49                ieeeValues(-0)
50            binary scan \x00\x00\x00\x00\x00\x00\x00\x00 d \
51                ieeeValues(+0)
52            binary scan \x00\x00\x00\x00\x00\x00\x08\x00 d \
53                ieeeValues(+Subnormal)
54            binary scan \x00\x00\x00\x00\x00\x00\xf0\x3f d \
55                ieeeValues(+Normal)
56            binary scan \x00\x00\x00\x00\x00\x00\xf0\x7f d \
57                ieeeValues(+Infinity)
58            binary scan \x00\x00\x00\x00\x00\x00\xf8\x7f d \
59                ieeeValues(NaN)
60            set ieeeValues(littleEndian) 1
61            return 1
62        }
63        {-65 -16 0 0 0 0 0 0 63 -16 0 0 0 0 0 0} {
64            binary scan \xff\xf0\x00\x00\x00\x00\x00\x00 d \
65                ieeeValues(-Infinity)
66            binary scan \xbf\xf0\x00\x00\x00\x00\x00\x00 d \
67                ieeeValues(-Normal)
68            binary scan \x80\x08\x00\x00\x00\x00\x00\x00 d \
69                ieeeValues(-Subnormal)
70            binary scan \x80\x00\x00\x00\x00\x00\x00\x00 d \
71                ieeeValues(-0)
72            binary scan \x00\x00\x00\x00\x00\x00\x00\x00 d \
73                ieeeValues(+0)
74            binary scan \x00\x08\x00\x00\x00\x00\x00\x00 d \
75                ieeeValues(+Subnormal)
76            binary scan \x3f\xf0\x00\x00\x00\x00\x00\x00 d \
77                ieeeValues(+Normal)
78            binary scan \x7f\xf0\x00\x00\x00\x00\x00\x00 d \
79                ieeeValues(+Infinity)
80            binary scan \x7f\xf8\x00\x00\x00\x00\x00\x00 d \
81                ieeeValues(NaN)
82            set ieeeValues(littleEndian) 0
83            return 1
84        }
85        default {
86            return 0
87        }
88    }
89}
90testConstraint ieeeFloatingPoint [testIEEE]
91
92# First, test all of the integer operators individually.
93
94test expr-old-1.1 {integer operators} {expr -4} -4
95test expr-old-1.2 {integer operators} {expr -(1+4)} -5
96test expr-old-1.3 {integer operators} {expr ~3} -4
97test expr-old-1.4 {integer operators} {expr !2} 0
98test expr-old-1.5 {integer operators} {expr !0} 1
99test expr-old-1.6 {integer operators} {expr 4*6} 24
100test expr-old-1.7 {integer operators} {expr 36/12} 3
101test expr-old-1.8 {integer operators} {expr 27/4} 6
102test expr-old-1.9 {integer operators} {expr 27%4} 3
103test expr-old-1.10 {integer operators} {expr 2+2} 4
104test expr-old-1.11 {integer operators} {expr 2-6} -4
105test expr-old-1.12 {integer operators} {expr 1<<3} 8
106test expr-old-1.13 {integer operators} {expr 0xff>>2} 63
107test expr-old-1.14 {integer operators} {expr -1>>2} -1
108test expr-old-1.15 {integer operators} {expr 3>2} 1
109test expr-old-1.16 {integer operators} {expr 2>2} 0
110test expr-old-1.17 {integer operators} {expr 1>2} 0
111test expr-old-1.18 {integer operators} {expr 3<2} 0
112test expr-old-1.19 {integer operators} {expr 2<2} 0
113test expr-old-1.20 {integer operators} {expr 1<2} 1
114test expr-old-1.21 {integer operators} {expr 3>=2} 1
115test expr-old-1.22 {integer operators} {expr 2>=2} 1
116test expr-old-1.23 {integer operators} {expr 1>=2} 0
117test expr-old-1.24 {integer operators} {expr 3<=2} 0
118test expr-old-1.25 {integer operators} {expr 2<=2} 1
119test expr-old-1.26 {integer operators} {expr 1<=2} 1
120test expr-old-1.27 {integer operators} {expr 3==2} 0
121test expr-old-1.28 {integer operators} {expr 2==2} 1
122test expr-old-1.29 {integer operators} {expr 3!=2} 1
123test expr-old-1.30 {integer operators} {expr 2!=2} 0
124test expr-old-1.31 {integer operators} {expr 7&0x13} 3
125test expr-old-1.32 {integer operators} {expr 7^0x13} 20
126test expr-old-1.33 {integer operators} {expr 7|0x13} 23
127test expr-old-1.34 {integer operators} {expr 0&&1} 0
128test expr-old-1.35 {integer operators} {expr 0&&0} 0
129test expr-old-1.36 {integer operators} {expr 1&&3} 1
130test expr-old-1.37 {integer operators} {expr 0||1} 1
131test expr-old-1.38 {integer operators} {expr 3||0} 1
132test expr-old-1.39 {integer operators} {expr 0||0} 0
133test expr-old-1.40 {integer operators} {expr 3>2?44:66} 44
134test expr-old-1.41 {integer operators} {expr 2>3?44:66} 66
135test expr-old-1.42 {integer operators} {expr 36/5} 7
136test expr-old-1.43 {integer operators} {expr 36%5} 1
137test expr-old-1.44 {integer operators} {expr -36/5} -8
138test expr-old-1.45 {integer operators} {expr -36%5} 4
139test expr-old-1.46 {integer operators} {expr 36/-5} -8
140test expr-old-1.47 {integer operators} {expr 36%-5} -4
141test expr-old-1.48 {integer operators} {expr -36/-5} 7
142test expr-old-1.49 {integer operators} {expr -36%-5} -1
143test expr-old-1.50 {integer operators} {expr +36} 36
144test expr-old-1.51 {integer operators} {expr +--++36} 36
145test expr-old-1.52 {integer operators} {expr +36%+5} 1
146test expr-old-1.53 {integer operators} {
147    catch {unset x}
148    set x yes
149    list [expr {1 && $x}] [expr {$x && 1}] \
150         [expr {0 || $x}] [expr {$x || 0}]
151} {1 1 1 1}
152
153# Check the floating-point operators individually, along with
154# automatic conversion to integers where needed.
155
156test expr-old-2.1 {floating-point operators} {expr -4.2} -4.2
157test expr-old-2.2 {floating-point operators} {expr -(1.125+4.25)} -5.375
158test expr-old-2.3 {floating-point operators} {expr +5.7} 5.7
159test expr-old-2.4 {floating-point operators} {expr +--+-62.0} -62.0
160test expr-old-2.5 {floating-point operators} {expr !2.1} 0
161test expr-old-2.6 {floating-point operators} {expr !0.0} 1
162test expr-old-2.7 {floating-point operators} {expr 4.2*6.3} 26.46
163test expr-old-2.8 {floating-point operators} {expr 36.0/12.0} 3.0
164test expr-old-2.9 {floating-point operators} {expr 27/4.0} 6.75
165test expr-old-2.10 {floating-point operators} {expr 2.3+2.1} 4.4
166test expr-old-2.11 {floating-point operators} {expr 2.3-6.5} -4.2
167test expr-old-2.12 {floating-point operators} {expr 3.1>2.1} 1
168test expr-old-2.13 {floating-point operators} {expr {2.1 > 2.1}} 0
169test expr-old-2.14 {floating-point operators} {expr 1.23>2.34e+1} 0
170test expr-old-2.15 {floating-point operators} {expr 3.45<2.34} 0
171test expr-old-2.16 {floating-point operators} {expr 0.002e3<--200e-2} 0
172test expr-old-2.17 {floating-point operators} {expr 1.1<2.1} 1
173test expr-old-2.18 {floating-point operators} {expr 3.1>=2.2} 1
174test expr-old-2.19 {floating-point operators} {expr 2.345>=2.345} 1
175test expr-old-2.20 {floating-point operators} {expr 1.1>=2.2} 0
176test expr-old-2.21 {floating-point operators} {expr 3.0<=2.0} 0
177test expr-old-2.22 {floating-point operators} {expr 2.2<=2.2} 1
178test expr-old-2.23 {floating-point operators} {expr 2.2<=2.2001} 1
179test expr-old-2.24 {floating-point operators} {expr 3.2==2.2} 0
180test expr-old-2.25 {floating-point operators} {expr 2.2==2.2} 1
181test expr-old-2.26 {floating-point operators} {expr 3.2!=2.2} 1
182test expr-old-2.27 {floating-point operators} {expr 2.2!=2.2} 0
183test expr-old-2.28 {floating-point operators} {expr 0.0&&0.0} 0
184test expr-old-2.29 {floating-point operators} {expr 0.0&&1.3} 0
185test expr-old-2.30 {floating-point operators} {expr 1.3&&0.0} 0
186test expr-old-2.31 {floating-point operators} {expr 1.3&&3.3} 1
187test expr-old-2.32 {floating-point operators} {expr 0.0||0.0} 0
188test expr-old-2.33 {floating-point operators} {expr 0.0||1.3} 1
189test expr-old-2.34 {floating-point operators} {expr 1.3||0.0} 1
190test expr-old-2.35 {floating-point operators} {expr 3.3||0.0} 1
191test expr-old-2.36 {floating-point operators} {expr 3.3>2.3?44.3:66.3} 44.3
192test expr-old-2.37 {floating-point operators} {expr 2.3>3.3?44.3:66.3} 66.3
193test expr-old-2.38 {floating-point operators} {
194    list [catch {expr 028.1 + 09.2} msg] $msg
195} {0 37.3}
196
197# Operators that aren't legal on floating-point numbers
198
199test expr-old-3.1 {illegal floating-point operations} {
200    list [catch {expr ~4.0} msg] $msg
201} {1 {can't use floating-point value as operand of "~"}}
202test expr-old-3.2 {illegal floating-point operations} {
203    list [catch {expr 27%4.0} msg] $msg
204} {1 {can't use floating-point value as operand of "%"}}
205test expr-old-3.3 {illegal floating-point operations} {
206    list [catch {expr 27.0%4} msg] $msg
207} {1 {can't use floating-point value as operand of "%"}}
208test expr-old-3.4 {illegal floating-point operations} {
209    list [catch {expr 1.0<<3} msg] $msg
210} {1 {can't use floating-point value as operand of "<<"}}
211test expr-old-3.5 {illegal floating-point operations} {
212    list [catch {expr 3<<1.0} msg] $msg
213} {1 {can't use floating-point value as operand of "<<"}}
214test expr-old-3.6 {illegal floating-point operations} {
215    list [catch {expr 24.0>>3} msg] $msg
216} {1 {can't use floating-point value as operand of ">>"}}
217test expr-old-3.7 {illegal floating-point operations} {
218    list [catch {expr 24>>3.0} msg] $msg
219} {1 {can't use floating-point value as operand of ">>"}}
220test expr-old-3.8 {illegal floating-point operations} {
221    list [catch {expr 24&3.0} msg] $msg
222} {1 {can't use floating-point value as operand of "&"}}
223test expr-old-3.9 {illegal floating-point operations} {
224    list [catch {expr 24.0|3} msg] $msg
225} {1 {can't use floating-point value as operand of "|"}}
226test expr-old-3.10 {illegal floating-point operations} {
227    list [catch {expr 24.0^3} msg] $msg
228} {1 {can't use floating-point value as operand of "^"}}
229
230# Check the string operators individually.
231
232test expr-old-4.1 {string operators} {expr {"abc" > "def"}} 0
233test expr-old-4.2 {string operators} {expr {"def" > "def"}} 0
234test expr-old-4.3 {string operators} {expr {"g" > "def"}} 1
235test expr-old-4.4 {string operators} {expr {"abc" < "abd"}} 1
236test expr-old-4.5 {string operators} {expr {"abd" < "abd"}} 0
237test expr-old-4.6 {string operators} {expr {"abe" < "abd"}} 0
238test expr-old-4.7 {string operators} {expr {"abc" >= "def"}} 0
239test expr-old-4.8 {string operators} {expr {"def" >= "def"}} 1
240test expr-old-4.9 {string operators} {expr {"g" >= "def"}} 1
241test expr-old-4.10 {string operators} {expr {"abc" <= "abd"}} 1
242test expr-old-4.11 {string operators} {expr {"abd" <= "abd"}} 1
243test expr-old-4.12 {string operators} {expr {"abe" <= "abd"}} 0
244test expr-old-4.13 {string operators} {expr {"abc" == "abd"}} 0
245test expr-old-4.14 {string operators} {expr {"abd" == "abd"}} 1
246test expr-old-4.15 {string operators} {expr {"abc" != "abd"}} 1
247test expr-old-4.16 {string operators} {expr {"abd" != "abd"}} 0
248test expr-old-4.17 {string operators} {expr {"0y" < "0x12"}} 0
249test expr-old-4.18 {string operators} {expr {"." < " "}} 0
250test expr-old-4.19 {string operators} {expr {"abc" eq "abd"}} 0
251test expr-old-4.20 {string operators} {expr {"abd" eq "abd"}} 1
252test expr-old-4.21 {string operators} {expr {"abc" ne "abd"}} 1
253test expr-old-4.22 {string operators} {expr {"abd" ne "abd"}} 0
254test expr-old-4.23 {string operators} {expr {"" eq "abd"}} 0
255test expr-old-4.24 {string operators} {expr {"" eq ""}} 1
256test expr-old-4.25 {string operators} {expr {"abd" ne ""}} 1
257test expr-old-4.26 {string operators} {expr {"" ne ""}} 0
258test expr-old-4.27 {string operators} {expr {"longerstring" eq "shorter"}} 0
259test expr-old-4.28 {string operators} {expr {"longerstring" ne "shorter"}} 1
260test expr-old-4.29 {string operators} {expr {"0" == "+"}} 0
261test expr-old-4.30 {string operators} {expr {"0" == "-"}} 0
262test expr-old-4.31 {string operators} {expr {1?"foo":"bar"}} foo
263test expr-old-4.32 {string operators} {expr {0?"foo":"bar"}} bar
264
265# Operators that aren't legal on string operands.
266
267test expr-old-5.1 {illegal string operations} {
268    list [catch {expr {-"a"}} msg] $msg
269} {1 {can't use non-numeric string as operand of "-"}}
270test expr-old-5.2 {illegal string operations} {
271    list [catch {expr {+"a"}} msg] $msg
272} {1 {can't use non-numeric string as operand of "+"}}
273test expr-old-5.3 {illegal string operations} {
274    list [catch {expr {~"a"}} msg] $msg
275} {1 {can't use non-numeric string as operand of "~"}}
276test expr-old-5.4 {illegal string operations} {
277    list [catch {expr {!"a"}} msg] $msg
278} {1 {can't use non-numeric string as operand of "!"}}
279test expr-old-5.5 {illegal string operations} {
280    list [catch {expr {"a"*"b"}} msg] $msg
281} {1 {can't use non-numeric string as operand of "*"}}
282test expr-old-5.6 {illegal string operations} {
283    list [catch {expr {"a"/"b"}} msg] $msg
284} {1 {can't use non-numeric string as operand of "/"}}
285test expr-old-5.7 {illegal string operations} {
286    list [catch {expr {"a"%"b"}} msg] $msg
287} {1 {can't use non-numeric string as operand of "%"}}
288test expr-old-5.8 {illegal string operations} {
289    list [catch {expr {"a"+"b"}} msg] $msg
290} {1 {can't use non-numeric string as operand of "+"}}
291test expr-old-5.9 {illegal string operations} {
292    list [catch {expr {"a"-"b"}} msg] $msg
293} {1 {can't use non-numeric string as operand of "-"}}
294test expr-old-5.10 {illegal string operations} {
295    list [catch {expr {"a"<<"b"}} msg] $msg
296} {1 {can't use non-numeric string as operand of "<<"}}
297test expr-old-5.11 {illegal string operations} {
298    list [catch {expr {"a">>"b"}} msg] $msg
299} {1 {can't use non-numeric string as operand of ">>"}}
300test expr-old-5.12 {illegal string operations} {
301    list [catch {expr {"a"&"b"}} msg] $msg
302} {1 {can't use non-numeric string as operand of "&"}}
303test expr-old-5.13 {illegal string operations} {
304    list [catch {expr {"a"^"b"}} msg] $msg
305} {1 {can't use non-numeric string as operand of "^"}}
306test expr-old-5.14 {illegal string operations} {
307    list [catch {expr {"a"|"b"}} msg] $msg
308} {1 {can't use non-numeric string as operand of "|"}}
309test expr-old-5.15 {illegal string operations} {
310    list [catch {expr {"a"&&"b"}} msg] $msg
311} {1 {expected boolean value but got "a"}}
312test expr-old-5.16 {illegal string operations} {
313    list [catch {expr {"a"||"b"}} msg] $msg
314} {1 {expected boolean value but got "a"}}
315test expr-old-5.17 {illegal string operations} {
316    list [catch {expr {"a"?4:2}} msg] $msg
317} {1 {expected boolean value but got "a"}}
318
319# Check precedence pairwise.
320
321test expr-old-6.1 {precedence checks} {expr -~3} 4
322test expr-old-6.2 {precedence checks} {expr -!3} 0
323test expr-old-6.3 {precedence checks} {expr -~0} 1
324
325test expr-old-7.1 {precedence checks} {expr 2*4/6} 1
326test expr-old-7.2 {precedence checks} {expr 24/6*3} 12
327test expr-old-7.3 {precedence checks} {expr 24/6/2} 2
328
329test expr-old-8.1 {precedence checks} {expr -2+4} 2
330test expr-old-8.2 {precedence checks} {expr -2-4} -6
331test expr-old-8.3 {precedence checks} {expr +2-4} -2
332
333test expr-old-9.1 {precedence checks} {expr 2*3+4} 10
334test expr-old-9.2 {precedence checks} {expr 8/2+4} 8
335test expr-old-9.3 {precedence checks} {expr 8%3+4} 6
336test expr-old-9.4 {precedence checks} {expr 2*3-1} 5
337test expr-old-9.5 {precedence checks} {expr 8/2-1} 3
338test expr-old-9.6 {precedence checks} {expr 8%3-1} 1
339
340test expr-old-10.1 {precedence checks} {expr 6-3-2} 1
341
342test expr-old-11.1 {precedence checks} {expr 7+1>>2} 2
343test expr-old-11.2 {precedence checks} {expr 7+1<<2} 32
344test expr-old-11.3 {precedence checks} {expr 7>>3-2} 3
345test expr-old-11.4 {precedence checks} {expr 7<<3-2} 14
346
347test expr-old-12.1 {precedence checks} {expr 6>>1>4} 0
348test expr-old-12.2 {precedence checks} {expr 6>>1<2} 0
349test expr-old-12.3 {precedence checks} {expr 6>>1>=3} 1
350test expr-old-12.4 {precedence checks} {expr 6>>1<=2} 0
351test expr-old-12.5 {precedence checks} {expr 6<<1>5} 1
352test expr-old-12.6 {precedence checks} {expr 6<<1<5} 0
353test expr-old-12.7 {precedence checks} {expr 5<=6<<1} 1
354test expr-old-12.8 {precedence checks} {expr 5>=6<<1} 0
355
356test expr-old-13.1 {precedence checks} {expr 2<3<4} 1
357test expr-old-13.2 {precedence checks} {expr 0<4>2} 0
358test expr-old-13.3 {precedence checks} {expr 4>2<1} 0
359test expr-old-13.4 {precedence checks} {expr 4>3>2} 0
360test expr-old-13.5 {precedence checks} {expr 4>3>=2} 0
361test expr-old-13.6 {precedence checks} {expr 4>=3>2} 0
362test expr-old-13.7 {precedence checks} {expr 4>=3>=2} 0
363test expr-old-13.8 {precedence checks} {expr 0<=4>=2} 0
364test expr-old-13.9 {precedence checks} {expr 4>=2<=0} 0
365test expr-old-13.10 {precedence checks} {expr 2<=3<=4} 1
366
367test expr-old-14.1 {precedence checks} {expr 1==4>3} 1
368test expr-old-14.2 {precedence checks} {expr 0!=4>3} 1
369test expr-old-14.3 {precedence checks} {expr 1==3<4} 1
370test expr-old-14.4 {precedence checks} {expr 0!=3<4} 1
371test expr-old-14.5 {precedence checks} {expr 1==4>=3} 1
372test expr-old-14.6 {precedence checks} {expr 0!=4>=3} 1
373test expr-old-14.7 {precedence checks} {expr 1==3<=4} 1
374test expr-old-14.8 {precedence checks} {expr 0!=3<=4} 1
375test expr-old-14.9 {precedence checks} {expr 1eq4>3} 1
376test expr-old-14.10 {precedence checks} {expr 0ne4>3} 1
377test expr-old-14.11 {precedence checks} {expr 1eq3<4} 1
378test expr-old-14.12 {precedence checks} {expr 0ne3<4} 1
379test expr-old-14.13 {precedence checks} {expr 1eq4>=3} 1
380test expr-old-14.14 {precedence checks} {expr 0ne4>=3} 1
381test expr-old-14.15 {precedence checks} {expr 1eq3<=4} 1
382test expr-old-14.16 {precedence checks} {expr 0ne3<=4} 1
383
384test expr-old-15.1 {precedence checks} {expr 1==3==3} 0
385test expr-old-15.2 {precedence checks} {expr 3==3!=2} 1
386test expr-old-15.3 {precedence checks} {expr 2!=3==3} 0
387test expr-old-15.4 {precedence checks} {expr 2!=1!=1} 0
388test expr-old-15.5 {precedence checks} {expr 1eq3eq3} 0
389test expr-old-15.6 {precedence checks} {expr 3eq3ne2} 1
390test expr-old-15.7 {precedence checks} {expr 2ne3eq3} 0
391test expr-old-15.8 {precedence checks} {expr 2ne1ne1} 0
392
393test expr-old-16.1 {precedence checks} {expr 2&3eq2} 0
394test expr-old-16.2 {precedence checks} {expr 1&3ne3} 0
395test expr-old-16.3 {precedence checks} {expr 2&3eq2} 0
396test expr-old-16.4 {precedence checks} {expr 1&3ne3} 0
397
398test expr-old-17.1 {precedence checks} {expr 7&3^0x10} 19
399test expr-old-17.2 {precedence checks} {expr 7^0x10&3} 7
400
401test expr-old-18.1 {precedence checks} {expr 7^0x10|3} 23
402test expr-old-18.2 {precedence checks} {expr 7|0x10^3} 23
403
404test expr-old-19.1 {precedence checks} {expr 7|3&&1} 1
405test expr-old-19.2 {precedence checks} {expr 1&&3|7} 1
406test expr-old-19.3 {precedence checks} {expr 0&&1||1} 1
407test expr-old-19.4 {precedence checks} {expr 1||1&&0} 1
408
409test expr-old-20.1 {precedence checks} {expr 1||0?3:4} 3
410test expr-old-20.2 {precedence checks} {expr 1?0:4||1} 0
411test expr-old-20.3 {precedence checks} {expr 1?2:0?3:4} 2
412test expr-old-20.4 {precedence checks} {expr 0?2:0?3:4} 4
413test expr-old-20.5 {precedence checks} {expr 1?2?3:4:0} 3
414test expr-old-20.6 {precedence checks} {expr 0?2?3:4:0} 0
415
416# Parentheses.
417
418test expr-old-21.1 {parenthesization} {expr (2+4)*6} 36
419test expr-old-21.2 {parenthesization} {expr (1?0:4)||1} 1
420test expr-old-21.3 {parenthesization} {expr +(3-4)} -1
421
422# Embedded commands and variable names.
423
424set a 16
425test expr-old-22.1 {embedded variables} {expr {2*$a}} 32
426test expr-old-22.2 {embedded variables} {
427    set x -5
428    set y 10
429    expr {$x + $y}
430} {5}
431test expr-old-22.3 {embedded variables} {
432    set x "  -5"
433    set y "  +10"
434    expr {$x + $y}
435} {5}
436test expr-old-22.4 {embedded commands and variables} {expr {[set a] - 14}} 2
437test expr-old-22.5 {embedded commands and variables} {
438    list [catch {expr {12 - [bad_command_name]}} msg] $msg
439} {1 {invalid command name "bad_command_name"}}
440
441# Double-quotes and things inside them.
442
443test expr-old-23.1 {double quotes} {expr {"abc"}} abc
444test expr-old-23.2 {double quotes} {
445    set a 189
446    expr {"$a.bc"}
447} 189.bc
448test expr-old-23.3 {double quotes} {
449    set b2 xyx
450    expr {"$b2$b2$b2.[set b2].[set b2]"}
451} xyxxyxxyx.xyx.xyx
452test expr-old-23.4 {double quotes} {expr {"11\}\}22"}} 11}}22
453test expr-old-23.5 {double quotes} {expr {"\*bc"}} {*bc}
454test expr-old-23.6 {double quotes} {
455    catch {unset bogus__}
456    list [catch {expr {"$bogus__"}} msg] $msg
457} {1 {can't read "bogus__": no such variable}}
458test expr-old-23.7 {double quotes} {
459    list [catch {expr {"a[error Testing]bc"}} msg] $msg
460} {1 Testing}
461test expr-old-23.8 {double quotes} {
462    list [catch {expr {"12398712938788234-1298379" != ""}} msg] $msg
463} {0 1}
464
465# Numbers in various bases.
466
467test expr-old-24.1 {numbers in different bases} {expr 0x20} 32
468test expr-old-24.2 {numbers in different bases} {expr 0o15} 13
469
470# Conversions between various data types.
471
472test expr-old-25.1 {type conversions} {expr 2+2.5} 4.5
473test expr-old-25.2 {type conversions} {expr 2.5+2} 4.5
474test expr-old-25.3 {type conversions} {expr 2-2.5} -0.5
475test expr-old-25.4 {type conversions} {expr 2/2.5} 0.8
476test expr-old-25.5 {type conversions} {expr 2>2.5} 0
477test expr-old-25.6 {type conversions} {expr 2.5>2} 1
478test expr-old-25.7 {type conversions} {expr 2<2.5} 1
479test expr-old-25.8 {type conversions} {expr 2>=2.5} 0
480test expr-old-25.9 {type conversions} {expr 2<=2.5} 1
481test expr-old-25.10 {type conversions} {expr 2==2.5} 0
482test expr-old-25.11 {type conversions} {expr 2!=2.5} 1
483test expr-old-25.12 {type conversions} {expr 2>"ab"} 0
484test expr-old-25.13 {type conversions} {expr {2>" "}} 1
485test expr-old-25.14 {type conversions} {expr {"24.1a" > 24.1}} 1
486test expr-old-25.15 {type conversions} {expr {24.1 > "24.1a"}} 0
487test expr-old-25.16 {type conversions} {expr 2+2.5} 4.5
488test expr-old-25.17 {type conversions} {expr 2+2.5} 4.5
489test expr-old-25.18 {type conversions} {expr 2.0e2} 200.0
490test expr-old-25.19 {type conversions} {expr 2.0e15} 2000000000000000.0
491test expr-old-25.20 {type conversions} {expr 10.0} 10.0
492
493# Various error conditions.
494
495test expr-old-26.1 {error conditions} {
496    list [catch {expr 2+"a"} msg] $msg
497} {1 {can't use non-numeric string as operand of "+"}}
498test expr-old-26.2 {error conditions} -body {
499    expr 2+4*
500} -returnCodes error -match glob -result *
501test expr-old-26.3 {error conditions} -body {
502    expr 2+4*(
503} -returnCodes error -match glob -result *
504catch {unset _non_existent_}
505test expr-old-26.4 {error conditions} {
506    list [catch {expr 2+$_non_existent_} msg] $msg
507} {1 {can't read "_non_existent_": no such variable}}
508set a xx
509test expr-old-26.5 {error conditions} {
510    list [catch {expr {2+$a}} msg] $msg
511} {1 {can't use non-numeric string as operand of "+"}}
512test expr-old-26.6 {error conditions} {
513    list [catch {expr {2+[set a]}} msg] $msg
514} {1 {can't use non-numeric string as operand of "+"}}
515test expr-old-26.7 {error conditions} -body {
516    expr {2+(4}
517} -returnCodes error -match glob -result *
518test expr-old-26.8 {error conditions} {
519    list [catch {expr 2/0} msg] $msg $errorCode
520} {1 {divide by zero} {ARITH DIVZERO {divide by zero}}}
521test expr-old-26.9 {error conditions} {
522    list [catch {expr 2%0} msg] $msg $errorCode
523} {1 {divide by zero} {ARITH DIVZERO {divide by zero}}}
524test expr-old-26.10a {error conditions} !ieeeFloatingPoint {
525    list [catch {expr 2.0/0.0} msg] $msg $errorCode
526} {1 {divide by zero} {ARITH DIVZERO {divide by zero}}}
527test expr-old-26.10b {error conditions} ieeeFloatingPoint {
528    list [catch {expr 2.0/0.0} msg] $msg
529} {0 Inf}
530test expr-old-26.11 {error conditions} -body {
531    expr 2#
532} -returnCodes error -match glob -result *
533test expr-old-26.12 {error conditions} -body {
534    expr a.b
535} -returnCodes error -match glob -result *
536test expr-old-26.13 {error conditions} {
537    list [catch {expr {"a"/"b"}} msg] $msg
538} {1 {can't use non-numeric string as operand of "/"}}
539test expr-old-26.14 {error conditions} -body {
540    expr 2:3
541} -returnCodes error -match glob -result *
542test expr-old-26.15 {error conditions} -body {
543    expr a@b
544} -returnCodes error -match glob -result *
545test expr-old-26.16 {error conditions} {
546    list [catch {expr a[b} msg] $msg
547} {1 {missing close-bracket}}
548test expr-old-26.17 {error conditions} -body {
549    expr a`b
550} -returnCodes error -match glob -result *
551test expr-old-26.18 {error conditions} -body {
552    expr \"a\"\{b
553} -returnCodes error -match glob -result *
554test expr-old-26.19 {error conditions} -body {
555    expr a
556} -returnCodes error -match glob -result *
557test expr-old-26.20 {error conditions} {
558    list [catch expr msg] $msg
559} {1 {wrong # args: should be "expr arg ?arg ...?"}}
560
561# Cancelled evaluation.
562
563test expr-old-27.1 {cancelled evaluation} {
564    set a 1
565    expr {0&&[set a 2]}
566    set a
567} 1
568test expr-old-27.2 {cancelled evaluation} {
569    set a 1
570    expr {1||[set a 2]}
571    set a
572} 1
573test expr-old-27.3 {cancelled evaluation} {
574    set a 1
575    expr {0?[set a 2]:1}
576    set a
577} 1
578test expr-old-27.4 {cancelled evaluation} {
579    set a 1
580    expr {1?2:[set a 2]}
581    set a
582} 1
583catch {unset x}
584test expr-old-27.5 {cancelled evaluation} {
585    list [catch {expr {[info exists x] && $x}} msg] $msg
586} {0 0}
587test expr-old-27.6 {cancelled evaluation} {
588    list [catch {expr {0 && [concat $x]}} msg] $msg
589} {0 0}
590test expr-old-27.7 {cancelled evaluation} {
591    set one 1
592    list [catch {expr {1 || 1/$one}} msg] $msg
593} {0 1}
594test expr-old-27.8 {cancelled evaluation} {
595    list [catch {expr {1 || -"string"}} msg] $msg
596} {0 1}
597test expr-old-27.9 {cancelled evaluation} {
598    list [catch {expr {1 || ("string" * ("x" && "y"))}} msg] $msg
599} {0 1}
600test expr-old-27.10 {cancelled evaluation} {
601    set x -1.0
602    list [catch {expr {($x > 0) ? round(log($x)) : 0}} msg] $msg
603} {0 0}
604test expr-old-27.11 {cancelled evaluation} -body {
605    expr {0 && foo}
606} -returnCodes error -match glob -result *
607test expr-old-27.12 {cancelled evaluation} -body {
608    expr {0 ? 1 : foo}
609} -returnCodes error -match glob -result *
610
611# Tcl_ExprBool as used in "if" statements
612
613test expr-old-28.1 {Tcl_ExprBoolean usage} {
614    set a 1
615    if {2} {set a 2}
616    set a
617} 2
618test expr-old-28.2 {Tcl_ExprBoolean usage} {
619    set a 1
620    if {0} {set a 2}
621    set a
622} 1
623test expr-old-28.3 {Tcl_ExprBoolean usage} {
624    set a 1
625    if {1.2} {set a 2}
626    set a
627} 2
628test expr-old-28.4 {Tcl_ExprBoolean usage} {
629    set a 1
630    if {-1.1} {set a 2}
631    set a
632} 2
633test expr-old-28.5 {Tcl_ExprBoolean usage} {
634    set a 1
635    if {0.0} {set a 2}
636    set a
637} 1
638test expr-old-28.6 {Tcl_ExprBoolean usage} {
639    set a 1
640    if {"YES"} {set a 2}
641    set a
642} 2
643test expr-old-28.7 {Tcl_ExprBoolean usage} {
644    set a 1
645    if {"no"} {set a 2}
646    set a
647} 1
648test expr-old-28.8 {Tcl_ExprBoolean usage} {
649    set a 1
650    if {"true"} {set a 2}
651    set a
652} 2
653test expr-old-28.9 {Tcl_ExprBoolean usage} {
654    set a 1
655    if {"fAlse"} {set a 2}
656    set a
657} 1
658test expr-old-28.10 {Tcl_ExprBoolean usage} {
659    set a 1
660    if {"on"} {set a 2}
661    set a
662} 2
663test expr-old-28.11 {Tcl_ExprBoolean usage} {
664    set a 1
665    if {"Off"} {set a 2}
666    set a
667} 1
668test expr-old-28.12 {Tcl_ExprBool usage} {
669    list [catch {if {"abc"} {}} msg] $msg
670} {1 {expected boolean value but got "abc"}}
671test expr-old-28.13 {Tcl_ExprBool usage} {
672    list [catch {if {"ogle"} {}} msg] $msg
673} {1 {expected boolean value but got "ogle"}}
674test expr-old-28.14 {Tcl_ExprBool usage} {
675    list [catch {if {"o"} {}} msg] $msg
676} {1 {expected boolean value but got "o"}}
677
678# Operands enclosed in braces
679
680test expr-old-29.1 {braces} {expr {{abc}}} abc
681test expr-old-29.2 {braces} {expr {{0o0010}}} 8
682test expr-old-29.3 {braces} {expr {{3.1200000}}} 3.12
683test expr-old-29.4 {braces} {expr {{a{b}{1 {2 3}}c}}} "a{b}{1 {2 3}}c"
684test expr-old-29.5 {braces} -body {
685    expr "\{abc"
686} -returnCodes error -match glob -result *
687
688# Very long values
689
690test expr-old-30.1 {long values} {
691    set a "0000 1111 2222 3333 4444"
692    set a "$a | $a | $a | $a | $a"
693    set a "$a || $a || $a || $a || $a"
694    expr {$a}
695} {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}
696test expr-old-30.2 {long values} {
697    set a "000000000000000000000000000000"
698    set a "$a$a$a$a$a$a$a$a$a$a$a$a$a$a$a$a${a}5"
699    expr $a
700} 5
701
702# Expressions spanning multiple arguments
703
704test expr-old-31.1 {multiple arguments to expr command} {
705    expr 4 + ( 6 *12) -3
706} 73
707test expr-old-31.2 {multiple arguments to expr command} -body {
708    expr 2 + (3 + 4
709} -returnCodes error -match glob -result *
710test expr-old-31.3 {multiple arguments to expr command} -body {
711    expr 2 + 3 +
712} -returnCodes error -match glob -result *
713test expr-old-31.4 {multiple arguments to expr command} -body {
714    expr 2 + 3 )
715} -returnCodes error -match glob -result *
716
717# Math functions
718
719test expr-old-32.1 {math functions in expressions} {
720    format %.6g [expr acos(0.5)]
721} {1.0472}
722test expr-old-32.2 {math functions in expressions} {
723    format %.6g [expr asin(0.5)]
724} {0.523599}
725test expr-old-32.3 {math functions in expressions} {
726    format %.6g [expr atan(1.0)]
727} {0.785398}
728test expr-old-32.4 {math functions in expressions} {
729    format %.6g [expr atan2(2.0, 2.0)]
730} {0.785398}
731test expr-old-32.5 {math functions in expressions} {
732    format %.6g [expr ceil(1.999)]
733} {2}
734test expr-old-32.6 {math functions in expressions} {
735    format %.6g [expr cos(.1)]
736} {0.995004}
737test expr-old-32.7 {math functions in expressions} {
738    format %.6g [expr cosh(.1)]
739} {1.005}
740test expr-old-32.8 {math functions in expressions} {
741    format %.6g [expr exp(1.0)]
742} {2.71828}
743test expr-old-32.9 {math functions in expressions} {
744    format %.6g [expr floor(2.000)]
745} {2}
746test expr-old-32.10 {math functions in expressions} {
747    format %.6g [expr floor(2.001)]
748} {2}
749test expr-old-32.11 {math functions in expressions} {
750    format %.6g [expr fmod(7.3, 3.2)]
751} {0.9}
752test expr-old-32.12 {math functions in expressions} {
753    format %.6g [expr hypot(3.0, 4.0)]
754} {5}
755test expr-old-32.13 {math functions in expressions} {
756    format %.6g [expr log(2.8)]
757} {1.02962}
758test expr-old-32.14 {math functions in expressions} {
759    format %.6g [expr log10(2.8)]
760} {0.447158}
761test expr-old-32.15 {math functions in expressions} {
762    format %.6g [expr pow(2.1, 3.1)]
763} {9.97424}
764test expr-old-32.16 {math functions in expressions} {
765    format %.6g [expr sin(.1)]
766} {0.0998334}
767test expr-old-32.17 {math functions in expressions} {
768    format %.6g [expr sinh(.1)]
769} {0.100167}
770test expr-old-32.18 {math functions in expressions} {
771    format %.6g [expr sqrt(2.0)]
772} {1.41421}
773test expr-old-32.19 {math functions in expressions} {
774    format %.6g [expr tan(0.8)]
775} {1.02964}
776test expr-old-32.20 {math functions in expressions} {
777    format %.6g [expr tanh(0.8)]
778} {0.664037}
779test expr-old-32.21 {math functions in expressions} {
780    format %.6g [expr abs(-1.8)]
781} {1.8}
782test expr-old-32.22 {math functions in expressions} {
783    expr abs(10.0)
784} {10.0}
785test expr-old-32.23 {math functions in expressions} {
786    format %.6g [expr abs(-4)]
787} {4}
788test expr-old-32.24 {math functions in expressions} {
789    format %.6g [expr abs(66)]
790} {66}
791
792test expr-old-32.25a {math functions in expressions} {
793    expr abs(0x8000000000000000)
794} [expr 1<<63]
795
796test expr-old-32.25b {math functions in expressions} {
797    expr abs(0x80000000)
798} 2147483648
799
800test expr-old-32.26 {math functions in expressions} {
801    expr double(1)
802} {1.0}
803test expr-old-32.27 {math functions in expressions} {
804    expr double(1.1)
805} {1.1}
806test expr-old-32.28 {math functions in expressions} {
807    expr int(1)
808} {1}
809test expr-old-32.29 {math functions in expressions} {
810    expr int(1.4)
811} {1}
812test expr-old-32.30 {math functions in expressions} {
813    expr int(1.6)
814} {1}
815test expr-old-32.31 {math functions in expressions} {
816    expr int(-1.4)
817} {-1}
818test expr-old-32.32 {math functions in expressions} {
819    expr int(-1.6)
820} {-1}
821test expr-old-32.33 {math functions in expressions} {
822    expr int(1e60)
823} 0
824test expr-old-32.34 {math functions in expressions} {
825    expr int(-1e60)
826} 0
827test expr-old-32.35 {math functions in expressions} {
828    expr round(1.49)
829} {1}
830test expr-old-32.36 {math functions in expressions} {
831    expr round(1.51)
832} {2}
833test expr-old-32.37 {math functions in expressions} {
834    expr round(-1.49)
835} {-1}
836test expr-old-32.38 {math functions in expressions} {
837    expr round(-1.51)
838} {-2}
839test expr-old-32.39 {math functions in expressions} {
840    expr round(1e60)
841} 999999999999999949387135297074018866963645011013410073083904
842test expr-old-32.40 {math functions in expressions} {
843    expr round(-1e60)
844} -999999999999999949387135297074018866963645011013410073083904
845test expr-old-32.41 {math functions in expressions} {
846    list [catch {expr pow(1.0 + 3.0 - 2, .8 * 5)} msg] $msg
847} {0 16.0}
848test expr-old-32.42 {math functions in expressions} {
849    list [catch {expr hypot(5*.8,3)} msg] $msg
850} {0 5.0}
851test expr-old-32.43 {math functions in expressions} testmathfunctions {
852    expr 2*T1()
853} 246
854test expr-old-32.44 {math functions in expressions} testmathfunctions {
855    expr T2()*3
856} 1035
857test expr-old-32.45 {math functions in expressions} {
858    expr (0 <= rand()) && (rand() < 1)
859} {1}
860test expr-old-32.46 {math functions in expressions} -body {
861    list [catch {expr rand(24)} msg] $msg
862} -match glob -result {1 {too many arguments for math function*}}
863test expr-old-32.47 {math functions in expressions} -body {
864    list [catch {expr srand()} msg] $msg
865} -match glob -result {1 {too few arguments for math function*}}
866test expr-old-32.48 {math functions in expressions} -body {
867    expr srand(3.79)
868} -returnCodes error -match glob -result *
869test expr-old-32.49 {math functions in expressions} -body {
870    expr srand("")
871} -returnCodes error -match glob -result *
872test expr-old-32.50 {math functions in expressions} {
873    set result [expr round(srand(12345) * 1000)]
874    for {set i 0} {$i < 10} {incr i} {
875        lappend result [expr round(rand() * 1000)]
876    }
877    set result
878} {97 834 948 36 12 51 766 585 914 784 333}
879test expr-old-32.51 {math functions in expressions} -body {
880    expr {srand([lindex "6ty" 0])}
881} -returnCodes error -match glob -result *
882test expr-old-32.52 {math functions in expressions} {
883    expr {srand(int(1<<37)) < 1}
884} {1}
885test expr-old-32.53 {math functions in expressions} {
886    expr {srand((1<<31) - 1) > 0}
887} {1}
888
889test expr-old-33.1 {conversions and fancy args to math functions} {
890    expr hypot ( 3 , 4 )
891} 5.0
892test expr-old-33.2 {conversions and fancy args to math functions} {
893    expr hypot ( (2.0+1.0) , 4 )
894} 5.0
895test expr-old-33.3 {conversions and fancy args to math functions} {
896    expr hypot ( 3 , (3.0 + 1.0) )
897} 5.0
898test expr-old-33.4 {conversions and fancy args to math functions} {
899    format %.6g [expr cos(acos(0.1))]
900} 0.1
901
902test expr-old-34.1 {errors in math functions} -body {
903    list [catch {expr func_2(1.0)} msg] $msg
904} -match glob -result {1 {* "*func_2"}}
905test expr-old-34.2 {errors in math functions} -body {
906    expr func|(1.0)
907} -returnCodes error -match glob -result *
908test expr-old-34.3 {errors in math functions} {
909    list [catch {expr {hypot("a b", 2.0)}} msg] $msg
910} {1 {expected floating-point number but got "a b"}}
911test expr-old-34.4 {errors in math functions} -body {
912    expr hypot(1.0 2.0)
913} -returnCodes error -match glob -result *
914test expr-old-34.5 {errors in math functions} -body {
915    expr hypot(1.0, 2.0
916} -returnCodes error -match glob -result *
917test expr-old-34.6 {errors in math functions} -body {
918    expr hypot(1.0 ,
919} -returnCodes error -match glob -result *
920test expr-old-34.7 {errors in math functions} -body {
921    list [catch {expr hypot(1.0)} msg] $msg
922} -match glob -result {1 {too few arguments for math function*}}
923test expr-old-34.8 {errors in math functions} -body {
924    list [catch {expr hypot(1.0, 2.0, 3.0)} msg] $msg
925} -match glob -result {1 {too many arguments for math function*}}
926test expr-old-34.9 {errors in math functions} {
927    list [catch {expr acos(-2.0)} msg] $msg $errorCode
928} {1 {domain error: argument not in valid range} {ARITH DOMAIN {domain error: argument not in valid range}}}
929test expr-old-34.10 {errors in math functions} {
930    list [catch {expr pow(-3, 1000001)} msg] $msg
931} {0 -Inf}
932test expr-old-34.11a {errors in math functions} !ieeeFloatingPoint {
933    list [catch {expr pow(3, 1000001)} msg] $msg $errorCode
934} {1 {floating-point value too large to represent} {ARITH OVERFLOW {floating-point value too large to represent}}}
935test expr-old-34.11b {errors in math functions} ieeeFloatingPoint {
936    list [catch {expr pow(3, 1000001)} msg] $msg
937} {0 Inf}
938test expr-old-34.12a {errors in math functions} !ieeeFloatingPoint {
939    list [catch {expr -14.0*exp(100000)} msg] $msg $errorCode
940} {1 {floating-point value too large to represent} {ARITH OVERFLOW {floating-point value too large to represent}}}
941test expr-old-34.12b {errors in math functions} ieeeFloatingPoint {
942    list [catch {expr -14.0*exp(100000)} msg] $msg
943} {0 -Inf}
944test expr-old-34.13 {errors in math functions} {
945    expr wide(1.0e30)
946} 5076964154930102272
947test expr-old-34.14 {errors in math functions} {
948    expr wide(-1.0e30)
949} -5076964154930102272
950test expr-old-34.15 {errors in math functions} {
951    expr round(1.0e30)
952} 1000000000000000019884624838656
953test expr-old-34.16 {errors in math functions} {
954    expr round(-1.0e30)
955} -1000000000000000019884624838656
956test expr-old-34.17 {errors in math functions} -constraints testmathfunctions \
957    -body {
958        list [catch {expr T1(4)} msg] $msg
959    } -match glob -result {1 {too many arguments for math function*}}
960
961test expr-old-36.1 {ExprLooksLikeInt procedure} -body {
962    expr 0o289
963} -returnCodes error -match glob -result {*invalid octal number*}
964test expr-old-36.2 {ExprLooksLikeInt procedure} {
965    set x 0o289
966    list [catch {expr {$x+1}} msg] $msg
967} {1 {can't use invalid octal number as operand of "+"}}
968test expr-old-36.3 {ExprLooksLikeInt procedure} {
969    list [catch {expr 0289.1} msg] $msg
970} {0 289.1}
971test expr-old-36.4 {ExprLooksLikeInt procedure} {
972    set x 0289.1
973    list [catch {expr {$x+1}} msg] $msg
974} {0 290.1}
975test expr-old-36.5 {ExprLooksLikeInt procedure} {
976    set x {  +22}
977    list [catch {expr {$x+1}} msg] $msg
978} {0 23}
979test expr-old-36.6 {ExprLooksLikeInt procedure} {
980    set x {     -22}
981    list [catch {expr {$x+1}} msg] $msg
982} {0 -21}
983test expr-old-36.7 {ExprLooksLikeInt procedure} {
984    list [catch {expr nan} msg] $msg
985} {1 {domain error: argument not in valid range}}
986test expr-old-36.8 {ExprLooksLikeInt procedure} {
987    list [catch {expr 78e1} msg] $msg
988} {0 780.0}
989test expr-old-36.9 {ExprLooksLikeInt procedure} {
990    list [catch {expr 24E1} msg] $msg
991} {0 240.0}
992test expr-old-36.10 {ExprLooksLikeInt procedure} -body {
993    expr 78e
994} -returnCodes error -match glob -result *
995
996# test for [Bug #542588]
997test expr-old-36.11 {ExprLooksLikeInt procedure} {
998    # define a "too large integer"; this one works also for 64bit arith
999    set x 665802003400000000000000
1000    expr {$x+1}
1001} 665802003400000000000001
1002
1003# tests for [Bug #587140]
1004test expr-old-36.12 {ExprLooksLikeInt procedure} {
1005    set x "10;"
1006    list [catch {expr {$x+1}} msg] $msg
1007} {1 {can't use non-numeric string as operand of "+"}}
1008test expr-old-36.13 {ExprLooksLikeInt procedure} {
1009    set x " +"
1010    list [catch {expr {$x+1}} msg] $msg
1011} {1 {can't use non-numeric string as operand of "+"}}
1012test expr-old-36.14 {ExprLooksLikeInt procedure} {
1013    set x "123456789012345678901234567890 "
1014    expr {$x+1}
1015} 123456789012345678901234567891
1016test expr-old-36.15 {ExprLooksLikeInt procedure} {
1017    set x "0o99 "
1018    list [catch {expr {$x+1}} msg] $msg
1019} {1 {can't use invalid octal number as operand of "+"}}
1020test expr-old-36.16 {ExprLooksLikeInt procedure} {
1021    set x " 0xffffffffffffffffffffffffffffffffffffff  "
1022    expr {$x+1}
1023} [expr 0x100000000000000000000000000000000000000]
1024
1025test expr-old-37.1 {Check that Tcl_ExprLong doesn't modify interpreter result if no error} testexprlong {
1026    testexprlong 4+1
1027} {This is a result: 5}
1028#Check for [Bug 1109484]
1029test expr-old-37.2 {Tcl_ExprLong handles wide ints gracefully} testexprlong {
1030    testexprlong wide(1)+2
1031} {This is a result: 3}
1032
1033test expr-old-37.3 {Tcl_ExprLong on the empty string} testexprlong {
1034    testexprlong ""
1035} {This is a result: 0}
1036test expr-old-37.4 {Tcl_ExprLong coerces doubles} testexprlong {
1037    testexprlong 3+.14159
1038} {This is a result: 3}
1039test expr-old-37.5 {Tcl_ExprLong handles overflows} {testexprlong longIs32bit} {
1040    testexprlong 0x80000000
1041} {This is a result: -2147483648}
1042test expr-old-37.6 {Tcl_ExprLong handles overflows} {testexprlong longIs32bit} {
1043    testexprlong 0xffffffff
1044} {This is a result: -1}
1045test expr-old-37.7 {Tcl_ExprLong handles overflows} \
1046    -constraints {testexprlong longIs32bit} \
1047    -match glob \
1048    -body {
1049        list [catch {testexprlong 0x100000000} result] $result
1050    } \
1051    -result {1 {integer value too large to represent*}}
1052test expr-old-37.8 {Tcl_ExprLong handles overflows} testexprlong {
1053    testexprlong -0x80000000
1054} {This is a result: -2147483648}
1055test expr-old-37.9 {Tcl_ExprLong handles overflows} {testexprlong longIs32bit} {
1056    testexprlong -0xffffffff
1057} {This is a result: 1}
1058test expr-old-37.10 {Tcl_ExprLong handles overflows} \
1059    -constraints {testexprlong longIs32bit} \
1060    -match glob \
1061    -body {
1062        list [catch {testexprlong -0x100000000} result] $result
1063    } \
1064    -result {1 {integer value too large to represent*}}
1065test expr-old-37.11 {Tcl_ExprLong handles overflows} {testexprlong longIs32bit}  {
1066    testexprlong 2147483648.
1067} {This is a result: -2147483648}
1068test expr-old-37.12 {Tcl_ExprLong handles overflows} {testexprlong longIs32bit} {
1069    testexprlong 4294967295.
1070} {This is a result: -1}
1071test expr-old-37.13 {Tcl_ExprLong handles overflows} \
1072    -constraints {testexprlong longIs32bit} \
1073    -match glob \
1074    -body {
1075        list [catch {testexprlong 4294967296.} result] $result
1076    } \
1077    -result {1 {integer value too large to represent*}}
1078test expr-old-37.14 {Tcl_ExprLong handles overflows} testexprlong {
1079    testexprlong -2147483648.
1080} {This is a result: -2147483648}
1081test expr-old-37.15 {Tcl_ExprLong handles overflows} {testexprlong longIs32bit} {
1082    testexprlong -4294967295.
1083} {This is a result: 1}
1084test expr-old-37.16 {Tcl_ExprLong handles overflows} \
1085    -constraints {testexprlong longIs32bit} \
1086    -match glob \
1087    -body {
1088        list [catch {testexprlong 4294967296.} result] $result
1089    } \
1090    -result {1 {integer value too large to represent*}}
1091
1092test expr-old-37.17 {Check that Tcl_ExprDouble doesn't modify interpreter result if no error} testexprdouble {
1093    testexprdouble 4.+1.
1094} {This is a result: 5.0}
1095#Check for [Bug 1109484]
1096test expr-old-37.18 {Tcl_ExprDouble on the empty string} testexprdouble {
1097    testexprdouble ""
1098} {This is a result: 0.0}
1099test expr-old-37.19 {Tcl_ExprDouble coerces wides} testexprdouble {
1100    testexprdouble 1[string repeat 0 17]
1101} {This is a result: 1e+17}
1102test expr-old-37.20 {Tcl_ExprDouble coerces bignums} testexprdouble {
1103    testexprdouble 1[string repeat 0 38]
1104} {This is a result: 1e+38}
1105test expr-old-37.21 {Tcl_ExprDouble handles overflows} testexprdouble {
1106    testexprdouble 17976931348623157[string repeat 0 292].
1107} {This is a result: 1.7976931348623157e+308}
1108test expr-old-37.22 {Tcl_ExprDouble handles overflows that look like int} \
1109    testexprdouble {
1110        testexprdouble 17976931348623157[string repeat 0 292]
1111    } {This is a result: 1.7976931348623157e+308}
1112test expr-old-37.23 {Tcl_ExprDouble handles overflows} \
1113    ieeeFloatingPoint&&testexprdouble {
1114        testexprdouble 17976931348623165[string repeat 0 292].
1115    } {This is a result: Inf}
1116test expr-old-37.24 {Tcl_ExprDouble handles overflows that look like int} \
1117    ieeeFloatingPoint&&testexprdouble {
1118        testexprdouble 17976931348623165[string repeat 0 292]
1119    } {This is a result: Inf}
1120test expr-old-37.25 {Tcl_ExprDouble and NaN} \
1121    {ieeeFloatingPoint testexprdouble} {
1122        list [catch {testexprdouble 0.0/0.0} result] $result
1123    } {1 {domain error: argument not in valid range}}
1124   
1125test expr-old-38.1 {Verify Tcl_ExprString's basic operation} -constraints {testexprstring} -body {
1126    list [testexprstring "1+4"] [testexprstring "2*3+4.2"] \
1127            [catch {testexprstring "1+"} msg] $msg
1128} -match glob -result {5 10.2 1 *}
1129test expr-old-38.2 {Tcl_ExprString} testexprstring {
1130    # This one is "magical"
1131    testexprstring {}
1132} 0
1133test expr-old-38.3 {Tcl_ExprString} -constraints testexprstring -body {
1134    testexprstring { }
1135} -returnCodes error -match glob -result *
1136
1137#
1138# Test for bug #908375: rounding numbers that do not fit in a
1139# long but do fit in a wide
1140#
1141
1142test expr-old-39.1 {Rounding with wide result} {
1143    set x 1.0e10
1144    set y [expr $x + 0.1]
1145    catch {
1146        set x [list [expr {$x == round($y)}] [expr $x == -round(-$y)]]
1147    }
1148    set x
1149} {1 1}
1150unset -nocomplain x y
1151
1152#
1153# TIP #255 min and max math functions
1154#
1155
1156test expr-old-40.1 {min math function} -body {
1157    expr {min(0)}
1158} -result 0
1159test expr-old-40.2 {min math function} -body {
1160    expr {min(0.0)}
1161} -result 0.0
1162test expr-old-40.3 {min math function} -body {
1163    list [catch {expr {min()}} msg] $msg
1164} -result {1 {too few arguments to math function "min"}}
1165test expr-old-40.4 {min math function} -body {
1166    expr {min(wide(-1) << 30, 4.5, -10)}
1167} -result [expr {wide(-1) << 30}]
1168test expr-old-40.5 {min math function} -body {
1169    expr {min("a", 0)}
1170} -returnCodes error -match glob -result *
1171test expr-old-40.6 {min math function} -body {
1172    expr {min(300, "0xFF")}
1173} -result 255
1174
1175test expr-old-41.1 {max math function} -body {
1176    expr {max(0)}
1177} -result 0
1178test expr-old-41.2 {max math function} -body {
1179    expr {max(0.0)}
1180} -result 0.0
1181test expr-old-41.3 {max math function} -body {
1182    list [catch {expr {max()}} msg] $msg
1183} -result {1 {too few arguments to math function "max"}}
1184test expr-old-41.4 {max math function} -body {
1185    expr {max(wide(1) << 30, 4.5, -10)}
1186} -result [expr {wide(1) << 30}]
1187test expr-old-41.5 {max math function} -body {
1188    expr {max("a", 0)}
1189} -returnCodes error -match glob -result *
1190test expr-old-41.6 {max math function} -body {
1191    expr {max(200, "0xFF")}
1192} -result 255
1193
1194# Special test for Pentium arithmetic bug of 1994:
1195
1196if {(4195835.0 - (4195835.0/3145727.0)*3145727.0) == 256.0} {
1197    puts "Warning: this machine contains a defective Pentium processor"
1198    puts "that performs arithmetic incorrectly.  I recommend that you"
1199    puts "call Intel customer service immediately at 1-800-628-8686"
1200    puts "to request a replacement processor."
1201}
1202
1203# cleanup
1204::tcltest::cleanupTests
1205return
1206
1207# Local Variables:
1208# mode: tcl
1209# End:
Note: See TracBrowser for help on using the repository browser.