]> git.lizzy.rs Git - nothing.git/blob - test/interpreter_suite.h
f4712107b27bbf5373bbf68d66c9c5864759116b
[nothing.git] / test / interpreter_suite.h
1 #ifndef INTERPRETER_SUITE_H_
2 #define INTERPRETER_SUITE_H_
3
4 #include "test.h"
5 #include "script/builtins.h"
6
7 TEST(equal_test)
8 {
9     struct Expr nil1 = NIL;
10     struct Expr nil2 = NIL;
11     ASSERT_TRUE(equal(nil1, nil2), "nils are not equal");
12     destroy_expr(nil1);
13     destroy_expr(nil2);
14
15     struct Expr list1 =
16         CONS(SYMBOL("a"),
17              CONS(SYMBOL("b"),
18                   CONS(SYMBOL("c"),
19                        NIL)));
20     struct Expr list2 =
21         CONS(SYMBOL("a"),
22              CONS(SYMBOL("b"),
23                   CONS(SYMBOL("c"),
24                        NIL)));
25     ASSERT_TRUE(equal(list1, list2), "lists are not equal");
26     destroy_expr(list1);
27     destroy_expr(list2);
28
29     return 0;
30 }
31
32 TEST(assoc_test)
33 {
34     struct Expr nil = NIL;
35
36     struct Expr a = SYMBOL("a");
37     struct Expr b = SYMBOL("b");
38     struct Expr c = SYMBOL("c");
39
40     struct Expr a_pair = CONS(a, NUMBER(10.0f));
41     struct Expr b_pair = CONS(b, NUMBER(20.0f));
42     struct Expr c_pair = CONS(c, NUMBER(30.0f));
43
44     struct Expr alist =
45         CONS(a_pair,
46              CONS(b_pair,
47                   CONS(c_pair, nil)));
48
49     equal(a_pair, assoc(b, alist));
50
51     destroy_expr(alist);
52     return 0;
53 }
54
55 TEST_SUITE(interpreter_suite)
56 {
57     TEST_RUN(equal_test);
58     TEST_RUN(assoc_test);
59
60     return 0;
61 }
62
63 #endif  // INTERPRETER_SUITE_H_