Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add regression test #2960

Merged
merged 1 commit into from
Aug 20, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion test/src/unit-regression2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ SOFTWARE.

#define JSON_TESTS_PRIVATE
#include <nlohmann/json.hpp>
using nlohmann::json;
using json = nlohmann::json;
using ordered_json = nlohmann::ordered_json;

#include <list>
#include <cstdio>
Expand Down Expand Up @@ -659,6 +660,25 @@ TEST_CASE("regression tests 2")
{
static_assert(std::is_copy_assignable<nlohmann::ordered_json>::value, "");
}

SECTION("issue #2958 - Inserting in unordered json using a pointer retains the leading slash")
{
std::string p = "/root";

// matching types
json test1;
test1[json::json_pointer(p)] = json::object();
CHECK(test1.dump() == "{\"root\":{}}");

ordered_json test2;
test2[ordered_json::json_pointer(p)] = json::object();
CHECK(test2.dump() == "{\"root\":{}}");

// mixed type - the JSON Pointer is implicitly converted into a string "/root"
ordered_json test3;
test3[json::json_pointer(p)] = json::object();
CHECK(test3.dump() == "{\"/root\":{}}");
}
}

DOCTEST_CLANG_SUPPRESS_WARNING_POP