Rename 'state' to 'scope'
This commit is contained in:
@@ -6,51 +6,51 @@
|
||||
#include "internal.h"
|
||||
#include "utility.h"
|
||||
#include "testing_helpers.h"
|
||||
#include "state.h"
|
||||
#include "scope.h"
|
||||
#include "builtins.h"
|
||||
#include "special.h"
|
||||
|
||||
static struct ucl_object *input;
|
||||
static struct ucl_object *response;
|
||||
static struct ucl_state *state;
|
||||
static struct ucl_scope *scope;
|
||||
|
||||
void setUp(void) {
|
||||
input = NULL;
|
||||
response = NULL;
|
||||
|
||||
state = ucl_state_create();
|
||||
ucl_state_put(state, "let", ucl_special_create(ucl_special_let));
|
||||
ucl_state_put(state, "defun", ucl_special_create(ucl_special_defun));
|
||||
ucl_state_put(state, "+", ucl_builtin_create(ucl_builtin_add));
|
||||
ucl_state_put(state, "error", ucl_builtin_create(ucl_builtin_error));
|
||||
ucl_state_put(state, "list", ucl_builtin_create(ucl_builtin_list));
|
||||
ucl_state_put(state, "setq", ucl_special_create(ucl_special_setq));
|
||||
ucl_state_put(state, "car", ucl_builtin_create(ucl_builtin_car));
|
||||
ucl_state_put(state, "cdr", ucl_builtin_create(ucl_builtin_cdr));
|
||||
ucl_state_put(state, "nth", ucl_builtin_create(ucl_builtin_nth));
|
||||
ucl_state_put(state, "mapcar", ucl_builtin_create(ucl_builtin_mapcar));
|
||||
ucl_state_put(state, "lambda", ucl_special_create(ucl_special_lambda));
|
||||
ucl_state_put(state, "quote", ucl_special_create(ucl_special_quote));
|
||||
scope = ucl_scope_create();
|
||||
ucl_scope_put(scope, "let", ucl_special_create(ucl_special_let));
|
||||
ucl_scope_put(scope, "defun", ucl_special_create(ucl_special_defun));
|
||||
ucl_scope_put(scope, "+", ucl_builtin_create(ucl_builtin_add));
|
||||
ucl_scope_put(scope, "error", ucl_builtin_create(ucl_builtin_error));
|
||||
ucl_scope_put(scope, "list", ucl_builtin_create(ucl_builtin_list));
|
||||
ucl_scope_put(scope, "setq", ucl_special_create(ucl_special_setq));
|
||||
ucl_scope_put(scope, "car", ucl_builtin_create(ucl_builtin_car));
|
||||
ucl_scope_put(scope, "cdr", ucl_builtin_create(ucl_builtin_cdr));
|
||||
ucl_scope_put(scope, "nth", ucl_builtin_create(ucl_builtin_nth));
|
||||
ucl_scope_put(scope, "mapcar", ucl_builtin_create(ucl_builtin_mapcar));
|
||||
ucl_scope_put(scope, "lambda", ucl_special_create(ucl_special_lambda));
|
||||
ucl_scope_put(scope, "quote", ucl_special_create(ucl_special_quote));
|
||||
}
|
||||
|
||||
void tearDown(void) {
|
||||
// TODO: Implement GC so we can clean these both up
|
||||
//ucl_object_delete(input);
|
||||
input = NULL;
|
||||
ucl_state_delete(state);
|
||||
ucl_scope_delete(scope);
|
||||
ucl_gc();
|
||||
response = NULL;
|
||||
state = NULL;
|
||||
scope = NULL;
|
||||
}
|
||||
|
||||
|
||||
static struct ucl_object *eval (const char *code) {
|
||||
struct ucl_object *sexp = ucl_parse(code);
|
||||
return ucl_evaluate(state, ucl_car(sexp));
|
||||
return ucl_evaluate(scope, ucl_car(sexp));
|
||||
}
|
||||
|
||||
void test_simple_add(void) {
|
||||
ucl_state_put(state, "+", ucl_builtin_create(ucl_builtin_add));
|
||||
ucl_scope_put(scope, "+", ucl_builtin_create(ucl_builtin_add));
|
||||
response = eval("(+ 2 3)");
|
||||
TEST_ASSERT_OBJ_INT(response);
|
||||
TEST_ASSERT_EQUAL(response->integer, 5);
|
||||
@@ -103,7 +103,7 @@ void test_eval_string(void) {
|
||||
}
|
||||
|
||||
void test_eval_sym_defined(void) {
|
||||
ucl_state_put(state, "foo", ucl_int_create(2));
|
||||
ucl_scope_put(scope, "foo", ucl_int_create(2));
|
||||
response = eval("foo");
|
||||
TEST_ASSERT_OBJ_INT(response);
|
||||
TEST_ASSERT_EQUAL(response->integer, 2);
|
||||
|
||||
Reference in New Issue
Block a user