From 2089367f519c7bc7fa938368081bd6faaadd4ebe Mon Sep 17 00:00:00 2001 From: paulklint Date: Sat, 14 Sep 2024 19:35:23 +0200 Subject: [PATCH] Added tests for Maybe data type --- .../rascal/tests/library/util/MaybeTests.rsc | 62 +++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 src/org/rascalmpl/library/lang/rascal/tests/library/util/MaybeTests.rsc diff --git a/src/org/rascalmpl/library/lang/rascal/tests/library/util/MaybeTests.rsc b/src/org/rascalmpl/library/lang/rascal/tests/library/util/MaybeTests.rsc new file mode 100644 index 0000000000..0551b1434f --- /dev/null +++ b/src/org/rascalmpl/library/lang/rascal/tests/library/util/MaybeTests.rsc @@ -0,0 +1,62 @@ +module lang::rascal::tests::library::util::MaybeTests + +import util::Maybe; + +test bool nothingStrEqual(){ + Maybe[str] x = nothing(); + Maybe[str] y = nothing(); + return x == nothing() && y == nothing() && x == y; +} + +test bool just2nothing(){ + x = just(3); + x = nothing(); + return x == nothing(); +} + +test bool inc1(){ + Maybe[int] x = just(3); + x.val += 1; + return x.val == 4; +} + +test bool inc2(){ + x = just(3); + x.val += 1; + return x.val == 4; +} + +test bool inc3(){ + x = just((1 : "a")); + x.val[1] ? "aaa" += "xxx"; + return x.val == (1:"axxx"); +} + +test bool inc4(){ + x = just((1 : "a")); + x.val[2] ? "aaa" += "xxx"; + return x.val == (1:"a",2:"aaaxxx"); +} + +data X = contain( + Maybe[bool] p, + Maybe[int] kw1 = just(2), + Maybe[str] kw2 = nothing() + ); + +test bool contain1(){ + c = contain(nothing()); + return c.p == nothing() && c.kw1.val == 2 && c.kw2 == nothing(); +} + +test bool contain2(){ + c = contain(nothing(), kw1 = nothing(), kw2 = just("hi")); + return c.p == nothing() && c.kw1 == nothing() && c.kw2 == just("hi"); +} + +test bool contain3(){ + c = contain(nothing()); + c.kw1 = nothing(); + c.kw2 = just("hi"); + return c.p == nothing() && c.kw1 == nothing() && c.kw2 == just("hi"); +} \ No newline at end of file