Refactor with new name uclisp

This commit is contained in:
2022-10-28 23:19:19 -04:00
parent 26a0d17074
commit d97be8ec4b
22 changed files with 596 additions and 580 deletions

View File

@@ -2,25 +2,25 @@
#include <unity.h>
#include <string.h>
#include "nihilispm.h"
#include "nihilispm_internal.h"
#include "uclisp.h"
#include "internal.h"
/* static struct nl_parse_result *result; */
static struct nl_object *response;
/* static struct ucl_parse_result *result; */
static struct ucl_object *response;
void setUp(void) {
response = NULL;
}
void tearDown(void) {
nl_object_delete(response);
ucl_object_delete(response);
}
static void test_token_next_empty_str(void) {
const char *input = "";
const char *curr = input;
response = nl_token_next(&curr);
response = ucl_token_next(&curr);
TEST_ASSERT_NULL(response);
TEST_ASSERT_EQUAL('\0', *curr);
@@ -30,7 +30,7 @@ static void test_token_next_only_whitespace(void) {
const char *input = " \n";
const char *curr = input;
response = nl_token_next(&curr);
response = ucl_token_next(&curr);
TEST_ASSERT_NULL(response);
TEST_ASSERT_EQUAL('\0', *curr);
@@ -40,11 +40,11 @@ static void test_token_next_lparen(void) {
const char *input = "(";
const char *curr = input;
response = nl_token_next(&curr);
response = ucl_token_next(&curr);
TEST_ASSERT_NOT_NULL(response);
TEST_ASSERT_EQUAL(NL_TYPE_CELL, response->type);
TEST_ASSERT_EQUAL(NL_TYPE_SYMBOL, response->cell.car->type);
TEST_ASSERT_EQUAL(UCL_TYPE_CELL, response->type);
TEST_ASSERT_EQUAL(UCL_TYPE_SYMBOL, response->cell.car->type);
TEST_ASSERT_EQUAL_STRING("(", response->cell.car->string);
TEST_ASSERT_EQUAL('\0', *curr);
}
@@ -53,11 +53,11 @@ static void test_token_next_rparen(void) {
const char *input = ")";
const char *curr = input;
response = nl_token_next(&curr);
response = ucl_token_next(&curr);
TEST_ASSERT_NOT_NULL(response);
TEST_ASSERT_EQUAL(NL_TYPE_CELL, response->type);
TEST_ASSERT_EQUAL(NL_TYPE_SYMBOL, response->cell.car->type);
TEST_ASSERT_EQUAL(UCL_TYPE_CELL, response->type);
TEST_ASSERT_EQUAL(UCL_TYPE_SYMBOL, response->cell.car->type);
TEST_ASSERT_EQUAL_STRING(")", response->cell.car->string);
TEST_ASSERT_EQUAL('\0', *curr);
}
@@ -66,20 +66,20 @@ static void test_token_next_lrparen(void) {
const char *input = "()";
const char *curr = input;
response = nl_token_next(&curr);
response = ucl_token_next(&curr);
TEST_ASSERT_NOT_NULL(response);
TEST_ASSERT_EQUAL(NL_TYPE_CELL, response->type);
TEST_ASSERT_EQUAL(NL_TYPE_SYMBOL, response->cell.car->type);
TEST_ASSERT_EQUAL(UCL_TYPE_CELL, response->type);
TEST_ASSERT_EQUAL(UCL_TYPE_SYMBOL, response->cell.car->type);
TEST_ASSERT_EQUAL_STRING("(", response->cell.car->string);
TEST_ASSERT_EQUAL(')', *curr);
nl_object_delete(response);
response = nl_token_next(&curr);
ucl_object_delete(response);
response = ucl_token_next(&curr);
TEST_ASSERT_NOT_NULL(response);
TEST_ASSERT_EQUAL(NL_TYPE_CELL, response->type);
TEST_ASSERT_EQUAL(NL_TYPE_SYMBOL, response->cell.car->type);
TEST_ASSERT_EQUAL(UCL_TYPE_CELL, response->type);
TEST_ASSERT_EQUAL(UCL_TYPE_SYMBOL, response->cell.car->type);
TEST_ASSERT_EQUAL_STRING(")", response->cell.car->string);
TEST_ASSERT_EQUAL('\0', *curr);
}
@@ -88,11 +88,11 @@ static void test_token_next_string(void) {
const char *input = "\"foo\"";
const char *curr = input;
response = nl_token_next(&curr);
response = ucl_token_next(&curr);
TEST_ASSERT_NOT_NULL(response);
TEST_ASSERT_EQUAL(NL_TYPE_CELL, response->type);
TEST_ASSERT_EQUAL(NL_TYPE_STRING, response->cell.car->type);
TEST_ASSERT_EQUAL(UCL_TYPE_CELL, response->type);
TEST_ASSERT_EQUAL(UCL_TYPE_STRING, response->cell.car->type);
TEST_ASSERT_EQUAL_STRING("foo", response->cell.car->string);
TEST_ASSERT_EQUAL('\0', *curr);
}
@@ -101,11 +101,11 @@ static void test_token_next_string_w_whitespace(void) {
const char *input = " \"foo\" ";
const char *curr = input;
response = nl_token_next(&curr);
response = ucl_token_next(&curr);
TEST_ASSERT_NOT_NULL(response);
TEST_ASSERT_EQUAL(NL_TYPE_CELL, response->type);
TEST_ASSERT_EQUAL(NL_TYPE_STRING, response->cell.car->type);
TEST_ASSERT_EQUAL(UCL_TYPE_CELL, response->type);
TEST_ASSERT_EQUAL(UCL_TYPE_STRING, response->cell.car->type);
TEST_ASSERT_EQUAL_STRING("foo", response->cell.car->string);
TEST_ASSERT_EQUAL_STRING(" ", curr);
}
@@ -114,11 +114,11 @@ static void test_token_next_symbol(void) {
const char *input = "foo";
const char *curr = input;
response = nl_token_next(&curr);
response = ucl_token_next(&curr);
TEST_ASSERT_NOT_NULL(response);
TEST_ASSERT_EQUAL(NL_TYPE_CELL, response->type);
TEST_ASSERT_EQUAL(NL_TYPE_SYMBOL, response->cell.car->type);
TEST_ASSERT_EQUAL(UCL_TYPE_CELL, response->type);
TEST_ASSERT_EQUAL(UCL_TYPE_SYMBOL, response->cell.car->type);
TEST_ASSERT_EQUAL_STRING("foo", response->cell.car->string);
TEST_ASSERT_EQUAL_STRING("", curr);
}
@@ -127,206 +127,206 @@ static void test_token_next_symbol_w_whitespace(void) {
const char *input = " foo ";
const char *curr = input;
response = nl_token_next(&curr);
response = ucl_token_next(&curr);
TEST_ASSERT_NOT_NULL(response);
TEST_ASSERT_EQUAL(NL_TYPE_CELL, response->type);
TEST_ASSERT_EQUAL(NL_TYPE_SYMBOL, response->cell.car->type);
TEST_ASSERT_EQUAL(UCL_TYPE_CELL, response->type);
TEST_ASSERT_EQUAL(UCL_TYPE_SYMBOL, response->cell.car->type);
TEST_ASSERT_EQUAL_STRING("foo", response->cell.car->string);
TEST_ASSERT_EQUAL_STRING(" ", curr);
}
static void test_tokenize_empty_str(void) {
response = nl_tokenize("");
response = ucl_tokenize("");
TEST_ASSERT_NULL(response);
}
static void test_tokenize_nil(void) {
response = nl_tokenize("()");
response = ucl_tokenize("()");
TEST_ASSERT_NOT_NULL(response);
TEST_ASSERT_EQUAL(NL_TYPE_CELL, response->type);
TEST_ASSERT_EQUAL(UCL_TYPE_CELL, response->type);
const struct nl_object *token1 = response;
const struct nl_object *token2 = response->cell.cdr;
const struct ucl_object *token1 = response;
const struct ucl_object *token2 = response->cell.cdr;
TEST_ASSERT_EQUAL(NL_TYPE_SYMBOL, token1->cell.car->type);
TEST_ASSERT_EQUAL(UCL_TYPE_SYMBOL, token1->cell.car->type);
TEST_ASSERT_EQUAL_STRING("(", token1->cell.car->string);
TEST_ASSERT_NOT_NULL(token2);
TEST_ASSERT_EQUAL(NL_TYPE_CELL, token2->type);
TEST_ASSERT_EQUAL(NL_TYPE_SYMBOL, token2->cell.car->type);
TEST_ASSERT_EQUAL(UCL_TYPE_CELL, token2->type);
TEST_ASSERT_EQUAL(UCL_TYPE_SYMBOL, token2->cell.car->type);
TEST_ASSERT_EQUAL_STRING(")", token2->cell.car->string);
TEST_ASSERT_NULL(token2->cell.cdr);
}
static void test_tokenize_statement(void) {
response = nl_tokenize("(foo)");
response = ucl_tokenize("(foo)");
TEST_ASSERT_NOT_NULL(response);
TEST_ASSERT_EQUAL(NL_TYPE_CELL, response->type);
TEST_ASSERT_EQUAL(UCL_TYPE_CELL, response->type);
const struct nl_object *token1 = response;
const struct nl_object *token2 = response->cell.cdr;
const struct ucl_object *token1 = response;
const struct ucl_object *token2 = response->cell.cdr;
TEST_ASSERT_EQUAL(NL_TYPE_SYMBOL, token1->cell.car->type);
TEST_ASSERT_EQUAL(UCL_TYPE_SYMBOL, token1->cell.car->type);
TEST_ASSERT_EQUAL_STRING("(", token1->cell.car->string);
TEST_ASSERT_NOT_NULL(token2);
TEST_ASSERT_EQUAL(NL_TYPE_CELL, token2->type);
TEST_ASSERT_EQUAL(NL_TYPE_SYMBOL, token2->cell.car->type);
TEST_ASSERT_EQUAL(UCL_TYPE_CELL, token2->type);
TEST_ASSERT_EQUAL(UCL_TYPE_SYMBOL, token2->cell.car->type);
TEST_ASSERT_EQUAL_STRING("foo", token2->cell.car->string);
const struct nl_object *token3 = token2->cell.cdr;
const struct ucl_object *token3 = token2->cell.cdr;
TEST_ASSERT_NOT_NULL(token3);
TEST_ASSERT_EQUAL(NL_TYPE_CELL, token3->type);
TEST_ASSERT_EQUAL(NL_TYPE_SYMBOL, token3->cell.car->type);
TEST_ASSERT_EQUAL(UCL_TYPE_CELL, token3->type);
TEST_ASSERT_EQUAL(UCL_TYPE_SYMBOL, token3->cell.car->type);
TEST_ASSERT_EQUAL_STRING(")", token3->cell.car->string);
}
static void test_parse_atom_symbol(void) {
response = nl_parse_token_atom(nl_symbol_create(strdup("foo")));
response = ucl_parse_token_atom(ucl_symbol_create(strdup("foo")));
TEST_ASSERT_EQUAL(response->type, NL_TYPE_SYMBOL);
TEST_ASSERT_EQUAL(response->type, UCL_TYPE_SYMBOL);
TEST_ASSERT_EQUAL_STRING(response->symbol, "foo");
}
static void test_parse_atom_lparen(void) {
response = nl_parse_token_atom(nl_symbol_create(strdup("(")));
response = ucl_parse_token_atom(ucl_symbol_create(strdup("(")));
TEST_ASSERT_NULL(response);
}
static void test_parse_atom_rparen(void) {
response = nl_parse_token_atom(nl_symbol_create(strdup(")")));
response = ucl_parse_token_atom(ucl_symbol_create(strdup(")")));
TEST_ASSERT_NULL(response);
}
static void test_parse_empty_str(void) {
response = nl_parse("");
response = ucl_parse("");
TEST_ASSERT_NOT_NULL(response);
TEST_ASSERT_EQUAL(NL_TYPE_CELL, response->type);
TEST_ASSERT_EQUAL(UCL_TYPE_CELL, response->type);
TEST_ASSERT_NULL(response->cell.car);
TEST_ASSERT_NULL(response->cell.cdr);
}
static void test_parse_symbol(void) {
response = nl_parse("foo");
response = ucl_parse("foo");
TEST_ASSERT_NOT_NULL(response);
TEST_ASSERT_EQUAL(NL_TYPE_CELL, response->type);
TEST_ASSERT_EQUAL(UCL_TYPE_CELL, response->type);
TEST_ASSERT_NOT_NULL(response->cell.car);
TEST_ASSERT_EQUAL(response->cell.car->type, NL_TYPE_SYMBOL);
TEST_ASSERT_EQUAL(response->cell.car->type, UCL_TYPE_SYMBOL);
TEST_ASSERT_EQUAL_STRING(response->cell.car->symbol, "foo");
}
static void test_parse_nil(void) {
response = nl_parse("()");
response = ucl_parse("()");
TEST_ASSERT_NOT_NULL(response);
TEST_ASSERT_EQUAL(NL_TYPE_CELL, response->type);
TEST_ASSERT_EQUAL(UCL_TYPE_CELL, response->type);
TEST_ASSERT_NOT_NULL(response->cell.car);
TEST_ASSERT_NULL(response->cell.cdr);
TEST_ASSERT_EQUAL(NL_TYPE_CELL, response->cell.car->type);
TEST_ASSERT_EQUAL(UCL_TYPE_CELL, response->cell.car->type);
TEST_ASSERT_NULL(response->cell.car->cell.car);
TEST_ASSERT_NULL(response->cell.car->cell.cdr);
}
static void test_parse_list_1elem(void) {
response = nl_parse("(foo)");
response = ucl_parse("(foo)");
TEST_ASSERT_NOT_NULL(response);
TEST_ASSERT_EQUAL(NL_TYPE_CELL, response->type);
TEST_ASSERT_EQUAL(UCL_TYPE_CELL, response->type);
TEST_ASSERT_NOT_NULL(response->cell.car);
TEST_ASSERT_NULL(response->cell.cdr);
TEST_ASSERT_EQUAL(NL_TYPE_CELL, response->cell.car->type);
TEST_ASSERT_EQUAL(UCL_TYPE_CELL, response->cell.car->type);
TEST_ASSERT_NULL(response->cell.car->cell.cdr);
TEST_ASSERT_EQUAL(NL_TYPE_SYMBOL, response->cell.car->cell.car->type);
TEST_ASSERT_EQUAL(UCL_TYPE_SYMBOL, response->cell.car->cell.car->type);
TEST_ASSERT_EQUAL_STRING("foo", response->cell.car->cell.car->symbol);
}
static void test_parse_list_2elem(void) {
response = nl_parse("(foo bar)");
response = ucl_parse("(foo bar)");
TEST_ASSERT_NOT_NULL(response);
TEST_ASSERT_EQUAL(NL_TYPE_CELL, response->type);
TEST_ASSERT_EQUAL(UCL_TYPE_CELL, response->type);
TEST_ASSERT_NOT_NULL(response->cell.car);
TEST_ASSERT_NULL(response->cell.cdr);
TEST_ASSERT_EQUAL(NL_TYPE_CELL, response->cell.car->type);
TEST_ASSERT_EQUAL(UCL_TYPE_CELL, response->cell.car->type);
TEST_ASSERT_NOT_NULL(response->cell.car->cell.cdr);
TEST_ASSERT_EQUAL(NL_TYPE_SYMBOL, response->cell.car->cell.car->type);
TEST_ASSERT_EQUAL(UCL_TYPE_SYMBOL, response->cell.car->cell.car->type);
TEST_ASSERT_EQUAL_STRING("foo", response->cell.car->cell.car->symbol);
TEST_ASSERT_EQUAL(NL_TYPE_CELL, response->cell.car->cell.cdr->type);
TEST_ASSERT_EQUAL(NL_TYPE_SYMBOL, response->cell.car->cell.cdr->cell.car->type);
TEST_ASSERT_EQUAL(UCL_TYPE_CELL, response->cell.car->cell.cdr->type);
TEST_ASSERT_EQUAL(UCL_TYPE_SYMBOL, response->cell.car->cell.cdr->cell.car->type);
TEST_ASSERT_EQUAL_STRING("bar", response->cell.car->cell.cdr->cell.car->string);
}
static void test_parse_2elem(void) {
response = nl_parse("foo bar");
response = ucl_parse("foo bar");
TEST_ASSERT_NOT_NULL(response);
TEST_ASSERT_EQUAL(NL_TYPE_CELL, response->type);
TEST_ASSERT_EQUAL(UCL_TYPE_CELL, response->type);
TEST_ASSERT_NOT_NULL(response->cell.car);
TEST_ASSERT_EQUAL(NL_TYPE_SYMBOL, response->cell.car->type);
TEST_ASSERT_EQUAL(UCL_TYPE_SYMBOL, response->cell.car->type);
TEST_ASSERT_EQUAL_STRING("foo", response->cell.car->symbol);
TEST_ASSERT_NOT_NULL(response->cell.cdr);
TEST_ASSERT_EQUAL(NL_TYPE_CELL, response->cell.cdr->type);
TEST_ASSERT_EQUAL(UCL_TYPE_CELL, response->cell.cdr->type);
TEST_ASSERT_EQUAL(NL_TYPE_SYMBOL, response->cell.cdr->cell.car->type);
TEST_ASSERT_EQUAL(UCL_TYPE_SYMBOL, response->cell.cdr->cell.car->type);
TEST_ASSERT_EQUAL_STRING("bar", response->cell.cdr->cell.car->symbol);
}
static void test_parse_2elem_str(void) {
response = nl_parse("\"foo\" \"bar\"");
response = ucl_parse("\"foo\" \"bar\"");
TEST_ASSERT_NOT_NULL(response);
TEST_ASSERT_EQUAL(NL_TYPE_CELL, response->type);
TEST_ASSERT_EQUAL(UCL_TYPE_CELL, response->type);
TEST_ASSERT_NOT_NULL(response->cell.car);
TEST_ASSERT_EQUAL(NL_TYPE_STRING, response->cell.car->type);
TEST_ASSERT_EQUAL(UCL_TYPE_STRING, response->cell.car->type);
TEST_ASSERT_EQUAL_STRING("foo", response->cell.car->string);
TEST_ASSERT_NOT_NULL(response->cell.cdr);
TEST_ASSERT_EQUAL(NL_TYPE_CELL, response->cell.cdr->type);
TEST_ASSERT_EQUAL(UCL_TYPE_CELL, response->cell.cdr->type);
TEST_ASSERT_EQUAL(NL_TYPE_STRING, response->cell.cdr->cell.car->type);
TEST_ASSERT_EQUAL(UCL_TYPE_STRING, response->cell.cdr->cell.car->type);
TEST_ASSERT_EQUAL_STRING("bar", response->cell.cdr->cell.car->string);
}
static void test_parse_nested(void) {
response = nl_parse("((foo))");
response = ucl_parse("((foo))");
TEST_ASSERT_NOT_NULL(response);
TEST_ASSERT_EQUAL(NL_TYPE_CELL, response->type);
TEST_ASSERT_EQUAL(UCL_TYPE_CELL, response->type);
TEST_ASSERT_NOT_NULL(response->cell.car);
TEST_ASSERT_NULL(response->cell.cdr);
TEST_ASSERT_EQUAL(NL_TYPE_CELL, response->cell.car->type);
TEST_ASSERT_EQUAL(UCL_TYPE_CELL, response->cell.car->type);
TEST_ASSERT_NULL(response->cell.car->cell.cdr);
TEST_ASSERT_EQUAL(NL_TYPE_CELL, response->cell.car->cell.car->type);
TEST_ASSERT_EQUAL(UCL_TYPE_CELL, response->cell.car->cell.car->type);
TEST_ASSERT_NULL(response->cell.car->cell.car->cell.cdr);
TEST_ASSERT_EQUAL(NL_TYPE_SYMBOL, response->cell.car->cell.car->cell.car->type);
TEST_ASSERT_EQUAL(UCL_TYPE_SYMBOL, response->cell.car->cell.car->cell.car->type);
TEST_ASSERT_EQUAL_STRING("foo", response->cell.car->cell.car->cell.car->symbol);
}

View File

@@ -2,57 +2,57 @@
#include <stdlib.h>
#include <string.h>
#include "nihilispm.h"
#include "nihilispm_internal.h"
#include "nihilispm_state.h"
#include "nihilispm_utility.h"
#include "uclisp.h"
#include "internal.h"
#include "state.h"
#include "utility.h"
#include "testing_helpers.h"
/* static struct nl_parse_result *result; */
static struct nl_state *state;
static struct nl_object *response;
/* static struct ucl_parse_result *result; */
static struct ucl_state *state;
static struct ucl_object *response;
void setUp(void) {
state = nl_state_create();
state = ucl_state_create();
}
void tearDown(void) {
nl_state_delete(state);
ucl_state_delete(state);
state = NULL;
}
static void test_get_empty(void) {
response = nl_state_get(state, "foo");
response = ucl_state_get(state, "foo");
TEST_ASSERT_OBJ_ERROR(response);
}
static void test_put_get(void) {
nl_state_put(state, "foo", nl_t_create());
response = nl_state_get(state, "foo");
ucl_state_put(state, "foo", ucl_t_create());
response = ucl_state_get(state, "foo");
TEST_ASSERT_T(response);
}
static void test_put2_get(void) {
nl_state_put(state, "foo1", nl_t_create());
nl_state_put(state, "foo2", nl_nil_create());
response = nl_state_get(state, "foo1");
ucl_state_put(state, "foo1", ucl_t_create());
ucl_state_put(state, "foo2", ucl_nil_create());
response = ucl_state_get(state, "foo1");
TEST_ASSERT_T(response);
}
static void test_put_modify_get(void) {
struct nl_object *obj = nl_tuple_create(
nl_string_create(strdup("bar")),
nl_string_create(strdup("baz")));
struct ucl_object *obj = ucl_tuple_create(
ucl_string_create(strdup("bar")),
ucl_string_create(strdup("baz")));
nl_state_put(state, "foo", obj);
nl_list_append(obj, nl_string_create(strdup("quux")));
response = nl_state_get(state, "foo");
ucl_state_put(state, "foo", obj);
ucl_list_append(obj, ucl_string_create(strdup("quux")));
response = ucl_state_get(state, "foo");
TEST_ASSERT_OBJ_STRING(nl_list_nth(response, 2));
TEST_ASSERT_EQUAL_STRING(nl_list_nth(response, 2)->string, "quux");
TEST_ASSERT_OBJ_STRING(ucl_list_nth(response, 2));
TEST_ASSERT_EQUAL_STRING(ucl_list_nth(response, 2)->string, "quux");
TEST_ASSERT_OBJ_STRING(nl_list_nth(obj, 2));
TEST_ASSERT_EQUAL_STRING(nl_list_nth(obj, 2)->string, "quux");
TEST_ASSERT_OBJ_STRING(ucl_list_nth(obj, 2));
TEST_ASSERT_EQUAL_STRING(ucl_list_nth(obj, 2)->string, "quux");
}

View File

@@ -2,13 +2,13 @@
#include <unity.h>
#include <string.h>
#include "nihilispm.h"
#include "nihilispm_internal.h"
#include "nihilispm_utility.h"
#include "uclisp.h"
#include "internal.h"
#include "utility.h"
#include "testing_helpers.h"
static struct nl_object *input;
static struct nl_object *response;
static struct ucl_object *input;
static struct ucl_object *response;
void setUp(void) {
input = NULL;
@@ -17,99 +17,99 @@ void setUp(void) {
void tearDown(void) {
// TODO: Implement GC so we can clean these both up
//nl_object_delete(input);
//ucl_object_delete(input);
input = NULL;
nl_object_delete(response);
ucl_object_delete(response);
response = NULL;
}
static void test_nil_create(void) {
response = nl_nil_create();
response = ucl_nil_create();
TEST_ASSERT_NIL(response);
}
static void test_t_create(void) {
response = nl_t_create();
response = ucl_t_create();
TEST_ASSERT_T(response);
}
static void test_predicate_true(void) {
response = nl_predicate(true);
response = ucl_predicate(true);
TEST_ASSERT_T(response);
}
static void test_predicate_false(void) {
response = nl_predicate(false);
response = ucl_predicate(false);
TEST_ASSERT_NIL(response);
}
static void test_car_nil(void) {
response = nl_car(nl_nil_create());
response = ucl_car(ucl_nil_create());
TEST_ASSERT_NIL(response);
}
static void test_cdr_nil(void) {
response = nl_cdr(nl_nil_create());
response = ucl_cdr(ucl_nil_create());
TEST_ASSERT_NIL(response);
}
static void test_car_t(void) {
response = nl_car(nl_t_create());
response = ucl_car(ucl_t_create());
TEST_ASSERT_OBJ_ERROR(response);
}
static void test_cdr_t(void) {
response = nl_car(nl_t_create());
response = ucl_car(ucl_t_create());
TEST_ASSERT_OBJ_ERROR(response);
}
static void test_car_list(void) {
input = nl_tuple_create(
nl_string_create(strdup("foo")),
nl_t_create());
response = nl_car(input);
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 = nl_tuple_create(
nl_t_create(),
nl_string_create(strdup("foo")));
response = nl_cdr(input);
input = ucl_tuple_create(
ucl_t_create(),
ucl_string_create(strdup("foo")));
response = ucl_cdr(input);
TEST_ASSERT_OBJ_STRING(nl_car(response));
TEST_ASSERT_OBJ_STRING(ucl_car(response));
}
static void test_list_length_nil() {
response = nl_list_length(nl_nil_create());
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 = nl_list_length(
nl_cell_create(
nl_t_create(), NULL));
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 = nl_list_length(
nl_tuple_create(
nl_t_create(),
nl_t_create()));
response = ucl_list_length(
ucl_tuple_create(
ucl_t_create(),
ucl_t_create()));
TEST_ASSERT_OBJ_INT(response);
TEST_ASSERT_EQUAL(response->integer, 2);
@@ -117,67 +117,67 @@ static void test_list_length_2() {
static void test_list_append_nil() {
input = nl_nil_create();
nl_list_append(input, nl_t_create());
input = ucl_nil_create();
ucl_list_append(input, ucl_t_create());
TEST_ASSERT_EQUAL(nl_list_length(input)->integer, 1);
TEST_ASSERT_EQUAL(ucl_list_length(input)->integer, 1);
}
static void test_list_append_list() {
input = nl_tuple_create(nl_t_create(), nl_t_create());
nl_list_append(input, nl_t_create());
input = ucl_tuple_create(ucl_t_create(), ucl_t_create());
ucl_list_append(input, ucl_t_create());
TEST_ASSERT_EQUAL(nl_list_length(input)->integer, 3);
TEST_ASSERT_EQUAL(ucl_list_length(input)->integer, 3);
}
static void test_list_nth_nil_0() {
response = nl_list_nth(nl_nil_create(), 0);
response = ucl_list_nth(ucl_nil_create(), 0);
TEST_ASSERT_OBJ_ERROR(response);
}
static void test_list_nth_nil_1() {
response = nl_list_nth(nl_nil_create(), 1);
response = ucl_list_nth(ucl_nil_create(), 1);
TEST_ASSERT_OBJ_ERROR(response);
}
static void test_list_nth_list_0() {
response = nl_list_nth(
nl_tuple_create(
nl_t_create(),
nl_string_create(strdup("foo"))),
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 = nl_list_nth(
nl_tuple_create(
nl_t_create(),
nl_string_create(strdup("foo"))),
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 = nl_list_nth(nl_t_create(), 1);
response = ucl_list_nth(ucl_t_create(), 1);
TEST_ASSERT_OBJ_ERROR(response);
}
static void test_list_nth_bounds_0() {
response = nl_list_nth(nl_nil_create(), 0);
response = ucl_list_nth(ucl_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(),
response = ucl_list_nth(
ucl_cell_create(
ucl_nil_create(),
NULL),
1);
@@ -185,10 +185,10 @@ static void test_list_nth_bounds_1() {
}
static void test_list_nth_bounds_2() {
response = nl_list_nth(
nl_tuple_create(
nl_nil_create(),
nl_nil_create()),
response = ucl_list_nth(
ucl_tuple_create(
ucl_nil_create(),
ucl_nil_create()),
2);
TEST_ASSERT_OBJ_ERROR(response);

View File

@@ -3,27 +3,27 @@
#include <unity.h>
#include "nihilispm.h"
#include "uclisp.h"
#define TEST_ASSERT_OBJ_ERROR(obj) \
TEST_ASSERT_EQUAL(obj->type, NL_TYPE_ERROR)
TEST_ASSERT_EQUAL(obj->type, UCL_TYPE_ERROR)
#define TEST_ASSERT_OBJ_SYMBOL(obj) \
TEST_ASSERT_EQUAL(obj->type, NL_TYPE_SYMBOL)
TEST_ASSERT_EQUAL(obj->type, UCL_TYPE_SYMBOL)
#define TEST_ASSERT_OBJ_STRING(obj) \
TEST_ASSERT_EQUAL(obj->type, NL_TYPE_STRING)
TEST_ASSERT_EQUAL(obj->type, UCL_TYPE_STRING)
#define TEST_ASSERT_OBJ_INT(obj) \
TEST_ASSERT_EQUAL(obj->type, NL_TYPE_INT)
TEST_ASSERT_EQUAL(obj->type, UCL_TYPE_INT)
#define TEST_ASSERT_OBJ_LIST(obj) \
TEST_ASSERT_EQUAL(obj->type, NL_TYPE_CELL)
TEST_ASSERT_EQUAL(obj->type, UCL_TYPE_CELL)
#define TEST_ASSERT_LIST_LEN(list, len) \
do { \
TEST_ASSERT_OBJ_LIST(list); \
TEST_ASSERT_EQUAL(nl_list_length(list)->integer, len); \
TEST_ASSERT_EQUAL(ucl_list_length(list)->integer, len); \
} while(0)
#define TEST_ASSERT_NIL(obj) \