1 # Commands covered: expr
3 # This file contains a collection of tests for one or more of the Tcl
4 # built-in commands. Sourcing this file into Tcl runs the tests and
5 # generates output for errors. No output means no errors were found.
7 # Copyright (c) 1996-1997 Sun Microsystems, Inc.
8 # Copyright (c) 1998-1999 by Scriptics Corporation.
10 # See the file "license.terms" for information on usage and redistribution
11 # of this file, and for a DISCLAIMER OF ALL WARRANTIES.
13 # RCS: @(#) $Id: expr.test,v 1.9 2000/04/10 17:18:59 ericm Exp $
15 source [file dirname [info script]]/testing.tcl
17 # procedures used below
19 proc put_hello_char {c} {
21 append a [format %c $c]
27 set L1 [set l0 [set h_1 [set q 0]]]
28 for {put_hello_char [expr [put_hello_char [expr [set h 7]*10+2]]+29]} {$l0?[put_hello_char $l0]
29 :!$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"])]
30 ?[set ll [set l0 [expr 54<<1]]]:$ll==108&&$L1<3?
31 [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"])]]]]
32 :[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
33 ?[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"])]]}
34 expr {$L1!=1<<3?[incr q [expr ([string length "abc"]-[string length "abc"])-1]]:[set h_1 [set ll $h1]]}
41 expr {1<$a?[expr {$a<3?[12days -79 -13 [string range $c [12days -87 \
42 [expr 1-$b] [string range $c [12days -86 0 [string range $c 1 end]] \
43 end]] end]]:1};expr {$a<$b?[12days [expr $a+1] $b $c]:3};expr {[12days \
44 -94 [expr $a-27] $c]&&$a==2?$b<13?[12days 2 [expr $b+1] "%s %d %d\n"]:9
45 :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' ')# \}'+\}##(!!/"]
46 :$a<-50?[string compare [format %c $b] [string index $c 0]]==0?[append \
47 xxx [string index $c 31];scan [string index $c 31] %c x;set x]
48 :[12days -65 $b [string range $c 1 end]]:[12days [expr ([string compare \
49 [string index $c 0] "/"]==0)+$a] $b [string range $c 1 end]]:0<$a
50 ?[12days 2 2 "%s"]:[string compare [string index $c 0] "/"]==0||
51 [12days 0 [12days -61 [scan [string index $c 0] %c x; set x] \
52 "!ek;dc i@bK'(q)-\[w\]*%n+r3#l,\{\}:\nuwloca-O;m .vpbks,fxntdCeghiry"] \
53 [string range $c 1 end]]}
55 proc do_twelve_days {} {
66 test expr-1.1 {TclCompileExprCmd: no expression} {
67 list [catch {expr } msg]
69 test expr-1.2 {TclCompileExprCmd: one expression word} {
72 test expr-1.3 {TclCompileExprCmd: two expression words} {
75 test expr-1.4 {TclCompileExprCmd: five expression words} {
78 test expr-1.5 {TclCompileExprCmd: quoted expression word} {
81 test expr-1.6 {TclCompileExprCmd: quoted expression word} {
82 catch {expr "0005"zxy} msg
84 test expr-1.7 {TclCompileExprCmd: expression word in braces} {
87 # XXX: I believe that this ought to return a string, thus -0x1234
88 #test expr-1.8 {TclCompileExprCmd: expression word in braces} {
91 test expr-1.9 {TclCompileExprCmd: expression word in braces} {
92 catch {expr {-0005}foo} msg
94 test expr-1.10 {TclCompileExprCmd: other expression word in braces} {
95 expr 4*[llength "6 2"]
97 test expr-1.11 {TclCompileExprCmd: expression word terminated by ;} {
98 expr 4*[llength "6 2"];
100 test expr-1.12 {TclCompileExprCmd: inlined expr (in "catch") inside other catch} {
103 # Might not be a number
107 test expr-1.13 {TclCompileExprCmd: second level of substitutions in expr not in braces with single var reference} {
109 set x 27; set bool {$x}; if $bool {set a foo}
112 test expr-1.14 {TclCompileExprCmd: second level of substitutions in expr with comparison as top-level operator} {
114 set x 2; set b {$x}; set a [expr $b == 2]
118 test expr-2.1 {TclCompileExpr: are builtin functions registered?} {
119 expr double(5*[llength "6 2"])
121 test expr-2.2 {TclCompileExpr: error in expr} {
122 catch {expr 2//3} msg
124 test expr-2.3 {TclCompileExpr: junk after legal expr} {
125 catch {expr 7*[llength "a b"]foo} msg
127 test expr-2.4 {TclCompileExpr: numeric expr string rep == formatted int rep} {
131 test expr-3.1 {CompileCondExpr: just lor expr} {expr 3||0} 1
132 test expr-3.2 {CompileCondExpr: error in lor expr} {
133 catch {expr x||3} msg
135 test expr-3.3 {CompileCondExpr: test true arm} {expr 3>2?44:66} 44
136 test expr-3.4 {CompileCondExpr: error compiling true arm} {
137 catch {expr 3>2?2//3:66} msg
139 test expr-3.5 {CompileCondExpr: test false arm} {expr 2>3?44:66} 66
140 test expr-3.6 {CompileCondExpr: error compiling false arm} {
141 catch {expr 2>3?44:2//3} msg
144 test expr-3.7 {CompileCondExpr: long arms & nested cond exprs} {
145 puts "Note: doing test expr-3.7 which can take several minutes to run"
149 test expr-3.8 {CompileCondExpr: long arms & nested cond exprs} {
150 puts "Note: doing test expr-3.8 which can take several minutes to run"
156 test expr-4.1 {CompileLorExpr: just land expr} {expr 1.3&&3.3} 1
157 test expr-4.2 {CompileLorExpr: error in land expr} {
158 catch {expr x&&3} msg
160 test expr-4.3 {CompileLorExpr: simple lor exprs} {expr 0||1.0} 1
161 test expr-4.4 {CompileLorExpr: simple lor exprs} {expr 3.0||0.0} 1
162 test expr-4.5 {CompileLorExpr: simple lor exprs} {expr 0||0||1} 1
163 test expr-4.6 {CompileLorExpr: error compiling lor arm} {
164 catch {expr 2//3||4.0} msg
166 test expr-4.7 {CompileLorExpr: error compiling lor arm} {
167 catch {expr 1.3||2//3} msg
169 test expr-4.8 {CompileLorExpr: error compiling lor arms} {
170 list [catch {expr {"a"||"b"}} msg]
172 test expr-4.9 {CompileLorExpr: long lor arm} {
175 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]]}
178 test expr-5.1 {CompileLandExpr: just bitor expr} {expr 7|0x13} 23
179 test expr-5.2 {CompileLandExpr: error in bitor expr} {
182 test expr-5.3 {CompileLandExpr: simple land exprs} {expr 0&&1.0} 0
183 test expr-5.4 {CompileLandExpr: simple land exprs} {expr 0&&0} 0
184 test expr-5.5 {CompileLandExpr: simple land exprs} {expr 3.0&&1.2} 1
185 test expr-5.6 {CompileLandExpr: simple land exprs} {expr 1&&1&&2} 1
186 test expr-5.7 {CompileLandExpr: error compiling land arm} {
187 catch {expr 2//3&&4.0} msg
189 test expr-5.8 {CompileLandExpr: error compiling land arm} {
190 catch {expr 1.3&&2//3} msg
192 test expr-5.9 {CompileLandExpr: error compiling land arm} {
193 list [catch {expr {"a"&&"b"}} msg]
195 test expr-5.10 {CompileLandExpr: long land arms} {
198 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]]}
201 test expr-6.1 {CompileBitXorExpr: just bitand expr} {expr 7&0x13} 3
202 test expr-6.2 {CompileBitXorExpr: error in bitand expr} {
205 test expr-6.3 {CompileBitXorExpr: simple bitxor exprs} {expr 7^0x13} 20
206 test expr-6.4 {CompileBitXorExpr: simple bitxor exprs} {expr 3^0x10} 19
207 test expr-6.5 {CompileBitXorExpr: simple bitxor exprs} {expr 0^7} 7
208 test expr-6.6 {CompileBitXorExpr: simple bitxor exprs} {expr -1^7} -8
209 test expr-6.7 {CompileBitXorExpr: error compiling bitxor arm} {
210 catch {expr 2//3|6} msg
212 test expr-6.8 {CompileBitXorExpr: error compiling bitxor arm} {
215 test expr-6.9 {CompileBitXorExpr: runtime error in bitxor arm} {
216 list [catch {expr {24.0^3}} msg]
218 test expr-6.10 {CompileBitXorExpr: runtime error in bitxor arm} {
219 list [catch {expr {"a"^"b"}} msg]
222 test expr-7.1 {CompileBitAndExpr: just equality expr} {expr 3==2} 0
223 test expr-7.2 {CompileBitAndExpr: just equality expr} {expr 2.0==2} 1
224 test expr-7.3 {CompileBitAndExpr: just equality expr} {expr 3.2!=2.2} 1
225 test expr-7.4 {CompileBitAndExpr: just equality expr} {expr {"abc" == "abd"}} 0
226 test expr-7.5 {CompileBitAndExpr: error in equality expr} {
227 catch {expr x==3} msg
229 test expr-7.6 {CompileBitAndExpr: simple bitand exprs} {expr 7&0x13} 3
230 test expr-7.7 {CompileBitAndExpr: simple bitand exprs} {expr 0xf2&0x53} 82
231 test expr-7.8 {CompileBitAndExpr: simple bitand exprs} {expr 3&6} 2
232 test expr-7.9 {CompileBitAndExpr: simple bitand exprs} {expr -1&-7} -7
233 test expr-7.10 {CompileBitAndExpr: error compiling bitand arm} {
234 catch {expr 2//3&6} msg
236 test expr-7.11 {CompileBitAndExpr: error compiling bitand arm} {
239 test expr-7.12 {CompileBitAndExpr: runtime error in bitand arm} {
240 list [catch {expr {24.0&3}} msg]
242 test expr-7.13 {CompileBitAndExpr: runtime error in bitand arm} {
243 list [catch {expr {"a"&"b"}} msg]
246 test expr-8.1 {CompileEqualityExpr: just relational expr} {expr 3>=2} 1
247 test expr-8.2 {CompileEqualityExpr: just relational expr} {expr 2<=2.1} 1
248 test expr-8.3 {CompileEqualityExpr: just relational expr} {expr 3.2>"2.2"} 1
249 test expr-8.4 {CompileEqualityExpr: just relational expr} {expr {"0y"<"0x12"}} 0
250 test expr-8.5 {CompileEqualityExpr: error in relational expr} {
253 test expr-8.6 {CompileEqualityExpr: simple equality exprs} {expr 7==0x13} 0
254 test expr-8.7 {CompileEqualityExpr: simple equality exprs} {expr -0xf2!=0x53} 1
255 test expr-8.8 {CompileEqualityExpr: simple equality exprs} {expr {"12398712938788234-1298379" != ""}} 1
256 test expr-8.9 {CompileEqualityExpr: simple equality exprs} {expr -1!="abc"} 1
257 test expr-8.10 {CompileEqualityExpr: error compiling equality arm} {
258 catch {expr 2//3==6} msg
260 test expr-8.11 {CompileEqualityExpr: error compiling equality arm} {
261 catch {expr 2!=x} msg
265 test expr-9.1 {CompileRelationalExpr: just shift expr} {expr 3<<2} 12
266 test expr-9.2 {CompileRelationalExpr: just shift expr} {expr 0xff>>2} 63
267 test expr-9.3 {CompileRelationalExpr: just shift expr} {expr -1>>2} -1
268 test expr-9.4 {CompileRelationalExpr: just shift expr} {expr {1<<3}} 8
270 # The following test is different for 32-bit versus 64-bit
271 # architectures because LONG_MIN is different
273 if {0x80000000 > 0} {
274 test expr-9.5 {CompileRelationalExpr: shift expr producing LONG_MIN (64bit)} jim {
276 } -9223372036854775808
278 test expr-9.5 {CompileRelationalExpr: shift expr producing LONG_MIN (32bit)} jim {
282 test expr-9.6 {CompileRelationalExpr: error in shift expr} {
283 catch {expr x>>3} msg
285 test expr-9.7 {CompileRelationalExpr: simple relational exprs} {expr 0xff>=+0x3} 1
286 test expr-9.8 {CompileRelationalExpr: simple relational exprs} {expr -0xf2<0x3} 1
287 test expr-9.9 {CompileRelationalExpr: error compiling relational arm} {
288 catch {expr 2//3>6} msg
290 test expr-9.10 {CompileRelationalExpr: error compiling relational arm} {
294 test expr-10.1 {CompileShiftExpr: just add expr} {expr 4+-2} 2
295 test expr-10.2 {CompileShiftExpr: just add expr} {expr 0xff-2} 253
296 test expr-10.3 {CompileShiftExpr: just add expr} {expr -1--2} 1
297 test expr-10.4 {CompileShiftExpr: just add expr} {expr 1-0123} -122
298 test expr-10.5 {CompileShiftExpr: error in add expr} {
301 test expr-10.6 {CompileShiftExpr: simple shift exprs} {expr 0xff>>0x3} 31
302 test expr-10.7 {CompileShiftExpr: simple shift exprs} {expr -0xf2<<0x3} -1936
303 test expr-10.8 {CompileShiftExpr: error compiling shift arm} {
304 catch {expr 2//3>>6} msg
306 test expr-10.9 {CompileShiftExpr: error compiling shift arm} {
307 catch {expr 2<<x} msg
309 test expr-10.10 {CompileShiftExpr: runtime error} {
310 list [catch {expr {24.0>>43}} msg]
312 test expr-10.11 {CompileShiftExpr: runtime error} {
313 list [catch {expr {"a"<<"b"}} msg]
316 test expr-11.1 {CompileAddExpr: just multiply expr} {expr 4*-2} -8
317 test expr-11.2 {CompileAddExpr: just multiply expr} {expr 0xff%2} 1
318 test expr-11.3 {CompileAddExpr: just multiply expr} {expr -1/2} -1
319 test expr-11.4 {CompileAddExpr: just multiply expr} {expr 7891%0123} 19
320 test expr-11.5 {CompileAddExpr: error in multiply expr} {
323 test expr-11.6 {CompileAddExpr: simple add exprs} {expr 0xff++0x3} 258
324 test expr-11.7 {CompileAddExpr: simple add exprs} {expr -0xf2--0x3} -239
325 test expr-11.8 {CompileAddExpr: error compiling add arm} {
326 catch {expr 2//3+6} msg
328 test expr-11.9 {CompileAddExpr: error compiling add arm} {
331 test expr-11.10 {CompileAddExpr: runtime error} {
332 list [catch {expr {24.0+"xx"}} msg]
334 test expr-11.11 {CompileAddExpr: runtime error} {
335 list [catch {expr {"a"-"b"}} msg]
337 test expr-11.12 {CompileAddExpr: runtime error} {
338 list [catch {expr {3/0}} msg]
340 test expr-11.13 {CompileAddExpr: divide by zero} {
343 test expr-11.14 {CompileAddExpr: divide by zero} {
347 test expr-12.1 {CompileMultiplyExpr: just unary expr} {expr ~4} -5
348 test expr-12.2 {CompileMultiplyExpr: just unary expr} {expr --5} 5
349 test expr-12.3 {CompileMultiplyExpr: just unary expr} {expr !27} 0
350 test expr-12.4 {CompileMultiplyExpr: just unary expr} {expr ~0xff00ff} -16711936
351 test expr-12.5 {CompileMultiplyExpr: error in unary expr} {
354 test expr-12.6 {CompileMultiplyExpr: simple multiply exprs} {expr 0xff*0x3} 765
355 test expr-12.7 {CompileMultiplyExpr: simple multiply exprs} {expr -0xf2%-0x3} -2
356 test expr-12.8 {CompileMultiplyExpr: error compiling multiply arm} {
357 catch {expr 2*3%%6} msg
359 test expr-12.9 {CompileMultiplyExpr: error compiling multiply arm} {
362 test expr-12.10 {CompileMultiplyExpr: runtime error} {
363 list [catch {expr {24.0*"xx"}} msg]
365 test expr-12.11 {CompileMultiplyExpr: runtime error} {
366 list [catch {expr {"a"/"b"}} msg]
369 test expr-13.1 {CompileUnaryExpr: unary exprs} {expr -0xff} -255
370 test expr-13.2 {CompileUnaryExpr: unary exprs} {expr +000123} 123
371 test expr-13.3 {CompileUnaryExpr: unary exprs} {expr +--++36} 36
372 test expr-13.4 {CompileUnaryExpr: unary exprs} {expr !2} 0
373 test expr-13.5 {CompileUnaryExpr: unary exprs} {expr +--+-62.0} -62.0
374 test expr-13.6 {CompileUnaryExpr: unary exprs} {expr !0.0} 1
375 test expr-13.7 {CompileUnaryExpr: unary exprs} {expr !0xef} 0
376 test expr-13.8 {CompileUnaryExpr: error compiling unary expr} {
379 test expr-13.9 {CompileUnaryExpr: error compiling unary expr} {
380 catch {expr !1.x} msg
382 test expr-13.10 {CompileUnaryExpr: runtime error} {
383 list [catch {expr {~"xx"}} msg]
385 test expr-13.11 {CompileUnaryExpr: runtime error} {
386 list [catch {expr ~4.0} msg]
388 test expr-13.12 {CompileUnaryExpr: just primary expr} {expr 0x123} 291
389 test expr-13.13 {CompileUnaryExpr: just primary expr} {
393 test expr-13.14 {CompileUnaryExpr: just primary expr} {
396 test expr-13.15 {CompileUnaryExpr: just primary expr} {expr "123"} 123
397 test expr-13.16 {CompileUnaryExpr: error in primary expr} {
398 catch {expr [set]} msg
400 test expr-14.1 {CompilePrimaryExpr: literal primary} {expr 1} 1
401 test expr-14.2 {CompilePrimaryExpr: literal primary} {expr 123} 123
402 test expr-14.3 {CompilePrimaryExpr: literal primary} {expr 0xff} 255
403 test expr-14.4 {CompilePrimaryExpr: literal primary} {expr 00010} 10
404 test expr-14.5 {CompilePrimaryExpr: literal primary} {expr 62.0} 62.0
405 test expr-14.6 {CompilePrimaryExpr: literal primary} {
408 test expr-14.7 {CompilePrimaryExpr: literal primary} {expr {{abcde}<{abcdef}}} 1
409 test expr-14.8 {CompilePrimaryExpr: literal primary} {expr {{abc\
411 test expr-14.9 {CompilePrimaryExpr: literal primary} {expr {{abc\tde} > {abc\tdef}}} 0
412 test expr-14.10 {CompilePrimaryExpr: literal primary} {expr {{123}}} 123
413 test expr-14.11 {CompilePrimaryExpr: var reference primary} {
415 list [expr {$i}] [expr $i]
417 test expr-14.12 {CompilePrimaryExpr: var reference primary} {
418 set i {789} ;# test expr's aggressive conversion to numeric semantics
419 list [expr {$i}] [expr $i]
421 test expr-14.13 {CompilePrimaryExpr: var reference primary} {
427 lappend result [expr $a(123)] [expr {$a(bar)<$a(foo)}]
431 test expr-14.14 {CompilePrimaryExpr: var reference primary} {
432 set i 123 ;# test "$var.0" floating point conversion hack
433 list [expr $i] [expr $i.0] [expr $i.0/12.0]
435 test expr-14.15 {CompilePrimaryExpr: var reference primary} {
437 catch {expr $i.2} msg
440 test expr-14.16 {CompilePrimaryExpr: error compiling var reference primary} {
441 catch {expr {$a(foo}} msg
443 test expr-14.18 {CompilePrimaryExpr: quoted string primary} {
446 test expr-14.19 {CompilePrimaryExpr: quoted string primary} {
451 test expr-14.20 {CompilePrimaryExpr: quoted string primary} {
456 test expr-14.21 {CompilePrimaryExpr: error in quoted string primary} {
457 catch {expr "[set]"} msg
459 test expr-14.22 {CompilePrimaryExpr: subcommand primary} {
460 expr {[set i 123; set i]}
462 test expr-14.23 {CompilePrimaryExpr: error in subcommand primary} {
463 catch {expr {[set]}} msg
465 test expr-14.24 {CompilePrimaryExpr: error in subcommand primary} {
466 catch {expr {[set blah}} msg
468 test expr-14.28 {CompilePrimaryExpr: subexpression primary} {
471 test expr-14.29 {CompilePrimaryExpr: error in subexpression primary} {
472 catch {expr 2+(3*[set])} msg
474 test expr-14.30 {CompilePrimaryExpr: missing paren in subexpression primary} {
475 catch {expr 2+(3*(4+5)} msg
477 test expr-14.31 {CompilePrimaryExpr: just var ref in subexpression primary} {
479 list "[expr $i] == 15" "[expr ($i)] == 15" "[eval expr ($i)] == 15"
480 } {{15 == 15} {15 == 15} {15 == 15}}
481 test expr-14.32 {CompilePrimaryExpr: unexpected token} {
485 test expr-15.2 {CompileMathFuncCall: unknown math function} {
486 catch {expr whazzathuh(1)} msg
489 test expr-16.1 {GetToken: checks whether integer token starting with "0x" (e.g., "0x$") is invalid} {
493 if {[expr 0x$a(VALUE)] & 16} {
498 test expr-16.2 {GetToken: check for string literal in braces} {
502 # Check "expr" and computed command names.
504 test expr-17.1 {expr and computed command names} {
510 # Check correct conversion of operands to numbers: If the string looks like
511 # an integer, convert to integer. Otherwise, if the string looks like a
512 # double, convert to double.
514 test expr-18.1 {expr and conversion of operands to numbers} {
519 test expr-18.2 {whitespace strings should not be == 0 (buggy strtod)} {
523 # Check "expr" and interpreter result object resetting before appending
524 # an error msg during evaluation of exprs not in {}s
526 test expr-19.1 {expr and interpreter result object resetting} {
534 set x [expr $x-$center]
536 set x [expr $x+$f+$center]
537 set x [expr $x+$f+$center]
538 set y [expr round($x)]
545 # Test for incorrect "double evaluation" semantics
547 #XXX: Jim doesn't care about missing braces
548 #test expr-20.1 {wrong brace matching} {
554 # set l "\{"; set r "\}"; set q "\""
555 # set cmd "expr $l$q|$q == $q$r$q$r"
558 test expr-20.3 {broken substitution of integer digits} {
559 # fails with 8.0.x, but not 8.1b2
560 list [set a 000; expr 0x1$a] [set a 1; expr ${a}000]
562 test expr-20.4 {proper double evaluation compilation, error case} {
563 catch {unset a}; # make sure $a doesn't exist
564 list [catch {expr 1?{$a}:0} msg]
566 test expr-20.5 {proper double evaluation compilation, working case} {
570 test expr-20.6 {handling of compile error in trial compile} {
571 list [catch {expr + {[incr]}} msg]
573 test expr-20.7 {handling of compile error in runtime case} {
574 list [catch {expr + {[error foo]}} msg]
577 test expr-21.1 {checking boolean 0} {
580 test expr-21.2 {checking boolean 0} {
583 test expr-21.3 {checking boolean false} {
586 test expr-21.4 {checking boolean no} {
589 test expr-21.5 {checking boolean off} {
592 test expr-21.6 {checking boolean 1} {
595 test expr-21.7 {checking boolean true} {
598 test expr-21.8 {checking boolean yes} {
601 test expr-21.9 {checking boolean on} {
604 test expr-21.7 {checking boolean mixed case} {
614 if {[info exists a]} {