1
0
Fork 0

Codechange: add unit test against over optimisation of enum-bitmasks

pull/13506/head
Rubidium 2025-01-25 15:52:53 +01:00 committed by rubidium42
parent 90f5a9440c
commit 0f5f5714b3
1 changed files with 16 additions and 0 deletions

View File

@ -13,6 +13,8 @@
#include "../stdafx.h" #include "../stdafx.h"
#include "../core/enum_type.hpp"
#include "../3rdparty/catch2/catch.hpp" #include "../3rdparty/catch2/catch.hpp"
enum TestEnum : int8_t { enum TestEnum : int8_t {
@ -29,3 +31,17 @@ TEST_CASE("EnumOverOptimisation_BoundsCheck")
TestEnum three = static_cast<TestEnum>(3); TestEnum three = static_cast<TestEnum>(3);
CHECK(TWO < three); CHECK(TWO < three);
} }
enum class TestEnumFlags : uint8_t {
Zero = 0,
One = 1 << 0,
Two = 1 << 1,
};
DECLARE_ENUM_AS_BIT_SET(TestEnumFlags)
TEST_CASE("EnumOverOptimisation_Bitmask")
{
TestEnumFlags three = TestEnumFlags::One | TestEnumFlags::Two;
CHECK(HasFlag(three, TestEnumFlags::One));
CHECK(HasFlag(three, TestEnumFlags::Two));
}