]> git.lizzy.rs Git - nothing.git/blob - test/interpreter_suite.h
TODO(#456)
[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     Gc *gc = create_gc();
10
11     struct Expr nil1 = NIL(gc);
12     struct Expr nil2 = NIL(gc);
13     ASSERT_TRUE(equal(nil1, nil2), "nils are not equal");
14
15     struct Expr list1 =
16         CONS(gc, SYMBOL(gc, "a"),
17              CONS(gc, SYMBOL(gc, "b"),
18                   CONS(gc, SYMBOL(gc, "c"),
19                        NIL(gc))));
20     struct Expr list2 =
21         CONS(gc, SYMBOL(gc, "a"),
22              CONS(gc, SYMBOL(gc, "b"),
23                   CONS(gc, SYMBOL(gc, "c"),
24                        NIL(gc))));
25     ASSERT_TRUE(equal(list1, list2), "lists are not equal");
26
27     destroy_gc(gc);
28
29     return 0;
30 }
31
32 TEST(assoc_test)
33 {
34     Gc *gc = create_gc();
35
36     struct Expr nil = NIL(gc);
37
38     struct Expr a = SYMBOL(gc, "a");
39     struct Expr b = SYMBOL(gc, "b");
40     struct Expr c = SYMBOL(gc, "c");
41
42     struct Expr a_pair = CONS(gc, a, NUMBER(gc, 10.0f));
43     struct Expr b_pair = CONS(gc, b, NUMBER(gc, 20.0f));
44     struct Expr c_pair = CONS(gc, c, NUMBER(gc, 30.0f));
45
46     struct Expr alist =
47         CONS(gc, a_pair,
48              CONS(gc, b_pair,
49                   CONS(gc, c_pair, nil)));
50
51     ASSERT_TRUE(equal(a_pair, assoc(a, alist)), "unexpected pair retrieved");
52
53     destroy_gc(gc);
54
55     return 0;
56 }
57
58 TEST_SUITE(interpreter_suite)
59 {
60     TEST_RUN(equal_test);
61     TEST_RUN(assoc_test);
62
63     return 0;
64 }
65
66 #endif  // INTERPRETER_SUITE_H_