[View] [Edit] [Lock] [References] [Attachments] [History] [Home] [Changes] [Search] [Help]
test[m8n] 45 BlockClosure
--setup
test=function() return "hello" end
--accessing
if (test:compiledSource():startsWith_("function:")) then error("Access to source code not implemented. Yet") end
local access=function() test:argumentCount() end; access:on_do_(Exception, function() error("Not implemented. Yet") end)
| |
--converting
if (test~=test:asJSONObject()) then error("Must return the receiver") end
--copying
if (test~=test:shallowCopy()) then error("Must return the receiver") end
if (test~=test:deepCopy()) then error("Must return the receiver") end
--error handling
local temp=nil;test:ensure_(function() temp=10 end); if (temp~=10) then error("Must execute the ensure block") end
local temp=nil; local f=function() error("ouch") end; f:ensure_(function() temp=10 end); if (temp~=10) then error("Must execute the ensure block") end
local temp=nil; local f=function() error("ouch") end; f:on_do_(smalltalk.Exception,function() temp=10 end); if (temp~=10) then error("temp must be 10") end
local temp=nil; local f=function() print("ok") end; f:on_do_(smalltalk.Exception,function() temp=10 end); if (temp~=nil) then error("temp must be nil") end
--evaluating
if ("hello"~=test:evaluate()) then error("Must return hello") end
if ("hello"~=test:evaluateFor_(43)) then error("Must return hello") end
local f=function(x) return x+4 end; if (7~=f:evaluateFor_(3)) then error("Must return 3+4") end
if ("hello"~=test:ifCurtailed_(function() return 43 end)) then error("Must return hello") end
if ("hello"~=test:value()) then error("Must return hello") end
local f=function(x) return x+4 end; if (7~=f:value_(3)) then error("Must return 3+4") end
"evaluating blocks"
| block result |
result := #().
block := [:a1 :a2|
result add: a1;add: a2.
# #print: #a1 with: a1 with: #a2 with: a2
].
block evaluateWithArguments: #(1 2).
result = #(1 2) ifFalse: [ self error: 'Test failed' ]!
--cleanup
test=nil