File: var-access.test

package info (click to toggle)
nsf 2.4.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 13,208 kB
  • sloc: ansic: 32,687; tcl: 10,723; sh: 660; pascal: 176; javascript: 135; lisp: 41; makefile: 24
file content (127 lines) | stat: -rw-r--r-- 2,663 bytes parent folder | download | duplicates (2)
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
# -*- Tcl -*-

package prefer latest

package require nx
::nx::configure defaultMethodCallProtection false
package require nx::test

namespace eval ::nx::var1 {
  namespace ensemble create -map {
    exists ::nsf::var::exists 
    import ::nsf::var::import 
    set ::nsf::var::set
  }
}

::nx::Object create ::nx::var2 {
  :object alias exists ::nsf::var::exists 
  :object alias import ::nsf::var::import
  :object alias set ::nsf::var::set
}


nx::test case set+array {
  nx::Object create o1
  
  # first set a scalar variable
  ? {nsf::var::set o1 x 100} "100"
  ? {nsf::var::set o1 x} "100"

  # now, set an array variable; "nsf::var::set -array" is a wrapper
  # around "array set" or "array get"
  ? {nsf::var::set -array o1 a {a 1 y 2}} ""
  ? {nsf::var::set -array o1 a} "y 2 a 1"

  # We have now a scalar and an array variable set.
  ? {lsort [o1 info vars]} "a x"

  # "x" is a variable, but not an array
  ? {nsf::var::exists o1 x} 1
  ? {nsf::var::exists -array o1 x} 0
  
  # "a" is a variable and an array
  ? {nsf::var::exists -array o1 a} 1
  ? {nsf::var::exists o1 a} 1

  # we unset the array
  ? {nsf::var::unset o1 a} ""
  ? {nsf::var::exists o1 a} 0
  ? {nsf::var::exists -array o1 a} 0

  # now, just the scalar is left
  ? {o1 info vars} "x"
  ? {nsf::var::exists o1 x} 1
  ? {nsf::var::exists -array o1 x} 0

  # we unset the scalar
  ? {nsf::var::unset o1 x} ""
  ? {nsf::var::exists o1 x} 0
  ? {nsf::var::exists -array o1 x} 0

  # unset on a non-existing variable
  ? {nsf::var::unset o1 x} {can't unset "x": no such variable}
  ? {nsf::var::unset -nocomplain o1 x} ""
}

nx::test configure -count 10000
nx::test case dummy {
  nx::Object create o {
    set :x 1
  }
  nx::Object create p {
    set :y 1
    :object method foo0 {} {
      incr :y
    }
    :object method foo1 {} {
      o eval {incr :x}
    }
    :object method foo2 {} {
      ::nsf::var::import o x
      incr x
    }
    :object method foo3 {} {
      ::nx::var1 import o x
      incr x
    }
    :object method foo4 {} {
      ::nx::var2 import o x
      incr x
    }
  }
  
  ? {::nsf::var::set o x} 1
  ? {::nsf::var::exists o x} 1
  ? {::nsf::var::exists o y} 0

  ? {::nx::var1 set o x} 1
  ? {::nx::var1 exists o x} 1
  ? {::nx::var1 exists o y} 0

  ? {::nx::var2 set o x} 1
  ? {::nx::var2 exists o x} 1
  ? {::nx::var2 exists o y} 0

  ? {p foo0} 2

  ? {p foo1} 2
  ? {::nsf::var::set o x} 10002

  ? {p foo2} 10003
  ? {::nsf::var::set o x} 20003

  ? {p foo3} 20004
  ? {::nsf::var::set o x} 30004

  ? {p foo4} 30005
  ? {::nsf::var::set o x} 40005
}


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