os/persistentdata/persistentstorage/sqlite3api/TEST/TCL/tcldistribution/tests/expr-old.test
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/persistentdata/persistentstorage/sqlite3api/TEST/TCL/tcldistribution/tests/expr-old.test Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,1011 @@
1.4 +# Commands covered: expr
1.5 +#
1.6 +# This file contains the original set of tests for Tcl's expr command.
1.7 +# Since the expr command is now compiled, a new set of tests covering
1.8 +# the new implementation are in the files "parseExpr.test" and
1.9 +# "compExpr.test". Sourcing this file into Tcl runs the tests and generates
1.10 +# output for errors. No output means no errors were found.
1.11 +#
1.12 +# Copyright (c) 1991-1994 The Regents of the University of California.
1.13 +# Copyright (c) 1994-1997 Sun Microsystems, Inc.
1.14 +# Copyright (c) 1998-2000 by Scriptics Corporation.
1.15 +#
1.16 +# See the file "license.terms" for information on usage and redistribution
1.17 +# of this file, and for a DISCLAIMER OF ALL WARRANTIES.
1.18 +#
1.19 +# RCS: @(#) $Id: expr-old.test,v 1.16.2.5 2006/05/04 12:34:39 dgp Exp $
1.20 +
1.21 +if {[lsearch [namespace children] ::tcltest] == -1} {
1.22 + package require tcltest 2.1
1.23 + namespace import -force ::tcltest::*
1.24 +}
1.25 +
1.26 +if {([catch {expr T1()} msg] == 1) && ($msg == {unknown math function "T1"})} {
1.27 + set gotT1 0
1.28 + puts "This application hasn't been compiled with the \"T1\" and"
1.29 + puts "\"T2\" math functions, so I'll skip some of the expr tests."
1.30 +} else {
1.31 + set gotT1 1
1.32 +}
1.33 +
1.34 +# First, test all of the integer operators individually.
1.35 +
1.36 +test expr-old-1.1 {integer operators} {expr -4} -4
1.37 +test expr-old-1.2 {integer operators} {expr -(1+4)} -5
1.38 +test expr-old-1.3 {integer operators} {expr ~3} -4
1.39 +test expr-old-1.4 {integer operators} {expr !2} 0
1.40 +test expr-old-1.5 {integer operators} {expr !0} 1
1.41 +test expr-old-1.6 {integer operators} {expr 4*6} 24
1.42 +test expr-old-1.7 {integer operators} {expr 36/12} 3
1.43 +test expr-old-1.8 {integer operators} {expr 27/4} 6
1.44 +test expr-old-1.9 {integer operators} {expr 27%4} 3
1.45 +test expr-old-1.10 {integer operators} {expr 2+2} 4
1.46 +test expr-old-1.11 {integer operators} {expr 2-6} -4
1.47 +test expr-old-1.12 {integer operators} {expr 1<<3} 8
1.48 +test expr-old-1.13 {integer operators} {expr 0xff>>2} 63
1.49 +test expr-old-1.14 {integer operators} {expr -1>>2} -1
1.50 +test expr-old-1.15 {integer operators} {expr 3>2} 1
1.51 +test expr-old-1.16 {integer operators} {expr 2>2} 0
1.52 +test expr-old-1.17 {integer operators} {expr 1>2} 0
1.53 +test expr-old-1.18 {integer operators} {expr 3<2} 0
1.54 +test expr-old-1.19 {integer operators} {expr 2<2} 0
1.55 +test expr-old-1.20 {integer operators} {expr 1<2} 1
1.56 +test expr-old-1.21 {integer operators} {expr 3>=2} 1
1.57 +test expr-old-1.22 {integer operators} {expr 2>=2} 1
1.58 +test expr-old-1.23 {integer operators} {expr 1>=2} 0
1.59 +test expr-old-1.24 {integer operators} {expr 3<=2} 0
1.60 +test expr-old-1.25 {integer operators} {expr 2<=2} 1
1.61 +test expr-old-1.26 {integer operators} {expr 1<=2} 1
1.62 +test expr-old-1.27 {integer operators} {expr 3==2} 0
1.63 +test expr-old-1.28 {integer operators} {expr 2==2} 1
1.64 +test expr-old-1.29 {integer operators} {expr 3!=2} 1
1.65 +test expr-old-1.30 {integer operators} {expr 2!=2} 0
1.66 +test expr-old-1.31 {integer operators} {expr 7&0x13} 3
1.67 +test expr-old-1.32 {integer operators} {expr 7^0x13} 20
1.68 +test expr-old-1.33 {integer operators} {expr 7|0x13} 23
1.69 +test expr-old-1.34 {integer operators} {expr 0&&1} 0
1.70 +test expr-old-1.35 {integer operators} {expr 0&&0} 0
1.71 +test expr-old-1.36 {integer operators} {expr 1&&3} 1
1.72 +test expr-old-1.37 {integer operators} {expr 0||1} 1
1.73 +test expr-old-1.38 {integer operators} {expr 3||0} 1
1.74 +test expr-old-1.39 {integer operators} {expr 0||0} 0
1.75 +test expr-old-1.40 {integer operators} {expr 3>2?44:66} 44
1.76 +test expr-old-1.41 {integer operators} {expr 2>3?44:66} 66
1.77 +test expr-old-1.42 {integer operators} {expr 36/5} 7
1.78 +test expr-old-1.43 {integer operators} {expr 36%5} 1
1.79 +test expr-old-1.44 {integer operators} {expr -36/5} -8
1.80 +test expr-old-1.45 {integer operators} {expr -36%5} 4
1.81 +test expr-old-1.46 {integer operators} {expr 36/-5} -8
1.82 +test expr-old-1.47 {integer operators} {expr 36%-5} -4
1.83 +test expr-old-1.48 {integer operators} {expr -36/-5} 7
1.84 +test expr-old-1.49 {integer operators} {expr -36%-5} -1
1.85 +test expr-old-1.50 {integer operators} {expr +36} 36
1.86 +test expr-old-1.51 {integer operators} {expr +--++36} 36
1.87 +test expr-old-1.52 {integer operators} {expr +36%+5} 1
1.88 +test expr-old-1.53 {integer operators} {
1.89 + catch {unset x}
1.90 + set x yes
1.91 + list [expr {1 && $x}] [expr {$x && 1}] \
1.92 + [expr {0 || $x}] [expr {$x || 0}]
1.93 +} {1 1 1 1}
1.94 +
1.95 +# Check the floating-point operators individually, along with
1.96 +# automatic conversion to integers where needed.
1.97 +
1.98 +test expr-old-2.1 {floating-point operators} {expr -4.2} -4.2
1.99 +test expr-old-2.2 {floating-point operators} {expr -(1.1+4.2)} -5.3
1.100 +test expr-old-2.3 {floating-point operators} {expr +5.7} 5.7
1.101 +test expr-old-2.4 {floating-point operators} {expr +--+-62.0} -62.0
1.102 +test expr-old-2.5 {floating-point operators} {expr !2.1} 0
1.103 +test expr-old-2.6 {floating-point operators} {expr !0.0} 1
1.104 +test expr-old-2.7 {floating-point operators} {expr 4.2*6.3} 26.46
1.105 +test expr-old-2.8 {floating-point operators} {expr 36.0/12.0} 3.0
1.106 +test expr-old-2.9 {floating-point operators} {expr 27/4.0} 6.75
1.107 +test expr-old-2.10 {floating-point operators} {expr 2.3+2.1} 4.4
1.108 +test expr-old-2.11 {floating-point operators} {expr 2.3-6.5} -4.2
1.109 +test expr-old-2.12 {floating-point operators} {expr 3.1>2.1} 1
1.110 +test expr-old-2.13 {floating-point operators} {expr {2.1 > 2.1}} 0
1.111 +test expr-old-2.14 {floating-point operators} {expr 1.23>2.34e+1} 0
1.112 +test expr-old-2.15 {floating-point operators} {expr 3.45<2.34} 0
1.113 +test expr-old-2.16 {floating-point operators} {expr 0.002e3<--200e-2} 0
1.114 +test expr-old-2.17 {floating-point operators} {expr 1.1<2.1} 1
1.115 +test expr-old-2.18 {floating-point operators} {expr 3.1>=2.2} 1
1.116 +test expr-old-2.19 {floating-point operators} {expr 2.345>=2.345} 1
1.117 +test expr-old-2.20 {floating-point operators} {expr 1.1>=2.2} 0
1.118 +test expr-old-2.21 {floating-point operators} {expr 3.0<=2.0} 0
1.119 +test expr-old-2.22 {floating-point operators} {expr 2.2<=2.2} 1
1.120 +test expr-old-2.23 {floating-point operators} {expr 2.2<=2.2001} 1
1.121 +test expr-old-2.24 {floating-point operators} {expr 3.2==2.2} 0
1.122 +test expr-old-2.25 {floating-point operators} {expr 2.2==2.2} 1
1.123 +test expr-old-2.26 {floating-point operators} {expr 3.2!=2.2} 1
1.124 +test expr-old-2.27 {floating-point operators} {expr 2.2!=2.2} 0
1.125 +test expr-old-2.28 {floating-point operators} {expr 0.0&&0.0} 0
1.126 +test expr-old-2.29 {floating-point operators} {expr 0.0&&1.3} 0
1.127 +test expr-old-2.30 {floating-point operators} {expr 1.3&&0.0} 0
1.128 +test expr-old-2.31 {floating-point operators} {expr 1.3&&3.3} 1
1.129 +test expr-old-2.32 {floating-point operators} {expr 0.0||0.0} 0
1.130 +test expr-old-2.33 {floating-point operators} {expr 0.0||1.3} 1
1.131 +test expr-old-2.34 {floating-point operators} {expr 1.3||0.0} 1
1.132 +test expr-old-2.35 {floating-point operators} {expr 3.3||0.0} 1
1.133 +test expr-old-2.36 {floating-point operators} {expr 3.3>2.3?44.3:66.3} 44.3
1.134 +test expr-old-2.37 {floating-point operators} {expr 2.3>3.3?44.3:66.3} 66.3
1.135 +test expr-old-2.38 {floating-point operators} {
1.136 + list [catch {expr 028.1 + 09.2} msg] $msg
1.137 +} {0 37.3}
1.138 +
1.139 +# Operators that aren't legal on floating-point numbers
1.140 +
1.141 +test expr-old-3.1 {illegal floating-point operations} {
1.142 + list [catch {expr ~4.0} msg] $msg
1.143 +} {1 {can't use floating-point value as operand of "~"}}
1.144 +test expr-old-3.2 {illegal floating-point operations} {
1.145 + list [catch {expr 27%4.0} msg] $msg
1.146 +} {1 {can't use floating-point value as operand of "%"}}
1.147 +test expr-old-3.3 {illegal floating-point operations} {
1.148 + list [catch {expr 27.0%4} msg] $msg
1.149 +} {1 {can't use floating-point value as operand of "%"}}
1.150 +test expr-old-3.4 {illegal floating-point operations} {
1.151 + list [catch {expr 1.0<<3} msg] $msg
1.152 +} {1 {can't use floating-point value as operand of "<<"}}
1.153 +test expr-old-3.5 {illegal floating-point operations} {
1.154 + list [catch {expr 3<<1.0} msg] $msg
1.155 +} {1 {can't use floating-point value as operand of "<<"}}
1.156 +test expr-old-3.6 {illegal floating-point operations} {
1.157 + list [catch {expr 24.0>>3} msg] $msg
1.158 +} {1 {can't use floating-point value as operand of ">>"}}
1.159 +test expr-old-3.7 {illegal floating-point operations} {
1.160 + list [catch {expr 24>>3.0} msg] $msg
1.161 +} {1 {can't use floating-point value as operand of ">>"}}
1.162 +test expr-old-3.8 {illegal floating-point operations} {
1.163 + list [catch {expr 24&3.0} msg] $msg
1.164 +} {1 {can't use floating-point value as operand of "&"}}
1.165 +test expr-old-3.9 {illegal floating-point operations} {
1.166 + list [catch {expr 24.0|3} msg] $msg
1.167 +} {1 {can't use floating-point value as operand of "|"}}
1.168 +test expr-old-3.10 {illegal floating-point operations} {
1.169 + list [catch {expr 24.0^3} msg] $msg
1.170 +} {1 {can't use floating-point value as operand of "^"}}
1.171 +
1.172 +# Check the string operators individually.
1.173 +
1.174 +test expr-old-4.1 {string operators} {expr {"abc" > "def"}} 0
1.175 +test expr-old-4.2 {string operators} {expr {"def" > "def"}} 0
1.176 +test expr-old-4.3 {string operators} {expr {"g" > "def"}} 1
1.177 +test expr-old-4.4 {string operators} {expr {"abc" < "abd"}} 1
1.178 +test expr-old-4.5 {string operators} {expr {"abd" < "abd"}} 0
1.179 +test expr-old-4.6 {string operators} {expr {"abe" < "abd"}} 0
1.180 +test expr-old-4.7 {string operators} {expr {"abc" >= "def"}} 0
1.181 +test expr-old-4.8 {string operators} {expr {"def" >= "def"}} 1
1.182 +test expr-old-4.9 {string operators} {expr {"g" >= "def"}} 1
1.183 +test expr-old-4.10 {string operators} {expr {"abc" <= "abd"}} 1
1.184 +test expr-old-4.11 {string operators} {expr {"abd" <= "abd"}} 1
1.185 +test expr-old-4.12 {string operators} {expr {"abe" <= "abd"}} 0
1.186 +test expr-old-4.13 {string operators} {expr {"abc" == "abd"}} 0
1.187 +test expr-old-4.14 {string operators} {expr {"abd" == "abd"}} 1
1.188 +test expr-old-4.15 {string operators} {expr {"abc" != "abd"}} 1
1.189 +test expr-old-4.16 {string operators} {expr {"abd" != "abd"}} 0
1.190 +test expr-old-4.17 {string operators} {expr {"0y" < "0x12"}} 0
1.191 +test expr-old-4.18 {string operators} {expr {"." < " "}} 0
1.192 +test expr-old-4.19 {string operators} {expr {"abc" eq "abd"}} 0
1.193 +test expr-old-4.20 {string operators} {expr {"abd" eq "abd"}} 1
1.194 +test expr-old-4.21 {string operators} {expr {"abc" ne "abd"}} 1
1.195 +test expr-old-4.22 {string operators} {expr {"abd" ne "abd"}} 0
1.196 +test expr-old-4.23 {string operators} {expr {"" eq "abd"}} 0
1.197 +test expr-old-4.24 {string operators} {expr {"" eq ""}} 1
1.198 +test expr-old-4.25 {string operators} {expr {"abd" ne ""}} 1
1.199 +test expr-old-4.26 {string operators} {expr {"" ne ""}} 0
1.200 +test expr-old-4.27 {string operators} {expr {"longerstring" eq "shorter"}} 0
1.201 +test expr-old-4.28 {string operators} {expr {"longerstring" ne "shorter"}} 1
1.202 +
1.203 +# The following tests are non-portable because on some systems "+"
1.204 +# and "-" can be parsed as numbers.
1.205 +
1.206 +test expr-old-4.29 {string operators} {nonPortable} {expr {"0" == "+"}} 0
1.207 +test expr-old-4.30 {string operators} {nonPortable} {expr {"0" == "-"}} 0
1.208 +test expr-old-4.31 {string operators} {expr {1?"foo":"bar"}} foo
1.209 +test expr-old-4.32 {string operators} {expr {0?"foo":"bar"}} bar
1.210 +
1.211 +# Operators that aren't legal on string operands.
1.212 +
1.213 +test expr-old-5.1 {illegal string operations} {
1.214 + list [catch {expr {-"a"}} msg] $msg
1.215 +} {1 {can't use non-numeric string as operand of "-"}}
1.216 +test expr-old-5.2 {illegal string operations} {
1.217 + list [catch {expr {+"a"}} msg] $msg
1.218 +} {1 {can't use non-numeric string as operand of "+"}}
1.219 +test expr-old-5.3 {illegal string operations} {
1.220 + list [catch {expr {~"a"}} msg] $msg
1.221 +} {1 {can't use non-numeric string as operand of "~"}}
1.222 +test expr-old-5.4 {illegal string operations} {
1.223 + list [catch {expr {!"a"}} msg] $msg
1.224 +} {1 {can't use non-numeric string as operand of "!"}}
1.225 +test expr-old-5.5 {illegal string operations} {
1.226 + list [catch {expr {"a"*"b"}} msg] $msg
1.227 +} {1 {can't use non-numeric string as operand of "*"}}
1.228 +test expr-old-5.6 {illegal string operations} {
1.229 + list [catch {expr {"a"/"b"}} msg] $msg
1.230 +} {1 {can't use non-numeric string as operand of "/"}}
1.231 +test expr-old-5.7 {illegal string operations} {
1.232 + list [catch {expr {"a"%"b"}} msg] $msg
1.233 +} {1 {can't use non-numeric string as operand of "%"}}
1.234 +test expr-old-5.8 {illegal string operations} {
1.235 + list [catch {expr {"a"+"b"}} msg] $msg
1.236 +} {1 {can't use non-numeric string as operand of "+"}}
1.237 +test expr-old-5.9 {illegal string operations} {
1.238 + list [catch {expr {"a"-"b"}} msg] $msg
1.239 +} {1 {can't use non-numeric string as operand of "-"}}
1.240 +test expr-old-5.10 {illegal string operations} {
1.241 + list [catch {expr {"a"<<"b"}} msg] $msg
1.242 +} {1 {can't use non-numeric string as operand of "<<"}}
1.243 +test expr-old-5.11 {illegal string operations} {
1.244 + list [catch {expr {"a">>"b"}} msg] $msg
1.245 +} {1 {can't use non-numeric string as operand of ">>"}}
1.246 +test expr-old-5.12 {illegal string operations} {
1.247 + list [catch {expr {"a"&"b"}} msg] $msg
1.248 +} {1 {can't use non-numeric string as operand of "&"}}
1.249 +test expr-old-5.13 {illegal string operations} {
1.250 + list [catch {expr {"a"^"b"}} msg] $msg
1.251 +} {1 {can't use non-numeric string as operand of "^"}}
1.252 +test expr-old-5.14 {illegal string operations} {
1.253 + list [catch {expr {"a"|"b"}} msg] $msg
1.254 +} {1 {can't use non-numeric string as operand of "|"}}
1.255 +test expr-old-5.15 {illegal string operations} {
1.256 + list [catch {expr {"a"&&"b"}} msg] $msg
1.257 +} {1 {expected boolean value but got "a"}}
1.258 +test expr-old-5.16 {illegal string operations} {
1.259 + list [catch {expr {"a"||"b"}} msg] $msg
1.260 +} {1 {expected boolean value but got "a"}}
1.261 +test expr-old-5.17 {illegal string operations} {
1.262 + list [catch {expr {"a"?4:2}} msg] $msg
1.263 +} {1 {expected boolean value but got "a"}}
1.264 +
1.265 +# Check precedence pairwise.
1.266 +
1.267 +test expr-old-6.1 {precedence checks} {expr -~3} 4
1.268 +test expr-old-6.2 {precedence checks} {expr -!3} 0
1.269 +test expr-old-6.3 {precedence checks} {expr -~0} 1
1.270 +
1.271 +test expr-old-7.1 {precedence checks} {expr 2*4/6} 1
1.272 +test expr-old-7.2 {precedence checks} {expr 24/6*3} 12
1.273 +test expr-old-7.3 {precedence checks} {expr 24/6/2} 2
1.274 +
1.275 +test expr-old-8.1 {precedence checks} {expr -2+4} 2
1.276 +test expr-old-8.2 {precedence checks} {expr -2-4} -6
1.277 +test expr-old-8.3 {precedence checks} {expr +2-4} -2
1.278 +
1.279 +test expr-old-9.1 {precedence checks} {expr 2*3+4} 10
1.280 +test expr-old-9.2 {precedence checks} {expr 8/2+4} 8
1.281 +test expr-old-9.3 {precedence checks} {expr 8%3+4} 6
1.282 +test expr-old-9.4 {precedence checks} {expr 2*3-1} 5
1.283 +test expr-old-9.5 {precedence checks} {expr 8/2-1} 3
1.284 +test expr-old-9.6 {precedence checks} {expr 8%3-1} 1
1.285 +
1.286 +test expr-old-10.1 {precedence checks} {expr 6-3-2} 1
1.287 +
1.288 +test expr-old-11.1 {precedence checks} {expr 7+1>>2} 2
1.289 +test expr-old-11.2 {precedence checks} {expr 7+1<<2} 32
1.290 +test expr-old-11.3 {precedence checks} {expr 7>>3-2} 3
1.291 +test expr-old-11.4 {precedence checks} {expr 7<<3-2} 14
1.292 +
1.293 +test expr-old-12.1 {precedence checks} {expr 6>>1>4} 0
1.294 +test expr-old-12.2 {precedence checks} {expr 6>>1<2} 0
1.295 +test expr-old-12.3 {precedence checks} {expr 6>>1>=3} 1
1.296 +test expr-old-12.4 {precedence checks} {expr 6>>1<=2} 0
1.297 +test expr-old-12.5 {precedence checks} {expr 6<<1>5} 1
1.298 +test expr-old-12.6 {precedence checks} {expr 6<<1<5} 0
1.299 +test expr-old-12.7 {precedence checks} {expr 5<=6<<1} 1
1.300 +test expr-old-12.8 {precedence checks} {expr 5>=6<<1} 0
1.301 +
1.302 +test expr-old-13.1 {precedence checks} {expr 2<3<4} 1
1.303 +test expr-old-13.2 {precedence checks} {expr 0<4>2} 0
1.304 +test expr-old-13.3 {precedence checks} {expr 4>2<1} 0
1.305 +test expr-old-13.4 {precedence checks} {expr 4>3>2} 0
1.306 +test expr-old-13.5 {precedence checks} {expr 4>3>=2} 0
1.307 +test expr-old-13.6 {precedence checks} {expr 4>=3>2} 0
1.308 +test expr-old-13.7 {precedence checks} {expr 4>=3>=2} 0
1.309 +test expr-old-13.8 {precedence checks} {expr 0<=4>=2} 0
1.310 +test expr-old-13.9 {precedence checks} {expr 4>=2<=0} 0
1.311 +test expr-old-13.10 {precedence checks} {expr 2<=3<=4} 1
1.312 +
1.313 +test expr-old-14.1 {precedence checks} {expr 1==4>3} 1
1.314 +test expr-old-14.2 {precedence checks} {expr 0!=4>3} 1
1.315 +test expr-old-14.3 {precedence checks} {expr 1==3<4} 1
1.316 +test expr-old-14.4 {precedence checks} {expr 0!=3<4} 1
1.317 +test expr-old-14.5 {precedence checks} {expr 1==4>=3} 1
1.318 +test expr-old-14.6 {precedence checks} {expr 0!=4>=3} 1
1.319 +test expr-old-14.7 {precedence checks} {expr 1==3<=4} 1
1.320 +test expr-old-14.8 {precedence checks} {expr 0!=3<=4} 1
1.321 +test expr-old-14.9 {precedence checks} {expr 1eq4>3} 1
1.322 +test expr-old-14.10 {precedence checks} {expr 0ne4>3} 1
1.323 +test expr-old-14.11 {precedence checks} {expr 1eq3<4} 1
1.324 +test expr-old-14.12 {precedence checks} {expr 0ne3<4} 1
1.325 +test expr-old-14.13 {precedence checks} {expr 1eq4>=3} 1
1.326 +test expr-old-14.14 {precedence checks} {expr 0ne4>=3} 1
1.327 +test expr-old-14.15 {precedence checks} {expr 1eq3<=4} 1
1.328 +test expr-old-14.16 {precedence checks} {expr 0ne3<=4} 1
1.329 +
1.330 +test expr-old-15.1 {precedence checks} {expr 1==3==3} 0
1.331 +test expr-old-15.2 {precedence checks} {expr 3==3!=2} 1
1.332 +test expr-old-15.3 {precedence checks} {expr 2!=3==3} 0
1.333 +test expr-old-15.4 {precedence checks} {expr 2!=1!=1} 0
1.334 +test expr-old-15.5 {precedence checks} {expr 1eq3eq3} 0
1.335 +test expr-old-15.6 {precedence checks} {expr 3eq3ne2} 1
1.336 +test expr-old-15.7 {precedence checks} {expr 2ne3eq3} 0
1.337 +test expr-old-15.8 {precedence checks} {expr 2ne1ne1} 0
1.338 +
1.339 +test expr-old-16.1 {precedence checks} {expr 2&3eq2} 0
1.340 +test expr-old-16.2 {precedence checks} {expr 1&3ne3} 0
1.341 +test expr-old-16.3 {precedence checks} {expr 2&3eq2} 0
1.342 +test expr-old-16.4 {precedence checks} {expr 1&3ne3} 0
1.343 +
1.344 +test expr-old-17.1 {precedence checks} {expr 7&3^0x10} 19
1.345 +test expr-old-17.2 {precedence checks} {expr 7^0x10&3} 7
1.346 +
1.347 +test expr-old-18.1 {precedence checks} {expr 7^0x10|3} 23
1.348 +test expr-old-18.2 {precedence checks} {expr 7|0x10^3} 23
1.349 +
1.350 +test expr-old-19.1 {precedence checks} {expr 7|3&&1} 1
1.351 +test expr-old-19.2 {precedence checks} {expr 1&&3|7} 1
1.352 +test expr-old-19.3 {precedence checks} {expr 0&&1||1} 1
1.353 +test expr-old-19.4 {precedence checks} {expr 1||1&&0} 1
1.354 +
1.355 +test expr-old-20.1 {precedence checks} {expr 1||0?3:4} 3
1.356 +test expr-old-20.2 {precedence checks} {expr 1?0:4||1} 0
1.357 +test expr-old-20.3 {precedence checks} {expr 1?2:0?3:4} 2
1.358 +test expr-old-20.4 {precedence checks} {expr 0?2:0?3:4} 4
1.359 +test expr-old-20.5 {precedence checks} {expr 1?2?3:4:0} 3
1.360 +test expr-old-20.6 {precedence checks} {expr 0?2?3:4:0} 0
1.361 +
1.362 +# Parentheses.
1.363 +
1.364 +test expr-old-21.1 {parenthesization} {expr (2+4)*6} 36
1.365 +test expr-old-21.2 {parenthesization} {expr (1?0:4)||1} 1
1.366 +test expr-old-21.3 {parenthesization} {expr +(3-4)} -1
1.367 +
1.368 +# Embedded commands and variable names.
1.369 +
1.370 +set a 16
1.371 +test expr-old-22.1 {embedded variables} {expr {2*$a}} 32
1.372 +test expr-old-22.2 {embedded variables} {
1.373 + set x -5
1.374 + set y 10
1.375 + expr {$x + $y}
1.376 +} {5}
1.377 +test expr-old-22.3 {embedded variables} {
1.378 + set x " -5"
1.379 + set y " +10"
1.380 + expr {$x + $y}
1.381 +} {5}
1.382 +test expr-old-22.4 {embedded commands and variables} {expr {[set a] - 14}} 2
1.383 +test expr-old-22.5 {embedded commands and variables} {
1.384 + list [catch {expr {12 - [bad_command_name]}} msg] $msg
1.385 +} {1 {invalid command name "bad_command_name"}}
1.386 +
1.387 +# Double-quotes and things inside them.
1.388 +
1.389 +test expr-old-23.1 {double quotes} {expr {"abc"}} abc
1.390 +test expr-old-23.2 {double quotes} {
1.391 + set a 189
1.392 + expr {"$a.bc"}
1.393 +} 189.bc
1.394 +test expr-old-23.3 {double quotes} {
1.395 + set b2 xyx
1.396 + expr {"$b2$b2$b2.[set b2].[set b2]"}
1.397 +} xyxxyxxyx.xyx.xyx
1.398 +test expr-old-23.4 {double quotes} {expr {"11\}\}22"}} 11}}22
1.399 +test expr-old-23.5 {double quotes} {expr {"\*bc"}} {*bc}
1.400 +test expr-old-23.6 {double quotes} {
1.401 + catch {unset bogus__}
1.402 + list [catch {expr {"$bogus__"}} msg] $msg
1.403 +} {1 {can't read "bogus__": no such variable}}
1.404 +test expr-old-23.7 {double quotes} {
1.405 + list [catch {expr {"a[error Testing]bc"}} msg] $msg
1.406 +} {1 Testing}
1.407 +test expr-old-23.8 {double quotes} {
1.408 + list [catch {expr {"12398712938788234-1298379" != ""}} msg] $msg
1.409 +} {0 1}
1.410 +
1.411 +# Numbers in various bases.
1.412 +
1.413 +test expr-old-24.1 {numbers in different bases} {expr 0x20} 32
1.414 +test expr-old-24.2 {numbers in different bases} {expr 015} 13
1.415 +
1.416 +# Conversions between various data types.
1.417 +
1.418 +test expr-old-25.1 {type conversions} {expr 2+2.5} 4.5
1.419 +test expr-old-25.2 {type conversions} {expr 2.5+2} 4.5
1.420 +test expr-old-25.3 {type conversions} {expr 2-2.5} -0.5
1.421 +test expr-old-25.4 {type conversions} {expr 2/2.5} 0.8
1.422 +test expr-old-25.5 {type conversions} {expr 2>2.5} 0
1.423 +test expr-old-25.6 {type conversions} {expr 2.5>2} 1
1.424 +test expr-old-25.7 {type conversions} {expr 2<2.5} 1
1.425 +test expr-old-25.8 {type conversions} {expr 2>=2.5} 0
1.426 +test expr-old-25.9 {type conversions} {expr 2<=2.5} 1
1.427 +test expr-old-25.10 {type conversions} {expr 2==2.5} 0
1.428 +test expr-old-25.11 {type conversions} {expr 2!=2.5} 1
1.429 +test expr-old-25.12 {type conversions} {expr 2>"ab"} 0
1.430 +test expr-old-25.13 {type conversions} {expr {2>" "}} 1
1.431 +test expr-old-25.14 {type conversions} {expr {"24.1a" > 24.1}} 1
1.432 +test expr-old-25.15 {type conversions} {expr {24.1 > "24.1a"}} 0
1.433 +test expr-old-25.16 {type conversions} {expr 2+2.5} 4.5
1.434 +test expr-old-25.17 {type conversions} {expr 2+2.5} 4.5
1.435 +test expr-old-25.18 {type conversions} {expr 2.0e2} 200.0
1.436 +test expr-old-25.19 {type conversions} {eformat} {expr 2.0e15} 2e+15
1.437 +test expr-old-25.20 {type conversions} {expr 10.0} 10.0
1.438 +
1.439 +# Various error conditions.
1.440 +
1.441 +test expr-old-26.1 {error conditions} {
1.442 + list [catch {expr 2+"a"} msg] $msg
1.443 +} {1 {can't use non-numeric string as operand of "+"}}
1.444 +test expr-old-26.2 {error conditions} {
1.445 + list [catch {expr 2+4*} msg] $msg
1.446 +} {1 {syntax error in expression "2+4*": premature end of expression}}
1.447 +test expr-old-26.3 {error conditions} {
1.448 + list [catch {expr 2+4*(} msg] $msg
1.449 +} {1 {syntax error in expression "2+4*(": premature end of expression}}
1.450 +catch {unset _non_existent_}
1.451 +test expr-old-26.4 {error conditions} {
1.452 + list [catch {expr 2+$_non_existent_} msg] $msg
1.453 +} {1 {can't read "_non_existent_": no such variable}}
1.454 +set a xx
1.455 +test expr-old-26.5 {error conditions} {
1.456 + list [catch {expr {2+$a}} msg] $msg
1.457 +} {1 {can't use non-numeric string as operand of "+"}}
1.458 +test expr-old-26.6 {error conditions} {
1.459 + list [catch {expr {2+[set a]}} msg] $msg
1.460 +} {1 {can't use non-numeric string as operand of "+"}}
1.461 +test expr-old-26.7 {error conditions} {
1.462 + list [catch {expr {2+(4}} msg] $msg
1.463 +} {1 {syntax error in expression "2+(4": looking for close parenthesis}}
1.464 +test expr-old-26.8 {error conditions} {
1.465 + list [catch {expr 2/0} msg] $msg $errorCode
1.466 +} {1 {divide by zero} {ARITH DIVZERO {divide by zero}}}
1.467 +test expr-old-26.9 {error conditions} {
1.468 + list [catch {expr 2%0} msg] $msg $errorCode
1.469 +} {1 {divide by zero} {ARITH DIVZERO {divide by zero}}}
1.470 +test expr-old-26.10 {error conditions} {
1.471 + list [catch {expr 2.0/0.0} msg] $msg $errorCode
1.472 +} {1 {divide by zero} {ARITH DIVZERO {divide by zero}}}
1.473 +test expr-old-26.11 {error conditions} {
1.474 + list [catch {expr 2#} msg] $msg
1.475 +} {1 {syntax error in expression "2#": extra tokens at end of expression}}
1.476 +test expr-old-26.12 {error conditions} {
1.477 + list [catch {expr a.b} msg] $msg
1.478 +} {1 {syntax error in expression "a.b": variable references require preceding $}}
1.479 +test expr-old-26.13 {error conditions} {
1.480 + list [catch {expr {"a"/"b"}} msg] $msg
1.481 +} {1 {can't use non-numeric string as operand of "/"}}
1.482 +test expr-old-26.14 {error conditions} {
1.483 + list [catch {expr 2:3} msg] $msg
1.484 +} {1 {syntax error in expression "2:3": extra tokens at end of expression}}
1.485 +test expr-old-26.15 {error conditions} {
1.486 + list [catch {expr a@b} msg] $msg
1.487 +} {1 {syntax error in expression "a@b": variable references require preceding $}}
1.488 +test expr-old-26.16 {error conditions} {
1.489 + list [catch {expr a[b} msg] $msg
1.490 +} {1 {missing close-bracket}}
1.491 +test expr-old-26.17 {error conditions} {
1.492 + list [catch {expr a`b} msg] $msg
1.493 +} {1 {syntax error in expression "a`b": variable references require preceding $}}
1.494 +test expr-old-26.18 {error conditions} {
1.495 + list [catch {expr \"a\"\{b} msg] $msg
1.496 +} {1 syntax\ error\ in\ expression\ \"\"a\"\{b\":\ extra\ tokens\ at\ end\ of\ expression}
1.497 +test expr-old-26.19 {error conditions} {
1.498 + list [catch {expr a} msg] $msg
1.499 +} {1 {syntax error in expression "a": variable references require preceding $}}
1.500 +test expr-old-26.20 {error conditions} {
1.501 + list [catch expr msg] $msg
1.502 +} {1 {wrong # args: should be "expr arg ?arg ...?"}}
1.503 +
1.504 +# Cancelled evaluation.
1.505 +
1.506 +test expr-old-27.1 {cancelled evaluation} {
1.507 + set a 1
1.508 + expr {0&&[set a 2]}
1.509 + set a
1.510 +} 1
1.511 +test expr-old-27.2 {cancelled evaluation} {
1.512 + set a 1
1.513 + expr {1||[set a 2]}
1.514 + set a
1.515 +} 1
1.516 +test expr-old-27.3 {cancelled evaluation} {
1.517 + set a 1
1.518 + expr {0?[set a 2]:1}
1.519 + set a
1.520 +} 1
1.521 +test expr-old-27.4 {cancelled evaluation} {
1.522 + set a 1
1.523 + expr {1?2:[set a 2]}
1.524 + set a
1.525 +} 1
1.526 +catch {unset x}
1.527 +test expr-old-27.5 {cancelled evaluation} {
1.528 + list [catch {expr {[info exists x] && $x}} msg] $msg
1.529 +} {0 0}
1.530 +test expr-old-27.6 {cancelled evaluation} {
1.531 + list [catch {expr {0 && [concat $x]}} msg] $msg
1.532 +} {0 0}
1.533 +test expr-old-27.7 {cancelled evaluation} {
1.534 + set one 1
1.535 + list [catch {expr {1 || 1/$one}} msg] $msg
1.536 +} {0 1}
1.537 +test expr-old-27.8 {cancelled evaluation} {
1.538 + list [catch {expr {1 || -"string"}} msg] $msg
1.539 +} {0 1}
1.540 +test expr-old-27.9 {cancelled evaluation} {
1.541 + list [catch {expr {1 || ("string" * ("x" && "y"))}} msg] $msg
1.542 +} {0 1}
1.543 +test expr-old-27.10 {cancelled evaluation} {
1.544 + set x -1.0
1.545 + list [catch {expr {($x > 0) ? round(log($x)) : 0}} msg] $msg
1.546 +} {0 0}
1.547 +test expr-old-27.11 {cancelled evaluation} {
1.548 + list [catch {expr {0 && foo}} msg] $msg
1.549 +} {1 {syntax error in expression "0 && foo": variable references require preceding $}}
1.550 +test expr-old-27.12 {cancelled evaluation} {
1.551 + list [catch {expr {0 ? 1 : foo}} msg] $msg
1.552 +} {1 {syntax error in expression "0 ? 1 : foo": variable references require preceding $}}
1.553 +
1.554 +# Tcl_ExprBool as used in "if" statements
1.555 +
1.556 +test expr-old-28.1 {Tcl_ExprBoolean usage} {
1.557 + set a 1
1.558 + if {2} {set a 2}
1.559 + set a
1.560 +} 2
1.561 +test expr-old-28.2 {Tcl_ExprBoolean usage} {
1.562 + set a 1
1.563 + if {0} {set a 2}
1.564 + set a
1.565 +} 1
1.566 +test expr-old-28.3 {Tcl_ExprBoolean usage} {
1.567 + set a 1
1.568 + if {1.2} {set a 2}
1.569 + set a
1.570 +} 2
1.571 +test expr-old-28.4 {Tcl_ExprBoolean usage} {
1.572 + set a 1
1.573 + if {-1.1} {set a 2}
1.574 + set a
1.575 +} 2
1.576 +test expr-old-28.5 {Tcl_ExprBoolean usage} {
1.577 + set a 1
1.578 + if {0.0} {set a 2}
1.579 + set a
1.580 +} 1
1.581 +test expr-old-28.6 {Tcl_ExprBoolean usage} {
1.582 + set a 1
1.583 + if {"YES"} {set a 2}
1.584 + set a
1.585 +} 2
1.586 +test expr-old-28.7 {Tcl_ExprBoolean usage} {
1.587 + set a 1
1.588 + if {"no"} {set a 2}
1.589 + set a
1.590 +} 1
1.591 +test expr-old-28.8 {Tcl_ExprBoolean usage} {
1.592 + set a 1
1.593 + if {"true"} {set a 2}
1.594 + set a
1.595 +} 2
1.596 +test expr-old-28.9 {Tcl_ExprBoolean usage} {
1.597 + set a 1
1.598 + if {"fAlse"} {set a 2}
1.599 + set a
1.600 +} 1
1.601 +test expr-old-28.10 {Tcl_ExprBoolean usage} {
1.602 + set a 1
1.603 + if {"on"} {set a 2}
1.604 + set a
1.605 +} 2
1.606 +test expr-old-28.11 {Tcl_ExprBoolean usage} {
1.607 + set a 1
1.608 + if {"Off"} {set a 2}
1.609 + set a
1.610 +} 1
1.611 +test expr-old-28.12 {Tcl_ExprBool usage} {
1.612 + list [catch {if {"abc"} {}} msg] $msg
1.613 +} {1 {expected boolean value but got "abc"}}
1.614 +test expr-old-28.13 {Tcl_ExprBool usage} {
1.615 + list [catch {if {"ogle"} {}} msg] $msg
1.616 +} {1 {expected boolean value but got "ogle"}}
1.617 +test expr-old-28.14 {Tcl_ExprBool usage} {
1.618 + list [catch {if {"o"} {}} msg] $msg
1.619 +} {1 {expected boolean value but got "o"}}
1.620 +
1.621 +# Operands enclosed in braces
1.622 +
1.623 +test expr-old-29.1 {braces} {expr {{abc}}} abc
1.624 +test expr-old-29.2 {braces} {expr {{00010}}} 8
1.625 +test expr-old-29.3 {braces} {expr {{3.1200000}}} 3.12
1.626 +test expr-old-29.4 {braces} {expr {{a{b}{1 {2 3}}c}}} "a{b}{1 {2 3}}c"
1.627 +test expr-old-29.5 {braces} {
1.628 + list [catch {expr "\{abc"} msg] $msg
1.629 +} {1 {missing close-brace}}
1.630 +
1.631 +# Very long values
1.632 +
1.633 +test expr-old-30.1 {long values} {
1.634 + set a "0000 1111 2222 3333 4444"
1.635 + set a "$a | $a | $a | $a | $a"
1.636 + set a "$a || $a || $a || $a || $a"
1.637 + expr {$a}
1.638 +} {0000 1111 2222 3333 4444 | 0000 1111 2222 3333 4444 | 0000 1111 2222 3333 4444 | 0000 1111 2222 3333 4444 | 0000 1111 2222 3333 4444 || 0000 1111 2222 3333 4444 | 0000 1111 2222 3333 4444 | 0000 1111 2222 3333 4444 | 0000 1111 2222 3333 4444 | 0000 1111 2222 3333 4444 || 0000 1111 2222 3333 4444 | 0000 1111 2222 3333 4444 | 0000 1111 2222 3333 4444 | 0000 1111 2222 3333 4444 | 0000 1111 2222 3333 4444 || 0000 1111 2222 3333 4444 | 0000 1111 2222 3333 4444 | 0000 1111 2222 3333 4444 | 0000 1111 2222 3333 4444 | 0000 1111 2222 3333 4444 || 0000 1111 2222 3333 4444 | 0000 1111 2222 3333 4444 | 0000 1111 2222 3333 4444 | 0000 1111 2222 3333 4444 | 0000 1111 2222 3333 4444}
1.639 +test expr-old-30.2 {long values} {
1.640 + set a "000000000000000000000000000000"
1.641 + set a "$a$a$a$a$a$a$a$a$a$a$a$a$a$a$a$a${a}5"
1.642 + expr $a
1.643 +} 5
1.644 +
1.645 +# Expressions spanning multiple arguments
1.646 +
1.647 +test expr-old-31.1 {multiple arguments to expr command} {
1.648 + expr 4 + ( 6 *12) -3
1.649 +} 73
1.650 +test expr-old-31.2 {multiple arguments to expr command} {
1.651 + list [catch {expr 2 + (3 + 4} msg] $msg
1.652 +} {1 {syntax error in expression "2 + (3 + 4": looking for close parenthesis}}
1.653 +test expr-old-31.3 {multiple arguments to expr command} {
1.654 + list [catch {expr 2 + 3 +} msg] $msg
1.655 +} {1 {syntax error in expression "2 + 3 +": premature end of expression}}
1.656 +test expr-old-31.4 {multiple arguments to expr command} {
1.657 + list [catch {expr 2 + 3 )} msg] $msg
1.658 +} {1 {syntax error in expression "2 + 3 )": extra tokens at end of expression}}
1.659 +
1.660 +# Math functions
1.661 +
1.662 +test expr-old-32.1 {math functions in expressions} {
1.663 + format %.6g [expr acos(0.5)]
1.664 +} {1.0472}
1.665 +test expr-old-32.2 {math functions in expressions} {
1.666 + format %.6g [expr asin(0.5)]
1.667 +} {0.523599}
1.668 +test expr-old-32.3 {math functions in expressions} {
1.669 + format %.6g [expr atan(1.0)]
1.670 +} {0.785398}
1.671 +test expr-old-32.4 {math functions in expressions} {
1.672 + format %.6g [expr atan2(2.0, 2.0)]
1.673 +} {0.785398}
1.674 +test expr-old-32.5 {math functions in expressions} {
1.675 + format %.6g [expr ceil(1.999)]
1.676 +} {2}
1.677 +test expr-old-32.6 {math functions in expressions} {
1.678 + format %.6g [expr cos(.1)]
1.679 +} {0.995004}
1.680 +test expr-old-32.7 {math functions in expressions} {
1.681 + format %.6g [expr cosh(.1)]
1.682 +} {1.005}
1.683 +test expr-old-32.8 {math functions in expressions} {
1.684 + format %.6g [expr exp(1.0)]
1.685 +} {2.71828}
1.686 +test expr-old-32.9 {math functions in expressions} {
1.687 + format %.6g [expr floor(2.000)]
1.688 +} {2}
1.689 +test expr-old-32.10 {math functions in expressions} {
1.690 + format %.6g [expr floor(2.001)]
1.691 +} {2}
1.692 +test expr-old-32.11 {math functions in expressions} {
1.693 + format %.6g [expr fmod(7.3, 3.2)]
1.694 +} {0.9}
1.695 +test expr-old-32.12 {math functions in expressions} {
1.696 + format %.6g [expr hypot(3.0, 4.0)]
1.697 +} {5}
1.698 +test expr-old-32.13 {math functions in expressions} {
1.699 + format %.6g [expr log(2.8)]
1.700 +} {1.02962}
1.701 +test expr-old-32.14 {math functions in expressions} {
1.702 + format %.6g [expr log10(2.8)]
1.703 +} {0.447158}
1.704 +test expr-old-32.15 {math functions in expressions} {
1.705 + format %.6g [expr pow(2.1, 3.1)]
1.706 +} {9.97424}
1.707 +test expr-old-32.16 {math functions in expressions} {
1.708 + format %.6g [expr sin(.1)]
1.709 +} {0.0998334}
1.710 +test expr-old-32.17 {math functions in expressions} {
1.711 + format %.6g [expr sinh(.1)]
1.712 +} {0.100167}
1.713 +test expr-old-32.18 {math functions in expressions} {
1.714 + format %.6g [expr sqrt(2.0)]
1.715 +} {1.41421}
1.716 +test expr-old-32.19 {math functions in expressions} {
1.717 + format %.6g [expr tan(0.8)]
1.718 +} {1.02964}
1.719 +test expr-old-32.20 {math functions in expressions} {
1.720 + format %.6g [expr tanh(0.8)]
1.721 +} {0.664037}
1.722 +test expr-old-32.21 {math functions in expressions} {
1.723 + format %.6g [expr abs(-1.8)]
1.724 +} {1.8}
1.725 +test expr-old-32.22 {math functions in expressions} {
1.726 + expr abs(10.0)
1.727 +} {10.0}
1.728 +test expr-old-32.23 {math functions in expressions} {
1.729 + format %.6g [expr abs(-4)]
1.730 +} {4}
1.731 +test expr-old-32.24 {math functions in expressions} {
1.732 + format %.6g [expr abs(66)]
1.733 +} {66}
1.734 +
1.735 +# The following test is different for 32-bit versus 64-bit architectures.
1.736 +
1.737 +if {0x80000000 > 0} {
1.738 + test expr-old-32.25 {math functions in expressions} {nonPortable} {
1.739 + list [catch {expr abs(0x8000000000000000)} msg] $msg
1.740 + } {1 {integer value too large to represent}}
1.741 +} else {
1.742 + test expr-old-32.25 {math functions in expressions} {nonPortable} {
1.743 + list [catch {expr abs(0x80000000)} msg] $msg
1.744 + } {1 {integer value too large to represent}}
1.745 +}
1.746 +
1.747 +test expr-old-32.26 {math functions in expressions} {
1.748 + expr double(1)
1.749 +} {1.0}
1.750 +test expr-old-32.27 {math functions in expressions} {
1.751 + expr double(1.1)
1.752 +} {1.1}
1.753 +test expr-old-32.28 {math functions in expressions} {
1.754 + expr int(1)
1.755 +} {1}
1.756 +test expr-old-32.29 {math functions in expressions} {
1.757 + expr int(1.4)
1.758 +} {1}
1.759 +test expr-old-32.30 {math functions in expressions} {
1.760 + expr int(1.6)
1.761 +} {1}
1.762 +test expr-old-32.31 {math functions in expressions} {
1.763 + expr int(-1.4)
1.764 +} {-1}
1.765 +test expr-old-32.32 {math functions in expressions} {
1.766 + expr int(-1.6)
1.767 +} {-1}
1.768 +test expr-old-32.33 {math functions in expressions} {
1.769 + list [catch {expr int(1e60)} msg] $msg
1.770 +} {1 {integer value too large to represent}}
1.771 +test expr-old-32.34 {math functions in expressions} {
1.772 + list [catch {expr int(-1e60)} msg] $msg
1.773 +} {1 {integer value too large to represent}}
1.774 +test expr-old-32.35 {math functions in expressions} {
1.775 + expr round(1.49)
1.776 +} {1}
1.777 +test expr-old-32.36 {math functions in expressions} {
1.778 + expr round(1.51)
1.779 +} {2}
1.780 +test expr-old-32.37 {math functions in expressions} {
1.781 + expr round(-1.49)
1.782 +} {-1}
1.783 +test expr-old-32.38 {math functions in expressions} {
1.784 + expr round(-1.51)
1.785 +} {-2}
1.786 +test expr-old-32.39 {math functions in expressions} {
1.787 + list [catch {expr round(1e60)} msg] $msg
1.788 +} {1 {integer value too large to represent}}
1.789 +test expr-old-32.40 {math functions in expressions} {
1.790 + list [catch {expr round(-1e60)} msg] $msg
1.791 +} {1 {integer value too large to represent}}
1.792 +test expr-old-32.41 {math functions in expressions} {
1.793 + list [catch {expr pow(1.0 + 3.0 - 2, .8 * 5)} msg] $msg
1.794 +} {0 16.0}
1.795 +test expr-old-32.42 {math functions in expressions} {
1.796 + list [catch {expr hypot(5*.8,3)} msg] $msg
1.797 +} {0 5.0}
1.798 +if $gotT1 {
1.799 + test expr-old-32.43 {math functions in expressions} {
1.800 + expr 2*T1()
1.801 + } 246
1.802 + test expr-old-32.44 {math functions in expressions} {
1.803 + expr T2()*3
1.804 + } 1035
1.805 +}
1.806 +test expr-old-32.45 {math functions in expressions} {
1.807 + expr (0 <= rand()) && (rand() < 1)
1.808 +} {1}
1.809 +test expr-old-32.46 {math functions in expressions} {
1.810 + list [catch {expr rand(24)} msg] $msg
1.811 +} {1 {too many arguments for math function}}
1.812 +test expr-old-32.47 {math functions in expressions} {
1.813 + list [catch {expr srand()} msg] $msg
1.814 +} {1 {too few arguments for math function}}
1.815 +test expr-old-32.48 {math functions in expressions} {
1.816 + list [catch {expr srand(3.79)} msg] $msg
1.817 +} {1 {expected integer but got "3.79"}}
1.818 +test expr-old-32.49 {math functions in expressions} {
1.819 + list [catch {expr srand("")} msg] $msg
1.820 +} {1 {argument to math function didn't have numeric value}}
1.821 +test expr-old-32.50 {math functions in expressions} {
1.822 + set result [expr round(srand(12345) * 1000)]
1.823 + for {set i 0} {$i < 10} {incr i} {
1.824 + lappend result [expr round(rand() * 1000)]
1.825 + }
1.826 + set result
1.827 +} {97 834 948 36 12 51 766 585 914 784 333}
1.828 +test expr-old-32.51 {math functions in expressions} {
1.829 + list [catch {expr {srand([lindex "6ty" 0])}} msg] $msg
1.830 +} {1 {argument to math function didn't have numeric value}}
1.831 +test expr-old-32.52 {math functions in expressions} {
1.832 + expr {srand(int(1<<37)) < 1}
1.833 +} {1}
1.834 +test expr-old-32.53 {math functions in expressions} {
1.835 + expr {srand((1<<31) - 1) > 0}
1.836 +} {1}
1.837 +
1.838 +test expr-old-33.1 {conversions and fancy args to math functions} {
1.839 + expr hypot ( 3 , 4 )
1.840 +} 5.0
1.841 +test expr-old-33.2 {conversions and fancy args to math functions} {
1.842 + expr hypot ( (2.0+1.0) , 4 )
1.843 +} 5.0
1.844 +test expr-old-33.3 {conversions and fancy args to math functions} {
1.845 + expr hypot ( 3 , (3.0 + 1.0) )
1.846 +} 5.0
1.847 +test expr-old-33.4 {conversions and fancy args to math functions} {
1.848 + format %.6g [expr cos(acos(0.1))]
1.849 +} 0.1
1.850 +
1.851 +test expr-old-34.1 {errors in math functions} {
1.852 + list [catch {expr func_2(1.0)} msg] $msg
1.853 +} {1 {unknown math function "func_2"}}
1.854 +test expr-old-34.2 {errors in math functions} {
1.855 + list [catch {expr func|(1.0)} msg] $msg
1.856 +} {1 {syntax error in expression "func|(1.0)": variable references require preceding $}}
1.857 +test expr-old-34.3 {errors in math functions} {
1.858 + list [catch {expr {hypot("a b", 2.0)}} msg] $msg
1.859 +} {1 {argument to math function didn't have numeric value}}
1.860 +test expr-old-34.4 {errors in math functions} {
1.861 + list [catch {expr hypot(1.0 2.0)} msg] $msg
1.862 +} {1 {syntax error in expression "hypot(1.0 2.0)": missing close parenthesis at end of function call}}
1.863 +test expr-old-34.5 {errors in math functions} {
1.864 + list [catch {expr hypot(1.0, 2.0} msg] $msg
1.865 +} {1 {syntax error in expression "hypot(1.0, 2.0": missing close parenthesis at end of function call}}
1.866 +test expr-old-34.6 {errors in math functions} {
1.867 + list [catch {expr hypot(1.0 ,} msg] $msg
1.868 +} {1 {syntax error in expression "hypot(1.0 ,": premature end of expression}}
1.869 +test expr-old-34.7 {errors in math functions} {
1.870 + list [catch {expr hypot(1.0)} msg] $msg
1.871 +} {1 {too few arguments for math function}}
1.872 +test expr-old-34.8 {errors in math functions} {
1.873 + list [catch {expr hypot(1.0, 2.0, 3.0)} msg] $msg
1.874 +} {1 {too many arguments for math function}}
1.875 +test expr-old-34.9 {errors in math functions} {
1.876 + list [catch {expr acos(-2.0)} msg] $msg $errorCode
1.877 +} {1 {domain error: argument not in valid range} {ARITH DOMAIN {domain error: argument not in valid range}}}
1.878 +test expr-old-34.10 {errors in math functions} {nonPortable} {
1.879 + list [catch {expr pow(-3, 1000001)} msg] $msg $errorCode
1.880 +} {1 {floating-point value too large to represent} {ARITH OVERFLOW {floating-point value too large to represent}}}
1.881 +test expr-old-34.11 {errors in math functions} {
1.882 + list [catch {expr pow(3, 1000001)} msg] $msg $errorCode
1.883 +} {1 {floating-point value too large to represent} {ARITH OVERFLOW {floating-point value too large to represent}}}
1.884 +test expr-old-34.12 {errors in math functions} {
1.885 + list [catch {expr -14.0*exp(100000)} msg] $msg $errorCode
1.886 +} {1 {floating-point value too large to represent} {ARITH OVERFLOW {floating-point value too large to represent}}}
1.887 +test expr-old-34.13 {errors in math functions} {
1.888 + list [catch {expr int(1.0e30)} msg] $msg $errorCode
1.889 +} {1 {integer value too large to represent} {ARITH IOVERFLOW {integer value too large to represent}}}
1.890 +test expr-old-34.14 {errors in math functions} {
1.891 + list [catch {expr int(-1.0e30)} msg] $msg $errorCode
1.892 +} {1 {integer value too large to represent} {ARITH IOVERFLOW {integer value too large to represent}}}
1.893 +test expr-old-34.15 {errors in math functions} {
1.894 + list [catch {expr round(1.0e30)} msg] $msg $errorCode
1.895 +} {1 {integer value too large to represent} {ARITH IOVERFLOW {integer value too large to represent}}}
1.896 +test expr-old-34.16 {errors in math functions} {
1.897 + list [catch {expr round(-1.0e30)} msg] $msg $errorCode
1.898 +} {1 {integer value too large to represent} {ARITH IOVERFLOW {integer value too large to represent}}}
1.899 +if $gotT1 {
1.900 + test expr-old-34.17 {errors in math functions} {
1.901 + list [catch {expr T1(4)} msg] $msg
1.902 + } {1 {too many arguments for math function}}
1.903 +}
1.904 +
1.905 +test expr-old-36.1 {ExprLooksLikeInt procedure} -body {
1.906 + expr 0289
1.907 +} -returnCodes error -match glob -result {*invalid octal number*}
1.908 +test expr-old-36.2 {ExprLooksLikeInt procedure} {
1.909 + set x 0289
1.910 + list [catch {expr {$x+1}} msg] $msg
1.911 +} {1 {can't use invalid octal number as operand of "+"}}
1.912 +test expr-old-36.3 {ExprLooksLikeInt procedure} {
1.913 + list [catch {expr 0289.1} msg] $msg
1.914 +} {0 289.1}
1.915 +test expr-old-36.4 {ExprLooksLikeInt procedure} {
1.916 + set x 0289.1
1.917 + list [catch {expr {$x+1}} msg] $msg
1.918 +} {0 290.1}
1.919 +test expr-old-36.5 {ExprLooksLikeInt procedure} {
1.920 + set x { +22}
1.921 + list [catch {expr {$x+1}} msg] $msg
1.922 +} {0 23}
1.923 +test expr-old-36.6 {ExprLooksLikeInt procedure} {
1.924 + set x { -22}
1.925 + list [catch {expr {$x+1}} msg] $msg
1.926 +} {0 -21}
1.927 +test expr-old-36.7 {ExprLooksLikeInt procedure} {nonPortable unixOnly} {
1.928 + list [catch {expr nan} msg] $msg
1.929 +} {1 {domain error: argument not in valid range}}
1.930 +test expr-old-36.8 {ExprLooksLikeInt procedure} {
1.931 + list [catch {expr 78e1} msg] $msg
1.932 +} {0 780.0}
1.933 +test expr-old-36.9 {ExprLooksLikeInt procedure} {
1.934 + list [catch {expr 24E1} msg] $msg
1.935 +} {0 240.0}
1.936 +test expr-old-36.10 {ExprLooksLikeInt procedure} {nonPortable unixOnly} {
1.937 + list [catch {expr 78e} msg] $msg
1.938 +} {1 {syntax error in expression "78e"}}
1.939 +
1.940 +# test for [Bug #542588]
1.941 +test expr-old-36.11 {ExprLooksLikeInt procedure} {
1.942 + # define a "too large integer"; this one works also for 64bit arith
1.943 + set x 665802003400000000000000
1.944 + list [catch {expr {$x+1}} msg] $msg
1.945 +} {1 {can't use integer value too large to represent as operand of "+"}}
1.946 +
1.947 +# tests for [Bug #587140]
1.948 +test expr-old-36.12 {ExprLooksLikeInt procedure} {
1.949 + set x "10;"
1.950 + list [catch {expr {$x+1}} msg] $msg
1.951 +} {1 {can't use non-numeric string as operand of "+"}}
1.952 +test expr-old-36.13 {ExprLooksLikeInt procedure} {
1.953 + set x " +"
1.954 + list [catch {expr {$x+1}} msg] $msg
1.955 +} {1 {can't use non-numeric string as operand of "+"}}
1.956 +test expr-old-36.14 {ExprLooksLikeInt procedure} {
1.957 + set x "123456789012345678901234567890 "
1.958 + list [catch {expr {$x+1}} msg] $msg
1.959 +} {1 {can't use integer value too large to represent as operand of "+"}}
1.960 +test expr-old-36.15 {ExprLooksLikeInt procedure} {
1.961 + set x "099 "
1.962 + list [catch {expr {$x+1}} msg] $msg
1.963 +} {1 {can't use invalid octal number as operand of "+"}}
1.964 +test expr-old-36.16 {ExprLooksLikeInt procedure} {
1.965 + set x " 0xffffffffffffffffffffffffffffffffffffff "
1.966 + list [catch {expr {$x+1}} msg] $msg
1.967 +} {1 {can't use integer value too large to represent as operand of "+"}}
1.968 +
1.969 +if {[info commands testexprlong] == {}} {
1.970 + puts "This application hasn't been compiled with the \"testexprlong\""
1.971 + puts "command, so I can't test Tcl_ExprLong etc."
1.972 +} else {
1.973 +test expr-old-37.1 {Check that Tcl_ExprLong doesn't modify interpreter result if no error} {
1.974 + testexprlong
1.975 +} {This is a result: 5}
1.976 +}
1.977 +
1.978 +if {[info commands testexprstring] == {}} {
1.979 + puts "This application hasn't been compiled with the \"testexprstring\""
1.980 + puts "command, so I can't test Tcl_ExprString etc."
1.981 +} else {
1.982 +test expr-old-38.1 {Verify Tcl_ExprString's basic operation} {
1.983 + list [testexprstring "1+4"] [testexprstring "2*3+4.2"] \
1.984 + [catch {testexprstring "1+"} msg] $msg
1.985 +} {5 10.2 1 {syntax error in expression "1+": premature end of expression}}
1.986 +}
1.987 +
1.988 +#
1.989 +# Test for bug #908375: rounding numbers that do not fit in a
1.990 +# long but do fit in a wide
1.991 +#
1.992 +
1.993 +test expr-old-39.1 {Rounding with wide result} {
1.994 + set x 1.0e10
1.995 + set y [expr $x + 0.1]
1.996 + catch {
1.997 + set x [list [expr {$x == round($y)}] [expr $x == -round(-$y)]]
1.998 + }
1.999 + set x
1.1000 +} {1 1}
1.1001 +unset -nocomplain x y
1.1002 +
1.1003 +# Special test for Pentium arithmetic bug of 1994:
1.1004 +
1.1005 +if {(4195835.0 - (4195835.0/3145727.0)*3145727.0) == 256.0} {
1.1006 + puts "Warning: this machine contains a defective Pentium processor"
1.1007 + puts "that performs arithmetic incorrectly. I recommend that you"
1.1008 + puts "call Intel customer service immediately at 1-800-628-8686"
1.1009 + puts "to request a replacement processor."
1.1010 +}
1.1011 +
1.1012 +# cleanup
1.1013 +::tcltest::cleanupTests
1.1014 +return