-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathsrefl.cpp
113 lines (94 loc) · 3.82 KB
/
srefl.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#include "mirrow/srefl/srefl.hpp"
#define CATCH_CONFIG_MAIN
#include "catch.hpp"
#include <string>
#include <vector>
using namespace mirrow::srefl;
class Person final {
public:
static std::string family_name;
Person(const std::string& name, float height)
: name(name), height(height) {}
void AddChild(const Person& person) { children.push_back(person); }
std::string Name() const { return name; }
float Height() const { return height; }
Person& operator+(const Person& child) {
AddChild(child);
return *this;
}
std::string name;
float height;
std::vector<Person> children;
};
std::string Person::family_name = "little home";
enum class MyEnum {
Value1 = 1,
Value2,
Value3,
};
TEST_CASE("strip name") {
static_assert(strip_name("Person") == "Person");
static_assert(strip_name("::Person") == "Person");
static_assert(strip_name("namespace::Person") == "Person");
static_assert(strip_name("&Person::Foo") == "Foo");
static_assert(strip_name("&Foo") == "Foo");
}
TEST_CASE("field traits") {
SECTION("member function") {
constexpr auto traits =
field_traits{&Person::AddChild, "&Person::AddChild"};
static_assert(std::is_same_v<decltype(traits)::return_type, void>);
static_assert(std::is_same_v<decltype(traits)::args,
mirrow::util::type_list<const Person&>>);
static_assert(!traits.is_const_member());
static_assert(traits.is_member());
static_assert(traits.pointer() == &Person::AddChild);
static_assert(traits.name() == "AddChild");
}
SECTION("member function") {
constexpr auto traits = field_traits{&Person::operator+, "&operator+"};
static_assert(!traits.is_const_member());
static_assert(std::is_same_v<decltype(traits)::return_type, Person&>);
static_assert(std::is_same_v<decltype(traits)::args,
mirrow::util::type_list<const Person&>>);
static_assert(traits.pointer() == &Person::operator+);
static_assert(traits.name() == "operator+");
}
SECTION("member const function") {
constexpr auto traits =
field_traits{&Person::Height, "&Person::Height"};
static_assert(std::is_same_v<decltype(traits)::return_type, float>);
static_assert(
std::is_same_v<decltype(traits)::args, mirrow::util::type_list<>>);
static_assert(traits.is_const_member());
static_assert(traits.is_member());
static_assert(traits.pointer() == &Person::Height);
static_assert(traits.name() == "Height");
}
SECTION("member variable") {
constexpr auto traits = field_traits(&Person::name, "&Person::name");
static_assert(!traits.is_const_member());
static_assert(traits.is_member());
static_assert(std::is_same_v<decltype(traits)::type, std::string>);
static_assert(traits.pointer() == &Person::name);
static_assert(traits.name() == "name");
}
SECTION("member variable") {
constexpr auto traits =
field_traits(&Person::children, "&Person::children");
static_assert(!traits.is_const_member());
static_assert(traits.is_member());
static_assert(
std::is_same_v<decltype(traits)::type, std::vector<Person>>);
static_assert(traits.pointer() == &Person::children);
static_assert(traits.name() == "children");
}
SECTION("static member variable") {
constexpr auto traits =
field_traits(&Person::family_name, "&Person::family_name");
static_assert(!traits.is_member());
static_assert(std::is_same_v<decltype(traits)::type, std::string>);
static_assert(traits.pointer() == &Person::family_name);
static_assert(traits.name() == "family_name");
}
}