Repository navigation
Expand file tree
/
Copy pathtest_monster_example.cpp
More file actions
67 lines (50 loc) · 1.56 KB
/
Copy pathtest_monster_example.cpp
File metadata and controls
67 lines (50 loc) · 1.56 KB
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
#include <gtest/gtest.h>
#include <rfl.hpp>
#include <rfl/env.hpp>
#include <string>
#include <vector>
#include "write_and_read.hpp"
namespace test_monster_example {
using Color = rfl::Literal<"Red", "Green", "Blue">;
struct Weapon {
std::string name;
short damage;
};
using Equipment = rfl::Variant<rfl::Field<"weapon", Weapon>>;
struct Vec3 {
float x;
float y;
float z;
};
struct Monster {
Vec3 pos;
short mana = 150;
short hp = 100;
std::string name;
bool friendly = false;
std::vector<int> inventory;
Color color = Color::make<"Blue">();
std::vector<Weapon> weapons;
Equipment equipped;
std::vector<Vec3> path;
};
TEST(env, test_monster_example) {
const auto scoped_environment = test_env::ScopedEnvironment();
const auto sword = Weapon{.name = "Sword", .damage = 3};
const auto axe = Weapon{.name = "Axe", .damage = 5};
const auto weapons = std::vector<Weapon>({sword, axe});
const auto position = Vec3{1.0f, 2.0f, 3.0f};
const auto inventory = std::vector<int>({0, 1, 2, 3, 4, 5, 6, 7, 8, 9});
const auto orc = Monster{.pos = position,
.mana = 150,
.hp = 80,
.name = "MyMonster",
.inventory = inventory,
.color = Color::make<"Red">(),
.weapons = weapons,
.equipped = rfl::make_field<"weapon">(axe)};
rfl::env::write(orc);
const auto read_orc = rfl::env::read<Monster>();
ASSERT_FALSE(read_orc);
}
} // namespace test_monster_example