Tests: cover the remaining lines of the library headers

Add tests for the lines of include/nlohmann that were not covered: the
binary readers and writers, the lexer and locale paths, the json_view
modules, the custom number, key and array types, json_pointer, json_patch,
diff and the iterators.

Signed-off-by: Niels Lohmann <mail@nlohmann.me>
This commit is contained in:
Niels Lohmann committed 2026-11-01 22:32:42 +01:00
1 parent d7b9472173
commit 056ba3b7c1
33 files changed
+1627 -1

No files matched your search

+19
View File
@@ -18,6 +18,8 @@
#include <nlohmann/json.hpp>
using nlohmann::json;
#include <iterator>
#if JSON_HAS_RANGES
#include <algorithm>
#include <ranges>
@@ -665,6 +667,23 @@ TEST_CASE("iterators 2")
}
}
SECTION("reverse iterators of a const value")
{
const json j_array = {1, 2, 3};
const json j_object = {{"one", 1}, {"two", 2}};
// rbegin() and rend() of a const value are crbegin() and crend()
CHECK(j_array.rbegin() == j_array.crbegin());
CHECK(j_array.rend() == j_array.crend());
CHECK(*j_array.rbegin() == 3);
CHECK(std::distance(j_array.rbegin(), j_array.rend()) == 3);
CHECK(j_object.rbegin() == j_object.crbegin());
CHECK(j_object.rend() == j_object.crend());
CHECK(j_object.rbegin().key() == "two");
CHECK(std::distance(j_object.rbegin(), j_object.rend()) == 2);
}
SECTION("reverse iterator arithmetic")
{
json j_object = {{"one", 1}, {"two", 2}, {"three", 3}};