[View]  [Edit]  [Lock]  [References]  [Attachments]  [History]  [Home]  [Changes]  [Search]  [Help] 

test[m8n] 41 Behavior and subclasses

-- setup
test=smalltalk.Behavior:new()


--testing instance methods
if (smalltalk.Object:compiledMethodAt_("yourself")==nil) then error("Should be implemented") end
if (smalltalk.Point:_gt_gt_gt("yourself")["@classField"]~=smalltalk.Object) then error("Must be implemented by Object") end
if (smalltalk.Point:instVarNames():size()~=2) then error("Must return 2") end
if (smalltalk.Point:allInstVarNames():asLiteral()~="#( #x #y )") then error("Wrong result") end
if (smalltalk.ComposedObjects:allInstVarNames():asLiteral()~="#( #contents #species )") then error("Wrong result") end

if (smalltalk.Class:allSuperclasses():size()~=2) then error("Must be 2") end
if (smalltalk.Association:basicNew():key()~=nil) then error("Must be nil") end
if (not smalltalk.Point:implements_("x")) then error("Must return true") end

if (not smalltalk.Point:inheritsFrom_(smalltalk.Object)) then error("Must return true") end
if (not smalltalk.Point["$klass"]:inheritsFrom_(smalltalk.Class)) then error("Must return true") end
if (not smalltalk.Point["$klass"]:inheritsFrom_(smalltalk.Object)) then error("Must return true") end
if (not smalltalk.Point["$klass"]:inheritsFrom_(smalltalk.Object["$klass"])) then error("Must return true") end
if (smalltalk.Object:inheritsFrom_(smalltalk.Point)) then error("Must return false") end
if (smalltalk.Point:inheritsFrom_(smalltalk.Collection)) then error("Must return false") end
if (smalltalk.Point:inheritsFrom_(smalltalk.Object["$klass"])) then error("Must return false") end

if (smalltalk.Behavior:withAllSubclasses():size()~=3) then error("Must be 3") end
if (smalltalk.Behavior:category()~="Kernel") then error("Must be Kernel") end


--hierarchy
if (smalltalk.Object:subclasses()==nil) then error("Broken subclasses - Needs work") end
if (not type(smalltalk.Object:subclasses():first():name())=="string") then error("Must be aString") end

if (smalltalk.Object:subclasses():collect_(function(each) return each:name() end)["$klass"]:name()~="Array") then error("Must be anArray") end
if (smalltalk.Object:subclasses():size()*2>smalltalk.Object:allSubclasses():size()) then error("All subclasses must be much more subclasses for Object") end


-- Behavior subclasses
if (smalltalk.Behavior:subclasses():size()~=2) then error("Must return two") end
if (smalltalk.Behavior:subclasses():asLiteral()~="#( Class Metaclass )") then error("Must return Class and Metaclass") end
if (smalltalk.Metaclass:subclasses():size()~=0) then error("Must be empty") end



-- cleanup
test = nil