tomato-testing/test/entt/meta/meta_template.cpp
Green Sky 5c7231b7a3 Squashed 'external/entt/entt/' content from commit fef92113
git-subtree-dir: external/entt/entt
git-subtree-split: fef921132cae7588213d0f9bcd2fb9c8ffd8b7fc
2023-07-25 11:29:51 +02:00

50 lines
1.8 KiB
C++

#include <gtest/gtest.h>
#include <entt/core/type_traits.hpp>
#include <entt/meta/meta.hpp>
#include <entt/meta/resolve.hpp>
#include <entt/meta/template.hpp>
template<typename>
struct function_type;
template<typename Ret, typename... Args>
struct function_type<Ret(Args...)> {};
template<typename Ret, typename... Args>
struct entt::meta_template_traits<function_type<Ret(Args...)>> {
using class_type = meta_class_template_tag<function_type>;
using args_type = type_list<Ret, Args...>;
};
TEST(MetaTemplate, Invalid) {
const auto type = entt::resolve<int>();
ASSERT_FALSE(type.is_template_specialization());
ASSERT_EQ(type.template_arity(), 0u);
ASSERT_EQ(type.template_type(), entt::meta_type{});
ASSERT_EQ(type.template_arg(0u), entt::meta_type{});
}
TEST(MetaTemplate, Valid) {
const auto type = entt::resolve<entt::type_list<int, char>>();
ASSERT_TRUE(type.is_template_specialization());
ASSERT_EQ(type.template_arity(), 2u);
ASSERT_EQ(type.template_type(), entt::resolve<entt::meta_class_template_tag<entt::type_list>>());
ASSERT_EQ(type.template_arg(0u), entt::resolve<int>());
ASSERT_EQ(type.template_arg(1u), entt::resolve<char>());
ASSERT_EQ(type.template_arg(2u), entt::meta_type{});
}
TEST(MetaTemplate, CustomTraits) {
const auto type = entt::resolve<function_type<void(int, const char &)>>();
ASSERT_TRUE(type.is_template_specialization());
ASSERT_EQ(type.template_arity(), 3u);
ASSERT_EQ(type.template_type(), entt::resolve<entt::meta_class_template_tag<function_type>>());
ASSERT_EQ(type.template_arg(0u), entt::resolve<void>());
ASSERT_EQ(type.template_arg(1u), entt::resolve<int>());
ASSERT_EQ(type.template_arg(2u), entt::resolve<char>());
ASSERT_EQ(type.template_arg(3u), entt::meta_type{});
}