267 lines
5.9 KiB
C
267 lines
5.9 KiB
C
#include <stdlib.h>
|
|
#include <unity.h>
|
|
#include <string.h>
|
|
|
|
#include "testing_helpers.h"
|
|
|
|
#include "uclisp.h"
|
|
#include "common.h"
|
|
|
|
static struct ucl *state;
|
|
static struct ucl_object *input;
|
|
static struct ucl_object *response;
|
|
|
|
void setUp(void) {
|
|
state = ucl_create();
|
|
input = NULL;
|
|
response = NULL;
|
|
}
|
|
|
|
void tearDown(void) {
|
|
// TODO: Release memory
|
|
state = NULL;
|
|
input = NULL;
|
|
response = NULL;
|
|
}
|
|
|
|
static void test_nil_create(void) {
|
|
response = ucl_nil_create(state);
|
|
|
|
TEST_ASSERT_NIL(response);
|
|
}
|
|
|
|
static void test_t_create(void) {
|
|
response = ucl_t_create(state);
|
|
|
|
TEST_ASSERT_T(response);
|
|
}
|
|
|
|
static void test_predicate_true(void) {
|
|
response = ucl_predicate(state, true);
|
|
|
|
TEST_ASSERT_T(response);
|
|
}
|
|
|
|
static void test_predicate_false(void) {
|
|
response = ucl_predicate(state, false);
|
|
|
|
TEST_ASSERT_NIL(response);
|
|
}
|
|
|
|
static void test_car_nil(void) {
|
|
response = ucl_car(state, ucl_nil_create(state));
|
|
|
|
TEST_ASSERT_NIL(response);
|
|
}
|
|
|
|
static void test_cdr_nil(void) {
|
|
response = ucl_cdr(state, ucl_nil_create(state));
|
|
|
|
TEST_ASSERT_NIL(response);
|
|
}
|
|
|
|
static void test_car_t(void) {
|
|
response = ucl_car(state, ucl_t_create(state));
|
|
|
|
TEST_ASSERT_OBJ_ERROR(response);
|
|
}
|
|
|
|
static void test_cdr_t(void) {
|
|
response = ucl_car(state, ucl_t_create(state));
|
|
|
|
TEST_ASSERT_OBJ_ERROR(response);
|
|
}
|
|
|
|
static void test_car_list(void) {
|
|
input = ucl_tuple_create(state,
|
|
ucl_string_create(state, "foo"),
|
|
ucl_t_create(state));
|
|
response = ucl_car(state, input);
|
|
|
|
TEST_ASSERT_OBJ_STRING(response);
|
|
}
|
|
|
|
static void test_cdr_list(void) {
|
|
input = ucl_tuple_create(state,
|
|
ucl_t_create(state),
|
|
ucl_string_create(state, "foo"));
|
|
response = ucl_cdr(state, input);
|
|
|
|
TEST_ASSERT_OBJ_STRING(ucl_car(state, response));
|
|
}
|
|
|
|
static void test_list_length_nil() {
|
|
response = ucl_list_length(state, ucl_nil_create(state));
|
|
|
|
TEST_ASSERT_OBJ_INT(response);
|
|
TEST_ASSERT_EQUAL(response->integer, 0);
|
|
}
|
|
|
|
static void test_list_length_1() {
|
|
response = ucl_list_length(
|
|
state,
|
|
ucl_cell_create(state,
|
|
ucl_t_create(state), NULL));
|
|
|
|
TEST_ASSERT_OBJ_INT(response);
|
|
TEST_ASSERT_EQUAL(response->integer, 1);
|
|
}
|
|
|
|
static void test_list_length_2() {
|
|
response = ucl_list_length(
|
|
state,
|
|
ucl_tuple_create(state,
|
|
ucl_t_create(state),
|
|
ucl_t_create(state)));
|
|
|
|
TEST_ASSERT_OBJ_INT(response);
|
|
TEST_ASSERT_EQUAL(response->integer, 2);
|
|
}
|
|
|
|
|
|
static void test_list_append_nil() {
|
|
input = ucl_nil_create(state);
|
|
ucl_list_append(state, input, ucl_t_create(state));
|
|
|
|
TEST_ASSERT_EQUAL(ucl_list_length(state, input)->integer, 1);
|
|
}
|
|
|
|
static void test_list_append_list() {
|
|
input = ucl_tuple_create(state, ucl_t_create(state), ucl_t_create(state));
|
|
ucl_list_append(state, input, ucl_t_create(state));
|
|
|
|
TEST_ASSERT_EQUAL(ucl_list_length(state, input)->integer, 3);
|
|
}
|
|
|
|
static void test_list_nth_nil_0() {
|
|
response = ucl_list_nth(ucl_nil_create(state), 0);
|
|
|
|
TEST_ASSERT_OBJ_ERROR(response);
|
|
}
|
|
|
|
static void test_list_nth_nil_1() {
|
|
response = ucl_list_nth(ucl_nil_create(state), 1);
|
|
|
|
TEST_ASSERT_OBJ_ERROR(response);
|
|
}
|
|
|
|
static void test_list_nth_list_0() {
|
|
response = ucl_list_nth(
|
|
ucl_tuple_create(state,
|
|
ucl_t_create(state),
|
|
ucl_string_create(state, "foo")),
|
|
0);
|
|
|
|
TEST_ASSERT_T(response);
|
|
}
|
|
|
|
static void test_list_nth_list_1() {
|
|
response = ucl_list_nth(
|
|
ucl_tuple_create(state,
|
|
ucl_t_create(state),
|
|
ucl_string_create(state, "foo")),
|
|
1);
|
|
|
|
TEST_ASSERT_OBJ_STRING(response);
|
|
}
|
|
|
|
static void test_list_nth_t_0() {
|
|
response = ucl_list_nth(ucl_t_create(state), 1);
|
|
|
|
TEST_ASSERT_OBJ_ERROR(response);
|
|
}
|
|
|
|
static void test_list_nth_bounds_0() {
|
|
response = ucl_list_nth(ucl_nil_create(state), 0);
|
|
|
|
TEST_ASSERT_OBJ_ERROR(response);
|
|
}
|
|
|
|
static void test_list_nth_bounds_1() {
|
|
response = ucl_list_nth(
|
|
ucl_cell_create(state,
|
|
ucl_nil_create(state),
|
|
NULL),
|
|
1);
|
|
|
|
TEST_ASSERT_OBJ_ERROR(response);
|
|
}
|
|
|
|
static void test_list_nth_bounds_2() {
|
|
response = ucl_list_nth(
|
|
ucl_tuple_create(state,
|
|
ucl_nil_create(state),
|
|
ucl_nil_create(state)),
|
|
2);
|
|
|
|
TEST_ASSERT_OBJ_ERROR(response);
|
|
}
|
|
|
|
static void test_truthy_0() {
|
|
response = ucl_truthy(state, ucl_int_create(state, 0));
|
|
|
|
TEST_ASSERT_NIL(response);
|
|
}
|
|
|
|
static void test_truthy_1() {
|
|
response = ucl_truthy(state, ucl_int_create(state, 1));
|
|
|
|
TEST_ASSERT_T(response);
|
|
}
|
|
|
|
static void test_truthy_nil() {
|
|
response = ucl_truthy(state, ucl_nil_create(state));
|
|
|
|
TEST_ASSERT_NIL(response);
|
|
}
|
|
|
|
static void test_truthy_list_w_elem() {
|
|
struct ucl_object *list = ucl_nil_create(state);
|
|
ucl_list_append(state, list, ucl_int_create(state, 0));
|
|
response = ucl_truthy(state, list);
|
|
|
|
TEST_ASSERT_T(response);
|
|
}
|
|
|
|
static void test_truthy_sym() {
|
|
response = ucl_truthy(state, ucl_symbol_create(state, "t"));
|
|
|
|
TEST_ASSERT_T(response);
|
|
}
|
|
|
|
|
|
int main(void) {
|
|
UNITY_BEGIN();
|
|
|
|
RUN_TEST(test_nil_create);
|
|
RUN_TEST(test_t_create);
|
|
RUN_TEST(test_predicate_true);
|
|
RUN_TEST(test_predicate_false);
|
|
RUN_TEST(test_car_nil);
|
|
RUN_TEST(test_cdr_nil);
|
|
RUN_TEST(test_car_t);
|
|
RUN_TEST(test_cdr_t);
|
|
RUN_TEST(test_car_list);
|
|
RUN_TEST(test_cdr_list);
|
|
RUN_TEST(test_list_length_nil);
|
|
RUN_TEST(test_list_length_1);
|
|
RUN_TEST(test_list_length_2);
|
|
RUN_TEST(test_list_append_nil);
|
|
RUN_TEST(test_list_append_list);
|
|
RUN_TEST(test_list_nth_nil_0);
|
|
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);
|
|
RUN_TEST(test_truthy_0);
|
|
RUN_TEST(test_truthy_1);
|
|
RUN_TEST(test_truthy_nil);
|
|
RUN_TEST(test_truthy_list_w_elem);
|
|
RUN_TEST(test_truthy_sym);
|
|
|
|
return UNITY_END();
|
|
}
|