forked from pmichaud/pmtcl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tcl_var_subst.t
executable file
·145 lines (121 loc) · 2.71 KB
/
tcl_var_subst.t
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
# Copyright (C) 2004-2007, The Parrot Foundation.
source lib/test_more.tcl
plan 20
eval_is {
catch {unset a}
set a whee
set b "foo $a bar"
} {foo whee bar} {middle of ""}
eval_is {
catch {unset a}
set a whee
set b "$a bar"
} {whee bar} {beginning of ""}
eval_is {
catch {unset a}
set a whee
set b "bar $a"
} {bar whee} {end of ""}
eval_is {
catch {unset a}
set a whee
set b $a
} whee {entire word}
eval_is {
catch {unset a}
set a(b) whee
set b $a(b)
} whee {array, entire word}
eval_is {
catch {unset a}
set a 2
set b $a(b)
} {can't read "a(b)": variable isn't array} {try to use scalar as array}
eval_is {
catch {unset a}
set a(b) 2
set b $a
} {can't read "a": variable is array} {try to use array as scalar} {TODO NQPRX}
eval_is {
catch {unset x}
set x(0) 44
set b ${x(0)}
} 44 {${} substitute an array item} {TODO NQPRX}
eval_is {
catch {unset x}
set x foo
set b $::x
} foo {explicit global} {TODO NQPRX}
eval_is {
namespace eval lib { variable version 0.1 }
set b $::lib::version
} 0.1 {absolute namespace var} {TODO NQPRX}
eval_is {
catch {unset x}
set ::x foo
set b $x
} foo {write to explicit global} {TODO NQPRX}
eval_is {
namespace eval lib { variable version }
set ::lib::version 0.1
set b $::lib::version
} 0.1 {write to absolute namespace var} {TODO NQPRX}
eval_is {
catch {unset array}
array set array {test ok}
set key test
set b $array($key)
} ok {variable index into array} {TODO NQPRX}
eval_is {
catch {unset bar}
set b $foo($bar)
} {can't read "bar": no such variable} {invalid variable as key} {TODO NQPRX}
eval_is {
catch {unset foo}
array set foo {$ ok}
set b $foo($)
} ok {single $ as index} {TODO NQPRX}
eval_is {
catch {unset foo}
array set foo {) ok}
set key )
set b $foo([set key])
} ok {use ) as a key} {TODO NQPRX}
eval_is {
catch {unset array}
catch {unset foo}
array set array {a 1 b 2 c 3}
set foo b
set b $array([set foo)
} {missing close-bracket} {missing ] in subcommand as key} {TODO NQPRX}
eval_is {
catch {unset array}
catch {unset foo}
array set array {a 1 b 2 c 3}
set foo b
set b $array([set foo]a)
} {can't read "array(ba)": no such element in array} {invalid key} {TODO NQPRX}
eval_is {
catch {unset array}
array set array {a 1 b 2 c 3}
set ) b
set b $array([set )])
} 2 {use literal ) inside the array key} {TODO NQPRX}
eval_is {
catch {unset x}
namespace eval foo { proc bar {} { return ok } }
set x foo
$x\::bar
} ok {namespace variable with escaped colon} {TODO NQPRX}
if 0 {
# DRASTIC TODO NQPRX
namespace eval foo {
variable y 7
}
set x 5
namespace eval test {
is [set foo::y] 7 {foo::y relative}
is [set x] 5 {x relative}
}
}
# vim: filetype=tcl: