From 037862601086536c7526fe1fdd4493cc6793a6cb Mon Sep 17 00:00:00 2001 From: Daniel Parker Date: Tue, 14 Nov 2023 22:06:39 -0500 Subject: [PATCH] json_location --- .../{jsoncons => jsoncons_ext/jsonpath}/json_location.hpp | 6 ++++-- include/jsoncons_ext/jsonpath/path_node.hpp | 2 +- test/CMakeLists.txt | 2 +- test/{corelib => jsonpath}/src/json_location_tests.cpp | 8 ++++---- test/jsonpath/src/path_node_tests.cpp | 2 +- 5 files changed, 11 insertions(+), 9 deletions(-) rename include/{jsoncons => jsoncons_ext/jsonpath}/json_location.hpp (98%) rename test/{corelib => jsonpath}/src/json_location_tests.cpp (60%) diff --git a/include/jsoncons/json_location.hpp b/include/jsoncons_ext/jsonpath/json_location.hpp similarity index 98% rename from include/jsoncons/json_location.hpp rename to include/jsoncons_ext/jsonpath/json_location.hpp index 33cdb25392..ddf2f40388 100644 --- a/include/jsoncons/json_location.hpp +++ b/include/jsoncons_ext/jsonpath/json_location.hpp @@ -4,8 +4,8 @@ // See https://github.com/danielaparker/jsoncons for latest version -#ifndef JSONCONS_JSON_LOCATION_HPP -#define JSONCONS_JSON_LOCATION_HPP +#ifndef JSONCONS_JSONPATH_JSON_LOCATION_HPP +#define JSONCONS_JSONPATH_JSON_LOCATION_HPP #include #include @@ -17,6 +17,7 @@ #include namespace jsoncons { +namespace jsonpath { enum class path_element_kind { name, index }; @@ -234,6 +235,7 @@ namespace jsoncons { using path_element = basic_path_element>; using wpath_element = basic_path_element>; +} // namespace jsonpath } // namespace jsoncons #endif diff --git a/include/jsoncons_ext/jsonpath/path_node.hpp b/include/jsoncons_ext/jsonpath/path_node.hpp index 5e4adccc33..8d9af0b261 100644 --- a/include/jsoncons_ext/jsonpath/path_node.hpp +++ b/include/jsoncons_ext/jsonpath/path_node.hpp @@ -11,7 +11,7 @@ #include #include #include // std::reverse -#include +#include #include #include #include diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 1b95b1b756..96f4a5f85a 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -86,6 +86,7 @@ add_executable(unit_tests mergepatch/src/mergepatch_test_suite.cpp jsonpatch/src/jsonpatch_test_suite.cpp jsonpatch/src/jsonpatch_tests.cpp + jsonpath/src/json_location_tests.cpp jsonpath/src/jsonpath_flatten_tests.cpp jsonpath/src/path_node_tests.cpp jsonpath/src/jsonpath_custom_function_tests.cpp @@ -141,7 +142,6 @@ add_executable(unit_tests corelib/src/json_less_tests.cpp corelib/src/json_line_split_tests.cpp corelib/src/json_literal_operator_tests.cpp - corelib/src/json_location_tests.cpp corelib/src/json_object_tests.cpp corelib/src/ojson_object_tests.cpp corelib/src/json_options_tests.cpp diff --git a/test/corelib/src/json_location_tests.cpp b/test/jsonpath/src/json_location_tests.cpp similarity index 60% rename from test/corelib/src/json_location_tests.cpp rename to test/jsonpath/src/json_location_tests.cpp index 843b5c0b92..cc73da8749 100644 --- a/test/corelib/src/json_location_tests.cpp +++ b/test/jsonpath/src/json_location_tests.cpp @@ -1,7 +1,7 @@ // Copyright 2013-2023 Daniel Parker // Distributed under Boost license -#include +#include #include #include @@ -11,14 +11,14 @@ TEST_CASE("test json_location") { SECTION("test 1") { - json_location loc; + jsonpath::json_location loc; loc /= "foo"; loc /= 1; CHECK(loc.size() == 2); - CHECK(loc[0].element_kind() == path_element_kind::name); + CHECK(loc[0].element_kind() == jsonpath::path_element_kind::name); CHECK(loc[0].name() == "foo"); - CHECK(loc[1].element_kind() == path_element_kind::index); + CHECK(loc[1].element_kind() == jsonpath::path_element_kind::index); CHECK(loc[1].index() == 1); } } diff --git a/test/jsonpath/src/path_node_tests.cpp b/test/jsonpath/src/path_node_tests.cpp index b557ccbd6a..cdae313e25 100644 --- a/test/jsonpath/src/path_node_tests.cpp +++ b/test/jsonpath/src/path_node_tests.cpp @@ -129,7 +129,7 @@ TEST_CASE("test to_json_location") jsonpath::path_node a3(&a2,"bar"); jsonpath::path_node a4(&a3,7); - jsoncons::json_location location; + jsonpath::json_location location; location /= "foo"; location /= "bar"; location /= 7;