diff --git a/test/entt/meta/meta.cpp b/test/entt/meta/meta.cpp index b9b233a0e..637079ec2 100644 --- a/test/entt/meta/meta.cpp +++ b/test/entt/meta/meta.cpp @@ -6,9 +6,19 @@ #include #include +template +void set(Type &prop, Type value) { + prop = value; +} + +template +Type get(Type &prop) { + return prop; +} + enum class properties { prop_int, - prop_bool + prop_bool, }; struct empty_type { @@ -138,11 +148,13 @@ struct Meta: public ::testing::Test { static void SetUpTestCase() { entt::reflect().conv(); - entt::reflect("char"_hs, std::make_pair(properties::prop_int, 42)); + entt::reflect("char"_hs, std::make_pair(properties::prop_int, 42)) + .data<&set, &get>("value"_hs); entt::reflect() .data("prop_bool"_hs) - .data("prop_int"_hs); + .data("prop_int"_hs) + .data<&set, &get>("value"_hs); entt::reflect().data<0u>("min"_hs).data<100u>("max"_hs); @@ -1938,6 +1950,22 @@ TEST_F(Meta, ArithmeticTypeAndNamedConstants) { ASSERT_EQ(type.data("max"_hs).get({}).cast(), 100u); } +TEST_F(Meta, Variables) { + auto p_data = entt::resolve().data("value"_hs); + auto c_data = entt::resolve("char"_hs).data("value"_hs); + + properties prop{properties::prop_int}; + char c = 'c'; + + p_data.set(prop, properties::prop_bool); + c_data.set(c, 'x'); + + ASSERT_EQ(p_data.get(prop).cast(), properties::prop_bool); + ASSERT_EQ(c_data.get(c).cast(), 'x'); + ASSERT_EQ(prop, properties::prop_bool); + ASSERT_EQ(c, 'x'); +} + TEST_F(Meta, Unregister) { ASSERT_FALSE(entt::unregister()); ASSERT_TRUE(entt::unregister());