aboutsummaryrefslogtreecommitdiff
path: root/tests/expr.test
blob: a2d573a409d9c0acc761cc77a97d69eb753660d7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
source testing.tcl

section "String comparison"

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}

# 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