diff options
Diffstat (limited to 'tests/expr-old.test')
-rw-r--r-- | tests/expr-old.test | 538 |
1 files changed, 368 insertions, 170 deletions
diff --git a/tests/expr-old.test b/tests/expr-old.test index 85e346a..40a38dd 100644 --- a/tests/expr-old.test +++ b/tests/expr-old.test @@ -13,20 +13,81 @@ # See the file "license.terms" for information on usage and redistribution # of this file, and for a DISCLAIMER OF ALL WARRANTIES. # -# RCS: @(#) $Id: expr-old.test,v 1.16.2.5 2006/05/04 12:34:39 dgp Exp $ +# RCS: @(#) $Id: expr-old.test,v 1.40 2007/12/13 15:26:06 dgp Exp $ if {[lsearch [namespace children] ::tcltest] == -1} { package require tcltest 2.1 namespace import -force ::tcltest::* } -if {([catch {expr T1()} msg] == 1) && ($msg == {unknown math function "T1"})} { - set gotT1 0 - puts "This application hasn't been compiled with the \"T1\" and" - puts "\"T2\" math functions, so I'll skip some of the expr tests." +testConstraint testexprlong [llength [info commands testexprlong]] +testConstraint testexprdouble [llength [info commands testexprdouble]] +testConstraint testexprstring [llength [info commands testexprstring]] +testConstraint longIs32bit [expr {int(0x80000000) < 0}] + +if {[catch {expr T1()} msg] && $msg eq {invalid command name "tcl::mathfunc::T1"}} { + testConstraint testmathfunctions 0 } else { - set gotT1 1 + testConstraint testmathfunctions 1 +} + +# Big test for correct ordering of data in [expr] + +proc testIEEE {} { + variable ieeeValues + binary scan [binary format dd -1.0 1.0] c* c + switch -exact -- $c { + {0 0 0 0 0 0 -16 -65 0 0 0 0 0 0 -16 63} { + # little endian + binary scan \x00\x00\x00\x00\x00\x00\xf0\xff d \ + ieeeValues(-Infinity) + binary scan \x00\x00\x00\x00\x00\x00\xf0\xbf d \ + ieeeValues(-Normal) + binary scan \x00\x00\x00\x00\x00\x00\x08\x80 d \ + ieeeValues(-Subnormal) + binary scan \x00\x00\x00\x00\x00\x00\x00\x80 d \ + ieeeValues(-0) + binary scan \x00\x00\x00\x00\x00\x00\x00\x00 d \ + ieeeValues(+0) + binary scan \x00\x00\x00\x00\x00\x00\x08\x00 d \ + ieeeValues(+Subnormal) + binary scan \x00\x00\x00\x00\x00\x00\xf0\x3f d \ + ieeeValues(+Normal) + binary scan \x00\x00\x00\x00\x00\x00\xf0\x7f d \ + ieeeValues(+Infinity) + binary scan \x00\x00\x00\x00\x00\x00\xf8\x7f d \ + ieeeValues(NaN) + set ieeeValues(littleEndian) 1 + return 1 + } + {-65 -16 0 0 0 0 0 0 63 -16 0 0 0 0 0 0} { + binary scan \xff\xf0\x00\x00\x00\x00\x00\x00 d \ + ieeeValues(-Infinity) + binary scan \xbf\xf0\x00\x00\x00\x00\x00\x00 d \ + ieeeValues(-Normal) + binary scan \x80\x08\x00\x00\x00\x00\x00\x00 d \ + ieeeValues(-Subnormal) + binary scan \x80\x00\x00\x00\x00\x00\x00\x00 d \ + ieeeValues(-0) + binary scan \x00\x00\x00\x00\x00\x00\x00\x00 d \ + ieeeValues(+0) + binary scan \x00\x08\x00\x00\x00\x00\x00\x00 d \ + ieeeValues(+Subnormal) + binary scan \x3f\xf0\x00\x00\x00\x00\x00\x00 d \ + ieeeValues(+Normal) + binary scan \x7f\xf0\x00\x00\x00\x00\x00\x00 d \ + ieeeValues(+Infinity) + binary scan \x7f\xf8\x00\x00\x00\x00\x00\x00 d \ + ieeeValues(NaN) + set ieeeValues(littleEndian) 0 + return 1 + } + default { + return 0 + } + } } +testConstraint ieeeFloatingPoint [testIEEE] # First, test all of the integer operators individually. @@ -93,7 +154,7 @@ test expr-old-1.53 {integer operators} { # automatic conversion to integers where needed. test expr-old-2.1 {floating-point operators} {expr -4.2} -4.2 -test expr-old-2.2 {floating-point operators} {expr -(1.1+4.2)} -5.3 +test expr-old-2.2 {floating-point operators} {expr -(1.125+4.25)} -5.375 test expr-old-2.3 {floating-point operators} {expr +5.7} 5.7 test expr-old-2.4 {floating-point operators} {expr +--+-62.0} -62.0 test expr-old-2.5 {floating-point operators} {expr !2.1} 0 @@ -196,12 +257,8 @@ test expr-old-4.25 {string operators} {expr {"abd" ne ""}} 1 test expr-old-4.26 {string operators} {expr {"" ne ""}} 0 test expr-old-4.27 {string operators} {expr {"longerstring" eq "shorter"}} 0 test expr-old-4.28 {string operators} {expr {"longerstring" ne "shorter"}} 1 - -# The following tests are non-portable because on some systems "+" -# and "-" can be parsed as numbers. - -test expr-old-4.29 {string operators} {nonPortable} {expr {"0" == "+"}} 0 -test expr-old-4.30 {string operators} {nonPortable} {expr {"0" == "-"}} 0 +test expr-old-4.29 {string operators} {expr {"0" == "+"}} 0 +test expr-old-4.30 {string operators} {expr {"0" == "-"}} 0 test expr-old-4.31 {string operators} {expr {1?"foo":"bar"}} foo test expr-old-4.32 {string operators} {expr {0?"foo":"bar"}} bar @@ -408,7 +465,7 @@ test expr-old-23.8 {double quotes} { # Numbers in various bases. test expr-old-24.1 {numbers in different bases} {expr 0x20} 32 -test expr-old-24.2 {numbers in different bases} {expr 015} 13 +test expr-old-24.2 {numbers in different bases} {expr 0o15} 13 # Conversions between various data types. @@ -430,7 +487,7 @@ test expr-old-25.15 {type conversions} {expr {24.1 > "24.1a"}} 0 test expr-old-25.16 {type conversions} {expr 2+2.5} 4.5 test expr-old-25.17 {type conversions} {expr 2+2.5} 4.5 test expr-old-25.18 {type conversions} {expr 2.0e2} 200.0 -test expr-old-25.19 {type conversions} {eformat} {expr 2.0e15} 2e+15 +test expr-old-25.19 {type conversions} {expr 2.0e15} 2000000000000000.0 test expr-old-25.20 {type conversions} {expr 10.0} 10.0 # Various error conditions. @@ -438,12 +495,12 @@ test expr-old-25.20 {type conversions} {expr 10.0} 10.0 test expr-old-26.1 {error conditions} { list [catch {expr 2+"a"} msg] $msg } {1 {can't use non-numeric string as operand of "+"}} -test expr-old-26.2 {error conditions} { - list [catch {expr 2+4*} msg] $msg -} {1 {syntax error in expression "2+4*": premature end of expression}} -test expr-old-26.3 {error conditions} { - list [catch {expr 2+4*(} msg] $msg -} {1 {syntax error in expression "2+4*(": premature end of expression}} +test expr-old-26.2 {error conditions} -body { + expr 2+4* +} -returnCodes error -match glob -result * +test expr-old-26.3 {error conditions} -body { + expr 2+4*( +} -returnCodes error -match glob -result * catch {unset _non_existent_} test expr-old-26.4 {error conditions} { list [catch {expr 2+$_non_existent_} msg] $msg @@ -455,45 +512,48 @@ test expr-old-26.5 {error conditions} { test expr-old-26.6 {error conditions} { list [catch {expr {2+[set a]}} msg] $msg } {1 {can't use non-numeric string as operand of "+"}} -test expr-old-26.7 {error conditions} { - list [catch {expr {2+(4}} msg] $msg -} {1 {syntax error in expression "2+(4": looking for close parenthesis}} +test expr-old-26.7 {error conditions} -body { + expr {2+(4} +} -returnCodes error -match glob -result * test expr-old-26.8 {error conditions} { list [catch {expr 2/0} msg] $msg $errorCode } {1 {divide by zero} {ARITH DIVZERO {divide by zero}}} test expr-old-26.9 {error conditions} { list [catch {expr 2%0} msg] $msg $errorCode } {1 {divide by zero} {ARITH DIVZERO {divide by zero}}} -test expr-old-26.10 {error conditions} { +test expr-old-26.10a {error conditions} !ieeeFloatingPoint { list [catch {expr 2.0/0.0} msg] $msg $errorCode } {1 {divide by zero} {ARITH DIVZERO {divide by zero}}} -test expr-old-26.11 {error conditions} { - list [catch {expr 2#} msg] $msg -} {1 {syntax error in expression "2#": extra tokens at end of expression}} -test expr-old-26.12 {error conditions} { - list [catch {expr a.b} msg] $msg -} {1 {syntax error in expression "a.b": variable references require preceding $}} +test expr-old-26.10b {error conditions} ieeeFloatingPoint { + list [catch {expr 2.0/0.0} msg] $msg +} {0 Inf} +test expr-old-26.11 {error conditions} -body { + expr 2# +} -returnCodes error -match glob -result * +test expr-old-26.12 {error conditions} -body { + expr a.b +} -returnCodes error -match glob -result * test expr-old-26.13 {error conditions} { list [catch {expr {"a"/"b"}} msg] $msg } {1 {can't use non-numeric string as operand of "/"}} -test expr-old-26.14 {error conditions} { - list [catch {expr 2:3} msg] $msg -} {1 {syntax error in expression "2:3": extra tokens at end of expression}} -test expr-old-26.15 {error conditions} { - list [catch {expr a@b} msg] $msg -} {1 {syntax error in expression "a@b": variable references require preceding $}} +test expr-old-26.14 {error conditions} -body { + expr 2:3 +} -returnCodes error -match glob -result * +test expr-old-26.15 {error conditions} -body { + expr a@b +} -returnCodes error -match glob -result * test expr-old-26.16 {error conditions} { list [catch {expr a[b} msg] $msg } {1 {missing close-bracket}} -test expr-old-26.17 {error conditions} { - list [catch {expr a`b} msg] $msg -} {1 {syntax error in expression "a`b": variable references require preceding $}} -test expr-old-26.18 {error conditions} { - list [catch {expr \"a\"\{b} msg] $msg -} {1 syntax\ error\ in\ expression\ \"\"a\"\{b\":\ extra\ tokens\ at\ end\ of\ expression} -test expr-old-26.19 {error conditions} { - list [catch {expr a} msg] $msg -} {1 {syntax error in expression "a": variable references require preceding $}} +test expr-old-26.17 {error conditions} -body { + expr a`b +} -returnCodes error -match glob -result * +test expr-old-26.18 {error conditions} -body { + expr \"a\"\{b +} -returnCodes error -match glob -result * +test expr-old-26.19 {error conditions} -body { + expr a +} -returnCodes error -match glob -result * test expr-old-26.20 {error conditions} { list [catch expr msg] $msg } {1 {wrong # args: should be "expr arg ?arg ...?"}} @@ -541,12 +601,12 @@ test expr-old-27.10 {cancelled evaluation} { set x -1.0 list [catch {expr {($x > 0) ? round(log($x)) : 0}} msg] $msg } {0 0} -test expr-old-27.11 {cancelled evaluation} { - list [catch {expr {0 && foo}} msg] $msg -} {1 {syntax error in expression "0 && foo": variable references require preceding $}} -test expr-old-27.12 {cancelled evaluation} { - list [catch {expr {0 ? 1 : foo}} msg] $msg -} {1 {syntax error in expression "0 ? 1 : foo": variable references require preceding $}} +test expr-old-27.11 {cancelled evaluation} -body { + expr {0 && foo} +} -returnCodes error -match glob -result * +test expr-old-27.12 {cancelled evaluation} -body { + expr {0 ? 1 : foo} +} -returnCodes error -match glob -result * # Tcl_ExprBool as used in "if" statements @@ -618,12 +678,12 @@ test expr-old-28.14 {Tcl_ExprBool usage} { # Operands enclosed in braces test expr-old-29.1 {braces} {expr {{abc}}} abc -test expr-old-29.2 {braces} {expr {{00010}}} 8 +test expr-old-29.2 {braces} {expr {{0o0010}}} 8 test expr-old-29.3 {braces} {expr {{3.1200000}}} 3.12 test expr-old-29.4 {braces} {expr {{a{b}{1 {2 3}}c}}} "a{b}{1 {2 3}}c" -test expr-old-29.5 {braces} { - list [catch {expr "\{abc"} msg] $msg -} {1 {missing close-brace}} +test expr-old-29.5 {braces} -body { + expr "\{abc" +} -returnCodes error -match glob -result * # Very long values @@ -644,15 +704,15 @@ test expr-old-30.2 {long values} { test expr-old-31.1 {multiple arguments to expr command} { expr 4 + ( 6 *12) -3 } 73 -test expr-old-31.2 {multiple arguments to expr command} { - list [catch {expr 2 + (3 + 4} msg] $msg -} {1 {syntax error in expression "2 + (3 + 4": looking for close parenthesis}} -test expr-old-31.3 {multiple arguments to expr command} { - list [catch {expr 2 + 3 +} msg] $msg -} {1 {syntax error in expression "2 + 3 +": premature end of expression}} -test expr-old-31.4 {multiple arguments to expr command} { - list [catch {expr 2 + 3 )} msg] $msg -} {1 {syntax error in expression "2 + 3 )": extra tokens at end of expression}} +test expr-old-31.2 {multiple arguments to expr command} -body { + expr 2 + (3 + 4 +} -returnCodes error -match glob -result * +test expr-old-31.3 {multiple arguments to expr command} -body { + expr 2 + 3 + +} -returnCodes error -match glob -result * +test expr-old-31.4 {multiple arguments to expr command} -body { + expr 2 + 3 ) +} -returnCodes error -match glob -result * # Math functions @@ -729,17 +789,13 @@ test expr-old-32.24 {math functions in expressions} { format %.6g [expr abs(66)] } {66} -# The following test is different for 32-bit versus 64-bit architectures. +test expr-old-32.25a {math functions in expressions} { + expr abs(0x8000000000000000) +} [expr 1<<63] -if {0x80000000 > 0} { - test expr-old-32.25 {math functions in expressions} {nonPortable} { - list [catch {expr abs(0x8000000000000000)} msg] $msg - } {1 {integer value too large to represent}} -} else { - test expr-old-32.25 {math functions in expressions} {nonPortable} { - list [catch {expr abs(0x80000000)} msg] $msg - } {1 {integer value too large to represent}} -} +test expr-old-32.25b {math functions in expressions} { + expr abs(0x80000000) +} 2147483648 test expr-old-32.26 {math functions in expressions} { expr double(1) @@ -763,11 +819,11 @@ test expr-old-32.32 {math functions in expressions} { expr int(-1.6) } {-1} test expr-old-32.33 {math functions in expressions} { - list [catch {expr int(1e60)} msg] $msg -} {1 {integer value too large to represent}} + expr int(1e60) +} 0 test expr-old-32.34 {math functions in expressions} { - list [catch {expr int(-1e60)} msg] $msg -} {1 {integer value too large to represent}} + expr int(-1e60) +} 0 test expr-old-32.35 {math functions in expressions} { expr round(1.49) } {1} @@ -781,40 +837,38 @@ test expr-old-32.38 {math functions in expressions} { expr round(-1.51) } {-2} test expr-old-32.39 {math functions in expressions} { - list [catch {expr round(1e60)} msg] $msg -} {1 {integer value too large to represent}} + expr round(1e60) +} 999999999999999949387135297074018866963645011013410073083904 test expr-old-32.40 {math functions in expressions} { - list [catch {expr round(-1e60)} msg] $msg -} {1 {integer value too large to represent}} + expr round(-1e60) +} -999999999999999949387135297074018866963645011013410073083904 test expr-old-32.41 {math functions in expressions} { list [catch {expr pow(1.0 + 3.0 - 2, .8 * 5)} msg] $msg } {0 16.0} test expr-old-32.42 {math functions in expressions} { list [catch {expr hypot(5*.8,3)} msg] $msg } {0 5.0} -if $gotT1 { - test expr-old-32.43 {math functions in expressions} { - expr 2*T1() - } 246 - test expr-old-32.44 {math functions in expressions} { - expr T2()*3 - } 1035 -} +test expr-old-32.43 {math functions in expressions} testmathfunctions { + expr 2*T1() +} 246 +test expr-old-32.44 {math functions in expressions} testmathfunctions { + expr T2()*3 +} 1035 test expr-old-32.45 {math functions in expressions} { expr (0 <= rand()) && (rand() < 1) } {1} -test expr-old-32.46 {math functions in expressions} { +test expr-old-32.46 {math functions in expressions} -body { list [catch {expr rand(24)} msg] $msg -} {1 {too many arguments for math function}} -test expr-old-32.47 {math functions in expressions} { +} -match glob -result {1 {too many arguments for math function*}} +test expr-old-32.47 {math functions in expressions} -body { list [catch {expr srand()} msg] $msg -} {1 {too few arguments for math function}} -test expr-old-32.48 {math functions in expressions} { - list [catch {expr srand(3.79)} msg] $msg -} {1 {expected integer but got "3.79"}} -test expr-old-32.49 {math functions in expressions} { - list [catch {expr srand("")} msg] $msg -} {1 {argument to math function didn't have numeric value}} +} -match glob -result {1 {too few arguments for math function*}} +test expr-old-32.48 {math functions in expressions} -body { + expr srand(3.79) +} -returnCodes error -match glob -result * +test expr-old-32.49 {math functions in expressions} -body { + expr srand("") +} -returnCodes error -match glob -result * test expr-old-32.50 {math functions in expressions} { set result [expr round(srand(12345) * 1000)] for {set i 0} {$i < 10} {incr i} { @@ -822,9 +876,9 @@ test expr-old-32.50 {math functions in expressions} { } set result } {97 834 948 36 12 51 766 585 914 784 333} -test expr-old-32.51 {math functions in expressions} { - list [catch {expr {srand([lindex "6ty" 0])}} msg] $msg -} {1 {argument to math function didn't have numeric value}} +test expr-old-32.51 {math functions in expressions} -body { + expr {srand([lindex "6ty" 0])} +} -returnCodes error -match glob -result * test expr-old-32.52 {math functions in expressions} { expr {srand(int(1<<37)) < 1} } {1} @@ -845,65 +899,70 @@ test expr-old-33.4 {conversions and fancy args to math functions} { format %.6g [expr cos(acos(0.1))] } 0.1 -test expr-old-34.1 {errors in math functions} { +test expr-old-34.1 {errors in math functions} -body { list [catch {expr func_2(1.0)} msg] $msg -} {1 {unknown math function "func_2"}} -test expr-old-34.2 {errors in math functions} { - list [catch {expr func|(1.0)} msg] $msg -} {1 {syntax error in expression "func|(1.0)": variable references require preceding $}} +} -match glob -result {1 {* "*func_2"}} +test expr-old-34.2 {errors in math functions} -body { + expr func|(1.0) +} -returnCodes error -match glob -result * test expr-old-34.3 {errors in math functions} { list [catch {expr {hypot("a b", 2.0)}} msg] $msg -} {1 {argument to math function didn't have numeric value}} -test expr-old-34.4 {errors in math functions} { - list [catch {expr hypot(1.0 2.0)} msg] $msg -} {1 {syntax error in expression "hypot(1.0 2.0)": missing close parenthesis at end of function call}} -test expr-old-34.5 {errors in math functions} { - list [catch {expr hypot(1.0, 2.0} msg] $msg -} {1 {syntax error in expression "hypot(1.0, 2.0": missing close parenthesis at end of function call}} -test expr-old-34.6 {errors in math functions} { - list [catch {expr hypot(1.0 ,} msg] $msg -} {1 {syntax error in expression "hypot(1.0 ,": premature end of expression}} -test expr-old-34.7 {errors in math functions} { +} {1 {expected floating-point number but got "a b"}} +test expr-old-34.4 {errors in math functions} -body { + expr hypot(1.0 2.0) +} -returnCodes error -match glob -result * +test expr-old-34.5 {errors in math functions} -body { + expr hypot(1.0, 2.0 +} -returnCodes error -match glob -result * +test expr-old-34.6 {errors in math functions} -body { + expr hypot(1.0 , +} -returnCodes error -match glob -result * +test expr-old-34.7 {errors in math functions} -body { list [catch {expr hypot(1.0)} msg] $msg -} {1 {too few arguments for math function}} -test expr-old-34.8 {errors in math functions} { +} -match glob -result {1 {too few arguments for math function*}} +test expr-old-34.8 {errors in math functions} -body { list [catch {expr hypot(1.0, 2.0, 3.0)} msg] $msg -} {1 {too many arguments for math function}} +} -match glob -result {1 {too many arguments for math function*}} test expr-old-34.9 {errors in math functions} { list [catch {expr acos(-2.0)} msg] $msg $errorCode } {1 {domain error: argument not in valid range} {ARITH DOMAIN {domain error: argument not in valid range}}} -test expr-old-34.10 {errors in math functions} {nonPortable} { - list [catch {expr pow(-3, 1000001)} msg] $msg $errorCode -} {1 {floating-point value too large to represent} {ARITH OVERFLOW {floating-point value too large to represent}}} -test expr-old-34.11 {errors in math functions} { +test expr-old-34.10 {errors in math functions} { + list [catch {expr pow(-3, 1000001)} msg] $msg +} {0 -Inf} +test expr-old-34.11a {errors in math functions} !ieeeFloatingPoint { list [catch {expr pow(3, 1000001)} msg] $msg $errorCode } {1 {floating-point value too large to represent} {ARITH OVERFLOW {floating-point value too large to represent}}} -test expr-old-34.12 {errors in math functions} { +test expr-old-34.11b {errors in math functions} ieeeFloatingPoint { + list [catch {expr pow(3, 1000001)} msg] $msg +} {0 Inf} +test expr-old-34.12a {errors in math functions} !ieeeFloatingPoint { list [catch {expr -14.0*exp(100000)} msg] $msg $errorCode } {1 {floating-point value too large to represent} {ARITH OVERFLOW {floating-point value too large to represent}}} +test expr-old-34.12b {errors in math functions} ieeeFloatingPoint { + list [catch {expr -14.0*exp(100000)} msg] $msg +} {0 -Inf} test expr-old-34.13 {errors in math functions} { - list [catch {expr int(1.0e30)} msg] $msg $errorCode -} {1 {integer value too large to represent} {ARITH IOVERFLOW {integer value too large to represent}}} + expr wide(1.0e30) +} 5076964154930102272 test expr-old-34.14 {errors in math functions} { - list [catch {expr int(-1.0e30)} msg] $msg $errorCode -} {1 {integer value too large to represent} {ARITH IOVERFLOW {integer value too large to represent}}} + expr wide(-1.0e30) +} -5076964154930102272 test expr-old-34.15 {errors in math functions} { - list [catch {expr round(1.0e30)} msg] $msg $errorCode -} {1 {integer value too large to represent} {ARITH IOVERFLOW {integer value too large to represent}}} + expr round(1.0e30) +} 1000000000000000019884624838656 test expr-old-34.16 {errors in math functions} { - list [catch {expr round(-1.0e30)} msg] $msg $errorCode -} {1 {integer value too large to represent} {ARITH IOVERFLOW {integer value too large to represent}}} -if $gotT1 { - test expr-old-34.17 {errors in math functions} { - list [catch {expr T1(4)} msg] $msg - } {1 {too many arguments for math function}} -} + expr round(-1.0e30) +} -1000000000000000019884624838656 +test expr-old-34.17 {errors in math functions} -constraints testmathfunctions \ + -body { + list [catch {expr T1(4)} msg] $msg + } -match glob -result {1 {too many arguments for math function*}} test expr-old-36.1 {ExprLooksLikeInt procedure} -body { - expr 0289 + expr 0o289 } -returnCodes error -match glob -result {*invalid octal number*} test expr-old-36.2 {ExprLooksLikeInt procedure} { - set x 0289 + set x 0o289 list [catch {expr {$x+1}} msg] $msg } {1 {can't use invalid octal number as operand of "+"}} test expr-old-36.3 {ExprLooksLikeInt procedure} { @@ -921,7 +980,7 @@ test expr-old-36.6 {ExprLooksLikeInt procedure} { set x { -22} list [catch {expr {$x+1}} msg] $msg } {0 -21} -test expr-old-36.7 {ExprLooksLikeInt procedure} {nonPortable unixOnly} { +test expr-old-36.7 {ExprLooksLikeInt procedure} { list [catch {expr nan} msg] $msg } {1 {domain error: argument not in valid range}} test expr-old-36.8 {ExprLooksLikeInt procedure} { @@ -930,16 +989,16 @@ test expr-old-36.8 {ExprLooksLikeInt procedure} { test expr-old-36.9 {ExprLooksLikeInt procedure} { list [catch {expr 24E1} msg] $msg } {0 240.0} -test expr-old-36.10 {ExprLooksLikeInt procedure} {nonPortable unixOnly} { - list [catch {expr 78e} msg] $msg -} {1 {syntax error in expression "78e"}} +test expr-old-36.10 {ExprLooksLikeInt procedure} -body { + expr 78e +} -returnCodes error -match glob -result * # test for [Bug #542588] test expr-old-36.11 {ExprLooksLikeInt procedure} { # define a "too large integer"; this one works also for 64bit arith set x 665802003400000000000000 - list [catch {expr {$x+1}} msg] $msg -} {1 {can't use integer value too large to represent as operand of "+"}} + expr {$x+1} +} 665802003400000000000001 # tests for [Bug #587140] test expr-old-36.12 {ExprLooksLikeInt procedure} { @@ -952,35 +1011,128 @@ test expr-old-36.13 {ExprLooksLikeInt procedure} { } {1 {can't use non-numeric string as operand of "+"}} test expr-old-36.14 {ExprLooksLikeInt procedure} { set x "123456789012345678901234567890 " - list [catch {expr {$x+1}} msg] $msg -} {1 {can't use integer value too large to represent as operand of "+"}} + expr {$x+1} +} 123456789012345678901234567891 test expr-old-36.15 {ExprLooksLikeInt procedure} { - set x "099 " + set x "0o99 " list [catch {expr {$x+1}} msg] $msg } {1 {can't use invalid octal number as operand of "+"}} test expr-old-36.16 {ExprLooksLikeInt procedure} { set x " 0xffffffffffffffffffffffffffffffffffffff " - list [catch {expr {$x+1}} msg] $msg -} {1 {can't use integer value too large to represent as operand of "+"}} + expr {$x+1} +} [expr 0x100000000000000000000000000000000000000] -if {[info commands testexprlong] == {}} { - puts "This application hasn't been compiled with the \"testexprlong\"" - puts "command, so I can't test Tcl_ExprLong etc." -} else { -test expr-old-37.1 {Check that Tcl_ExprLong doesn't modify interpreter result if no error} { - testexprlong +test expr-old-37.1 {Check that Tcl_ExprLong doesn't modify interpreter result if no error} testexprlong { + testexprlong 4+1 } {This is a result: 5} -} - -if {[info commands testexprstring] == {}} { - puts "This application hasn't been compiled with the \"testexprstring\"" - puts "command, so I can't test Tcl_ExprString etc." -} else { -test expr-old-38.1 {Verify Tcl_ExprString's basic operation} { +#Check for [Bug 1109484] +test expr-old-37.2 {Tcl_ExprLong handles wide ints gracefully} testexprlong { + testexprlong wide(1)+2 +} {This is a result: 3} + +test expr-old-37.3 {Tcl_ExprLong on the empty string} testexprlong { + testexprlong "" +} {This is a result: 0} +test expr-old-37.4 {Tcl_ExprLong coerces doubles} testexprlong { + testexprlong 3+.14159 +} {This is a result: 3} +test expr-old-37.5 {Tcl_ExprLong handles overflows} {testexprlong longIs32bit} { + testexprlong 0x80000000 +} {This is a result: -2147483648} +test expr-old-37.6 {Tcl_ExprLong handles overflows} {testexprlong longIs32bit} { + testexprlong 0xffffffff +} {This is a result: -1} +test expr-old-37.7 {Tcl_ExprLong handles overflows} \ + -constraints {testexprlong longIs32bit} \ + -match glob \ + -body { + list [catch {testexprlong 0x100000000} result] $result + } \ + -result {1 {integer value too large to represent*}} +test expr-old-37.8 {Tcl_ExprLong handles overflows} testexprlong { + testexprlong -0x80000000 +} {This is a result: -2147483648} +test expr-old-37.9 {Tcl_ExprLong handles overflows} {testexprlong longIs32bit} { + testexprlong -0xffffffff +} {This is a result: 1} +test expr-old-37.10 {Tcl_ExprLong handles overflows} \ + -constraints {testexprlong longIs32bit} \ + -match glob \ + -body { + list [catch {testexprlong -0x100000000} result] $result + } \ + -result {1 {integer value too large to represent*}} +test expr-old-37.11 {Tcl_ExprLong handles overflows} {testexprlong longIs32bit} { + testexprlong 2147483648. +} {This is a result: -2147483648} +test expr-old-37.12 {Tcl_ExprLong handles overflows} {testexprlong longIs32bit} { + testexprlong 4294967295. +} {This is a result: -1} +test expr-old-37.13 {Tcl_ExprLong handles overflows} \ + -constraints {testexprlong longIs32bit} \ + -match glob \ + -body { + list [catch {testexprlong 4294967296.} result] $result + } \ + -result {1 {integer value too large to represent*}} +test expr-old-37.14 {Tcl_ExprLong handles overflows} testexprlong { + testexprlong -2147483648. +} {This is a result: -2147483648} +test expr-old-37.15 {Tcl_ExprLong handles overflows} {testexprlong longIs32bit} { + testexprlong -4294967295. +} {This is a result: 1} +test expr-old-37.16 {Tcl_ExprLong handles overflows} \ + -constraints {testexprlong longIs32bit} \ + -match glob \ + -body { + list [catch {testexprlong 4294967296.} result] $result + } \ + -result {1 {integer value too large to represent*}} + +test expr-old-37.17 {Check that Tcl_ExprDouble doesn't modify interpreter result if no error} testexprdouble { + testexprdouble 4.+1. +} {This is a result: 5.0} +#Check for [Bug 1109484] +test expr-old-37.18 {Tcl_ExprDouble on the empty string} testexprdouble { + testexprdouble "" +} {This is a result: 0.0} +test expr-old-37.19 {Tcl_ExprDouble coerces wides} testexprdouble { + testexprdouble 1[string repeat 0 17] +} {This is a result: 1e+17} +test expr-old-37.20 {Tcl_ExprDouble coerces bignums} testexprdouble { + testexprdouble 1[string repeat 0 38] +} {This is a result: 1e+38} +test expr-old-37.21 {Tcl_ExprDouble handles overflows} testexprdouble { + testexprdouble 17976931348623157[string repeat 0 292]. +} {This is a result: 1.7976931348623157e+308} +test expr-old-37.22 {Tcl_ExprDouble handles overflows that look like int} \ + testexprdouble { + testexprdouble 17976931348623157[string repeat 0 292] + } {This is a result: 1.7976931348623157e+308} +test expr-old-37.23 {Tcl_ExprDouble handles overflows} \ + ieeeFloatingPoint&&testexprdouble { + testexprdouble 17976931348623165[string repeat 0 292]. + } {This is a result: Inf} +test expr-old-37.24 {Tcl_ExprDouble handles overflows that look like int} \ + ieeeFloatingPoint&&testexprdouble { + testexprdouble 17976931348623165[string repeat 0 292] + } {This is a result: Inf} +test expr-old-37.25 {Tcl_ExprDouble and NaN} \ + {ieeeFloatingPoint testexprdouble} { + list [catch {testexprdouble 0.0/0.0} result] $result + } {1 {domain error: argument not in valid range}} + +test expr-old-38.1 {Verify Tcl_ExprString's basic operation} -constraints {testexprstring} -body { list [testexprstring "1+4"] [testexprstring "2*3+4.2"] \ - [catch {testexprstring "1+"} msg] $msg -} {5 10.2 1 {syntax error in expression "1+": premature end of expression}} -} + [catch {testexprstring "1+"} msg] $msg +} -match glob -result {5 10.2 1 *} +test expr-old-38.2 {Tcl_ExprString} testexprstring { + # This one is "magical" + testexprstring {} +} 0 +test expr-old-38.3 {Tcl_ExprString} -constraints testexprstring -body { + testexprstring { } +} -returnCodes error -match glob -result * # # Test for bug #908375: rounding numbers that do not fit in a @@ -997,6 +1149,48 @@ test expr-old-39.1 {Rounding with wide result} { } {1 1} unset -nocomplain x y +# +# TIP #255 min and max math functions +# + +test expr-old-40.1 {min math function} -body { + expr {min(0)} +} -result 0 +test expr-old-40.2 {min math function} -body { + expr {min(0.0)} +} -result 0.0 +test expr-old-40.3 {min math function} -body { + list [catch {expr {min()}} msg] $msg +} -result {1 {too few arguments to math function "min"}} +test expr-old-40.4 {min math function} -body { + expr {min(wide(-1) << 30, 4.5, -10)} +} -result [expr {wide(-1) << 30}] +test expr-old-40.5 {min math function} -body { + expr {min("a", 0)} +} -returnCodes error -match glob -result * +test expr-old-40.6 {min math function} -body { + expr {min(300, "0xFF")} +} -result 255 + +test expr-old-41.1 {max math function} -body { + expr {max(0)} +} -result 0 +test expr-old-41.2 {max math function} -body { + expr {max(0.0)} +} -result 0.0 +test expr-old-41.3 {max math function} -body { + list [catch {expr {max()}} msg] $msg +} -result {1 {too few arguments to math function "max"}} +test expr-old-41.4 {max math function} -body { + expr {max(wide(1) << 30, 4.5, -10)} +} -result [expr {wide(1) << 30}] +test expr-old-41.5 {max math function} -body { + expr {max("a", 0)} +} -returnCodes error -match glob -result * +test expr-old-41.6 {max math function} -body { + expr {max(200, "0xFF")} +} -result 255 + # Special test for Pentium arithmetic bug of 1994: if {(4195835.0 - (4195835.0/3145727.0)*3145727.0) == 256.0} { @@ -1009,3 +1203,7 @@ if {(4195835.0 - (4195835.0/3145727.0)*3145727.0) == 256.0} { # cleanup ::tcltest::cleanupTests return + +# Local Variables: +# mode: tcl +# End: |