Implement atom evaluation

This commit is contained in:
2025-08-10 13:55:20 +01:00
parent 03bd0ff597
commit 3f871d2b43
5 changed files with 95 additions and 0 deletions

View File

@@ -11,6 +11,7 @@ endfunction()
add_test_suites(
am_tests.c
env_tests.c
eval_tests.c
expr_tests.c
parse_tests.c
store_tests.c

66
tests/eval_tests.c Normal file
View File

@@ -0,0 +1,66 @@
#include "am.h"
#include "env.h"
#include "eval.h"
#include "store.h"
#include "unity.h"
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_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_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_foo_evals_to_42_when_set_in_env);
return UNITY_END();
}