mirror of
https://github.com/falk-werner/webfuse-provider
synced 2026-03-02 04:09:18 +00:00
refactor: renamed json_parse to json_doc
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
#include "webfuse_provider/impl/json/parser.h"
|
||||
#include "webfuse_provider/impl/json/doc.h"
|
||||
#include "webfuse_provider/impl/json/node.h"
|
||||
#include <gtest/gtest.h>
|
||||
#include <cstring>
|
||||
@@ -7,7 +7,7 @@ namespace
|
||||
{
|
||||
wfp_json_doc * parse_json(char * text)
|
||||
{
|
||||
return wfp_impl_json_parse_buffer(text, strlen(text));
|
||||
return wfp_impl_json_doc_loadb(text, strlen(text));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,11 +16,11 @@ TEST(json_parser, parse_true)
|
||||
char text[] = "true";
|
||||
wfp_json_doc * doc = parse_json(text);
|
||||
ASSERT_NE(nullptr, doc);
|
||||
wfp_json const * root = wfp_impl_json_root(doc);
|
||||
wfp_json const * root = wfp_impl_json_doc_root(doc);
|
||||
ASSERT_TRUE(wfp_impl_json_is_bool(root));
|
||||
ASSERT_TRUE(wfp_impl_json_get_bool(root));
|
||||
|
||||
wfp_impl_json_dispose(doc);
|
||||
wfp_impl_json_doc_dispose(doc);
|
||||
}
|
||||
|
||||
TEST(json_parser, parse_false)
|
||||
@@ -28,11 +28,11 @@ TEST(json_parser, parse_false)
|
||||
char text[] = "false";
|
||||
wfp_json_doc * doc = parse_json(text);
|
||||
ASSERT_NE(nullptr, doc);
|
||||
wfp_json const * root = wfp_impl_json_root(doc);
|
||||
wfp_json const * root = wfp_impl_json_doc_root(doc);
|
||||
ASSERT_TRUE(wfp_impl_json_is_bool(root));
|
||||
ASSERT_FALSE(wfp_impl_json_get_bool(root));
|
||||
|
||||
wfp_impl_json_dispose(doc);
|
||||
wfp_impl_json_doc_dispose(doc);
|
||||
}
|
||||
|
||||
TEST(json_parser, parse_int)
|
||||
@@ -40,11 +40,11 @@ TEST(json_parser, parse_int)
|
||||
char text[] = "42";
|
||||
wfp_json_doc * doc = parse_json(text);
|
||||
ASSERT_NE(nullptr, doc);
|
||||
wfp_json const * root = wfp_impl_json_root(doc);
|
||||
wfp_json const * root = wfp_impl_json_doc_root(doc);
|
||||
ASSERT_TRUE(wfp_impl_json_is_int(root));
|
||||
ASSERT_EQ(42, wfp_impl_json_get_int(root));
|
||||
|
||||
wfp_impl_json_dispose(doc);
|
||||
wfp_impl_json_doc_dispose(doc);
|
||||
}
|
||||
|
||||
TEST(json_parser, parse_negative_int)
|
||||
@@ -52,11 +52,11 @@ TEST(json_parser, parse_negative_int)
|
||||
char text[] = "-1234";
|
||||
wfp_json_doc * doc = parse_json(text);
|
||||
ASSERT_NE(nullptr, doc);
|
||||
wfp_json const * root = wfp_impl_json_root(doc);
|
||||
wfp_json const * root = wfp_impl_json_doc_root(doc);
|
||||
ASSERT_TRUE(wfp_impl_json_is_int(root));
|
||||
ASSERT_EQ(-1234, wfp_impl_json_get_int(root));
|
||||
|
||||
wfp_impl_json_dispose(doc);
|
||||
wfp_impl_json_doc_dispose(doc);
|
||||
}
|
||||
|
||||
TEST(json_parser, parse_string)
|
||||
@@ -64,11 +64,11 @@ TEST(json_parser, parse_string)
|
||||
char text[] = "\"brummni\"";
|
||||
wfp_json_doc * doc = parse_json(text);
|
||||
ASSERT_NE(nullptr, doc);
|
||||
wfp_json const * root = wfp_impl_json_root(doc);
|
||||
wfp_json const * root = wfp_impl_json_doc_root(doc);
|
||||
ASSERT_TRUE(wfp_impl_json_is_string(root));
|
||||
ASSERT_STREQ("brummni", wfp_impl_json_get_string(root));
|
||||
|
||||
wfp_impl_json_dispose(doc);
|
||||
wfp_impl_json_doc_dispose(doc);
|
||||
}
|
||||
|
||||
TEST(json_parser, parse_array)
|
||||
@@ -76,7 +76,7 @@ TEST(json_parser, parse_array)
|
||||
char text[] = "[true,1,\"foo\",[42]]";
|
||||
wfp_json_doc * doc = parse_json(text);
|
||||
ASSERT_NE(nullptr, doc);
|
||||
wfp_json const * root = wfp_impl_json_root(doc);
|
||||
wfp_json const * root = wfp_impl_json_doc_root(doc);
|
||||
ASSERT_TRUE(wfp_impl_json_is_array(root));
|
||||
ASSERT_EQ(4, wfp_impl_json_array_size(root));
|
||||
|
||||
@@ -85,7 +85,7 @@ TEST(json_parser, parse_array)
|
||||
ASSERT_TRUE(wfp_impl_json_is_string(wfp_impl_json_array_get(root, 2)));
|
||||
ASSERT_TRUE(wfp_impl_json_is_array(wfp_impl_json_array_get(root, 3)));
|
||||
|
||||
wfp_impl_json_dispose(doc);
|
||||
wfp_impl_json_doc_dispose(doc);
|
||||
}
|
||||
|
||||
TEST(json_parser, parse_object)
|
||||
@@ -93,7 +93,7 @@ TEST(json_parser, parse_object)
|
||||
char text[] = "{\"method\":\"add\",\"params\":[1,2],\"id\":42}";
|
||||
wfp_json_doc * doc = parse_json(text);
|
||||
ASSERT_NE(nullptr, doc);
|
||||
wfp_json const * root = wfp_impl_json_root(doc);
|
||||
wfp_json const * root = wfp_impl_json_doc_root(doc);
|
||||
ASSERT_TRUE(wfp_impl_json_is_object(root));
|
||||
ASSERT_EQ(3, wfp_impl_json_object_size(root));
|
||||
|
||||
@@ -101,7 +101,7 @@ TEST(json_parser, parse_object)
|
||||
ASSERT_STREQ("params", wfp_impl_json_object_key(root, 1));
|
||||
ASSERT_STREQ("id", wfp_impl_json_object_key(root, 2));
|
||||
|
||||
wfp_impl_json_dispose(doc);
|
||||
wfp_impl_json_doc_dispose(doc);
|
||||
}
|
||||
|
||||
TEST(json_parser, parse_fail_invalid_json)
|
||||
|
||||
Reference in New Issue
Block a user