mirror of
https://github.com/dragonflydb/dragonfly.git
synced 2024-12-15 17:51:06 +00:00
Add jsoncons library as third-party dependency
This commit is contained in:
parent
4e4ed63467
commit
ad6e904a53
3 changed files with 57 additions and 0 deletions
|
@ -15,6 +15,19 @@ add_third_party(
|
|||
LIB libdouble-conversion.a
|
||||
)
|
||||
|
||||
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"
|
||||
|
||||
LIB "none"
|
||||
)
|
||||
|
||||
add_library(TRDP::jsoncons INTERFACE IMPORTED)
|
||||
add_dependencies(TRDP::jsoncons jsoncons_project)
|
||||
set_target_properties(TRDP::jsoncons PROPERTIES
|
||||
INTERFACE_INCLUDE_DIRECTORIES "${JSONCONS_INCLUDE_DIR}")
|
||||
|
||||
Message(STATUS "THIRD_PARTY_LIB_DIR ${THIRD_PARTY_LIB_DIR}")
|
||||
|
||||
|
||||
|
|
|
@ -14,3 +14,4 @@ cxx_test(extent_tree_test dfly_core LABELS DFLY)
|
|||
cxx_test(external_alloc_test dfly_core LABELS DFLY)
|
||||
cxx_test(dash_test dfly_core LABELS DFLY)
|
||||
cxx_test(interpreter_test dfly_core LABELS DFLY)
|
||||
cxx_test(json_test dfly_core TRDP::jsoncons LABELS DFLY)
|
||||
|
|
43
src/core/json_test.cc
Normal file
43
src/core/json_test.cc
Normal file
|
@ -0,0 +1,43 @@
|
|||
// Copyright 2022, Roman Gershman. All rights reserved.
|
||||
// See LICENSE for licensing terms.
|
||||
//
|
||||
|
||||
#include <jsoncons/json.hpp>
|
||||
#include <jsoncons_ext/jsonpath/jsonpath.hpp>
|
||||
|
||||
#include "base/gtest.h"
|
||||
#include "base/logging.h"
|
||||
|
||||
namespace dfly {
|
||||
using namespace std;
|
||||
using namespace jsoncons;
|
||||
|
||||
class JsonTest : public ::testing::Test {
|
||||
protected:
|
||||
JsonTest() {
|
||||
}
|
||||
};
|
||||
|
||||
TEST_F(JsonTest, Basic) {
|
||||
string data = R"(
|
||||
{
|
||||
"application": "hiking",
|
||||
"reputons": [
|
||||
{
|
||||
"rater": "HikingAsylum",
|
||||
"assertion": "advanced",
|
||||
"rated": "Marilyn C",
|
||||
"rating": 0.90,
|
||||
"confidence": 0.99
|
||||
}
|
||||
]
|
||||
}
|
||||
)";
|
||||
|
||||
json j = json::parse(data);
|
||||
EXPECT_TRUE(j.contains("reputons"));
|
||||
jsonpath::json_replace(j, "$.reputons[*].rating", 1.1);
|
||||
EXPECT_EQ(1.1, j["reputons"][0]["rating"].as_double());
|
||||
}
|
||||
|
||||
} // namespace dfly
|
Loading…
Reference in a new issue