#include "am.h" #include "env.h" #include "eval.h" #include "store.h" #include "unity.h" 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); store_init(&store); env_init(&am, &store); } void tearDown(void) { } static void test_42_self_evals(void) { am.expr = expr_integer(&store, 42); eval(&am); TEST_ASSERT_NOT_NULL(am.val); TEST_ASSERT_TRUE(am.val->is_atom); TEST_ASSERT_EQUAL(ATOM_TYPE_INTEGER, am.val->atom.type); TEST_ASSERT_EQUAL(42, am.val->atom.integer); } static void test_empty_list_self_evals(void) { am.expr = expr_empty_list(&store); eval(&am); TEST_ASSERT_NOT_NULL(am.val); TEST_ASSERT_TRUE(am.val->is_atom); 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"); am.val = expr_integer(&store, 42); env_set(&am, &store); am.val = NULL; eval(&am); TEST_ASSERT_NOT_NULL(am.val); TEST_ASSERT_TRUE(am.val->is_atom); TEST_ASSERT_EQUAL(ATOM_TYPE_INTEGER, am.val->atom.type); TEST_ASSERT_EQUAL(42, am.val->atom.integer); } 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(); }