From f3cd5d04b43d3dbfec7992b93cfa11c8326a9f3c Mon Sep 17 00:00:00 2001 From: Patrick Urbanke Date: Wed, 15 Nov 2023 21:45:09 +0100 Subject: [PATCH] Added struct flattening with tuple --- tests/json/test_flatten_tuple.hpp | 27 +++++++++++++++++++++++++++ tests/json/tests.cpp | 2 ++ 2 files changed, 29 insertions(+) create mode 100644 tests/json/test_flatten_tuple.hpp diff --git a/tests/json/test_flatten_tuple.hpp b/tests/json/test_flatten_tuple.hpp new file mode 100644 index 00000000..81442cfb --- /dev/null +++ b/tests/json/test_flatten_tuple.hpp @@ -0,0 +1,27 @@ +#include +#include +#include +#include +#include +#include + +#include "write_and_read.hpp" + +void test_flatten_tuple() { + std::cout << "test_flatten_tuple" << std::endl; + + using Person = std::tuple, int>; + + struct Employee { + rfl::Flatten person; + rfl::Box employer; + float salary; + }; + + const auto employee = Employee{ + .person = Person{"Homer", rfl::make_box("Simpson"), 45}, + .employer = rfl::make_box("Mr. Burns"), + .salary = 60000.0}; + + write_and_read(employee, R"(["Homer","Simpson",45,"Mr. Burns",60000.0])"); +} diff --git a/tests/json/tests.cpp b/tests/json/tests.cpp index 4d49ea7a..cff4107d 100644 --- a/tests/json/tests.cpp +++ b/tests/json/tests.cpp @@ -17,6 +17,7 @@ #include "test_field_variant.hpp" #include "test_flatten.hpp" #include "test_flatten_anonymous.hpp" +#include "test_flatten_tuple.hpp" #include "test_forward_list.hpp" #include "test_list.hpp" #include "test_literal.hpp" @@ -63,6 +64,7 @@ int main() { test_timestamp(); test_flatten(); test_flatten_anonymous(); + test_flatten_tuple(); test_deque(); test_forward_list(); test_list();