chore: update jsoncons dependency (#1066)

* chore: update jsoncons dependency

* fix: remove unused test case

Signed-off-by: iko1 <me@remotecpp.dev>

* initial attempt to create custom memory allocator test

Signed-off-by: iko1 <me@remotecpp.dev>

* chore: update jsoncons dependency

Signed-off-by: iko1 <me@remotecpp.dev>

* chore: update jsoncons dependency

Signed-off-by: iko1 <me@remotecpp.dev>

---------

Signed-off-by: iko1 <me@remotecpp.dev>
This commit is contained in:
iko1 2023-07-11 09:17:22 +02:00 committed by GitHub
parent c27fa8d674
commit 37eedd4c8b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 40 additions and 23 deletions

View file

@ -61,8 +61,8 @@ set(REFLEX "${THIRD_PARTY_LIB_DIR}/reflex/bin/reflex")
add_third_party(
jsoncons
URL https://github.com/danielaparker/jsoncons/archive/refs/tags/v0.168.7.tar.gz
CMAKE_PASS_FLAGS "-DJSONCONS_BUILD_TESTS=OFF"
URL https://github.com/danielaparker/jsoncons/archive/refs/tags/v0.171.0.tar.gz
CMAKE_PASS_FLAGS "-DJSONCONS_BUILD_TESTS=OFF -DJSONCONS_HAS_POLYMORPHIC_ALLOCATOR=ON"
LIB "none"
)

View file

@ -1,15 +1,15 @@
// Copyright 2022, DragonflyDB authors. All rights reserved.
// Copyright 2023, DragonflyDB authors. All rights reserved.
// See LICENSE for licensing terms.
//
#include <jsoncons/json.hpp>
#include <jsoncons_ext/jsonpath/jsonpath.hpp>
#include <memory_resource>
#include "base/gtest.h"
#include "base/logging.h"
namespace dfly {
using namespace std;
using namespace jsoncons;
using namespace jsoncons::literals;
@ -20,7 +20,7 @@ class JsonTest : public ::testing::Test {
};
TEST_F(JsonTest, Basic) {
string data = R"(
std::string data = R"(
{
"application": "hiking",
"reputons": [
@ -69,7 +69,7 @@ TEST_F(JsonTest, Errors) {
json_decoder<json> decoder;
basic_json_parser<char> parser(basic_json_decode_options<char>{}, cb);
string_view input{"\000bla"};
std::string_view input{"\000bla"};
parser.update(input.data(), input.size());
parser.parse_some(decoder);
parser.finish_parse(decoder);
@ -101,19 +101,36 @@ TEST_F(JsonTest, Delete) {
EXPECT_EQ(R"({"c":{"a":1, "b":2}, "d":{"b":2, "c":3}, "e": [1,2]})"_json, j1);
}
TEST_F(JsonTest, DeleteExt) {
jsonpath::detail::static_resources<json, const json&> resources;
jsonpath::jsonpath_expression<json>::evaluator_t eval;
jsonpath::jsonpath_expression<json>::json_selector_t sel = eval.compile(resources, "$.d.*");
json j1 = R"({"c":{"a":1, "b":2}, "d":{"a":1, "b":2, "c":3}, "e": [1,2]})"_json;
TEST_F(JsonTest, JsonWithPolymorhicAllocator) {
char buffer[1024] = {};
std::pmr::monotonic_buffer_resource pool{std::data(buffer), std::size(buffer)};
std::pmr::polymorphic_allocator<char> alloc(&pool);
jsoncons::jsonpath::detail::dynamic_resources<json, const json&> dyn_res;
auto f = [](const jsonpath::json_location<char>& path, const json& val) {
LOG(INFO) << path.to_string();
};
sel.evaluate(dyn_res, j1, dyn_res.root_path_node(), j1, f, jsonpath::result_options::path);
std::string input = R"(
{ "store": {
"book": [
{ "category": "Roman",
"author": "Felix Lobrecht",
"title": "Sonne und Beton",
"price": 12.99
},
{ "category": "Roman",
"author": "Thomas F. Schneider",
"title": "Im Westen nichts Neues",
"price": 10.00
}
]
}
}
)";
auto j1 = pmr::json::parse(combine_allocators(alloc), input, json_options{});
EXPECT_EQ("Roman", j1["store"]["book"][0]["category"].as_string());
EXPECT_EQ("Felix Lobrecht", j1["store"]["book"][0]["author"].as_string());
EXPECT_EQ(12.99, j1["store"]["book"][0]["price"].as_double());
EXPECT_EQ("Roman", j1["store"]["book"][1]["category"].as_string());
EXPECT_EQ("Im Westen nichts Neues", j1["store"]["book"][1]["title"].as_string());
EXPECT_EQ(10.00, j1["store"]["book"][1]["price"].as_double());
}
} // namespace dfly

View file

@ -149,7 +149,7 @@ optional<vector<ClusterConfig::SlotRange>> GetClusterSlotRanges(const JsonType&
vector<ClusterConfig::SlotRange> ranges;
for (const auto& range : slots.array_value()) {
for (const auto& range : slots.array_range()) {
if (!range.is_object()) {
LOG(WARNING) << kInvalidConfigPrefix << "slot_ranges element is not an object " << range;
return nullopt;
@ -212,7 +212,7 @@ optional<ClusterConfig::ClusterShards> BuildClusterConfigFromJson(const JsonType
return nullopt;
}
for (const auto& element : json.array_value()) {
for (const auto& element : json.array_range()) {
ClusterConfig::ClusterShard shard;
if (!element.is_object()) {
@ -238,7 +238,7 @@ optional<ClusterConfig::ClusterShards> BuildClusterConfigFromJson(const JsonType
return nullopt;
}
for (const auto& replica : replicas.array_value()) {
for (const auto& replica : replicas.array_range()) {
auto node = ParseClusterNode(replica);
if (!node.has_value()) {
return nullopt;

View file

@ -462,7 +462,7 @@ OpResult<vector<OptSizeT>> OpObjLen(const OpArgs& op_args, string_view key,
vector<OptSizeT> vec;
auto cb = [&vec](const string_view& path, const JsonType& val) {
if (val.is_object()) {
vec.emplace_back(val.object_value().size());
vec.emplace_back(val.size());
} else {
vec.emplace_back(nullopt);
}
@ -483,7 +483,7 @@ OpResult<vector<OptSizeT>> OpArrLen(const OpArgs& op_args, string_view key,
vector<OptSizeT> vec;
auto cb = [&vec](const string_view& path, const JsonType& val) {
if (val.is_array()) {
vec.emplace_back(val.array_value().size());
vec.emplace_back(val.size());
} else {
vec.emplace_back(nullopt);
}