// __ _____ _____ _____
// __| | __| | | | JSON for Modern C++ (supporting code)
// | | |__ | | | | | | version 3.10.5
// |_____|_____|_____|_|___| https://github.com/nlohmann/json
//
// SPDX-FileCopyrightText: 2013-2022 Niels Lohmann <https://nlohmann.me>
// SPDX-License-Identifier: MIT
#include "doctest_compatibility.h"
#include <nlohmann/json.hpp>
using nlohmann::json;
TEST_CASE("other constructors and destructor")
{
SECTION("copy constructor")
SECTION("object")
json j {{"foo", 1}, {"bar", false}};
json k(j); // NOLINT(performance-unnecessary-copy-initialization)
CHECK(j == k);
}
SECTION("array")
json j {"foo", 1, 42.23, false};
SECTION("null")
json j(nullptr);
SECTION("boolean")
json j(true);
SECTION("string")
json j("Hello world");
SECTION("number (integer)")
json j(42);
SECTION("number (unsigned)")
json j(42u);
SECTION("number (floating-point)")
json j(42.23);
SECTION("binary")
json j = json::binary({1, 2, 3});
SECTION("move constructor")
json j {{"foo", "bar"}, {"baz", {1, 2, 3, 4}}, {"a", 42u}, {"b", 42.23}, {"c", nullptr}};
CHECK(j.type() == json::value_t::object);
json k(std::move(j));
CHECK(k.type() == json::value_t::object);
CHECK(j.type() == json::value_t::null); // NOLINT: access after move is OK here
SECTION("copy assignment")
json k;
k = j;
SECTION("destructor")
auto* j = new json {{"foo", 1}, {"bar", false}}; // NOLINT(cppcoreguidelines-owning-memory)
delete j; // NOLINT(cppcoreguidelines-owning-memory)
auto* j = new json {"foo", 1, 1u, false, 23.42}; // NOLINT(cppcoreguidelines-owning-memory)
auto* j = new json("Hello world"); // NOLINT(cppcoreguidelines-owning-memory)