From d911c70338fa5bcc1e36cd1010c0eec21b65c22d Mon Sep 17 00:00:00 2001 From: Sander Mertens Date: Wed, 18 Dec 2024 11:20:23 -0800 Subject: [PATCH] #1466 Add test that ensures empty enum reflection works --- test/cpp/project.json | 3 ++- test/cpp/src/Enum.cpp | 10 ++++++++++ test/cpp/src/main.cpp | 7 ++++++- 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/test/cpp/project.json b/test/cpp/project.json index c03ff8d5f..abb70ad63 100644 --- a/test/cpp/project.json +++ b/test/cpp/project.json @@ -416,7 +416,8 @@ "mixed_auto_manual_constants", "enum_class_mixed_auto_manual_constants", "enum_child_count", - "multi_world_constant_ids" + "multi_world_constant_ids", + "empty_enum" ] }, { "id": "Union", diff --git a/test/cpp/src/Enum.cpp b/test/cpp/src/Enum.cpp index 509ba178c..e55f7173f 100644 --- a/test/cpp/src/Enum.cpp +++ b/test/cpp/src/Enum.cpp @@ -90,6 +90,8 @@ enum class EnumClassWithLargeConstant { X, Y, Z = 1000 }; +enum EmptyEnum { }; + /* Optional, but improves compile time */ FLECS_ENUM_LAST(StandardEnum, Blue) FLECS_ENUM_LAST(SparseEnum, Grey) @@ -1205,3 +1207,11 @@ void Enum_multi_world_constant_ids(void) { test_assert(green_a == world_a.to_entity(StandardEnum::Green)); test_assert(blue_a == world_a.to_entity(StandardEnum::Blue)); } + +void Enum_empty_enum(void) { + flecs::world ecs; + + auto enum_type = flecs::enum_type(ecs); + + test_int(enum_type.index_by_value(0), -1); +} diff --git a/test/cpp/src/main.cpp b/test/cpp/src/main.cpp index cb47f881c..6a2b7a0de 100644 --- a/test/cpp/src/main.cpp +++ b/test/cpp/src/main.cpp @@ -405,6 +405,7 @@ void Enum_mixed_auto_manual_constants(void); void Enum_enum_class_mixed_auto_manual_constants(void); void Enum_enum_child_count(void); void Enum_multi_world_constant_ids(void); +void Enum_empty_enum(void); // Testsuite 'Union' void Union_add_case(void); @@ -2980,6 +2981,10 @@ bake_test_case Enum_testcases[] = { { "multi_world_constant_ids", Enum_multi_world_constant_ids + }, + { + "empty_enum", + Enum_empty_enum } }; @@ -6926,7 +6931,7 @@ static bake_test_suite suites[] = { "Enum", NULL, NULL, - 40, + 41, Enum_testcases }, {