From d7e9cc74966211ec9724bb61630269ac0b123a56 Mon Sep 17 00:00:00 2001 From: Patrick Urbanke Date: Wed, 15 Nov 2023 21:01:37 +0100 Subject: [PATCH] Add a flatten anonymous test for flexbuffers --- tests/flexbuffers/test_flatten_anonymous.hpp | 33 ++++++++++++++++++++ tests/flexbuffers/tests.cpp | 2 ++ 2 files changed, 35 insertions(+) create mode 100644 tests/flexbuffers/test_flatten_anonymous.hpp diff --git a/tests/flexbuffers/test_flatten_anonymous.hpp b/tests/flexbuffers/test_flatten_anonymous.hpp new file mode 100644 index 00000000..5971adb4 --- /dev/null +++ b/tests/flexbuffers/test_flatten_anonymous.hpp @@ -0,0 +1,33 @@ +#include +#include +#include +#include +#include +#include + +#include "write_and_read.hpp" + +void test_flatten_anonymous() { + std::cout << "test_flatten_anonymous" << std::endl; + + struct Person { + std::string first_name; + rfl::Box last_name; + int age; + }; + + struct Employee { + rfl::Flatten person; + rfl::Box employer; + float salary; + }; + + const auto employee = Employee{ + .person = Person{.first_name = "Homer", + .last_name = rfl::make_box("Simpson"), + .age = 45}, + .employer = rfl::make_box("Mr. Burns"), + .salary = 60000.0}; + + write_and_read(employee); +} diff --git a/tests/flexbuffers/tests.cpp b/tests/flexbuffers/tests.cpp index 0b2bc4a7..3bb1137e 100644 --- a/tests/flexbuffers/tests.cpp +++ b/tests/flexbuffers/tests.cpp @@ -7,6 +7,7 @@ #include "test_custom_constructor.hpp" #include "test_deque.hpp" #include "test_field_variant.hpp" +#include "test_flatten_anonymous.hpp" #include "test_forward_list.hpp" #include "test_list.hpp" #include "test_literal.hpp" @@ -36,6 +37,7 @@ int main() { test_monster_example1(); test_monster_example2(); test_anonymous_fields(); + test_flatten_anonymous(); test_optional_fields(); test_unique_ptr(); test_unique_ptr2();