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.
 
 
 
 
 

61 lines
1.9 KiB

#include "ptlisp-test.h"
static Pointer STANDARD_OUTPUT_STREAM;
static char buffer[255];
START_TEST(print_fn_test) {
Pointer list = LIST(number(1), number(2), number(69.420));
Pointer result = print_fn(LIST(list, STANDARD_OUTPUT_STREAM), NIL);
ck_assert_str_eq(buffer, "\n(1 2 69.42) ");
ck_assert_uint_eq(list, result);
rewind(STREAM(STANDARD_OUTPUT_STREAM));
list = LIST(number(1), number(2), LIST(number(3), number(4)));
result = print_fn(LIST(list, STANDARD_OUTPUT_STREAM), NIL);
ck_assert_str_eq(buffer, "\n(1 2 (3 4)) ");
ck_assert_uint_eq(list, result);
rewind(STREAM(STANDARD_OUTPUT_STREAM));
Pointer tbl = table(4);
Pointer a = symbol("a", sizeof("a"));
Pointer b = symbol("b", sizeof("b"));
Pointer c = symbol("c", sizeof("c"));
Pointer d = symbol("d", sizeof("d"));
tbl = table_set(tbl, a, number(1));
tbl = table_set(tbl, b, number(2));
tbl = table_set(tbl, c, number(3));
tbl = table_set(tbl, d, number(4));
result = print_fn(LIST(tbl, STANDARD_OUTPUT_STREAM), NIL);
ck_assert_str_eq(buffer, "\n{c: 3, a: 1, d: 4, b: 2} ");
rewind(STREAM(STANDARD_OUTPUT_STREAM));
result = print_fn(LIST(character('a'), STANDARD_OUTPUT_STREAM), NIL);
fprintf(STREAM(STANDARD_OUTPUT_STREAM), "%c", '\0');
fflush(STREAM(STANDARD_OUTPUT_STREAM));
ck_assert_str_eq(buffer, "\n\\a ");
rewind(STREAM(STANDARD_OUTPUT_STREAM));
} END_TEST
static void setup(void) {
memory_init(16);
symbol_init();
reader_init();
environment_init();
STANDARD_OUTPUT_STREAM = stream(fmemopen(buffer, sizeof(buffer), "w+"));
environment_set(NIL, STANDARD_OUTPUT, STANDARD_OUTPUT_STREAM);
}
static void teardown(void) {
fclose(STREAM(STANDARD_OUTPUT_STREAM));
memory_free();
}
Suite* make_printer_test_suite(void) {
Suite *s1 = suite_create("Printer");
TCase *tc1_1 = tcase_create("Printer");
suite_add_tcase(s1, tc1_1);
tcase_add_checked_fixture(tc1_1, setup, teardown);
tcase_add_test(tc1_1, print_fn_test);
return s1;
}