From 0f5f5714b34d9a4878138b32c0da05d00e8c3bb1 Mon Sep 17 00:00:00 2001 From: Rubidium Date: Sat, 25 Jan 2025 15:52:53 +0100 Subject: [PATCH] Codechange: add unit test against over optimisation of enum-bitmasks --- src/tests/enum_over_optimisation.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/tests/enum_over_optimisation.cpp b/src/tests/enum_over_optimisation.cpp index ef88150e64..bdb3c6a9a4 100644 --- a/src/tests/enum_over_optimisation.cpp +++ b/src/tests/enum_over_optimisation.cpp @@ -13,6 +13,8 @@ #include "../stdafx.h" +#include "../core/enum_type.hpp" + #include "../3rdparty/catch2/catch.hpp" enum TestEnum : int8_t { @@ -29,3 +31,17 @@ TEST_CASE("EnumOverOptimisation_BoundsCheck") TestEnum three = static_cast(3); 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)); +}