mirror of
https://github.com/Neargye/magic_enum.git
synced 2026-01-10 23:44:29 +00:00
add MAGIC_ENUM_NO_ASSERT
This commit is contained in:
parent
cf659c59c8
commit
e7749da06b
7 changed files with 59 additions and 61 deletions
|
|
@ -140,14 +140,14 @@ TEST_CASE("enum_cast") {
|
|||
REQUIRE_FALSE(enum_cast<number>("four").has_value());
|
||||
REQUIRE_FALSE(enum_cast<number>("None").has_value());
|
||||
|
||||
REQUIRE(magic_enum::enum_cast<crc_hack>("b5a7b602ab754d7ab30fb42c4fb28d82").has_value());
|
||||
REQUIRE_FALSE(magic_enum::enum_cast<crc_hack>("d19f2e9e82d14b96be4fa12b8a27ee9f").has_value());
|
||||
REQUIRE(enum_cast<crc_hack>("b5a7b602ab754d7ab30fb42c4fb28d82").has_value());
|
||||
REQUIRE_FALSE(enum_cast<crc_hack>("d19f2e9e82d14b96be4fa12b8a27ee9f").has_value());
|
||||
|
||||
constexpr auto crc = magic_enum::enum_cast<crc_hack_2>("b5a7b602ab754d7ab30fb42c4fb28d82");
|
||||
constexpr auto crc = enum_cast<crc_hack_2>("b5a7b602ab754d7ab30fb42c4fb28d82");
|
||||
REQUIRE(crc.value() == crc_hack_2::b5a7b602ab754d7ab30fb42c4fb28d82);
|
||||
REQUIRE(magic_enum::enum_cast<crc_hack_2>("d19f2e9e82d14b96be4fa12b8a27ee9f").value() == crc_hack_2::d19f2e9e82d14b96be4fa12b8a27ee9f);
|
||||
REQUIRE(enum_cast<crc_hack_2>("d19f2e9e82d14b96be4fa12b8a27ee9f").value() == crc_hack_2::d19f2e9e82d14b96be4fa12b8a27ee9f);
|
||||
|
||||
REQUIRE(magic_enum::enum_cast<BoolTest>("Nay").has_value());
|
||||
REQUIRE(enum_cast<BoolTest>("Nay").has_value());
|
||||
}
|
||||
|
||||
SECTION("integer") {
|
||||
|
|
@ -408,7 +408,7 @@ TEST_CASE("enum_value") {
|
|||
}
|
||||
|
||||
TEST_CASE("enum_values") {
|
||||
REQUIRE(std::is_same_v<decltype(magic_enum::enum_values<Color>()), const std::array<Color, 3>&>);
|
||||
REQUIRE(std::is_same_v<decltype(enum_values<Color>()), const std::array<Color, 3>&>);
|
||||
|
||||
constexpr auto& s1 = enum_values<Color&>();
|
||||
REQUIRE(s1 == std::array<Color, 3>{{Color::RED, Color::GREEN, Color::BLUE}});
|
||||
|
|
@ -648,7 +648,7 @@ TEST_CASE("enum_name") {
|
|||
}
|
||||
|
||||
TEST_CASE("enum_names") {
|
||||
REQUIRE(std::is_same_v<decltype(magic_enum::enum_names<Color>()), const std::array<std::string_view, 3>&>);
|
||||
REQUIRE(std::is_same_v<decltype(enum_names<Color>()), const std::array<std::string_view, 3>&>);
|
||||
|
||||
constexpr auto& s1 = enum_names<Color&>();
|
||||
REQUIRE(s1 == std::array<std::string_view, 3>{{"red", "GREEN", "BLUE"}});
|
||||
|
|
@ -664,7 +664,7 @@ TEST_CASE("enum_names") {
|
|||
}
|
||||
|
||||
TEST_CASE("enum_entries") {
|
||||
REQUIRE(std::is_same_v<decltype(magic_enum::enum_entries<Color>()), const std::array<std::pair<Color, std::string_view>, 3>&>);
|
||||
REQUIRE(std::is_same_v<decltype(enum_entries<Color>()), const std::array<std::pair<Color, std::string_view>, 3>&>);
|
||||
|
||||
constexpr auto& s1 = enum_entries<Color&>();
|
||||
REQUIRE(s1 == std::array<std::pair<Color, std::string_view>, 3>{{{Color::RED, "red"}, {Color::GREEN, "GREEN"}, {Color::BLUE, "BLUE"}}});
|
||||
|
|
@ -879,7 +879,7 @@ TEST_CASE("extrema") {
|
|||
};
|
||||
|
||||
REQUIRE(magic_enum::enum_name<BadColor>(BadColor::NONE).empty());
|
||||
REQUIRE_FALSE(magic_enum::enum_cast<BadColor>(std::numeric_limits<std::uint64_t>::max()).has_value());
|
||||
REQUIRE_FALSE(enum_cast<BadColor>(std::numeric_limits<std::uint64_t>::max()).has_value());
|
||||
REQUIRE_FALSE(magic_enum::enum_contains<BadColor>(std::numeric_limits<std::uint64_t>::max()));
|
||||
REQUIRE_FALSE(magic_enum::enum_contains<BadColor>(BadColor::NONE));
|
||||
|
||||
|
|
@ -1090,10 +1090,10 @@ TEST_CASE("constexpr_for") {
|
|||
#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():
|
||||
switch (enum_fuse(color, direction).value()) {
|
||||
case enum_fuse(Color::RED, Directions::Up).value():
|
||||
return 1;
|
||||
case magic_enum::enum_fuse(Color::BLUE, Directions::Down).value():
|
||||
case enum_fuse(Color::BLUE, Directions::Down).value():
|
||||
return 2;
|
||||
default:
|
||||
return 0;
|
||||
|
|
@ -1103,10 +1103,10 @@ static int switch_case_2d(Color color, Directions direction) {
|
|||
enum class Index { zero = 0, one = 1, two = 2 };
|
||||
|
||||
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():
|
||||
switch (enum_fuse(color, direction, index).value()) {
|
||||
case enum_fuse(Color::RED, Directions::Up, Index::zero).value():
|
||||
return 1;
|
||||
case magic_enum::enum_fuse(Color::BLUE, Directions::Up, Index::zero).value():
|
||||
case enum_fuse(Color::BLUE, Directions::Up, Index::zero).value():
|
||||
return 2;
|
||||
default:
|
||||
return 0;
|
||||
|
|
|
|||
|
|
@ -295,14 +295,6 @@ TEST_CASE("containers_set") {
|
|||
REQUIRE_FALSE(magic_enum::enum_count<Color>() == color_set_not_const.size());
|
||||
}
|
||||
|
||||
TEST_CASE("containers_flat_set") {
|
||||
|
||||
// constexpr magic_enum::containers::flat_set color_flat_set_filled = {Color::RED, Color::GREEN, Color::BLUE};
|
||||
// REQUIRE_FALSE(color_flat_set_filled.empty());
|
||||
// REQUIRE(color_flat_set_filled.size() == 3);
|
||||
// REQUIRE(magic_enum::enum_count<Color>() == color_flat_set_filled.size());
|
||||
}
|
||||
|
||||
TEST_CASE("map_like_container") {
|
||||
|
||||
using namespace magic_enum::ostream_operators;
|
||||
|
|
|
|||
|
|
@ -390,7 +390,7 @@ TEST_CASE("enum_value") {
|
|||
}
|
||||
|
||||
TEST_CASE("enum_values") {
|
||||
REQUIRE(std::is_same_v<decltype(magic_enum::enum_values<Color>()), const std::array<Color, 3>&>);
|
||||
REQUIRE(std::is_same_v<decltype(enum_values<Color>()), const std::array<Color, 3>&>);
|
||||
|
||||
constexpr auto& s1 = enum_values<Color&>();
|
||||
REQUIRE(s1 == std::array<Color, 3>{{Color::RED, Color::GREEN, Color::BLUE}});
|
||||
|
|
@ -506,7 +506,7 @@ TEST_CASE("enum_flags_name") {
|
|||
}
|
||||
|
||||
TEST_CASE("enum_names") {
|
||||
REQUIRE(std::is_same_v<decltype(magic_enum::enum_names<Color>()), const std::array<std::string_view, 3>&>);
|
||||
REQUIRE(std::is_same_v<decltype(enum_names<Color>()), const std::array<std::string_view, 3>&>);
|
||||
|
||||
constexpr auto& s1 = enum_names<Color&>();
|
||||
REQUIRE(s1 == std::array<std::string_view, 3>{{"RED", "GREEN", "BLUE"}});
|
||||
|
|
@ -522,7 +522,7 @@ TEST_CASE("enum_names") {
|
|||
}
|
||||
|
||||
TEST_CASE("enum_entries") {
|
||||
REQUIRE(std::is_same_v<decltype(magic_enum::enum_entries<Color>()), const std::array<std::pair<Color, std::string_view>, 3>&>);
|
||||
REQUIRE(std::is_same_v<decltype(enum_entries<Color>()), const std::array<std::pair<Color, std::string_view>, 3>&>);
|
||||
|
||||
constexpr auto& s1 = enum_entries<Color&>();
|
||||
REQUIRE(s1 == std::array<std::pair<Color, std::string_view>, 3>{{{Color::RED, "RED"}, {Color::GREEN, "GREEN"}, {Color::BLUE, "BLUE"}}});
|
||||
|
|
|
|||
|
|
@ -68,7 +68,7 @@ TEST_CASE("enum_cast") {
|
|||
}
|
||||
|
||||
TEST_CASE("enum_values") {
|
||||
REQUIRE(std::is_same_v<decltype(magic_enum::enum_values<Color>()), const std::array<Color, 3>&>);
|
||||
REQUIRE(std::is_same_v<decltype(enum_values<Color>()), const std::array<Color, 3>&>);
|
||||
|
||||
constexpr auto& s1 = enum_values<Color&>();
|
||||
REQUIRE(s1 == std::array<Color, 3>{{Color::RED, Color::GREEN, Color::BLUE}});
|
||||
|
|
@ -103,14 +103,14 @@ TEST_CASE("enum_name") {
|
|||
}
|
||||
|
||||
TEST_CASE("enum_names") {
|
||||
REQUIRE(std::is_same_v<decltype(magic_enum::enum_names<Color>()), const std::array<std::wstring_view, 3>&>);
|
||||
REQUIRE(std::is_same_v<decltype(enum_names<Color>()), const std::array<std::wstring_view, 3>&>);
|
||||
|
||||
constexpr auto& s1 = enum_names<Color&>();
|
||||
REQUIRE(s1 == std::array<std::wstring_view, 3>{{L"red", L"GREEN", L"BLUE"}});
|
||||
}
|
||||
|
||||
TEST_CASE("enum_entries") {
|
||||
REQUIRE(std::is_same_v<decltype(magic_enum::enum_entries<Color>()), const std::array<std::pair<Color, std::wstring_view>, 3>&>);
|
||||
REQUIRE(std::is_same_v<decltype(enum_entries<Color>()), const std::array<std::pair<Color, std::wstring_view>, 3>&>);
|
||||
|
||||
constexpr auto& s1 = enum_entries<Color&>();
|
||||
REQUIRE(s1 == std::array<std::pair<Color, std::wstring_view>, 3>{{{Color::RED, L"red"}, {Color::GREEN, L"GREEN"}, {Color::BLUE, L"BLUE"}}});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue