Add primitive procedures to expression type
This commit is contained in:
@@ -7,6 +7,12 @@
|
||||
static am_t am;
|
||||
static store_t store;
|
||||
|
||||
void test_prim_proc(am_t *am, store_t *store)
|
||||
{
|
||||
(void)am;
|
||||
(void)store;
|
||||
}
|
||||
|
||||
void setUp(void)
|
||||
{
|
||||
am_init(&am);
|
||||
@@ -41,6 +47,18 @@ static void test_empty_list_self_evals(void)
|
||||
TEST_ASSERT_EQUAL(ATOM_TYPE_EMPTY_LIST, am.val->atom.type);
|
||||
}
|
||||
|
||||
static void test_prim_proc_self_evals(void)
|
||||
{
|
||||
am.expr = expr_prim_proc(&store, test_prim_proc);
|
||||
|
||||
eval(&am);
|
||||
|
||||
TEST_ASSERT_NOT_NULL(am.val);
|
||||
TEST_ASSERT_TRUE(am.val->is_atom);
|
||||
TEST_ASSERT_EQUAL(ATOM_TYPE_PRIM_PROC, am.val->atom.type);
|
||||
TEST_ASSERT_EQUAL(test_prim_proc, am.val->atom.prim_proc);
|
||||
}
|
||||
|
||||
static void test_foo_evals_to_42_when_set_in_env(void)
|
||||
{
|
||||
am.expr = expr_str_symbol(&store, "foo");
|
||||
@@ -61,6 +79,7 @@ int main(void)
|
||||
UNITY_BEGIN();
|
||||
RUN_TEST(test_42_self_evals);
|
||||
RUN_TEST(test_empty_list_self_evals);
|
||||
RUN_TEST(test_prim_proc_self_evals);
|
||||
RUN_TEST(test_foo_evals_to_42_when_set_in_env);
|
||||
return UNITY_END();
|
||||
}
|
||||
|
||||
@@ -1,9 +1,16 @@
|
||||
#include "am.h"
|
||||
#include "expr.h"
|
||||
#include "store.h"
|
||||
#include "unity.h"
|
||||
|
||||
static store_t store;
|
||||
|
||||
void test_prim_proc(am_t *am, store_t *store)
|
||||
{
|
||||
(void)am;
|
||||
(void)store;
|
||||
}
|
||||
|
||||
void setUp(void)
|
||||
{
|
||||
store_init(&store);
|
||||
@@ -92,6 +99,16 @@ static void test_expr_pair(void)
|
||||
TEST_ASSERT_EQUAL(cdr, expr->pair.cdr);
|
||||
}
|
||||
|
||||
static void test_expr_prim_proc(void)
|
||||
{
|
||||
|
||||
expr_t *expr = expr_prim_proc(&store, test_prim_proc);
|
||||
TEST_ASSERT_NOT_NULL(expr);
|
||||
TEST_ASSERT_TRUE(expr->is_atom);
|
||||
TEST_ASSERT_EQUAL(ATOM_TYPE_PRIM_PROC, expr->atom.type);
|
||||
TEST_ASSERT_EQUAL(test_prim_proc, expr->atom.prim_proc);
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
UNITY_BEGIN();
|
||||
@@ -103,5 +120,6 @@ int main(void)
|
||||
RUN_TEST(test_expr_str_symbol_quux);
|
||||
RUN_TEST(test_expr_empty_list);
|
||||
RUN_TEST(test_expr_pair);
|
||||
RUN_TEST(test_expr_prim_proc);
|
||||
return UNITY_END();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user