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