33
44#include < catch2/catch_test_macros.hpp>
55
6- #include < iostream>
76#include < string>
87#include < string_view>
98
@@ -23,7 +22,7 @@ struct TestStruct
2322 Person e;
2423};
2524
26- enum Color
25+ enum Color : std:: uint8_t
2726{
2827 Red,
2928 Green,
@@ -71,7 +70,7 @@ TEST_CASE("core", "[reflection]")
7170 auto s = SingleValueRecord { 42 };
7271 CHECK (Reflection::Inspect (s) == " value=42" );
7372
74- auto p = Person {
" John Doe" ,
" [email protected] " ,
42 };
73+ auto p = Person {
. name = " John Doe" ,
. email = " [email protected] " ,
. age = 42 };
7574 auto const result = Reflection::Inspect (p);
7675 CHECK (result ==
R"( name="John Doe" email="[email protected] " age=42)" );
7776}
8988
9089TEST_CASE (" nested" , " [reflection]" )
9190{
92- auto ts = TestStruct {
1 ,
2 .
0f ,
3.0 ,
" hello" , {
" John Doe" ,
" [email protected] " ,
42 } };
91+ auto ts = TestStruct {
92+ .a = 1 ,
93+ .b = 2 .0f ,
94+ .c = 3.0 ,
95+ .d = " hello" ,
96+ .
e = { .
name =
" John Doe" , .
email =
" [email protected] " , .
age =
42 },
97+ };
9398 auto const result = Reflection::Inspect (ts);
9499 CHECK (result ==
R"( a=1 b=2 c=3 d="hello" e={name="John Doe" email="[email protected] " age=42})" );
95100}
96101
97102TEST_CASE (" EnumerateMembers.index_and_value" , " [reflection]" )
98103{
99- auto ps = Person {
" John Doe" ,
" [email protected] " ,
42 };
104+ auto ps = Person {
. name = " John Doe" ,
. email = " [email protected] " ,
. age = 42 };
100105 Reflection::EnumerateMembers (ps, []<size_t I>(auto && value) {
101106 if constexpr (I == 0 )
102107 {
@@ -118,22 +123,22 @@ TEST_CASE("EnumerateMembers.index_and_type", "[reflection]")
118123 Reflection::EnumerateMembers<Person>([]<auto I, typename T>() {
119124 if constexpr (I == 0 )
120125 {
121- static_assert (std::same_as<T,std::string_view>);
126+ static_assert (std::same_as<T, std::string_view>);
122127 }
123128 if constexpr (I == 1 )
124129 {
125- static_assert (std::same_as<T,std::string>);
130+ static_assert (std::same_as<T, std::string>);
126131 }
127132 if constexpr (I == 2 )
128133 {
129- static_assert (std::same_as<T,int >);
134+ static_assert (std::same_as<T, int >);
130135 }
131136 });
132137}
133138
134139TEST_CASE (" CallOnMembers" , " [reflection]" )
135140{
136- auto ps = Person {
" John Doe" ,
" [email protected] " ,
42 };
141+ auto ps = Person {
. name = " John Doe" ,
. email = " [email protected] " ,
. age = 42 };
137142 std::string result;
138143 Reflection::CallOnMembers (ps, [&result](auto && name, auto && value) {
139144 result += name;
@@ -163,7 +168,7 @@ struct S
163168
164169TEST_CASE (" FoldMembers.value" , " [reflection]" )
165170{
166- auto const s = S { 1 , 2 , 3 };
171+ auto const s = S { . a = 1 , . b = 2 , . c = 3 };
167172 auto const result = Reflection::FoldMembers (
168173 s, 0 , [](auto && /* name*/ , auto && memberValue, auto && accum) { return accum + memberValue; });
169174
@@ -203,23 +208,20 @@ TEST_CASE("Compare.simple", "[reflection]")
203208 CHECK (diff == " id: 1 != 2\n name: John Doe != Jane Doe\n age: 42 != 43\n " );
204209}
205210
206-
207-
208211TEST_CASE (" Compare.simple_with_indexing" , " [reflection]" )
209212{
210213 auto const r1 = Record { .id = 1 , .name = " John Doe" , .age = 42 };
211214 auto const r2 = Record { .id = 2 , .name = " John Doe" , .age = 42 };
212215
213- size_t check = - 1 ;
214- auto differenceCallback = [&](size_t ind , auto const & lhs, auto const & rhs) {
215- check = ind ;
216+ auto check = static_cast < size_t >(- 1 ) ;
217+ auto differenceCallback = [&](size_t index , auto const & /* lhs*/ , auto const & /* rhs*/ ) {
218+ check = index ;
216219 };
217220
218221 Reflection::CollectDifferences (r1, r2, differenceCallback);
219222 CHECK (check == 0 );
220223}
221224
222-
223225struct Table
224226{
225227 Record first;
0 commit comments