fixing the compilation issue with 3 test suites

This commit is contained in:
xcyang 2023-12-03 20:54:23 -05:00
parent 9cca280a4d
commit cd6fd3e823
4 changed files with 186 additions and 2 deletions

View File

@ -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 <compare>
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

83
tests/src/unit-make1.cpp Normal file
View File

@ -0,0 +1,83 @@
// test_json_suite_extended.cpp
#include "doctest_compatibility.h"
#include <nlohmann/json.hpp>
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.
}

49
tests/src/unit-make2.cpp Normal file
View File

@ -0,0 +1,49 @@
// test_json_suite.cpp
#include "doctest_compatibility.h"
#include <nlohmann/json.hpp>
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.
}

48
tests/src/unit-make3.cpp Normal file
View File

@ -0,0 +1,48 @@
// test_json_suite_more.cpp
#include "doctest_compatibility.h"
#include <nlohmann/json.hpp>
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.
}