build: review example tests

This commit is contained in:
skypjack
2025-12-24 10:26:01 +01:00
parent 9bcd14f31f
commit 1f7efe511d
5 changed files with 104 additions and 94 deletions

View File

@@ -4,33 +4,37 @@
#include <entt/entity/registry.hpp>
#include <entt/entity/storage.hpp>
template<typename Type, typename Entity>
struct entt::storage_type<Type, Entity> {
struct SignalLess: testing::Test {
enum entity : std::uint32_t {};
template<typename, typename = void>
struct has_on_construct: std::false_type {};
template<typename Type>
struct has_on_construct<Type, std::void_t<decltype(&entt::storage_type_t<Type, entity>::on_construct)>>: std::true_type {};
template<typename Type>
static constexpr auto has_on_construct_v = has_on_construct<Type>::value;
};
template<typename Type>
struct entt::storage_type<Type, SignalLess::entity> {
// no signal regardless of element type ...
using type = basic_storage<Type, Entity>;
using type = basic_storage<Type, SignalLess::entity>;
};
template<typename Entity>
struct entt::storage_type<char, Entity> {
template<>
struct entt::storage_type<char, SignalLess::entity> {
// ... unless it's char, because yes.
using type = sigh_mixin<basic_storage<char, Entity>>;
using type = sigh_mixin<basic_storage<char, SignalLess::entity>>;
};
template<typename, typename, typename = void>
struct has_on_construct: std::false_type {};
template<typename Entity, typename Type>
struct has_on_construct<Entity, Type, std::void_t<decltype(&entt::storage_type_t<Type>::on_construct)>>: std::true_type {};
template<typename Entity, typename Type>
inline constexpr auto has_on_construct_v = has_on_construct<Entity, Type>::value;
TEST(Example, SignalLess) {
TEST_F(SignalLess, Example) {
// invoking registry::on_construct<int> is a compile-time error
ASSERT_FALSE((has_on_construct_v<entt::entity, int>));
ASSERT_TRUE((has_on_construct_v<entt::entity, char>));
ASSERT_FALSE((has_on_construct_v<int>));
ASSERT_TRUE((has_on_construct_v<char>));
entt::registry registry;
entt::basic_registry<entity> registry;
const std::array entity{registry.create()};
// literally a test for storage_adapter_mixin