Files
uclisp/test/test_utility.c

227 lines
4.8 KiB
C

#include <stdlib.h>
#include <unity.h>
#include <string.h>
#include "uclisp.h"
#include "internal.h"
#include "utility.h"
#include "testing_helpers.h"
static struct ucl_object *input;
static struct ucl_object *response;
void setUp(void) {
input = NULL;
response = NULL;
}
void tearDown(void) {
// TODO: Implement GC so we can clean these both up
//ucl_object_delete(input);
input = NULL;
ucl_object_delete(response);
response = NULL;
}
static void test_nil_create(void) {
response = ucl_nil_create();
TEST_ASSERT_NIL(response);
}
static void test_t_create(void) {
response = ucl_t_create();
TEST_ASSERT_T(response);
}
static void test_predicate_true(void) {
response = ucl_predicate(true);
TEST_ASSERT_T(response);
}
static void test_predicate_false(void) {
response = ucl_predicate(false);
TEST_ASSERT_NIL(response);
}
static void test_car_nil(void) {
response = ucl_car(ucl_nil_create());
TEST_ASSERT_NIL(response);
}
static void test_cdr_nil(void) {
response = ucl_cdr(ucl_nil_create());
TEST_ASSERT_NIL(response);
}
static void test_car_t(void) {
response = ucl_car(ucl_t_create());
TEST_ASSERT_OBJ_ERROR(response);
}
static void test_cdr_t(void) {
response = ucl_car(ucl_t_create());
TEST_ASSERT_OBJ_ERROR(response);
}
static void test_car_list(void) {
input = ucl_tuple_create(
ucl_string_create(strdup("foo")),
ucl_t_create());
response = ucl_car(input);
TEST_ASSERT_OBJ_STRING(response);
}
static void test_cdr_list(void) {
input = ucl_tuple_create(
ucl_t_create(),
ucl_string_create(strdup("foo")));
response = ucl_cdr(input);
TEST_ASSERT_OBJ_STRING(ucl_car(response));
}
static void test_list_length_nil() {
response = ucl_list_length(ucl_nil_create());
TEST_ASSERT_OBJ_INT(response);
TEST_ASSERT_EQUAL(response->integer, 0);
}
static void test_list_length_1() {
response = ucl_list_length(
ucl_cell_create(
ucl_t_create(), NULL));
TEST_ASSERT_OBJ_INT(response);
TEST_ASSERT_EQUAL(response->integer, 1);
}
static void test_list_length_2() {
response = ucl_list_length(
ucl_tuple_create(
ucl_t_create(),
ucl_t_create()));
TEST_ASSERT_OBJ_INT(response);
TEST_ASSERT_EQUAL(response->integer, 2);
}
static void test_list_append_nil() {
input = ucl_nil_create();
ucl_list_append(input, ucl_t_create());
TEST_ASSERT_EQUAL(ucl_list_length(input)->integer, 1);
}
static void test_list_append_list() {
input = ucl_tuple_create(ucl_t_create(), ucl_t_create());
ucl_list_append(input, ucl_t_create());
TEST_ASSERT_EQUAL(ucl_list_length(input)->integer, 3);
}
static void test_list_nth_nil_0() {
response = ucl_list_nth(ucl_nil_create(), 0);
TEST_ASSERT_OBJ_ERROR(response);
}
static void test_list_nth_nil_1() {
response = ucl_list_nth(ucl_nil_create(), 1);
TEST_ASSERT_OBJ_ERROR(response);
}
static void test_list_nth_list_0() {
response = ucl_list_nth(
ucl_tuple_create(
ucl_t_create(),
ucl_string_create(strdup("foo"))),
0);
TEST_ASSERT_T(response);
}
static void test_list_nth_list_1() {
response = ucl_list_nth(
ucl_tuple_create(
ucl_t_create(),
ucl_string_create(strdup("foo"))),
1);
TEST_ASSERT_OBJ_STRING(response);
}
static void test_list_nth_t_0() {
response = ucl_list_nth(ucl_t_create(), 1);
TEST_ASSERT_OBJ_ERROR(response);
}
static void test_list_nth_bounds_0() {
response = ucl_list_nth(ucl_nil_create(), 0);
TEST_ASSERT_OBJ_ERROR(response);
}
static void test_list_nth_bounds_1() {
response = ucl_list_nth(
ucl_cell_create(
ucl_nil_create(),
NULL),
1);
TEST_ASSERT_OBJ_ERROR(response);
}
static void test_list_nth_bounds_2() {
response = ucl_list_nth(
ucl_tuple_create(
ucl_nil_create(),
ucl_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);
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);
return UNITY_END();
}