summaryrefslogtreecommitdiff
path: root/tiger-compiler/tests/unit/parse/tiger_factory/test_make_if_exp.cc
diff options
context:
space:
mode:
authorMartial Simon <msimon_fr@hotmail.com>2025-09-15 01:07:58 +0200
committerMartial Simon <msimon_fr@hotmail.com>2025-09-15 01:07:58 +0200
commit967be9e750221ab2ab783f95df79bb26d290a45e (patch)
tree6802900a5e975f9f68b169f0f503f040056d6952 /tiger-compiler/tests/unit/parse/tiger_factory/test_make_if_exp.cc
add: added projectsHEADmain
Diffstat (limited to 'tiger-compiler/tests/unit/parse/tiger_factory/test_make_if_exp.cc')
-rw-r--r--tiger-compiler/tests/unit/parse/tiger_factory/test_make_if_exp.cc48
1 files changed, 48 insertions, 0 deletions
diff --git a/tiger-compiler/tests/unit/parse/tiger_factory/test_make_if_exp.cc b/tiger-compiler/tests/unit/parse/tiger_factory/test_make_if_exp.cc
new file mode 100644
index 0000000..d324591
--- /dev/null
+++ b/tiger-compiler/tests/unit/parse/tiger_factory/test_make_if_exp.cc
@@ -0,0 +1,48 @@
+#include <ast/exp.hh>
+#include <ast/libast.hh>
+#include <criterion/criterion.h>
+#include <criterion/assert.h>
+#include <parse/libparse.hh>
+#include <ast/fwd.hh>
+#include <ast/pretty-printer.hh>
+
+TestSuite(BasicIf);
+
+Test(BasicIf, OnlyIf)
+{
+ std::cout << "----- IfLoops -----";
+ ast::PrettyPrinter print(std::cout);
+ ast::Exp* test = parse::parse("if a > 5 then a");
+ cr_assert_not_null(test);
+ print(test);
+ cr_assert_eq(1, 1);
+}
+
+TestSuite(RealisticIf);
+
+Test(RealisticIf, IfElse)
+{
+ ast::PrettyPrinter print(std::cout);
+ ast::Exp* test = parse::parse("if a > 5 then a else b");
+ cr_assert_not_null(test);
+ print(test);
+ cr_assert_eq(1, 1);
+}
+
+Test(RealisticIf, IfsElses)
+{
+ ast::PrettyPrinter print(std::cout);
+ ast::Exp* test = parse::parse("if a > 5 then a else if a < 0 then b else c");
+ cr_assert_not_null(test);
+ print(test);
+ cr_assert_eq(1, 1);
+}
+
+Test(RealisticIf, DanglingElse)
+{
+ ast::PrettyPrinter print(std::cout);
+ ast::Exp* test = parse::parse("if a > 5 then if a < 0 then b else c else d");
+ cr_assert_not_null(test);
+ print(test);
+ cr_assert_eq(1, 1);
+} \ No newline at end of file