Index: library/lib/nx-traits.tcl =================================================================== diff -u -rf69de2050abfb8d71c92588c4d42d0cc1ea39aaf -r9d0ea2cf357adc5108001519286490593977e7e1 --- library/lib/nx-traits.tcl (.../nx-traits.tcl) (revision f69de2050abfb8d71c92588c4d42d0cc1ea39aaf) +++ library/lib/nx-traits.tcl (.../nx-traits.tcl) (revision 9d0ea2cf357adc5108001519286490593977e7e1) @@ -89,7 +89,7 @@ if {${per-object} || ![::nsf::is class $obj]} { error "per-object traits are currently not supported" } - foreach m [$traitName info methods -callprotection all] { + foreach m [$traitName info methods -callprotection all -path] { if {[info exists map($m)]} {set newName $map($m)} else {set newName $m} # do not add entries with $newName empty if {$newName eq ""} continue @@ -178,4 +178,11 @@ #puts "final reqMethods of [self]: $finalReqMethods // defined=[:info methods]" set :requiredMethods $finalReqMethods } -} \ No newline at end of file +} + +# +# Local variables: +# mode: tcl +# tcl-indent-level: 2 +# indent-tabs-mode: nil +# End: Index: tests/traits.test =================================================================== diff -u --- tests/traits.test (revision 0) +++ tests/traits.test (revision 9d0ea2cf357adc5108001519286490593977e7e1) @@ -0,0 +1,66 @@ +package require nx::trait +package require nx::test + +nx::test case basics { + + nx::Trait create t1 { + :public method t1m1 {} {return t1.[current method]} + :public method t1m2 {} {return t1.[current method]} + + # This trait requires a method "foo" + :requiredMethods foo + } + nx::Trait create t2 { + :public method "bar x" {} {return t2.[current methodpath]} + :public method "bar y" {} {return t2.[current methodpath]} + :public method foo {} {return t2.[current methodpath]} + + # This trait requires a method "t1m1" + :requiredMethods t1m1 + } + + nx::Trait create t3 { + :public method "bar y" {} {return t3.[current methodpath]} + :public method "bar z" {} {return t3.[current methodpath]} + } + + nx::Class create C { + :property {collection ""} + :public method foo {} {return [current method]} + :create c1 + } + + ? {c1 foo} "foo" + + ? {C require trait t2} "trait t2 requires t1m1, which is not defined for ::C" + + ? {lsort [C info methods]} "foo" + C require trait t1 + ? {lsort [C info methods]} "foo t1m1 t1m2" + ? {c1 foo} "foo" + + ? {C require trait t2} "" + ? {lsort [C info methods]} "bar foo t1m1 t1m2" + ? {lsort [C info methods -path]} "{bar x} {bar y} foo t1m1 t1m2" + # trait t2 redefines t2, so we call that see its result here + ? {c1 foo} "t2.foo" + ? {c1 bar x} "t2.bar x" + ? {c1 bar y} "t2.bar y" + + ? {C require trait t3} "" + ? {lsort [C info methods]} "bar foo t1m1 t1m2" + ? {lsort [C info methods -path]} "{bar x} {bar y} {bar z} foo t1m1 t1m2" + # trait t3 redefines "bar y", so we call that see its result here + ? {c1 foo} "t2.foo" + ? {c1 bar x} "t2.bar x" + ? {c1 bar y} "t3.bar y" + ? {c1 bar z} "t3.bar z" +} + + +# +# Local variables: +# mode: tcl +# tcl-indent-level: 2 +# indent-tabs-mode: nil +# End: