mirror of
https://github.com/Neargye/magic_enum.git
synced 2026-01-10 23:44:29 +00:00
parent
785b3f253d
commit
9d1cf196cf
3 changed files with 34 additions and 7 deletions
|
|
@ -1026,6 +1026,11 @@ TEST_CASE("constexpr_for") {
|
|||
});
|
||||
}
|
||||
|
||||
#ifdef _MSC_VER
|
||||
# pragma warning(push)
|
||||
# pragma warning(disable : 4064)
|
||||
#endif
|
||||
|
||||
static int switch_case_2d(Color color, Directions direction) {
|
||||
switch (magic_enum::enum_fuse(color, direction).value()) {
|
||||
case magic_enum::enum_fuse(Color::RED, Directions::Up).value():
|
||||
|
|
@ -1043,21 +1048,24 @@ static int switch_case_3d(Color color, Directions direction, Index index) {
|
|||
switch (magic_enum::enum_fuse(color, direction, index).value()) {
|
||||
case magic_enum::enum_fuse(Color::RED, Directions::Up, Index::zero).value():
|
||||
return 1;
|
||||
// model accidental removal of last index, must not match anything
|
||||
case magic_enum::enum_fuse(Color::BLUE, Directions::Up).value():
|
||||
case magic_enum::enum_fuse(Color::BLUE, Directions::Up, Index::zero).value():
|
||||
return 2;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef _MSC_VER
|
||||
# pragma warning(pop)
|
||||
#endif
|
||||
|
||||
TEST_CASE("multdimensional-switch-case") {
|
||||
REQUIRE(switch_case_2d(Color::RED, Directions::Up) == 1);
|
||||
REQUIRE(switch_case_2d(Color::RED, Directions::Down) == 0);
|
||||
REQUIRE(switch_case_2d(Color::BLUE, Directions::Up) == 0);
|
||||
REQUIRE(switch_case_2d(Color::BLUE, Directions::Down) == 2);
|
||||
REQUIRE(switch_case_3d(Color::RED, Directions::Up, Index::zero) == 1);
|
||||
REQUIRE(switch_case_3d(Color::BLUE, Directions::Up, Index::zero) == 0);
|
||||
REQUIRE(switch_case_3d(Color::BLUE, Directions::Up, Index::zero) == 2);
|
||||
REQUIRE(switch_case_3d(Color::BLUE, Directions::Up, Index::one) == 0);
|
||||
REQUIRE(switch_case_3d(Color::BLUE, Directions::Up, Index::two) == 0);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue