diff --git a/docs/Makefile b/docs/Makefile index 35c30daefb..739e5c57e5 100644 --- a/docs/Makefile +++ b/docs/Makefile @@ -15,8 +15,11 @@ cxx_standard = $(lastword c++11 $(filter c++%, $(subst ., ,$1))) %.output: %.cpp @echo "standard $(call cxx_standard $(<:.cpp=))" $(MAKE) $(<:.cpp=) \ - CPPFLAGS="-I $(SRCDIR) -DJSON_USE_GLOBAL_UDLS=0" \ - CXXFLAGS="-std=$(call cxx_standard,$(<:.cpp=)) -Wno-deprecated-declarations" + + CPPFLAGS="-I ../single_include -DJSON_USE_GLOBAL_UDLS=0" \ + CXXFLAGS="-std=c++2a -Wno-deprecated-declarations" + CPPFLAGS += -include + examples/operator_spaceship__const_reference.c++20: examples/operator_spaceship__const_reference.c++20.cpp $(CXX) $(CXXFLAGS) $(CPPFLAGS) $< -o $@ ./$(<:.cpp=) > $@ rm $(<:.cpp=) @@ -41,5 +44,6 @@ check_output_portable: $(filter-out examples/meta.test examples/max_size.test ex clean: rm -fr $(EXAMPLES:.cpp=) + rm -f examples/operator_spaceship__const_reference.c++20 $(MAKE) clean -C docset $(MAKE) clean -C mkdocs diff --git a/tests/src/unit-make1.cpp b/tests/src/unit-make1.cpp new file mode 100644 index 0000000000..63175b6a4a --- /dev/null +++ b/tests/src/unit-make1.cpp @@ -0,0 +1,92 @@ +// __ _____ _____ _____ +// __| | __| | | | JSON for Modern C++ (supporting code) +// | | |__ | | | | | | version 3.11.3 +// |_____|_____|_____|_|___| https://github.com/nlohmann/json +// +// SPDX-FileCopyrightText: 2013-2023 Niels Lohmann +// SPDX-License-Identifier: MIT + +#include "doctest_compatibility.h" + +#include +#include +using nlohmann::json; + +TEST_SUITE("nlohmann/json test suite - Extended") +{ + TEST_CASE("Nested Structures") + { + SECTION("Nested Objects") + { + json nested_object = { + {"person", { + {"name", "Bob"}, + {"age", 40}, + {"address", { + {"city", "Example City"}, + {"zip", "12345"} + }} + }} + }; + + CHECK(nested_object["person"]["name"] == "Bob"); + CHECK(nested_object["person"]["address"]["city"] == "Example City"); + } + + SECTION("Nested Arrays") + { + json nested_array = { + {"numbers", {1, 2, {3, 4}, 5}} + }; + + CHECK(nested_array["numbers"][2][1] == 4); + } + } + + TEST_CASE("Exception Handling") + { + SECTION("Parsing Invalid JSON") + { + // Expecting a parse error for invalid JSON + CHECK_THROWS_AS(json::parse("invalid_json_string"), json::parse_error); + } + + SECTION("Accessing Nonexistent Key") + { + json object = {{"name", "Alice"}, {"age", 25}}; + + // Expecting an exception when accessing a nonexistent key + CHECK_THROWS_AS(object.at("nonexistent_key"), json::out_of_range); + } + } + + TEST_CASE("Additional Serialization and Deserialization") + { + SECTION("Serialize and Deserialize with Custom Format") + { + json data = {{"key1", 42}, {"key2", "value"}}; + + // Serialize with indentation for human-readable format + std::string serialized = data.dump(2); + + // Deserialize the serialized string + json parsed = json::parse(serialized); + + CHECK(parsed == data); + } + + // SECTION("Deserialize from Stream") + // { + // std::istringstream stream(R"({"name": "Charlie", "age": 35})"); + + // // Deserialize from the input stream + // json parsed; + // stream >> parsed; + + // CHECK(parsed["name"] == "Charlie"); + // CHECK(parsed["age"] == 35); + // } + } + + // Add more test cases and sections as needed to cover other functionalities. +} \ No newline at end of file diff --git a/tests/src/unit-make2.cpp b/tests/src/unit-make2.cpp new file mode 100644 index 0000000000..91d2da85d7 --- /dev/null +++ b/tests/src/unit-make2.cpp @@ -0,0 +1,58 @@ +// __ _____ _____ _____ +// __| | __| | | | JSON for Modern C++ (supporting code) +// | | |__ | | | | | | version 3.11.3 +// |_____|_____|_____|_|___| https://github.com/nlohmann/json +// +// SPDX-FileCopyrightText: 2013-2023 Niels Lohmann +// SPDX-License-Identifier: MIT + +#include "doctest_compatibility.h" + +#include +#include +using nlohmann::json; + +TEST_SUITE("nlohmann/json test suite") +{ + TEST_CASE("Basic JSON Operations") + { + SECTION("Construction and Type Checks") + { + json number = 42; + json text = "Hello, JSON!"; + json array = {1, 2, 3}; + json object = {{"key", "value"}}; + + CHECK(number.is_number()); + CHECK(text.is_string()); + CHECK(array.is_array()); + CHECK(object.is_object()); + } + + SECTION("Serialization and Deserialization") + { + json original = {{"name", "John"}, {"age", 30}}; + std::string serialized = original.dump(); + json parsed = json::parse(serialized); + + CHECK(parsed == original); + } + + SECTION("Array and Object Operations") + { + json array = {1, 2, 3}; + array.push_back(4); + array.insert(array.begin() + 1, 10); + + CHECK(array.size() == 5); + CHECK(array[1] == 10); + + json object = {{"name", "Alice"}, {"age", 25}}; + object["city"] = "Wonderland"; + + CHECK(object["city"] == "Wonderland"); + } + } + + // Add more test cases and sections as needed to cover other functionalities. +} \ No newline at end of file diff --git a/tests/src/unit-make3.cpp b/tests/src/unit-make3.cpp new file mode 100644 index 0000000000..edaf76b979 --- /dev/null +++ b/tests/src/unit-make3.cpp @@ -0,0 +1,57 @@ +// __ _____ _____ _____ +// __| | __| | | | JSON for Modern C++ (supporting code) +// | | |__ | | | | | | version 3.11.3 +// |_____|_____|_____|_|___| https://github.com/nlohmann/json +// +// SPDX-FileCopyrightText: 2013-2023 Niels Lohmann +// SPDX-License-Identifier: MIT + +#include "doctest_compatibility.h" + +#include +#include +using nlohmann::json; + +TEST_SUITE("nlohmann/json test suite - More") +{ + TEST_CASE("Comparing JSON Objects") + { + SECTION("Ordering of Object Keys Matters") + { + json object1 = { + {"name", "Alice"}, + {"age", 25}, + {"city", "Wonderland"} + }; + + json object2 = { + {"name", "Alice"}, + {"city", "Wonderland"}, + {"age", 25} + }; + + // Expecting the objects to be different due to key order + CHECK(object1 != object2); + } + + SECTION("Ordering of Object Keys Doesn't Matter") + { + json object1 = { + {"name", "Bob"}, + {"age", 30}, + {"city", "Example City"} + }; + + json object2 = { + {"age", 30}, + {"name", "Bob"}, + {"city", "Example City"} + }; + + // Expecting the objects to be considered equal + CHECK(object1 == object2); + } + } + + // Add more test cases and sections as needed to cover other functionalities. +} \ No newline at end of file