Index: tests/parameters.xotcl =================================================================== diff -u -r5524b83ed5dda30e55f7a02e4c22d26783688954 -red15b5be7e88cbbcdf6121f3869722dbc354d76f --- tests/parameters.xotcl (.../parameters.xotcl) (revision 5524b83ed5dda30e55f7a02e4c22d26783688954) +++ tests/parameters.xotcl (.../parameters.xotcl) (revision ed15b5be7e88cbbcdf6121f3869722dbc354d76f) @@ -13,7 +13,11 @@ Test case valuecheck Test parameter count 10000 #Test parameter count 10 + Object create o1 +Class create C -parameter {a {b:boolean} {c 1}} +C create c1 + ? {::xotcl::valuecheck object o1} 1 ? {::xotcl::is o1 object} 1 ? {::xotcl::valuecheck class o1} 0 @@ -23,6 +27,10 @@ ? {::xotcl::valuecheck integer,multivalued [list 1 2 3]} 1 ? {::xotcl::valuecheck integer,multivalued [list 1 2 3 a]} 0 ? {::xotcl::valuecheck in1 aaa} {invalid value constraints "in1"} +? {::xotcl::valuecheck type=::C c1} 1 +? {::xotcl::valuecheck type=::C o} 0 "object, but different type" +? {::xotcl::valuecheck type=::C c} 0 "no object" +? {::xotcl::valuecheck type=::xotcl2::Object c1} 1 "general type" # # parameter options @@ -51,6 +59,7 @@ # boolean YES YES NO NO YES YES YES # object YES YES NO NO YES YES YES # class YES YES NO NO YES YES YES +# objectOfType YES YES NO NO YES YES YES # userdefined YES YES NO YES YES YES YES ####################################################### @@ -303,7 +312,7 @@ ? {D info method args bar} {s literal c d switch optflag x y z} "all args" ? {D info method parameter bar} \ - {{-s:substdefault {[self]}} {-literal {[self]}} {-c:substdefault {[my c]}} {-d:integer,substdefault {$d}} {-switch:switch 0} -optflag x y:integer {z 1}} \ + {{-s:substdefault "[self]"} {-literal "[self]"} {-c:substdefault "[my c]"} {-d:integer,substdefault "$d"} -switch:switch -optflag x y:integer {z 1}} \ "query method parameter" D method foo {a b {-c 1} {-d} x {-end 100}} { @@ -477,11 +486,6 @@ # are already predefined, define the rest. # TODO: should go finally to predefined. -::xotcl::parameterType method type=type {name value arg} { - if {![::xotcl::is $value type $arg]} { - error "Value '$value' of $name of not of type $arg" - } -} ::xotcl::parameterType method type=mixin {name value arg} { if {![::xotcl::is $value mixin $arg]} { error "Value '$value' of $name has not mixin $arg" @@ -503,8 +507,12 @@ D method foo-object {x:object} {return $x} D method foo-meta {x:metaclass} {return $x} D method foo-mixin {x:mixin,arg=::M} {return $x} -D method foo-type {x:type,arg=::C} {return $x} +D method foo-type {x:type=::C} {return $x} +? {D info method parameter foo-base} "x:baseclass" +? {D info method parameter foo-mixin} "x:mixin,arg=::M" +? {D info method parameter foo-type} "x:type=::C" + ? {d1 foo-base ::xotcl2::Object} "::xotcl2::Object" ? {d1 foo-base C} \ "Value 'C' of x is not a baseclass" \ @@ -536,7 +544,7 @@ ? {d1 foo-type d1} "d1" ? {d1 foo-type c1} "c1" ? {d1 foo-type o} \ - "Value 'o' of x of not of type ::C" \ + {expected object of type ::C but got "o"} \ "o not of type ::C" @@ -552,11 +560,27 @@ Class create ParamTest -parameter { o:object c:class - d:type,arg=D + d:type=::C + d1:type=C m:metaclass mix:mixin,arg=M b:baseclass + {x:object,multivalued {o}} } + +# TODO: we have no good interface for querying the slot notation for parameters +proc parameterFromSlot {class objectparameter} { + set slot ${class}::slot::$objectparameter + array set "" [::xotcl::parameterFromSlot $slot $objectparameter] + return $(oparam) +} + +? {parameterFromSlot ParamTest o} "o:object" +? {parameterFromSlot ParamTest d} "d:type=::C" +? {parameterFromSlot ParamTest d1} "d1:type=C" +? {parameterFromSlot ParamTest mix} "mix:mixin,arg=M" +? {parameterFromSlot ParamTest x} "x:object,multivalued o" + ? {ParamTest create p -o o} ::p ? {ParamTest create p -o xxx} \ {expected object but got "xxx"} \ @@ -567,6 +591,13 @@ "Value 'o' of mix has not mixin M" \ "does not have mixin M" +? {ParamTest create p -d d1} ::p +? {ParamTest create p -d1 d1} ::p +? {ParamTest create p -d c1} ::p +? {ParamTest create p -d o} \ + {expected object of type ::C but got "o"} \ + "o not of type ::C" + # TODO: naming "type" and "mixin" not perfect. # maybe "type" => "hastype" # maybe "mixin" => "hasmixin"