Refactor to encapsulate all state in a 'ucl'
This commit is contained in:
@@ -7,89 +7,91 @@
|
||||
#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) {
|
||||
ucl_gc();
|
||||
|
||||
// TODO: Release memory
|
||||
state = NULL;
|
||||
input = NULL;
|
||||
response = NULL;
|
||||
}
|
||||
|
||||
static void test_nil_create(void) {
|
||||
response = ucl_nil_create();
|
||||
response = ucl_nil_create(state);
|
||||
|
||||
TEST_ASSERT_NIL(response);
|
||||
}
|
||||
|
||||
static void test_t_create(void) {
|
||||
response = ucl_t_create();
|
||||
response = ucl_t_create(state);
|
||||
|
||||
TEST_ASSERT_T(response);
|
||||
}
|
||||
|
||||
static void test_predicate_true(void) {
|
||||
response = ucl_predicate(true);
|
||||
response = ucl_predicate(state, true);
|
||||
|
||||
TEST_ASSERT_T(response);
|
||||
}
|
||||
|
||||
static void test_predicate_false(void) {
|
||||
response = ucl_predicate(false);
|
||||
response = ucl_predicate(state, false);
|
||||
|
||||
TEST_ASSERT_NIL(response);
|
||||
}
|
||||
|
||||
static void test_car_nil(void) {
|
||||
response = ucl_car(ucl_nil_create());
|
||||
response = ucl_car(state, ucl_nil_create(state));
|
||||
|
||||
TEST_ASSERT_NIL(response);
|
||||
}
|
||||
|
||||
static void test_cdr_nil(void) {
|
||||
response = ucl_cdr(ucl_nil_create());
|
||||
response = ucl_cdr(state, ucl_nil_create(state));
|
||||
|
||||
TEST_ASSERT_NIL(response);
|
||||
}
|
||||
|
||||
static void test_car_t(void) {
|
||||
response = ucl_car(ucl_t_create());
|
||||
response = ucl_car(state, ucl_t_create(state));
|
||||
|
||||
TEST_ASSERT_OBJ_ERROR(response);
|
||||
}
|
||||
|
||||
static void test_cdr_t(void) {
|
||||
response = ucl_car(ucl_t_create());
|
||||
response = ucl_car(state, ucl_t_create(state));
|
||||
|
||||
TEST_ASSERT_OBJ_ERROR(response);
|
||||
}
|
||||
|
||||
static void test_car_list(void) {
|
||||
input = ucl_tuple_create(
|
||||
ucl_string_create("foo"),
|
||||
ucl_t_create());
|
||||
response = ucl_car(input);
|
||||
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(
|
||||
ucl_t_create(),
|
||||
ucl_string_create("foo"));
|
||||
response = ucl_cdr(input);
|
||||
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(response));
|
||||
TEST_ASSERT_OBJ_STRING(ucl_car(state, response));
|
||||
}
|
||||
|
||||
static void test_list_length_nil() {
|
||||
response = ucl_list_length(ucl_nil_create());
|
||||
response = ucl_list_length(state, ucl_nil_create(state));
|
||||
|
||||
TEST_ASSERT_OBJ_INT(response);
|
||||
TEST_ASSERT_EQUAL(response->integer, 0);
|
||||
@@ -97,8 +99,9 @@ static void test_list_length_nil() {
|
||||
|
||||
static void test_list_length_1() {
|
||||
response = ucl_list_length(
|
||||
ucl_cell_create(
|
||||
ucl_t_create(), NULL));
|
||||
state,
|
||||
ucl_cell_create(state,
|
||||
ucl_t_create(state), NULL));
|
||||
|
||||
TEST_ASSERT_OBJ_INT(response);
|
||||
TEST_ASSERT_EQUAL(response->integer, 1);
|
||||
@@ -106,9 +109,10 @@ static void test_list_length_1() {
|
||||
|
||||
static void test_list_length_2() {
|
||||
response = ucl_list_length(
|
||||
ucl_tuple_create(
|
||||
ucl_t_create(),
|
||||
ucl_t_create()));
|
||||
state,
|
||||
ucl_tuple_create(state,
|
||||
ucl_t_create(state),
|
||||
ucl_t_create(state)));
|
||||
|
||||
TEST_ASSERT_OBJ_INT(response);
|
||||
TEST_ASSERT_EQUAL(response->integer, 2);
|
||||
@@ -116,36 +120,37 @@ static void test_list_length_2() {
|
||||
|
||||
|
||||
static void test_list_append_nil() {
|
||||
input = ucl_nil_create();
|
||||
ucl_list_append(input, ucl_t_create());
|
||||
input = ucl_nil_create(state);
|
||||
ucl_list_append(state, input, ucl_t_create(state));
|
||||
|
||||
TEST_ASSERT_EQUAL(ucl_list_length(input)->integer, 1);
|
||||
TEST_ASSERT_EQUAL(ucl_list_length(state, 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());
|
||||
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(input)->integer, 3);
|
||||
TEST_ASSERT_EQUAL(ucl_list_length(state, input)->integer, 3);
|
||||
}
|
||||
|
||||
static void test_list_nth_nil_0() {
|
||||
response = ucl_list_nth(ucl_nil_create(), 0);
|
||||
response = ucl_list_nth(state, ucl_nil_create(state), 0);
|
||||
|
||||
TEST_ASSERT_OBJ_ERROR(response);
|
||||
}
|
||||
|
||||
static void test_list_nth_nil_1() {
|
||||
response = ucl_list_nth(ucl_nil_create(), 1);
|
||||
response = ucl_list_nth(state, ucl_nil_create(state), 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("foo")),
|
||||
state,
|
||||
ucl_tuple_create(state,
|
||||
ucl_t_create(state),
|
||||
ucl_string_create(state, "foo")),
|
||||
0);
|
||||
|
||||
TEST_ASSERT_T(response);
|
||||
@@ -153,30 +158,32 @@ static void test_list_nth_list_0() {
|
||||
|
||||
static void test_list_nth_list_1() {
|
||||
response = ucl_list_nth(
|
||||
ucl_tuple_create(
|
||||
ucl_t_create(),
|
||||
ucl_string_create("foo")),
|
||||
state,
|
||||
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(), 1);
|
||||
response = ucl_list_nth(state, ucl_t_create(state), 1);
|
||||
|
||||
TEST_ASSERT_OBJ_ERROR(response);
|
||||
}
|
||||
|
||||
static void test_list_nth_bounds_0() {
|
||||
response = ucl_list_nth(ucl_nil_create(), 0);
|
||||
response = ucl_list_nth(state, ucl_nil_create(state), 0);
|
||||
|
||||
TEST_ASSERT_OBJ_ERROR(response);
|
||||
}
|
||||
|
||||
static void test_list_nth_bounds_1() {
|
||||
response = ucl_list_nth(
|
||||
ucl_cell_create(
|
||||
ucl_nil_create(),
|
||||
state,
|
||||
ucl_cell_create(state,
|
||||
ucl_nil_create(state),
|
||||
NULL),
|
||||
1);
|
||||
|
||||
@@ -185,42 +192,43 @@ static void test_list_nth_bounds_1() {
|
||||
|
||||
static void test_list_nth_bounds_2() {
|
||||
response = ucl_list_nth(
|
||||
ucl_tuple_create(
|
||||
ucl_nil_create(),
|
||||
ucl_nil_create()),
|
||||
state,
|
||||
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(ucl_int_create(0));
|
||||
response = ucl_truthy(state, ucl_int_create(state, 0));
|
||||
|
||||
TEST_ASSERT_NIL(response);
|
||||
}
|
||||
|
||||
static void test_truthy_1() {
|
||||
response = ucl_truthy(ucl_int_create(1));
|
||||
response = ucl_truthy(state, ucl_int_create(state, 1));
|
||||
|
||||
TEST_ASSERT_T(response);
|
||||
}
|
||||
|
||||
static void test_truthy_nil() {
|
||||
response = ucl_truthy(ucl_nil_create());
|
||||
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();
|
||||
ucl_list_append(list, ucl_int_create(0));
|
||||
response = ucl_truthy(list);
|
||||
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(ucl_symbol_create("t"));
|
||||
response = ucl_truthy(state, ucl_symbol_create(state, "t"));
|
||||
|
||||
TEST_ASSERT_T(response);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user