Debian Codegraph @

tests/compExpr-old.test

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