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

test[m8n] 40 Object


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


--testing instance methods
test:basicAt_put_("sample",123)
if (not test:basicAt_("sample")==123) then error("Must be 123") end
test:basicDelete_("sample")
if (test:basicAt_ifAbsent_("sample",function() return "empty" end)~="empty") then error("Must be empty") end
if (not test:respondsTo_("yourself")) then error("Must return true") end
if (test:methodFor_("yourself")["@classField"]~=smalltalk.Object) then error("Must be implemented by Object") end


--copying
test=smalltalk.Point:x_y_(3,4)
point= test:copy()
if (not point:x()==3) then error("Invalid x value") end
if (not point:y()==4) then error("Invalid y value") end
test= smalltalk.Point:x_y_(1,smalltalk.Point:x_y_("two",3))
point=test:deepCopy()
if (not point:x()==3) then error("Invalid x value") end
if (not point:y():isKindOf_(smalltalk.Point)) then error("Invalid y value") end


-- natives
test=smalltalk.Object:new()
if (not test:isObject_(test)) then error("Must be an Object") end
if (not test:isObject_(smalltalk.Point:x_y_(1,2))) then error("Must be an Object") end
if (test:isObject_(nil)) then error("nil is NOT an Object") end
if (test:isObject_(0)) then error("0 is NOT an Object") end
if (test:isObject_(7)) then error("Number is NOT an Object") end
if (test:isObject_(function() end)) then error("Function is NOT an Object") end


-- smalltalk
test=smalltalk.Object:new()
if (test:smalltalk()~=smalltalk) then error("Must be smalltalk") end
if (smalltalk.Point:smalltalk()~=smalltalk) then error("Must be smalltalk") end


-- perform and globals lookup
if (smalltalk.Point:x_y_(3,5):basicPerform_withArguments_("x",smalltalk.Array:new())~=3) then error("Must return 3") end
if (not smalltalk.Smalltalk:includesKey_("Point")) then error("Missing global Point") end
if smalltalk.Smalltalk:includesKey_("Missing global") then error("Must return false") end


--perform
if (test:perform_("yourself")~=test) then error("Must be equal") end


--events
test=smalltalk.Object:new()
if (test:eventTable():class()~=smalltalk.PoolDictionary) then error("Must be aPoolDictionary") end
if (test:eventTable():notEmpty()) then error("Must be empty") end
if (test:triggerEvent_ifNotHandled_("needsPoint",function() return smalltalk.Point:x_y_(1,2) end):class()~=smalltalk.Point) then error("Must be aPoint") end
if (test:triggerEvent_ifNotHandled_("needsPoint",function() return smalltalk.Point:x_y_(1,2) end):x()~=1) then error("Must be 1@2") end
test:when_do_("needsPoint",function() return smalltalk.Point:x_y_(5,5) end)
if (test:triggerEvent_ifNotHandled_("needsPoint",nil):x()~=5) then error("Must be 5@5") end


-- cleanup
test = nil
point = nil