]> git.lizzy.rs Git - nothing.git/blob - test/scope_suite.h
(#781) Don't show the cursor in game play mode
[nothing.git] / test / scope_suite.h
1 #ifndef SCOPE_SUITE_H_
2 #define SCOPE_SUITE_H_
3
4 #include "test.h"
5 #include "ebisp/scope.h"
6 #include "ebisp/expr.h"
7
8 TEST(set_scope_value_test)
9 {
10     Gc *gc = create_gc();
11
12     struct Expr z = SYMBOL(gc, "z");
13     struct Expr x = SYMBOL(gc, "x");
14     struct Expr y = SYMBOL(gc, "y");
15
16     struct Scope scope = {
17         .expr = CONS(gc, NIL(gc), NIL(gc))
18     };
19
20     push_scope_frame(gc, &scope,
21                      list(gc, "ee", x, y),
22                      list(gc, "ss", "hello", "world"));
23
24     set_scope_value(gc, &scope, z, STRING(gc, "foo"));
25
26     ASSERT_TRUE(equal(CONS(gc, x, STRING(gc, "hello")), get_scope_value(&scope, x)),
27                 { fprintf(stderr, "Unexpected value of `x`\n"); });
28     ASSERT_TRUE(equal(CONS(gc, y, STRING(gc, "world")), get_scope_value(&scope, y)),
29                 { fprintf(stderr, "Unexpected value of `y`\n"); });
30     ASSERT_TRUE(equal(CONS(gc, z, STRING(gc, "foo")), get_scope_value(&scope, z)),
31                 { fprintf(stderr, "Unexpected value of `z`\n"); });
32
33     pop_scope_frame(gc, &scope);
34
35     ASSERT_TRUE(equal(NIL(gc), get_scope_value(&scope, x)),
36                 { fprintf(stderr, "Unexpected value of `x`\n"); });
37     ASSERT_TRUE(equal(NIL(gc), get_scope_value(&scope, y)),
38                 { fprintf(stderr, "Unexpected value of `y`\n"); });
39     ASSERT_TRUE(equal(CONS(gc, z, STRING(gc, "foo")), get_scope_value(&scope, z)),
40                 { fprintf(stderr, "Unexpected value of `z`\n"); });
41
42
43     destroy_gc(gc);
44
45     return 0;
46 }
47
48 TEST_SUITE(scope_suite)
49 {
50     TEST_RUN(set_scope_value_test);
51
52     return 0;
53 }
54
55 #endif  // SCOPE_SUITE_H_