diff options
author | Steve Bennett <steveb@workware.net.au> | 2010-01-24 10:56:26 +1000 |
---|---|---|
committer | Steve Bennett <steveb@workware.net.au> | 2010-10-15 11:02:40 +1000 |
commit | f32ada62c0567ce439868b04f5de0ebe2a504e79 (patch) | |
tree | 88b9586976ab95ae8f5191146d92e41a4fe7f0f8 /tests | |
parent | 6ef810ae664dccd457fe1ed750f7d509b6f60878 (diff) | |
download | jimtcl-f32ada62c0567ce439868b04f5de0ebe2a504e79.zip jimtcl-f32ada62c0567ce439868b04f5de0ebe2a504e79.tar.gz jimtcl-f32ada62c0567ce439868b04f5de0ebe2a504e79.tar.bz2 |
Improve expression support
Especially ternary operator and unary minus
Still evaluates both sides of the ternary operator :-(
Fix unary minus
And add const in more places to avoid this mistake in future
Diffstat (limited to 'tests')
-rw-r--r-- | tests/expr.test | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/tests/expr.test b/tests/expr.test index 99ef609..a2d573a 100644 --- a/tests/expr.test +++ b/tests/expr.test @@ -15,3 +15,48 @@ test expr-1.2 "Compare strings with embedded nulls" { test expr-1.3 "Hex values" { set mask1 [expr 0x4050 & 0x0CCC] } {64} + +test expr-1.4 "Ternary operator - true" { + expr {1 ? 2 : 3} +} {2} + +test expr-1.5 "Ternary operator - false" { + expr {0 ? 2 : 3} +} {3} + +test expr-1.6 "Ternary operator - double check" { + expr {1.0 ? 2 : 3} +} {2} + +test expr-1.7 "Ternary operator - string result" { + expr {1 ? "two" : 3} +} {two} + +test expr-1.8 "Ternary operator - don't eval false path" { + set a 100 + set b 200 + set c [expr {20 ? [incr a] : [incr b]}] + list $a $b $c +} {101 200 101} + +test expr-1.9 "Unary minus" { + set a 1 + expr {-$a} +} {-1} + +test expr-1.10 "Subtraction" { + set a 1 + set b 10 + expr {$b-$a} +} {9} + +# This crashes older jim +test expr-2.1 "bogus unarymin" { + expr {unarymin 1} +} {-1} + +test expr-2.2 "Ternary operator - missing colon" { + list [catch {expr {1 ? 2 3}} msg] $msg +} {1 {Invalid expression}} + +testreport |