Tcl Library Source Code

Check-in [ccd9433cb2]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Fix namespace resolution for relative namespaces. Add "normalize" and 'strip" commands.
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256:ccd9433cb2abd51c897bc2a05b1053ff976bd4d22f05db5bfbd7b15bde2831f8
User & Date: pooryorick 2018-09-06 09:46:11
Context
2018-09-19
14:20
Pulling in latest versions of clay, httpd, and practcl from the hypnotoad branch check-in: 9f6fd773b3 user: hypnotoad tags: trunk
2018-09-08
18:56
Pulling changes from trunk check-in: 57af8b6c63 user: hypnotoad tags: hypnotoad
2018-09-06
09:46
Fix namespace resolution for relative namespaces. Add "normalize" and 'strip" commands. check-in: ccd9433cb2 user: pooryorick tags: trunk
2018-09-04
19:11
Add several commands to the statistics package: Wasserstein distance, KL divergence, logistic regression. Also documentation and tests for these commands. check-in: 44761b447e user: arjenmarkus tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to modules/namespacex/namespacex.man.

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
[call [cmd {::namespacex hook add}]  [opt [arg namespace]] [arg cmdprefix]]
[call [cmd {::namespacex hook proc}] [opt [arg namespace]] [arg arguments] [arg body]]
[call [cmd {::namespacex hook on}]   [opt [arg namespace]] [arg guardcmdprefix] [arg actioncmdprefix]]
[call [cmd {::namespacex hook next}] [arg arg]...]

[call [cmd {::namespacex info allchildren}] [arg namespace]]

This command returns a list containing the names of all child
namespaces in the specified [arg namespace] and its children. The
names are all fully qualified.

[call [cmd {::namespacex info allvars}] [arg namespace]]

This command returns a list containing the names of all variables in
the specified [arg namespace] and its children. The names are all
relative to [arg namespace], and [emph not] fully qualified.

[call [cmd {::namespacex info vars}] [arg namespace] [opt [arg pattern]]]

This command returns a list containing the names of all variables in
the specified [arg namespace].






[call [cmd {::namespacex state get}] [arg namespace]]

This command returns a dictionary holding the names and values of all
variables in the specified [arg namespace] and its child namespaces.

[para]
Note that the names are all relative to [arg namespace],
and [emph not] fully qualified.

[call [cmd {::namespacex state set}] [arg namespace] [arg dict]]

This command takes a dictionary holding the names and values for a set
of variables and replaces the current state of the specified
[arg namespace] and its child namespaces with this state.

The result of the command is the empty string.

[call [cmd {::namespacex state drop}] [arg namespace]]

This command unsets all variables in the specified [arg namespace] and
its child namespaces.

The result of the command is the empty string.








[list_end]
[manpage_end]







|





|





|


>
>
>
>
>


|








|







|




>
>
>
>
>
>
>


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
[call [cmd {::namespacex hook add}]  [opt [arg namespace]] [arg cmdprefix]]
[call [cmd {::namespacex hook proc}] [opt [arg namespace]] [arg arguments] [arg body]]
[call [cmd {::namespacex hook on}]   [opt [arg namespace]] [arg guardcmdprefix] [arg actioncmdprefix]]
[call [cmd {::namespacex hook next}] [arg arg]...]

[call [cmd {::namespacex info allchildren}] [arg namespace]]

Returns a list containing the names of all child
namespaces in the specified [arg namespace] and its children. The
names are all fully qualified.

[call [cmd {::namespacex info allvars}] [arg namespace]]

Returns a list containing the names of all variables in
the specified [arg namespace] and its children. The names are all
relative to [arg namespace], and [emph not] fully qualified.

[call [cmd {::namespacex info vars}] [arg namespace] [opt [arg pattern]]]

Returns a list containing the names of all variables in
the specified [arg namespace].

[call [cmd {::namespacex normalize}] [arg namespace]]

Returns the absolute name of [arg namespace], which is resolved relative
to the namespace of the caller, with all unneeded colon characters removed.

[call [cmd {::namespacex state get}] [arg namespace]]

Returns a dictionary holding the names and values of all
variables in the specified [arg namespace] and its child namespaces.

[para]
Note that the names are all relative to [arg namespace],
and [emph not] fully qualified.

[call [cmd {::namespacex state set}] [arg namespace] [arg dict]]

Takes a dictionary holding the names and values for a set
of variables and replaces the current state of the specified
[arg namespace] and its child namespaces with this state.

The result of the command is the empty string.

[call [cmd {::namespacex state drop}] [arg namespace]]

Unsets all variables in the specified [arg namespace] and
its child namespaces.

The result of the command is the empty string.


[call [cmd {::namespacex strip}] [arg namespace] [arg namespaces]]

Each item in [arg namespaces] must be the absolute normalized name of a child
namespace of [arg prefix].  Returns the corresponding list of relative names of
child namespaces.

[list_end]
[manpage_end]

Changes to modules/namespacex/namespacex.tcl.

11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
...
179
180
181
182
183
184
185

186
187

188
189
190
191
192
193
194

195
196

197
198
199
200
201
202
203
204

205

206
207
208


209












210
211
212
213

214
215
216
217
218
219
220
221
222


223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249

250
251
252
253
254

# # ## ### ##### ######## ############# ######################
## Requisites

package require Tcl 8.5  ; # namespace ensembles, {*}

namespace eval ::namespacex {
    namespace export add hook info state
    namespace ensemble create

    namespace eval hook {
	namespace export add proc on next
	namespace ensemble create

	# add - hook a command prefix into the chain of unknown handlers for a
................................................................................
        return -code $rc $result
    }
}

# # ## ### ##### ######## ############# ######################
## Implementation :: Info - Visible API


proc ::namespacex::info::allvars {ns} {
    if {![string match {::*} $ns]} { set ns ::$ns }

    ::set result [::info vars ${ns}::*]
    foreach cns [allchildren $ns] {
	lappend result {*}[::info vars ${cns}::*]
    }
    return [Strip $ns $result]
}


proc ::namespacex::info::allchildren {ns} {
    if {![string match {::*} $ns]} { set ns ::$ns }

    ::set result [list]
    foreach cns [::namespace children $ns] {
	lappend result {*}[allchildren $cns]
	lappend result $cns
    }
    return $result
}


proc ::namespacex::info::vars {ns {pattern *}} {

    return [Strip $ns [::info vars ${ns}::$pattern]]
}



proc ::namespacex::info::Strip {ns itemlist} {












    set n [string length $ns]
    if {![string match {::*} $ns]} {
	incr n 4
    } else {

	incr n 2
    }

    set result {}
    foreach i $itemlist {
	lappend result [string range $i $n end]
    }
    return $result
}



# # ## ### ##### ######## ############# ######################
## Implementation :: State - Visible API

proc ::namespacex::state::drop {ns} {
    if {![string match {::*} $ns]} { ::set ns ::$ns }
    namespace eval $ns [list ::unset {*}[::namespacex info allvars $ns]]
    return
}

proc ::namespacex::state::get {ns} {
    if {![string match {::*} $ns]} { ::set ns ::$ns }
    ::set result {}
    foreach v [::namespacex info allvars $ns] {
	namespace upvar $ns $v value
	lappend result $v $value
    }
    return $result
}

proc ::namespacex::state::set {ns state} {
    if {![string match {::*} $ns]} { ::set ns ::$ns }
    # Inlined 'state drop'.
    namespace eval $ns [list ::unset  {*}[::namespacex info allvars $ns]]
    namespace eval $ns [list variable {*}$state]
    return
}


# # ## ### ##### ######## ############# ######################
## Ready

package provide namespacex 0.1







|







 







>
|
<
>




|


>
|
<
>








>

>
|


>
>
|
>
>
>
>
>
>
>
>
>
>
>
>

<
<
<
>









>
>




|
|




|
|









|





>





11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
...
179
180
181
182
183
184
185
186
187

188
189
190
191
192
193
194
195
196
197

198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228



229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273

# # ## ### ##### ######## ############# ######################
## Requisites

package require Tcl 8.5  ; # namespace ensembles, {*}

namespace eval ::namespacex {
    namespace export add hook info normalize strip state
    namespace ensemble create

    namespace eval hook {
	namespace export add proc on next
	namespace ensemble create

	# add - hook a command prefix into the chain of unknown handlers for a
................................................................................
        return -code $rc $result
    }
}

# # ## ### ##### ######## ############# ######################
## Implementation :: Info - Visible API


proc ::namespacex::info::allvars ns {

    set ns [uplevel 1 [list [namespace parent] normalize $ns]]
    ::set result [::info vars ${ns}::*]
    foreach cns [allchildren $ns] {
	lappend result {*}[::info vars ${cns}::*]
    }
    return [[namespace parent] strip $ns $result]
}


proc ::namespacex::info::allchildren ns {

    set ns [uplevel 1 [list [namespace parent] normalize $ns]]
    ::set result [list]
    foreach cns [::namespace children $ns] {
	lappend result {*}[allchildren $cns]
	lappend result $cns
    }
    return $result
}


proc ::namespacex::info::vars {ns {pattern *}} {
    set ns [uplevel 1 [list [namespace parent] normalize $ns]]
    return [[namespace parent] strip $ns [::info vars ${ns}::$pattern]]
}


# this implementation avoids string operations
proc ::namespacex::normalize ns {
    if {[uplevel 1 [list ::namespace exists $ns]]} {
	return [uplevel 1 [list namespace eval $ns {namespace current}]]
    }
    if {![string match ::* $ns]} {
	set ns [uplevel 1 {namespace current}]::$ns
    }
    regsub {::+} $ns :: ns
    return $ns
}


proc ::namespacex::strip {ns itemlist} {
    set n [string length $ns]



    if {$ns ne {::}} {
	incr n 2
    }

    set result {}
    foreach i $itemlist {
	lappend result [string range $i $n end]
    }
    return $result
}



# # ## ### ##### ######## ############# ######################
## Implementation :: State - Visible API

proc ::namespacex::state::drop ns {
    ::set ns [uplevel 1 [list [namespace parent] normalize $ns]]
    namespace eval $ns [list ::unset {*}[::namespacex info allvars $ns]]
    return
}

proc ::namespacex::state::get ns {
    ::set ns [uplevel 1 [list [namespace parent] normalize $ns]]
    ::set result {}
    foreach v [::namespacex info allvars $ns] {
	namespace upvar $ns $v value
	lappend result $v $value
    }
    return $result
}

proc ::namespacex::state::set {ns state} {
    ::set ns [uplevel 1 [list [namespace parent] normalize $ns]]
    # Inlined 'state drop'.
    namespace eval $ns [list ::unset  {*}[::namespacex info allvars $ns]]
    namespace eval $ns [list variable {*}$state]
    return
}


# # ## ### ##### ######## ############# ######################
## Ready

package provide namespacex 0.1

Changes to modules/namespacex/namespacex.test.

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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351












































testing {
    useLocal namespacex.tcl namespacex
}

# -------------------------------------------------------------------------

proc ns_setup {} {
    namespace eval ::X {
        namespace eval A {}
        namespace eval B {
            namespace eval D {}
        }
        namespace eval C {}
    }
}

proc ns2_setup {} {
    namespace eval ::X {
        variable vXa 1
        variable vXb aleph
        namespace eval B {
            variable vB 3
        }
    }
}

proc ns3_setup {} {
    namespace eval ::X {
        namespace eval B {
            variable vB mjolnir
        }
    }
}

# -------------------------------------------------------------------------

test namespacex-info-allchildren-1.0 {namespacex info allchildren, wrong\#args} -body {
    namespacex info allchildren
} -returnCodes error -result {wrong # args: should be "namespacex info allchildren ns"}

test namespacex-info-allchildren-1.1 {namespacex info allchildren, wrong\#args} -body {
    namespacex info allchildren N X
} -returnCodes error -result {wrong # args: should be "namespacex info allchildren ns"}

test namespacex-info-allchildren-2.0.0 {namespacex info allchildren} -setup {
    ns_setup
} -body {
    lsort -dict [namespacex info allchildren ::X]
} -cleanup {
    namespace delete ::X
} -result {::X::A ::X::B ::X::B::D ::X::C}

test namespacex-info-allchildren-2.0.1 {namespacex info allchildren} -setup {
    ns_setup
} -body {
    lsort -dict [namespacex info allchildren X]
} -cleanup {
    namespace delete ::X
} -result {::X::A ::X::B ::X::B::D ::X::C}

# -------------------------------------------------------------------------

test namespacex-info-vars-1.0 {namespacex info vars, wrong\#args} -body {
    namespacex info vars
} -returnCodes error -result {wrong # args: should be "namespacex info vars ns ?pattern?"}

test namespacex-info-vars-1.1 {namespacex info vars, wrong\#args} -body {
    namespacex info vars N P X
} -returnCodes error -result {wrong # args: should be "namespacex info vars ns ?pattern?"}

test namespacex-info-vars-2.0 {namespacex info vars} -setup {
    ns2_setup
} -body {
    lsort -dict [namespacex info vars ::X]
} -cleanup {
    namespace delete ::X
} -result {vXa vXb}

test namespacex-info-vars-2.1 {namespacex info vars} -setup {
    namespace eval ::X {}
} -body {
    lsort -dict [namespacex info vars ::X]
} -cleanup {
    namespace delete ::X
} -result {}

test namespacex-info-vars-2.2 {namespacex info vars} -setup {
    ns3_setup
} -body {
    lsort -dict [namespacex info vars ::X]
} -cleanup {
    namespace delete ::X
} -result {}

# -------------------------------------------------------------------------

test namespacex-info-allvars-1.0 {namespacex info allvars, wrong\#args} -body {
    namespacex info allvars
} -returnCodes error -result {wrong # args: should be "namespacex info allvars ns"}

test namespacex-info-allvars-1.1 {namespacex info allvars, wrong\#args} -body {
    namespacex info allvars N X
} -returnCodes error -result {wrong # args: should be "namespacex info allvars ns"}

test namespacex-info-allvars-2.0.0 {namespacex info allvars} -setup {
    ns2_setup
} -body {
    lsort -dict [namespacex info allvars ::X]
} -cleanup {
    namespace delete ::X
} -result {B::vB vXa vXb}

test namespacex-info-allvars-2.0.1 {namespacex info allvars} -setup {
    ns2_setup
} -body {
    lsort -dict [namespacex info allvars X]
} -cleanup {
    namespace delete ::X
} -result {B::vB vXa vXb}

test namespacex-info-allvars-2.1.0 {namespacex info allvars} -setup {
    namespace eval ::X {}
} -body {
    lsort -dict [namespacex info allvars ::X]
} -cleanup {
    namespace delete ::X
} -result {}

test namespacex-info-allvars-2.1.1 {namespacex info allvars} -setup {
    namespace eval ::X {}
} -body {
    lsort -dict [namespacex info allvars X]
} -cleanup {
    namespace delete ::X
} -result {}

test namespacex-info-allvars-2.2.0 {namespacex info allvars} -setup {
    ns3_setup
} -body {
    lsort -dict [namespacex info allvars ::X]
} -cleanup {
    namespace delete ::X
} -result {B::vB}

test namespacex-info-allvars-2.2.1 {namespacex info allvars} -setup {
    ns3_setup
} -body {
    lsort -dict [namespacex info allvars X]
} -cleanup {
    namespace delete ::X
} -result {B::vB}

# -------------------------------------------------------------------------

test namespacex-state-get-1.0 {namespacex state get, wrong\#args} -body {
    namespacex state get
} -returnCodes error -result {wrong # args: should be "namespacex state get ns"}

test namespacex-state-get-1.1 {namespacex state get, wrong\#args} -body {
    namespacex state get N X
} -returnCodes error -result {wrong # args: should be "namespacex state get ns"}

test namespacex-state-get-2.0.0 {namespacex state get} -setup {
    ns2_setup
} -body {
    dictsort [namespacex state get ::X]
} -cleanup {
    namespace delete ::X
} -result {B::vB 3 vXa 1 vXb aleph}

test namespacex-state-get-2.0.1 {namespacex state get} -setup {
    ns2_setup
} -body {
    dictsort [namespacex state get X]
} -cleanup {
    namespace delete ::X
} -result {B::vB 3 vXa 1 vXb aleph}

test namespacex-state-get-2.1.0 {namespacex state get} -setup {
    namespace eval ::X {}
} -body {
    dictsort [namespacex state get ::X]
} -cleanup {
    namespace delete ::X
} -result {}

test namespacex-state-get-2.1.1 {namespacex state get} -setup {
    namespace eval ::X {}
} -body {
    dictsort [namespacex state get X]
} -cleanup {
    namespace delete ::X
} -result {}

test namespacex-state-get-2.2.0 {namespacex state get} -setup {
    ns3_setup
} -body {
    dictsort [namespacex state get ::X]
} -cleanup {
    namespace delete ::X
} -result {B::vB mjolnir}

test namespacex-state-get-2.2.1 {namespacex state get} -setup {
    ns3_setup
} -body {
    dictsort [namespacex state get X]
} -cleanup {
    namespace delete ::X
} -result {B::vB mjolnir}

# -------------------------------------------------------------------------

test namespacex-state-drop-1.0 {namespacex state drop, wrong\#args} -body {
    namespacex state drop
} -returnCodes error -result {wrong # args: should be "namespacex state drop ns"}

test namespacex-state-drop-1.1 {namespacex state drop, wrong\#args} -body {
    namespacex state drop N X
} -returnCodes error -result {wrong # args: should be "namespacex state drop ns"}

test namespacex-state-drop-2.0.0 {namespacex state drop} -setup {
    ns2_setup
} -body {
    namespacex state drop ::X
    dictsort [namespacex state get ::X]
} -cleanup {
    namespace delete ::X
} -result {}

test namespacex-state-drop-2.0.1 {namespacex state drop} -setup {
    ns2_setup
} -body {
    namespacex state drop X
    dictsort [namespacex state get X]
} -cleanup {
    namespace delete ::X
} -result {}

test namespacex-state-drop-2.1.0 {namespacex state drop} -setup {
    namespace eval ::X {}
} -body {
    namespacex state drop X
    dictsort [namespacex state get ::X]
} -cleanup {
    namespace delete ::X
} -result {}

test namespacex-state-drop-2.1.1 {namespacex state drop} -setup {
    namespace eval ::X {}
} -body {
    namespacex state drop X
    dictsort [namespacex state get X]
} -cleanup {
    namespace delete ::X
} -result {}

test namespacex-state-drop-2.2.0 {namespacex state drop} -setup {
    ns3_setup
} -body {
    namespacex state drop X
    dictsort [namespacex state get ::X]
} -cleanup {
    namespace delete ::X
} -result {}

test namespacex-state-drop-2.2.1 {namespacex state drop} -setup {
    ns3_setup
} -body {
    namespacex state drop X
    dictsort [namespacex state get X]
} -cleanup {
    namespace delete ::X
} -result {}

# -------------------------------------------------------------------------

test namespacex-state-set-1.0 {namespacex state set, wrong\#args} -body {
    namespacex state set
} -returnCodes error -result {wrong # args: should be "namespacex state set ns state"}

test namespacex-state-set-1.1 {namespacex state set, wrong\#args} -body {
    namespacex state set N
} -returnCodes error -result {wrong # args: should be "namespacex state set ns state"}

test namespacex-state-set-1.2 {namespacex state set, wrong\#args} -body {
    namespacex state set N S X
} -returnCodes error -result {wrong # args: should be "namespacex state set ns state"}

test namespacex-state-set-2.0.0 {namespacex state set} -setup {
    ns2_setup
    set ST [namespacex state get ::X]
    ns3_setup
} -body {
    namespacex state set ::X $ST
    dictsort [namespacex state get ::X]
} -cleanup {
    namespace delete ::X
} -result {B::vB 3 vXa 1 vXb aleph}

test namespacex-state-set-2.0.1 {namespacex state set} -setup {
    ns2_setup
    set ST [namespacex state get ::X]
    ns3_setup
} -body {
    namespacex state set X $ST
    dictsort [namespacex state get X]
} -cleanup {
    namespace delete ::X
} -result {B::vB 3 vXa 1 vXb aleph}

test namespacex-state-set-2.1.0 {namespacex state set} -setup {
    ns3_setup
    set ST [namespacex state get ::X]
    ns2_setup
} -body {
    namespacex state set ::X $ST
    dictsort [namespacex state get ::X]
} -cleanup {
    namespace delete ::X
} -result {B::vB mjolnir}

test namespacex-state-set-2.1.1 {namespacex state set} -setup {
    ns3_setup
    set ST [namespacex state get ::X]
    ns2_setup
} -body {
    namespacex state set X $ST
    dictsort [namespacex state get X]
} -cleanup {
    namespace delete ::X
} -result {B::vB mjolnir}

# -------------------------------------------------------------------------
testsuiteCleanup

# Local variables:
# mode: tcl
# indent-tabs-mode: nil
# End:


















































|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394

testing {
    useLocal namespacex.tcl namespacex
}

# -------------------------------------------------------------------------


namespace eval Q {
    proc ns_setup {} {
	namespace eval X {
	    namespace eval A {}
	    namespace eval B {
		namespace eval D {}
	    }
	    namespace eval C {}
	}
    }

    proc ns2_setup {} {
	namespace eval X::Y {
	    variable vXa 1
	    variable vXb aleph
	    namespace eval B {
		variable vB 3
	    }
	}
    }

    proc ns3_setup {} {
	namespace eval X {
	    namespace eval B {
		variable vB mjolnir
	    }
	}
    }

    # -------------------------------------------------------------------------


    test namespacex-info-allchildren-1.0 {namespacex info allchildren, wrong\#args} -body {
	namespacex info allchildren
    } -returnCodes error -result {wrong # args: should be "namespacex info allchildren ns"}


    test namespacex-info-allchildren-1.1 {namespacex info allchildren, wrong\#args} -body {
	namespacex info allchildren N X
    } -returnCodes error -result {wrong # args: should be "namespacex info allchildren ns"}


    test namespacex-info-allchildren-2.0.0 {namespacex info allchildren} -setup {
	ns_setup
    } -body {
	lsort -dict [namespacex strip [namespace current] [namespacex info allchildren X]]
    } -cleanup {
	namespace delete X
    } -result {X::A X::B X::B::D X::C}


    test namespacex-info-allchildren-2.0.1 {namespacex info allchildren} -setup {
	ns_setup
    } -body {
	lsort -dict [namespacex strip [namespace current] [namespacex info allchildren X]]
    } -cleanup {
	namespace delete X
    } -result {X::A X::B X::B::D X::C}

    # -------------------------------------------------------------------------


    test namespacex-info-vars-1.0 {namespacex info vars, wrong\#args} -body {
	namespacex info vars
    } -returnCodes error -result {wrong # args: should be "namespacex info vars ns ?pattern?"}


    test namespacex-info-vars-1.1 {namespacex info vars, wrong\#args} -body {
	namespacex info vars N P X
    } -returnCodes error -result {wrong # args: should be "namespacex info vars ns ?pattern?"}


    test namespacex-info-vars-2.0 {namespacex info vars} -setup {
	ns2_setup
    } -body {
	lsort -dict [namespacex info vars X::::Y]
    } -cleanup {
	namespace delete X
    } -result {vXa vXb}


    test namespacex-info-vars-2.1 {namespacex info vars} -setup {
	namespace eval X {}
    } -body {
	lsort -dict [namespacex info vars X]
    } -cleanup {
	namespace delete X
    } -result {}


    test namespacex-info-vars-2.2 {namespacex info vars} -setup {
	ns3_setup
    } -body {
	lsort -dict [namespacex info vars X]
    } -cleanup {
	namespace delete X
    } -result {}

    # -------------------------------------------------------------------------


    test namespacex-info-allvars-1.0 {namespacex info allvars, wrong\#args} -body {
	namespacex info allvars
    } -returnCodes error -result {wrong # args: should be "namespacex info allvars ns"}


    test namespacex-info-allvars-1.1 {namespacex info allvars, wrong\#args} -body {
	namespacex info allvars N X
    } -returnCodes error -result {wrong # args: should be "namespacex info allvars ns"}


    test namespacex-info-allvars-2.0.0 {namespacex info allvars} -setup {
	ns2_setup
    } -body {
	lsort -dict [namespacex info allvars X::::Y]
    } -cleanup {
	namespace delete X
    } -result {B::vB vXa vXb}


    test namespacex-info-allvars-2.0.1 {namespacex info allvars} -setup {
	ns2_setup
    } -body {
	lsort -dict [namespacex info allvars X::Y]
    } -cleanup {
	namespace delete X
    } -result {B::vB vXa vXb}


    test namespacex-info-allvars-2.1.0 {namespacex info allvars} -setup {
	namespace eval X {}
    } -body {
	lsort -dict [namespacex info allvars X]
    } -cleanup {
	namespace delete X
    } -result {}


    test namespacex-info-allvars-2.1.1 {namespacex info allvars} -setup {
	namespace eval X {}
    } -body {
	lsort -dict [namespacex info allvars X]
    } -cleanup {
	namespace delete X
    } -result {}


    test namespacex-info-allvars-2.2.0 {namespacex info allvars} -setup {
	ns3_setup
    } -body {
	lsort -dict [namespacex info allvars X]
    } -cleanup {
	namespace delete X
    } -result {B::vB}


    test namespacex-info-allvars-2.2.1 {namespacex info allvars} -setup {
	ns3_setup
    } -body {
	lsort -dict [namespacex info allvars X]
    } -cleanup {
	namespace delete X
    } -result {B::vB}

    # -------------------------------------------------------------------------


    test namespacex-state-get-1.0 {namespacex state get, wrong\#args} -body {
	namespacex state get
    } -returnCodes error -result {wrong # args: should be "namespacex state get ns"}


    test namespacex-state-get-1.1 {namespacex state get, wrong\#args} -body {
	namespacex state get N X
    } -returnCodes error -result {wrong # args: should be "namespacex state get ns"}


    test namespacex-state-get-2.0.0 {namespacex state get} -setup {
	ns2_setup
    } -body {
	dictsort [namespacex state get X::Y]
    } -cleanup {
	namespace delete X
    } -result {B::vB 3 vXa 1 vXb aleph}


    test namespacex-state-get-2.0.1 {namespacex state get} -setup {
	ns2_setup
    } -body {
	dictsort [namespacex state get X::Y]
    } -cleanup {
	namespace delete X
    } -result {B::vB 3 vXa 1 vXb aleph}


    test namespacex-state-get-2.1.0 {namespacex state get} -setup {
	namespace eval ::X {}
    } -body {
	dictsort [namespacex state get ::X]
    } -cleanup {
	namespace delete ::X
    } -result {}


    test namespacex-state-get-2.1.1 {namespacex state get} -setup {
	namespace eval X {}
    } -body {
	dictsort [namespacex state get X]
    } -cleanup {
	namespace delete X
    } -result {}


    test namespacex-state-get-2.2.0 {namespacex state get} -setup {
	ns3_setup
    } -body {
	dictsort [namespacex state get X]
    } -cleanup {
	namespace delete X
    } -result {B::vB mjolnir}


    test namespacex-state-get-2.2.1 {namespacex state get} -setup {
	ns3_setup
    } -body {
	dictsort [namespacex state get X]
    } -cleanup {
	namespace delete X
    } -result {B::vB mjolnir}

    # -------------------------------------------------------------------------


    test namespacex-state-drop-1.0 {namespacex state drop, wrong\#args} -body {
	namespacex state drop
    } -returnCodes error -result {wrong # args: should be "namespacex state drop ns"}


    test namespacex-state-drop-1.1 {namespacex state drop, wrong\#args} -body {
	namespacex state drop N X
    } -returnCodes error -result {wrong # args: should be "namespacex state drop ns"}


    test namespacex-state-drop-2.0.0 {namespacex state drop} -setup {
	ns2_setup
    } -body {
	namespacex state drop X
	dictsort [namespacex state get X]
    } -cleanup {
	namespace delete X
    } -result {}


    test namespacex-state-drop-2.0.1 {namespacex state drop} -setup {
	ns2_setup
    } -body {
	namespacex state drop X
	dictsort [namespacex state get X]
    } -cleanup {
	namespace delete X
    } -result {}


    test namespacex-state-drop-2.1.0 {namespacex state drop} -setup {
	namespace eval X {}
    } -body {
	namespacex state drop X
	dictsort [namespacex state get X]
    } -cleanup {
	namespace delete X
    } -result {}


    test namespacex-state-drop-2.1.1 {namespacex state drop} -setup {
	namespace eval X {}
    } -body {
	namespacex state drop X
	dictsort [namespacex state get X]
    } -cleanup {
	namespace delete X
    } -result {}


    test namespacex-state-drop-2.2.0 {namespacex state drop} -setup {
	ns3_setup
    } -body {
	namespacex state drop X
	dictsort [namespacex state get X]
    } -cleanup {
	namespace delete X
    } -result {}


    test namespacex-state-drop-2.2.1 {namespacex state drop} -setup {
	ns3_setup
    } -body {
	namespacex state drop X
	dictsort [namespacex state get X]
    } -cleanup {
	namespace delete X
    } -result {}

    # -------------------------------------------------------------------------


    test namespacex-state-set-1.0 {namespacex state set, wrong\#args} -body {
	namespacex state set
    } -returnCodes error -result {wrong # args: should be "namespacex state set ns state"}


    test namespacex-state-set-1.1 {namespacex state set, wrong\#args} -body {
	namespacex state set N
    } -returnCodes error -result {wrong # args: should be "namespacex state set ns state"}


    test namespacex-state-set-1.2 {namespacex state set, wrong\#args} -body {
	namespacex state set N S X
    } -returnCodes error -result {wrong # args: should be "namespacex state set ns state"}


    test namespacex-state-set-2.0.0 {namespacex state set} -setup {
	ns2_setup
	set ST [namespacex state get X::Y]
	ns3_setup
    } -body {
	namespacex state set X::Y $ST
	dictsort [namespacex state get X::Y]
    } -cleanup {
	namespace delete X
    } -result {B::vB 3 vXa 1 vXb aleph}


    test namespacex-state-set-2.0.1 {namespacex state set} -setup {
	ns2_setup
	set ST [namespacex state get X::Y]
	ns3_setup
    } -body {
	namespacex state set X::Y $ST
	dictsort [namespacex state get X::Y]
    } -cleanup {
	namespace delete X::Y
    } -result {B::vB 3 vXa 1 vXb aleph}


    test namespacex-state-set-2.1.0 {namespacex state set} -setup {
	ns3_setup
	set ST [namespacex state get X]
	ns2_setup
    } -body {
	namespacex state set X $ST
	dictsort [namespacex state get X]
    } -cleanup {
	namespace delete X
    } -result {B::vB mjolnir}


    test namespacex-state-set-2.1.1 {namespacex state set} -setup {
	ns3_setup
	set ST [namespacex state get X]
	ns2_setup
    } -body {
	namespacex state set X $ST
	dictsort [namespacex state get X]
    } -cleanup {
	namespace delete X
    } -result {B::vB mjolnir}

    # -------------------------------------------------------------------------
    testsuiteCleanup

    # Local variables:
    # mode: tcl
    # indent-tabs-mode: nil
    # End:
}