Files
uclisp/test/test_state.c

67 lines
1.6 KiB
C

#include <unity.h>
#include <stdlib.h>
#include <string.h>
#include "nihilispm.h"
#include "nihilispm_internal.h"
#include "nihilispm_state.h"
#include "nihilispm_utility.h"
#include "testing_helpers.h"
/* static struct nl_parse_result *result; */
static struct nl_state *state;
static struct nl_object *response;
void setUp(void) {
state = nl_state_create();
}
void tearDown(void) {
nl_state_delete(state);
state = NULL;
}
static void test_get_empty(void) {
response = nl_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");
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");
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")));
nl_state_put(state, "foo", obj);
nl_list_append(obj, nl_string_create(strdup("quux")));
response = nl_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(nl_list_nth(obj, 2));
TEST_ASSERT_EQUAL_STRING(nl_list_nth(obj, 2)->string, "quux");
}
int main(void) {
UNITY_BEGIN();
RUN_TEST(test_get_empty);
RUN_TEST(test_put_get);
RUN_TEST(test_put2_get);
RUN_TEST(test_put_modify_get);
return UNITY_END();
}