Files
imp/tests/expr_tests.c

124 lines
3.1 KiB
C

#include "am.h"
#include "expr.h"
#include "unity.h"
static am_t am;
void test_prim_proc(am_t *am)
{
(void)am;
}
void setUp(void)
{
am_init(&am);
}
void tearDown(void)
{
}
static void test_expr_integer_123(void)
{
expr_t *expr = expr_integer(&am, 123);
TEST_ASSERT_NOT_NULL(expr);
TEST_ASSERT_TRUE(expr->is_atom);
TEST_ASSERT_EQUAL(ATOM_TYPE_INTEGER, expr->atom.type);
TEST_ASSERT_EQUAL(123, expr->atom.integer);
}
static void test_expr_integer_456(void)
{
expr_t *expr = expr_integer(&am, 456);
TEST_ASSERT_NOT_NULL(expr);
TEST_ASSERT_TRUE(expr->is_atom);
TEST_ASSERT_EQUAL(ATOM_TYPE_INTEGER, expr->atom.type);
TEST_ASSERT_EQUAL(456, expr->atom.integer);
}
static void test_expr_symbol_foo(void)
{
const symbol_t symbol = { .buf = "foo", .len = 3 };
expr_t *expr = expr_symbol(&am, &symbol);
TEST_ASSERT_NOT_NULL(expr);
TEST_ASSERT_TRUE(expr->is_atom);
TEST_ASSERT_EQUAL(ATOM_TYPE_SYMBOL, expr->atom.type);
TEST_ASSERT_EQUAL(3, expr->atom.symbol.len);
TEST_ASSERT_EQUAL_MEMORY("foo", expr->atom.symbol.buf, 3);
}
static void test_expr_symbol_quux(void)
{
const symbol_t symbol = { .buf = "quux", .len = 4 };
expr_t *expr = expr_symbol(&am, &symbol);
TEST_ASSERT_NOT_NULL(expr);
TEST_ASSERT_TRUE(expr->is_atom);
TEST_ASSERT_EQUAL(ATOM_TYPE_SYMBOL, expr->atom.type);
TEST_ASSERT_EQUAL(4, expr->atom.symbol.len);
TEST_ASSERT_EQUAL_MEMORY("quux", expr->atom.symbol.buf, 4);
}
static void test_expr_str_symbol_foo(void)
{
expr_t *expr = expr_str_symbol(&am, "foo");
TEST_ASSERT_NOT_NULL(expr);
TEST_ASSERT_TRUE(expr->is_atom);
TEST_ASSERT_EQUAL(ATOM_TYPE_SYMBOL, expr->atom.type);
TEST_ASSERT_EQUAL(3, expr->atom.symbol.len);
TEST_ASSERT_EQUAL_MEMORY("foo", expr->atom.symbol.buf, 3);
}
static void test_expr_str_symbol_quux(void)
{
expr_t *expr = expr_str_symbol(&am, "quux");
TEST_ASSERT_NOT_NULL(expr);
TEST_ASSERT_TRUE(expr->is_atom);
TEST_ASSERT_EQUAL(ATOM_TYPE_SYMBOL, expr->atom.type);
TEST_ASSERT_EQUAL(4, expr->atom.symbol.len);
TEST_ASSERT_EQUAL_MEMORY("quux", expr->atom.symbol.buf, 4);
}
static void test_expr_empty_list(void)
{
expr_t *expr = expr_empty_list(&am);
TEST_ASSERT_NOT_NULL(expr);
TEST_ASSERT_TRUE(expr->is_atom);
TEST_ASSERT_EQUAL(ATOM_TYPE_EMPTY_LIST, expr->atom.type);
}
static void test_expr_pair(void)
{
expr_t *car = expr_integer(&am, 123);
expr_t *cdr = expr_integer(&am, 456);
expr_t *expr = expr_pair(&am, car, cdr);
TEST_ASSERT_NOT_NULL(expr);
TEST_ASSERT_FALSE(expr->is_atom);
TEST_ASSERT_EQUAL(car, expr->pair.car);
TEST_ASSERT_EQUAL(cdr, expr->pair.cdr);
}
static void test_expr_prim_proc(void)
{
expr_t *expr = expr_prim_proc(&am, 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();
RUN_TEST(test_expr_integer_123);
RUN_TEST(test_expr_integer_456);
RUN_TEST(test_expr_symbol_foo);
RUN_TEST(test_expr_symbol_quux);
RUN_TEST(test_expr_str_symbol_foo);
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();
}