3
3
4
4
#include < catch2/catch_test_macros.hpp>
5
5
6
- #include < iostream>
7
6
#include < string>
8
7
#include < string_view>
9
8
@@ -23,7 +22,7 @@ struct TestStruct
23
22
Person e;
24
23
};
25
24
26
- enum Color
25
+ enum Color : std:: uint8_t
27
26
{
28
27
Red,
29
28
Green,
@@ -71,7 +70,7 @@ TEST_CASE("core", "[reflection]")
71
70
auto s = SingleValueRecord { 42 };
72
71
CHECK (Reflection::Inspect (s) == " value=42" );
73
72
74
- auto p = Person {
" John Doe" ,
" [email protected] " ,
42 };
73
+ auto p = Person {
. name = " John Doe" ,
. email = " [email protected] " ,
. age = 42 };
75
74
auto const result = Reflection::Inspect (p);
76
75
CHECK (result ==
R"( name="John Doe" email="[email protected] " age=42)" );
77
76
}
89
88
90
89
TEST_CASE (" nested" , " [reflection]" )
91
90
{
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
+ };
93
98
auto const result = Reflection::Inspect (ts);
94
99
CHECK (result ==
R"( a=1 b=2 c=3 d="hello" e={name="John Doe" email="[email protected] " age=42})" );
95
100
}
96
101
97
102
TEST_CASE (" EnumerateMembers.index_and_value" , " [reflection]" )
98
103
{
99
- auto ps = Person {
" John Doe" ,
" [email protected] " ,
42 };
104
+ auto ps = Person {
. name = " John Doe" ,
. email = " [email protected] " ,
. age = 42 };
100
105
Reflection::EnumerateMembers (ps, []<size_t I>(auto && value) {
101
106
if constexpr (I == 0 )
102
107
{
@@ -118,22 +123,22 @@ TEST_CASE("EnumerateMembers.index_and_type", "[reflection]")
118
123
Reflection::EnumerateMembers<Person>([]<auto I, typename T>() {
119
124
if constexpr (I == 0 )
120
125
{
121
- static_assert (std::same_as<T,std::string_view>);
126
+ static_assert (std::same_as<T, std::string_view>);
122
127
}
123
128
if constexpr (I == 1 )
124
129
{
125
- static_assert (std::same_as<T,std::string>);
130
+ static_assert (std::same_as<T, std::string>);
126
131
}
127
132
if constexpr (I == 2 )
128
133
{
129
- static_assert (std::same_as<T,int >);
134
+ static_assert (std::same_as<T, int >);
130
135
}
131
136
});
132
137
}
133
138
134
139
TEST_CASE (" CallOnMembers" , " [reflection]" )
135
140
{
136
- auto ps = Person {
" John Doe" ,
" [email protected] " ,
42 };
141
+ auto ps = Person {
. name = " John Doe" ,
. email = " [email protected] " ,
. age = 42 };
137
142
std::string result;
138
143
Reflection::CallOnMembers (ps, [&result](auto && name, auto && value) {
139
144
result += name;
@@ -163,7 +168,7 @@ struct S
163
168
164
169
TEST_CASE (" FoldMembers.value" , " [reflection]" )
165
170
{
166
- auto const s = S { 1 , 2 , 3 };
171
+ auto const s = S { . a = 1 , . b = 2 , . c = 3 };
167
172
auto const result = Reflection::FoldMembers (
168
173
s, 0 , [](auto && /* name*/ , auto && memberValue, auto && accum) { return accum + memberValue; });
169
174
@@ -203,23 +208,20 @@ TEST_CASE("Compare.simple", "[reflection]")
203
208
CHECK (diff == " id: 1 != 2\n name: John Doe != Jane Doe\n age: 42 != 43\n " );
204
209
}
205
210
206
-
207
-
208
211
TEST_CASE (" Compare.simple_with_indexing" , " [reflection]" )
209
212
{
210
213
auto const r1 = Record { .id = 1 , .name = " John Doe" , .age = 42 };
211
214
auto const r2 = Record { .id = 2 , .name = " John Doe" , .age = 42 };
212
215
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 ;
216
219
};
217
220
218
221
Reflection::CollectDifferences (r1, r2, differenceCallback);
219
222
CHECK (check == 0 );
220
223
}
221
224
222
-
223
225
struct Table
224
226
{
225
227
Record first;
0 commit comments