Multiple implementations (JS, Wasm, C) of a Lisp.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

73 lines
1.8 KiB

#include "ptlisp-test.h"
#include "../src/lisp.h"
START_TEST(eval_nil_test) {
ck_assert_uint_eq(eval_fn(NIL, NIL), NIL);
}
END_TEST
START_TEST(eval_number_test) {
Pointer num = number(69);
3 years ago
ck_assert_uint_eq(eval(num, NIL), num);
ck_assert_double_eq(NUMBER(eval(num, NIL)), 69);
}
END_TEST
START_TEST(eval_addition_test) {
Pointer add_symbol = symbol("+", 1);
Pointer add_func = native_func(add_fn);
Pointer func_table = table(1);
func_table = table_set(func_table, add_symbol, add_func);
Pointer env = cons(func_table, NIL);
Pointer result = eval_fn(LIST(LIST(add_symbol, number(69), number(420))), env);
ck_assert_uint_ne(result, UNDEFINED);
ck_assert_double_eq(NUMBER(result), 489);
}
END_TEST
START_TEST(eval_arthimetic_test) {
Pointer add_symbol = symbol("+", 1);
Pointer sub_symbol = symbol("-", 1);
Pointer add_func = native_func(add_fn);
Pointer sub_func = native_func(sub_fn);
Pointer func_table = table(2);
table_set(func_table, add_symbol, add_func);
table_set(func_table, sub_symbol, sub_func);
Pointer env = cons(func_table, NIL);
Pointer result = eval_fn(LIST(LIST(add_symbol,
number(69),
number(420),
LIST(sub_symbol,
number(1337),
number(52)))),
env);
ck_assert_double_eq(NUMBER(result), 1774);
}
END_TEST
static void setup(void) {
memory_init(16);
symbol_init();
}
static void teardown(void) {
memory_free();
}
Suite* make_evaluator_test_suite(void) {
Suite *s1 = suite_create("Evaluator");
TCase *tc1_1 = tcase_create("Evaluator");
suite_add_tcase(s1, tc1_1);
tcase_add_checked_fixture(tc1_1, setup, teardown);
tcase_add_test(tc1_1, eval_nil_test);
tcase_add_test(tc1_1, eval_number_test);
tcase_add_test(tc1_1, eval_addition_test);
tcase_add_test(tc1_1, eval_arthimetic_test);
return s1;
}