2019-06-27 06:29:09 +00:00
|
|
|
//
|
|
|
|
// TEST CASES for basic methods
|
|
|
|
//
|
2016-03-28 13:27:03 +00:00
|
|
|
|
2019-06-27 08:06:33 +00:00
|
|
|
#include "Moo.moo".
|
2016-03-28 13:27:03 +00:00
|
|
|
|
2019-06-27 06:29:09 +00:00
|
|
|
////////////////////////////////////////////////////////////////#
|
|
|
|
// MAIN
|
|
|
|
////////////////////////////////////////////////////////////////#
|
2016-03-28 13:27:03 +00:00
|
|
|
|
2017-10-05 17:14:38 +00:00
|
|
|
class MyObject(Object)
|
2016-03-28 13:27:03 +00:00
|
|
|
{
|
2017-04-24 09:20:27 +00:00
|
|
|
var(#classinst) t1, t2.
|
|
|
|
|
2017-01-06 09:53:40 +00:00
|
|
|
method(#class) xxxx
|
2016-03-28 13:27:03 +00:00
|
|
|
{
|
|
|
|
| g1 g2 |
|
|
|
|
t1 dump.
|
|
|
|
t2 := [ g1 := 50. g2 := 100. ^g1 + g2 ].
|
|
|
|
(t1 < 100) ifFalse: [ ^self ].
|
|
|
|
t1 := t1 + 1.
|
|
|
|
^self xxxx.
|
|
|
|
}
|
2019-02-18 08:57:59 +00:00
|
|
|
method(#class) test1
|
|
|
|
{
|
2019-06-27 06:29:09 +00:00
|
|
|
//// TODO: add this to the test case list.
|
2019-02-18 08:57:59 +00:00
|
|
|
| rec results |
|
|
|
|
|
2019-06-27 06:29:09 +00:00
|
|
|
//rec := [ :y :z | (108.0000000000000000000000 - (815.000000000000000000 - (1500.0000000000000000 div: z) div: y)) truncate: 18. ].
|
|
|
|
//rec := [ :y :z | (108.0000000000000000000000 - (815.000000000000000000 - (1500.0000000000000000 div: z) div: y)) truncate: 16. ].
|
|
|
|
//rec := [ :y :z | 108.0000000000000000000000 - (815.000000000000000000 - (1500.0000000000000000 div: z) div: y) ].
|
|
|
|
//rec := [ :y :z | (108.0 scale: 22) - ((815 scale: 18) - ((1500 scale: 16) div: z) div: y) ].
|
|
|
|
//rec := [ :y :z | 108.000000000000000000000000000000 - (815.00000000000000000000000000 - (1500.0000000000000000 div: z) div: y) ].
|
2019-02-19 05:02:37 +00:00
|
|
|
rec := [ :y :z | 22p108 - (18p815 - (16p1500 div: z) div: y) ].
|
2019-02-18 08:57:59 +00:00
|
|
|
|
|
|
|
|
2019-06-27 07:43:17 +00:00
|
|
|
// results := ##( 4.0, 425 div: 100.0 ) asOrderedCollection.
|
2019-02-18 08:57:59 +00:00
|
|
|
results := OrderedCollection new.
|
|
|
|
results add: 4.0; add: (425.00 div: 100.00).
|
|
|
|
|
|
|
|
|
|
|
|
3 to: 100 do: [ :i |
|
2019-06-27 06:29:09 +00:00
|
|
|
//(results at: i - 2) dump.
|
|
|
|
//(results at: i - 3) dump.
|
2019-06-27 08:06:33 +00:00
|
|
|
//"----------" dump.
|
2019-02-18 08:57:59 +00:00
|
|
|
results add: (rec value: (results at: i - 2) value: (results at: i - 3)).
|
|
|
|
].
|
|
|
|
|
|
|
|
results doWithIndex: [ :each :i |
|
|
|
|
System log: (i asString); log: "\t";
|
|
|
|
log: each; logNl: "".
|
|
|
|
].
|
|
|
|
}
|
2016-03-28 13:27:03 +00:00
|
|
|
|
2019-08-06 10:01:54 +00:00
|
|
|
|
2019-08-07 08:34:53 +00:00
|
|
|
method(#class) test_local_return_001
|
2019-08-06 10:01:54 +00:00
|
|
|
{
|
|
|
|
| a b c d|
|
|
|
|
a := 10.
|
|
|
|
c := 2.
|
|
|
|
d := 3.
|
|
|
|
b := ([
|
|
|
|
[
|
|
|
|
a := a + 3.
|
|
|
|
if (a > 10) { ^^77 } // ^^ must return to the calling method despite 2 blocks nested.
|
|
|
|
] value.
|
|
|
|
d := 99. // this is skipped because of ^^77 above.
|
|
|
|
] ensure: [ c := 88 ]). // however, the ensured block must be executed.
|
|
|
|
|
|
|
|
^a == 13 and b == 77 and c == 88 and d == 3.
|
|
|
|
}
|
|
|
|
|
2019-08-07 08:34:53 +00:00
|
|
|
method(#class) test_if_001
|
|
|
|
{
|
|
|
|
| a b c d e x |
|
|
|
|
|
|
|
|
x := if (false) { X02: a := 55. goto Z02 }
|
|
|
|
elif (false) { b := 66.}
|
|
|
|
elif (2 > 1) { c := 77. goto X02 }
|
|
|
|
elif (true) { d := 88 }
|
|
|
|
else { Z02: e := 99 }.
|
|
|
|
|
|
|
|
^c == 77 and a == 55 and e == 99 and b == nil and d == nil and x == 99.
|
|
|
|
}
|
|
|
|
|
|
|
|
method(#class) test_while_001
|
|
|
|
{
|
|
|
|
| a b i |
|
|
|
|
|
|
|
|
a := 0.
|
|
|
|
b := #(0 0 0 0 0) copy.
|
|
|
|
i := 0.
|
|
|
|
|
|
|
|
while (false)
|
|
|
|
{
|
|
|
|
X02:
|
|
|
|
a := a + 1.
|
|
|
|
b at: i put: 1.
|
|
|
|
i := i + 1.
|
|
|
|
goto X03.
|
|
|
|
}.
|
|
|
|
goto X02.
|
|
|
|
|
|
|
|
until (false)
|
|
|
|
{
|
|
|
|
X03:
|
|
|
|
a := a + 2.
|
|
|
|
b at: i put: 2.
|
|
|
|
i := i + 1.
|
|
|
|
goto Y01.
|
|
|
|
}.
|
|
|
|
|
|
|
|
do
|
|
|
|
{
|
|
|
|
X04:
|
|
|
|
a := a + 3.
|
|
|
|
b at: i put: 3.
|
|
|
|
i := i + 1.
|
|
|
|
goto X05.
|
|
|
|
}
|
|
|
|
while (true).
|
|
|
|
Y01:
|
|
|
|
goto X04.
|
|
|
|
|
|
|
|
do
|
|
|
|
{
|
|
|
|
a := a + 4.
|
|
|
|
b at: i put: 4.
|
|
|
|
i := i + 1.
|
|
|
|
break.
|
|
|
|
X05:
|
|
|
|
a := a + 5.
|
|
|
|
b at: i put: 5.
|
|
|
|
i := i + 1.
|
|
|
|
}
|
|
|
|
until (false).
|
|
|
|
|
|
|
|
^a == 15 and b = #(1 2 3 5 4).
|
|
|
|
}
|
|
|
|
|
2019-08-02 09:32:19 +00:00
|
|
|
method(#class) q
|
|
|
|
{
|
|
|
|
| v |
|
|
|
|
|
|
|
|
v := 0.
|
|
|
|
start:
|
|
|
|
if (v > 100) { ^nil }.
|
|
|
|
v dump.
|
|
|
|
v := v + 1.
|
|
|
|
goto start.
|
|
|
|
}
|
|
|
|
|
2017-01-06 09:53:40 +00:00
|
|
|
method(#class) main
|
2016-03-28 13:27:03 +00:00
|
|
|
{
|
2017-09-29 15:03:54 +00:00
|
|
|
| tc limit |
|
2017-09-30 04:49:54 +00:00
|
|
|
|
2019-06-27 07:43:17 +00:00
|
|
|
tc := ##(
|
2019-06-27 06:29:09 +00:00
|
|
|
// 0 - 4
|
2017-09-29 15:03:54 +00:00
|
|
|
[(Object isKindOf: Class) == true],
|
|
|
|
[(Object isKindOf: Apex) == true],
|
|
|
|
[(Class isKindOf: Class) == true],
|
|
|
|
[(Class isKindOf: Apex) == true],
|
|
|
|
[(Class isKindOf: Object) == false],
|
|
|
|
|
2019-06-27 06:29:09 +00:00
|
|
|
// 5-9
|
2017-09-29 15:03:54 +00:00
|
|
|
[(Apex isKindOf: Class) == true],
|
2017-09-30 04:49:54 +00:00
|
|
|
[(Apex isKindOf: Apex) == true],
|
2017-09-29 15:03:54 +00:00
|
|
|
[(SmallInteger isKindOf: Integer) == false],
|
2017-10-02 01:22:49 +00:00
|
|
|
[(SmallInteger isKindOf: SmallInteger) == false],
|
|
|
|
[(Object isKindOf: SmallInteger) == false],
|
2017-09-29 15:03:54 +00:00
|
|
|
|
2019-06-27 06:29:09 +00:00
|
|
|
// 10-14
|
2017-10-02 01:22:49 +00:00
|
|
|
[(10 isKindOf: Integer) == true],
|
|
|
|
[(10 isKindOf: 20) == false],
|
2020-10-15 14:50:08 +00:00
|
|
|
[([] isKindOf: CompiledBlock) == true],
|
|
|
|
[([] isKindOf: CompiledMethod) == false],
|
|
|
|
[([] isKindOf: BlockContext) == false],
|
|
|
|
|
|
|
|
|
2017-10-02 01:22:49 +00:00
|
|
|
|
2019-08-06 10:01:54 +00:00
|
|
|
// 15-19
|
2020-10-15 14:50:08 +00:00
|
|
|
[([] isKindOf: MethodContext) == false],
|
|
|
|
[([] isKindOf: Context) == false],
|
2019-06-27 08:06:33 +00:00
|
|
|
[("string" isKindOf: String) == true],
|
2017-09-30 04:49:54 +00:00
|
|
|
[(#symbol isKindOf: String) == true],
|
2019-06-27 08:06:33 +00:00
|
|
|
[("string" isKindOf: Symbol) == false],
|
2019-08-06 10:01:54 +00:00
|
|
|
|
|
|
|
// 20-24
|
2020-10-15 14:50:08 +00:00
|
|
|
[(#symbol isKindOf: Symbol) == true],
|
|
|
|
[ [] value == nil ],
|
2019-08-07 08:34:53 +00:00
|
|
|
[ self test_local_return_001 ],
|
|
|
|
[ self test_if_001 ],
|
|
|
|
[ self test_while_001 ],
|
2019-08-06 10:01:54 +00:00
|
|
|
[ (if (1 > 2) { } else { }) == nil. ],
|
|
|
|
|
|
|
|
// 25-29
|
2020-10-15 14:50:08 +00:00
|
|
|
[ (if (1 < 2) { } else { }) == nil. ],
|
|
|
|
[ (if (1 > 2) { } else { goto A01. A01: nil }) == nil ],
|
2019-11-08 07:28:09 +00:00
|
|
|
[ (if (1 > 2) { } else { 9876. goto A02. A02: 9876. }) == 9876 ],
|
2019-08-06 10:01:54 +00:00
|
|
|
[ [ | a3 | a3:= 20. if (a3 == 21) { a3 := 4321. goto L03 } else { a3 := 1234. goto L03 }. a3 := 8888. L03: a3 ] value == 1234 ],
|
|
|
|
[ [ | a4 | a4:= 21. if (a4 == 21) { a4 := 4321. goto L04 } else { a4 := 1234. goto L04 }. a4 := 8888. L04: a4 ] value == 4321 ]
|
2017-09-29 15:03:54 +00:00
|
|
|
).
|
2016-03-28 13:27:03 +00:00
|
|
|
|
2017-09-29 15:03:54 +00:00
|
|
|
limit := tc size.
|
|
|
|
|
|
|
|
0 priorTo: limit by: 1 do: [ :idx |
|
|
|
|
| tb |
|
|
|
|
tb := tc at: idx.
|
2019-06-27 08:06:33 +00:00
|
|
|
System log(System.Log.INFO, idx asString, (if (tb value) { " PASS" } else { " FAIL" }), "\n").
|
2019-02-19 05:02:37 +00:00
|
|
|
].
|
2019-08-06 10:01:54 +00:00
|
|
|
|
|
|
|
|
|
|
|
// (if (true) { a: 10. b: 1p1000. c: 20000 }) dump.
|
|
|
|
// [goto B02. A01: 10. B02: 1000. ] value class dump.
|
2019-08-02 09:32:19 +00:00
|
|
|
self q.
|
2019-07-12 07:24:37 +00:00
|
|
|
|
2019-08-06 10:01:54 +00:00
|
|
|
//[ | a | a := 21. if (a = 21) { goto X02 }. X02: ] value dump. // this causes a stack depletion problem... TODO:
|
|
|
|
|
|
|
|
//[ a := 4. while (1) { X44: goto X33 }. X33: 1233 dump. if (a < 10) { a := a + 1. 'X44' dump. goto X44 } else { 'ELSE' dump. a := a * 10}. ] value dump.
|
|
|
|
|
2019-08-04 16:38:09 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
this is horrible... the stack won't be cleared when goto is made...
|
|
|
|
System should never be popped out
|
|
|
|
(if (2 > 1) { 20. System log: (if (2 > 1) {goto X2}) }) dump.
|
|
|
|
X2:
|
|
|
|
a dump.
|
|
|
|
*/
|
2019-08-02 16:19:24 +00:00
|
|
|
|
2019-08-01 16:05:04 +00:00
|
|
|
EXCEPTION_TEST:
|
2019-07-12 07:24:37 +00:00
|
|
|
Exception signal: 'experiment with exception signalling'.
|
2019-05-30 15:44:24 +00:00
|
|
|
|
2019-06-27 06:29:09 +00:00
|
|
|
// TODO:
|
2019-11-03 09:15:24 +00:00
|
|
|
System logNl: String format("%s", " 나 는\\\"").
|
2019-05-30 15:44:24 +00:00
|
|
|
#"a b\nc" dump.
|
2017-09-29 15:03:54 +00:00
|
|
|
}
|
2016-03-28 13:27:03 +00:00
|
|
|
}
|