summaryrefslogtreecommitdiff
path: root/tests/exprsugar.test
blob: 943945a1756ef85c819b69e73016c60bf4b5281d (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
source [file dirname [info script]]/testing.tcl

needs constraint jim

# Test the expr-sugar syntax: $(...)

test exprsugar-1.1 {Simple operations} {
	set x $(2)
} 2
test exprsugar-1.2 {Simple operations} {
	set x $(-3)
} -3
test exprsugar-1.3 {Simple operations} {
	set x $(!0)
} 1
test exprsugar-1.4 {Simple operations} {
	set a 3
	set x $($a)
} 3
test exprsugar-1.5 {Simple operations} {
	set x $($a + 4)
} 7
test exprsugar-1.6 {Simple operations} {
	set x $(6 * 7 + 2)
} 44
test exprsugar-1.7 {Simple operations} {
	set a bb
	set x $($a in {aa bb cc})
} 1
test exprsugar-1.8 {Simple operations} {
	set a 1
	set x $($a ? "yes" : "no")
} yes
test exprsugar-1.9 {Simple operations} {
	set a 1
	set x $([incr a])
	list $a $x
} {2 2}
# expr sugar inside an expression is an error
test exprsugar-1.10 {Simple operations} {
	catch {set x $(1 + $(5 * 7))}
} 1
test exprsugar-1.11 {Simple operations} {
	unset a
	set a(b) 3
	set x $(2 + $a(b))
} 5
test exprsugar-1.12 {Simple operations} {
	set x $((2 + 4))
} 6
# This necessary to ensure that things like exit will pass through expr-sugar
test exprsugar-1.13 {Non-error return inside expr-sugar} -body {
	proc a {} { break }
	set x $([a])
} -returnCodes break

testreport