diff --git a/tests/flexbuffers/test_monster_example.hpp b/tests/flexbuffers/test_monster_example.hpp new file mode 100644 index 00000000..bcf114e2 --- /dev/null +++ b/tests/flexbuffers/test_monster_example.hpp @@ -0,0 +1,61 @@ +#include +#include +#include +#include +#include + +#include "write_and_read.hpp" + +void test_monster_example() { + std::cout << "test_monster_example" << std::endl; + + using Color = rfl::Literal<"Red", "Green", "Blue">; + + struct Weapon { + std::string name; + short damage; + }; + + using Equipment = rfl::Variant>; + + 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 inventory; + Color color = Color::make<"Blue">(); + std::vector weapons; + Equipment equipped; + std::vector path; + }; + + const auto sword = Weapon{.name = "Sword", .damage = 3}; + const auto axe = Weapon{.name = "Axe", .damage = 5}; + + const auto weapons = std::vector({sword, axe}); + + const auto position = Vec3{1.0f, 2.0f, 3.0f}; + + const auto inventory = + std::vector({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)}; + + write_and_read(orc); +} + diff --git a/tests/flexbuffers/tests.cpp b/tests/flexbuffers/tests.cpp index 88396bd9..3f86e5c5 100644 --- a/tests/flexbuffers/tests.cpp +++ b/tests/flexbuffers/tests.cpp @@ -11,6 +11,7 @@ #include "test_list.hpp" #include "test_literal.hpp" #include "test_map.hpp" +#include "test_monster_example.hpp" #include "test_multimap.hpp" #include "test_multiset.hpp" #include "test_optional_fields.hpp" @@ -30,6 +31,7 @@ int main() { test_readme_example(); + test_monster_example(); test_anonymous_fields(); test_optional_fields(); test_unique_ptr();