File: exprsugar.test

package info (click to toggle)
jimtcl 0.81%2Bdfsg0-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 15,416 kB
  • sloc: ansic: 175,569; tcl: 5,456; sh: 4,814; cpp: 1,671; makefile: 269
file content (57 lines) | stat: -rw-r--r-- 1,218 bytes parent folder | download | duplicates (6)
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