Files
imp/tests/am_tests.c

67 lines
1.3 KiB
C

#include "am.h"
#include "unity.h"
#define CAR(expr) (expr->pair.car)
#define CDR(expr) (expr->pair.cdr)
static am_t am;
void setUp(void)
{
am_init(&am);
}
void tearDown(void)
{
}
static void test_expr_value_restored_after_push_modify_pop(void)
{
expr_t a, b;
am.regs[EXPR] = &a;
am_push(&am, EXPR);
am.regs[EXPR] = &b;
am_pop(&am, EXPR);
TEST_ASSERT_EQUAL(&a, am.regs[EXPR]);
}
static void test_argl_value_restored_after_push_modify_pop(void)
{
expr_t a, b;
am.regs[ARGL] = &a;
am_push(&am, ARGL);
am.regs[ARGL] = &b;
am_pop(&am, ARGL);
TEST_ASSERT_EQUAL(&a, am.regs[ARGL]);
}
static void test_append_arg_42_with_empty_argl(void)
{
am.regs[ARGL] = expr_empty_list(&am);
am.regs[VAL] = expr_integer(&am, 42);
am_append_arg(&am);
TEST_ASSERT_FALSE(am.regs[ARGL]->is_atom);
TEST_ASSERT_NOT_NULL(CAR(am.regs[ARGL]));
TEST_ASSERT_TRUE(CAR(am.regs[ARGL])->is_atom);
TEST_ASSERT_EQUAL(ATOM_TYPE_INTEGER, CAR(am.regs[ARGL])->atom.type);
TEST_ASSERT_EQUAL(42, CAR(am.regs[ARGL])->atom.integer);
TEST_ASSERT_TRUE(CDR(am.regs[ARGL])->is_atom);
TEST_ASSERT_EQUAL(ATOM_TYPE_EMPTY_LIST, CDR(am.regs[ARGL])->atom.type);
}
int main(void)
{
UNITY_BEGIN();
RUN_TEST(test_expr_value_restored_after_push_modify_pop);
RUN_TEST(test_argl_value_restored_after_push_modify_pop);
RUN_TEST(test_append_arg_42_with_empty_argl);
return UNITY_END();
}