]> git.lizzy.rs Git - nothing.git/blobdiff - test/scope_suite.h
(#819) Recompile levels
[nothing.git] / test / scope_suite.h
index 79dc84306e59150a202a13ef68b62bc63037b547..eb4874aa7fa28b469f1e11042501e2d7dce7f907 100644 (file)
@@ -2,8 +2,8 @@
 #define SCOPE_SUITE_H_
 
 #include "test.h"
-#include "script/scope.h"
-#include "script/expr.h"
+#include "ebisp/scope.h"
+#include "ebisp/expr.h"
 
 TEST(set_scope_value_test)
 {
@@ -13,25 +13,32 @@ TEST(set_scope_value_test)
     struct Expr x = SYMBOL(gc, "x");
     struct Expr y = SYMBOL(gc, "y");
 
-    struct Scope initial_scope = {
-        .expr = list(gc, 2,
-                     list(gc, 2,
-                          CONS(gc, x, STRING(gc, "hello")),
-                          CONS(gc, y, STRING(gc, "world"))),
-                     NIL(gc))
+    struct Scope scope = {
+        .expr = CONS(gc, NIL(gc), NIL(gc))
     };
 
-    struct Expr expected_scope_expr =
-        list(gc, 2,
-             list(gc, 2,
-                  CONS(gc, x, STRING(gc, "hello")),
-                  CONS(gc, y, STRING(gc, "world"))),
-             list(gc, 1,
-                  CONS(gc, z, STRING(gc, "foo"))));
+    push_scope_frame(gc, &scope,
+                     list(gc, "ee", x, y),
+                     list(gc, "ss", "hello", "world"));
 
-    set_scope_value(gc, &initial_scope, z, STRING(gc, "foo"));
+    set_scope_value(gc, &scope, z, STRING(gc, "foo"));
+
+    ASSERT_TRUE(equal(CONS(gc, x, STRING(gc, "hello")), get_scope_value(&scope, x)),
+                { fprintf(stderr, "Unexpected value of `x`\n"); });
+    ASSERT_TRUE(equal(CONS(gc, y, STRING(gc, "world")), get_scope_value(&scope, y)),
+                { fprintf(stderr, "Unexpected value of `y`\n"); });
+    ASSERT_TRUE(equal(CONS(gc, z, STRING(gc, "foo")), get_scope_value(&scope, z)),
+                { fprintf(stderr, "Unexpected value of `z`\n"); });
+
+    pop_scope_frame(gc, &scope);
+
+    ASSERT_TRUE(equal(NIL(gc), get_scope_value(&scope, x)),
+                { fprintf(stderr, "Unexpected value of `x`\n"); });
+    ASSERT_TRUE(equal(NIL(gc), get_scope_value(&scope, y)),
+                { fprintf(stderr, "Unexpected value of `y`\n"); });
+    ASSERT_TRUE(equal(CONS(gc, z, STRING(gc, "foo")), get_scope_value(&scope, z)),
+                { fprintf(stderr, "Unexpected value of `z`\n"); });
 
-    ASSERT_TRUE(equal(expected_scope_expr, initial_scope.expr), "Unexpected scope");
 
     destroy_gc(gc);