File: procref.test

package info (click to toggle)
jimtcl 0.83-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 17,432 kB
  • sloc: ansic: 207,301; tcl: 5,862; sh: 4,834; cpp: 1,671; makefile: 288
file content (56 lines) | stat: -rw-r--r-- 894 bytes parent folder | download | duplicates (15)
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
# Tests auto-upref with the "&name" syntax

source [file dirname [info script]]/testing.tcl

needs constraint jim

proc a1 {&b c} {
	append b b
	append c c
}

proc a2 {&b {dummy 3} &c} {
	append b b
	append c c
}

proc a3 {&b(c)} {
	append b(c) b_c
}

# This is treated as a normal var "&b"
proc a4 {{&b x}} {
	append &b B
}

set B 1
set C 1

test procref-1.1 {Basic test} {
	a1 B $C
	set B
} {1b}

test procref-1.2 {Basic test} {
	a1 B $C
	set B
} {1bb}

test procref-1.3 {Unset var} -body {
	a1 unsetB $C
} -returnCodes error -result {can't read "unsetB": no such variable}

test procref-1.4 {Left and right args are refs} {
	a2 B C
	list $B $C
} {1bbb 1c}

test procref-1.5 {Invalid arg} -body {
	a3 B
} -returnCodes error -result {bad variable name "b(c)": upvar won't create a scalar variable that looks like an array element}

test procref-1.6 {Default arg as ref} {
	a4
} xB

testreport