2 ObjectTest
:= UnitTest
clone do(
14 assertSame(Object, a
proto)
15 assertSame(a
, b
proto)
19 assertEquals(5, for(i
, 1, 10, if(i
== 5, break(i
))))
22 testHasLocalSlot
:= method(
23 assertFalse(Object clone hasLocalSlot("clone"))
24 assertTrue(Object hasLocalSlot("clone"))
27 testHasSlot
:= method(
28 assertFalse(Object hasSlot("slotThatShouldNotExist"))
29 assertTrue(Object clone hasSlot("clone"))
30 assertTrue(Object hasSlot("clone"))
36 A test
:= method(a
, for(i
, 1, 2, s
appendSeq(a
, i asString
, "."); yield))
40 yield; yield; yield; yield;
41 assertEquals("a1.b1.a2.b2.", A s asString
)
47 obj double
:= method(v
, return v
* 2)
48 future
:= obj
@double(2)
49 assertEquals(future
, 4)
50 // known bug
- assertEquals(4, future
)
53 testQuestionMarkReturns
:= method(
54 a
:= method(x
, x
return "first"; "second")
55 b
:= method(x
, x ?
return "first"; "second")
59 testQuestionMarkContinues
:= method(
62 list(1,2,3,4,5) foreach(x
,
70 list(1,2,3,4,5) foreach(x
,
79 testForeachSlotStopStatus
:= method(
82 o
:= Object clone do(a
:= 1; b
:= 2; c
:= 3; d
:= 4; e
:= 5; f
:= 6)
84 if(k
== "a", continue)
89 if(k
== "d", return r
)
92 r
append("didn't return")
96 assertEquals(f
, list("b", "c", "d", "a", "b", "c"))
100 Lobby willFreeWorked
:= false
101 Object clone do(willFree
:= method(Lobby willFreeWorked
:= true
))
105 testWillFree
:= method(
108 assertEquals(Lobby willFreeWorked
, true
)
111 testLazySlot
:= method(
114 o
lazySlot("bob", bobCalcCount
= bobCalcCount
+ 1; 19)
116 assertEquals(o bobCalcCount
, 0)
117 assertEquals(o bob
, 19)
118 assertEquals(o bobCalcCount
, 1)
119 assertEquals(o bob
, 19)
120 assertEquals(o bobCalcCount
, 1)
121 assertEquals(o bob
, 19)
122 assertEquals(o bobCalcCount
, 1)
125 testRemoveAllProtosAsString
:= method(
127 assertRaisesException(Object clone removeAllProtos asString)