Consolidate expression creation functions in expr module
This commit is contained in:
@@ -6,24 +6,6 @@
|
||||
static am_t am;
|
||||
static store_t store;
|
||||
|
||||
static expr_t *integer(int64_t value)
|
||||
{
|
||||
expr_t *expr = store_alloc(&store);
|
||||
expr->is_atom = true;
|
||||
expr->atom.type = ATOM_TYPE_INTEGER;
|
||||
expr->atom.integer = value;
|
||||
return expr;
|
||||
}
|
||||
|
||||
static expr_t *symbol(const char *s)
|
||||
{
|
||||
expr_t *expr = store_alloc(&store);
|
||||
expr->is_atom = true;
|
||||
expr->atom.type = ATOM_TYPE_SYMBOL;
|
||||
memcpy(expr->atom.symbol.buf, s, strlen(s));
|
||||
return expr;
|
||||
}
|
||||
|
||||
void setUp(void)
|
||||
{
|
||||
am_init(&am);
|
||||
@@ -37,11 +19,11 @@ void tearDown(void)
|
||||
|
||||
static void test_set_foo_to_42_then_fetch(void)
|
||||
{
|
||||
am.expr = symbol("foo");
|
||||
am.val = integer(42);
|
||||
am.expr = expr_str_symbol(&store, "foo");
|
||||
am.val = expr_integer(&store, 42);
|
||||
env_set(&am, &store);
|
||||
|
||||
am.expr = symbol("foo");
|
||||
am.expr = expr_str_symbol(&store, "foo");
|
||||
am.val = NULL;
|
||||
env_fetch(&am);
|
||||
|
||||
@@ -53,13 +35,13 @@ static void test_set_foo_to_42_then_fetch(void)
|
||||
|
||||
static void test_update_foo_from_123_to_456_then_fetch(void)
|
||||
{
|
||||
am.expr = symbol("foo");
|
||||
am.val = integer(123);
|
||||
am.expr = expr_str_symbol(&store, "foo");
|
||||
am.val = expr_integer(&store, 123);
|
||||
env_set(&am, &store);
|
||||
am.val = integer(456);
|
||||
am.val = expr_integer(&store, 456);
|
||||
env_set(&am, &store);
|
||||
|
||||
am.expr = symbol("foo");
|
||||
am.expr = expr_str_symbol(&store, "foo");
|
||||
am.val = NULL;
|
||||
env_fetch(&am);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user