@@ -82,8 +82,21 @@ struct value_two
82
82
int number = {};
83
83
vector_one<value_one> ones = {};
84
84
key key = {};
85
+
86
+ friend std::ostream& operator <<(std::ostream& s, const value_two& value)
87
+ {
88
+ return s << fmt::format (" number = {}, ones = {}, key = '{}'" ,
89
+ value.number ,
90
+ value.ones .size (),
91
+ value.key .str );
92
+ }
85
93
};
86
94
95
+ std::ostream& operator <<(std::ostream& s, const two_boxed& value)
96
+ {
97
+ return s << value.two .get ();
98
+ }
99
+
87
100
const key& get_table_key (const two_boxed& two) { return two.two .get ().key ; }
88
101
89
102
std::size_t xx_hash_value (const two_boxed& value)
@@ -98,6 +111,10 @@ two_boxed::two_boxed(value_two val)
98
111
99
112
} // namespace model
100
113
114
+ template <>
115
+ struct fmt ::formatter<model::two_boxed> : ostream_formatter
116
+ {};
117
+
101
118
BOOST_HANA_ADAPT_STRUCT (model::value_two, number, ones, key);
102
119
103
120
namespace model {
@@ -224,6 +241,14 @@ TEST_CASE("Test exception while circular converting")
224
241
immer::archive::to_json_with_auto_archive (value, names);
225
242
// REQUIRE(json_str == "");
226
243
244
+ SECTION (" Try to load" )
245
+ {
246
+ const auto loaded =
247
+ immer::archive::from_json_with_auto_archive<model::value_one>(
248
+ json_str, names);
249
+ REQUIRE (loaded == value);
250
+ }
251
+
227
252
/* *
228
253
* NOTE: There is a circular dependency between archives: to convert
229
254
* value_one we need to convert value_two and vice versa.
@@ -554,16 +579,6 @@ TEST_CASE("Test circular dependency archives", "[conversion]")
554
579
REQUIRE (format_twos.impl ().root == format_twos_2.impl ().root );
555
580
}
556
581
REQUIRE (test::to_json (value.twos_table ) == test::to_json (format_twos));
557
-
558
- // SECTION("Compare structure")
559
- // {
560
- // const auto [format_twos_json, ar] =
561
- // immer::archive::to_json_with_auto_archive(format_twos,
562
- // format_names);
563
- // const auto [model_twos_json, ar2] =
564
- // immer::archive::to_json_with_auto_archive(value, names);
565
- // REQUIRE(model_twos_json == format_twos_json);
566
- // }
567
582
}
568
583
569
584
SECTION (" map" )
@@ -635,4 +650,23 @@ TEST_CASE("Test circular dependency archives", "[conversion]")
635
650
REQUIRE (model_twos_json == format_twos_json);
636
651
}
637
652
}
653
+
654
+ SECTION (" everything" )
655
+ {
656
+ const auto convert = [&](const auto & value) {
657
+ return immer::archive::convert_container (
658
+ model_archives, format_load_archives, value);
659
+ };
660
+ const auto format_value = [&] {
661
+ auto result = format::value_one{};
662
+ hana::for_each (hana::keys (result), [&](auto key) {
663
+ hana::at_key (result, key) = convert (hana::at_key (value, key));
664
+ });
665
+ return result;
666
+ }();
667
+ const auto [format_json_str, model_archives] =
668
+ immer::archive::to_json_with_auto_archive (format_value,
669
+ format_names);
670
+ REQUIRE (format_json_str == json_str);
671
+ }
638
672
}
0 commit comments