Index: tests/methods.test =================================================================== diff -u -re884c2b0d63fa1b5a691e866ccff8d4094a2a8e4 -r764ac30a3ca9712d9fc59853b36759e1dd146114 --- tests/methods.test (.../methods.test) (revision e884c2b0d63fa1b5a691e866ccff8d4094a2a8e4) +++ tests/methods.test (.../methods.test) (revision 764ac30a3ca9712d9fc59853b36759e1dd146114) @@ -1,10 +1,11 @@ # -*- Tcl -*- package require nx -::nx::configure defaultMethodCallProtection false package require nx::test -nx::Test parameter count 10 +::nx::configure defaultMethodCallProtection false +nx::test configure -count 10 + nx::Class create C { # methods :method plain_method {} {return [current method]} @@ -27,78 +28,78 @@ :protected alias protected_alias [C info method registrationhandle protected_method] # class-object - :class method plain_object_method {} {return [current method]} - :public class method public_object_method {} {return [current method]} - :protected class method protected_object_method {} {return [current method]} - :class forward plain_object_forward %self plain_object_method - :public class forward public_object_forward %self public_object_method - :protected class forward protected_object_forward %self protected_object_method + :object method plain_object_method {} {return [current method]} + :public object method public_object_method {} {return [current method]} + :protected object method protected_object_method {} {return [current method]} + :object forward plain_object_forward %self plain_object_method + :public object forward public_object_forward %self public_object_method + :protected object forward protected_object_forward %self protected_object_method - :class property {plain_object_setter ""} - :class property -accessor public {public_object_setter ""} - :class property -accessor protected {protected_object_setter ""} + :object property {plain_object_setter ""} + :object property -accessor public {public_object_setter ""} + :object property -accessor protected {protected_object_setter ""} - :class alias plain_object_alias [:class info method registrationhandle plain_object_method] - :public class alias public_object_alias [:class info method registrationhandle public_object_method] - :protected class alias protected_object_alias [:class info method registrationhandle protected_object_method] + :object alias plain_object_alias [:info object method registrationhandle plain_object_method] + :public object alias public_object_alias [:info object method registrationhandle public_object_method] + :protected object alias protected_object_alias [:info object method registrationhandle protected_object_method] } C create c1 { # methods - :method plain_object_method {} {return [current method]} - :public method public_object_method {} {return [current method]} - :protected method protected_object_method {} {return [current method]} + :object method plain_object_method {} {return [current method]} + :public object method public_object_method {} {return [current method]} + :protected object method protected_object_method {} {return [current method]} # forwards - :forward plain_object_forward %self plain_object_method - :public forward public_object_forward %self public_object_method - :protected forward protected_object_forward %self protected_object_method + :object forward plain_object_forward %self plain_object_method + :public object forward public_object_forward %self public_object_method + :protected object forward protected_object_forward %self protected_object_method # setter - :property {plain_object_setter ""} - :property -accessor public {public_object_setter ""} - :property -accessor protected protected_object_setter + :object property {plain_object_setter ""} + :object property -accessor public {public_object_setter ""} + :object property -accessor protected protected_object_setter # alias - :alias plain_object_alias [:info method registrationhandle plain_object_method] - :public alias public_object_alias [:info method registrationhandle public_object_method] - :protected alias protected_object_alias [:info method registrationhandle protected_object_method] + :object alias plain_object_alias [:info object method registrationhandle plain_object_method] + :public object alias public_object_alias [:info object method registrationhandle public_object_method] + :protected object alias protected_object_alias [:info object method registrationhandle protected_object_method] } C property -accessor public s0 C property -accessor protected s1 ? {c1 s0 0} 0 ? {::nsf::dispatch c1 s1 1} 1 -C class property -accessor public {s3 ""} +C object property -accessor public {s3 ""} ? {C s3 3} 3 # create a fresh object (different from c1) C create c2 # test scripted class level methods -nx::Test case scripted-class-level-methods { +nx::test case scripted-class-level-methods { ? {c2 plain_method} "plain_method" ? {c2 public_method} "public_method" ? {catch {c2 protected_method}} 1 ? {::nsf::dispatch c2 protected_method} "protected_method" } # class level forwards -nx::Test case class-level-forwards { +nx::test case class-level-forwards { ? {c2 plain_forward} "plain_method" ? {c2 public_forward} "public_method" ? {catch {c2 protected_forward}} 1 ? {::nsf::dispatch c2 protected_forward} "protected_method" } # class level setter -nx::Test case class-level-setter { - #? {c2 plain_setter 1} {::c2: unable to dispatch method 'plain_setter'} - ? {c2 plain_setter 1} 1 +nx::test case class-level-setter { + ? {c2 plain_setter 1} {::c2: unable to dispatch method 'plain_setter'} + #? {c2 plain_setter 1} 1 ? {c2 public_setter 2} "2" ? {catch {c2 protected_setter 3}} 1 ? {::nsf::dispatch c2 protected_setter 4} "4" } # class level alias .... -nx::Test case class-level-alias { +nx::test case class-level-alias { ? {c2 plain_alias} "plain_alias" ? {c2 public_alias} "public_alias" ? {catch {c2 protected_alias}} 1 @@ -108,32 +109,32 @@ ########### # scripted class level methods -nx::Test case scripted-class-object-level { +nx::test case scripted-class-object-level { ? {C plain_object_method} "plain_object_method" ? {C public_object_method} "public_object_method" ? {catch {C protected_object_method}} 1 ? {::nsf::dispatch C protected_object_method} "protected_object_method" } # class level forwards -nx::Test case class-object-level-forwards { +nx::test case class-object-level-forwards { ? {C plain_object_forward} "plain_object_method" ? {C public_object_forward} "public_object_method" ? {catch {C protected_object_forward}} 1 ? {::nsf::dispatch C protected_object_forward} "protected_object_method" } # class level setter -nx::Test case class-object-level-setter { - #? {C plain_object_setter 1} {method 'plain_object_setter' unknown for ::C; consider '::C create plain_object_setter 1' instead of '::C plain_object_setter 1'} - ? {C plain_object_setter 1} "1" +nx::test case class-object-level-setter { + ? {C plain_object_setter 1} {method 'plain_object_setter' unknown for ::C; consider '::C create plain_object_setter 1' instead of '::C plain_object_setter 1'} + #? {C plain_object_setter 1} "1" ? {C public_object_setter 2} "2" ? {catch {C protected_object_setter 3}} 1 ? {::nsf::dispatch C protected_object_setter 4} "4" } # class level alias .... -nx::Test case class-object-level-alias { +nx::test case class-object-level-alias { ? {C plain_object_alias} "plain_object_alias" ? {C public_object_alias} "public_object_alias" ? {catch {C protected_object_alias}} 1 @@ -143,91 +144,91 @@ ########### # scripted object level methods -nx::Test case scripted-object-level-methods { +nx::test case scripted-object-level-methods { ? {c1 plain_object_method} "plain_object_method" ? {c1 public_object_method} "public_object_method" ? {catch {c1 protected_object_method}} 1 ? {::nsf::dispatch c1 protected_object_method} "protected_object_method" } # object level forwards -nx::Test case object-level-forwards { +nx::test case object-level-forwards { ? {c1 plain_object_forward} "plain_object_method" ? {c1 public_object_forward} "public_object_method" ? {catch {c1 protected_object_forward}} 1 ? {::nsf::dispatch c1 protected_object_forward} "protected_object_method" } # object level setter -nx::Test case object-level-setter { - #? {c1 plain_object_setter 1} {::c1: unable to dispatch method 'plain_object_setter'} - ? {c1 plain_object_setter 1} "1" +nx::test case object-level-setter { + ? {c1 plain_object_setter 1} {::c1: unable to dispatch method 'plain_object_setter'} + #? {c1 plain_object_setter 1} "1" ? {c1 public_object_setter 2} "2" ? {catch {c1 protected_object_setter 3}} 1 ? {::nsf::dispatch c1 protected_object_setter 4} "4" } # object level alias .... -nx::Test case object-level-alias { +nx::test case object-level-alias { ? {c1 plain_object_alias} "plain_object_alias" ? {c1 public_object_alias} "public_object_alias" ? {catch {c1 protected_object_alias}} 1 ? {::nsf::dispatch c1 protected_object_alias} "protected_object_alias" - #? {lsort [c1 info methods]} \ + #? {lsort [c1 info object methods]} \ "plain_object_alias plain_object_forward plain_object_method public_object_alias public_object_forward public_object_method public_object_setter" - ? {lsort [c1 info methods]} \ - "plain_object_alias plain_object_forward plain_object_method plain_object_setter public_object_alias public_object_forward public_object_method public_object_setter" + ? {lsort [c1 info object methods]} \ + "plain_object_alias plain_object_forward plain_object_method public_object_alias public_object_forward public_object_method public_object_setter" - #? {lsort [C class info methods]} \ + #? {lsort [C info methods]} \ "plain_object_alias plain_object_forward plain_object_method public_object_alias public_object_forward public_object_method public_object_setter s3" - ? {lsort [C class info methods]} \ - "plain_object_alias plain_object_forward plain_object_method plain_object_setter public_object_alias public_object_forward public_object_method public_object_setter s3" + ? {lsort [C info object methods]} \ + "plain_object_alias plain_object_forward plain_object_method public_object_alias public_object_forward public_object_method public_object_setter s3" } C destroy -nx::Test case colondispatch { +nx::test case colondispatch { nx::Object create ::o { - #:public method foo args {;} - :public method bar args {;} + #:public object method foo args {;} + :public object method bar args {;} } ? {o :bar} "::o: method name ':bar' must not start with a colon" ? {o eval :bar} "" ? {o :foo} "::o: method name ':foo' must not start with a colon" ? {o eval :foo} "::o: unable to dispatch method 'foo'" } -nx::Test case mixinguards { +nx::test case mixinguards { # define a Class C and mixin class M nx::Class create C nx::Class create M - # register the mixin on C as a class mixin and define a mixinguard + # register the mixin on C as a object mixin and define a mixinguard C mixin M C mixin guard M {1 == 1} ? {C info mixin guard M} "1 == 1" C mixin guard M {} ? {C info mixin guard M} "" # now the same as class mixin and class mixin guard - C class mixin M - C class mixin guard M {1 == 1} - ? {C class info mixin guard M} "1 == 1" - C class mixin guard M {} - ? {C class info mixin guard M} "" + C object mixin M + C object mixin guard M {1 == 1} + ? {C info object mixin guard M} "1 == 1" + C object mixin guard M {} + ? {C info object mixin guard M} "" } -nx::Test case mixin-via-objectparam { +nx::test case mixin-via-objectparam { # add an object and class mixin via object-parameter and via slots nx::Class create M1; nx::Class create M2; nx::Class create M3; nx::Class create M4 nx::Class create C -mixin M1 -object-mixin M2 { :mixin add M3 - :class mixin add M4 + :object mixin add M4 } - ? {lsort [C class info mixin classes]} "::M2 ::M4" - #? {lsort [C class info mixin classes]} "::M2" + ? {lsort [C info object mixin classes]} "::M2 ::M4" + #? {lsort [C info object mixin classes]} "::M2" ? {lsort [C info mixin classes]} "::M1 ::M3" #? {lsort [C info mixin classes]} "::M1" @@ -236,10 +237,10 @@ } # testing next via nonpos-args -nx::Test case next-from-nonpos-args { +nx::test case next-from-nonpos-args { nx::Object create o { - :method bar {-y:required -x:required} { + :object method bar {-y:required -x:required} { #puts stderr "+++ o x=$x, y=$y [current args] ... next [current nextmethod]" return [list x $x y $y [current args]] } @@ -251,15 +252,15 @@ } } - o mixin M + o object mixin M ? {o bar -x 13 -y 14} "x 13 y 14 {-x 13 -y 14} -- x 13 y 14 {-x 13 -y 14}" ? {o bar -y 14 -x 13} "x 13 y 14 {-y 14 -x 13} -- x 13 y 14 {-y 14 -x 13}" } # # test method property with protected/public # -nx::Test case property-method { +nx::test case property-method { nx::Class create C { set x [:property -accessor public a] @@ -271,13 +272,13 @@ :property -accessor public {c c1} :property -accessor protected {d d1} - set X [:class property -accessor public A] + set X [:object property -accessor public A] ? [list set _ $X] "::C::A" - # class property with default - :class property {B B2} - :class property -accessor public {C C2} - :class property -accessor protected {D D2} + # object property with default + :object property {B B2} + :object property -accessor public {C C2} + :object property -accessor protected {D D2} } C create c1 -a 1 @@ -288,28 +289,28 @@ ? {C A 2} 2 ? {C A} 2 - #? {C B} {method 'B' unknown for ::C; consider '::C create B ' instead of '::C B '} - ? {C B} B2 + ? {C B} {method 'B' unknown for ::C; consider '::C create B ' instead of '::C B '} + #? {C B} B2 ? {C C} C2 ? {C D} "method 'D' unknown for ::C; consider '::C create D ' instead of '::C D '" nx::Object create o { - set x [:property -accessor public a] + set x [:object property -accessor public a] ? [list set _ $x] "::o::a" # property with default - :property {b b1} - :property -accessor public {c c1} - :property -accessor protected {d d1} + :object property {b b1} + :object property -accessor public {c c1} + :object property -accessor protected {d d1} } ? {o a 2} 2 - #? {o b} {::o: unable to dispatch method 'b'} - ? {o b} b1 + ? {o b} {::o: unable to dispatch method 'b'} + #? {o b} b1 ? {o c} c1 ? {o d} "::o: unable to dispatch method 'd'" } -nx::Test case subcmd { +nx::test case subcmd { nx::Class create Foo { @@ -318,16 +319,16 @@ :method "Info args" {} {return [current object]-[current method]} :method "Info foo" {} {return [current object]-[current method]} - :class method "INFO filter guard" {a b} {return [current object]-[current method]} - :class method "INFO filter methods" {-guards pattern:optional} {return [current object]-[current method]} + :object method "INFO filter guard" {a b} {return [current object]-[current method]} + :object method "INFO filter methods" {-guards pattern:optional} {return [current object]-[current method]} } ? {Foo INFO filter guard 1 2} ::Foo-guard ? {Foo INFO filter methods a*} ::Foo-methods Foo create f1 { - :method "list length" {} {return [current object]-[current method]} - :method "list reverse" {} {return [current object]-[current method]} + :object method "list length" {} {return [current object]-[current method]} + :object method "list reverse" {} {return [current object]-[current method]} } ? {f1 Info filter guard x} "::f1-guard" @@ -340,16 +341,16 @@ } package req nx::serializer -nx::Test case class-object-property { +nx::test case class-object-property { nx::Class create C { - :class property -accessor public x + :object property -accessor public x :property -accessor public a:int :create c1 } ? {C x 1} 1 ? {C x} 1 ? {lsort [C info methods]} "a" - ? {lsort [C class info methods]} "x" + ? {lsort [C info object methods]} "x" ? {c1 a b} {expected integer but got "b" for parameter "a"} set s(C) [C serialize] @@ -371,19 +372,19 @@ # tests should work as again ? {C x} 1 ? {lsort [C info methods]} "a" - ? {lsort [C class info methods]} "x" + ? {lsort [C info object methods]} "x" ? {c1 a b} {expected integer but got "b" for parameter "a"} } # # Test method deletion # -nx::Test parameter count 1 +nx::test configure -count 1 -nx::Test case methoddelete { +nx::test case methoddelete { nx::Class create C { :public method foo {x} {return $x} - :public class method bar {x} {return $x} + :public object method bar {x} {return $x} :create c1 } @@ -399,37 +400,37 @@ # # Test error message of method modifier # -nx::Test parameter count 1 +nx::test configure -count 1 -nx::Test case errormessage { +nx::test case errormessage { nx::Class create C ? {C public method foo {x} {return $x}} "::nsf::classes::C::foo" - ? {C public object method bar {x} {return $x}} \ - "'object' is not a method defining method" - ? {C protected object method bar {x} {return $x}} \ - "'object' is not a method defining method" - ? {C object method bar {x} {return $x}} \ - {method 'object' unknown for ::C; consider '::C create object method bar x {return $x}' instead of '::C object method bar x {return $x}'} - #? {C public class object method bar {x} {return $x}} "'object' not allowed to be modified by 'class'" - ? {C public class object method bar {x} {return $x}} \ - {'object' is not a method defining method} + ? {C public Object method bar {x} {return $x}} \ + "'Object' is not a method defining method" + ? {C protected Object method bar {x} {return $x}} \ + "'Object' is not a method defining method" + ? {C Object method bar {x} {return $x}} \ + {method 'Object' unknown for ::C; consider '::C create Object method bar x {return $x}' instead of '::C Object method bar x {return $x}'} + #? {C public object Object method bar {x} {return $x}} "'Object' not allowed to be modified by 'class'" + #? {C public object Object method bar {x} {return $x}} \ + {'Object' is not a method defining method} } # # test dispatch without object # -nx::Test case dispatch-without-object { +nx::test case dispatch-without-object { nx::Object create o { # property defines a setter, we need a current object - :property -accessor public {a v} + :object property -accessor public {a v} # the other methods don't require them as strong - :forward b ::o2 bar - :method foo {} {return [nx::self]} - :alias x ::o::foo + :object forward b ::o2 bar + :object method foo {} {return [nx::self]} + :object alias x ::o::foo } nx::Object create o2 { - :public method bar {} {return [nx::self]} + :public object method bar {} {return [nx::self]} } # dispatch methods without current object @@ -451,11 +452,11 @@ # b) ensemble methods on level 1 # c) ensemble methods on level 2 # -nx::Test case scopes { +nx::test case scopes { nx::Object create o1 { - :public method foo {} {return [namespace current]-[namespace which info]} - :public method "info foo" {} {return [namespace current]-[namespace which info]} - :public method "info bar foo" {} {return [namespace current]-[namespace which info]} + :public object method foo {} {return [namespace current]-[namespace which info]} + :public object method "info foo" {} {return [namespace current]-[namespace which info]} + :public object method "info bar foo" {} {return [namespace current]-[namespace which info]} } ? {o1 foo} "::-::info" @@ -481,13 +482,13 @@ # b) ensemble methods on level 1 # c) ensemble methods on level 2 # -nx::Test case namespaced-scopes { +nx::test case namespaced-scopes { namespace eval ::ns { nx::Object create o1 { - :public method foo {} {return [namespace current]-[namespace which info]} - :public method "info foo" {} {return [namespace current]-[namespace which info]} - :public method "info bar foo" {} {return [namespace current]-[namespace which info]} + :public object method foo {} {return [namespace current]-[namespace which info]} + :public object method "info foo" {} {return [namespace current]-[namespace which info]} + :public object method "info bar foo" {} {return [namespace current]-[namespace which info]} } nx::Class create C { :public method foo {} {return [namespace current]-[namespace which info]} @@ -514,12 +515,12 @@ # b) ensemble methods on level 1 # c) ensemble methods on level 2 # -nx::Test case nested-scopes { +nx::test case nested-scopes { nx::Object create o nx::Object create o::o1 { - :public method foo {} {return [namespace current]-[namespace which info]} - :public method "info foo" {} {return [namespace current]-[namespace which info]} - :public method "info bar foo" {} {return [namespace current]-[namespace which info]} + :public object method foo {} {return [namespace current]-[namespace which info]} + :public object method "info foo" {} {return [namespace current]-[namespace which info]} + :public object method "info bar foo" {} {return [namespace current]-[namespace which info]} } ? {o::o1 foo} "::o-::info" @@ -546,43 +547,43 @@ # b) test simple methods # c) test ensemble methods # -nx::Test case delete-per-object { +nx::test case delete-per-object { nx::Object create o1 { - :property -accessor public a1 - :property -accessor public a2 - :public method foo {} {return [namespace current]-[namespace which info]} - :public method "info foo" {} {return [namespace current]-[namespace which info]} - :public method "info bar foo" {} {return [namespace current]-[namespace which info]} + :object property -accessor public a1 + :object property -accessor public a2 + :public object method foo {} {return [namespace current]-[namespace which info]} + :public object method "info foo" {} {return [namespace current]-[namespace which info]} + :public object method "info bar foo" {} {return [namespace current]-[namespace which info]} } - ? {o1 info methods -path} "{info foo} {info bar foo} foo a1 a2" + ? {o1 info object methods -path} "{info foo} {info bar foo} foo a1 a2" ? {o1 info children} "::o1::info ::o1::per-object-slot" - ? {o1 delete method bar} "::o1: object specific method 'bar' does not exist" + ? {o1 delete object method bar} "::o1: object specific method 'bar' does not exist" # For a1, we have a method and an property. We can delete the # method without the slot. - ? {o1 delete method a1} "" + ? {o1 delete object method a1} "" # After the deletion of the accessor, the slot exists still ? {o1::per-object-slot info children} "::o1::per-object-slot::a1 ::o1::per-object-slot::a2" - # If we perform now a "delete property a1", the slot will be removed. - ? {o1 delete property a1} "" + # If we perform now a "delete object property a1", the slot will be removed. + ? {o1 delete object property a1} "" ? {o1::per-object-slot info children} "::o1::per-object-slot::a2" # try to delete the property again: - ? {o1 delete property a1} "::o1: cannot delete object specific property 'a1'" + ? {o1 delete object property a1} "::o1: cannot delete object specific property 'a1'" - ? {o1 info methods -path} "{info foo} {info bar foo} foo a2" - ? {o1 delete property a2} "" - ? {o1 info methods -path} "{info foo} {info bar foo} foo" + ? {o1 info object methods -path} "{info foo} {info bar foo} foo a2" + ? {o1 delete object property a2} "" + ? {o1 info object methods -path} "{info foo} {info bar foo} foo" - ? {o1 delete method foo} "" - ? {o1 info methods -path} "{info foo} {info bar foo}" + ? {o1 delete object method foo} "" + ? {o1 info object methods -path} "{info foo} {info bar foo}" - ? {o1 delete method "info foo"} "" - ? {o1 info methods -path} "{info bar foo}" + ? {o1 delete object method "info foo"} "" + ? {o1 info object methods -path} "{info bar foo}" - ? {o1 delete method "info bar foo"} "" - ? {o1 info methods -path} "" + ? {o1 delete object method "info bar foo"} "" + ? {o1 info object methods -path} "" } # @@ -592,35 +593,35 @@ # b) test simple methods # c) test ensemble methods # -nx::Test case delete-per-object-on-class { +nx::test case delete-per-object-on-class { nx::Class create C { - :class property -accessor public a1 - :public class method foo {} {return [namespace current]-[namespace which info]} - :public class method "info foo" {} {return [namespace current]-[namespace which info]} - :public class method "info bar foo" {} {return [namespace current]-[namespace which info]} + :object property -accessor public a1 + :public object method foo {} {return [namespace current]-[namespace which info]} + :public object method "info foo" {} {return [namespace current]-[namespace which info]} + :public object method "info bar foo" {} {return [namespace current]-[namespace which info]} :property -accessor public a2 } - ? {C class info methods -path} "{info foo} {info bar foo} foo a1" + ? {C info object methods -path} "{info foo} {info bar foo} foo a1" ? {C info children} "::C::info ::C::slot ::C::per-object-slot" - ? {C class delete method bar} "::C: object specific method 'bar' does not exist" + ? {C delete object method bar} "::C: object specific method 'bar' does not exist" - ? {C class delete property a1} "" - ? {C class info methods -path} "{info foo} {info bar foo} foo" - ? {C class delete property a1} "::C: cannot delete object specific property 'a1'" + ? {C delete object property a1} "" + ? {C info object methods -path} "{info foo} {info bar foo} foo" + ? {C delete object property a1} "::C: cannot delete object specific property 'a1'" - ? {C class delete method foo} "" - ? {C class info methods -path} "{info foo} {info bar foo}" + ? {C delete object method foo} "" + ? {C info object methods -path} "{info foo} {info bar foo}" - ? {C class delete method "info foo"} "" - ? {C class info methods -path} "{info bar foo}" + ? {C delete object method "info foo"} "" + ? {C info object methods -path} "{info bar foo}" - ? {C class delete method "info bar foo"} "" - ? {C class info methods -path} "" + ? {C delete object method "info bar foo"} "" + ? {C info object methods -path} "" ? {C info methods} "a2" - ? {C info slot objects} "::C::slot::a2" + ? {C info slots} "::C::slot::a2" } @@ -631,7 +632,7 @@ # b) test simple methods # c) test ensemble methods # -nx::Test case delete-class-level-method { +nx::test case delete-class-level-method { nx::Class create C { :property -accessor public a1 :public method foo {} {return [namespace current]-[namespace which info]} @@ -663,29 +664,29 @@ # simple unknown tests; # ensemble unknown tests are in submethods.test # -nx::Test case test-simple-unknown { +nx::test case test-simple-unknown { # # calling unknown with a plain "method" without arguments # ::nx::Class create A { - :class method unknown args {? [list set _ $args] "hello"} + :object method unknown args {? [list set _ $args] "hello"} } A hello # # calling unknown with a plain "method" with arguments # ::nx::Class create B { - :class method unknown args {? [list set _ $args] "hello world"} + :object method unknown args {? [list set _ $args] "hello world"} } B hello world # # calling unknown with a method with spaces # ::nx::Class create C { - :class method unknown args {? [list set _ $args] "{hello world}"} + :object method unknown args {? [list set _ $args] "{hello world}"} } C {hello world} } @@ -695,24 +696,24 @@ # simple speed tests # ensemble unknown tests are in submethods.test # -nx::Test parameter count 1000 -nx::Test case speed-dispatch { +nx::test configure -count 1000 +nx::test case speed-dispatch { # # define various forms of simple dispatches # ::nx::Object create o { - :public method foo {} {return ::o} - :public method bar00 {} {self} - :public method bar01 {} {:} - :public method bar02 {} {[self]} - :public method bar03 {} {[:]} - :public method bar04 {} {:foo} - :public method bar05 {} {: foo} - #:public method bar06 {} {my foo} - :public method bar07 {} {[self] foo} - :public method bar08 {} {: -system info methods foo} - #:public method bar09 {} {my -system info methods foo} + :public object method foo {} {return ::o} + :public object method bar00 {} {self} + :public object method bar01 {} {:} + :public object method bar02 {} {[self]} + :public object method bar03 {} {[:]} + :public object method bar04 {} {:foo} + :public object method bar05 {} {: foo} + #:public object method bar06 {} {my foo} + :public object method bar07 {} {[self] foo} + :public object method bar08 {} {: -system info object methods foo} + #:public object method bar09 {} {my -system info object methods foo} } ? {o foo} ::o @@ -728,15 +729,15 @@ #? {o bar09} foo "my -system info" } -nx::Test parameter count 1 -nx::Test case fq-obj-dispatch { +nx::test configure -count 1 +nx::test case fq-obj-dispatch { # # Capture the (current) dispatcher rules for fully-qualified # selectors which resolve to existing objects. # nx::Class create C { set :unknown 0 - :public class method unknown {m args} { + :public object method unknown {m args} { incr :unknown return unknown-$m } @@ -840,4 +841,266 @@ ? {::X set p1} 3 ? {::X set unknown} 2 ? {::X set recreate} 1 -} \ No newline at end of file +} + + +# +# object copy +# +nx::test case object-copy { + nsf::method::provide set {::nsf::method::alias set -frame object ::set} + + nx::Object create o { + :public object method foo {} {return foo} + :public object method "a b" {} {return "a b"} + :public object method "a c" {} {return "a c"} + :protected object method bar {} {return bar} + :private object method baz {} {return baz} + :public object forward fwd %self xxx + :require public object method set + } + ? {lsort [::o info object methods -path]} "{a b} {a c} foo fwd set" + ? {o a b} "a b" + ? {o a c} "a c" + ? {o set x 1} 1 + + ? {o copy p} ::p + ? {lsort [::p info object methods -path]} "{a b} {a c} foo fwd set" + + ? {p a b} "a b" + ? {p a c} "a c" + + #package require nx::serializer + #puts stderr [o serialize] + #puts stderr [p serialize] + ? {p set x} 1 +} + +# +# class copy +# +nx::test case class-copy { + nsf::method::provide set {::nsf::method::alias set -frame object ::set} + + nx::Class create C { + :public method foo {} {return foo} + :public method "a b" {} {return "a b"} + :public method "a c" {} {return "a c"} + :protected method bar {} {return bar} + :private method baz {} {return baz} + :public forward fwd %self xxx + :require public method set + :create c1 + } + + ? {lsort [::C info methods -path]} "{a b} {a c} foo fwd set" + ? {::c1 a b} "a b" + ? {::c1 a c} "a c" + ? {::c1 set x 1} 1 + + ? {::C copy ::D} ::D + + ? {lsort [::D info methods -path]} "{a b} {a c} foo fwd set" + + #package require nx::serializer + #puts stderr [::C serialize] + #puts stderr [::D serialize] + + ::D create d1 + + ? {::d1 a b} "a b" + ? {::d1 a c} "a c" + + #puts stderr [::c1 serialize] + #puts stderr [::d1 serialize] + ? {::d1 set x 2} 2 +} + + +# +# class copy with class object methods +# +nx::test case object+class-copy { + nsf::method::provide set {::nsf::method::alias set -frame object ::set} + nsf::method::provide exists {::nsf::method::alias exists ::nsf::methods::object::exists} + + nx::Class create C { + :public method foo {} {return foo} + :public method "a b" {} {return "a b"} + :public method "a c" {} {return "a c"} + :protected method bar {} {return bar} + :private method baz {} {return baz} + :public forward fwd %self xxx + :require public method set + + :public object method ofoo {} {return foo} + :public object method "oa b" {} {return "oa b"} + :public object method "oa c" {} {return "oa c"} + :protected object method obar {} {return bar} + :private object method obaz {} {return baz} + :public object forward ofwd %self xxx + #TODO: the following line leads to a crash + #:require public object method exists + :require public object method set + :create c1 + } + + ? {lsort [::C info methods -path]} "{a b} {a c} foo fwd set" + ? {lsort [::C info object methods -path]} "{oa b} {oa c} ofoo ofwd set" + + ? {::c1 a b} "a b" + ? {::c1 a c} "a c" + ? {::c1 set x 1} 1 + + ? {::C oa b} "oa b" + ? {::C oa c} "oa c" + ? {::C set y 100} "100" + + ? {::C copy ::D} ::D + + ? {lsort [::D info methods -path]} "{a b} {a c} foo fwd set" + #? {lsort [::D info object methods -path]} "{oa b} {oa c} ofoo ofwd set" + + ? {::D oa b} "oa b" + ? {::D oa c} "oa c" + ? {::D set y} "100" + + ::D create d1 + + ? {::d1 a b} "a b" + ? {::d1 a c} "a c" + + ? {::d1 set x 2} 2 +} + + + +nx::test configure -count 10 +# +# class copy with class object methods +# +nx::test case object+class+property-copy { + nsf::method::provide set {::nsf::method::alias set -frame object ::set} + nsf::method::provide exists {::nsf::method::alias exists ::nsf::methods::object::exists} + + package require nx::serializer + + nx::Class create C { + :public method foo {} {return foo} + :public method "a b" {} {return "a b"} + :public method "a c" {} {return "a c"} + :protected method bar {} {return bar} + :private method baz {} {return baz} + :public forward fwd %self xxx + :require public method set + :property p + :variable v 0 + + :public object method ofoo {} {return foo} + :public object method "oa b" {} {return "oa b"} + :public object method "oa c" {} {return "oa c"} + :protected object method obar {} {return bar} + :private object method obaz {} {return baz} + :public object forward ofwd %self xxx + :require public object method exists + :require public object method set + + :object property op + :object variable ov 0 + + :create c1 + } + + ? {lsort [::C info methods -path]} "{a b} {a c} foo fwd set" + ? {lsort [::C info object methods -path]} "exists {oa b} {oa c} ofoo ofwd set" + + ? {::c1 a b} "a b" + ? {::c1 a c} "a c" + ? {::c1 set x 1} 1 + + ? {::C oa b} "oa b" + ? {::C oa c} "oa c" + ? {::C set y 100} "100" + + ::nx::Object public method COPY {target} { + set code [::Serializer deepSerialize -objmap [list [self] $target] [self]] + #puts CODE=$code + eval $code + return $target + } + + ? {::C copy ::D} ::D + ? {::C COPY ::E} ::E + + ? {lsort [::D info methods -path]} "{a b} {a c} foo fwd set" + ? {lsort [::D info object methods -path]} "exists {oa b} {oa c} ofoo ofwd set" + + ? {::D oa b} "oa b" + ? {::D oa c} "oa c" + ? {::D set y} "100" + + ? {::D create d1} ::d1 + ? {::d1 a b} "a b" + ? {::d1 a c} "a c" + ? {::d1 set x 2} 2 + + ? {::E oa b} "oa b" + ? {::E oa c} "oa c" + ? {::E set y} "100" + + ? {::E create e1} ::e1 + ? {::e1 a b} "a b" + ? {::e1 a c} "a c" + ? {::e1 set x 2} 2 + +} + +nx::test case xotcl-COPY { + package req XOTcl + xotcl::Class create C + C proc foo {} {return foo} + C instproc bar {} {return bar} + C set x 1 + + ::xotcl::Object instproc COPY {target} { + set code [::Serializer deepSerialize -objmap [list [self] $target] [self]] + #puts CODE=$code + eval $code + return $target + } + + ? {C set x} 1 + C copy D + C COPY E + + ? {D set x} 1 + ? {D foo} foo + ? {D create d1} ::d1 + ? {d1 bar} bar + + ? {E set x} 1 + ? {E foo} foo + ? {E create e1} ::e1 + ? {e1 bar} bar +} + +nx::test case assertion-swallows-result { + + nx::Class create Edge { + :public method foo {} { + :configure -xxx 1 + } + :create e1 + } + + # base case + ? {catch {e1 foo} errMsg} 1 + ? {string match "invalid non-positional*" $errMsg} 1 + + # turn on assertion checking + nsf::method::assertion e1 check all + + # still report error + ? {catch {e1 foo} errMsg} 1 + ? {string match "invalid non-positional*" $errMsg} 1 +}