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.

95 lines
2.4 KiB

#include "ptlisp-test.h"
#include "../src/lisp.h"
START_TEST(array_create_test) {
Pointer arr = array(1);
ck_assert_uint_eq(ARRAY(arr).length, 0);
ck_assert_uint_eq(ARRAY(arr).size, 1);
}
END_TEST
START_TEST(array_new_empty_test) {
Pointer arr = array(0);
ck_assert_uint_eq(ARRAY(arr).length, 0);
ck_assert_uint_eq(ARRAY(arr).size, 0);
}
END_TEST
START_TEST(array_push_test) {
Pointer arr = array(1);
arr = array_push(arr, 69);
ck_assert_uint_eq(ARRAY(arr).length, 1);
ck_assert_uint_eq(ARRAY(arr).size, 1);
ck_assert_uint_eq(ARRAY(arr).data[0], 69);
arr = array_push(arr, 420);
ck_assert_uint_eq(ARRAY(arr).length, 2);
ck_assert_uint_eq(ARRAY(arr).size, 2);
ck_assert_uint_eq(ARRAY(arr).data[0], 69);
ck_assert_uint_eq(ARRAY(arr).data[1], 420);
}
END_TEST
START_TEST(array_pop_test) {
Pointer arr = array(1);
ck_assert_uint_eq(array_pop(arr), NIL);
array_push(arr, 69);
ck_assert_uint_eq(ARRAY(arr).data[0], 69);
ck_assert_uint_eq(array_pop(arr), 69);
ck_assert_uint_eq(ARRAY(arr).length, 0);
}
END_TEST
START_TEST(array_set_test) {
Pointer arr = array(1);
arr = array_set(arr, 0, 69);
arr = array_set(arr, 8, 420);
ck_assert_uint_eq(ARRAY(arr).data[0], 69);
ck_assert_uint_eq(ARRAY(arr).data[2], UNDEFINED);
ck_assert_uint_eq(ARRAY(arr).data[8], 420);
ck_assert_uint_eq(ARRAY(arr).length, 9);
ck_assert_uint_eq(ARRAY(arr).size, 16);
}
END_TEST
START_TEST(array_get_test) {
Pointer arr = array(1);
arr = array_push(arr, 69);
ck_assert_uint_eq(array_get(arr, 0), 69);
ck_assert_uint_eq(array_get(arr, 9), UNDEFINED);
}
END_TEST
START_TEST(array_length_test) {
Pointer arr = array(1);
ck_assert_uint_eq(array_length(arr), 0);
arr = array_push(arr, 69u);
ck_assert_uint_eq(array_length(arr), 1);
}
END_TEST
static void setup(void) {
memory_init(16);
}
static void teardown(void) {
memory_free();
}
Suite* make_array_test_suite(void) {
Suite *s1 = suite_create("Array");
TCase *tc1_1 = tcase_create("Array");
suite_add_tcase(s1, tc1_1);
tcase_add_checked_fixture(tc1_1, setup, teardown);
tcase_add_test(tc1_1, array_create_test);
tcase_add_test(tc1_1, array_new_empty_test);
tcase_add_test(tc1_1, array_push_test);
tcase_add_test(tc1_1, array_pop_test);
tcase_add_test(tc1_1, array_set_test);
tcase_add_test(tc1_1, array_get_test);
tcase_add_test(tc1_1, array_length_test);
return s1;
}