diff options
Diffstat (limited to 'tests/expr.test')
| -rw-r--r-- | tests/expr.test | 1065 | 
1 files changed, 833 insertions, 232 deletions
| diff --git a/tests/expr.test b/tests/expr.test index 39b8eb8..8e083c5 100644 --- a/tests/expr.test +++ b/tests/expr.test @@ -9,16 +9,17 @@  #  # See the file "license.terms" for information on usage and redistribution  # of this file, and for a DISCLAIMER OF ALL WARRANTIES. -# -# RCS: @(#) $Id: expr.test,v 1.51 2006/03/21 18:30:54 dgp Exp $  if {[lsearch [namespace children] ::tcltest] == -1} {      package require tcltest 2.1      namespace import -force ::tcltest::*  } +::tcltest::loadTestedCommands +catch [list package require -exact Tcltest [info patchlevel]] +  testConstraint testmathfunctions [expr { -    ([catch {expr T1()} msg] != 1) || ($msg ne {unknown math function "T1"}) +    ([catch {expr T1()} msg] != 1) || ($msg ne {invalid command name "tcl::mathfunc::T1"})  }]  # Determine if "long int" type is a 32 bit number and if the wide @@ -203,33 +204,28 @@ test expr-1.15 {TclCompileExprCmd: second level of substitutions in expr with co  test expr-2.1 {TclCompileExpr: are builtin functions registered?} {      expr double(5*[llength "6 2"])  } 10.0 -test expr-2.2 {TclCompileExpr: error in expr} { -    catch {expr 2***3} msg -    set msg -} {syntax error in expression "2***3": unexpected operator *} -test expr-2.3 {TclCompileExpr: junk after legal expr} { -    catch {expr 7*[llength "a b"]foo} msg -    set msg -} {syntax error in expression "7*2foo": extra tokens at end of expression} +test expr-2.2 {TclCompileExpr: error in expr} -body { +    expr 2***3 +} -returnCodes error -match glob -result * +test expr-2.3 {TclCompileExpr: junk after legal expr} -body { +    expr 7*[llength "a b"]foo +} -returnCodes error -match glob -result *  test expr-2.4 {TclCompileExpr: numeric expr string rep == formatted int rep} {      expr {0001}  } 1  test expr-3.1 {CompileCondExpr: just lor expr} {expr 3||0} 1  test expr-3.2 {CompileCondExpr: error in lor expr} -body { -    catch {expr x||3} msg -    set msg -} -match glob -result {syntax error in expression "x||3": * preceding $*} +    expr x||3 +} -returnCodes error -match glob -result *  test expr-3.3 {CompileCondExpr: test true arm} {expr 3>2?44:66} 44 -test expr-3.4 {CompileCondExpr: error compiling true arm} { -    catch {expr 3>2?2***3:66} msg -    set msg -} {syntax error in expression "3>2?2***3:66": unexpected operator *} +test expr-3.4 {CompileCondExpr: error compiling true arm} -body { +    expr 3>2?2***3:66 +} -returnCodes error -match glob -result *  test expr-3.5 {CompileCondExpr: test false arm} {expr 2>3?44:66} 66 -test expr-3.6 {CompileCondExpr: error compiling false arm} { -    catch {expr 2>3?44:2***3} msg -    set msg -} {syntax error in expression "2>3?44:2***3": unexpected operator *} +test expr-3.6 {CompileCondExpr: error compiling false arm} -body { +    expr 2>3?44:2***3 +} -returnCodes error -match glob -result *  test expr-3.7 {CompileCondExpr: long arms & nested cond exprs} {      hello_world  } {Hello world} @@ -240,20 +236,17 @@ test expr-3.8 {CompileCondExpr: long arms & nested cond exprs} unix {  test expr-4.1 {CompileLorExpr: just land expr} {expr 1.3&&3.3} 1  test expr-4.2 {CompileLorExpr: error in land expr} -body { -    catch {expr x&&3} msg -    set msg -} -match glob -result {syntax error in expression "x&&3": *preceding $*}  +    expr x&&3 +} -returnCodes error -match glob -result *  test expr-4.3 {CompileLorExpr: simple lor exprs} {expr 0||1.0} 1  test expr-4.4 {CompileLorExpr: simple lor exprs} {expr 3.0||0.0} 1  test expr-4.5 {CompileLorExpr: simple lor exprs} {expr 0||0||1} 1 -test expr-4.6 {CompileLorExpr: error compiling lor arm} { -    catch {expr 2***3||4.0} msg -    set msg -} {syntax error in expression "2***3||4.0": unexpected operator *} -test expr-4.7 {CompileLorExpr: error compiling lor arm} { -    catch {expr 1.3||2***3} msg -    set msg -} {syntax error in expression "1.3||2***3": unexpected operator *} +test expr-4.6 {CompileLorExpr: error compiling lor arm} -body { +    expr 2***3||4.0 +} -returnCodes error -match glob -result * +test expr-4.7 {CompileLorExpr: error compiling lor arm} -body { +    expr 1.3||2***3 +} -returnCodes error -match glob -result *  test expr-4.8 {CompileLorExpr: error compiling lor arms} {      list [catch {expr {"a"||"b"}} msg] $msg  } {1 {expected boolean value but got "a"}} @@ -274,21 +267,18 @@ test expr-4.12 {CompileLorExpr: error compiling land arms} {  test expr-5.1 {CompileLandExpr: just bitor expr} {expr 7|0x13} 23  test expr-5.2 {CompileLandExpr: error in bitor expr} -body { -    catch {expr x|3} msg -    set msg -} -match glob -result {syntax error in expression "x|3": * preceding $*}  +    expr x|3 +} -returnCodes error -match glob -result *  test expr-5.3 {CompileLandExpr: simple land exprs} {expr 0&&1.0} 0  test expr-5.4 {CompileLandExpr: simple land exprs} {expr 0&&0} 0  test expr-5.5 {CompileLandExpr: simple land exprs} {expr 3.0&&1.2} 1  test expr-5.6 {CompileLandExpr: simple land exprs} {expr 1&&1&&2} 1 -test expr-5.7 {CompileLandExpr: error compiling land arm} { -    catch {expr 2***3&&4.0} msg -    set msg -} {syntax error in expression "2***3&&4.0": unexpected operator *} -test expr-5.8 {CompileLandExpr: error compiling land arm} { -    catch {expr 1.3&&2***3} msg -    set msg -} {syntax error in expression "1.3&&2***3": unexpected operator *} +test expr-5.7 {CompileLandExpr: error compiling land arm} -body { +    expr 2***3&&4.0 +} -returnCodes error -match glob -result * +test expr-5.8 {CompileLandExpr: error compiling land arm} -body { +    expr 1.3&&2***3 +} -returnCodes error -match glob -result *  test expr-5.9 {CompileLandExpr: error compiling land arm} {      list [catch {expr {"a"&&"b"}} msg] $msg  } {1 {expected boolean value but got "a"}} @@ -300,21 +290,18 @@ test expr-5.10 {CompileLandExpr: long land arms} {  test expr-6.1 {CompileBitXorExpr: just bitand expr} {expr 7&0x13} 3  test expr-6.2 {CompileBitXorExpr: error in bitand expr} -body { -    catch {expr x|3} msg -    set msg -} -match glob -result {syntax error in expression "x|3": * preceding $*}  +    expr x|3 +} -returnCodes error -match glob -result *  test expr-6.3 {CompileBitXorExpr: simple bitxor exprs} {expr 7^0x13} 20  test expr-6.4 {CompileBitXorExpr: simple bitxor exprs} {expr 3^0x10} 19  test expr-6.5 {CompileBitXorExpr: simple bitxor exprs} {expr 0^7} 7  test expr-6.6 {CompileBitXorExpr: simple bitxor exprs} {expr -1^7} -8 -test expr-6.7 {CompileBitXorExpr: error compiling bitxor arm} { -    catch {expr 2***3|6} msg -    set msg -} {syntax error in expression "2***3|6": unexpected operator *} +test expr-6.7 {CompileBitXorExpr: error compiling bitxor arm} -body { +    expr 2***3|6 +} -returnCodes error -match glob -result *  test expr-6.8 {CompileBitXorExpr: error compiling bitxor arm} -body { -    catch {expr 2^x} msg -    set msg -} -match glob -result {syntax error in expression "2^x": * preceding $**} +    expr 2^x +} -returnCodes error -match glob -result *  test expr-6.9 {CompileBitXorExpr: runtime error in bitxor arm} {      list [catch {expr {24.0^3}} msg] $msg  } {1 {can't use floating-point value as operand of "^"}} @@ -327,21 +314,18 @@ test expr-7.2 {CompileBitAndExpr: just equality expr} {expr 2.0==2} 1  test expr-7.3 {CompileBitAndExpr: just equality expr} {expr 3.2!=2.2} 1  test expr-7.4 {CompileBitAndExpr: just equality expr} {expr {"abc" == "abd"}} 0  test expr-7.5 {CompileBitAndExpr: error in equality expr} -body { -    catch {expr x==3} msg -    set msg -} -match glob -result {syntax error in expression "x==3": * preceding $*} +    expr x==3 +} -returnCodes error -match glob -result *  test expr-7.6 {CompileBitAndExpr: simple bitand exprs} {expr 7&0x13} 3  test expr-7.7 {CompileBitAndExpr: simple bitand exprs} {expr 0xf2&0x53} 82  test expr-7.8 {CompileBitAndExpr: simple bitand exprs} {expr 3&6} 2  test expr-7.9 {CompileBitAndExpr: simple bitand exprs} {expr -1&-7} -7 -test expr-7.10 {CompileBitAndExpr: error compiling bitand arm} { -    catch {expr 2***3&6} msg -    set msg -} {syntax error in expression "2***3&6": unexpected operator *} +test expr-7.10 {CompileBitAndExpr: error compiling bitand arm} -body { +    expr 2***3&6 +} -returnCodes error -match glob -result *  test expr-7.11 {CompileBitAndExpr: error compiling bitand arm} -body { -    catch {expr 2&x} msg -    set msg -} -match glob -result {syntax error in expression "2&x": * preceding $*} +    expr 2&x +} -returnCodes error -match glob -result *  test expr-7.12 {CompileBitAndExpr: runtime error in bitand arm} {      list [catch {expr {24.0&3}} msg] $msg  } {1 {can't use floating-point value as operand of "&"}} @@ -351,32 +335,28 @@ test expr-7.13 {CompileBitAndExpr: runtime error in bitand arm} {  test expr-7.14 {CompileBitAndExpr: equality expr} {expr 3eq2} 0  test expr-7.18 {CompileBitAndExpr: equality expr} {expr {"abc" eq "abd"}} 0  test expr-7.20 {CompileBitAndExpr: error in equality expr} -body { -    catch {expr xne3} msg -    set msg -} -match glob -result {syntax error in expression "xne3": * preceding $*}  +    expr xne3 +} -returnCodes error -match glob -result *  test expr-8.1 {CompileEqualityExpr: just relational expr} {expr 3>=2} 1  test expr-8.2 {CompileEqualityExpr: just relational expr} {expr 2<=2.1} 1  test expr-8.3 {CompileEqualityExpr: just relational expr} {expr 3.2>"2.2"} 1  test expr-8.4 {CompileEqualityExpr: just relational expr} {expr {"0y"<"0x12"}} 0  test expr-8.5 {CompileEqualityExpr: error in relational expr} -body { -    catch {expr x>3} msg -    set msg -} -match glob -result {syntax error in expression "x>3": * preceding $*} +    expr x>3 +} -returnCodes error -match glob -result *  test expr-8.6 {CompileEqualityExpr: simple equality exprs} {expr 7==0x13} 0  test expr-8.7 {CompileEqualityExpr: simple equality exprs} {expr -0xf2!=0x53} 1  test expr-8.8 {CompileEqualityExpr: simple equality exprs} {expr {"12398712938788234-1298379" != ""}} 1  test expr-8.9 {CompileEqualityExpr: simple equality exprs} {expr -1!="abc"} 1 -test expr-8.10 {CompileEqualityExpr: error compiling equality arm} { -    catch {expr 2***3==6} msg -    set msg -} {syntax error in expression "2***3==6": unexpected operator *} +test expr-8.10 {CompileEqualityExpr: error compiling equality arm} -body { +    expr 2***3==6 +} -returnCodes error -match glob -result *  test expr-8.11 {CompileEqualityExpr: error compiling equality arm} -body { -    catch {expr 2!=x} msg -    set msg -} -match glob -result {syntax error in expression "2!=x": * preceding $*} +    expr 2!=x +} -returnCodes error -match glob -result *  test expr-8.12 {CompileBitAndExpr: equality expr} {expr {"a"eq"a"}} 1 -test expr-8.13 {CompileBitAndExpr: equality expr} {expr {"\374" eq "ü"}} 1 +test expr-8.13 {CompileBitAndExpr: equality expr} {expr {"\374" eq [set s \u00fc]}} 1  test expr-8.14 {CompileBitAndExpr: equality expr} {expr 3eq2} 0  test expr-8.15 {CompileBitAndExpr: equality expr} {expr 2.0eq2} 0  test expr-8.16 {CompileBitAndExpr: equality expr} {expr 3.2ne2.2} 1 @@ -384,22 +364,18 @@ test expr-8.17 {CompileBitAndExpr: equality expr} {expr 01eq1} 0  test expr-8.18 {CompileBitAndExpr: equality expr} {expr {"abc" eq "abd"}} 0  test expr-8.19 {CompileBitAndExpr: equality expr} {expr {"abc" ne "abd"}} 1  test expr-8.20 {CompileBitAndExpr: error in equality expr} -body { -    catch {expr x ne3} msg -    set msg -} -match glob -result {syntax error in expression "x ne3": * preceding $*}  +    expr x ne3 +} -returnCodes error -match glob -result *  test expr-8.21 {CompileBitAndExpr: error in equality expr} -body {      # These should be ""ed to avoid the error -    catch {expr a eq b} msg -    set msg -} -match glob -result {syntax error in expression "a eq b": * preceding $*} -test expr-8.22 {CompileBitAndExpr: error in equality expr} { -    catch {expr {false eqfalse}} msg -    set msg -} {syntax error in expression "false eqfalse": extra tokens at end of expression} -test expr-8.23 {CompileBitAndExpr: error in equality expr} { -    catch {expr {false nefalse}} msg -    set msg -} {syntax error in expression "false nefalse": extra tokens at end of expression} +    expr a eq b +} -returnCodes error -match glob -result * +test expr-8.22 {CompileBitAndExpr: error in equality expr} -body { +    expr {false eqfalse} +} -returnCodes error -match glob -result * +test expr-8.23 {CompileBitAndExpr: error in equality expr} -body { +    expr {false nefalse} +} -returnCodes error -match glob -result *  test expr-8.24 {CompileEqualityExpr: simple equality exprs} {      set x 12398712938788234      expr {$x == 100} @@ -425,21 +401,21 @@ test expr-8.29 {CompileEqualityExpr: just relational expr} {  test expr-8.30 {CompileEqualityExpr: simple equality exprs} {      expr {"fake" != "bob"}  } 1 -test expr-8.31 {expr edge cases} { -    list [catch {expr {1e}} err] $err -} {1 {syntax error in expression "1e": extra tokens at end of expression}} -test expr-8.32 {expr edge cases} { -    list [catch {expr {1E}} err] $err -} {1 {syntax error in expression "1E": extra tokens at end of expression}} -test expr-8.33 {expr edge cases} { -    list [catch {expr {1e+}} err] $err -} {1 {syntax error in expression "1e+": extra tokens at end of expression}} -test expr-8.34 {expr edge cases} { -    list [catch {expr {1E+}} err] $err -} {1 {syntax error in expression "1E+": extra tokens at end of expression}} -test expr-8.35 {expr edge cases} { -    list [catch {expr {1ea}} err] $err -} {1 {syntax error in expression "1ea": extra tokens at end of expression}} +test expr-8.31 {expr edge cases} -body { +    expr {1e} +} -returnCodes error -match glob -result * +test expr-8.32 {expr edge cases} -body { +    expr {1E} +} -returnCodes error -match glob -result * +test expr-8.33 {expr edge cases} -body { +    expr {1e+} +} -returnCodes error -match glob -result * +test expr-8.34 {expr edge cases} -body { +    expr {1E+} +} -returnCodes error -match glob -result * +test expr-8.35 {expr edge cases} -body { +    expr {1ea} +} -returnCodes error -match glob -result *  test expr-9.1 {CompileRelationalExpr: just shift expr} {expr 3<<2} 12  test expr-9.2 {CompileRelationalExpr: just shift expr} {expr 0xff>>2} 63 @@ -452,38 +428,32 @@ test expr-9.5b {CompileRelationalExpr: shift expr producing LONG_MIN} longIs32bi      expr {int(1<<31)}  } -2147483648  test expr-9.6 {CompileRelationalExpr: error in shift expr} -body { -    catch {expr x>>3} msg -    set msg -} -match glob -result {syntax error in expression "x>>3": * preceding $*} +    expr x>>3 +} -returnCodes error -match glob -result *  test expr-9.7 {CompileRelationalExpr: simple relational exprs} {expr 0xff>=+0x3} 1  test expr-9.8 {CompileRelationalExpr: simple relational exprs} {expr -0xf2<0x3} 1 -test expr-9.9 {CompileRelationalExpr: error compiling relational arm} { -    catch {expr 2***3>6} msg -    set msg -} {syntax error in expression "2***3>6": unexpected operator *} +test expr-9.9 {CompileRelationalExpr: error compiling relational arm} -body { +    expr 2***3>6 +} -returnCodes error -match glob -result *  test expr-9.10 {CompileRelationalExpr: error compiling relational arm} -body { -    catch {expr 2<x} msg -    set msg -} -match glob -result {syntax error in expression "2<x": * preceding $*} +    expr 2<x +} -returnCodes error -match glob -result *  test expr-10.1 {CompileShiftExpr: just add expr} {expr 4+-2} 2  test expr-10.2 {CompileShiftExpr: just add expr} {expr 0xff-2} 253  test expr-10.3 {CompileShiftExpr: just add expr} {expr -1--2} 1 -test expr-10.4 {CompileShiftExpr: just add expr} {expr 1-0123} -82 +test expr-10.4 {CompileShiftExpr: just add expr} {expr 1-0o123} -82  test expr-10.5 {CompileShiftExpr: error in add expr} -body { -    catch {expr x+3} msg -    set msg -} -match glob -result {syntax error in expression "x+3": * preceding $*} +    expr x+3 +} -returnCodes error -match glob -result *  test expr-10.6 {CompileShiftExpr: simple shift exprs} {expr 0xff>>0x3} 31  test expr-10.7 {CompileShiftExpr: simple shift exprs} {expr -0xf2<<0x3} -1936 -test expr-10.8 {CompileShiftExpr: error compiling shift arm} { -    catch {expr 2***3>>6} msg -    set msg -} {syntax error in expression "2***3>>6": unexpected operator *} +test expr-10.8 {CompileShiftExpr: error compiling shift arm} -body { +    expr 2***3>>6 +} -returnCodes error -match glob -result *  test expr-10.9 {CompileShiftExpr: error compiling shift arm} -body { -    catch {expr 2<<x} msg -    set msg -} -match glob -result {syntax error in expression "2<<x": * preceding $*} +    expr 2<<x +} -returnCodes error -match glob -result *  test expr-10.10 {CompileShiftExpr: runtime error} {      list [catch {expr {24.0>>43}} msg] $msg  } {1 {can't use floating-point value as operand of ">>"}} @@ -494,21 +464,18 @@ test expr-10.11 {CompileShiftExpr: runtime error} {  test expr-11.1 {CompileAddExpr: just multiply expr} {expr 4*-2} -8  test expr-11.2 {CompileAddExpr: just multiply expr} {expr 0xff%2} 1  test expr-11.3 {CompileAddExpr: just multiply expr} {expr -1/2} -1 -test expr-11.4 {CompileAddExpr: just multiply expr} {expr 7891%0123} 6 +test expr-11.4 {CompileAddExpr: just multiply expr} {expr 7891%0o123} 6  test expr-11.5 {CompileAddExpr: error in multiply expr} -body { -    catch {expr x*3} msg -    set msg -} -match glob -result {syntax error in expression "x*3": * preceding $*} +    expr x*3 +} -returnCodes error -match glob -result *  test expr-11.6 {CompileAddExpr: simple add exprs} {expr 0xff++0x3} 258  test expr-11.7 {CompileAddExpr: simple add exprs} {expr -0xf2--0x3} -239 -test expr-11.8 {CompileAddExpr: error compiling add arm} { -    catch {expr 2***3+6} msg -    set msg -} {syntax error in expression "2***3+6": unexpected operator *} +test expr-11.8 {CompileAddExpr: error compiling add arm} -body { +    expr 2***3+6 +} -returnCodes error -match glob -result *  test expr-11.9 {CompileAddExpr: error compiling add arm} -body { -    catch {expr 2-x} msg -    set msg -} -match glob -result {syntax error in expression "2-x": * preceding $*} +    expr 2-x +} -returnCodes error -match glob -result *  test expr-11.10 {CompileAddExpr: runtime error} {      list [catch {expr {24.0+"xx"}} msg] $msg  } {1 {can't use non-numeric string as operand of "+"}} @@ -530,19 +497,16 @@ test expr-12.2 {CompileMultiplyExpr: just unary expr} {expr --5} 5  test expr-12.3 {CompileMultiplyExpr: just unary expr} {expr !27} 0  test expr-12.4 {CompileMultiplyExpr: just unary expr} {expr ~0xff00ff} -16711936  test expr-12.5 {CompileMultiplyExpr: error in unary expr} -body { -    catch {expr ~x} msg -    set msg -} -match glob -result {syntax error in expression "~x": * preceding $*} +    expr ~x +} -returnCodes error -match glob -result *  test expr-12.6 {CompileMultiplyExpr: simple multiply exprs} {expr 0xff*0x3} 765  test expr-12.7 {CompileMultiplyExpr: simple multiply exprs} {expr -0xf2%-0x3} -2 -test expr-12.8 {CompileMultiplyExpr: error compiling multiply arm} { -    catch {expr 2*3%%6} msg -    set msg -} {syntax error in expression "2*3%%6": unexpected operator %} +test expr-12.8 {CompileMultiplyExpr: error compiling multiply arm} -body { +    expr 2*3%%6 +} -returnCodes error -match glob -result *  test expr-12.9 {CompileMultiplyExpr: error compiling multiply arm} -body { -    catch {expr 2*x} msg -    set msg -} -match glob -result {syntax error in expression "2*x": * preceding $*} +    expr 2*x +} -returnCodes error -match glob -result *  test expr-12.10 {CompileMultiplyExpr: runtime error} {      list [catch {expr {24.0*"xx"}} msg] $msg  } {1 {can't use non-numeric string as operand of "*"}} @@ -551,20 +515,18 @@ test expr-12.11 {CompileMultiplyExpr: runtime error} {  } {1 {can't use non-numeric string as operand of "/"}}  test expr-13.1 {CompileUnaryExpr: unary exprs} {expr -0xff} -255 -test expr-13.2 {CompileUnaryExpr: unary exprs} {expr +000123} 83 +test expr-13.2 {CompileUnaryExpr: unary exprs} {expr +0o00123} 83  test expr-13.3 {CompileUnaryExpr: unary exprs} {expr +--++36} 36  test expr-13.4 {CompileUnaryExpr: unary exprs} {expr !2} 0  test expr-13.5 {CompileUnaryExpr: unary exprs} {expr +--+-62.0} -62.0  test expr-13.6 {CompileUnaryExpr: unary exprs} {expr !0.0} 1  test expr-13.7 {CompileUnaryExpr: unary exprs} {expr !0xef} 0  test expr-13.8 {CompileUnaryExpr: error compiling unary expr} -body { -    catch {expr ~x} msg -    set msg -} -match glob -result {syntax error in expression "~x": * preceding $*} -test expr-13.9 {CompileUnaryExpr: error compiling unary expr} { -    catch {expr !1.x} msg -    set msg -} {syntax error in expression "!1.x": extra tokens at end of expression} +    expr ~x +} -returnCodes error -match glob -result * +test expr-13.9 {CompileUnaryExpr: error compiling unary expr} -body { +    expr !1.x +} -returnCodes error -match glob -result *  test expr-13.10 {CompileUnaryExpr: runtime error} {      list [catch {expr {~"xx"}} msg] $msg  } {1 {can't use non-numeric string as operand of "~"}} @@ -592,7 +554,7 @@ test expr-13.17 {CompileUnaryExpr: negating non-numeric boolean literals} {  test expr-14.1 {CompilePrimaryExpr: literal primary} {expr 1} 1  test expr-14.2 {CompilePrimaryExpr: literal primary} {expr 123} 123  test expr-14.3 {CompilePrimaryExpr: literal primary} {expr 0xff} 255 -test expr-14.4 {CompilePrimaryExpr: literal primary} {expr 00010} 8 +test expr-14.4 {CompilePrimaryExpr: literal primary} {expr 0o0010} 8  test expr-14.5 {CompilePrimaryExpr: literal primary} {expr 62.0} 62.0  test expr-14.6 {CompilePrimaryExpr: literal primary} {      expr 3.1400000 @@ -630,14 +592,11 @@ test expr-14.15 {CompilePrimaryExpr: var reference primary} {      set msg  } 123.2  test expr-14.16 {CompilePrimaryExpr: error compiling var reference primary} -body { -    catch {expr {$a(foo}} msg -    set errorInfo -} -match glob -result {missing ) -    while *ing -"expr {$a(foo}"} -test expr-14.17 {CompilePrimaryExpr: string primary that looks like var ref} { +    expr {$a(foo} +} -returnCodes error -match glob -result * +test expr-14.17 {CompilePrimaryExpr: string primary that looks like var ref} -body {      expr $ -} $ +} -returnCodes error -match glob -result *  test expr-14.18 {CompilePrimaryExpr: quoted string primary} {      expr "21"  } 21 @@ -660,16 +619,13 @@ test expr-14.22 {CompilePrimaryExpr: subcommand primary} {  } 123  test expr-14.23 {CompilePrimaryExpr: error in subcommand primary} -body {      catch {expr {[set]}} msg -    set errorInfo +    set ::errorInfo  } -match glob -result {wrong # args: should be "set varName ?newValue?"      while *ing  "set"*}  test expr-14.24 {CompilePrimaryExpr: error in subcommand primary} -body { -    catch {expr {[set i}} msg -    set errorInfo -} -match glob -result {missing close-bracket -    while *ing -"expr {\[set i}"} +    expr {[set i} +} -returnCodes error -match glob -result *  test expr-14.25 {CompilePrimaryExpr: math function primary} {      format %.6g [expr exp(1.0)]  } 2.71828 @@ -677,73 +633,58 @@ test expr-14.26 {CompilePrimaryExpr: math function primary} {      format %.6g [expr pow(2.0+0.1,3.0+0.1)]  } 9.97424  test expr-14.27 {CompilePrimaryExpr: error in math function primary} -body { -    catch {expr sinh::(2.0)} msg -    set errorInfo -} -match glob -result {syntax error in expression "sinh::(2.0)": * function arguments* -    while *ing -"expr sinh::(2.0)"} +    expr sinh::(2.0) +} -returnCodes error -match glob -result *  test expr-14.28 {CompilePrimaryExpr: subexpression primary} {      expr 2+(3*4)  } 14  test expr-14.29 {CompilePrimaryExpr: error in subexpression primary} -body {      catch {expr 2+(3*[set])} msg -    set errorInfo +    set ::errorInfo  } -match glob -result {wrong # args: should be "set varName ?newValue?"      while *ing  "set"*}  test expr-14.30 {CompilePrimaryExpr: missing paren in subexpression primary} -body { -    catch {expr 2+(3*(4+5)} msg -    set errorInfo -} -match glob -result {syntax error in expression "2+(3*(4+5)": looking for close parenthesis -    while *ing -"expr 2+(3*(4+5)"} +    expr 2+(3*(4+5) +} -returnCodes error -match glob -result *  test expr-14.31 {CompilePrimaryExpr: just var ref in subexpression primary} {      set i "5+10"      list "[expr $i] == 15" "[expr ($i)] == 15" "[eval expr ($i)] == 15"  } {{15 == 15} {15 == 15} {15 == 15}}  test expr-14.32 {CompilePrimaryExpr: unexpected token} -body { -    catch {expr @} msg -    set errorInfo -} -match glob -result {syntax error in expression "@": character not legal in expressions -    while *ing -"expr @"} +    expr @ +} -returnCodes error -match glob -result *  test expr-15.1 {CompileMathFuncCall: missing parenthesis} -body { -    catch {expr sinh2.0)} msg -    set errorInfo -} -match glob -result {syntax error in expression "sinh2.0)": * preceding $* -    while *ing -"expr sinh2.0)"} +    expr sinh2.0) +} -returnCodes error -match glob -result *  test expr-15.2 {CompileMathFuncCall: unknown math function} -body {      catch {expr whazzathuh(1)} msg -    set errorInfo +    set ::errorInfo  } -match glob -result {* "*whazzathuh"      while *ing  "expr whazzathuh(1)"}  test expr-15.3 {CompileMathFuncCall: too many arguments} -body {      catch {expr sin(1,2,3)} msg -    set errorInfo +    set ::errorInfo  } -match glob -result {too many arguments for math function*      while *ing  "expr sin(1,2,3)"}  test expr-15.4 {CompileMathFuncCall: ')' found before last required arg} -body {      catch {expr sin()} msg -    set errorInfo +    set ::errorInfo  } -match glob -result {too few arguments for math function*      while *ing  "expr sin()"}  test expr-15.5 {CompileMathFuncCall: too few arguments} -body {      catch {expr pow(1)} msg -    set errorInfo +    set ::errorInfo  } -match glob -result {too few arguments for math function*      while *ing  "expr pow(1)"}  test expr-15.6 {CompileMathFuncCall: missing ')'} -body { -    catch {expr sin(1} msg -    set errorInfo -} -match glob -result {syntax error in expression "sin(1": missing close parenthesis at end of function call -    while *ing -"expr sin(1"} +    expr sin(1 +} -returnCodes error -match glob -result *  test expr-15.7 {CompileMathFuncCall: call registered math function} {testmathfunctions} {      expr 2*T1()  } 246 @@ -847,7 +788,7 @@ test expr-20.1 {wrong brace matching} {      set cmd "expr $l$q|$q == $q$r$q$r"      list [catch $cmd a] $a  } {1 {extra characters after close-brace}} -test expr-20.2 {double invocation of variable traces} { +test expr-20.2 {double invocation of variable traces} -body {      set exprtracecounter 0      proc exprtraceproc {args} {         upvar #0 exprtracecounter counter @@ -865,7 +806,7 @@ test expr-20.2 {double invocation of variable traces} {      list [catch {expr "$exprtracevar + 20"} a] $a \          [catch {expr "$exprtracevar + 20"} b] $b \          [unset exprtracevar exprtracecounter] -} {1 {syntax error in expression "1 oops 10 + 20": extra tokens at end of expression} 0 32 {}} +} -match glob -result {1 * 0 32 {}}  test expr-20.3 {broken substitution of integer digits} {      # fails with 8.0.x, but not 8.1b2      list [set a 000; expr 0x1$a] [set a 1; expr ${a}000] @@ -898,9 +839,9 @@ test expr-21.9 	{non-numeric boolean literals} {expr !off  } 1  test expr-21.10 {non-numeric boolean literals} {expr !on   } 0  test expr-21.11 {non-numeric boolean literals} {expr !no   } 1  test expr-21.12 {non-numeric boolean literals} {expr !yes  } 0 -test expr-21.13 {non-numeric boolean literals} { -    list [catch {expr !truef} err] $err -} {1 {syntax error in expression "!truef": the word "truef" requires a preceding $ if it's a variable or function arguments if it's a function}} +test expr-21.13 {non-numeric boolean literals} -body { +    expr !truef +} -returnCodes error -match glob -result *  test expr-21.14 {non-numeric boolean literals} {      list [catch {expr !"truef"} err] $err  } {1 {can't use non-numeric string as operand of "!"}} @@ -969,6 +910,15 @@ test expr-22.9 {non-numeric floats: shared object equality and NaN} {      set x NaN      expr {$x == $x}  } 0 +# Make sure [Bug d0f7ba56f0] stays fixed. +test expr-22.10 {non-numeric arguments: equality and NaN} { +    set x NaN +    expr {$x > "Gran"} +} 1 +test expr-22.11 {non-numeric arguments: equality and NaN} { +    set x NaN +    expr {"Gran" < $x} +} 1  # Tests for exponentiation handling  test expr-23.1 {CompileExponentialExpr: just exponential expr} {expr 4**2} 16 @@ -976,18 +926,15 @@ test expr-23.2 {CompileExponentialExpr: just exponential expr} {expr 0xff**2} 65  test expr-23.3 {CompileExponentialExpr: just exponential expr} {expr -1**2} 1  test expr-23.4 {CompileExponentialExpr: just exponential expr} {expr 18**07} 612220032  test expr-23.5 {CompileExponentialExpr: error in exponential expr} -body { -    catch {expr x**3} msg -    set msg -} -match glob -result {syntax error in expression "x**3": * preceding $*} +    expr x**3 +} -returnCodes error -match glob -result *  test expr-23.6 {CompileExponentialExpr: simple expo exprs} {expr 0xff**0x3} 16581375 -test expr-23.7 {CompileExponentialExpr: error compiling expo arm} { -    catch {expr (-3-)**6} msg -    set msg -} {syntax error in expression "(-3-)**6": unexpected close parenthesis} +test expr-23.7 {CompileExponentialExpr: error compiling expo arm} -body { +    expr (-3-)**6 +} -returnCodes error -match glob -result *  test expr-23.8 {CompileExponentialExpr: error compiling expo arm} -body { -    catch {expr 2**x} msg -    set msg -} -match glob -result {syntax error in expression "2**x": * preceding $*} +    expr 2**x +} -returnCodes error -match glob -result *  test expr-23.9 {CompileExponentialExpr: runtime error} {      list [catch {expr {24.0**"xx"}} msg] $msg  } {1 {can't use non-numeric string as operand of "**"}} @@ -1025,6 +972,472 @@ test expr-23.32 {INST_EXPON: special cases} {expr {wide(1)**wide(1234567)}} 1  test expr-23.33 {INST_EXPON: special cases} {expr {wide(2)**wide(-2)}} 0  test expr-23.34 {INST_EXPON: special cases} {expr {2**0}} 1  test expr-23.35 {INST_EXPON: special cases} {expr {wide(2)**0}} 1 +test expr-23.36 {INST_EXPON: big integer} {expr {10**17}} 1[string repeat 0 17] +test expr-23.37 {INST_EXPON: big integer} {expr {10**18}} 1[string repeat 0 18] +test expr-23.38 {INST_EXPON: big integer} {expr {10**19}} 1[string repeat 0 19] +test expr-23.39 {INST_EXPON: big integer} { +    expr 1[string repeat 0 30]**2 +} 1[string repeat 0 60] +test expr-23.40 {INST_EXPON: overflow to big integer} {expr {(-10)**3}} -1000 +test expr-23.41 {INST_EXPON: overflow to big integer} {expr 2**64} [expr 1<<64] +test expr-23.42 {INST_EXPON: overflow to big integer} {expr 4**32} [expr 1<<64] +test expr-23.43 {INST_EXPON: overflow to big integer} {expr 16**16} [expr 1<<64] +test expr-23.44 {INST_EXPON: overflow to big integer} {expr 256**8} [expr 1<<64] +test expr-23.45 {INST_EXPON: Bug 1555371} {expr 2**1} 2 +test expr-23.46 {INST_EXPON: Bug 1561260} -body { +    expr 5**28 +} -match glob -result *5 +test expr-23.47 {INST_EXPON: Bug 1561260} { +    expr 2**32*5**32 +} 1[string repeat 0 32] +test expr-23.48 {INST_EXPON: TIP 274: right assoc} { +expr 2**3**4 +} 2417851639229258349412352 +test expr-23.49 {INST_EXPON: optimize powers of 2} { +    set trouble {test powers of 2} +    for {set tval 0} {$tval <= 66} {incr tval} { +	set is [expr {2 ** $tval}] +	set sb [expr {1 << $tval}] +	if {$is != $sb} { +	    append trouble \n "2**" $tval " is " $is " should be " $sb +	} +	if {$tval >= 1} { +	    set is [expr {-2 ** $tval}] +	    set sb [expr {1 << $tval}] +	    if {$tval & 1} { +		set sb [expr {-$sb}] +	    } +	    if {$is != $sb} { +		append trouble \n "-2**" $tval " is " $is " should be " $sb +	    } +	} +    } +    set trouble +} {test powers of 2} +test expr-23.50 {INST_EXPON: small powers of 32-bit integers} { +    set trouble {test small powers of 32-bit ints} +    for {set base 3} {$base <= 45} {incr base} { +	set sb $base +	set sbm [expr {-$base}] +	for {set expt 2} {$expt <= 8} {incr expt} { +	    set sb [expr {$sb * $base}] +	    set is [expr {$base ** $expt}] +	    if {$sb != $is} { +		append trouble \n $base ** $expt " is " $is " should be " $sb +	    } +	    set sbm [expr {-$sbm * $base}] +	    set ism [expr {(-$base) ** $expt}] +	    if {$sbm != $ism} { +		append trouble \n - $base ** $expt " is " $ism \ +		    " should be " $sbm +	    } +	} +    } +    set trouble +} {test small powers of 32-bit ints} +test expr-23.51 {INST_EXPON: intermediate powers of 32-bit integers} { +    set trouble {test intermediate powers of 32-bit ints} +    for {set base 3} {$base <= 11} {incr base} { +	set sb [expr {$base ** 8}] +	set sbm $sb +	for {set expt 9} {$expt <= 21} {incr expt} { +	    set sb [expr {$sb * $base}] +	    set sbm [expr {$sbm * -$base}] +	    set is [expr {$base ** $expt}] +	    set ism [expr {-$base ** $expt}] +	    if {$sb != $is} { +		append trouble \n $base ** $expt " is " $is " should be " $sb +	    } +	    if {$sbm != $ism} { +		append trouble \n - $base ** $expt " is " $ism  \ +		    " should be " $sbm +	    } +	} +    } +    set trouble +} {test intermediate powers of 32-bit ints} +test expr-23.52 {INST_EXPON: small integer powers with 64-bit results} { +    set trouble {test small int powers with 64-bit results} +    for {set exp 2} {$exp <= 16} {incr exp} { +	set base [expr {entier(pow(double(0x7fffffffffffffff),(1.0/$exp)))}] +	set sb 1 +	set sbm 1 +	for {set i 0} {$i < $exp} {incr i} { +	    set sb [expr {$sb * $base}] +	    set sbm [expr {$sbm * -$base}] +	} +	set is [expr {$base ** $exp}] +	set ism [expr {-$base ** $exp}] +	if {$sb != $is} { +	    append trouble \n $base ** $exp " is " $is " should be " $sb +	} +	if {$sbm != $ism} { +	    append trouble \n - $base ** $exp " is " $ism " should be " $sbm +	} +	incr base +	set sb 1 +	set sbm 1 +	for {set i 0} {$i < $exp} {incr i} { +	    set sb [expr {$sb * $base}] +	    set sbm [expr {$sbm * -$base}] +	} +	set is [expr {$base ** $exp}] +	set ism [expr {-$base ** $exp}] +	if {$sb != $is} { +	    append trouble \n $base ** $exp " is " $is " should be " $sb +	} +	if {$sbm != $ism} { +	    append trouble \n - $base ** $exp " is " $ism " should be " $sbm +	} +    } +    set trouble +} {test small int powers with 64-bit results} +test expr-23.53 {INST_EXPON: intermediate powers of 64-bit integers} { +    set trouble {test intermediate powers of 64-bit ints} +    for {set base 3} {$base <= 13} {incr base} { +	set sb [expr {$base ** 15}] +	set sbm [expr {-$sb}] +	for {set expt 16} {$expt <= 39} {incr expt} { +	    set sb [expr {$sb * $base}] +	    set sbm [expr {$sbm * -$base}] +	    set is [expr {$base ** $expt}] +	    set ism [expr {-$base ** $expt}] +	    if {$sb != $is} { +		append trouble \n $base ** $expt " is " $is " should be " $sb +	    } +	    if {$sbm != $ism} { +		append trouble \n - $base ** $expt " is " $ism  \ +		    " should be " $sbm +	    } +	} +    } +    set trouble +} {test intermediate powers of 64-bit ints} +test expr-23.54.0 {INST_EXPON: Bug 2798543} { +    expr {3**9 == 3**65545} +} 0 +test expr-23.54.1 {INST_EXPON: Bug 2798543} { +    expr {3**10 == 3**65546} +} 0 +test expr-23.54.2 {INST_EXPON: Bug 2798543} { +    expr {3**11 == 3**65547} +} 0 +test expr-23.54.3 {INST_EXPON: Bug 2798543} { +    expr {3**12 == 3**65548} +} 0 +test expr-23.54.4 {INST_EXPON: Bug 2798543} { +    expr {3**13 == 3**65549} +} 0 +test expr-23.54.5 {INST_EXPON: Bug 2798543} { +    expr {3**14 == 3**65550} +} 0 +test expr-23.54.6 {INST_EXPON: Bug 2798543} { +    expr {3**15 == 3**65551} +} 0 +test expr-23.54.7 {INST_EXPON: Bug 2798543} { +    expr {3**16 == 3**65552} +} 0 +test expr-23.54.8 {INST_EXPON: Bug 2798543} { +    expr {3**17 == 3**65553} +} 0 +test expr-23.54.9 {INST_EXPON: Bug 2798543} { +    expr {3**18 == 3**65554} +} 0 +test expr-23.54.10 {INST_EXPON: Bug 2798543} { +    expr {3**19 == 3**65555} +} 0 +test expr-23.54.11 {INST_EXPON: Bug 2798543} { +    expr {3**9 == 3**131081} +} 0 +test expr-23.54.12 {INST_EXPON: Bug 2798543} -body { +    expr {3**9 == 3**268435465} +} -returnCodes error -result {exponent too large} +test expr-23.54.13 {INST_EXPON: Bug 2798543} { +    expr {(-3)**9 == (-3)**65545} +} 0 +test expr-23.55.0 {INST_EXPON: Bug 2798543} { +    expr {4**9 == 4**65545} +} 0 +test expr-23.55.1 {INST_EXPON: Bug 2798543} { +    expr {4**15 == 4**65551} +} 0 +test expr-23.55.2 {INST_EXPON: Bug 2798543} { +    expr {4**9 == 4**131081} +} 0 +test expr-23.55.3 {INST_EXPON: Bug 2798543} -body { +    expr {4**9 == 4**268435465} +} -returnCodes error -result {exponent too large} +test expr-23.55.4 {INST_EXPON: Bug 2798543} { +    expr {(-4)**9 == (-4)**65545} +} 0 +test expr-23.56.0 {INST_EXPON: Bug 2798543} { +    expr {5**9 == 5**65545} +} 0 +test expr-23.56.1 {INST_EXPON: Bug 2798543} { +    expr {5**13 == 5**65549} +} 0 +test expr-23.56.2 {INST_EXPON: Bug 2798543} { +    expr {5**9 == 5**131081} +} 0 +test expr-23.56.3 {INST_EXPON: Bug 2798543} -body { +    expr {5**9 == 5**268435465} +} -returnCodes error -result {exponent too large} +test expr-23.56.4 {INST_EXPON: Bug 2798543} { +    expr {(-5)**9 == (-5)**65545} +} 0 +test expr-23.57.0 {INST_EXPON: Bug 2798543} { +    expr {6**9 == 6**65545} +} 0 +test expr-23.57.1 {INST_EXPON: Bug 2798543} { +    expr {6**11 == 6**65547} +} 0 +test expr-23.57.2 {INST_EXPON: Bug 2798543} { +    expr {6**9 == 6**131081} +} 0 +test expr-23.57.3 {INST_EXPON: Bug 2798543} -body { +    expr {6**9 == 6**268435465} +} -returnCodes error -result {exponent too large} +test expr-23.57.4 {INST_EXPON: Bug 2798543} { +    expr {(-6)**9 == (-6)**65545} +} 0 +test expr-23.58.0 {INST_EXPON: Bug 2798543} { +    expr {7**9 == 7**65545} +} 0 +test expr-23.58.1 {INST_EXPON: Bug 2798543} { +    expr {7**11 == 7**65547} +} 0 +test expr-23.58.2 {INST_EXPON: Bug 2798543} { +    expr {7**9 == 7**131081} +} 0 +test expr-23.58.3 {INST_EXPON: Bug 2798543} -body { +    expr {7**9 == 7**268435465} +} -returnCodes error -result {exponent too large} +test expr-23.58.4 {INST_EXPON: Bug 2798543} { +    expr {(-7)**9 == (-7)**65545} +} 0 +test expr-23.59.0 {INST_EXPON: Bug 2798543} { +    expr {8**9 == 8**65545} +} 0 +test expr-23.59.1 {INST_EXPON: Bug 2798543} { +    expr {8**10 == 8**65546} +} 0 +test expr-23.59.2 {INST_EXPON: Bug 2798543} { +    expr {8**9 == 8**131081} +} 0 +test expr-23.59.3 {INST_EXPON: Bug 2798543} -body { +    expr {8**9 == 8**268435465} +} -returnCodes error -result {exponent too large} +test expr-23.59.4 {INST_EXPON: Bug 2798543} { +    expr {(-8)**9 == (-8)**65545} +} 0 +test expr-23.60.0 {INST_EXPON: Bug 2798543} { +    expr {9**9 == 9**65545} +} 0 +test expr-23.60.1 {INST_EXPON: Bug 2798543} { +    expr {9**9 == 9**131081} +} 0 +test expr-23.60.2 {INST_EXPON: Bug 2798543} -body { +    expr {9**9 == 9**268435465} +} -returnCodes error -result {exponent too large} +test expr-23.60.3 {INST_EXPON: Bug 2798543} { +    expr {(-9)**9 == (-9)**65545} +} 0 +test expr-23.61.0 {INST_EXPON: Bug 2798543} { +    expr {10**9 == 10**65545} +} 0 +test expr-23.61.1 {INST_EXPON: Bug 2798543} { +    expr {10**9 == 10**131081} +} 0 +test expr-23.61.2 {INST_EXPON: Bug 2798543} -body { +    expr {10**9 == 10**268435465} +} -returnCodes error -result {exponent too large} +test expr-23.61.3 {INST_EXPON: Bug 2798543} { +    expr {(-10)**9 == (-10)**65545} +} 0 +test expr-23.62.0 {INST_EXPON: Bug 2798543} { +    expr {11**9 == 11**65545} +} 0 +test expr-23.62.1 {INST_EXPON: Bug 2798543} { +    expr {11**9 == 11**131081} +} 0 +test expr-23.62.2 {INST_EXPON: Bug 2798543} -body { +    expr {11**9 == 11**268435465} +} -returnCodes error -result {exponent too large} +test expr-23.62.3 {INST_EXPON: Bug 2798543} { +    expr {(-11)**9 == (-11)**65545} +} 0 +test expr-23.63.0 {INST_EXPON: Bug 2798543} { +    expr {3**20 == 3**65556} +} 0 +test expr-23.63.1 {INST_EXPON: Bug 2798543} { +    expr {3**39 == 3**65575} +} 0 +test expr-23.63.2 {INST_EXPON: Bug 2798543} { +    expr {3**20 == 3**131092} +} 0 +test expr-23.63.3 {INST_EXPON: Bug 2798543} -body { +    expr {3**20 == 3**268435476} +} -returnCodes error -result {exponent too large} +test expr-23.63.4 {INST_EXPON: Bug 2798543} { +    expr {(-3)**20 == (-3)**65556} +} 0 +test expr-23.64.0 {INST_EXPON: Bug 2798543} { +    expr {4**17 == 4**65553} +} 0 +test expr-23.64.1 {INST_EXPON: Bug 2798543} { +    expr {4**31 == 4**65567} +} 0 +test expr-23.64.2 {INST_EXPON: Bug 2798543} { +    expr {4**17 == 4**131089} +} 0 +test expr-23.64.3 {INST_EXPON: Bug 2798543} -body { +    expr {4**17 == 4**268435473} +} -returnCodes error -result {exponent too large} +test expr-23.64.4 {INST_EXPON: Bug 2798543} { +    expr {(-4)**17 == (-4)**65553} +} 0 +test expr-23.65.0 {INST_EXPON: Bug 2798543} { +    expr {5**17 == 5**65553} +} 0 +test expr-23.65.1 {INST_EXPON: Bug 2798543} { +    expr {5**27 == 5**65563} +} 0 +test expr-23.65.2 {INST_EXPON: Bug 2798543} { +    expr {5**17 == 5**131089} +} 0 +test expr-23.65.3 {INST_EXPON: Bug 2798543} -body { +    expr {5**17 == 5**268435473} +} -returnCodes error -result {exponent too large} +test expr-23.65.4 {INST_EXPON: Bug 2798543} { +    expr {(-5)**17 == (-5)**65553} +} 0 +test expr-23.66.0 {INST_EXPON: Bug 2798543} { +    expr {6**17 == 6**65553} +} 0 +test expr-23.66.1 {INST_EXPON: Bug 2798543} { +    expr {6**24 == 6**65560} +} 0 +test expr-23.66.2 {INST_EXPON: Bug 2798543} { +    expr {6**17 == 6**131089} +} 0 +test expr-23.66.3 {INST_EXPON: Bug 2798543} -body { +    expr {6**17 == 6**268435473} +} -returnCodes error -result {exponent too large} +test expr-23.66.4 {INST_EXPON: Bug 2798543} { +    expr {(-6)**17 == (-6)**65553} +} 0 +test expr-23.67.0 {INST_EXPON: Bug 2798543} { +    expr {7**17 == 7**65553} +} 0 +test expr-23.67.1 {INST_EXPON: Bug 2798543} { +    expr {7**22 == 7**65558} +} 0 +test expr-23.67.2 {INST_EXPON: Bug 2798543} { +    expr {7**17 == 7**131089} +} 0 +test expr-23.67.3 {INST_EXPON: Bug 2798543} -body { +    expr {7**17 == 7**268435473} +} -returnCodes error -result {exponent too large} +test expr-23.67.4 {INST_EXPON: Bug 2798543} { +    expr {(-7)**17 == (-7)**65553} +} 0 +test expr-23.68.0 {INST_EXPON: Bug 2798543} { +    expr {8**17 == 8**65553} +} 0 +test expr-23.68.1 {INST_EXPON: Bug 2798543} { +    expr {8**20 == 8**65556} +} 0 +test expr-23.68.2 {INST_EXPON: Bug 2798543} { +    expr {8**17 == 8**131089} +} 0 +test expr-23.68.3 {INST_EXPON: Bug 2798543} -body { +    expr {8**17 == 8**268435473} +} -returnCodes error -result {exponent too large} +test expr-23.68.4 {INST_EXPON: Bug 2798543} { +    expr {(-8)**17 == (-8)**65553} +} 0 +test expr-23.69.0 {INST_EXPON: Bug 2798543} { +    expr {9**17 == 9**65553} +} 0 +test expr-23.69.1 {INST_EXPON: Bug 2798543} { +    expr {9**19 == 9**65555} +} 0 +test expr-23.69.2 {INST_EXPON: Bug 2798543} { +    expr {9**17 == 9**131089} +} 0 +test expr-23.69.3 {INST_EXPON: Bug 2798543} -body { +    expr {9**17 == 9**268435473} +} -returnCodes error -result {exponent too large} +test expr-23.69.4 {INST_EXPON: Bug 2798543} { +    expr {(-9)**17 == (-9)**65553} +} 0 +test expr-23.70.0 {INST_EXPON: Bug 2798543} { +    expr {10**17 == 10**65553} +} 0 +test expr-23.70.1 {INST_EXPON: Bug 2798543} { +    expr {10**18 == 10**65554} +} 0 +test expr-23.70.2 {INST_EXPON: Bug 2798543} { +    expr {10**17 == 10**131089} +} 0 +test expr-23.70.3 {INST_EXPON: Bug 2798543} -body { +    expr {10**17 == 10**268435473} +} -returnCodes error -result {exponent too large} +test expr-23.70.4 {INST_EXPON: Bug 2798543} { +    expr {(-10)**17 == (-10)**65553} +} 0 +test expr-23.71.0 {INST_EXPON: Bug 2798543} { +    expr {11**17 == 11**65553} +} 0 +test expr-23.71.1 {INST_EXPON: Bug 2798543} { +    expr {11**18 == 11**65554} +} 0 +test expr-23.71.2 {INST_EXPON: Bug 2798543} { +    expr {11**17 == 11**131089} +} 0 +test expr-23.71.3 {INST_EXPON: Bug 2798543} -body { +    expr {11**17 == 11**268435473} +} -returnCodes error -result {exponent too large} +test expr-23.71.4 {INST_EXPON: Bug 2798543} { +    expr {(-11)**17 == (-11)**65553} +} 0 +test expr-23.72.0 {INST_EXPON: Bug 2798543} { +    expr {12**17 == 12**65553} +} 0 +test expr-23.72.1 {INST_EXPON: Bug 2798543} { +    expr {12**17 == 12**131089} +} 0 +test expr-23.72.2 {INST_EXPON: Bug 2798543} -body { +    expr {12**17 == 12**268435473} +} -returnCodes error -result {exponent too large} +test expr-23.72.3 {INST_EXPON: Bug 2798543} { +    expr {(-12)**17 == (-12)**65553} +} 0 +test expr-23.73.0 {INST_EXPON: Bug 2798543} { +    expr {13**17 == 13**65553} +} 0 +test expr-23.73.1 {INST_EXPON: Bug 2798543} { +    expr {13**17 == 13**131089} +} 0 +test expr-23.73.2 {INST_EXPON: Bug 2798543} -body { +    expr {13**17 == 13**268435473} +} -returnCodes error -result {exponent too large} +test expr-23.73.3 {INST_EXPON: Bug 2798543} { +    expr {(-13)**17 == (-13)**65553} +} 0 +test expr-23.74.0 {INST_EXPON: Bug 2798543} { +    expr {14**17 == 14**65553} +} 0 +test expr-23.74.1 {INST_EXPON: Bug 2798543} { +    expr {14**17 == 14**131089} +} 0 +test expr-23.74.2 {INST_EXPON: Bug 2798543} -body { +    expr {14**17 == 14**268435473} +} -returnCodes error -result {exponent too large} +test expr-23.74.3 {INST_EXPON: Bug 2798543} { +    expr {(-14)**17 == (-14)**65553} +} 0 +  # Some compilers get this wrong; ensure that we work around it correctly  test expr-24.1 {expr edge cases; shifting} {expr int(5)>>32} 0 @@ -1037,6 +1450,8 @@ test expr-24.7 {expr edge cases; shifting} {expr wide(5)<<32} 21474836480  test expr-24.8 {expr edge cases; shifting} {expr wide(10<<63)} 0  test expr-24.9 {expr edge cases; shifting} {expr 5>>32} 0 +test expr-24.10 {INST_LSHIFT: Bug 1567222} {expr 500000000000000<<28} 134217728000000000000000 +  # List membership tests  test expr-25.1 {'in' operator} {expr {"a" in "a b c"}} 1  test expr-25.2 {'in' operator} {expr {"a" in "b a c"}} 1 @@ -5371,7 +5786,7 @@ test expr-32.1 {expr mod basics} {      0 1 0 3 3 \      0 -1 0 -1 -2 \      ] -         +  test expr-32.2 {expr div basics} {      set mod_nums [list \          {-3 1} {-3 2} {-3 3} {-3 4} {-3 5} \ @@ -5411,6 +5826,19 @@ test expr-32.2 {expr div basics} {      -3 -2 -1 -1 -1 \      ] +test expr-32.3 {Bug 1585704} { +    expr 1%(1<<63) +} 1 +test expr-32.4 {Bug 1585704} { +    expr -1%(1<<63) +} [expr (1<<63)-1] +test expr-32.5 {Bug 1585704} { +    expr (1<<32)%(1<<63) +} [expr 1<<32] +test expr-32.6 {Bug 1585704} { +    expr -(1<<32)%(1<<63) +} [expr (1<<63)-(1<<32)] +  test expr-33.1 {parse largest long value} longIs32bit {      set max_long_str 2147483647      set max_long_hex "0x7FFFFFFF " @@ -6249,6 +6677,42 @@ test expr-37.14 {expr edge cases} {wideIs64bit} {  test expr-38.1 {abs of smallest 32-bit integer [Bug 1241572]} {wideIs64bit} {      expr {abs(-2147483648)}  } 2147483648 +test expr-38.2 {abs and -0 [Bug 1893815]} { +    expr {abs(-0)} +} 0 +test expr-38.3 {abs and -0 [Bug 1893815]} { +    expr {abs(-0.0)} +} 0.0 +test expr-38.4 {abs and -0 [Bug 1893815]} { +    expr {abs(-1e-324)} +} 0.0 +test expr-38.5 {abs and -0 [Bug 1893815]} { +    ::tcl::mathfunc::abs -0 +} 0 +test expr-38.6 {abs and -0 [Bug 1893815]} { +    ::tcl::mathfunc::abs -0.0 +} 0.0 +test expr-38.7 {abs and -0 [Bug 1893815]} { +    ::tcl::mathfunc::abs -1e-324 +} 0.0 +test expr-38.8 {abs and 0.0 [Bug 2954959]} { +    ::tcl::mathfunc::abs 0.0 +} 0.0 +test expr-38.9 {abs and 0.0 [Bug 2954959]} { +    expr {abs(0.0)} +} 0.0 +test expr-38.10 {abs and -0x0 [Bug 2954959]} { +    expr {abs(-0x0)} +} 0 +test expr-38.11 {abs and 0x0 [Bug 2954959]} { +    ::tcl::mathfunc::abs { 	0x0} +} { 	0x0} +test expr-38.12 {abs and -0x0 [Bug 2954959]} { +    ::tcl::mathfunc::abs { 	-0x0} +} 0 +test expr-38.13 {abs and 0.0 [Bug 2954959]} { +    ::tcl::mathfunc::abs 1e-324 +} 1e-324  testConstraint testexprlongobj   [llength [info commands testexprlongobj]]  testConstraint testexprdoubleobj [llength [info commands testexprdoubleobj]] @@ -6262,12 +6726,10 @@ test expr-39.2 {Tcl_ExprLongObj handles wide ints gracefully} testexprlongobj {  } {This is a result: 3}  test expr-39.3 {Tcl_ExprLongObj on the empty string} \ -    -constraints testexprlongobj \ -    -body { -	list [catch {testexprlongobj ""} result] $result -    } \ +    -constraints {testexprlongobj}\ +    -body {testexprlongobj ""} \      -match glob \ -    -result {1 {syntax error*}} +    -returnCodes error -result *  test expr-39.4 {Tcl_ExprLongObj coerces doubles} testexprlongobj {      testexprlongobj 3+.14159  } {This is a result: 3} @@ -6323,18 +6785,16 @@ test expr-39.16 {Tcl_ExprLongObj handles overflows} \  	list [catch {testexprlongobj 4294967296.} result] $result      } \      -result {1 {integer value too large to represent*}} -     +  test expr-39.17 {Check that Tcl_ExprDoubleObj doesn't modify interpreter result if no error} testexprdoubleobj {      testexprdoubleobj 4.+1.  } {This is a result: 5.0}  #Check for [Bug 1109484]  test expr-39.18 {Tcl_ExprDoubleObj on the empty string} \ -    -constraints testexprdoubleobj \ +    -constraints {testexprdoubleobj} \      -match glob \ -    -body { -	list [catch {testexprdoubleobj ""} result] $result -    } \ -    -result {1 {syntax error*}} +    -body {testexprdoubleobj ""} \ +    -returnCodes error -result *  test expr-39.19 {Tcl_ExprDoubleObj coerces wides} testexprdoubleobj {      testexprdoubleobj 1[string repeat 0 17]  } {This is a result: 1e+17} @@ -6358,15 +6818,15 @@ test expr-39.24 {Tcl_ExprDoubleObj handles overflows that look like int} \  	testexprdoubleobj 17976931348623165[string repeat 0 292]      } {This is a result: Inf}  test expr-39.25 {Tcl_ExprDoubleObj and NaN} \ -    {knownBug testexprdoubleobj ieeeFloatingPoint} { +    {testexprdoubleobj ieeeFloatingPoint} {  	list [catch {testexprdoubleobj 0.0/0.0} result] $result -    } {1 {floating point value is Not a Number}} +    } {1 {domain error: argument not in valid range}}  test expr-40.1 {large octal shift} { -    expr 0100000000000000000000000000000000 +    expr 0o100000000000000000000000000000000  } [expr 0x1000000000000000000000000]  test expr-40.2 {large octal shift} { -    expr 0100000000000000000000000000000001 +    expr 0o100000000000000000000000000000001  } [expr 0x1000000000000000000000001]  test expr-41.1 {exponent overflow} { @@ -6587,6 +7047,147 @@ test expr-46.19 {round() handling of long/bignum boundary} {      expr {round(double(0x7fffffffffffffff))}  } 9223372036854775808 +test expr-47.1 {isqrt() - arg count} { +    list [catch {expr {isqrt(1,2)}} result] $result +} {1 {too many arguments for math function "isqrt"}} + +test expr-47.2 {isqrt() - non-number} { +    list [catch {expr {isqrt({rubbish})}} result] $result +} {1 {expected number but got "rubbish"}} + +test expr-47.3 {isqrt() - NaN} ieeeFloatingPoint { +    list [catch {expr {isqrt(NaN)}} result] $result +} {1 {floating point value is Not a Number}} + +test expr-47.4 {isqrt() of negative floating point number} { +    list [catch {expr {isqrt(-1.0)}} result] $result +} {1 {square root of negative argument}} + +test expr-47.5 {isqrt() of floating point zero} { +    expr isqrt(0.0) +} 0 + +test expr-47.6 {isqrt() of exact floating point numbers} { +    set trouble {} +    for {set i 0} {$i < 16} {incr i} { +	set root [expr {1 << $i}] +	set rm1 [expr {$root - 1}] +	set arg [expr {pow(2., (2 * $i))}] +	if {isqrt($arg-1) != $rm1} { +	    append trouble "i = " $i ": isqrt( " $arg "-1) != " $rm1 "\n" +	} +	if {isqrt($arg) != $root} { +	    append trouble "i = " $i ": isqrt( " $arg ") != " $root "\n" +	} +	if {isqrt($arg+1) != $root} { +	    append trouble "i = " $i ": isqrt( " $arg "+1) != " $root "\n" +	} +    } +    set trouble +} {} + +test expr-47.7 {isqrt() of exact floating point numbers} ieeeFloatingPoint { +    set trouble {} +    for {set i 17} {$i < 27} {incr i} { +	set root [expr {1 << $i}] +	set rm1 [expr {$root - 1}] +	set arg [expr {pow(2., (2 * $i))}] +	if {isqrt($arg-1.0) != $rm1} { +	    append trouble "i = " $i ": isqrt( " $arg "-1) != " $rm1 "\n" +	} +	if {isqrt($arg) != $root} { +	    append trouble "i = " $i ": isqrt( " $arg ") != " $root "\n" +	} +	if {isqrt($arg+1.0) != $root} { +	    append trouble "i = " $i ": isqrt( " $arg "+1) != " $root "\n" +	} +    } +    set trouble +} {} + +test expr-47.8 {isqrt of inexact floating point number} ieeeFloatingPoint { +    expr isqrt(2[string repeat 0 34]) +} 141421356237309504 + +test expr-47.9 {isqrt of negative int} { +    list [catch {expr isqrt(-1)} result] $result +} {1 {square root of negative argument}} + +test expr-47.10 {isqrt of negative bignum} { +    list [catch {expr isqrt(-1[string repeat 0 1000])} result] $result +} {1 {square root of negative argument}} + +test expr-47.11 {isqrt of zero} { +    expr {isqrt(0)} +} 0 + +test expr-47.12 {isqrt of various sizes of integer} { +    set faults 0 +    set trouble {} +    for {set i 0} {$faults < 10 && $i <= 1024} {incr i} { +	set root [expr {1 << $i}] +	set rm1 [expr {$root - 1}] +	set arg [expr {1 << (2 * $i)}] +	set tval [expr {isqrt($arg-1)}] +	if {$tval != $rm1} { +	    append trouble "i = " $i ": isqrt(" $arg "-1) == " $tval \ +		" != " $rm1 "\n" +	    incr faults +	} +	set tval [expr {isqrt($arg)}] +	if {$tval != $root} { +	    append trouble "i = " $i ": isqrt(" $arg ") == " $tval \ +		" != " $root "\n" +	    incr faults +	} +	set tval [expr {isqrt($arg+1)}] +	if {$tval != $root} { +	    append trouble "i = " $i ": isqrt(" $arg "+1) == " $tval \ +		" != " $root "\n" +	    incr faults +	} +    } +    set trouble +} {} + +test expr-47.13 {isqrt and floating point rounding (Bug 2143288)} { +    set trouble {} +    set faults 0 +    for {set i 0} {$i < 29 && $faults < 10} {incr i} { +	for {set j 0} {$j <= $i} {incr j} { +	    set k [expr {isqrt((1<<56)+(1<<$i)+(1<<$j))}] +	    if {$k != (1<<28)} { +		append trouble "i = $i, j = $j, k = $k\n" +		incr faults +	    } +	} +	set k [expr {isqrt((1<<56)+(1<<29)+(1<<$i))}] +	if {$k != (1<<28)+1} { +	    append trouble "i = $i, k = $k\n" +	    incr faults +	} +    } +    set trouble +} {} + +test expr-48.1 {Bug 1770224} { +    expr {-0x8000000000000001 >> 0x8000000000000000} +} -1 + +test expr-49.1 {Bug 2823282} { +    coroutine foo apply {{} {set expr expr; $expr {[yield]}}} +    foo 1 +} 1 + +test expr-50.1 {test sqrt() of bignums with non-Inf answer} { +    expr {sqrt("1[string repeat 0 616]") == 1e308} +} 1 + +test expr-51.1 {test round-to-even on input} { +    expr 6.9294956446009195e15 +} 6929495644600920.0 + +  # cleanup  if {[info exists a]} { | 
