69 lines
1.7 KiB
C
69 lines
1.7 KiB
C
#include <unity.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
|
|
#include "testing_helpers.h"
|
|
|
|
#include "uclisp.h"
|
|
#include "common.h"
|
|
#include "scope.h"
|
|
|
|
/* static struct ucl_parse_result *result; */
|
|
static struct ucl *state;
|
|
static struct ucl_scope *scope;
|
|
static struct ucl_object *response;
|
|
|
|
void setUp(void) {
|
|
state = ucl_create();
|
|
scope = ucl_scope_create(state);
|
|
}
|
|
|
|
void tearDown(void) {
|
|
state = NULL;
|
|
scope = NULL;
|
|
}
|
|
|
|
static void test_get_empty(void) {
|
|
response = ucl_scope_get(state, scope, "foo");
|
|
TEST_ASSERT_OBJ_ERROR(response);
|
|
}
|
|
|
|
static void test_put_get(void) {
|
|
ucl_scope_put(state, scope, "foo", ucl_t_create(state));
|
|
response = ucl_scope_get(state, scope, "foo");
|
|
TEST_ASSERT_T(response);
|
|
}
|
|
|
|
static void test_put2_get(void) {
|
|
ucl_scope_put(state, scope, "foo1", ucl_t_create(state));
|
|
ucl_scope_put(state, scope, "foo2", ucl_nil_create(state));
|
|
response = ucl_scope_get(state, scope, "foo1");
|
|
TEST_ASSERT_T(response);
|
|
}
|
|
|
|
static void test_put_modify_get(void) {
|
|
struct ucl_object *obj = ucl_tuple_create(state,
|
|
ucl_string_create(state, "bar"),
|
|
ucl_string_create(state, "baz"));
|
|
|
|
ucl_scope_put(state, scope, "foo", obj);
|
|
ucl_list_append(state, obj, ucl_string_create(state, "quux"));
|
|
response = ucl_scope_get(state, scope, "foo");
|
|
|
|
TEST_ASSERT_OBJ_STRING(ucl_list_nth(response, 2));
|
|
TEST_ASSERT_EQUAL_STRING(ucl_list_nth(response, 2)->string, "quux");
|
|
|
|
TEST_ASSERT_OBJ_STRING(ucl_list_nth(obj, 2));
|
|
TEST_ASSERT_EQUAL_STRING(ucl_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();
|
|
}
|