## expand-oop-syntax2-unit.pkg
# Compiled by:
#
src/lib/test/unit-tests.lib# Run by:
#
src/lib/test/all-unit-tests.pkgclass2__ test2_class {
class2__ 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;
};
class2__ test2_subclass {
class2__ super = test2_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;
};
class2__ test2_subsubclass {
class2__ super = test2_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_syntax2_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-syntax2-unit-test.pkg";
fun run ()
=
{
printf "\nDoing %s:\n" name;
obj1 = test2_class::make__object ( { field1b => "abcb" }, () );
obj2 = test2_subclass::make__object ( { field2b => "defb" }, { field1b => "Abcb" }, () );
obj3 = test2_subsubclass::make__object ( { field3b => "ghib" }, { field2b => "defb" }, { field1b => "ABcb" }, () );
obj4 = test2_class::combine obj1 obj1;
assert (test2_class::get1 obj1 == "tsr" );
assert (test2_class::get1 obj2 == "[tsr]" );
assert (test2_class::get1 obj3 == "{[tsr]}");
assert (test2_subclass::get2 obj2 == "uvw");
assert (test2_subclass::get2 obj3 == "uvw");
assert (test2_subsubclass::get3 obj3 == "xyz");
assert (test2_class::get1b obj1 "prefix" == "prefixbcba");
assert (test2_class::combine_ints obj1 (12,13) == 25);
assert (test2_class::combine_ints obj2 (12,13) == 156);
assert (test2_class::get1b obj1 "prefix_" == "prefix_bcba");
assert (test2_class::get1b obj2 "prefix_" == "prefix_bcbA");
assert (test2_class::get1b obj3 "prefix_" == "prefix_bcBA");
assert (test2_class::get1b obj4 "prefix_" == "prefix_bcbabcba");
summarize_unit_tests name;
};
};