Skip to content

Commit 489afb5

Browse files
Clean up tests
1 parent 199b473 commit 489afb5

1 file changed

Lines changed: 51 additions & 32 deletions

File tree

src/modules/tests.cpp

Lines changed: 51 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,62 @@
1-
import rfl;
2-
31
#include <string>
4-
#include <type_traits>
52
#include <vector>
63

4+
import rfl;
5+
6+
using String = std::string;
7+
template <typename T>
8+
using Vector = std::vector<T>;
9+
10+
using rfl::Email;
11+
using rfl::Minimum;
12+
using rfl::Maximum;
13+
using rfl::Rename;
14+
using rfl::Timestamp;
15+
using rfl::Validator;
16+
17+
using Age = Validator<unsigned int, Minimum<0>, Maximum<130>>;
18+
719
struct Person {
8-
rfl::Rename<"firstName", std::string> first_name;
9-
rfl::Rename<"lastName", std::string> last_name = "Simpson";
10-
std::string town = "Springfield";
11-
rfl::Timestamp<"%Y-%m-%d"> birthday;
12-
unsigned int age;
13-
rfl::Email email;
14-
std::vector<Person> child;
20+
Rename<"firstName", String> first_name;
21+
Rename<"lastName", String> last_name = "Simpson";
22+
String town = "Springfield";
23+
Timestamp<"%Y-%m-%d"> birthday;
24+
Age age;
25+
Email email;
26+
Vector<Person> child;
1527
};
1628

1729
void test_json() {
18-
const auto bart = Person{.first_name = "Bart",
19-
.birthday = "1987-04-19",
20-
.age = 10,
21-
.email = "bart@simpson.com"};
22-
23-
const auto lisa = Person{.first_name = "Lisa",
24-
.birthday = "1987-04-19",
25-
.age = 8,
26-
.email = "lisa@simpson.com"};
27-
28-
const auto maggie = Person{.first_name = "Maggie",
29-
.birthday = "1987-04-19",
30-
.age = 0,
31-
.email = "maggie@simpson.com"};
32-
33-
const auto homer = Person{.first_name = "Homer",
34-
.birthday = "1987-04-19",
35-
.age = 45,
36-
.email = "homer@simpson.com",
37-
.child = std::vector<Person>({bart, lisa, maggie})};
30+
const Person bart{
31+
.first_name = "Bart",
32+
.birthday = "1987-04-19",
33+
.age = 10,
34+
.email = "bart@simpson.com"
35+
};
36+
37+
const Person lisa{
38+
.first_name = "Lisa",
39+
.birthday = "1987-04-19",
40+
.age = 8,
41+
.email = "lisa@simpson.com"
42+
};
43+
44+
const Person maggie{
45+
.birthday = "1987-04-19",
46+
.age = 0,
47+
.email = "maggie@simpson.com"
48+
};
49+
50+
const Person homer{
51+
.first_name = "Homer",
52+
.birthday = "1987-04-19",
53+
.age = 45,
54+
.email = "homer@simpson.com",
55+
.child = Vector<Person>({bart, lisa, maggie})
56+
};
3857
}
3958

4059
int main() {
41-
test_json();
42-
return 0;
60+
test_json();
61+
return 0;
4362
}

0 commit comments

Comments
 (0)