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