-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes problem of working on structs with only a single element
- Loading branch information
Showing
2 changed files
with
29 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,6 +30,11 @@ enum Color | |
Blue | ||
}; | ||
|
||
struct SingleValueRecord | ||
{ | ||
int value; | ||
}; | ||
|
||
TEST_CASE("GetName", "[reflection]") | ||
{ | ||
auto const enumValue = Reflection::GetName<Color::Red>(); | ||
|
@@ -38,13 +43,34 @@ TEST_CASE("GetName", "[reflection]") | |
auto const enumValue2 = Reflection::GetName<Color::Green>(); | ||
CHECK(enumValue2 == "Green"); | ||
|
||
auto const person = Person { "John Doe", "[email protected]", 42 }; | ||
auto const memberName1 = Reflection::GetName<&Person::email>(); | ||
CHECK(memberName1 == "email"); | ||
|
||
auto const singleValueField = Reflection::GetName<&SingleValueRecord::value>(); | ||
CHECK(singleValueField == "value"); | ||
} | ||
|
||
TEST_CASE("single value record", "[reflection]") | ||
{ | ||
static_assert(Reflection::CountMembers<SingleValueRecord> == 1); | ||
|
||
auto const s = SingleValueRecord { 42 }; | ||
auto const t = Reflection::ToTuple(s); | ||
|
||
CHECK(std::get<0>(t) == 42); | ||
CHECK(Reflection::GetMemberAt<0>(s) == 42); | ||
|
||
Reflection::CallOnMembers(s, [](auto&& name, auto&& value) { | ||
CHECK(name == "value"); | ||
CHECK(value == 42); | ||
}); | ||
} | ||
|
||
TEST_CASE("core", "[reflection]") | ||
{ | ||
auto s = SingleValueRecord { 42 }; | ||
CHECK(Reflection::Inspect(s) == "value=42"); | ||
|
||
auto p = Person { "John Doe", "[email protected]", 42 }; | ||
auto const result = Reflection::Inspect(p); | ||
CHECK(result == R"(name="John Doe" email="[email protected]" age=42)"); | ||
|