Rename 'state' to 'scope'
This commit is contained in:
66
test/test_scope.c
Normal file
66
test/test_scope.c
Normal file
@@ -0,0 +1,66 @@
|
||||
#include <unity.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "uclisp.h"
|
||||
#include "internal.h"
|
||||
#include "scope.h"
|
||||
#include "utility.h"
|
||||
#include "testing_helpers.h"
|
||||
|
||||
/* static struct ucl_parse_result *result; */
|
||||
static struct ucl_scope *scope;
|
||||
static struct ucl_object *response;
|
||||
|
||||
void setUp(void) {
|
||||
scope = ucl_scope_create();
|
||||
}
|
||||
|
||||
void tearDown(void) {
|
||||
ucl_scope_delete(scope);
|
||||
scope = NULL;
|
||||
}
|
||||
|
||||
static void test_get_empty(void) {
|
||||
response = ucl_scope_get(scope, "foo");
|
||||
TEST_ASSERT_OBJ_ERROR(response);
|
||||
}
|
||||
|
||||
static void test_put_get(void) {
|
||||
ucl_scope_put(scope, "foo", ucl_t_create());
|
||||
response = ucl_scope_get(scope, "foo");
|
||||
TEST_ASSERT_T(response);
|
||||
}
|
||||
|
||||
static void test_put2_get(void) {
|
||||
ucl_scope_put(scope, "foo1", ucl_t_create());
|
||||
ucl_scope_put(scope, "foo2", ucl_nil_create());
|
||||
response = ucl_scope_get(scope, "foo1");
|
||||
TEST_ASSERT_T(response);
|
||||
}
|
||||
|
||||
static void test_put_modify_get(void) {
|
||||
struct ucl_object *obj = ucl_tuple_create(
|
||||
ucl_string_create("bar"),
|
||||
ucl_string_create("baz"));
|
||||
|
||||
ucl_scope_put(scope, "foo", obj);
|
||||
ucl_list_append(obj, ucl_string_create("quux"));
|
||||
response = ucl_scope_get(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();
|
||||
}
|
||||
Reference in New Issue
Block a user