]> git.lizzy.rs Git - nothing.git/blob - test/scope_suite.h
(#427) Fix svg2rects failure on newlines in labels
[nothing.git] / test / scope_suite.h
1 #ifndef SCOPE_SUITE_H_
2 #define SCOPE_SUITE_H_
3
4 #include "test.h"
5 #include "script/scope.h"
6 #include "script/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, 2, x, y),
22                      list(gc, 2, STRING(gc, "hello"), STRING(gc, "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                 "Unexpected value of `x`");
28     ASSERT_TRUE(equal(CONS(gc, y, STRING(gc, "world")), get_scope_value(&scope, y)),
29                 "Unexpected value of `y`");
30     ASSERT_TRUE(equal(CONS(gc, z, STRING(gc, "foo")), get_scope_value(&scope, z)),
31                 "Unexpected value of `z`");
32
33     pop_scope_frame(gc, &scope);
34
35     ASSERT_TRUE(equal(NIL(gc), get_scope_value(&scope, x)),
36                 "Unexpected value of `x`");
37     ASSERT_TRUE(equal(NIL(gc), get_scope_value(&scope, y)),
38                 "Unexpected value of `y`");
39     ASSERT_TRUE(equal(CONS(gc, z, STRING(gc, "foo")), get_scope_value(&scope, z)),
40                 "Unexpected value of `z`");
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_