1 BlockTest
:= UnitTest
clone do(
4 block1
:= Lobby getSlot("Block") clone
5 assertNotEquals(Lobby getSlot("Block") uniqueId, getSlot("block2") uniqueId)
6 block2
:= Lobby getSlot("Block") clone
7 assertNotEquals(getSlot("block1") uniqueId, getSlot("block2") uniqueId)
11 // would need to be able to read stdout
or install a printCallback from Io to test
print()
16 assertEquals("block(foo bar)", block(foo bar
) code
)
17 testBlock
:= block(foo bar
)
18 getSlot("testBlock") setScope(nil
)
19 assertEquals("method(foo bar)", getSlot("testBlock") code
)
20 getSlot("testBlock") setScope(self)
21 assertEquals("block(foo bar)", getSlot("testBlock") code
)
24 testMessage
:= method(
25 assertRaisesException(block(foo bar
) setMessage
)
26 assertRaisesException(block(foo bar
) setMessage(nil
))
27 assertEquals("foo bar", block(foo bar
) message code
)
28 testMessage
:= Message fromString("blah fasel")
29 assertEquals(testMessage
, block(foo bar
) setMessage(testMessage
) message)
32 testArgumentNames
:= method(
33 assertRaisesException(block(foo bar
) setArgumentNames
)
34 assertRaisesException(block(foo bar
) setArgumentNames(nil
))
35 testBlock
:= block(a
, b
, c
, foo bar
)
36 assertEquals(List clone append("a", "b", "c"), getSlot("testBlock") argumentNames
)
37 testBlock
= block(foo bar
)
38 assertEquals(List, getSlot("testBlock") argumentNames
)
39 getSlot("testBlock") setArgumentNames(List clone append("d", "e"))
40 assertEquals(List clone append("d", "e"), getSlot("testBlock") argumentNames
)
43 testConstruction
:= method(
44 testMessage
:= Message fromString("arg1 + arg2")
45 argumentNames
:= List clone append("arg1", "arg2")
46 testBlock
:= Lobby getSlot("Block") clone setMessage(testMessage
) setArgumentNames(argumentNames
)
47 assertEquals(5, testBlock
call(3, 2))
51 assertSame(self, block(foo bar
) scope
self)
53 selfBlock
:= block(thisContext)
54 getSlot("selfBlock") setScope(nil
)
55 assertNil(getSlot("selfBlock") scope
)
56 //assertSame(thisContext, selfBlock call call target
) // should this be true?
block recycling doesn
't like it?
57 //assertSame(getSlot("selfBlock") message, selfBlock call message)
59 object := Object clone
60 getSlot("selfBlock") setScope(object)
61 assertSame(object, getSlot("selfBlock") scope)
63 getSlot("selfBlock") setScope
64 assertNil(getSlot("selfBlock") scope)
69 assertRaisesException(block(1) ifTrue)
71 block(1) ifTrue(called = 1)
73 block(nil) ifTrue(fail)
76 testIfFalse := method(
77 assertRaisesException(block(1) ifFalse)
78 block(1) ifFalse(fail)
80 block(nil) ifFalse(called = 1)
84 testWhileTrue := method(
85 assertRaisesException(block(1) whileTrue)
88 block(amount = amount -1; amount >= 0) whileTrue(callCounter = callCounter + 1)
89 assertEquals(3, callCounter)
92 testWhileFalse := method(
93 assertRaisesException(block(1) whileFalse)
96 block(amount = amount -1; amount < 0) whileFalse(callCounter = callCounter + 1)
97 assertEquals(3, callCounter)