Skip to content

Commit

Permalink
Add unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
falbrechtskirchinger committed Aug 7, 2022
1 parent 5fe8b92 commit aecfa16
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions tests/src/unit-json_pointer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ using nlohmann::json;
using namespace nlohmann::literals; // NOLINT(google-build-using-namespace)
#endif

#include <map>
#include <sstream>

TEST_CASE("JSON pointers")
Expand Down Expand Up @@ -697,6 +698,31 @@ TEST_CASE("JSON pointers")
}
}

SECTION("less-than comparison")
{
auto ptr1 = json::json_pointer("/foo/a");
auto ptr2 = json::json_pointer("/foo/b");

CHECK(ptr1 < ptr2);

// build with C++20
// JSON_HAS_CPP_20
#if JSON_HAS_THREE_WAY_COMPARISON
CHECK((ptr1 <=> ptr2) == std::strong_ordering::less); // *NOPAD*
CHECK(ptr2 > ptr1);
#endif
}

SECTION("usable as map key")
{
auto ptr = json::json_pointer("/foo");
std::map<json::json_pointer, int> m;

m[ptr] = 42;

CHECK(m.find(ptr) != m.end());
}

SECTION("backwards compatibility and mixing")
{
json j = R"(
Expand Down

0 comments on commit aecfa16

Please sign in to comment.