From 44af0213717ef59a22f744eca78a4679a14ae113 Mon Sep 17 00:00:00 2001 From: Patrick Urbanke Date: Tue, 28 Nov 2023 20:07:24 +0100 Subject: [PATCH] Use a proper stack trace inside the tests --- tests/json/test_all_of.hpp | 3 +- tests/json/test_alphanumeric_map.hpp | 3 +- .../json/test_alphanumeric_unordered_map.hpp | 3 +- tests/json/test_anonymous_fields.hpp | 3 +- tests/json/test_any_of.hpp | 3 +- tests/json/test_array.hpp | 3 +- tests/json/test_as.hpp | 3 +- tests/json/test_as_flatten.hpp | 46 ++++++++------- tests/json/test_box.hpp | 3 +- tests/json/test_custom_class1.hpp | 3 +- tests/json/test_custom_class2.hpp | 3 +- tests/json/test_custom_class3.hpp | 3 +- tests/json/test_custom_class4.hpp | 3 +- tests/json/test_custom_constructor.hpp | 3 +- tests/json/test_default_values.hpp | 3 +- tests/json/test_deque.hpp | 3 +- tests/json/test_email.hpp | 3 +- tests/json/test_error_messages.hpp | 3 +- tests/json/test_field_variant.hpp | 3 +- tests/json/test_flatten.hpp | 3 +- tests/json/test_flatten_anonymous.hpp | 3 +- tests/json/test_flatten_tuple.hpp | 3 +- tests/json/test_forward_list.hpp | 3 +- tests/json/test_list.hpp | 3 +- tests/json/test_literal.hpp | 3 +- tests/json/test_literal_map.hpp | 3 +- tests/json/test_literal_unordered_map.hpp | 3 +- tests/json/test_map.hpp | 3 +- tests/json/test_map_with_key_validation.hpp | 3 +- tests/json/test_monster_example.hpp | 3 +- tests/json/test_move_replace.hpp | 3 +- tests/json/test_multimap.hpp | 3 +- tests/json/test_multiset.hpp | 3 +- tests/json/test_one_of.hpp | 3 +- tests/json/test_optional_fields.hpp | 3 +- tests/json/test_readme_example.hpp | 24 ++------ tests/json/test_ref.hpp | 3 +- tests/json/test_rename.hpp | 56 ------------------- tests/json/test_replace.hpp | 3 +- tests/json/test_replace_flatten.hpp | 3 +- tests/json/test_replace_with_other_struct.hpp | 3 +- tests/json/test_result.hpp | 3 +- tests/json/test_save_load.hpp | 3 +- tests/json/test_set.hpp | 3 +- tests/json/test_size.hpp | 3 +- tests/json/test_string_map.hpp | 3 +- tests/json/test_string_unordered_map.hpp | 3 +- tests/json/test_tagged_union.hpp | 3 +- tests/json/test_tagged_union2.hpp | 3 +- tests/json/test_timestamp.hpp | 3 +- tests/json/test_unique_ptr.hpp | 3 +- tests/json/test_unique_ptr2.hpp | 3 +- tests/json/test_unordered_map.hpp | 3 +- tests/json/test_unordered_multimap.hpp | 3 +- tests/json/test_unordered_multiset.hpp | 3 +- tests/json/test_unordered_set.hpp | 3 +- tests/json/test_variant.hpp | 3 +- tests/json/tests.cpp | 4 +- 58 files changed, 140 insertions(+), 152 deletions(-) delete mode 100644 tests/json/test_rename.hpp diff --git a/tests/json/test_all_of.hpp b/tests/json/test_all_of.hpp index 5003a9d6..eae5fe93 100644 --- a/tests/json/test_all_of.hpp +++ b/tests/json/test_all_of.hpp @@ -1,6 +1,7 @@ #include #include #include +#include #include #include @@ -17,7 +18,7 @@ struct Person { }; void test() { - std::cout << "test_all_of" << std::endl; + std::cout << std::source_location::current().function_name() << std::endl; const auto homer = Person{.first_name = "Homer", .last_name = "Simpson", .age = 45}; diff --git a/tests/json/test_alphanumeric_map.hpp b/tests/json/test_alphanumeric_map.hpp index a92c30e5..a2fca5ec 100644 --- a/tests/json/test_alphanumeric_map.hpp +++ b/tests/json/test_alphanumeric_map.hpp @@ -3,6 +3,7 @@ #include #include #include +#include #include #include "write_and_read.hpp" @@ -10,7 +11,7 @@ namespace test_alphanumeric_map { void test() { - std::cout << "test_alphanumeric_map" << std::endl; + std::cout << std::source_location::current().function_name() << std::endl; std::map> homer; homer.insert( diff --git a/tests/json/test_alphanumeric_unordered_map.hpp b/tests/json/test_alphanumeric_unordered_map.hpp index bb07dbe7..9dd15a19 100644 --- a/tests/json/test_alphanumeric_unordered_map.hpp +++ b/tests/json/test_alphanumeric_unordered_map.hpp @@ -2,6 +2,7 @@ #include #include #include +#include #include #include @@ -9,7 +10,7 @@ namespace test_alphanumeric_unordered_map { void test() { - std::cout << "test_alphanumeric_unordered_map" << std::endl; + std::cout << std::source_location::current().function_name() << std::endl; using Map = std::unordered_map>; diff --git a/tests/json/test_anonymous_fields.hpp b/tests/json/test_anonymous_fields.hpp index 405a2d64..f13aedcc 100644 --- a/tests/json/test_anonymous_fields.hpp +++ b/tests/json/test_anonymous_fields.hpp @@ -1,6 +1,7 @@ #include #include #include +#include #include #include @@ -21,7 +22,7 @@ struct Person { }; void test() { - std::cout << "test_anonymous_fields" << std::endl; + std::cout << std::source_location::current().function_name() << std::endl; const auto bart = Person{.first_name = "Bart", .last_name = "Simpson", diff --git a/tests/json/test_any_of.hpp b/tests/json/test_any_of.hpp index dbbdd5d5..390724f1 100644 --- a/tests/json/test_any_of.hpp +++ b/tests/json/test_any_of.hpp @@ -1,6 +1,7 @@ #include #include #include +#include #include #include @@ -20,7 +21,7 @@ struct Person { }; void test() { - std::cout << "test_any_of" << std::endl; + std::cout << std::source_location::current().function_name() << std::endl; const auto homer = Person{.first_name = "Homer", .last_name = "Simpson", .age = 45}; diff --git a/tests/json/test_array.hpp b/tests/json/test_array.hpp index bacd21a1..de51ddc8 100644 --- a/tests/json/test_array.hpp +++ b/tests/json/test_array.hpp @@ -3,6 +3,7 @@ #include #include #include +#include #include #include "write_and_read.hpp" @@ -16,7 +17,7 @@ struct Person { }; void test() { - std::cout << "test_array" << std::endl; + std::cout << std::source_location::current().function_name() << std::endl; auto bart = Person{.first_name = "Bart"}; diff --git a/tests/json/test_as.hpp b/tests/json/test_as.hpp index 87024573..c392c009 100644 --- a/tests/json/test_as.hpp +++ b/tests/json/test_as.hpp @@ -2,6 +2,7 @@ #include #include #include +#include #include #include @@ -26,7 +27,7 @@ struct C { }; void test() { - std::cout << "test_as" << std::endl; + std::cout << std::source_location::current().function_name() << std::endl; auto a = A{.f1 = "Hello", .f2 = rfl::make_box("World")}; diff --git a/tests/json/test_as_flatten.hpp b/tests/json/test_as_flatten.hpp index a50c7f68..69cda447 100644 --- a/tests/json/test_as_flatten.hpp +++ b/tests/json/test_as_flatten.hpp @@ -2,37 +2,41 @@ #include #include #include +#include #include #include #include "write_and_read.hpp" -void test_as_flatten() { - std::cout << "test_as_flatten" << std::endl; +namespace test_as_flatten { - struct A { - rfl::Field<"f1", std::string> f1; - rfl::Field<"f2", rfl::Box> f2; - }; +struct A { + rfl::Field<"f1", std::string> f1; + rfl::Field<"f2", rfl::Box> f2; +}; - struct B { - rfl::Field<"f3", std::string> f3; - rfl::Field<"f4", rfl::Box> f4; - }; +struct B { + rfl::Field<"f3", std::string> f3; + rfl::Field<"f4", rfl::Box> f4; +}; - struct C { - rfl::Flatten a; - rfl::Flatten b; - rfl::Field<"f5", int> f5; - }; +struct C { + rfl::Flatten a; + rfl::Flatten b; + rfl::Field<"f5", int> f5; +}; - auto a = A{.f1 = "Hello", .f2 = rfl::make_box("World")}; +void test() { + std::cout << std::source_location::current().function_name() << std::endl; - auto b = B{.f3 = "Hello", .f4 = rfl::make_box("World")}; + auto a = A{.f1 = "Hello", .f2 = rfl::make_box("World")}; - const auto c = - rfl::as(std::move(a), std::move(b), rfl::make_field<"f5">(5)); + auto b = B{.f3 = "Hello", .f4 = rfl::make_box("World")}; - write_and_read( - c, R"({"f1":"Hello","f2":"World","f3":"Hello","f4":"World","f5":5})"); + const auto c = + rfl::as(std::move(a), std::move(b), rfl::make_field<"f5">(5)); + + write_and_read( + c, R"({"f1":"Hello","f2":"World","f3":"Hello","f4":"World","f5":5})"); } +} // namespace test_as_flatten diff --git a/tests/json/test_box.hpp b/tests/json/test_box.hpp index 3e72b202..1e08f80c 100644 --- a/tests/json/test_box.hpp +++ b/tests/json/test_box.hpp @@ -2,6 +2,7 @@ #include #include #include +#include #include #include @@ -28,7 +29,7 @@ struct DecisionTree { }; void test() { - std::cout << "test_box" << std::endl; + std::cout << std::source_location::current().function_name() << std::endl; auto leaf1 = DecisionTree::Leaf{.value = 3.0}; diff --git a/tests/json/test_custom_class1.hpp b/tests/json/test_custom_class1.hpp index 0b4bbacf..468752b0 100644 --- a/tests/json/test_custom_class1.hpp +++ b/tests/json/test_custom_class1.hpp @@ -2,6 +2,7 @@ #include #include #include +#include #include #include @@ -30,7 +31,7 @@ struct Person { }; void test() { - std::cout << "test_custom_class1" << std::endl; + std::cout << std::source_location::current().function_name() << std::endl; const auto bart = Person("Bart"); diff --git a/tests/json/test_custom_class2.hpp b/tests/json/test_custom_class2.hpp index 9989be22..aff5b697 100644 --- a/tests/json/test_custom_class2.hpp +++ b/tests/json/test_custom_class2.hpp @@ -2,6 +2,7 @@ #include #include #include +#include #include #include #include @@ -29,7 +30,7 @@ struct FiveDigitCode { }; void test() { - std::cout << "test_custom_class2" << std::endl; + std::cout << std::source_location::current().function_name() << std::endl; const auto result = rfl::json::read("123"); diff --git a/tests/json/test_custom_class3.hpp b/tests/json/test_custom_class3.hpp index 89fe6b42..f65e22c1 100644 --- a/tests/json/test_custom_class3.hpp +++ b/tests/json/test_custom_class3.hpp @@ -2,6 +2,7 @@ #include #include #include +#include #include #include @@ -55,7 +56,7 @@ struct Parser namespace test_custom_class3 { void test() { - std::cout << "test_custom_class3" << std::endl; + std::cout << std::source_location::current().function_name() << std::endl; const auto bart = Person("Bart", "Simpson", 10); diff --git a/tests/json/test_custom_class4.hpp b/tests/json/test_custom_class4.hpp index ac89f574..5178acb4 100644 --- a/tests/json/test_custom_class4.hpp +++ b/tests/json/test_custom_class4.hpp @@ -2,6 +2,7 @@ #include #include #include +#include #include #include @@ -56,7 +57,7 @@ struct Parser namespace test_custom_class4 { void test() { - std::cout << "test_custom_class4" << std::endl; + std::cout << std::source_location::current().function_name() << std::endl; const auto bart = test_custom_class4::Person( "Bart", rfl::make_box("Simpson"), 10); diff --git a/tests/json/test_custom_constructor.hpp b/tests/json/test_custom_constructor.hpp index 028b4ad2..3ccd0c1a 100644 --- a/tests/json/test_custom_constructor.hpp +++ b/tests/json/test_custom_constructor.hpp @@ -1,6 +1,7 @@ #include #include #include +#include #include #include @@ -30,7 +31,7 @@ struct Person { }; void test() { - std::cout << "test_custom_constructor" << std::endl; + std::cout << std::source_location::current().function_name() << std::endl; const auto res = rfl::json::read( R"({"firstName":"Homer","lastName":"Simpson","birthday":"1987-04-19"})"); diff --git a/tests/json/test_default_values.hpp b/tests/json/test_default_values.hpp index f3fc04a3..b2854f48 100644 --- a/tests/json/test_default_values.hpp +++ b/tests/json/test_default_values.hpp @@ -2,6 +2,7 @@ #include #include #include +#include #include #include @@ -16,7 +17,7 @@ struct Person { }; void test() { - std::cout << "test_default_values" << std::endl; + std::cout << std::source_location::current().function_name() << std::endl; const auto bart = Person{.first_name = "Bart"}; const auto lisa = Person{.first_name = "Lisa"}; diff --git a/tests/json/test_deque.hpp b/tests/json/test_deque.hpp index 85e4bfae..66540ef2 100644 --- a/tests/json/test_deque.hpp +++ b/tests/json/test_deque.hpp @@ -1,6 +1,7 @@ #include #include #include +#include #include #include @@ -15,7 +16,7 @@ struct Person { }; void test() { - std::cout << "test_deque" << std::endl; + std::cout << std::source_location::current().function_name() << std::endl; auto children = std::make_unique>(); children->emplace_back(Person{.first_name = "Bart"}); diff --git a/tests/json/test_email.hpp b/tests/json/test_email.hpp index 82ff6bc5..74d3c90b 100644 --- a/tests/json/test_email.hpp +++ b/tests/json/test_email.hpp @@ -1,6 +1,7 @@ #include #include #include +#include #include #include @@ -15,7 +16,7 @@ struct Person { }; void test() { - std::cout << "test_email" << std::endl; + std::cout << std::source_location::current().function_name() << std::endl; const auto homer = Person{.first_name = "Homer", .last_name = "Simpson", diff --git a/tests/json/test_error_messages.hpp b/tests/json/test_error_messages.hpp index d318476b..adba716b 100644 --- a/tests/json/test_error_messages.hpp +++ b/tests/json/test_error_messages.hpp @@ -1,6 +1,7 @@ #include #include #include +#include #include #include @@ -16,7 +17,7 @@ struct Person { }; void test() { - std::cout << "test_error_messages" << std::endl; + std::cout << std::source_location::current().function_name() << std::endl; const std::string faulty_string = R"({"firstName":"Homer","lastName":12345,"birthday":"04/19/1987"})"; diff --git a/tests/json/test_field_variant.hpp b/tests/json/test_field_variant.hpp index 81ed6450..4b541ffc 100644 --- a/tests/json/test_field_variant.hpp +++ b/tests/json/test_field_variant.hpp @@ -2,6 +2,7 @@ #include #include #include +#include #include #include @@ -27,7 +28,7 @@ using Shapes = rfl::Variant, rfl::Field<"square", rfl::Box>>; void test() { - std::cout << "test_field_variant" << std::endl; + std::cout << std::source_location::current().function_name() << std::endl; const Shapes r = rfl::make_field<"rectangle">(Rectangle{.height = 10, .width = 5}); diff --git a/tests/json/test_flatten.hpp b/tests/json/test_flatten.hpp index f7cc7b2f..c2485755 100644 --- a/tests/json/test_flatten.hpp +++ b/tests/json/test_flatten.hpp @@ -2,6 +2,7 @@ #include #include #include +#include #include #include @@ -22,7 +23,7 @@ struct Employee { }; void test() { - std::cout << "test_flatten" << std::endl; + std::cout << std::source_location::current().function_name() << std::endl; const auto employee = Employee{ .person = Person{.first_name = "Homer", diff --git a/tests/json/test_flatten_anonymous.hpp b/tests/json/test_flatten_anonymous.hpp index 85050ae7..32dcdc07 100644 --- a/tests/json/test_flatten_anonymous.hpp +++ b/tests/json/test_flatten_anonymous.hpp @@ -2,6 +2,7 @@ #include #include #include +#include #include #include @@ -22,7 +23,7 @@ struct Employee { }; void test() { - std::cout << "test_flatten_anonymous" << std::endl; + std::cout << std::source_location::current().function_name() << std::endl; const auto employee = Employee{ .person = Person{.first_name = "Homer", diff --git a/tests/json/test_flatten_tuple.hpp b/tests/json/test_flatten_tuple.hpp index 81442cfb..ea640024 100644 --- a/tests/json/test_flatten_tuple.hpp +++ b/tests/json/test_flatten_tuple.hpp @@ -2,13 +2,14 @@ #include #include #include +#include #include #include #include "write_and_read.hpp" void test_flatten_tuple() { - std::cout << "test_flatten_tuple" << std::endl; + std::cout << std::source_location::current().function_name() << std::endl; using Person = std::tuple, int>; diff --git a/tests/json/test_forward_list.hpp b/tests/json/test_forward_list.hpp index db94a354..b4b87090 100644 --- a/tests/json/test_forward_list.hpp +++ b/tests/json/test_forward_list.hpp @@ -1,6 +1,7 @@ #include #include #include +#include #include #include @@ -15,7 +16,7 @@ struct Person { }; void test() { - std::cout << "test_forward_list" << std::endl; + std::cout << std::source_location::current().function_name() << std::endl; auto children = std::make_unique>(); children->emplace_front(Person{.first_name = "Maggie"}); diff --git a/tests/json/test_list.hpp b/tests/json/test_list.hpp index 71a7618d..d80efb65 100644 --- a/tests/json/test_list.hpp +++ b/tests/json/test_list.hpp @@ -1,6 +1,7 @@ #include #include #include +#include #include #include @@ -15,7 +16,7 @@ struct Person { }; void test() { - std::cout << "test_list" << std::endl; + std::cout << std::source_location::current().function_name() << std::endl; auto children = std::make_unique>(); children->emplace_back(Person{.first_name = "Bart"}); diff --git a/tests/json/test_literal.hpp b/tests/json/test_literal.hpp index a2ca8c03..2a666633 100644 --- a/tests/json/test_literal.hpp +++ b/tests/json/test_literal.hpp @@ -2,6 +2,7 @@ #include #include #include +#include #include #include @@ -19,7 +20,7 @@ struct Person { }; void test() { - std::cout << "test_literal" << std::endl; + std::cout << std::source_location::current().function_name() << std::endl; const auto bart = Person{.first_name = FirstName::make<"Bart">()}; diff --git a/tests/json/test_literal_map.hpp b/tests/json/test_literal_map.hpp index eba3ee3a..72281f50 100644 --- a/tests/json/test_literal_map.hpp +++ b/tests/json/test_literal_map.hpp @@ -3,6 +3,7 @@ #include #include #include +#include #include #include @@ -13,7 +14,7 @@ namespace test_literal_map { using FieldName = rfl::Literal<"firstName", "lastName">; void test() { - std::cout << "test_literal_map" << std::endl; + std::cout << std::source_location::current().function_name() << std::endl; std::map> homer; homer.insert(std::make_pair(FieldName::make<"firstName">(), diff --git a/tests/json/test_literal_unordered_map.hpp b/tests/json/test_literal_unordered_map.hpp index cb4149a6..8a41e494 100644 --- a/tests/json/test_literal_unordered_map.hpp +++ b/tests/json/test_literal_unordered_map.hpp @@ -4,6 +4,7 @@ #include #include #include +#include #include #include @@ -16,7 +17,7 @@ using FieldName = rfl::Literal<"firstName", "lastName">; using Map = std::unordered_map>; void test() { - std::cout << "test_literal_unordered_map" << std::endl; + std::cout << std::source_location::current().function_name() << std::endl; Map homer; diff --git a/tests/json/test_map.hpp b/tests/json/test_map.hpp index b73309a8..bb96439c 100644 --- a/tests/json/test_map.hpp +++ b/tests/json/test_map.hpp @@ -2,6 +2,7 @@ #include #include #include +#include #include #include "write_and_read.hpp" @@ -15,7 +16,7 @@ struct Person { }; void test() { - std::cout << "test_map" << std::endl; + std::cout << std::source_location::current().function_name() << std::endl; auto children = std::make_unique>(); children->insert(std::make_pair(1, Person{.first_name = "Bart"})); diff --git a/tests/json/test_map_with_key_validation.hpp b/tests/json/test_map_with_key_validation.hpp index 813eb892..ddd46c38 100644 --- a/tests/json/test_map_with_key_validation.hpp +++ b/tests/json/test_map_with_key_validation.hpp @@ -2,6 +2,7 @@ #include #include #include +#include #include #include "write_and_read.hpp" @@ -17,7 +18,7 @@ struct Person { }; void test() { - std::cout << "test_map_with_key_validation" << std::endl; + std::cout << std::source_location::current().function_name() << std::endl; auto children = std::make_unique>(); diff --git a/tests/json/test_monster_example.hpp b/tests/json/test_monster_example.hpp index 1b28378b..85d5a758 100644 --- a/tests/json/test_monster_example.hpp +++ b/tests/json/test_monster_example.hpp @@ -1,6 +1,7 @@ #include #include #include +#include #include #include @@ -37,7 +38,7 @@ struct Monster { }; void test() { - std::cout << "test_monster_example" << std::endl; + std::cout << std::source_location::current().function_name() << std::endl; const auto sword = Weapon{.name = "Sword", .damage = 3}; const auto axe = Weapon{.name = "Axe", .damage = 5}; diff --git a/tests/json/test_move_replace.hpp b/tests/json/test_move_replace.hpp index edb7ce1a..fae44c5c 100644 --- a/tests/json/test_move_replace.hpp +++ b/tests/json/test_move_replace.hpp @@ -2,6 +2,7 @@ #include #include #include +#include #include #include @@ -16,7 +17,7 @@ struct Person { }; void test() { - std::cout << "test_move_replace" << std::endl; + std::cout << std::source_location::current().function_name() << std::endl; const auto lisa = Person{.first_name = "Lisa", .last_name = "Simpson", diff --git a/tests/json/test_multimap.hpp b/tests/json/test_multimap.hpp index d7ae7a2d..0f875fd4 100644 --- a/tests/json/test_multimap.hpp +++ b/tests/json/test_multimap.hpp @@ -2,6 +2,7 @@ #include #include #include +#include #include #include "write_and_read.hpp" @@ -15,7 +16,7 @@ struct Person { }; void test() { - std::cout << "test_multimap" << std::endl; + std::cout << std::source_location::current().function_name() << std::endl; auto children = std::make_unique>(); children->insert(std::make_pair(1, Person{.first_name = "Bart"})); diff --git a/tests/json/test_multiset.hpp b/tests/json/test_multiset.hpp index c6eaa8bb..1335ee02 100644 --- a/tests/json/test_multiset.hpp +++ b/tests/json/test_multiset.hpp @@ -1,6 +1,7 @@ #include #include #include +#include #include #include @@ -15,7 +16,7 @@ struct Person { }; void test() { - std::cout << "test_multiset" << std::endl; + std::cout << std::source_location::current().function_name() << std::endl; auto children = std::make_unique>( std::multiset({"Bart", "Lisa", "Maggie"})); diff --git a/tests/json/test_one_of.hpp b/tests/json/test_one_of.hpp index 002e8bbb..51be48c7 100644 --- a/tests/json/test_one_of.hpp +++ b/tests/json/test_one_of.hpp @@ -1,6 +1,7 @@ #include #include #include +#include #include #include @@ -20,7 +21,7 @@ struct Person { }; void test() { - std::cout << "test_one_of" << std::endl; + std::cout << std::source_location::current().function_name() << std::endl; const auto homer = Person{.first_name = "Homer", .last_name = "Simpson", .age = 45}; diff --git a/tests/json/test_optional_fields.hpp b/tests/json/test_optional_fields.hpp index f97b9a5a..22adfb02 100644 --- a/tests/json/test_optional_fields.hpp +++ b/tests/json/test_optional_fields.hpp @@ -1,6 +1,7 @@ #include #include #include +#include #include #include @@ -15,7 +16,7 @@ struct Person { }; void test() { - std::cout << "test_optional_fields" << std::endl; + std::cout << std::source_location::current().function_name() << std::endl; const auto bart = Person{.first_name = "Bart"}; diff --git a/tests/json/test_readme_example.hpp b/tests/json/test_readme_example.hpp index 48df1ae3..649e9077 100644 --- a/tests/json/test_readme_example.hpp +++ b/tests/json/test_readme_example.hpp @@ -1,27 +1,20 @@ #include #include #include +#include #include #include #include "write_and_read.hpp" -// Makes sure that the example in the README works as expected. -// It would be embarrassing if it didn't... - namespace test_readme_example { -// Age must be a plausible number, between 0 and 130. This will -// be validated automatically. using Age = rfl::Validator, rfl::Maximum<130>>; -// "firstName", "lastName" and "children" are the field names -// as they will appear in the JSON. The C++ standard is -// snake case, the JSON standard is camel case, so the names -// will not always be identical. struct Person { rfl::Rename<"firstName", std::string> first_name; - rfl::Rename<"lastName", std::string> last_name; + rfl::Rename<"lastName", std::string> last_name = "Simpson"; + std::string town = "Springfield"; rfl::Timestamp<"%Y-%m-%d"> birthday; Age age; rfl::Email email; @@ -29,30 +22,25 @@ struct Person { }; void test() { - std::cout << "test_readme_example" << std::endl; + std::cout << std::source_location::current().function_name() << std::endl; const auto bart = Person{.first_name = "Bart", - .last_name = "Simpson", .birthday = "1987-04-19", .age = 10, - .email = "bart@simpson.com", - .children = std::vector()}; + .email = "bart@simpson.com"}; const auto lisa = Person{.first_name = "Lisa", - .last_name = "Simpson", .birthday = "1987-04-19", .age = 8, .email = "lisa@simpson.com"}; const auto maggie = Person{.first_name = "Maggie", - .last_name = "Simpson", .birthday = "1987-04-19", .age = 0, .email = "maggie@simpson.com"}; const auto homer = Person{.first_name = "Homer", - .last_name = "Simpson", .birthday = "1987-04-19", .age = 45, .email = "homer@simpson.com", @@ -60,6 +48,6 @@ void test() { write_and_read( homer, - R"({"firstName":"Homer","lastName":"Simpson","birthday":"1987-04-19","age":45,"email":"homer@simpson.com","children":[{"firstName":"Bart","lastName":"Simpson","birthday":"1987-04-19","age":10,"email":"bart@simpson.com","children":[]},{"firstName":"Lisa","lastName":"Simpson","birthday":"1987-04-19","age":8,"email":"lisa@simpson.com","children":[]},{"firstName":"Maggie","lastName":"Simpson","birthday":"1987-04-19","age":0,"email":"maggie@simpson.com","children":[]}]})"); + R"({"firstName":"Homer","lastName":"Simpson","town":"Springfield","birthday":"1987-04-19","age":45,"email":"homer@simpson.com","children":[{"firstName":"Bart","lastName":"Simpson","town":"Springfield","birthday":"1987-04-19","age":10,"email":"bart@simpson.com","children":[]},{"firstName":"Lisa","lastName":"Simpson","town":"Springfield","birthday":"1987-04-19","age":8,"email":"lisa@simpson.com","children":[]},{"firstName":"Maggie","lastName":"Simpson","town":"Springfield","birthday":"1987-04-19","age":0,"email":"maggie@simpson.com","children":[]}]})"); } } // namespace test_readme_example diff --git a/tests/json/test_ref.hpp b/tests/json/test_ref.hpp index c6929241..b85e4d2b 100644 --- a/tests/json/test_ref.hpp +++ b/tests/json/test_ref.hpp @@ -2,6 +2,7 @@ #include #include #include +#include #include #include @@ -28,7 +29,7 @@ struct DecisionTree { }; void test() { - std::cout << "test_ref" << std::endl; + std::cout << std::source_location::current().function_name() << std::endl; const auto leaf1 = DecisionTree::Leaf{.value = 3.0}; diff --git a/tests/json/test_rename.hpp b/tests/json/test_rename.hpp deleted file mode 100644 index b1cd38a3..00000000 --- a/tests/json/test_rename.hpp +++ /dev/null @@ -1,56 +0,0 @@ -#include -#include -#include -#include -#include - -#include "write_and_read.hpp" - -namespace test_rename { - -using Age = rfl::Validator, rfl::Maximum<130>>>; - -struct Person { - rfl::Rename<"firstName", std::string> first_name; - rfl::Rename<"lastName", std::string> last_name; - rfl::Timestamp<"%Y-%m-%d"> birthday; - Age age; - rfl::Email email; - std::vector children; -}; - -void test() { - std::cout << "test_anonymous_fields" << std::endl; - - const auto bart = Person{.first_name = "Bart", - .last_name = "Simpson", - .birthday = "1987-04-19", - .age = 10, - .email = "bart@simpson.com"}; - - const auto lisa = Person{.first_name = "Lisa", - .last_name = "Simpson", - .birthday = "1987-04-19", - .age = 8, - .email = "lisa@simpson.com"}; - - const auto maggie = Person{.first_name = "Maggie", - .last_name = "Simpson", - .birthday = "1987-04-19", - .age = 0, - .email = "maggie@simpson.com"}; - - const auto homer = - Person{.first_name = "Homer", - .last_name = "Simpson", - .birthday = "1987-04-19", - .age = 45, - .email = "homer@simpson.com", - .children = std::vector({bart, lisa, maggie})}; - - write_and_read( - homer, - R"({"firstName":"Homer","lastName":"Simpson","birthday":"1987-04-19","age":45,"email":"homer@simpson.com","children":[{"firstName":"Bart","lastName":"Simpson","birthday":"1987-04-19","age":10,"email":"bart@simpson.com","children":[]},{"firstName":"Lisa","lastName":"Simpson","birthday":"1987-04-19","age":8,"email":"lisa@simpson.com","children":[]},{"firstName":"Maggie","lastName":"Simpson","birthday":"1987-04-19","age":0,"email":"maggie@simpson.com","children":[]}]})"); -} -} // namespace test_rename diff --git a/tests/json/test_replace.hpp b/tests/json/test_replace.hpp index e2d328f7..d69eca37 100644 --- a/tests/json/test_replace.hpp +++ b/tests/json/test_replace.hpp @@ -2,6 +2,7 @@ #include #include #include +#include #include #include @@ -16,7 +17,7 @@ struct Person { }; void test() { - std::cout << "test_replace" << std::endl; + std::cout << std::source_location::current().function_name() << std::endl; auto lisa = Person{.first_name = "Lisa", .last_name = "Simpson", diff --git a/tests/json/test_replace_flatten.hpp b/tests/json/test_replace_flatten.hpp index c2f67d1e..9f22f8a3 100644 --- a/tests/json/test_replace_flatten.hpp +++ b/tests/json/test_replace_flatten.hpp @@ -2,6 +2,7 @@ #include #include #include +#include #include #include @@ -22,7 +23,7 @@ struct Employee { }; void test() { - std::cout << "test_replace_flatten" << std::endl; + std::cout << std::source_location::current().function_name() << std::endl; auto employee = Employee{ .person = Person{.first_name = "Homer", diff --git a/tests/json/test_replace_with_other_struct.hpp b/tests/json/test_replace_with_other_struct.hpp index cffccb7c..8f946a3f 100644 --- a/tests/json/test_replace_with_other_struct.hpp +++ b/tests/json/test_replace_with_other_struct.hpp @@ -2,6 +2,7 @@ #include #include #include +#include #include #include @@ -22,7 +23,7 @@ struct Employee { }; void test() { - std::cout << "test_replace_with_other_struct" << std::endl; + std::cout << std::source_location::current().function_name() << std::endl; const auto employee = Employee{ .person = diff --git a/tests/json/test_result.hpp b/tests/json/test_result.hpp index 59471b09..dddc6576 100644 --- a/tests/json/test_result.hpp +++ b/tests/json/test_result.hpp @@ -1,6 +1,7 @@ #include #include #include +#include #include #include @@ -15,7 +16,7 @@ struct Person { }; void test() { - std::cout << "test_result" << std::endl; + std::cout << std::source_location::current().function_name() << std::endl; const rfl::Result bart = Person{.first_name = "Bart"}; diff --git a/tests/json/test_save_load.hpp b/tests/json/test_save_load.hpp index 1998698c..72130d94 100644 --- a/tests/json/test_save_load.hpp +++ b/tests/json/test_save_load.hpp @@ -2,6 +2,7 @@ #include #include #include +#include #include #include @@ -20,7 +21,7 @@ struct Person { }; void test() { - std::cout << "test_save_load" << std::endl; + std::cout << std::source_location::current().function_name() << std::endl; const auto bart = Person{.first_name = "Bart", .last_name = "Simpson", diff --git a/tests/json/test_set.hpp b/tests/json/test_set.hpp index 2e98d91d..572f3f73 100644 --- a/tests/json/test_set.hpp +++ b/tests/json/test_set.hpp @@ -1,6 +1,7 @@ #include #include #include +#include #include #include @@ -15,7 +16,7 @@ struct Person { }; void test() { - std::cout << "test_set" << std::endl; + std::cout << std::source_location::current().function_name() << std::endl; auto children = std::make_unique>( std::set({"Bart", "Lisa", "Maggie"})); diff --git a/tests/json/test_size.hpp b/tests/json/test_size.hpp index ebc4729a..cc5c9c3b 100644 --- a/tests/json/test_size.hpp +++ b/tests/json/test_size.hpp @@ -1,6 +1,7 @@ #include #include #include +#include #include #include @@ -18,7 +19,7 @@ struct Person { }; void test() { - std::cout << "test_size" << std::endl; + std::cout << std::source_location::current().function_name() << std::endl; const auto bart = Person{ .first_name = "Bart", .last_name = "Simpson", .birthday = "1987-04-19"}; diff --git a/tests/json/test_string_map.hpp b/tests/json/test_string_map.hpp index 5920cb0a..628c5f7d 100644 --- a/tests/json/test_string_map.hpp +++ b/tests/json/test_string_map.hpp @@ -3,13 +3,14 @@ #include #include #include +#include #include #include "write_and_read.hpp" namespace test_string_map { void test() { - std::cout << "test_string_map" << std::endl; + std::cout << std::source_location::current().function_name() << std::endl; std::map> homer; homer.insert( diff --git a/tests/json/test_string_unordered_map.hpp b/tests/json/test_string_unordered_map.hpp index 35f86960..d3796093 100644 --- a/tests/json/test_string_unordered_map.hpp +++ b/tests/json/test_string_unordered_map.hpp @@ -2,6 +2,7 @@ #include #include #include +#include #include #include @@ -9,7 +10,7 @@ namespace test_string_unordered_map { void test() { - std::cout << "test_string_unordered_map" << std::endl; + std::cout << std::source_location::current().function_name() << std::endl; using Map = std::unordered_map>; Map homer; diff --git a/tests/json/test_tagged_union.hpp b/tests/json/test_tagged_union.hpp index 0246ee55..c8cf5f78 100644 --- a/tests/json/test_tagged_union.hpp +++ b/tests/json/test_tagged_union.hpp @@ -2,6 +2,7 @@ #include #include #include +#include #include #include @@ -25,7 +26,7 @@ struct Square { using Shapes = rfl::TaggedUnion<"shape", Circle, Square, Rectangle>; void test() { - std::cout << "test_tagged_union" << std::endl; + std::cout << std::source_location::current().function_name() << std::endl; const Shapes r = Rectangle{.height = 10, .width = 5}; diff --git a/tests/json/test_tagged_union2.hpp b/tests/json/test_tagged_union2.hpp index 03c89fd8..3dac1168 100644 --- a/tests/json/test_tagged_union2.hpp +++ b/tests/json/test_tagged_union2.hpp @@ -2,6 +2,7 @@ #include #include #include +#include #include #include @@ -28,7 +29,7 @@ struct Square { using Shapes = rfl::TaggedUnion<"shape", Circle, Square, Rectangle>; void test() { - std::cout << "test_tagged_union2" << std::endl; + std::cout << std::source_location::current().function_name() << std::endl; const Shapes r = Rectangle{.height = 10, .width = 5}; diff --git a/tests/json/test_timestamp.hpp b/tests/json/test_timestamp.hpp index f8cde9aa..62f5a0c6 100644 --- a/tests/json/test_timestamp.hpp +++ b/tests/json/test_timestamp.hpp @@ -2,6 +2,7 @@ #include #include #include +#include #include #include @@ -18,7 +19,7 @@ struct Person { }; void test() { - std::cout << "test_timestamp" << std::endl; + std::cout << std::source_location::current().function_name() << std::endl; const auto result = TS::from_string("nonsense"); diff --git a/tests/json/test_unique_ptr.hpp b/tests/json/test_unique_ptr.hpp index fb24cfcd..c36e2d92 100644 --- a/tests/json/test_unique_ptr.hpp +++ b/tests/json/test_unique_ptr.hpp @@ -2,6 +2,7 @@ #include #include #include +#include #include #include @@ -16,7 +17,7 @@ struct Person { }; void test() { - std::cout << "test_unique_ptr" << std::endl; + std::cout << std::source_location::current().function_name() << std::endl; auto children = std::make_unique>(); children->emplace_back(Person{.first_name = "Bart"}); diff --git a/tests/json/test_unique_ptr2.hpp b/tests/json/test_unique_ptr2.hpp index 8263afa5..085db6aa 100644 --- a/tests/json/test_unique_ptr2.hpp +++ b/tests/json/test_unique_ptr2.hpp @@ -2,6 +2,7 @@ #include #include #include +#include #include #include @@ -28,7 +29,7 @@ struct DecisionTree { }; void test() { - std::cout << "test_unique_ptr2" << std::endl; + std::cout << std::source_location::current().function_name() << std::endl; auto leaf1 = DecisionTree::Leaf{.value = 3.0}; diff --git a/tests/json/test_unordered_map.hpp b/tests/json/test_unordered_map.hpp index 980a9917..bc2fccd0 100644 --- a/tests/json/test_unordered_map.hpp +++ b/tests/json/test_unordered_map.hpp @@ -1,6 +1,7 @@ #include #include #include +#include #include #include @@ -15,7 +16,7 @@ struct Person { }; void test() { - std::cout << "test_unordered_map" << std::endl; + std::cout << std::source_location::current().function_name() << std::endl; auto children = std::make_unique>(); children->insert(std::make_pair(1, Person{.first_name = "Bart"})); diff --git a/tests/json/test_unordered_multimap.hpp b/tests/json/test_unordered_multimap.hpp index 3e82d255..7662d0ee 100644 --- a/tests/json/test_unordered_multimap.hpp +++ b/tests/json/test_unordered_multimap.hpp @@ -2,6 +2,7 @@ #include #include #include +#include #include #include "write_and_read.hpp" @@ -15,7 +16,7 @@ struct Person { }; void test() { - std::cout << "test_unordered_multimap" << std::endl; + std::cout << std::source_location::current().function_name() << std::endl; auto children = std::make_unique>(); children->insert(std::make_pair(1, Person{.first_name = "Bart"})); diff --git a/tests/json/test_unordered_multiset.hpp b/tests/json/test_unordered_multiset.hpp index 15a5d7d1..40ce4401 100644 --- a/tests/json/test_unordered_multiset.hpp +++ b/tests/json/test_unordered_multiset.hpp @@ -1,6 +1,7 @@ #include #include #include +#include #include #include @@ -15,7 +16,7 @@ struct Person { }; void test() { - std::cout << "test_unordered_multiset" << std::endl; + std::cout << std::source_location::current().function_name() << std::endl; auto children = std::make_unique>( std::unordered_multiset({"Bart", "Lisa", "Maggie"})); diff --git a/tests/json/test_unordered_set.hpp b/tests/json/test_unordered_set.hpp index c4ced669..0cea2752 100644 --- a/tests/json/test_unordered_set.hpp +++ b/tests/json/test_unordered_set.hpp @@ -1,6 +1,7 @@ #include #include #include +#include #include #include @@ -15,7 +16,7 @@ struct Person { }; void test() { - std::cout << "test_unordered_set" << std::endl; + std::cout << std::source_location::current().function_name() << std::endl; auto children = std::make_unique>( std::unordered_set({"Bart", "Lisa", "Maggie"})); diff --git a/tests/json/test_variant.hpp b/tests/json/test_variant.hpp index 520489b8..24bdabc1 100644 --- a/tests/json/test_variant.hpp +++ b/tests/json/test_variant.hpp @@ -2,6 +2,7 @@ #include #include #include +#include #include #include @@ -25,7 +26,7 @@ struct Square { using Shapes = std::variant>; void test() { - std::cout << "test_variant" << std::endl; + std::cout << std::source_location::current().function_name() << std::endl; const Shapes r = Rectangle{.height = 10, .width = 5}; diff --git a/tests/json/tests.cpp b/tests/json/tests.cpp index a9c8784e..ab6796ab 100644 --- a/tests/json/tests.cpp +++ b/tests/json/tests.cpp @@ -33,7 +33,6 @@ #include "test_optional_fields.hpp" #include "test_readme_example.hpp" #include "test_ref.hpp" -#include "test_rename.hpp" #include "test_replace.hpp" #include "test_replace_flatten.hpp" #include "test_replace_with_other_struct.hpp" @@ -71,7 +70,6 @@ int main() { test_timestamp::test(); test_flatten::test(); test_flatten_anonymous::test(); - test_rename::test(); test_deque::test(); test_forward_list::test(); test_list::test(); @@ -104,7 +102,7 @@ int main() { test_replace_flatten::test(); test_replace_with_other_struct::test(); test_as::test(); - test_as_flatten(); + test_as_flatten::test(); test_custom_constructor::test();