From 12528fe28b8d12eca65ae23d233a48d2bc34160d Mon Sep 17 00:00:00 2001 From: Patrick Urbanke Date: Wed, 29 Nov 2023 19:54:58 +0100 Subject: [PATCH] Updated the flexbuffers tests --- tests/flexbuffers/test_all_of.hpp | 8 ++- tests/flexbuffers/test_anonymous_fields.hpp | 28 ++++---- tests/flexbuffers/test_box.hpp | 38 ++++++----- tests/flexbuffers/test_custom_class1.hpp | 41 ++++++------ tests/flexbuffers/test_custom_class2.hpp | 21 +++--- tests/flexbuffers/test_custom_class3.hpp | 23 ++++--- tests/flexbuffers/test_custom_constructor.hpp | 48 +++++++------- tests/flexbuffers/test_deque.hpp | 34 +++++----- tests/flexbuffers/test_field_variant.hpp | 34 +++++----- tests/flexbuffers/test_flatten_anonymous.hpp | 28 ++++---- tests/flexbuffers/test_forward_list.hpp | 34 +++++----- tests/flexbuffers/test_list.hpp | 34 +++++----- tests/flexbuffers/test_literal.hpp | 23 ++++--- tests/flexbuffers/test_map.hpp | 34 +++++----- tests/flexbuffers/test_monster_example1.hpp | 54 ++++++++------- tests/flexbuffers/test_monster_example2.hpp | 55 ++++++++-------- tests/flexbuffers/test_multimap.hpp | 34 +++++----- tests/flexbuffers/test_multiset.hpp | 30 +++++---- tests/flexbuffers/test_optional_fields.hpp | 20 +++--- tests/flexbuffers/test_readme_example.hpp | 28 ++++---- tests/flexbuffers/test_ref.hpp | 38 ++++++----- tests/flexbuffers/test_save_load.hpp | 28 ++++---- tests/flexbuffers/test_set.hpp | 30 +++++---- tests/flexbuffers/test_string_map.hpp | 19 +++--- .../flexbuffers/test_string_unordered_map.hpp | 29 ++++---- tests/flexbuffers/test_tagged_union.hpp | 32 ++++----- tests/flexbuffers/test_unique_ptr.hpp | 20 +++--- tests/flexbuffers/test_unique_ptr2.hpp | 38 ++++++----- tests/flexbuffers/test_unordered_map.hpp | 42 ++++++------ tests/flexbuffers/test_unordered_multimap.hpp | 43 ++++++------ tests/flexbuffers/test_unordered_multiset.hpp | 39 ++++++----- tests/flexbuffers/test_unordered_set.hpp | 38 ++++++----- tests/flexbuffers/test_variant.hpp | 29 ++++---- tests/flexbuffers/tests.cpp | 66 +++++++++---------- 34 files changed, 627 insertions(+), 513 deletions(-) diff --git a/tests/flexbuffers/test_all_of.hpp b/tests/flexbuffers/test_all_of.hpp index b568c6d0..45049094 100644 --- a/tests/flexbuffers/test_all_of.hpp +++ b/tests/flexbuffers/test_all_of.hpp @@ -1,13 +1,16 @@ #include #include #include +#include #include #include #include "write_and_read.hpp" -void test_all_of() { - std::cout << "test_all_of" << std::endl; +namespace test_all_of { + +void test() { + std::cout << std::source_location::current().function_name() << std::endl; using Age = rfl::Validator, rfl::Maximum<130>>>; @@ -23,3 +26,4 @@ void test_all_of() { write_and_read(homer); } +} // namespace test_all_of diff --git a/tests/flexbuffers/test_anonymous_fields.hpp b/tests/flexbuffers/test_anonymous_fields.hpp index 0b1e229f..5f6a9cad 100644 --- a/tests/flexbuffers/test_anonymous_fields.hpp +++ b/tests/flexbuffers/test_anonymous_fields.hpp @@ -1,25 +1,28 @@ #include #include #include +#include #include #include #include "write_and_read.hpp" -void test_anonymous_fields() { - std::cout << "test_anonymous_fields" << std::endl; +namespace test_anonymous_fields { - using Age = rfl::Validator, rfl::Maximum<130>>>; +using Age = rfl::Validator, rfl::Maximum<130>>>; - struct Person { - std::string first_name; - std::string last_name; - rfl::Timestamp<"%Y-%m-%d"> birthday; - Age age; - rfl::Email email; - std::vector children; - }; +struct Person { + std::string first_name; + std::string last_name; + rfl::Timestamp<"%Y-%m-%d"> birthday; + Age age; + rfl::Email email; + std::vector children; +}; + +void test() { + std::cout << std::source_location::current().function_name() << std::endl; const auto bart = Person{.first_name = "Bart", .last_name = "Simpson", @@ -49,3 +52,4 @@ void test_anonymous_fields() { write_and_read(homer); } +} // namespace test_anonymous_fields diff --git a/tests/flexbuffers/test_box.hpp b/tests/flexbuffers/test_box.hpp index 2de1b372..a886056b 100644 --- a/tests/flexbuffers/test_box.hpp +++ b/tests/flexbuffers/test_box.hpp @@ -2,32 +2,33 @@ #include #include #include +#include #include #include #include "write_and_read.hpp" -void test_box() { - std::cout << "test_box" << std::endl; +namespace test_box { - struct DecisionTree { - struct Leaf { - rfl::Field<"type", rfl::Literal<"Leaf">> type = rfl::default_value; - rfl::Field<"value", double> value; - }; - - struct Node { - rfl::Field<"type", rfl::Literal<"Node">> type = rfl::default_value; - rfl::Field<"criticalValue", double> critical_value; - rfl::Field<"left", rfl::Box> lesser; - rfl::Field<"right", rfl::Box> greater; - }; - - using LeafOrNode = rfl::TaggedUnion<"type", Leaf, Node>; - - rfl::Field<"leafOrNode", LeafOrNode> leaf_or_node; +struct DecisionTree { + struct Leaf { + rfl::Field<"value", double> value; }; + struct Node { + rfl::Field<"criticalValue", double> critical_value; + rfl::Field<"left", rfl::Box> lesser; + rfl::Field<"right", rfl::Box> greater; + }; + + using LeafOrNode = rfl::TaggedUnion<"type", Leaf, Node>; + + rfl::Field<"leafOrNode", LeafOrNode> leaf_or_node; +}; + +void test() { + std::cout << std::source_location::current().function_name() << std::endl; + auto leaf1 = DecisionTree::Leaf{.value = 3.0}; auto leaf2 = DecisionTree::Leaf{.value = 5.0}; @@ -41,3 +42,4 @@ void test_box() { write_and_read(tree); } +} // namespace test_box diff --git a/tests/flexbuffers/test_custom_class1.hpp b/tests/flexbuffers/test_custom_class1.hpp index 1d8425ba..cdbfc4e6 100644 --- a/tests/flexbuffers/test_custom_class1.hpp +++ b/tests/flexbuffers/test_custom_class1.hpp @@ -2,36 +2,39 @@ #include #include #include +#include #include #include #include "write_and_read.hpp" -void test_custom_class1() { - std::cout << "test_custom_class1" << std::endl; +namespace test_custom_class1 { - struct Person { - struct PersonImpl { - rfl::Field<"firstName", std::string> first_name; - rfl::Field<"lastName", std::string> last_name = "Simpson"; - rfl::Field<"children", std::vector> children = - rfl::default_value; - }; +struct Person { + struct PersonImpl { + rfl::Field<"firstName", std::string> first_name; + rfl::Field<"lastName", std::string> last_name = "Simpson"; + rfl::Field<"children", std::vector> children = rfl::default_value; + }; - using ReflectionType = PersonImpl; + using ReflectionType = PersonImpl; - Person(const PersonImpl& _impl) : impl(_impl) {} + Person(const PersonImpl& _impl) : impl(_impl) {} - Person(const std::string& _first_name) - : impl(PersonImpl{.first_name = _first_name}) {} + Person(const std::string& _first_name) + : impl(PersonImpl{.first_name = _first_name}) {} - const ReflectionType& reflection() const { return impl; }; + const ReflectionType& reflection() const { return impl; }; - private: - PersonImpl impl; - }; + private: + PersonImpl impl; +}; - const auto bart = Person("Bart"); +void test() { + std::cout << std::source_location::current().function_name() << std::endl; - write_and_read(bart); + const auto bart = Person("Bart"); + + write_and_read(bart); } +} // namespace test_custom_class1 diff --git a/tests/flexbuffers/test_custom_class2.hpp b/tests/flexbuffers/test_custom_class2.hpp index 101849f1..161900a7 100644 --- a/tests/flexbuffers/test_custom_class2.hpp +++ b/tests/flexbuffers/test_custom_class2.hpp @@ -2,12 +2,13 @@ #include #include #include +#include #include #include #include "write_and_read.hpp" -namespace tcc2 { +namespace test_custom_class2 { struct Person { Person(const std::string& _first_name, const std::string& _last_name, @@ -40,23 +41,27 @@ struct PersonImpl { Person to_class() const { return Person(first_name(), last_name(), age()); } }; -} // namespace tcc2 +} // namespace test_custom_class2 namespace rfl { namespace parsing { template -struct Parser - : public CustomParser {}; +struct Parser + : public CustomParser {}; } // namespace parsing } // namespace rfl -void test_custom_class2() { - std::cout << "test_custom_class2" << std::endl; +namespace test_custom_class2 { - const auto bart = tcc2::Person("Bart", "Simpson", 10); +void test() { + std::cout << std::source_location::current().function_name() << std::endl; + + const auto bart = test_custom_class2::Person("Bart", "Simpson", 10); write_and_read(bart); } + +} // namespace test_custom_class2 diff --git a/tests/flexbuffers/test_custom_class3.hpp b/tests/flexbuffers/test_custom_class3.hpp index 06d95c62..00d2eb5a 100644 --- a/tests/flexbuffers/test_custom_class3.hpp +++ b/tests/flexbuffers/test_custom_class3.hpp @@ -2,12 +2,13 @@ #include #include #include +#include #include #include #include "write_and_read.hpp" -namespace tcc3 { +namespace test_custom_class3 { struct Person { Person(const std::string& _first_name, @@ -40,24 +41,28 @@ struct PersonImpl { } }; -} // namespace tcc3 +} // namespace test_custom_class3 namespace rfl { namespace parsing { template -struct Parser - : public CustomParser {}; +struct Parser + : public CustomParser {}; } // namespace parsing } // namespace rfl -void test_custom_class3() { - std::cout << "test_custom_class3" << std::endl; +namespace test_custom_class3 { - const auto bart = - tcc3::Person("Bart", rfl::make_box("Simpson"), 10); +void test() { + std::cout << std::source_location::current().function_name() << std::endl; + + const auto bart = test_custom_class3::Person( + "Bart", rfl::make_box("Simpson"), 10); write_and_read(bart); } + +} // namespace test_custom_class3 diff --git a/tests/flexbuffers/test_custom_constructor.hpp b/tests/flexbuffers/test_custom_constructor.hpp index 08b36c84..dda87d79 100644 --- a/tests/flexbuffers/test_custom_constructor.hpp +++ b/tests/flexbuffers/test_custom_constructor.hpp @@ -1,36 +1,37 @@ #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... -void test_custom_constructor() { - std::cout << "test_custom_constructor" << std::endl; +namespace test_custom_constructor { - struct Person { - static rfl::Result from_flexbuf( - typename rfl::flexbuf::Reader::InputVarType _obj) { - /// This only exists for the purpose of the test. - const auto change_first_name = [](auto&& _person) { - return rfl::replace(std::move(_person), - rfl::Field<"firstName", std::string>("Bart")); - }; - const auto from_nt = [](auto&& _nt) { - return rfl::from_named_tuple(std::move(_nt)); - }; - return rfl::flexbuf::read>(_obj) - .transform(from_nt) - .transform(change_first_name); - } +struct Person { + static rfl::Result from_flexbuf( + typename rfl::flexbuf::Reader::InputVarType _obj) { + /// This only exists for the purpose of the test. + const auto change_first_name = [](auto&& _person) { + return rfl::replace(std::move(_person), + rfl::Field<"firstName", std::string>("Bart")); + }; + const auto from_nt = [](auto&& _nt) { + return rfl::from_named_tuple(std::move(_nt)); + }; + return rfl::flexbuf::read>(_obj) + .transform(from_nt) + .transform(change_first_name); + } - rfl::Field<"firstName", std::string> first_name; - rfl::Field<"lastName", std::string> last_name; - rfl::Field<"birthday", rfl::Timestamp<"%Y-%m-%d">> birthday; - }; + rfl::Field<"firstName", std::string> first_name; + rfl::Field<"lastName", std::string> last_name; + rfl::Field<"birthday", rfl::Timestamp<"%Y-%m-%d">> birthday; +}; + +void test() { + std::cout << std::source_location::current().function_name() << std::endl; const auto person1 = Person{ .first_name = "Homer", .last_name = "Simpson", .birthday = "1987-04-19"}; @@ -53,3 +54,4 @@ void test_custom_constructor() { std::cout << "OK" << std::endl << std::endl; } } +} // namespace test_custom_constructor diff --git a/tests/flexbuffers/test_deque.hpp b/tests/flexbuffers/test_deque.hpp index ad0a3311..e18fb7c9 100644 --- a/tests/flexbuffers/test_deque.hpp +++ b/tests/flexbuffers/test_deque.hpp @@ -1,28 +1,32 @@ #include #include #include +#include #include #include #include "write_and_read.hpp" -void test_deque() { - std::cout << "test_deque" << std::endl; +namespace test_deque { - struct Person { - rfl::Field<"firstName", std::string> first_name; - rfl::Field<"lastName", std::string> last_name = "Simpson"; - rfl::Field<"children", std::unique_ptr>> children = - rfl::default_value; - }; +struct Person { + rfl::Field<"firstName", std::string> first_name; + rfl::Field<"lastName", std::string> last_name = "Simpson"; + rfl::Field<"children", std::unique_ptr>> children = + rfl::default_value; +}; - auto children = std::make_unique>(); - children->emplace_back(Person{.first_name = "Bart"}); - children->emplace_back(Person{.first_name = "Lisa"}); - children->emplace_back(Person{.first_name = "Maggie"}); +void test() { + std::cout << std::source_location::current().function_name() << std::endl; - const auto homer = - Person{.first_name = "Homer", .children = std::move(children)}; + auto children = std::make_unique>(); + children->emplace_back(Person{.first_name = "Bart"}); + children->emplace_back(Person{.first_name = "Lisa"}); + children->emplace_back(Person{.first_name = "Maggie"}); - write_and_read(homer); + const auto homer = + Person{.first_name = "Homer", .children = std::move(children)}; + + write_and_read(homer); } +} // namespace test_deque diff --git a/tests/flexbuffers/test_field_variant.hpp b/tests/flexbuffers/test_field_variant.hpp index 3aa9d305..4cf1f508 100644 --- a/tests/flexbuffers/test_field_variant.hpp +++ b/tests/flexbuffers/test_field_variant.hpp @@ -2,33 +2,37 @@ #include #include #include +#include #include #include #include "write_and_read.hpp" -void test_field_variant() { - std::cout << "test_field_variant" << std::endl; +namespace test_field_variant { - struct Circle { - rfl::Field<"radius", double> radius; - }; +struct Circle { + rfl::Field<"radius", double> radius; +}; - struct Rectangle { - rfl::Field<"height", double> height; - rfl::Field<"width", double> width; - }; +struct Rectangle { + rfl::Field<"height", double> height; + rfl::Field<"width", double> width; +}; - struct Square { - rfl::Field<"width", double> width; - }; +struct Square { + rfl::Field<"width", double> width; +}; - using Shapes = rfl::Variant, - rfl::Field<"rectangle", Rectangle>, - rfl::Field<"square", rfl::Box>>; +using Shapes = rfl::Variant, + rfl::Field<"rectangle", Rectangle>, + rfl::Field<"square", rfl::Box>>; + +void test() { + std::cout << std::source_location::current().function_name() << std::endl; const Shapes r = rfl::make_field<"rectangle">(Rectangle{.height = 10, .width = 5}); write_and_read(r); } +} // namespace test_field_variant diff --git a/tests/flexbuffers/test_flatten_anonymous.hpp b/tests/flexbuffers/test_flatten_anonymous.hpp index 5971adb4..656b9697 100644 --- a/tests/flexbuffers/test_flatten_anonymous.hpp +++ b/tests/flexbuffers/test_flatten_anonymous.hpp @@ -2,25 +2,28 @@ #include #include #include +#include #include #include #include "write_and_read.hpp" -void test_flatten_anonymous() { - std::cout << "test_flatten_anonymous" << std::endl; +namespace test_flatten_anonymous { - struct Person { - std::string first_name; - rfl::Box last_name; - int age; - }; +struct Person { + std::string first_name; + rfl::Box last_name; + int age; +}; - struct Employee { - rfl::Flatten person; - rfl::Box employer; - float salary; - }; +struct Employee { + rfl::Flatten person; + rfl::Box employer; + float salary; +}; + +void test() { + std::cout << std::source_location::current().function_name() << std::endl; const auto employee = Employee{ .person = Person{.first_name = "Homer", @@ -31,3 +34,4 @@ void test_flatten_anonymous() { write_and_read(employee); } +} // namespace test_flatten_anonymous diff --git a/tests/flexbuffers/test_forward_list.hpp b/tests/flexbuffers/test_forward_list.hpp index da8da2da..833e8a30 100644 --- a/tests/flexbuffers/test_forward_list.hpp +++ b/tests/flexbuffers/test_forward_list.hpp @@ -1,28 +1,32 @@ #include #include #include +#include #include #include #include "write_and_read.hpp" -void test_forward_list() { - std::cout << "test_forward_list" << std::endl; +namespace test_forward_list { - struct Person { - rfl::Field<"firstName", std::string> first_name; - rfl::Field<"lastName", std::string> last_name = "Simpson"; - rfl::Field<"children", std::unique_ptr>> - children = rfl::default_value; - }; +struct Person { + rfl::Field<"firstName", std::string> first_name; + rfl::Field<"lastName", std::string> last_name = "Simpson"; + rfl::Field<"children", std::unique_ptr>> children = + rfl::default_value; +}; - auto children = std::make_unique>(); - children->emplace_front(Person{.first_name = "Maggie"}); - children->emplace_front(Person{.first_name = "Lisa"}); - children->emplace_front(Person{.first_name = "Bart"}); +void test() { + std::cout << std::source_location::current().function_name() << std::endl; - const auto homer = - Person{.first_name = "Homer", .children = std::move(children)}; + auto children = std::make_unique>(); + children->emplace_front(Person{.first_name = "Maggie"}); + children->emplace_front(Person{.first_name = "Lisa"}); + children->emplace_front(Person{.first_name = "Bart"}); - write_and_read(homer); + const auto homer = + Person{.first_name = "Homer", .children = std::move(children)}; + + write_and_read(homer); } +} // namespace test_forward_list diff --git a/tests/flexbuffers/test_list.hpp b/tests/flexbuffers/test_list.hpp index 637bcd70..22f4eb60 100644 --- a/tests/flexbuffers/test_list.hpp +++ b/tests/flexbuffers/test_list.hpp @@ -1,28 +1,32 @@ #include #include #include +#include #include #include #include "write_and_read.hpp" -void test_list() { - std::cout << "test_list" << std::endl; +namespace test_list { - struct Person { - rfl::Field<"firstName", std::string> first_name; - rfl::Field<"lastName", std::string> last_name = "Simpson"; - rfl::Field<"children", std::unique_ptr>> children = - rfl::default_value; - }; +struct Person { + rfl::Field<"firstName", std::string> first_name; + rfl::Field<"lastName", std::string> last_name = "Simpson"; + rfl::Field<"children", std::unique_ptr>> children = + rfl::default_value; +}; - auto children = std::make_unique>(); - children->emplace_back(Person{.first_name = "Bart"}); - children->emplace_back(Person{.first_name = "Lisa"}); - children->emplace_back(Person{.first_name = "Maggie"}); +void test() { + std::cout << std::source_location::current().function_name() << std::endl; - const auto homer = - Person{.first_name = "Homer", .children = std::move(children)}; + auto children = std::make_unique>(); + children->emplace_back(Person{.first_name = "Bart"}); + children->emplace_back(Person{.first_name = "Lisa"}); + children->emplace_back(Person{.first_name = "Maggie"}); - write_and_read(homer); + const auto homer = + Person{.first_name = "Homer", .children = std::move(children)}; + + write_and_read(homer); } +} // namespace test_list diff --git a/tests/flexbuffers/test_literal.hpp b/tests/flexbuffers/test_literal.hpp index 5bff332a..5ade3bfd 100644 --- a/tests/flexbuffers/test_literal.hpp +++ b/tests/flexbuffers/test_literal.hpp @@ -2,25 +2,28 @@ #include #include #include +#include #include #include #include "write_and_read.hpp" -// Makes sure that we can set default values. -void test_literal() { - std::cout << "test_literal" << std::endl; +namespace test_literal { - using FirstName = rfl::Literal<"Homer", "Marge", "Bart", "Lisa", "Maggie">; - using LastName = rfl::Literal<"Simpson">; +using FirstName = rfl::Literal<"Homer", "Marge", "Bart", "Lisa", "Maggie">; +using LastName = rfl::Literal<"Simpson">; - struct Person { - rfl::Field<"firstName", FirstName> first_name; - rfl::Field<"lastName", LastName> last_name = rfl::default_value; - rfl::Field<"children", std::vector> children = rfl::default_value; - }; +struct Person { + rfl::Field<"firstName", FirstName> first_name; + rfl::Field<"lastName", LastName> last_name = rfl::default_value; + rfl::Field<"children", std::vector> children = rfl::default_value; +}; + +void test() { + std::cout << std::source_location::current().function_name() << std::endl; const auto bart = Person{.first_name = FirstName::make<"Bart">()}; write_and_read(bart); } +} // namespace test_literal diff --git a/tests/flexbuffers/test_map.hpp b/tests/flexbuffers/test_map.hpp index afba3d4e..4dcc9d6b 100644 --- a/tests/flexbuffers/test_map.hpp +++ b/tests/flexbuffers/test_map.hpp @@ -2,27 +2,31 @@ #include #include #include +#include #include #include "write_and_read.hpp" -void test_map() { - std::cout << "test_map" << std::endl; +namespace test_map { - struct Person { - rfl::Field<"firstName", std::string> first_name; - rfl::Field<"lastName", std::string> last_name = "Simpson"; - rfl::Field<"children", std::unique_ptr>> - children = rfl::default_value; - }; +struct Person { + rfl::Field<"firstName", std::string> first_name; + rfl::Field<"lastName", std::string> last_name = "Simpson"; + rfl::Field<"children", std::unique_ptr>> children = + rfl::default_value; +}; - auto children = std::make_unique>(); - children->insert(std::make_pair(1, Person{.first_name = "Bart"})); - children->insert(std::make_pair(2, Person{.first_name = "Lisa"})); - children->insert(std::make_pair(3, Person{.first_name = "Maggie"})); +void test() { + std::cout << std::source_location::current().function_name() << std::endl; - const auto homer = - Person{.first_name = "Homer", .children = std::move(children)}; + auto children = std::make_unique>(); + children->insert(std::make_pair(1, Person{.first_name = "Bart"})); + children->insert(std::make_pair(2, Person{.first_name = "Lisa"})); + children->insert(std::make_pair(3, Person{.first_name = "Maggie"})); - write_and_read(homer); + const auto homer = + Person{.first_name = "Homer", .children = std::move(children)}; + + write_and_read(homer); } +} // namespace test_map diff --git a/tests/flexbuffers/test_monster_example1.hpp b/tests/flexbuffers/test_monster_example1.hpp index c0449005..0a6bcb00 100644 --- a/tests/flexbuffers/test_monster_example1.hpp +++ b/tests/flexbuffers/test_monster_example1.hpp @@ -1,41 +1,44 @@ #include #include #include +#include #include #include #include "write_and_read.hpp" -void test_monster_example1() { - std::cout << "test_monster_example1" << std::endl; +namespace test_monster_example1 { - using Color = rfl::Literal<"Red", "Green", "Blue">; +using Color = rfl::Literal<"Red", "Green", "Blue">; - struct Weapon { - std::string name; - short damage; - }; +struct Weapon { + std::string name; + short damage; +}; - using Equipment = rfl::Variant>; +using Equipment = rfl::Variant>; - struct Vec3 { - float x; - float y; - float z; - }; +struct Vec3 { + float x; + float y; + float z; +}; - struct Monster { - Vec3 pos; - short mana = 150; - short hp = 100; - std::string name; - bool friendly = false; - std::vector inventory; - Color color = Color::make<"Blue">(); - std::vector weapons; - Equipment equipped; - std::vector path; - }; +struct Monster { + Vec3 pos; + short mana = 150; + short hp = 100; + std::string name; + bool friendly = false; + std::vector inventory; + Color color = Color::make<"Blue">(); + std::vector weapons; + Equipment equipped; + std::vector path; +}; + +void test() { + 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}; @@ -59,3 +62,4 @@ void test_monster_example1() { write_and_read(orc); } +} // namespace test_monster_example1 diff --git a/tests/flexbuffers/test_monster_example2.hpp b/tests/flexbuffers/test_monster_example2.hpp index 2cb79197..459bde52 100644 --- a/tests/flexbuffers/test_monster_example2.hpp +++ b/tests/flexbuffers/test_monster_example2.hpp @@ -1,41 +1,44 @@ #include #include #include +#include #include #include #include "write_and_read.hpp" -void test_monster_example2() { - std::cout << "test_monster_example2" << std::endl; +namespace test_monster_example2 { - using Color = rfl::Literal<"Red", "Green", "Blue">; +using Color = rfl::Literal<"Red", "Green", "Blue">; - struct Weapon { - rfl::Field<"name", std::string> name; - rfl::Field<"damage", short> damage; - }; +struct Weapon { + rfl::Field<"name", std::string> name; + rfl::Field<"damage", short> damage; +}; - using Equipment = rfl::Variant>; +using Equipment = rfl::Variant>; - struct Vec3 { - rfl::Field<"x", float> x; - rfl::Field<"y", float> y; - rfl::Field<"z", float> z; - }; +struct Vec3 { + rfl::Field<"x", float> x; + rfl::Field<"y", float> y; + rfl::Field<"z", float> z; +}; - struct Monster { - rfl::Field<"pos", Vec3> pos; - rfl::Field<"mana", short> mana = 150; - rfl::Field<"hp", short> hp = 100; - rfl::Field<"name", std::string> name; - rfl::Field<"friendly", bool> friendly = false; - rfl::Field<"inventory", std::vector> inventory; - rfl::Field<"color", Color> color = Color::make<"Blue">(); - rfl::Field<"weapons", std::vector> weapons; - rfl::Field<"equipped", Equipment> equipped; - rfl::Field<"path", std::vector> path; - }; +struct Monster { + rfl::Field<"pos", Vec3> pos; + rfl::Field<"mana", short> mana = 150; + rfl::Field<"hp", short> hp = 100; + rfl::Field<"name", std::string> name; + rfl::Field<"friendly", bool> friendly = false; + rfl::Field<"inventory", std::vector> inventory; + rfl::Field<"color", Color> color = Color::make<"Blue">(); + rfl::Field<"weapons", std::vector> weapons; + rfl::Field<"equipped", Equipment> equipped; + rfl::Field<"path", std::vector> path; +}; + +void test() { + 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}; @@ -59,4 +62,4 @@ void test_monster_example2() { write_and_read(orc); } - +} // namespace test_monster_example2 diff --git a/tests/flexbuffers/test_multimap.hpp b/tests/flexbuffers/test_multimap.hpp index 7b28ab84..24e7fe84 100644 --- a/tests/flexbuffers/test_multimap.hpp +++ b/tests/flexbuffers/test_multimap.hpp @@ -2,27 +2,31 @@ #include #include #include +#include #include #include "write_and_read.hpp" -void test_multimap() { - std::cout << "test_multimap" << std::endl; +namespace test_multimap { - struct Person { - rfl::Field<"firstName", std::string> first_name; - rfl::Field<"lastName", std::string> last_name = "Simpson"; - rfl::Field<"children", std::unique_ptr>> - children = rfl::default_value; - }; +struct Person { + rfl::Field<"firstName", std::string> first_name; + rfl::Field<"lastName", std::string> last_name = "Simpson"; + rfl::Field<"children", std::unique_ptr>> children = + rfl::default_value; +}; - auto children = std::make_unique>(); - children->insert(std::make_pair(1, Person{.first_name = "Bart"})); - children->insert(std::make_pair(2, Person{.first_name = "Lisa"})); - children->insert(std::make_pair(3, Person{.first_name = "Maggie"})); +void test() { + std::cout << std::source_location::current().function_name() << std::endl; - const auto homer = - Person{.first_name = "Homer", .children = std::move(children)}; + auto children = std::make_unique>(); + children->insert(std::make_pair(1, Person{.first_name = "Bart"})); + children->insert(std::make_pair(2, Person{.first_name = "Lisa"})); + children->insert(std::make_pair(3, Person{.first_name = "Maggie"})); - write_and_read(homer); + const auto homer = + Person{.first_name = "Homer", .children = std::move(children)}; + + write_and_read(homer); } +} // namespace test_multimap diff --git a/tests/flexbuffers/test_multiset.hpp b/tests/flexbuffers/test_multiset.hpp index 2bc3455f..38a528cf 100644 --- a/tests/flexbuffers/test_multiset.hpp +++ b/tests/flexbuffers/test_multiset.hpp @@ -1,26 +1,30 @@ #include #include #include +#include #include #include #include "write_and_read.hpp" -void test_multiset() { - std::cout << "test_multiset" << std::endl; +namespace test_multiset { - struct Person { - rfl::Field<"firstName", std::string> first_name; - rfl::Field<"lastName", std::string> last_name = "Simpson"; - rfl::Field<"children", std::unique_ptr>> - children = rfl::default_value; - }; +struct Person { + rfl::Field<"firstName", std::string> first_name; + rfl::Field<"lastName", std::string> last_name = "Simpson"; + rfl::Field<"children", std::unique_ptr>> children = + rfl::default_value; +}; - auto children = std::make_unique>( - std::multiset({"Bart", "Lisa", "Maggie"})); +void test() { + std::cout << std::source_location::current().function_name() << std::endl; - const auto homer = - Person{.first_name = "Homer", .children = std::move(children)}; + auto children = std::make_unique>( + std::multiset({"Bart", "Lisa", "Maggie"})); - write_and_read(homer); + const auto homer = + Person{.first_name = "Homer", .children = std::move(children)}; + + write_and_read(homer); } +} // namespace test_multiset diff --git a/tests/flexbuffers/test_optional_fields.hpp b/tests/flexbuffers/test_optional_fields.hpp index fd5c777d..c3a11126 100644 --- a/tests/flexbuffers/test_optional_fields.hpp +++ b/tests/flexbuffers/test_optional_fields.hpp @@ -1,20 +1,23 @@ #include #include #include +#include #include #include #include "write_and_read.hpp" -void test_optional_fields() { - std::cout << "test_optional_fields" << std::endl; +namespace test_optional_fields { - struct Person { - rfl::Field<"firstName", std::string> first_name; - rfl::Field<"lastName", std::string> last_name = "Simpson"; - rfl::Field<"children", std::optional>> children = - rfl::default_value; - }; +struct Person { + rfl::Field<"firstName", std::string> first_name; + rfl::Field<"lastName", std::string> last_name = "Simpson"; + rfl::Field<"children", std::optional>> children = + rfl::default_value; +}; + +void test() { + std::cout << std::source_location::current().function_name() << std::endl; const auto bart = Person{.first_name = "Bart"}; @@ -28,3 +31,4 @@ void test_optional_fields() { write_and_read(homer); } +} // namespace test_optional_fields diff --git a/tests/flexbuffers/test_readme_example.hpp b/tests/flexbuffers/test_readme_example.hpp index df31a5a8..32fba941 100644 --- a/tests/flexbuffers/test_readme_example.hpp +++ b/tests/flexbuffers/test_readme_example.hpp @@ -1,25 +1,28 @@ #include #include #include +#include #include #include #include "write_and_read.hpp" -void test_readme_example() { - std::cout << "test_readme_example" << std::endl; +namespace test_readme_example { - using Age = rfl::Validator, rfl::Maximum<130>>>; +using Age = rfl::Validator, rfl::Maximum<130>>>; - struct Person { - rfl::Field<"firstName", std::string> first_name; - rfl::Field<"lastName", std::string> last_name; - rfl::Field<"birthday", rfl::Timestamp<"%Y-%m-%d">> birthday; - rfl::Field<"age", Age> age; - rfl::Field<"email", rfl::Email> email; - rfl::Field<"children", std::vector> children; - }; +struct Person { + rfl::Field<"firstName", std::string> first_name; + rfl::Field<"lastName", std::string> last_name; + rfl::Field<"birthday", rfl::Timestamp<"%Y-%m-%d">> birthday; + rfl::Field<"age", Age> age; + rfl::Field<"email", rfl::Email> email; + rfl::Field<"children", std::vector> children; +}; + +void test() { + std::cout << std::source_location::current().function_name() << std::endl; const auto bart = Person{.first_name = "Bart", .last_name = "Simpson", @@ -52,3 +55,4 @@ void test_readme_example() { write_and_read(homer); } +} // namespace test_readme_example diff --git a/tests/flexbuffers/test_ref.hpp b/tests/flexbuffers/test_ref.hpp index c9f7e2cf..218900a4 100644 --- a/tests/flexbuffers/test_ref.hpp +++ b/tests/flexbuffers/test_ref.hpp @@ -2,32 +2,33 @@ #include #include #include +#include #include #include #include "write_and_read.hpp" -void test_ref() { - std::cout << "test_ref" << std::endl; +namespace test_ref { - struct DecisionTree { - struct Leaf { - rfl::Field<"type", rfl::Literal<"Leaf">> type = rfl::default_value; - rfl::Field<"value", double> value; - }; - - struct Node { - rfl::Field<"type", rfl::Literal<"Node">> type = rfl::default_value; - rfl::Field<"criticalValue", double> critical_value; - rfl::Field<"left", rfl::Ref> lesser; - rfl::Field<"right", rfl::Ref> greater; - }; - - using LeafOrNode = rfl::TaggedUnion<"type", Leaf, Node>; - - rfl::Field<"leafOrNode", LeafOrNode> leaf_or_node; +struct DecisionTree { + struct Leaf { + rfl::Field<"value", double> value; }; + struct Node { + rfl::Field<"criticalValue", double> critical_value; + rfl::Field<"left", rfl::Ref> lesser; + rfl::Field<"right", rfl::Ref> greater; + }; + + using LeafOrNode = rfl::TaggedUnion<"type", Leaf, Node>; + + rfl::Field<"leafOrNode", LeafOrNode> leaf_or_node; +}; + +void test() { + std::cout << std::source_location::current().function_name() << std::endl; + const auto leaf1 = DecisionTree::Leaf{.value = 3.0}; const auto leaf2 = DecisionTree::Leaf{.value = 5.0}; @@ -41,3 +42,4 @@ void test_ref() { write_and_read(tree); } +} // namespace test_ref diff --git a/tests/flexbuffers/test_save_load.hpp b/tests/flexbuffers/test_save_load.hpp index 505c1c55..e3fbc7dd 100644 --- a/tests/flexbuffers/test_save_load.hpp +++ b/tests/flexbuffers/test_save_load.hpp @@ -2,25 +2,28 @@ #include #include #include +#include #include #include #include "write_and_read.hpp" -void test_save_load() { - std::cout << "test_save_load" << std::endl; +namespace test_save_load { - using Age = rfl::Validator, rfl::Maximum<130>>>; +using Age = rfl::Validator, rfl::Maximum<130>>>; - struct Person { - rfl::Field<"firstName", std::string> first_name; - rfl::Field<"lastName", std::string> last_name; - rfl::Field<"birthday", rfl::Timestamp<"%Y-%m-%d">> birthday; - rfl::Field<"age", Age> age; - rfl::Field<"email", rfl::Email> email; - rfl::Field<"children", std::vector> children; - }; +struct Person { + rfl::Field<"firstName", std::string> first_name; + rfl::Field<"lastName", std::string> last_name; + rfl::Field<"birthday", rfl::Timestamp<"%Y-%m-%d">> birthday; + rfl::Field<"age", Age> age; + rfl::Field<"email", rfl::Email> email; + rfl::Field<"children", std::vector> children; +}; + +void test() { + std::cout << std::source_location::current().function_name() << std::endl; const auto bart = Person{.first_name = "Bart", .last_name = "Simpson", @@ -66,3 +69,4 @@ void test_save_load() { std::cout << "OK" << std::endl << std::endl; } +} // namespace test_save_load diff --git a/tests/flexbuffers/test_set.hpp b/tests/flexbuffers/test_set.hpp index 1dceee01..7ac91c0e 100644 --- a/tests/flexbuffers/test_set.hpp +++ b/tests/flexbuffers/test_set.hpp @@ -1,26 +1,30 @@ #include #include #include +#include #include #include #include "write_and_read.hpp" -void test_set() { - std::cout << "test_set" << std::endl; +namespace test_set { - struct Person { - rfl::Field<"firstName", std::string> first_name; - rfl::Field<"lastName", std::string> last_name = "Simpson"; - rfl::Field<"children", std::unique_ptr>> - children = rfl::default_value; - }; +struct Person { + rfl::Field<"firstName", std::string> first_name; + rfl::Field<"lastName", std::string> last_name = "Simpson"; + rfl::Field<"children", std::unique_ptr>> children = + rfl::default_value; +}; - auto children = std::make_unique>( - std::set({"Bart", "Lisa", "Maggie"})); +void test() { + std::cout << std::source_location::current().function_name() << std::endl; - const auto homer = - Person{.first_name = "Homer", .children = std::move(children)}; + auto children = std::make_unique>( + std::set({"Bart", "Lisa", "Maggie"})); - write_and_read(homer); + const auto homer = + Person{.first_name = "Homer", .children = std::move(children)}; + + write_and_read(homer); } +} // namespace test_set diff --git a/tests/flexbuffers/test_string_map.hpp b/tests/flexbuffers/test_string_map.hpp index a1d97aed..ec6d5997 100644 --- a/tests/flexbuffers/test_string_map.hpp +++ b/tests/flexbuffers/test_string_map.hpp @@ -3,18 +3,21 @@ #include #include #include +#include #include #include "write_and_read.hpp" -void test_string_map() { - std::cout << "test_string_map" << std::endl; +namespace test_string_map { +void test() { + std::cout << std::source_location::current().function_name() << std::endl; - std::map> homer; - homer.insert( - std::make_pair("firstName", std::make_unique("Homer"))); - homer.insert( - std::make_pair("lastName", std::make_unique("Simpson"))); + std::map> homer; + homer.insert( + std::make_pair("firstName", std::make_unique("Homer"))); + homer.insert( + std::make_pair("lastName", std::make_unique("Simpson"))); - write_and_read(homer); + write_and_read(homer); } +} // namespace test_string_map diff --git a/tests/flexbuffers/test_string_unordered_map.hpp b/tests/flexbuffers/test_string_unordered_map.hpp index 325277ca..9f510245 100644 --- a/tests/flexbuffers/test_string_unordered_map.hpp +++ b/tests/flexbuffers/test_string_unordered_map.hpp @@ -2,24 +2,27 @@ #include #include #include +#include #include #include #include "write_and_read.hpp" -void test_string_unordered_map() { - std::cout << "test_string_unordered_map" << std::endl; +namespace test_string_unordered_map { +void test() { + std::cout << std::source_location::current().function_name() << std::endl; - using Map = std::unordered_map>; - Map homer; - homer.insert( - std::make_pair("firstName", std::make_unique("Homer"))); - homer.insert( - std::make_pair("lastName", std::make_unique("Simpson"))); + using Map = std::unordered_map>; + Map homer; + homer.insert( + std::make_pair("firstName", std::make_unique("Homer"))); + homer.insert( + std::make_pair("lastName", std::make_unique("Simpson"))); - // Unordered maps are unpredictable. We therefore only make sure that this - // compiles. - const auto json_string = rfl::flexbuf::write(homer); - const auto homer2 = rfl::flexbuf::read(json_string); - std::cout << "OK" << std::endl << std::endl; + // Unordered maps are unpredictable. We therefore only make sure that this + // compiles. + const auto json_string = rfl::flexbuf::write(homer); + const auto homer2 = rfl::flexbuf::read(json_string); + std::cout << "OK" << std::endl << std::endl; } +} // namespace test_string_unordered_map diff --git a/tests/flexbuffers/test_tagged_union.hpp b/tests/flexbuffers/test_tagged_union.hpp index a33b6fbe..9b18b64d 100644 --- a/tests/flexbuffers/test_tagged_union.hpp +++ b/tests/flexbuffers/test_tagged_union.hpp @@ -2,30 +2,29 @@ #include #include #include +#include #include #include #include "write_and_read.hpp" -// Makes sure that we can set default values. -void test_tagged_union() { - std::cout << "test_tagged_union" << std::endl; +namespace test_tagged_union { - struct Circle { - rfl::Field<"shape", rfl::Literal<"Circle">> shape = rfl::default_value; - rfl::Field<"radius", double> radius; - }; +struct Circle { + double radius; +}; - struct Rectangle { - rfl::Field<"shape", rfl::Literal<"Rectangle">> shape = rfl::default_value; - rfl::Field<"height", double> height; - rfl::Field<"width", double> width; - }; +struct Rectangle { + double height; + double width; +}; - struct Square { - rfl::Field<"shape", rfl::Literal<"Square">> shape = rfl::default_value; - rfl::Field<"width", double> width; - }; +struct Square { + double width; +}; + +void test() { + std::cout << std::source_location::current().function_name() << std::endl; using Shapes = rfl::TaggedUnion<"shape", Circle, Square, Rectangle>; @@ -33,3 +32,4 @@ void test_tagged_union() { write_and_read(r); } +} // namespace test_tagged_union diff --git a/tests/flexbuffers/test_unique_ptr.hpp b/tests/flexbuffers/test_unique_ptr.hpp index 3f36e5d0..938baae5 100644 --- a/tests/flexbuffers/test_unique_ptr.hpp +++ b/tests/flexbuffers/test_unique_ptr.hpp @@ -2,20 +2,23 @@ #include #include #include +#include #include #include #include "write_and_read.hpp" -void test_unique_ptr() { - std::cout << "test_unique_ptr" << std::endl; +namespace test_unique_ptr { - struct Person { - rfl::Field<"firstName", std::string> first_name; - rfl::Field<"lastName", std::string> last_name = "Simpson"; - rfl::Field<"children", std::unique_ptr>> children = - rfl::default_value; - }; +struct Person { + rfl::Field<"firstName", std::string> first_name; + rfl::Field<"lastName", std::string> last_name = "Simpson"; + rfl::Field<"children", std::unique_ptr>> children = + rfl::default_value; +}; + +void test() { + std::cout << std::source_location::current().function_name() << std::endl; auto children = std::make_unique>(); children->emplace_back(Person{.first_name = "Bart"}); @@ -27,3 +30,4 @@ void test_unique_ptr() { write_and_read(homer); } +} // namespace test_unique_ptr diff --git a/tests/flexbuffers/test_unique_ptr2.hpp b/tests/flexbuffers/test_unique_ptr2.hpp index dcfaa060..73936561 100644 --- a/tests/flexbuffers/test_unique_ptr2.hpp +++ b/tests/flexbuffers/test_unique_ptr2.hpp @@ -2,32 +2,33 @@ #include #include #include +#include #include #include #include "write_and_read.hpp" -void test_unique_ptr2() { - std::cout << "test_unique_ptr2" << std::endl; +namespace test_unique_ptr2 { - struct DecisionTree { - struct Leaf { - rfl::Field<"type", rfl::Literal<"Leaf">> type = rfl::default_value; - rfl::Field<"value", double> value; - }; - - struct Node { - rfl::Field<"type", rfl::Literal<"Node">> type = rfl::default_value; - rfl::Field<"criticalValue", double> critical_value; - rfl::Field<"left", std::unique_ptr> lesser; - rfl::Field<"right", std::unique_ptr> greater; - }; - - using LeafOrNode = rfl::TaggedUnion<"type", Leaf, Node>; - - rfl::Field<"leafOrNode", LeafOrNode> leaf_or_node; +struct DecisionTree { + struct Leaf { + rfl::Field<"value", double> value; }; + struct Node { + rfl::Field<"criticalValue", double> critical_value; + rfl::Field<"left", std::unique_ptr> lesser; + rfl::Field<"right", std::unique_ptr> greater; + }; + + using LeafOrNode = rfl::TaggedUnion<"type", Leaf, Node>; + + rfl::Field<"leafOrNode", LeafOrNode> leaf_or_node; +}; + +void test() { + std::cout << std::source_location::current().function_name() << std::endl; + auto leaf1 = DecisionTree::Leaf{.value = 3.0}; auto leaf2 = DecisionTree::Leaf{.value = 5.0}; @@ -41,3 +42,4 @@ void test_unique_ptr2() { write_and_read(tree); } +} // namespace test_unique_ptr2 diff --git a/tests/flexbuffers/test_unordered_map.hpp b/tests/flexbuffers/test_unordered_map.hpp index 17c02df6..2fa6a07a 100644 --- a/tests/flexbuffers/test_unordered_map.hpp +++ b/tests/flexbuffers/test_unordered_map.hpp @@ -1,32 +1,36 @@ #include #include #include +#include #include #include #include "write_and_read.hpp" -void test_unordered_map() { - std::cout << "test_unordered_map" << std::endl; +namespace test_unordered_map { - struct Person { - rfl::Field<"firstName", std::string> first_name; - rfl::Field<"lastName", std::string> last_name = "Simpson"; - rfl::Field<"children", std::unique_ptr>> - children = rfl::default_value; - }; +struct Person { + rfl::Field<"firstName", std::string> first_name; + rfl::Field<"lastName", std::string> last_name = "Simpson"; + rfl::Field<"children", std::unique_ptr>> + children = rfl::default_value; +}; - auto children = std::make_unique>(); - children->insert(std::make_pair(1, Person{.first_name = "Bart"})); - children->insert(std::make_pair(2, Person{.first_name = "Lisa"})); - children->insert(std::make_pair(3, Person{.first_name = "Maggie"})); +void test() { + std::cout << std::source_location::current().function_name() << std::endl; - const auto homer = - Person{.first_name = "Homer", .children = std::move(children)}; + auto children = std::make_unique>(); + children->insert(std::make_pair(1, Person{.first_name = "Bart"})); + children->insert(std::make_pair(2, Person{.first_name = "Lisa"})); + children->insert(std::make_pair(3, Person{.first_name = "Maggie"})); - // Unordered maps are unpredictable. We therefore only make sure that this - // compiles. - const auto json_string = rfl::flexbuf::write(homer); - const auto homer2 = rfl::flexbuf::read(json_string); - std::cout << "OK" << std::endl << std::endl; + const auto homer = + Person{.first_name = "Homer", .children = std::move(children)}; + + // Unordered maps are unpredictable. We therefore only make sure that this + // compiles. + const auto json_string = rfl::flexbuf::write(homer); + const auto homer2 = rfl::flexbuf::read(json_string); + std::cout << "OK" << std::endl << std::endl; } +} // namespace test_unordered_map diff --git a/tests/flexbuffers/test_unordered_multimap.hpp b/tests/flexbuffers/test_unordered_multimap.hpp index 8cf4302c..fda91b1a 100644 --- a/tests/flexbuffers/test_unordered_multimap.hpp +++ b/tests/flexbuffers/test_unordered_multimap.hpp @@ -2,32 +2,35 @@ #include #include #include +#include #include #include "write_and_read.hpp" -void test_unordered_multimap() { - std::cout << "test_unordered_multimap" << std::endl; +namespace test_unordered_multimap { - struct Person { - rfl::Field<"firstName", std::string> first_name; - rfl::Field<"lastName", std::string> last_name = "Simpson"; - rfl::Field<"children", - std::unique_ptr>> - children = rfl::default_value; - }; +struct Person { + rfl::Field<"firstName", std::string> first_name; + rfl::Field<"lastName", std::string> last_name = "Simpson"; + rfl::Field<"children", std::unique_ptr>> + children = rfl::default_value; +}; - auto children = std::make_unique>(); - children->insert(std::make_pair(1, Person{.first_name = "Bart"})); - children->insert(std::make_pair(2, Person{.first_name = "Lisa"})); - children->insert(std::make_pair(3, Person{.first_name = "Maggie"})); +void test() { + std::cout << std::source_location::current().function_name() << std::endl; - const auto homer = - Person{.first_name = "Homer", .children = std::move(children)}; + auto children = std::make_unique>(); + children->insert(std::make_pair(1, Person{.first_name = "Bart"})); + children->insert(std::make_pair(2, Person{.first_name = "Lisa"})); + children->insert(std::make_pair(3, Person{.first_name = "Maggie"})); - // Unordered maps are unpredictable. We therefore only make sure that this - // compiles. - const auto json_string = rfl::flexbuf::write(homer); - const auto homer2 = rfl::flexbuf::read(json_string); - std::cout << "OK" << std::endl << std::endl; + const auto homer = + Person{.first_name = "Homer", .children = std::move(children)}; + + // Unordered maps are unpredictable. We therefore only make sure that this + // compiles. + const auto json_string = rfl::flexbuf::write(homer); + const auto homer2 = rfl::flexbuf::read(json_string); + std::cout << "OK" << std::endl << std::endl; } +} // namespace test_unordered_multimap diff --git a/tests/flexbuffers/test_unordered_multiset.hpp b/tests/flexbuffers/test_unordered_multiset.hpp index 2289b8d6..d47e54a8 100644 --- a/tests/flexbuffers/test_unordered_multiset.hpp +++ b/tests/flexbuffers/test_unordered_multiset.hpp @@ -1,31 +1,34 @@ #include #include #include +#include #include #include #include "write_and_read.hpp" -void test_unordered_multiset() { - std::cout << "test_unordered_multiset" << std::endl; +namespace test_unordered_multiset { - struct Person { - rfl::Field<"firstName", std::string> first_name; - rfl::Field<"lastName", std::string> last_name = "Simpson"; - rfl::Field<"children", - std::unique_ptr>> - children = rfl::default_value; - }; +struct Person { + rfl::Field<"firstName", std::string> first_name; + rfl::Field<"lastName", std::string> last_name = "Simpson"; + rfl::Field<"children", std::unique_ptr>> + children = rfl::default_value; +}; - auto children = std::make_unique>( - std::unordered_multiset({"Bart", "Lisa", "Maggie"})); +void test() { + std::cout << std::source_location::current().function_name() << std::endl; - const auto homer = - Person{.first_name = "Homer", .children = std::move(children)}; + auto children = std::make_unique>( + std::unordered_multiset({"Bart", "Lisa", "Maggie"})); - // Unordered multisets are unpredictable. We therefore only make sure that - // this compiles. - const auto json_string = rfl::flexbuf::write(homer); - const auto homer2 = rfl::flexbuf::read(json_string); - std::cout << "OK" << std::endl << std::endl; + const auto homer = + Person{.first_name = "Homer", .children = std::move(children)}; + + // Unordered multisets are unpredictable. We therefore only make sure that + // this compiles. + const auto json_string = rfl::flexbuf::write(homer); + const auto homer2 = rfl::flexbuf::read(json_string); + std::cout << "OK" << std::endl << std::endl; } +} // namespace test_unordered_multiset diff --git a/tests/flexbuffers/test_unordered_set.hpp b/tests/flexbuffers/test_unordered_set.hpp index 50ce449b..a1d43693 100644 --- a/tests/flexbuffers/test_unordered_set.hpp +++ b/tests/flexbuffers/test_unordered_set.hpp @@ -1,30 +1,34 @@ #include #include #include +#include #include #include #include "write_and_read.hpp" -void test_unordered_set() { - std::cout << "test_unordered_set" << std::endl; +namespace test_unordered_set { - struct Person { - rfl::Field<"firstName", std::string> first_name; - rfl::Field<"lastName", std::string> last_name = "Simpson"; - rfl::Field<"children", std::unique_ptr>> - children = rfl::default_value; - }; +struct Person { + rfl::Field<"firstName", std::string> first_name; + rfl::Field<"lastName", std::string> last_name = "Simpson"; + rfl::Field<"children", std::unique_ptr>> + children = rfl::default_value; +}; - auto children = std::make_unique>( - std::unordered_set({"Bart", "Lisa", "Maggie"})); +void test() { + std::cout << std::source_location::current().function_name() << std::endl; - const auto homer = - Person{.first_name = "Homer", .children = std::move(children)}; + auto children = std::make_unique>( + std::unordered_set({"Bart", "Lisa", "Maggie"})); - // Unordered sets are unpredictable. We therefore only make sure that this - // compiles. - const auto json_string = rfl::flexbuf::write(homer); - const auto homer2 = rfl::flexbuf::read(json_string); - std::cout << "OK" << std::endl << std::endl; + const auto homer = + Person{.first_name = "Homer", .children = std::move(children)}; + + // Unordered sets are unpredictable. We therefore only make sure that this + // compiles. + const auto json_string = rfl::flexbuf::write(homer); + const auto homer2 = rfl::flexbuf::read(json_string); + std::cout << "OK" << std::endl << std::endl; } +} // namespace test_unordered_set diff --git a/tests/flexbuffers/test_variant.hpp b/tests/flexbuffers/test_variant.hpp index da4e1f70..1b3927ab 100644 --- a/tests/flexbuffers/test_variant.hpp +++ b/tests/flexbuffers/test_variant.hpp @@ -2,27 +2,29 @@ #include #include #include +#include #include #include #include "write_and_read.hpp" -// Makes sure that we can set default values. -void test_variant() { - std::cout << "test_variant" << std::endl; +namespace test_variant { - struct Circle { - rfl::Field<"radius", double> radius; - }; +struct Circle { + rfl::Field<"radius", double> radius; +}; - struct Rectangle { - rfl::Field<"height", double> height; - rfl::Field<"width", double> width; - }; +struct Rectangle { + rfl::Field<"height", double> height; + rfl::Field<"width", double> width; +}; - struct Square { - rfl::Field<"width", double> width; - }; +struct Square { + rfl::Field<"width", double> width; +}; + +void test() { + std::cout << std::source_location::current().function_name() << std::endl; using Shapes = std::variant>; @@ -30,3 +32,4 @@ void test_variant() { write_and_read(r); } +} // namespace test_variant diff --git a/tests/flexbuffers/tests.cpp b/tests/flexbuffers/tests.cpp index 3bb1137e..90095446 100644 --- a/tests/flexbuffers/tests.cpp +++ b/tests/flexbuffers/tests.cpp @@ -33,43 +33,43 @@ #include "test_variant.hpp" int main() { - test_readme_example(); - test_monster_example1(); - test_monster_example2(); - test_anonymous_fields(); - test_flatten_anonymous(); - test_optional_fields(); - test_unique_ptr(); - test_unique_ptr2(); - test_literal(); - test_variant(); - test_field_variant(); - test_tagged_union(); - test_custom_class1(); - test_custom_class2(); - test_custom_class3(); - test_box(); - test_ref(); + test_readme_example::test(); + test_monster_example1::test(); + test_monster_example2::test(); + test_anonymous_fields::test(); + test_flatten_anonymous::test(); + test_optional_fields::test(); + test_unique_ptr::test(); + test_unique_ptr2::test(); + test_literal::test(); + test_variant::test(); + test_field_variant::test(); + test_tagged_union::test(); + test_custom_class1::test(); + test_custom_class2::test(); + test_custom_class3::test(); + test_box::test(); + test_ref::test(); - test_deque(); - test_forward_list(); - test_list(); - test_map(); - test_multimap(); - test_multiset(); - test_set(); - test_string_map(); - test_string_unordered_map(); - test_unordered_map(); - test_unordered_multimap(); - test_unordered_multiset(); - test_unordered_set(); + test_deque::test(); + test_forward_list::test(); + test_list::test(); + test_map::test(); + test_multimap::test(); + test_multiset::test(); + test_set::test(); + test_string_map::test(); + test_string_unordered_map::test(); + test_unordered_map::test(); + test_unordered_multimap::test(); + test_unordered_multiset::test(); + test_unordered_set::test(); - test_custom_constructor(); + test_custom_constructor::test(); - test_all_of(); + test_all_of::test(); - test_save_load(); + test_save_load::test(); return 0; }