#include "env.h" #include "unity.h" #include static am_t am; static store_t store; void setUp(void) { am_init(&am); store_init(&store); env_init(&am, &store); } void tearDown(void) { } static void test_set_foo_to_42_then_fetch(void) { am.expr = expr_str_symbol(&store, "foo"); am.val = expr_integer(&store, 42); env_set(&am, &store); am.expr = expr_str_symbol(&store, "foo"); am.val = NULL; env_fetch(&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_update_foo_from_123_to_456_then_fetch(void) { am.expr = expr_str_symbol(&store, "foo"); am.val = expr_integer(&store, 123); env_set(&am, &store); am.val = expr_integer(&store, 456); env_set(&am, &store); am.expr = expr_str_symbol(&store, "foo"); am.val = NULL; env_fetch(&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(456, am.val->atom.integer); } int main(void) { UNITY_BEGIN(); RUN_TEST(test_set_foo_to_42_then_fetch); RUN_TEST(test_update_foo_from_123_to_456_then_fetch); return UNITY_END(); }