## expand-oop-syntax-unit.pkg
# Compiled by:
#
src/lib/test/unit-tests.lib# Run by:
#
src/lib/test/all-unit-tests.pkgclass__ test_class {
class__ super = object; # This is the default.
fun invert string
=
implode (reverse (explode string));
field my String field1 = "rst";
field my String field1b;
message fun
Self(X) -> String
get1 self
=
invert self->field1;
message fun
Self(X) -> String -> String
get1b self prefix
=
prefix + (invert self->field1b);
message fun
Self(X) -> Self(X) -> Myself
combine a b
=
make__object ({ field1b => a->field1b + b->field1b }, ());
message fun
Self(X) -> (Int, Int) -> Int
combine_ints self (i, j)
=
i + j;
};
class__ test_subclass {
class__ super = test_class;
field my String field2 = "uvw";
field my String field2b;
message fun
Self(X) -> String
get2 self
=
self->field2;
message fun
Self(X) -> String
get2b self
=
self->field2b;
method fun
get1 old self = "[" + (old self) + "]";
method fun
combine_ints old self (i, j)
=
i * j;
};
class__ test_subsubclass {
class__ super = test_subclass;
field my String field3 = "xyz";
field my String field3b;
message fun
Self(X) -> String
get3 self
=
self->field3;
message fun
Self(X) -> String
get3b self
=
self->field3b;
method fun
get1 old self = "{" + (old self) + "}";
};
package expand_oop_syntax_unit_test {
include package unit_test; # unit_test is from
src/lib/src/unit-test.pkg name = "src/lib/compiler/front/typer/main/expand-oop-syntax-unit-test.pkg";
fun run ()
=
{
printf "\nDoing %s:\n" name;
obj1 = test_class::make__object ( { field1b => "abcb" }, () );
obj2 = test_subclass::make__object ( { field2b => "defb" }, { field1b => "Abcb" }, () );
obj3 = test_subsubclass::make__object ( { field3b => "ghib" }, { field2b => "defb" }, { field1b => "ABcb" }, () );
obj4 = test_class::combine obj1 obj1;
assert (test_class::get1 obj1 == "tsr" );
assert (test_class::get1 obj2 == "[tsr]" );
assert (test_class::get1 obj3 == "{[tsr]}");
assert (test_subclass::get2 obj2 == "uvw");
assert (test_subclass::get2 obj3 == "uvw");
assert (test_subsubclass::get3 obj3 == "xyz");
assert (test_class::get1b obj1 "prefix" == "prefixbcba");
assert (test_class::combine_ints obj1 (12,13) == 25);
assert (test_class::combine_ints obj2 (12,13) == 156);
assert (test_class::get1b obj1 "prefix_" == "prefix_bcba");
assert (test_class::get1b obj2 "prefix_" == "prefix_bcbA");
assert (test_class::get1b obj3 "prefix_" == "prefix_bcBA");
assert (test_class::get1b obj4 "prefix_" == "prefix_bcbabcba");
summarize_unit_tests name;
};
};