From 949a94fd81c3f5f1788c17bb986dd9dde2f9c735 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Wed, 3 Apr 2024 21:21:49 +0200 Subject: entity: fix getting vector min/max Leads to returning {0,0} and the field becoming uneditable in the GUI. --- test/entity.cpp | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) (limited to 'test/entity.cpp') diff --git a/test/entity.cpp b/test/entity.cpp index 3c099a37..36302662 100644 --- a/test/entity.cpp +++ b/test/entity.cpp @@ -1,6 +1,8 @@ #include "app.hpp" #include "compat/assert.hpp" +#include "compat/limits.hpp" #include "entity/metadata.hpp" +#include "entity/accessor.hpp" #include using namespace floormat; @@ -148,8 +150,10 @@ void test_type_name() constexpr StringView name = name_of; fm_assert(name.contains("foobar"_s)); static_assert(name.data() == name_of.data()); +#ifndef __CLION_IDE__ static_assert(name_of != name_of); static_assert(name_of != name_of); +#endif using foobar2 = foobar; static_assert(name_of.data() == name_of.data()); } @@ -239,6 +243,44 @@ void test_erased_constraints() fm_assert(erased.get_max_length(&x) == 42); } +constexpr bool test_range1() +{ + constexpr auto x = TestAccessors{}; + constexpr auto r = m_foo.get_range(x); + static_assert(r.max == limits::max); + return true; +} + +void test_range2() +{ + constexpr auto x = TestAccessors{}; + constexpr auto rʹ = m_foo.get_range(x); + constexpr auto A = m_foo.erased(); + auto r = A.get_range(&x); + auto i = r.convert(); + fm_assert(i.second == rʹ.max); +} + +constexpr bool test_range3() +{ + constexpr auto f = entity::type::field("vec"_s, constantly(Vector2i(0)), [](auto&&, auto&&) {}); + constexpr auto r = f.get_range(f.range, TestAccessors{}); + static_assert(r.max == Vector2i(limits::max)); + + return true; +} + +void test_range4() +{ + constexpr auto x = TestAccessors{}; + constexpr auto f = entity::type::field("vec"_s, constantly(Vector2i(0)), [](auto&&, auto&&) {}); + constexpr auto rʹ = f.get_range(f.range, TestAccessors{}); + const auto A = f.erased(); + const auto r = A.get_range(&x).convert(); + fm_assert(r.first == rʹ.min); + fm_assert(r.second == rʹ.max); +} + } // namespace void test_app::test_entity() @@ -254,6 +296,10 @@ void test_app::test_entity() test_metadata(); test_constraints(); test_erased_constraints(); + static_assert(test_range1()); + test_range2(); + static_assert(test_range3()); + test_range4(); } } // namespace floormat -- cgit v1.2.3