mirror of
https://github.com/nlohmann/json.git
synced 2026-11-02 19:05:35 +00:00
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:
33 files changed
+1627
-1
No files matched your search
@@ -12,7 +12,10 @@
|
||||
using nlohmann::json;
|
||||
|
||||
#include <algorithm>
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
|
||||
TEST_CASE("tests on very large JSONs")
|
||||
{
|
||||
@@ -140,6 +143,56 @@ TEST_CASE("tests on deeply nested JSONs")
|
||||
}
|
||||
}
|
||||
|
||||
SECTION("leaf values of every type below the bound of the recursive descent")
|
||||
{
|
||||
// the elements and members of the containers below the bound are
|
||||
// copied one by one, whatever their type
|
||||
const json leaves = json::array(
|
||||
{
|
||||
nullptr, true, false, -1, std::uint64_t{1}, 1.5, "text", json::binary({1, 2, 3})
|
||||
});
|
||||
const json members =
|
||||
{
|
||||
{"null", nullptr}, {"boolean", true}, {"integer", -1}, {"unsigned", std::uint64_t{1}},
|
||||
{"float", 1.5}, {"string", "text"}, {"binary", json::binary({1, 2, 3})}
|
||||
};
|
||||
|
||||
for (const bool objects :
|
||||
{
|
||||
false, true
|
||||
})
|
||||
{
|
||||
CAPTURE(objects)
|
||||
|
||||
json j = objects ? members : leaves;
|
||||
for (std::size_t i = 0; i < 300; ++i)
|
||||
{
|
||||
json wrapper = objects ? json::object() : json::array();
|
||||
if (objects)
|
||||
{
|
||||
wrapper["a"] = std::move(j);
|
||||
}
|
||||
else
|
||||
{
|
||||
wrapper.push_back(std::move(j));
|
||||
}
|
||||
j = std::move(wrapper);
|
||||
}
|
||||
|
||||
const json copy(j); // NOLINT(performance-unnecessary-copy-initialization): the copy is what is tested
|
||||
|
||||
const json* current = ©
|
||||
for (std::size_t i = 0; i < 300; ++i)
|
||||
{
|
||||
current = objects ? ¤t->at("a") : ¤t->front();
|
||||
}
|
||||
|
||||
// the innermost value is shallow: it is safe to compare
|
||||
CHECK(*current == (objects ? members : leaves));
|
||||
CHECK(current->size() == (objects ? members.size() : leaves.size()));
|
||||
}
|
||||
}
|
||||
|
||||
SECTION("a value that is deep in one place only")
|
||||
{
|
||||
json j = json::object();
|
||||
|
||||
Reference in new issue
Block a user