Making object switch(...) return nil as a default if no default is specified
[io/quag.git] / libs / iovm / tests / ObjectTest.io
blobe16c0e036719a69216c57119daf4c0d655b9b73e
2 ObjectTest := UnitTest clone do(
3 setUp := method(
4 super(setUp)
7 tearDown := method(
8 super(tearDown)
11 testProto := method(
12 a := Object clone
13 b := a clone
14 assertSame(Object, a proto)
15 assertSame(a, b proto)
18 testFor := method(
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"))
33 testActor := method(
34 A := Object clone
35 A s := Sequence clone
36 A test := method(a, for(i, 1, 2, s appendSeq(a, i asString, "."); yield))
37 A clone @@test("a");
38 yield
39 A clone @@test("b")
40 yield; yield; yield; yield;
41 assertEquals("a1.b1.a2.b2.", A s asString)
45 testFuture := method(
46 obj := Object clone
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")
56 assertEquals(a, b)
59 testQuestionMarkContinues := method(
60 a := method(
61 r := list
62 list(1,2,3,4,5) foreach(x,
63 if(x > 3, continue)
64 r append(x)
68 b := method(
69 r := list
70 list(1,2,3,4,5) foreach(x,
71 if(x > 3, ?continue)
72 r append(x)
76 assertEquals(a, b)
79 testForeachSlotStopStatus := method(
80 f := method(
81 r := list
82 o := Object clone do(a := 1; b := 2; c := 3; d := 4; e := 5; f := 6)
83 o foreachSlot(k, v,
84 if(k == "a", continue)
85 if(k == "e", break)
86 r append(k)
88 o foreachSlot(k, v,
89 if(k == "d", return r)
90 r append(k)
92 r append("didn't return")
96 assertEquals(f, list("b", "c", "d", "a", "b", "c"))
99 _willFree2 := method(
100 Lobby willFreeWorked := false
101 Object clone do(willFree := method(Lobby willFreeWorked := true))
105 testWillFree := method(
106 _willFree2
107 Collector collect
108 assertEquals(Lobby willFreeWorked, true)
111 testLazySlot := method(
112 o := Object clone
113 o bobCalcCount := 0
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)