Index: library/xotcl/library/xotcl2.tcl =================================================================== diff -u -ref9dd92a0a9b741825ab45dbdbcfc3cce546c0f9 -re13b154388485b71f544c2db0ff2038da06e08d4 --- library/xotcl/library/xotcl2.tcl (.../xotcl2.tcl) (revision ef9dd92a0a9b741825ab45dbdbcfc3cce546c0f9) +++ library/xotcl/library/xotcl2.tcl (.../xotcl2.tcl) (revision e13b154388485b71f544c2db0ff2038da06e08d4) @@ -924,19 +924,27 @@ :public forward proc %self public class method # # As NX/XOTcl hybrids, all slot kinds would not inherit the - # unknown behaviour of ::xotcl::Class. Therefore, we need to - # provide it explicitly to slots for backward compatibility ... + # unknown behaviour of ::xotcl::Class. Therefore, we provide it + # explicitly to slots for backward compatibility ... # :public alias unknown ::nsf::classes::xotcl::Class::unknown } # # Create ::xotcl::Attribute for compatibility # - ::xotcl::MetaSlot create ::xotcl::Attribute -superclass ::nx::VariableSlot - # - # TODO: multivalued emulation is missing! - # + ::xotcl::MetaSlot create ::xotcl::Attribute -superclass ::nx::VariableSlot { + :property multivalued { + :public method assign {object property value} { + set mClass [expr {$value?"0..n":"1..1"}] + $object incremental $value + $object multiplicity $mClass + } + :public method get {object property} { + return [$object eval [list :isMultivalued]] + } + } + } # # Provide a backward compatible version of ::xotcl::alias Index: library/xotcl/tests/slottest.xotcl =================================================================== diff -u -r59e100d383b22ea1407f5e5c40e303f2c6bb9027 -re13b154388485b71f544c2db0ff2038da06e08d4 --- library/xotcl/tests/slottest.xotcl (.../slottest.xotcl) (revision 59e100d383b22ea1407f5e5c40e303f2c6bb9027) +++ library/xotcl/tests/slottest.xotcl (.../slottest.xotcl) (revision e13b154388485b71f544c2db0ff2038da06e08d4) @@ -568,13 +568,64 @@ x move y ? {y a} 4 -exit +::nx::Test case slots-compat { + # + # Some tests covering the backward compatibility of NX/XOTcl2 hybrid + # slots to the XOTcl1 slot API (as extracted from the XOTcl language + # reference) + # + + # + # 1) old-style Attribute creation + # + + Class Window -slots { + Attribute scrollbar; # old style + Attribute create title; # new style + } + + ? {lsort [Window info slots]} "::Window::slot::scrollbar ::Window::slot::title" + + # + # 2) Dropped/missing slot attributes: multivalued + # + + Class Person -slots { + Attribute name + Attribute salary -default 0 + Attribute projects -default {} -multivalued true + } + + ? {lsort [Person info slots]} "::Person::slot::name ::Person::slot::projects ::Person::slot::salary" + + ? {Person::slot::name multivalued} 0 + ? {Person::slot::salary multivalued} 0 + ? {Person::slot::projects multivalued} 1 + + Person p2 -name "John Doe" + ? {p2 name} "John Doe" + ? {p2 salary} "0" + ? {p2 projects} [list] + + Project compatPrj -name XOTclCompat + p2 projects add ::compatPrj + p2 projects add some-other-value + + ? {lsort [p2 projects]} "::compatPrj some-other-value" + p2 projects delete some-other-value + ? {lsort [p2 projects]} "::compatPrj" -#puts [Person array get __defaults] -#puts [Person serialize] -puts [Serializer all] -eval [Serializer all] + ? {catch {p2 name add BOOM!}} 1 + ? {p2 name} "John Doe" +} +exit + + #puts [Person array get __defaults] + #puts [Person serialize] + puts [Serializer all] + eval [Serializer all] + ? {p2 salary} 1009 ? {catch {p2 append salary b}} 1 ? {p2 salary} 1009 @@ -686,6 +737,10 @@ puts stderr DONE-[p1 name]-[p1 age] p3 age 77 + + + + exit puts [XoXML asXML]