Index: tests/parameters.test =================================================================== diff -u -r2e7f0b2256363d70c78778c9ed401f9450622a6a -rfd3666742ed34091dbb93a872fe1d34d6b66ad9d --- tests/parameters.test (.../parameters.test) (revision 2e7f0b2256363d70c78778c9ed401f9450622a6a) +++ tests/parameters.test (.../parameters.test) (revision fd3666742ed34091dbb93a872fe1d34d6b66ad9d) @@ -37,7 +37,11 @@ Test case parametercheck { Object create o1 - Class create C -attributes {a {b:boolean} {c 1}} + Class create C { + :property a + :property {b:boolean} + :property {c 1} + } C create c1 Class create M c1 mixin M @@ -245,7 +249,7 @@ # {elementtype ::nx::Class} # } -- sample instances: class superclass, mixin filter # -# ::nx::Attribute -superclass ::xotcl::Slot { +# ::nx::VariableSlot -superclass ::xotcl::Slot { # {value_check once} # defaultcmd # valuecmd @@ -263,7 +267,11 @@ Test parameter count 10 Test case objectparameter { - Class create C -attributes {a {b:boolean} {c 1}} + Class create C { + :property a + :property {b:boolean} + :property {c 1} + } C create c1 ? {C eval :objectparameter} \ @@ -278,7 +286,11 @@ ####################################################### Test case reclass { - Class create C -attributes {a {b:boolean} {c 1}} + Class create C { + :property a + :property {b:boolean} + :property {c 1} + } C create c1 ? {c1 info lookup slots -source application} "::C::slot::a ::C::slot::b ::C::slot::c" @@ -287,7 +299,7 @@ ? {c1 info lookup slots -source application} "" - Class create D -superclass C -attributes {d:required} + Class create D -superclass C {:property d:required} D create d1 -d 100 ? {d1 info lookup slots -source application} \ @@ -302,12 +314,24 @@ ####################################################### Test case objparam-mixins { - Class create C -attributes {a {b:boolean} {c 1}} - Class create D -superclass C -attributes {d:required} + Class create C { + :property a + :property {b:boolean} + :property {c 1} + } + Class create D -superclass C { + :property d:required + } D create d1 -d 100 - Class create M -attributes {m1 m2 b} - Class create M2 -attributes {b2} + Class create M { + :property m1 + :property m2 + :property b + } + Class create M2 { + :property b2 + } D mixin M ? {D eval :objectparameter} \ @@ -342,8 +366,12 @@ Test case passed-arguments { - Class create C -attributes {a {b:boolean} {c 1}} - Class create D -superclass C -attributes {d:required} + Class create C { + :property a + :property b:boolean + :property {c 1} + } + Class create D -superclass C {:property d:required} ? {catch {D create d1 -d 123}} 0 "create d1 with required argument given" ? {catch {D create d1}} 1 "create d1 without required argument given" @@ -454,8 +482,8 @@ {invalid value in "o d1 x": expected object but got "x" for parameter "m"} \ "multiple values" - Class create Foo -attributes { - {ints:integer,1..*} + Class create Foo { + :property ints:integer,1..* } ? {Foo create foo -ints {1 2}} "::foo" ? {Foo create foo -ints {1 a 2}} {invalid value in "1 a 2": expected integer but got "a" for parameter "-ints"} @@ -477,8 +505,8 @@ Test case subst-default { Class create D { - :attribute {c 1} - :attribute {d 2} + :property {c 1} + :property {d 2} :create d1 @@ -494,14 +522,14 @@ ? {d1 bar -c 1} {::d1-[current]-1-2} "substdefault in method parameter" - Class create Bar -superclass D -attributes { - {s "[current]"} - {literal "\\[current\\]"} - {c "[:info class]"} - {d "literal $d"} + Class create Bar -superclass D { + :property {s "[current]"} + :property {literal "\\[current\\]"} + :property {c "[:info class]"} + :property {d "literal $d"} } - ? {Bar attribute ss:switch} "::nsf::classes::Bar::ss" + ? {Bar property ss:switch} "::nsf::classes::Bar::ss" Bar create bar1 #puts stderr [bar1 objectparameter] @@ -607,7 +635,7 @@ ####################################################### Test case user-types { - Class create D -attributes d + Class create D {:property d} D create d1 # create a userdefined type @@ -706,7 +734,7 @@ Test case mp-object-types { Class create C - Class create D -superclass C -attributes d + Class create D -superclass C {:property d} Class create M Class create M2 @@ -780,7 +808,11 @@ ####################################################### Test case substdefault { - Class create S -attributes {{x 1} {y b} {z {1 2 3}}} + Class create S { + :property {x 1} + :property {y b} + :property {z {1 2 3}} + } S create s1 { :public method foo {{y:substdefault ${:x}}} { return $y @@ -838,16 +870,16 @@ Class create Bar { # simple, implicit substdefault - :attribute {s0 "[current]"} + :property {s0 "[current]"} # explicit substdefault - :attribute {s1:substdefault "[current]"} + :property {s1:substdefault "[current]"} # unneeded double substdefault - :attribute {s2:substdefault,substdefault "[current]"} + :property {s2:substdefault,substdefault "[current]"} # substdefault with incremental - :attribute {s3:substdefault "[current]"} { + :property {s3:substdefault "[current]"} { # Bypassing the Optimizer helps after applying the patch (solving step 1) set :incremental 1 } @@ -867,8 +899,8 @@ ::nsf::method::require nx::Object configure Class create C { - :attribute {a ""} - :attribute {b 1} + :property {a ""} + :property {b 1} :method init {} { :configure -b 1 @@ -890,7 +922,7 @@ Test case op-object-types { Class create C - Class create D -superclass C -attributes d + Class create D -superclass C {:property d} Class create MC -superclass Class MC create MC1 @@ -899,17 +931,17 @@ C create c1 -mixin M Object create o - Class create ParamTest -attributes { - o:object - c:class - c1:class,type=::MC - d:object,type=::C - d1:object,type=C - m:metaclass - b:baseclass - u:upper - us:upper,1..* - {x:object,1..* {o}} + Class create ParamTest { + :property o:object + :property c:class + :property c1:class,type=::MC + :property d:object,type=::C + :property d1:object,type=C + :property m:metaclass + :property b:baseclass + :property u:upper + :property us:upper,1..* + :property {x:object,1..* {o}} } # TODO: we have no good interface for querying the slot notation for parameters @@ -974,11 +1006,11 @@ "value is not an object" # - # define multivalued attribute "os" via instance variables of the + # define multivalued property "os" via instance variables of the # slot object # ParamTest eval { - :attribute os { + :property os { :type object :multiplicity 1..n } @@ -1093,7 +1125,7 @@ Test case slot-specfic-converter { Class create Person { - :attribute sex { + :property sex { :type "sex" :convert true :method type=sex {name value} { @@ -1162,7 +1194,11 @@ Test parameter count 1000 Test case slot-optimizer { - Class create C -attributes {a b:integer c:integer,0..n} + Class create C { + :property a + :property b:integer + :property c:integer,0..n + } C create c1 ? {c1 a 1} 1 @@ -1182,7 +1218,11 @@ Test parameter count 10 Test case slot-nosetter { - Class create C -attributes {a b:integer,accessor=false {c:accessor=false ""}} + Class create C { + :property a + :property b:integer,noaccessor + :property {c:noaccessor ""} + } ? {C create c1 -a 1 -b 2} ::c1 ? {c1 info vars} "a b c" @@ -1227,9 +1267,9 @@ Test case slot-traces { ::nx::Object create o { - :attribute a {set :defaultcmd { set _ 4 } } - :attribute b {set :valuecmd { set _ 44 } } - :attribute c {set :valuechangedcmd { ::nsf::var::set $obj $var 999 }} + :property a {set :defaultcmd { set _ 4 } } + :property b {set :valuecmd { set _ 44 } } + :property c {set :valuechangedcmd { ::nsf::var::set $obj $var 999 }} } ? {o a} 4 @@ -1243,9 +1283,9 @@ ? {o c 5} 999 ::nx::Class create C { - :attribute a {set :defaultcmd { set _ 4 } } - :attribute b {set :valuecmd { set _ 44 } } - :attribute c {set :valuechangedcmd { ::nsf::var::set $obj $var 999 }} + :property a {set :defaultcmd { set _ 4 } } + :property b {set :valuecmd { set _ 44 } } + :property c {set :valuechangedcmd { ::nsf::var::set $obj $var 999 }} :create c1 } ? {c1 a} 4 @@ -1402,7 +1442,7 @@ # Test case dont-reset-to-defaults { Class create C { - :attribute {a 1} + :property {a 1} :create c1 } ? {c1 a} 1 @@ -1460,8 +1500,8 @@ Test case req-param { ::nx::Class create C { - :attribute y:required - :attribute x:required + :property y:required + :property x:required :method init args {set ::_ $args} } @@ -1482,8 +1522,8 @@ # Test case nsf-subdefault { nx::Class create C { - :attribute {n1 "[namespace tail [::nsf::self]]"} - :attribute {n2:any "[namespace tail [::nsf::self]]"} + :property {n1 "[namespace tail [::nsf::self]]"} + :property {n2:any "[namespace tail [::nsf::self]]"} :create c1 } ? {c1 n1} c1 @@ -1584,10 +1624,10 @@ Test case parameter-alias { Class create C { - :attribute {x:alias} - :attribute {A:alias,method=bar} - :attribute {{F:forward,method=%self foo %1 a b c %method}} - :attribute {D def} + :property {x:alias} + :property {A:alias,method=bar} + :property {{F:forward,method=%self foo %1 a b c %method}} + :property {D def} :public method x args {set :x $args} :public method foo args {set :foo $args} :public method bar args {set :bar $args} @@ -1606,9 +1646,9 @@ Test case parameter-alias-default { Class create C { - :attribute {x1:alias "hugo"} - :attribute {{F:forward,method=%self foo a %1 b c %method} "habicht"} - :attribute {x2:alias "[self]"} + :property {x1:alias "hugo"} + :property {{F:forward,method=%self foo a %1 b c %method} "habicht"} + :property {x2:alias "[self]"} :public method x1 args {set :x1 $args} :public method x2 args {set :x2 $args} :public method foo args {set :foo $args} @@ -1619,7 +1659,7 @@ ? {c1 eval {set :foo}} "a habicht b c F" ? {c1 eval {set :x2}} "::c1" ? {lsort [c1 info lookup methods -source application]} "foo x1 x2" - ? {lsort [C info slots]} "::C::slot::F ::C::slot::x1 ::C::slot::x2" + ? {lsort [C info slot objects]} "::C::slot::F ::C::slot::x1 ::C::slot::x2" ? {::C::slot::x1 getParameterSpec} {-x1:alias hugo} ? {::C::slot::x2 getParameterSpec} {-x2:alias,substdefault {[self]}} } @@ -1629,21 +1669,21 @@ # Test case parameter-object-mixin-dependency { Class create C { - :attribute a1 + :property a1 :create c1 { - :attribute a2 + :property a2 } } Class create M { - :attribute b1:required + :property b1:required } c1 mixin M ? {c1 info precedence} "::M ::C ::nx::Object" - ? {C info slots -closure} "::C::slot::a1 ::nx::Object::slot::volatile ::nx::Object::slot::noinit ::nx::Object::slot::mixin ::nx::Object::slot::__initcmd ::nx::Object::slot::class ::nx::Object::slot::filter" + ? {C info slot objects -closure} "::C::slot::a1 ::nx::Object::slot::volatile ::nx::Object::slot::noinit ::nx::Object::slot::mixin ::nx::Object::slot::__initcmd ::nx::Object::slot::class ::nx::Object::slot::filter" ? {C eval :objectparameter} "-a1 -volatile:alias,noarg -noinit:alias,method=::nsf::methods::object::noinit,noarg -mixin:mixinreg,alias,1..n -class:class,alias,method=::nsf::methods::object::class -filter:filterreg,alias,1..n __initcmd:initcmd,optional" @@ -1657,7 +1697,7 @@ ? {c1 info precedence} "::M ::C ::nx::Object" - ? {C info slots -closure} "::C::slot::a1 ::nx::Object::slot::volatile ::nx::Object::slot::noinit ::nx::Object::slot::mixin ::nx::Object::slot::__initcmd ::nx::Object::slot::class ::nx::Object::slot::filter" + ? {C info slot objects -closure} "::C::slot::a1 ::nx::Object::slot::volatile ::nx::Object::slot::noinit ::nx::Object::slot::mixin ::nx::Object::slot::__initcmd ::nx::Object::slot::class ::nx::Object::slot::filter" ? {C eval :objectparameter} "-a1 -volatile:alias,noarg -noinit:alias,method=::nsf::methods::object::noinit,noarg -mixin:mixinreg,alias,1..n -class:class,alias,method=::nsf::methods::object::class -filter:filterreg,alias,1..n __initcmd:initcmd,optional" @@ -1754,30 +1794,30 @@ nx::Test case reconfigure-perobj-default { Object create o ? {o eval {info exists :a}} 0 - o attribute {a oldvalue} + o property {a oldvalue} ? {o eval {info exists :a}} 1 ? {o a} oldvalue # - # By unsetting the var, upon recreating the attribute slot (or - # calling reconfigure upon the attribute) we can trigger + # By unsetting the var, upon recreating the property slot (or + # calling reconfigure upon the property) we can trigger # a re-assignment of the default value. # o eval {unset :a} ? {o eval {info exists :a}} 0 # # re-assignment of the default is handled by init # - o attribute {a newvalue} + o property {a newvalue} ? {o eval {info exists :a}} 1 ? {o a} newvalue o eval {unset :a} ? {o eval {info exists :a}} 0 - [o info slots a] default anothervalue + [o info slot objects a] default anothervalue ? {o eval {info exists :a}} 0 # # re-assignment must be requested by a reconfigure call # - [o info slots a] reconfigure + [o info slot objects a] reconfigure ? {o eval {info exists :a}} 1 ? {o a} anothervalue } @@ -1800,7 +1840,7 @@ # Strengths of object-level parameters: # - same interface as class-level attributes # - can use same meta-data mechanisms as for class-level attributes -# (e.g database types, attribute name in the database, persistence +# (e.g database types, property name in the database, persistence # information, ...) # - can use same setters/checkers as for class-level attributes # - can use as well incremental as for class-level attributes @@ -1820,7 +1860,7 @@ # cannot be called. # -# test object level attribute and variable +# test object level property and variable # nx::Test case object-level-variable { @@ -1829,33 +1869,33 @@ # just to get a reference value for the timing ? [list [self] eval {set :dummy 1}] "1" - # set 2 variables, one via variable, one via attribute + # set 2 variables, one via variable, one via property ? [list [self] variable -nocomplain captain1 "James Kirk"] "" - ? [list [self] attribute -nocomplain [list captain2 "Jean Luc"]] "::enterprise::captain2" + ? [list [self] property -nocomplain [list captain2 "Jean Luc"]] "::enterprise::captain2" # in both cases, we expect instance variables ? [list [self] eval {set :captain1}] "James Kirk" ? [list [self] eval {set :captain2}] "Jean Luc" - # just for the attribute, we have accessors + # just for the property, we have accessors ? [list [self] info lookup method captain1] "" ? [list [self] info lookup method captain2] "::enterprise::captain2" # set variable with a value checker ? [list [self] variable -nocomplain x1:int 1] "" - ? [list [self] attribute -nocomplain [list x2:int 2]] "::enterprise::x2" + ? [list [self] property -nocomplain [list x2:int 2]] "::enterprise::x2" # set variable with a value checker and an invalid value ? [list [self] variable y1:int a] {expected integer but got "a"} - ? [list [self] attribute [list y2:int b]] {expected integer but got "b"} + ? [list [self] property [list y2:int b]] {expected integer but got "b"} # set variable again, without -nocomplain ? [list [self] variable x1:int 1] {Object ::enterprise has already an instance variable named 'x1'} - ? [list [self] attribute [list x2:int 2]] {Object ::enterprise has already an instance variable named 'x2'} + ? [list [self] property [list x2:int 2]] {Object ::enterprise has already an instance variable named 'x2'} # set variable with a value checker, multiple ? [list [self] variable -nocomplain xm1:int,1..n {1 2 3}] "" - ? [list [self] attribute -nocomplain [list xm2:int,1..n {1 2 3}]] "::enterprise::xm2" + ? [list [self] property -nocomplain [list xm2:int,1..n {1 2 3}]] "::enterprise::xm2" # in both cases, we expect instance variables ? [list [self] eval {set :xm1}] "1 2 3" @@ -1864,7 +1904,7 @@ # set variable with a value checker, multiple with invalid value ? [list [self] variable -nocomplain xm1:int,1..n {1 2a 3}] \ {invalid value in "1 2a 3": expected integer but got "2a"} - ? [list [self] attribute -nocomplain [list xm2:int,1..n {1 2a 3}]] \ + ? [list [self] property -nocomplain [list xm2:int,1..n {1 2a 3}]] \ {invalid value in "1 2a 3": expected integer but got "2a"} # useless definition @@ -1875,7 +1915,7 @@ # define an application specific converter # # TODO: currently, we need two converters (or a converter on nx::Slot), since - # variable uses nsf::is and attribute uses the slot obj. method variable should + # variable uses nsf::is and property uses the slot obj. method variable should # be changed to use the slotobj as well. ::nx::ObjectParameterSlot method type=range {name value arg} { lassign [split $arg -] min max @@ -1894,20 +1934,20 @@ # # Test usage of application specific converter in "variable" and - # "attribute"; invalid value + # "property"; invalid value ? [list [self] variable -nocomplain r1:range,arg=1-10 11] \ {Value '11' of parameter value not between 1 and 10} - ? [list [self] attribute -nocomplain [list r2:range,arg=1-10 11]] \ + ? [list [self] property -nocomplain [list r2:range,arg=1-10 11]] \ {Value '11' of parameter value not between 1 and 10} # valid value ? [list [self] variable -nocomplain r1:range,arg=1-10 5] "" - ? [list [self] attribute -nocomplain [list r2:range,arg=1-10 5]] \ + ? [list [self] property -nocomplain [list r2:range,arg=1-10 5]] \ {::enterprise::r2} # testing incremental ? [list [self] variable -incremental -nocomplain i:int,0..* {}] "::enterprise::i" - ? [list [self] attribute -incremental -nocomplain j:int,0..* {}] "::enterprise::j" + ? [list [self] property -incremental -nocomplain j:int,0..* {}] "::enterprise::j" :i add 1 :j add 1 ? [list [self] i] "1" @@ -1921,9 +1961,9 @@ } nx::Class create C { - # set 2 class variables, one via variable, one via attribute + # set 2 class variables, one via variable, one via property ? [list [self] class variable -nocomplain v "v0"] "" - ? [list [self] class attribute -nocomplain [list a "a0"]] "::C::a" + ? [list [self] class property -nocomplain [list a "a0"]] "::C::a" # in both cases, we expect instance variables ? [list [self] eval {set :v}] "v0" @@ -1937,14 +1977,14 @@ } # -# test class level attribute and variable +# test class level property and variable # nx::Test case class-level-variable { nx::Class create C { - # define 2 class-level variables, one via variable, one via attribute + # define 2 class-level variables, one via variable, one via property :variable v v0 - :attribute {a a0} + :property {a a0} # create an instance :create c1 @@ -1958,13 +1998,14 @@ # # We expect a specifiable object parameter for "a" but not for "v". # The parameter for v can be obtained via spec, but is not listed in - # "info parameter syntax" or "info parameter spec". + # "info parameter syntax" or "info parameter definition". # ? {C info parameter list a} "-a" - ? {C info parameter spec a} "{-a a0}" + ? {C info parameter definition a} "{-a a0}" ? {C info parameter syntax a} "?-a value?" - ? {C info parameter spec v} "{-v:noconfig v0}" + ? {C info parameter definition v} "" + ? {C info slot definition v} "{v:noaccessor,noconfig v0}" ? {C info parameter list v} "" ? {C info parameter syntax v} "" @@ -1998,14 +2039,14 @@ } # -# test deletion of class level attribute and variable +# test deletion of class level property and variable # -nx::Test case delete-class-level-variable-and-attribute { +nx::Test case delete-class-level-variable-and-property { nx::Class create C { - # define 2 class-level variables, one via variable, one via attribute + # define 2 class-level variables, one via variable, one via property :variable v v0 - :attribute {a a0} + :property {a a0} # create an instance :create c1 @@ -2022,10 +2063,10 @@ ? {c1 info lookup method a} "::nsf::classes::C::a" ? {c1 info lookup method v} "" - # if we delete a class-level attribute or variable, + # if we delete a class-level property or variable, # the object parameter and setters for "a" will be gone C delete variable v - C delete attribute a + C delete property a ? {C info parameter list a} "" ? {c1 info lookup method a} "" @@ -2038,14 +2079,14 @@ } # -# test deletion of class level attribute and variable +# test deletion of class level property and variable # -nx::Test case delete-object-level-variable-and-attribute { +nx::Test case delete-object-level-variable-and-property { nx::Object create o { - # define 2 object-level variables, one via variable, one via attribute + # define 2 object-level variables, one via variable, one via property :variable v v0 - :attribute {a a0} + :property {a a0} } # the instance of C will have the two variables set ... @@ -2056,23 +2097,26 @@ ? {o info lookup method v} "" # Object-level attributes and variables set und unset instance - # variables. If we delete an object-level attribute or variable, + # variables. If we delete an object-level property or variable, # the setters for "a" will be unset. o delete variable v - o delete attribute a + o delete property a ? {o info lookup method a} "" # Both instance variables are unset ? {lsort [o info vars]} {} } +# +# Testing object parameters of type "switch" +# nx::Test case object-parameter-switch { - # Create a class with an attribute of type switch and an instance of + # Create a class with an property of type switch and an instance of # the class ? {::nx::Class create C { - :attribute foo:switch + :property foo:switch :create c1 }} "::C" @@ -2104,7 +2148,7 @@ # In the inverted case, the switch has a default of "true". If the # switch is specified, the valus is "false" - C attribute {foo2:switch 1} + C property {foo2:switch 1} C create c4 ? {lsort [c4 info vars]} {foo foo2} ? {c4 eval {set :foo2}} {1} @@ -2121,5 +2165,35 @@ }} ::o1 ? {o1 eval {set :foo}} 0 ? {o1 eval {set :bar}} 1 +} +# +# Test slots with configparameter true/false, accessor true/false +# against "info slot definition" and "info parameter" +# +Test case info-slots-types { + Class create C { + # variable has no config parameter and no accessor + :variable v 100 + } + + # "v" does not show up in "info parameter" + ? {C info parameter list} "-volatile -noinit -mixin -class -filter __initcmd" + ? {C info parameter names} "volatile noinit mixin class filter __initcmd" + + # "v" does show up in "info slot" + ? {C info slot objects} "::C::slot::v" + ? {C info slot definition} "{v:noaccessor,noconfig 100}" + + Class create D { + :property {p:noaccessor 200} + } + + # "p" does show up in "info parameter" + ? {D info parameter list} "-p -volatile -noinit -mixin -class -filter __initcmd" + ? {D info parameter names} "p volatile noinit mixin class filter __initcmd" + + # "p" does show up in "info slot" + ? {D info slot objects} "::D::slot::p" + ? {D info slot definition} "{p:noaccessor 200}" } \ No newline at end of file