Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/tcl8.5.2/tests/compExpr-old.test @ 42

Last change on this file since 42 was 25, checked in by landauf, 18 years ago

added tcl to libs

File size: 36.2 KB
Line 
1# Commands covered: expr
2#
3# This file contains the original set of tests for the compilation (and
4# indirectly execution) of Tcl's expr command. 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) 1996-1997 Sun Microsystems, Inc.
10# Copyright (c) 1998-1999 by Scriptics Corporation.
11#
12# See the file "license.terms" for information on usage and redistribution
13# of this file, and for a DISCLAIMER OF ALL WARRANTIES.
14#
15# RCS: @(#) $Id: compExpr-old.test,v 1.23 2007/12/13 15:26:06 dgp Exp $
16
17if {[lsearch [namespace children] ::tcltest] == -1} {
18    package require tcltest 2
19    namespace import -force ::tcltest::*
20}
21
22if {[catch {expr T1()} msg] && $msg eq {invalid command name "tcl::mathfunc::T1"}} {
23    testConstraint testmathfunctions 0
24} else {
25    testConstraint testmathfunctions 1
26}
27
28# Big test for correct ordering of data in [expr]
29
30proc testIEEE {} {
31    variable ieeeValues
32    binary scan [binary format dd -1.0 1.0] c* c
33    switch -exact -- $c {
34        {0 0 0 0 0 0 -16 -65 0 0 0 0 0 0 -16 63} {
35            # little endian
36            binary scan \x00\x00\x00\x00\x00\x00\xf0\xff d \
37                ieeeValues(-Infinity)
38            binary scan \x00\x00\x00\x00\x00\x00\xf0\xbf d \
39                ieeeValues(-Normal)
40            binary scan \x00\x00\x00\x00\x00\x00\x08\x80 d \
41                ieeeValues(-Subnormal)
42            binary scan \x00\x00\x00\x00\x00\x00\x00\x80 d \
43                ieeeValues(-0)
44            binary scan \x00\x00\x00\x00\x00\x00\x00\x00 d \
45                ieeeValues(+0)
46            binary scan \x00\x00\x00\x00\x00\x00\x08\x00 d \
47                ieeeValues(+Subnormal)
48            binary scan \x00\x00\x00\x00\x00\x00\xf0\x3f d \
49                ieeeValues(+Normal)
50            binary scan \x00\x00\x00\x00\x00\x00\xf0\x7f d \
51                ieeeValues(+Infinity)
52            binary scan \x00\x00\x00\x00\x00\x00\xf8\x7f d \
53                ieeeValues(NaN)
54            set ieeeValues(littleEndian) 1
55            return 1
56        }
57        {-65 -16 0 0 0 0 0 0 63 -16 0 0 0 0 0 0} {
58            binary scan \xff\xf0\x00\x00\x00\x00\x00\x00 d \
59                ieeeValues(-Infinity)
60            binary scan \xbf\xf0\x00\x00\x00\x00\x00\x00 d \
61                ieeeValues(-Normal)
62            binary scan \x80\x08\x00\x00\x00\x00\x00\x00 d \
63                ieeeValues(-Subnormal)
64            binary scan \x80\x00\x00\x00\x00\x00\x00\x00 d \
65                ieeeValues(-0)
66            binary scan \x00\x00\x00\x00\x00\x00\x00\x00 d \
67                ieeeValues(+0)
68            binary scan \x00\x08\x00\x00\x00\x00\x00\x00 d \
69                ieeeValues(+Subnormal)
70            binary scan \x3f\xf0\x00\x00\x00\x00\x00\x00 d \
71                ieeeValues(+Normal)
72            binary scan \x7f\xf0\x00\x00\x00\x00\x00\x00 d \
73                ieeeValues(+Infinity)
74            binary scan \x7f\xf8\x00\x00\x00\x00\x00\x00 d \
75                ieeeValues(NaN)
76            set ieeeValues(littleEndian) 0
77            return 1
78        }
79        default {
80            return 0
81        }
82    }
83}
84testConstraint ieeeFloatingPoint [testIEEE]
85
86testConstraint longIs32bit [expr {int(0x80000000) < 0}]
87testConstraint longIs64bit [expr {int(0x8000000000000000) < 0}]
88
89# procedures used below
90
91proc put_hello_char {c} {
92    global a
93    append a [format %c $c]
94    return $c
95}
96proc hello_world {} {
97    global a
98    set a ""
99    set L1 [set l0 [set h_1 [set q 0]]]
100    for {put_hello_char [expr [put_hello_char [expr [set h 7]*10+2]]+29]} {$l0?[put_hello_char $l0]
101        :!$h_1} {put_hello_char $ll;expr {$L1==2?[set ll [expr 32+0-0+[set bar 0]]]:0}} {expr {[incr L1]==[expr 1+([string length "abc"]-[string length "abc"])]
102        ?[set ll [set l0 [expr 54<<1]]]:$ll==108&&$L1<3?
103        [incr ll [expr 1|1<<1]; set ll $ll; set ll $ll; set ll $ll; set ll $ll; set l0 [expr ([string length "abc"]-[string length "abc"])+([string length "abc"]-[string length "abc"])-([string length "abc"]-[string length "abc"])+([string length "abc"]-[string length "abc"])]; set l0; set l0 $l0; set l0; set l0]:$L1==4&&$ll==32?[set ll [expr 19+$h1+([string length "abc"]-[string length "abc"])-([string length "abc"]-[string length "abc"])+([string length "abc"]-[string length "abc"])-([string length "abc"]-[string length "abc"])+[set foo [expr ([string length "abc"]-[string length "abc"])+([string length "abc"]-[string length "abc"])+([string length "abc"]-[string length "abc"])]]]]
104        :[set q [expr $q-$h1+([string length "abc"]-[string length "abc"])-([string length "abc"]-[string length "abc"])]]};expr {$L1==5?[incr ll -8; set ll $ll; set ll]:$q&&$h1&&1};expr {$L1==4+2
105        ?[incr ll 3]:[expr ([string length "abc"]-[string length "abc"])+1]};expr {$ll==($h<<4)+2+0&&$L1!=6?[incr ll -6]:[set h1 [expr 100+([string length "abc"]-[string length "abc"])-([string length "abc"]-[string length "abc"])]]}
106        expr {$L1!=1<<3?[incr q [expr ([string length "abc"]-[string length "abc"])-1]]:[set h_1 [set ll $h1]]}
107    }
108    set a
109}
110
111proc 12days {a b c} {
112    global xxx
113    expr {1<$a?[expr {$a<3?[12days -79 -13 [string range $c [12days -87 \
114        [expr 1-$b] [string range $c [12days -86 0 [string range $c 1 end]] \
115        end]] end]]:1};expr {$a<$b?[12days [expr $a+1] $b $c]:3};expr {[12days \
116        -94 [expr $a-27] $c]&&$a==2?$b<13?[12days 2 [expr $b+1] "%s %d %d\n"]:9
117        :16}]:$a<0?$a<-72?[12days $b $a "@n'+,#'/*\{\}w+/w#cdnr/+,\{\}r/*de\}+,/*\{*+,/w\{%+,/w#q#n+,/#\{l+,/n\{n+,/+#n+,/#;#q#n+,/+k#;*+,/'r :'d*'3,\}\{w+K w'K:'+\}e#';dq#'l q#'+d'K#!/+k#;q#'r\}eKK#\}w'r\}eKK\{nl\]'/#;#q#n')\{)#\}w')\{)\{nl\]'/+#n';d\}rw' i;# )\{nl\]!/n\{n#'; r\{#w'r nc\{nl\]'/#\{l,+'K \{rw' iK\{;\[\{nl\]'/w#q#n'wk nw' iwk\{KK\{nl\]!/w\{%'l##w#' i; :\{nl\]'/*\{q#'ld;r'\}\{nlwb!/*de\}'c ;;\{nl'-\{\}rw\]'/+,\}##'*\}#nc,',#nw\]'/+kd'+e\}+;#'rdq#w! nr'/ ') \}+\}\{rl#'\{n' ')# \}'+\}##(!!/"]
118        :$a<-50?[string compare [format %c $b] [string index $c 0]]==0?[append \
119        xxx [string index $c 31];scan [string index $c 31] %c x;set x]
120        :[12days -65 $b [string range $c 1 end]]:[12days [expr ([string compare \
121        [string index $c 0] "/"]==0)+$a] $b [string range $c 1 end]]:0<$a
122        ?[12days 2 2 "%s"]:[string compare [string index $c 0] "/"]==0||
123        [12days 0 [12days -61 [scan [string index $c 0] %c x; set x] \
124        "!ek;dc i@bK'(q)-\[w\]*%n+r3#l,\{\}:\nuwloca-O;m .vpbks,fxntdCeghiry"] \
125        [string range $c 1 end]]}
126}
127proc do_twelve_days {} {
128    global xxx
129    set xxx ""
130    12days 1 1 1
131    set result [string length $xxx]
132    unset xxx
133    return $result
134}
135
136# start of tests
137
138catch {unset a b i x}
139
140test compExpr-old-1.1 {TclCompileExprCmd: no expression} {
141    list [catch {expr  } msg] $msg
142} {1 {wrong # args: should be "expr arg ?arg ...?"}}
143test compExpr-old-1.2 {TclCompileExprCmd: one expression word} {
144    expr -25
145} -25
146test compExpr-old-1.3 {TclCompileExprCmd: two expression words} {
147    expr -8.2   -6
148} -14.2
149test compExpr-old-1.4 {TclCompileExprCmd: five expression words} {
150    expr 20 - 5 +10 -7
151} 18
152test compExpr-old-1.5 {TclCompileExprCmd: quoted expression word} {
153    expr "0005"
154} 5
155test compExpr-old-1.6 {TclCompileExprCmd: quoted expression word} {
156    catch {expr "0005"zxy} msg
157    set msg
158} {extra characters after close-quote}
159test compExpr-old-1.7 {TclCompileExprCmd: expression word in braces} {
160    expr {-0005}
161} -5
162test compExpr-old-1.8 {TclCompileExprCmd: expression word in braces} {
163    expr {{-0x1234}}
164} -4660
165test compExpr-old-1.9 {TclCompileExprCmd: expression word in braces} {
166    catch {expr {-0005}foo} msg
167    set msg
168} {extra characters after close-brace}
169test compExpr-old-1.10 {TclCompileExprCmd: other expression word in braces} {
170    expr 4*[llength "6 2"]
171} 8
172test compExpr-old-1.11 {TclCompileExprCmd: expression word terminated by ;} {
173    expr 4*[llength "6 2"];
174} 8
175test compExpr-old-1.12 {TclCompileExprCmd: inlined expr (in "catch") inside other catch} {
176    set a xxx
177    catch {
178        # Might not be a number
179        set a [expr 10*$a]
180    }
181} 1
182test compExpr-old-1.13 {TclCompileExprCmd: second level of substitutions in expr not in braces with single var reference} {
183    set a xxx
184    set x 27;  set bool {$x};  if $bool {set a foo}
185    set a
186} foo
187test compExpr-old-1.14 {TclCompileExprCmd: second level of substitutions in expr with comparison as top-level operator} {
188    set a xxx
189    set x 2;  set b {$x};  set a [expr $b == 2]
190    set a
191} 1
192
193test compExpr-old-2.1 {TclCompileExpr: are builtin functions registered?} {
194    expr double(5*[llength "6 2"])
195} 10.0
196test compExpr-old-2.2 {TclCompileExpr: error in expr} -body {
197    expr 2***3
198} -returnCodes error -match glob -result *
199test compExpr-old-2.3 {TclCompileExpr: junk after legal expr} -body {
200    expr 7*[llength "a b"]foo
201} -returnCodes error -match glob -result *
202test compExpr-old-2.4 {TclCompileExpr: numeric expr string rep == formatted int rep} {
203    expr {0001}
204} 1
205
206test compExpr-old-3.1 {CompileCondExpr: just lor expr} {expr 3||0} 1
207test compExpr-old-3.2 {CompileCondExpr: error in lor expr} -body {
208    expr x||3
209} -returnCodes error -match glob -result *
210test compExpr-old-3.3 {CompileCondExpr: test true arm} {expr 3>2?44:66} 44
211test compExpr-old-3.4 {CompileCondExpr: error compiling true arm} -body {
212    expr 3>2?2***3:66
213} -returnCodes error -match glob -result *
214test compExpr-old-3.5 {CompileCondExpr: test false arm} {expr 2>3?44:66} 66
215test compExpr-old-3.6 {CompileCondExpr: error compiling false arm} -body {
216    expr 2>3?44:2***3
217} -returnCodes error -match glob -result *
218test compExpr-old-3.7 {CompileCondExpr: long arms & nested cond exprs} {
219    hello_world
220} {Hello world}
221test compExpr-old-3.8 {CompileCondExpr: long arms & nested cond exprs} unix {
222    # Fails with a stack overflow on threaded Windows builds
223    do_twelve_days
224} 2358
225
226test compExpr-old-4.1 {CompileLorExpr: just land expr} {expr 1.3&&3.3} 1
227test compExpr-old-4.2 {CompileLorExpr: error in land expr} -body {
228    expr x&&3
229} -returnCodes error -match glob -result *
230test compExpr-old-4.3 {CompileLorExpr: simple lor exprs} {expr 0||1.0} 1
231test compExpr-old-4.4 {CompileLorExpr: simple lor exprs} {expr 3.0||0.0} 1
232test compExpr-old-4.5 {CompileLorExpr: simple lor exprs} {expr 0||0||1} 1
233test compExpr-old-4.6 {CompileLorExpr: error compiling lor arm} -body {
234    expr 2***3||4.0
235} -returnCodes error -match glob -result *
236test compExpr-old-4.7 {CompileLorExpr: error compiling lor arm} -body {
237    expr 1.3||2***3
238} -returnCodes error -match glob -result *
239test compExpr-old-4.8 {CompileLorExpr: error compiling lor arms} {
240    list [catch {expr {"a"||"b"}} msg] $msg
241} {1 {expected boolean value but got "a"}}
242test compExpr-old-4.9 {CompileLorExpr: long lor arm} {
243    set a "abcdefghijkl"
244    set i 7
245    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]]}
246} 1
247
248test compExpr-old-5.1 {CompileLandExpr: just bitor expr} {expr 7|0x13} 23
249test compExpr-old-5.2 {CompileLandExpr: error in bitor expr} -body {
250    expr x|3
251} -returnCodes error -match glob -result *
252test compExpr-old-5.3 {CompileLandExpr: simple land exprs} {expr 0&&1.0} 0
253test compExpr-old-5.4 {CompileLandExpr: simple land exprs} {expr 0&&0} 0
254test compExpr-old-5.5 {CompileLandExpr: simple land exprs} {expr 3.0&&1.2} 1
255test compExpr-old-5.6 {CompileLandExpr: simple land exprs} {expr 1&&1&&2} 1
256test compExpr-old-5.7 {CompileLandExpr: error compiling land arm} -body {
257    expr 2***3&&4.0
258} -returnCodes error -match glob -result *
259test compExpr-old-5.8 {CompileLandExpr: error compiling land arm} -body {
260    expr 1.3&&2***3
261} -returnCodes error -match glob -result *
262test compExpr-old-5.9 {CompileLandExpr: error compiling land arm} {
263    list [catch {expr {"a"&&"b"}} msg] $msg
264} {1 {expected boolean value but got "a"}}
265test compExpr-old-5.10 {CompileLandExpr: long land arms} {
266    set a "abcdefghijkl"
267    set i 7
268    expr {[string compare [format %c 103] [string index $a $i]]^[string compare [format %c 105] [string index $a $i]]^[string compare [format %c 103] [string index $a $i]]^[string compare [format %c 105] [string index $a $i]]^[string compare [format %c 103] [string index $a $i]]^[string compare [format %c 105] [string index $a $i]]^[string compare [format %c 103] [string index $a $i]]^[string compare [format %c 105] [string index $a $i]]^[string compare [format %c 103] [string index $a $i]]^[string compare [format %c 105] [string index $a $i]]^[string compare [format %c 103] [string index $a $i]]^[string compare [format %c 105] [string index $a $i]]^[string compare [format %c 103] [string index $a $i]]^[string compare [format %c 105] [string index $a $i]]^[string compare [format %c 103] [string index $a $i]]^[string compare [format %c 105] [string index $a $i]]^[string compare [format %c 103] [string index $a $i]]^[string compare [format %c 105] [string index $a $i]] && [string compare [format %c 103] [string index $a $i]]^[string compare [format %c 105] [string index $a $i]]^[string compare [format %c 103] [string index $a $i]]^[string compare [format %c 105] [string index $a $i]]^[string compare [format %c 103] [string index $a $i]]^[string compare [format %c 105] [string index $a $i]]^[string compare [format %c 103] [string index $a $i]]^[string compare [format %c 105] [string index $a $i]]^[string compare [format %c 103] [string index $a $i]]^[string compare [format %c 105] [string index $a $i]]^[string compare [format %c 103] [string index $a $i]]^[string compare [format %c 105] [string index $a $i]]^[string compare [format %c 103] [string index $a $i]]^[string compare [format %c 105] [string index $a $i]]^[string compare [format %c 103] [string index $a $i]]^[string compare [format %c 105] [string index $a $i]]^[string compare [format %c 103] [string index $a $i]]^[string compare [format %c 105] [string index $a $i]] && [string compare [format %c 103] [string index $a $i]]^[string compare [format %c 105] [string index $a $i]]^[string compare [format %c 103] [string index $a $i]]^[string compare [format %c 105] [string index $a $i]]^[string compare [format %c 103] [string index $a $i]]^[string compare [format %c 105] [string index $a $i]]^[string compare [format %c 103] [string index $a $i]]^[string compare [format %c 105] [string index $a $i]]^[string compare [format %c 103] [string index $a $i]]^[string compare [format %c 105] [string index $a $i]]^[string compare [format %c 103] [string index $a $i]]^[string compare [format %c 105] [string index $a $i]]^[string compare [format %c 103] [string index $a $i]]^[string compare [format %c 105] [string index $a $i]]^[string compare [format %c 103] [string index $a $i]]^[string compare [format %c 105] [string index $a $i]]^[string compare [format %c 103] [string index $a $i]]^[string compare [format %c 105] [string index $a $i]] && [string compare [format %c 103] [string index $a $i]]^[string compare [format %c 105] [string index $a $i]]^[string compare [format %c 103] [string index $a $i]]^[string compare [format %c 105] [string index $a $i]]^[string compare [format %c 103] [string index $a $i]]^[string compare [format %c 105] [string index $a $i]]^[string compare [format %c 103] [string index $a $i]]^[string compare [format %c 105] [string index $a $i]]^[string compare [format %c 103] [string index $a $i]]^[string compare [format %c 105] [string index $a $i]]^[string compare [format %c 103] [string index $a $i]]^[string compare [format %c 105] [string index $a $i]]^[string compare [format %c 103] [string index $a $i]]^[string compare [format %c 105] [string index $a $i]]^[string compare [format %c 103] [string index $a $i]]^[string compare [format %c 105] [string index $a $i]]^[string compare [format %c 103] [string index $a $i]]^[string compare [format %c 105] [string index $a $i]]}
269} 1
270
271test compExpr-old-6.1 {CompileBitXorExpr: just bitand expr} {expr 7&0x13} 3
272test compExpr-old-6.2 {CompileBitXorExpr: error in bitand expr} -body {
273    expr x|3
274} -returnCodes error -match glob -result *
275test compExpr-old-6.3 {CompileBitXorExpr: simple bitxor exprs} {expr 7^0x13} 20
276test compExpr-old-6.4 {CompileBitXorExpr: simple bitxor exprs} {expr 3^0x10} 19
277test compExpr-old-6.5 {CompileBitXorExpr: simple bitxor exprs} {expr 0^7} 7
278test compExpr-old-6.6 {CompileBitXorExpr: simple bitxor exprs} {expr -1^7} -8
279test compExpr-old-6.7 {CompileBitXorExpr: error compiling bitxor arm} -body {
280    expr 2***3|6
281} -returnCodes error -match glob -result *
282test compExpr-old-6.8 {CompileBitXorExpr: error compiling bitxor arm} -body {
283    expr 2^x
284} -returnCodes error -match glob -result *
285test compExpr-old-6.9 {CompileBitXorExpr: runtime error in bitxor arm} {
286    list [catch {expr {24.0^3}} msg] $msg
287} {1 {can't use floating-point value as operand of "^"}}
288test compExpr-old-6.10 {CompileBitXorExpr: runtime error in bitxor arm} {
289    list [catch {expr {"a"^"b"}} msg] $msg
290} {1 {can't use non-numeric string as operand of "^"}}
291
292test compExpr-old-7.1 {CompileBitAndExpr: just equality expr} {expr 3==2} 0
293test compExpr-old-7.2 {CompileBitAndExpr: just equality expr} {expr 2.0==2} 1
294test compExpr-old-7.3 {CompileBitAndExpr: just equality expr} {expr 3.2!=2.2} 1
295test compExpr-old-7.4 {CompileBitAndExpr: just equality expr} {expr {"abc" == "abd"}} 0
296test compExpr-old-7.5 {CompileBitAndExpr: error in equality expr} -body {
297    expr x==3
298} -returnCodes error -match glob -result *
299test compExpr-old-7.6 {CompileBitAndExpr: simple bitand exprs} {expr 7&0x13} 3
300test compExpr-old-7.7 {CompileBitAndExpr: simple bitand exprs} {expr 0xf2&0x53} 82
301test compExpr-old-7.8 {CompileBitAndExpr: simple bitand exprs} {expr 3&6} 2
302test compExpr-old-7.9 {CompileBitAndExpr: simple bitand exprs} {expr -1&-7} -7
303test compExpr-old-7.10 {CompileBitAndExpr: error compiling bitand arm} -body {
304    expr 2***3&6
305} -returnCodes error -match glob -result *
306test compExpr-old-7.11 {CompileBitAndExpr: error compiling bitand arm} -body {
307    expr 2&x
308} -returnCodes error -match glob -result *
309test compExpr-old-7.12 {CompileBitAndExpr: runtime error in bitand arm} {
310    list [catch {expr {24.0&3}} msg] $msg
311} {1 {can't use floating-point value as operand of "&"}}
312test compExpr-old-7.13 {CompileBitAndExpr: runtime error in bitand arm} {
313    list [catch {expr {"a"&"b"}} msg] $msg
314} {1 {can't use non-numeric string as operand of "&"}}
315
316test compExpr-old-8.1 {CompileEqualityExpr: just relational expr} {expr 3>=2} 1
317test compExpr-old-8.2 {CompileEqualityExpr: just relational expr} {expr 2<=2.1} 1
318test compExpr-old-8.3 {CompileEqualityExpr: just relational expr} {expr 3.2>"2.2"} 1
319test compExpr-old-8.4 {CompileEqualityExpr: just relational expr} {expr {"0y"<"0x12"}} 0
320test compExpr-old-8.5 {CompileEqualityExpr: error in relational expr} -body {
321    expr x>3
322} -returnCodes error -match glob -result *
323test compExpr-old-8.6 {CompileEqualityExpr: simple equality exprs} {expr 7==0x13} 0
324test compExpr-old-8.7 {CompileEqualityExpr: simple equality exprs} {expr -0xf2!=0x53} 1
325test compExpr-old-8.8 {CompileEqualityExpr: simple equality exprs} {expr {"12398712938788234-1298379" != ""}} 1
326test compExpr-old-8.9 {CompileEqualityExpr: simple equality exprs} {expr -1!="abc"} 1
327test compExpr-old-8.10 {CompileEqualityExpr: error compiling equality arm} -body {
328    expr 2***3==6
329} -returnCodes error -match glob -result *
330test compExpr-old-8.11 {CompileEqualityExpr: error compiling equality arm} -body {
331    expr 2!=x
332} -returnCodes error -match glob -result *
333
334
335test compExpr-old-9.1 {CompileRelationalExpr: just shift expr} {expr 3<<2} 12
336test compExpr-old-9.2 {CompileRelationalExpr: just shift expr} {expr 0xff>>2} 63
337test compExpr-old-9.3 {CompileRelationalExpr: just shift expr} {expr -1>>2} -1
338test compExpr-old-9.4 {CompileRelationalExpr: just shift expr} {expr {1<<3}} 8
339
340# The following test is different for 32-bit versus 64-bit
341# architectures because LONG_MIN is different
342
343test compExpr-old-9.5a {CompileRelationalExpr: shift expr producing LONG_MIN} longIs64bit {
344    expr {int(1<<63)}
345} -9223372036854775808
346test compExpr-old-9.5b {CompileRelationalExpr: shift expr producing LONG_MIN} longIs32bit {
347    expr {int(1<<31)}
348} -2147483648
349
350test compExpr-old-9.6 {CompileRelationalExpr: error in shift expr} -body {
351    expr x>>3
352} -returnCodes error -match glob -result *
353test compExpr-old-9.7 {CompileRelationalExpr: simple relational exprs} {expr 0xff>=+0x3} 1
354test compExpr-old-9.8 {CompileRelationalExpr: simple relational exprs} {expr -0xf2<0x3} 1
355test compExpr-old-9.9 {CompileRelationalExpr: error compiling relational arm} -body {
356    expr 2***3>6
357} -returnCodes error -match glob -result *
358test compExpr-old-9.10 {CompileRelationalExpr: error compiling relational arm} -body {
359    expr 2<x
360} -returnCodes error -match glob -result *
361
362test compExpr-old-10.1 {CompileShiftExpr: just add expr} {expr 4+-2} 2
363test compExpr-old-10.2 {CompileShiftExpr: just add expr} {expr 0xff-2} 253
364test compExpr-old-10.3 {CompileShiftExpr: just add expr} {expr -1--2} 1
365test compExpr-old-10.4 {CompileShiftExpr: just add expr} {expr 1-0o123} -82
366test compExpr-old-10.5 {CompileShiftExpr: error in add expr} -body {
367    expr x+3
368} -returnCodes error -match glob -result *
369test compExpr-old-10.6 {CompileShiftExpr: simple shift exprs} {expr 0xff>>0x3} 31
370test compExpr-old-10.7 {CompileShiftExpr: simple shift exprs} {expr -0xf2<<0x3} -1936
371test compExpr-old-10.8 {CompileShiftExpr: error compiling shift arm} -body {
372    expr 2***3>>6
373} -returnCodes error -match glob -result *
374test compExpr-old-10.9 {CompileShiftExpr: error compiling shift arm} -body {
375    expr 2<<x
376} -returnCodes error -match glob -result *
377test compExpr-old-10.10 {CompileShiftExpr: runtime error} {
378    list [catch {expr {24.0>>43}} msg] $msg
379} {1 {can't use floating-point value as operand of ">>"}}
380test compExpr-old-10.11 {CompileShiftExpr: runtime error} {
381    list [catch {expr {"a"<<"b"}} msg] $msg
382} {1 {can't use non-numeric string as operand of "<<"}}
383
384test compExpr-old-11.1 {CompileAddExpr: just multiply expr} {expr 4*-2} -8
385test compExpr-old-11.2 {CompileAddExpr: just multiply expr} {expr 0xff%2} 1
386test compExpr-old-11.3 {CompileAddExpr: just multiply expr} {expr -1/2} -1
387test compExpr-old-11.4 {CompileAddExpr: just multiply expr} {expr 7891%0o123} 6
388test compExpr-old-11.5 {CompileAddExpr: error in multiply expr} -body {
389    expr x*3
390} -returnCodes error -match glob -result *
391test compExpr-old-11.6 {CompileAddExpr: simple add exprs} {expr 0xff++0x3} 258
392test compExpr-old-11.7 {CompileAddExpr: simple add exprs} {expr -0xf2--0x3} -239
393test compExpr-old-11.8 {CompileAddExpr: error compiling add arm} -body {
394    expr 2***3+6
395} -returnCodes error -match glob -result *
396test compExpr-old-11.9 {CompileAddExpr: error compiling add arm} -body {
397    expr 2-x
398} -returnCodes error -match glob -result *
399test compExpr-old-11.10 {CompileAddExpr: runtime error} {
400    list [catch {expr {24.0+"xx"}} msg] $msg
401} {1 {can't use non-numeric string as operand of "+"}}
402test compExpr-old-11.11 {CompileAddExpr: runtime error} {
403    list [catch {expr {"a"-"b"}} msg] $msg
404} {1 {can't use non-numeric string as operand of "-"}}
405test compExpr-old-11.12 {CompileAddExpr: runtime error} {
406    list [catch {expr {3/0}} msg] $msg
407} {1 {divide by zero}}
408test compExpr-old-11.13a {CompileAddExpr: runtime error} ieeeFloatingPoint {
409    list [catch {expr {2.3/0.0}} msg] $msg
410} {0 Inf}
411test compExpr-old-11.13b {CompileAddExpr: runtime error} !ieeeFloatingPoint {
412    list [catch {expr {2.3/0.0}} msg] $msg
413} {1 {divide by zero}}
414
415test compExpr-old-12.1 {CompileMultiplyExpr: just unary expr} {expr ~4} -5
416test compExpr-old-12.2 {CompileMultiplyExpr: just unary expr} {expr --5} 5
417test compExpr-old-12.3 {CompileMultiplyExpr: just unary expr} {expr !27} 0
418test compExpr-old-12.4 {CompileMultiplyExpr: just unary expr} {expr ~0xff00ff} -16711936
419test compExpr-old-12.5 {CompileMultiplyExpr: error in unary expr} -body {
420    expr ~x
421} -returnCodes error -match glob -result *
422test compExpr-old-12.6 {CompileMultiplyExpr: simple multiply exprs} {expr 0xff*0x3} 765
423test compExpr-old-12.7 {CompileMultiplyExpr: simple multiply exprs} {expr -0xf2%-0x3} -2
424test compExpr-old-12.8 {CompileMultiplyExpr: error compiling multiply arm} -body {
425    expr 2*3%%6
426} -returnCodes error -match glob -result *
427test compExpr-old-12.9 {CompileMultiplyExpr: error compiling multiply arm} -body {
428    expr 2*x
429} -returnCodes error -match glob -result *
430test compExpr-old-12.10 {CompileMultiplyExpr: runtime error} {
431    list [catch {expr {24.0*"xx"}} msg] $msg
432} {1 {can't use non-numeric string as operand of "*"}}
433test compExpr-old-12.11 {CompileMultiplyExpr: runtime error} {
434    list [catch {expr {"a"/"b"}} msg] $msg
435} {1 {can't use non-numeric string as operand of "/"}}
436
437test compExpr-old-13.1 {CompileUnaryExpr: unary exprs} {expr -0xff} -255
438test compExpr-old-13.2 {CompileUnaryExpr: unary exprs} {expr +0o00123} 83
439test compExpr-old-13.3 {CompileUnaryExpr: unary exprs} {expr +--++36} 36
440test compExpr-old-13.4 {CompileUnaryExpr: unary exprs} {expr !2} 0
441test compExpr-old-13.5 {CompileUnaryExpr: unary exprs} {expr +--+-62.0} -62.0
442test compExpr-old-13.6 {CompileUnaryExpr: unary exprs} {expr !0.0} 1
443test compExpr-old-13.7 {CompileUnaryExpr: unary exprs} {expr !0xef} 0
444test compExpr-old-13.8 {CompileUnaryExpr: error compiling unary expr} -body {
445    expr ~x
446} -returnCodes error -match glob -result *
447test compExpr-old-13.9 {CompileUnaryExpr: error compiling unary expr} -body {
448    expr !1.x
449    set msg
450} -returnCodes error -match glob -result *
451test compExpr-old-13.10 {CompileUnaryExpr: runtime error} {
452    list [catch {expr {~"xx"}} msg] $msg
453} {1 {can't use non-numeric string as operand of "~"}}
454test compExpr-old-13.11 {CompileUnaryExpr: runtime error} {
455    list [catch {expr ~4.0} msg] $msg
456} {1 {can't use floating-point value as operand of "~"}}
457test compExpr-old-13.12 {CompileUnaryExpr: just primary expr} {expr 0x123} 291
458test compExpr-old-13.13 {CompileUnaryExpr: just primary expr} {
459    set a 27
460    expr $a
461} 27
462test compExpr-old-13.14 {CompileUnaryExpr: just primary expr} {
463    expr double(27)
464} 27.0
465test compExpr-old-13.15 {CompileUnaryExpr: just primary expr} {expr "123"} 123
466test compExpr-old-13.16 {CompileUnaryExpr: error in primary expr} {
467    catch {expr [set]} msg
468    set msg
469} {wrong # args: should be "set varName ?newValue?"}
470test compExpr-old-14.1 {CompilePrimaryExpr: literal primary} {expr 1} 1
471test compExpr-old-14.2 {CompilePrimaryExpr: literal primary} {expr 123} 123
472test compExpr-old-14.3 {CompilePrimaryExpr: literal primary} {expr 0xff} 255
473test compExpr-old-14.4 {CompilePrimaryExpr: literal primary} {expr 0o0010} 8
474test compExpr-old-14.5 {CompilePrimaryExpr: literal primary} {expr 62.0} 62.0
475test compExpr-old-14.6 {CompilePrimaryExpr: literal primary} {
476    expr 3.1400000
477} 3.14
478test compExpr-old-14.7 {CompilePrimaryExpr: literal primary} {expr {{abcde}<{abcdef}}} 1
479test compExpr-old-14.8 {CompilePrimaryExpr: literal primary} {expr {{abc\
480def} < {abcdef}}} 1
481test compExpr-old-14.9 {CompilePrimaryExpr: literal primary} {expr {{abc\tde} > {abc\tdef}}} 0
482test compExpr-old-14.10 {CompilePrimaryExpr: literal primary} {expr {{123}}} 123
483test compExpr-old-14.11 {CompilePrimaryExpr: var reference primary} {
484    set i 789
485    list [expr {$i}] [expr $i]
486} {789 789}
487test compExpr-old-14.12 {CompilePrimaryExpr: var reference primary} {
488    set i {789}    ;# test expr's aggressive conversion to numeric semantics
489    list [expr {$i}] [expr $i]
490} {789 789}
491test compExpr-old-14.13 {CompilePrimaryExpr: var reference primary} {
492    catch {unset a}
493    set a(foo) foo
494    set a(bar) bar
495    set a(123) 123
496    set result ""
497    lappend result [expr $a(123)] [expr {$a(bar)<$a(foo)}]
498    catch {unset a}
499    set result
500} {123 1}
501test compExpr-old-14.14 {CompilePrimaryExpr: var reference primary} {
502    set i 123    ;# test "$var.0" floating point conversion hack
503    list [expr $i] [expr $i.0] [expr $i.0/12.0]
504} {123 123.0 10.25}
505test compExpr-old-14.15 {CompilePrimaryExpr: var reference primary} {
506    set i 123
507    catch {expr $i.2} msg
508    set msg
509} 123.2
510test compExpr-old-14.16 {CompilePrimaryExpr: error compiling var reference primary} -body {
511    expr {$a(foo}
512} -returnCodes error -match glob -result *
513test compExpr-old-14.17 {CompilePrimaryExpr: string primary that looks like var ref} -body {
514    expr $
515} -returnCodes error -match glob -result *
516test compExpr-old-14.18 {CompilePrimaryExpr: quoted string primary} {
517    expr "21"
518} 21
519test compExpr-old-14.19 {CompilePrimaryExpr: quoted string primary} {
520    set i 123
521    set x 456
522    expr "$i+$x"
523} 579
524test compExpr-old-14.20 {CompilePrimaryExpr: quoted string primary} {
525    set i 3
526    set x 6
527    expr 2+"$i.$x"
528} 5.6
529test compExpr-old-14.21 {CompilePrimaryExpr: error in quoted string primary} {
530    catch {expr "[set]"} msg
531    set msg
532} {wrong # args: should be "set varName ?newValue?"}
533test compExpr-old-14.22 {CompilePrimaryExpr: subcommand primary} {
534    expr {[set i 123; set i]}
535} 123
536test compExpr-old-14.23 {CompilePrimaryExpr: error in subcommand primary} -body {
537    catch {expr {[set]}} msg
538    set ::errorInfo
539} -match glob -result {wrong # args: should be "set varName ?newValue?"
540    while *ing
541"set"*}
542test compExpr-old-14.24 {CompilePrimaryExpr: error in subcommand primary} -body {
543    expr {[set i}
544} -returnCodes error -match glob -result *
545test compExpr-old-14.25 {CompilePrimaryExpr: math function primary} {
546    format %.6g [expr exp(1.0)]
547} 2.71828
548test compExpr-old-14.26 {CompilePrimaryExpr: math function primary} {
549    format %.6g [expr pow(2.0+0.1,3.0+0.1)]
550} 9.97424
551test compExpr-old-14.27 {CompilePrimaryExpr: error in math function primary} -body {
552    expr sinh::(2.0)
553} -returnCodes error -match glob -result *
554test compExpr-old-14.28 {CompilePrimaryExpr: subexpression primary} {
555    expr 2+(3*4)
556} 14
557test compExpr-old-14.29 {CompilePrimaryExpr: error in subexpression primary} -body {
558    catch {expr 2+(3*[set])} msg
559    set ::errorInfo
560} -match glob -result {wrong # args: should be "set varName ?newValue?"
561    while *ing
562"set"*}
563test compExpr-old-14.30 {CompilePrimaryExpr: missing paren in subexpression primary} -body {
564    expr 2+(3*(4+5)
565} -returnCodes error -match glob -result *
566test compExpr-old-14.31 {CompilePrimaryExpr: just var ref in subexpression primary} {
567    set i "5+10"
568    list "[expr $i] == 15" "[expr ($i)] == 15" "[eval expr ($i)] == 15"
569} {{15 == 15} {15 == 15} {15 == 15}}
570test compExpr-old-14.32 {CompilePrimaryExpr: unexpected token} -body {
571    expr @
572} -returnCodes error -match glob -result *
573
574test compExpr-old-15.1 {CompileMathFuncCall: missing parenthesis} -body {
575    expr sinh2.0)
576} -returnCodes error -match glob -result *
577test compExpr-old-15.2 {CompileMathFuncCall: unknown math function} -body {
578    catch {expr whazzathuh(1)} msg
579    set ::errorInfo
580} -match glob -result {* "*whazzathuh"
581    while *ing
582"expr whazzathuh(1)"}
583test compExpr-old-15.3 {CompileMathFuncCall: too many arguments} -body {
584    catch {expr sin(1,2,3)} msg
585    set ::errorInfo
586} -match glob -result {too many arguments for math function*
587    while *ing
588"expr sin(1,2,3)"}
589test compExpr-old-15.4 {CompileMathFuncCall: ')' found before last required arg} -body {
590    catch {expr sin()} msg
591    set ::errorInfo
592} -match glob -result {too few arguments for math function*
593    while *ing
594"expr sin()"}
595test compExpr-old-15.5 {CompileMathFuncCall: too few arguments} -body {
596    catch {expr pow(1)} msg
597    set ::errorInfo
598} -match glob -result {too few arguments for math function*
599    while *ing
600"expr pow(1)"}
601test compExpr-old-15.6 {CompileMathFuncCall: missing ')'} -body {
602    expr sin(1
603} -returnCodes error -match glob -result *
604test compExpr-old-15.7 {CompileMathFuncCall: call registered math function} testmathfunctions {
605    expr 2*T1()
606} 246
607test compExpr-old-15.8 {CompileMathFuncCall: call registered math function} testmathfunctions {
608    expr T2()*3
609} 1035
610test compExpr-old-15.9 {CompileMathFuncCall: call registered math function} testmathfunctions {
611    expr T3(21, 37)
612} 37
613test compExpr-old-15.10 {CompileMathFuncCall: call registered math function} testmathfunctions {
614    expr T3(21.2, 37)
615} 37.0
616test compExpr-old-15.11 {CompileMathFuncCall: call registered math function} testmathfunctions {
617    expr T3(-21.2, -17.5)
618} -17.5
619
620test compExpr-old-16.1 {GetToken: checks whether integer token starting with "0x" (e.g., "0x$") is invalid} {
621    catch {unset a}
622    set a(VALUE) ff15
623    set i 123
624    if {[expr 0x$a(VALUE)] & 16} {
625        set i {}
626    }
627    set i
628} {}
629test compExpr-old-16.2 {GetToken: check for string literal in braces} {
630    expr {{1}}
631} {1}
632
633# Check "expr" and computed command names.
634
635test compExpr-old-17.1 {expr and computed command names} {
636    set i 0
637    set z expr
638    $z 1+2
639} 3
640
641# Check correct conversion of operands to numbers: If the string looks like
642# an integer, convert to integer. Otherwise, if the string looks like a
643# double, convert to double.
644
645test compExpr-old-18.1 {expr and conversion of operands to numbers} {
646    set x [lindex 11 0]
647    catch {expr int($x)}
648    expr {$x}
649} 11
650
651# Check "expr" and interpreter result object resetting before appending
652# an error msg during evaluation of exprs not in {}s
653
654test compExpr-old-19.1 {expr and interpreter result object resetting} {
655    proc p {} {
656        set t  10.0
657        set x  2.0
658        set dx 0.2
659        set f  {$dx-$x/10}
660        set g  {-$x/5}
661        set center 1.0
662        set x  [expr $x-$center]
663        set dx [expr $dx+$g]
664        set x  [expr $x+$f+$center]
665        set x  [expr $x+$f+$center]
666        set y  [expr round($x)]
667    }
668    p
669} 3
670
671# cleanup
672if {[info exists a]} {
673    unset a
674}
675::tcltest::cleanupTests
676return
Note: See TracBrowser for help on using the repository browser.