159 lines
2.9 KiB
Plaintext
159 lines
2.9 KiB
Plaintext
source [file dirname [info script]]/testing.tcl
|
|
|
|
test expr-1.1 "Compare strings lt" {
|
|
expr {"V000500" < "V000405"}
|
|
} {0}
|
|
|
|
test expr-1.2 "Compare strings with embedded nulls" {
|
|
set s1 [format abc%cdef 0]
|
|
set s2 [format abc%cghi 0]
|
|
expr {$s1 < $s2}
|
|
} {1}
|
|
|
|
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}
|
|
|
|
test expr-1.11 "Short circuit evaluation" {
|
|
set a 100
|
|
set c [expr {0 || [incr a]}]
|
|
list $a $c
|
|
} {101 1}
|
|
|
|
test expr-1.12 "Short circuit evaluation" {
|
|
set a 100
|
|
set c [expr {1 || [incr a]}]
|
|
list $a $c
|
|
} {100 1}
|
|
|
|
test expr-1.13 "Short circuit evaluation" {
|
|
set a 100
|
|
set c [expr {1 || [incr a] && [incr a]}]
|
|
list $a $c
|
|
} {100 1}
|
|
|
|
test expr-1.14 "Rotate left" jim {
|
|
expr {1 <<< 5}
|
|
} {32}
|
|
|
|
test expr-1.15 "Rotate left" jim {
|
|
expr {1 <<< 65}
|
|
} {2}
|
|
|
|
test expr-1.16 "Rotate right" jim {
|
|
expr {1 >>> 48}
|
|
} {65536}
|
|
|
|
test expr-1.17 "Rotate left" jim {
|
|
expr {1 >>> 63}
|
|
} {2}
|
|
|
|
# This crashes older jim
|
|
test expr-2.1 "bogus unarymin" -body {
|
|
expr {unarymin 1}
|
|
} -returnCodes error -match glob -result *
|
|
|
|
test expr-2.2 "Ternary operator - missing colon" -body {
|
|
expr {1 ? 2 3}
|
|
} -returnCodes error -match glob -result {missing operator*}
|
|
|
|
test expr-2.3 "Ternary operator - missing third term" -body {
|
|
expr {1 ? 2}
|
|
} -returnCodes error -match glob -result *
|
|
|
|
test expr-2.4 "Ternary operator - missing question" -body {
|
|
expr {1 : 2}
|
|
} -returnCodes error -match glob -result *
|
|
|
|
test expr-2.5 "Ternary operator with -ve values" {
|
|
expr {-1?-2:-3}
|
|
} -2
|
|
|
|
test expr-2.6 "Ternary operator with -ve values" {
|
|
expr {0?-2:-3}
|
|
} -3
|
|
|
|
test expr-3.1 "in, ni operators" {
|
|
set l {a b c d}
|
|
set c C
|
|
list [expr {"a" in $l}] [expr {$c in $l}] [expr {"b" ni $l}] [expr {$c ni $l}]
|
|
} {1 0 0 1}
|
|
|
|
test expr-3.2 "if: in, ni operators" {
|
|
set l {a b c d}
|
|
set a a
|
|
set c C
|
|
set result {}
|
|
if {$a in $l} {
|
|
lappend result 1
|
|
}
|
|
if {$c in $l} {
|
|
lappend result 2
|
|
}
|
|
if {$a ni $l} {
|
|
lappend result 3
|
|
}
|
|
if {$c ni $l} {
|
|
lappend result 4
|
|
}
|
|
if {"d" in $l} {
|
|
lappend result 5
|
|
}
|
|
} {1 4 5}
|
|
|
|
# Don't want a to become 2.0
|
|
test expr-4.1 "Shimmering" {
|
|
set a 2
|
|
expr {$a < 3.0}
|
|
set a
|
|
} {2}
|
|
|
|
test expr-5.1 "Not" {
|
|
lmap x {1 0 true false on off yes no} { expr {!$x} }
|
|
} {0 1 0 1 0 1 0 1}
|
|
|
|
test expr-5.2 "Not" -body {
|
|
expr {!this}
|
|
} -returnCodes error -result {syntax error in expression: "!this"}
|
|
|
|
test expr-5.3 {boolean in expression} {
|
|
expr {true ? 4 : 5}
|
|
} {4}
|
|
|
|
|
|
testreport
|