Add error types and simple state

This commit is contained in:
2022-10-28 16:08:40 -04:00
parent fd91e66b8a
commit ed173bd17a
14 changed files with 302 additions and 89 deletions

View File

@@ -5,38 +5,11 @@
#include "nihilispm.h"
#include "nihilispm_internal.h"
#include "nihilispm_utility.h"
#include "testing_helpers.h"
static struct nl_object *input;
static struct nl_object *response;
#define TEST_ASSERT_OBJ_SYMBOL(obj) \
TEST_ASSERT_EQUAL(obj->type, NL_TYPE_SYMBOL)
#define TEST_ASSERT_OBJ_STRING(obj) \
TEST_ASSERT_EQUAL(obj->type, NL_TYPE_STRING)
#define TEST_ASSERT_OBJ_INT(obj) \
TEST_ASSERT_EQUAL(obj->type, NL_TYPE_INT)
#define TEST_ASSERT_OBJ_LIST(obj) \
TEST_ASSERT_EQUAL(obj->type, NL_TYPE_CELL)
#define TEST_ASSERT_LIST_LEN(list, len) \
do { \
TEST_ASSERT_OBJ_LIST(list); \
TEST_ASSERT_EQUAL(nl_list_length(list)->integer, len); \
} while(0)
#define TEST_ASSERT_NIL(obj) \
TEST_ASSERT_LIST_LEN(obj, 0)
#define TEST_ASSERT_T(obj) \
do { \
TEST_ASSERT_OBJ_SYMBOL(obj); \
TEST_ASSERT_EQUAL_STRING(obj->symbol, "t"); \
} while(0)
void setUp(void) {
input = NULL;
response = NULL;
@@ -89,13 +62,13 @@ static void test_cdr_nil(void) {
static void test_car_t(void) {
response = nl_car(nl_t_create());
TEST_ASSERT_NULL(response);
TEST_ASSERT_OBJ_ERROR(response);
}
static void test_cdr_t(void) {
response = nl_car(nl_t_create());
TEST_ASSERT_NULL(response);
TEST_ASSERT_OBJ_ERROR(response);
}
static void test_car_list(void) {
@@ -160,13 +133,13 @@ static void test_list_append_list() {
static void test_list_nth_nil_0() {
response = nl_list_nth(nl_nil_create(), 0);
TEST_ASSERT_NULL(response);
TEST_ASSERT_OBJ_ERROR(response);
}
static void test_list_nth_nil_1() {
response = nl_list_nth(nl_nil_create(), 1);
TEST_ASSERT_NULL(response);
TEST_ASSERT_OBJ_ERROR(response);
}
static void test_list_nth_list_0() {
@@ -189,9 +162,42 @@ static void test_list_nth_list_1() {
TEST_ASSERT_OBJ_STRING(response);
}
static void test_list_nth_t_0() {
response = nl_list_nth(nl_t_create(), 1);
TEST_ASSERT_OBJ_ERROR(response);
}
static void test_list_nth_bounds_0() {
response = nl_list_nth(nl_nil_create(), 0);
TEST_ASSERT_OBJ_ERROR(response);
}
static void test_list_nth_bounds_1() {
response = nl_list_nth(
nl_cell_create(
nl_nil_create(),
NULL),
1);
TEST_ASSERT_OBJ_ERROR(response);
}
static void test_list_nth_bounds_2() {
response = nl_list_nth(
nl_tuple_create(
nl_nil_create(),
nl_nil_create()),
2);
TEST_ASSERT_OBJ_ERROR(response);
}
int main(void) {
UNITY_BEGIN();
RUN_TEST(test_nil_create);
RUN_TEST(test_t_create);
RUN_TEST(test_predicate_true);
@@ -211,5 +217,10 @@ int main(void) {
RUN_TEST(test_list_nth_nil_1);
RUN_TEST(test_list_nth_list_0);
RUN_TEST(test_list_nth_list_1);
RUN_TEST(test_list_nth_t_0);
RUN_TEST(test_list_nth_bounds_0);
RUN_TEST(test_list_nth_bounds_1);
RUN_TEST(test_list_nth_bounds_2);
return UNITY_END();
}