Index: tests/submethods.test =================================================================== diff -u -r3b5d2f4e0bc018420ebea39e54ad3212ade2a5bd -r4bc60e16c10fdbbb640b3019d4bdebdc469fdf55 --- tests/submethods.test (.../submethods.test) (revision 3b5d2f4e0bc018420ebea39e54ad3212ade2a5bd) +++ tests/submethods.test (.../submethods.test) (revision 4bc60e16c10fdbbb640b3019d4bdebdc469fdf55) @@ -1,11 +1,11 @@ # -*- Tcl -*- package req nx -::nx::configure defaultMethodCallProtection false package require nx::test -namespace import ::nx::* -Test parameter count 100 -Test case submethods { +::nx::configure defaultMethodCallProtection false + +nx::test configure -count 100 +nx::test case submethods { #Object method unknown {} {} Object create o1 ? {o1 foo} "::o1: unable to dispatch method 'foo'" @@ -16,15 +16,15 @@ # - names equal to helper methods of the ensemble object # Object create o { - :method "string length" x {return [current method]} - :method "string tolower" x {return [current method]} - :method "string info" x {return [current method]} - :method "foo a x" {} {return [current method]} - :method "foo a y" {} {return [current method]} - :method "foo a subcmdName" {} {return [current method]} - :method "foo a defaultmethod" {} {return [current method]} - :method "foo a unknown" args {return [current method]} - :method "foo b" {} {return [current method]} + :object method "string length" x {return [current method]} + :object method "string tolower" x {return [current method]} + :object method "string info" x {return [current method]} + :object method "foo a x" {} {return [current method]} + :object method "foo a y" {} {return [current method]} + :object method "foo a subcmdName" {} {return [current method]} + :object method "foo a defaultmethod" {} {return [current method]} + :object method "foo a unknown" args {return [current method]} + :object method "foo b" {} {return [current method]} } Class create Foo { :method "bar m1" {a:integer -flag} {;} @@ -46,7 +46,7 @@ ? {o foo a z} \ {unable to dispatch sub-method "z" of ::o foo a; valid are: foo a defaultmethod, foo a subcmdName, foo a unknown, foo a x, foo a y} - ? {o info method type string} object + ? {o info object method type string} object # the following is a problem, when string has subcmd "info" #? {o::string info class} ::nx::EnsembleObject @@ -63,18 +63,18 @@ #unable to dispatch method baz a m3; valid subcommands of a: m1 m2} # -Test parameter count 1 -Test case defaultmethod { +nx::test configure -count 1 +nx::test case defaultmethod { Object create o { - :method "string length" x {return [current method]} - :method "string tolower" x {return [current method]} - :method "string info" x {return [current method]} - :method "foo a x" {} {return [current method]} - :method "foo a y" {} {return [current method]} - :method "foo a subcmdName" {} {return [current method]} - :method "foo a defaultmethod" {} {return [current method]} - :method "foo a unknown" args {return [current method]} - :method "foo b" {} {return [current method]} + :object method "string length" x {return [current method]} + :object method "string tolower" x {return [current method]} + :object method "string info" x {return [current method]} + :object method "foo a x" {} {return [current method]} + :object method "foo a y" {} {return [current method]} + :object method "foo a subcmdName" {} {return [current method]} + :object method "foo a defaultmethod" {} {return [current method]} + :object method "foo a unknown" args {return [current method]} + :object method "foo b" {} {return [current method]} } Class create Foo { :method "bar m1" {a:integer -flag} {;} @@ -96,8 +96,8 @@ # # testing ensemble objects with next # -Test parameter count 1 -Test case ensemble-next { +nx::test configure -count 1 +nx::test case ensemble-next { nx::Class create FOO { # reduced ensemble @@ -179,7 +179,7 @@ ? {f1 l1 l2 l3a 100} "{M1.l1 l2 l3a//l3a (100)} {l1 l2//l2 (l3a 100)} {FOO.l1 l2 l3a//l3a (100)}" } -Test case ensemble-partial-next { +nx::test case ensemble-partial-next { nx::Class create M { :public method "info has namespace" {} { nx::next @@ -229,7 +229,8 @@ # defaultcmd has to return also subcmds of other shadowed ensembles ? {lsort [o1 info has]} "valid submethods of ::o1 info has: mixin namespace something type" - ? {lsort [o1 info]} "valid submethods of ::o1 info: children class filter has info is lookup method methods mixin name parent precedence slot vars" + ? {lsort [o1 info]} \ + "valid submethods of ::o1 info: children class configure has info lookup name object parameter parent precedence variable vars" # returning methodpath in ensemble ? {o1 info has something path} "info has something path" @@ -241,7 +242,7 @@ # # Check behavior of upvars in ensemble methods # -Test case ensemble-upvar { +nx::test case ensemble-upvar { nx::Class create FOO { :method "bar0 x" {varname} {upvar $varname v; return [info exists v]} @@ -264,13 +265,13 @@ # # Check behavior of next with arguments within an ensemble # -Test case ensemble-next-with-args { +nx::test case ensemble-next-with-args { nx::Object create o { - :method foo {x} {return $x} - :method "e1 sm" {x} {return $x} - :method "e2 sm1 sm2" {x} {return $x} - :method "e2 e2 e2" {x} {return $x} - :method "e1 e1 e1" args {return $args} + :object method foo {x} {return $x} + :object method "e1 sm" {x} {return $x} + :object method "e2 sm1 sm2" {x} {return $x} + :object method "e2 e2 e2" {x} {return $x} + :object method "e1 e1 e1" args {return $args} } nx::Class create M { :method foo {} {next 1} @@ -279,7 +280,7 @@ :method "e2 e2 e2" {} {next 4} :method "e1 e1 e1" args {next {e1 e1 e1}} } - o mixin add M + o object mixin add M # case without ensemble ? {o foo} 1 @@ -297,12 +298,12 @@ ? {o e1 e1 e1} {e1 e1 e1} } -Test parameter count 1 -Test case ensemble-next-with-colon-prefix +nx::test configure -count 1 +nx::test case ensemble-next-with-colon-prefix namespace eval ::ns1 { - Object create obj { - :public method foo {} { return [:info class] } - :public method ifoo {} { [current] ::nsf::methods::object::info::lookupmethod info} + nx::Object create obj { + :public object method foo {} { return [:info class] } + :public object method ifoo {} { [current] ::nsf::methods::object::info::lookupmethod info} } ? {obj info class} ::nx::Object @@ -317,17 +318,17 @@ ? [list obj $infolookup info] ::nsf::classes::nx::Object::info ? [list obj $infomethod type ::nsf::classes::nx::Object::info] alias - obj method info {} {;} + obj object method info {} {;} ? [list obj $infolookup info] ::ns1::obj::info ? [list obj $infomethod type ::ns1::obj::info] scripted ? {obj ifoo} ::ns1::obj::info ? {obj foo} {wrong # args: should be ":info"} # Now we try to overwrite the object specific method with an object # named "info" - ? {Object create obj::info} "refuse to overwrite cmd ::ns1::obj::info; delete/rename it before overwriting" + ? {nx::Object create obj::info} "refuse to overwrite cmd ::ns1::obj::info; delete/rename it before overwriting" rename obj::info "" - ? {Object create obj::info} ::ns1::obj::info + ? {nx::Object create obj::info} ::ns1::obj::info ? [list obj $infolookup info] ::ns1::obj::info ? [list obj $infomethod type ::ns1::obj::info] object @@ -347,16 +348,16 @@ # Leaf next: Do not trigger unknown handling (see also # NextSearchAndInvoke()) # -nx::Test case leaf-next-in-submethods { - Object create container { +nx::test case leaf-next-in-submethods { + nx::Object create container { set :x 0 - :public method "FOO bar" {} { + :public object method "FOO bar" {} { incr :x; next; # a "leaf next" } - :public method intercept args { + :public object method intercept args { incr :x; next; # a "filter next" } - :filter intercept + :object filter intercept :FOO bar # Rationale: A call count > 2 would indicate that the leaf next # triggers a further call into filter ... @@ -365,7 +366,7 @@ } -nx::Test case submethods-and-filters { +nx::test case submethods-and-filters { # # submethods as filters? # @@ -375,12 +376,12 @@ #C filter {{BAR bar}} } -nx::Test case submethods-current-introspection { +nx::test case submethods-current-introspection { # # [current] & [current class] # - Object create o - o public method "FOO foo" {} { + nx::Object create o + o public object method "FOO foo" {} { return "-[current]-[current class]-" } ? {o FOO foo} -::o-- @@ -400,18 +401,18 @@ ? {c FOO foo} -::c-::M1-::c-::C- - o mixin ::M1 + o object mixin ::M1 ? {o FOO foo} -::o-::M1-::o-- - o mixin {} + o object mixin {} C mixin {} # # limit [current methodpath] to collect only ensemble methods? # o eval { - :public method faz {} {return [concat [current methodpath] [current method]]} + :public object method faz {} {return [concat [current methodpath] [current method]]} ? [list set _ [:faz]] "faz" } @@ -421,33 +422,33 @@ o eval { set body {? [list set _ [:bar]] [current class]-[current]-[concat [current methodpath] [current method]]} - :public method "FOO foo" {} $body - :public method "BAR BUU boo" {} $body - :public method baz {} $body + :public object method "FOO foo" {} $body + :public object method "BAR BUU boo" {} $body + :public object method baz {} $body set calleeBody {return "[current callingclass]-[current callingobject]-[current callingmethod]"} - :method bar {} $calleeBody + :public object method bar {} $calleeBody :FOO foo :BAR BUU boo :baz - :method "a b" {} $calleeBody + :object method "a b" {} $calleeBody set body {? [list set _ [:a b]] [current class]-[current]-[concat [current methodpath] [current method]]} - :public method "FOO foo" {} $body - :public method "BAR BUU boo" {} $body - :public method baz {} $body + :public object method "FOO foo" {} $body + :public object method "BAR BUU boo" {} $body + :public object method baz {} $body :FOO foo :BAR BUU boo :baz # TODO: :method "a b c" {} $calleeBody; FAILS -> "can't append to scripted" - :method "x y z" {} $calleeBody; + :object method "x y z" {} $calleeBody; set body {? [list set _ [:x y z]] [current class]-[current]-[concat [current methodpath] [current method]]} - :public method "FOO foo" {} $body - :public method "BAR BUU boo" {} $body - :public method baz {} $body + :public object method "FOO foo" {} $body + :public object method "BAR BUU boo" {} $body + :public object method baz {} $body :FOO foo :BAR BUU boo @@ -492,7 +493,7 @@ # filter-local argv. Class create Z { - :class property -accessor public msg + :object property -accessor public msg :method intercept args { [current class] eval [list set :msg [list [current methodpath] \ [current calledmethod] \ @@ -521,7 +522,7 @@ # # Test current args in ensemble methods # -nx::Test case current-args { +nx::test case current-args { nx::Class create C { :method foo {{-x 1} z:optional} {return [current args]} :method "bar foo" {{-x 1} z:optional} {return [current args]} @@ -541,21 +542,21 @@ # method interface # -nx::Test case per-object-dispatch { +nx::test case per-object-dispatch { nx::Class create C { :public method foo {} {return foo-[self]} :public method baz {} {return [c1::1 baz]} :create c1 { - :public method bar {} {return bar-[self]} + :public object method bar {} {return bar-[self]} } } ? {c1 foo} "foo-::c1" ? {c1 bar} "bar-::c1" C create c1::1 { - :public method bar {} {return bar-[self]} - :public method baz {} {return baz-[self]} + :public object method bar {} {return bar-[self]} + :public object method baz {} {return baz-[self]} } # @@ -617,18 +618,18 @@ # Test forwarding to child object, with respect to settings of the # object properties keepcallerself and allowmethoddispatch # -nx::Test parameter count 1000 -nx::Test case child-obj-delegation { +nx::test configure -count 1000 +nx::test case child-obj-delegation { nx::Object create obj { nx::Object create [self]::child { - :public method foo {} {return [self]} + :public object method foo {} {return [self]} } - :public forward link1 {%[self]::child} - :public forward link2 :child - :public method link3 args {[self]::child {*}$args} - :public alias link4 [self]::child - :public forward link5 [self]::child + :public object forward link1 {%[self]::child} + :public object forward link2 :child + :public object method link3 args {[self]::child {*}$args} + :public object alias link4 [self]::child + :public object forward link5 [self]::child } # @@ -648,12 +649,12 @@ ? {obj link5 foo} {::obj::child} ? {obj child foo} {::obj::child} - #? {lsort [obj info methods child]} {} - #? {lsort [obj info methods]} {link1 link2 link3 link4 link5} + #? {lsort [obj info object methods child]} {} + #? {lsort [obj info object methods]} {link1 link2 link3 link4 link5} #? {lsort [obj info lookup methods child]} {} #? {lsort [obj info lookup methods child*]} {} - ? {lsort [obj info methods child]} {child} - ? {lsort [obj info methods]} {child link1 link2 link3 link4 link5} + ? {lsort [obj info object methods child]} {child} + ? {lsort [obj info object methods]} {child link1 link2 link3 link4 link5} ? {lsort [obj info lookup methods child]} {child} ? {lsort [obj info lookup methods child*]} {child} @@ -671,12 +672,12 @@ ? {obj link5 foo} {::obj::child} ? {obj child foo} {::obj} - #? {lsort [obj info methods child]} {} - #? {lsort [obj info methods]} {link1 link2 link3 link4 link5} + #? {lsort [obj info object methods child]} {} + #? {lsort [obj info object methods]} {link1 link2 link3 link4 link5} #? {lsort [obj info lookup methods child]} {} #? {lsort [obj info lookup methods child*]} {} - ? {lsort [obj info methods child]} {child} - ? {lsort [obj info methods]} {child link1 link2 link3 link4 link5} + ? {lsort [obj info object methods child]} {child} + ? {lsort [obj info object methods]} {child link1 link2 link3 link4 link5} ? {lsort [obj info lookup methods child]} {child} ? {lsort [obj info lookup methods child*]} {child} @@ -694,8 +695,8 @@ ? {obj link5 foo} {::obj::child} ? {obj child foo} {::obj::child} - ? {lsort [obj info methods child]} {child} - ? {lsort [obj info methods]} {child link1 link2 link3 link4 link5} + ? {lsort [obj info object methods child]} {child} + ? {lsort [obj info object methods]} {child link1 link2 link3 link4 link5} ? {lsort [obj info lookup methods child]} {child} ? {lsort [obj info lookup methods child*]} {child} @@ -715,8 +716,8 @@ #? {obj child foo} {::obj: unable to dispatch method 'foo'} ? {obj child foo} {::obj} - ? {lsort [obj info methods child]} {child} - ? {lsort [obj info methods]} {child link1 link2 link3 link4 link5} + ? {lsort [obj info object methods child]} {child} + ? {lsort [obj info object methods]} {child link1 link2 link3 link4 link5} ? {lsort [obj info lookup methods child]} {child} ? {lsort [obj info lookup methods child*]} {child} } @@ -726,21 +727,21 @@ # Examplify the current behavior of "keepcallerself" with and without # the setting of "perobjectdispatch" # -nx::Test parameter count 1 -nx::Test case keepcallerself { +nx::test configure -count 1 +nx::test case keepcallerself { nx::Class create C {:public method foo {} {return C-[self]}} nx::Class create D {:public method foo {} {return D-[self]}} C create c1 { ::nsf::object::property [self] keepcallerself true - :public method bar {} {return c1-[self]} - :public method baz {} {return c1-[self]} + :public object method bar {} {return c1-[self]} + :public object method baz {} {return c1-[self]} } D create d1 { - :public method bar {} {return d1-[self]} - :public alias c1 ::c1 + :public object method bar {} {return d1-[self]} + :public object alias c1 ::c1 } # The normal dispatch ignores the keepcallerself completely @@ -770,12 +771,12 @@ C create c1 { ::nsf::object::property [self] keepcallerself true ::nsf::object::property [self] perobjectdispatch true - :public method bar {} {return c1-[self]} - :public method baz {} {return c1-[self]} + :public object method bar {} {return c1-[self]} + :public object method baz {} {return c1-[self]} } D create d1 { - :public method bar {} {return d1-[self]} - :public alias c1 ::c1 + :public object method bar {} {return d1-[self]} + :public object alias c1 ::c1 } # The normal dispatch ignores the keepcallerself and @@ -789,4 +790,12 @@ ? {d1 c1 bar} c1-::d1 ? {d1 c1 foo} "::c1: unable to dispatch method 'foo'" ? {d1 c1 baz} c1-::d1 -} \ No newline at end of file +} + +# +# Local variables: +# mode: tcl +# tcl-indent-level: 2 +# indent-tabs-mode: nil +# End: +