]> git.lizzy.rs Git - nothing.git/blobdiff - test/scope_suite.h
Use stock python3 on CI
[nothing.git] / test / scope_suite.h
index 343af781783b4433a9b23772cd73c1d2c38454f0..95c3ce052b9cb26478b7f20cd6ede6d30fe3c800 100644 (file)
@@ -13,24 +13,32 @@ TEST(set_scope_value_test)
     struct Expr x = SYMBOL(gc, "x");
     struct Expr y = SYMBOL(gc, "y");
 
-    struct Expr initial_scope =
-        list(gc, 2,
-             list(gc, 2,
-                  CONS(gc, x, STRING(gc, "hello")),
-                  CONS(gc, y, STRING(gc, "world"))),
-             NIL(gc));
-
-    struct Expr expected_scope =
-        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"))));
-
-    struct Expr actual_scope = set_scope_value(gc, initial_scope, z, STRING(gc, "foo"));
-
-    ASSERT_TRUE(equal(expected_scope, actual_scope), "Unexpected scope");
+    struct Scope scope = {
+        .expr = CONS(gc, NIL(gc), NIL(gc))
+    };
+
+    push_scope_frame(gc, &scope,
+                     list(gc, 2, x, y),
+                     list(gc, 2, STRING(gc, "hello"), STRING(gc, "world")));
+
+    set_scope_value(gc, &scope, z, STRING(gc, "foo"));
+
+    ASSERT_TRUE(equal(CONS(gc, x, STRING(gc, "hello")), get_scope_value(&scope, x)),
+                "Unexpected value of `x`");
+    ASSERT_TRUE(equal(CONS(gc, y, STRING(gc, "world")), get_scope_value(&scope, y)),
+                "Unexpected value of `y`");
+    ASSERT_TRUE(equal(CONS(gc, z, STRING(gc, "foo")), get_scope_value(&scope, z)),
+                "Unexpected value of `z`");
+
+    pop_scope_frame(gc, &scope);
+
+    ASSERT_TRUE(equal(NIL(gc), get_scope_value(&scope, x)),
+                "Unexpected value of `x`");
+    ASSERT_TRUE(equal(NIL(gc), get_scope_value(&scope, y)),
+                "Unexpected value of `y`");
+    ASSERT_TRUE(equal(CONS(gc, z, STRING(gc, "foo")), get_scope_value(&scope, z)),
+                "Unexpected value of `z`");
+
 
     destroy_gc(gc);