summaryrefslogtreecommitdiff
path: root/tiger-compiler/tests/unit/parse/tiger_factory/test_make_if_exp.cc
blob: d32459113af054813a86163b60b840b01aef863a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
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);
}