Files
imp/tests/env_tests.c

58 lines
1.2 KiB
C

#include "env.h"
#include "unity.h"
#include <string.h>
static am_t am;
void setUp(void)
{
am_init(&am);
}
void tearDown(void)
{
}
static void test_set_foo_to_42_then_fetch(void)
{
am.regs[EXPR] = expr_str_symbol(&am, "foo");
am.regs[VAL] = expr_integer(&am, 42);
env_set(&am);
am.regs[EXPR] = expr_str_symbol(&am, "foo");
am.regs[VAL] = NULL;
env_fetch(&am);
TEST_ASSERT_NOT_NULL(am.regs[VAL]);
TEST_ASSERT_TRUE(am.regs[VAL]->is_atom);
TEST_ASSERT_EQUAL(ATOM_TYPE_INTEGER, am.regs[VAL]->atom.type);
TEST_ASSERT_EQUAL(42, am.regs[VAL]->atom.integer);
}
static void test_update_foo_from_123_to_456_then_fetch(void)
{
am.regs[EXPR] = expr_str_symbol(&am, "foo");
am.regs[VAL] = expr_integer(&am, 123);
env_set(&am);
am.regs[VAL] = expr_integer(&am, 456);
env_set(&am);
am.regs[EXPR] = expr_str_symbol(&am, "foo");
am.regs[VAL] = NULL;
env_fetch(&am);
TEST_ASSERT_NOT_NULL(am.regs[VAL]);
TEST_ASSERT_TRUE(am.regs[VAL]->is_atom);
TEST_ASSERT_EQUAL(ATOM_TYPE_INTEGER, am.regs[VAL]->atom.type);
TEST_ASSERT_EQUAL(456, am.regs[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();
}