]> git.lizzy.rs Git - nothing.git/blob - test/parser_suite.h
(#427) Fix svg2rects failure on newlines in labels
[nothing.git] / test / parser_suite.h
1 #ifndef PARSER_SUITE_H_
2 #define PARSER_SUITE_H_
3
4 #include "test.h"
5 #include "script/parser.h"
6 #include "script/gc.h"
7
8 TEST(read_expr_from_file_test)
9 {
10     Gc *gc = create_gc();
11
12     struct ParseResult result = read_expr_from_file(gc, "test-data/simple-sum.lisp");
13
14     ASSERT_TRUE(!result.is_error, result.error_message);
15
16     struct Expr head = result.expr;
17
18     struct Expr expr = head;
19     ASSERT_INTEQ(EXPR_CONS, expr.type);
20     ASSERT_INTEQ(EXPR_ATOM, expr.cons->car.type);
21     ASSERT_INTEQ(ATOM_SYMBOL, expr.cons->car.atom->type);
22     ASSERT_STREQ("+", expr.cons->car.atom->sym);
23
24     expr = expr.cons->cdr;
25     ASSERT_INTEQ(EXPR_CONS, expr.type);
26     ASSERT_INTEQ(EXPR_ATOM, expr.cons->car.type);
27     ASSERT_INTEQ(ATOM_NUMBER, expr.cons->car.atom->type);
28     ASSERT_LONGINTEQ(1L, expr.cons->car.atom->num);
29
30     expr = expr.cons->cdr;
31     ASSERT_INTEQ(EXPR_CONS, expr.type);
32     ASSERT_INTEQ(EXPR_ATOM, expr.cons->car.type);
33     ASSERT_INTEQ(ATOM_NUMBER, expr.cons->car.atom->type);
34     ASSERT_LONGINTEQ(2L, expr.cons->car.atom->num);
35
36     expr = expr.cons->cdr;
37     ASSERT_INTEQ(EXPR_CONS, expr.type);
38     ASSERT_INTEQ(EXPR_ATOM, expr.cons->car.type);
39     ASSERT_INTEQ(ATOM_NUMBER, expr.cons->car.atom->type);
40     ASSERT_LONGINTEQ(3L, expr.cons->car.atom->num);
41
42     expr = expr.cons->cdr;
43     ASSERT_INTEQ(EXPR_ATOM, expr.type);
44     ASSERT_INTEQ(ATOM_SYMBOL, expr.atom->type);
45     ASSERT_STREQ("nil", expr.atom->sym);
46
47     destroy_gc(gc);
48
49     return 0;
50 }
51
52 TEST(parse_negative_numbers_test)
53 {
54     Gc *gc = create_gc();
55     struct ParseResult result = read_expr_from_string(gc, "-12345");
56
57     ASSERT_FALSE(result.is_error, "Parsing failed");
58     ASSERT_TRUE(result.expr.type == EXPR_ATOM, "Parsed expression is not an atom");
59     ASSERT_TRUE(result.expr.atom->type == ATOM_NUMBER, "Parsed expression is not a number");
60     ASSERT_LONGINTEQ(-12345L, result.expr.atom->num);
61
62     destroy_gc(gc);
63
64     return 0;
65 }
66
67 TEST_SUITE(parser_suite)
68 {
69     TEST_RUN(read_expr_from_file_test);
70     TEST_RUN(parse_negative_numbers_test);
71
72     return 0;
73 }
74
75 #endif  // PARSER_SUITE_H_