1
0
Fork 0
mirror of https://github.com/Neargye/magic_enum.git synced 2026-01-10 23:44:29 +00:00
This commit is contained in:
neargye 2020-08-16 17:43:22 +05:00
parent 521b753a86
commit 02f2249239
4 changed files with 34 additions and 33 deletions

View file

@ -23,8 +23,6 @@
#define CATCH_CONFIG_MAIN
#include <catch.hpp>
#define MAGIC_ENUM_RANGE_MIN -120
#define MAGIC_ENUM_RANGE_MAX 120
#include <magic_enum.hpp>
#include <array>
@ -487,16 +485,16 @@ TEST_CASE("enum_value") {
TEST_CASE("enum_values") {
REQUIRE(std::is_same_v<decltype(magic_enum::enum_values<Color>()), const std::array<Color, 3>&>);
constexpr auto s1 = enum_values<Color&>();
constexpr auto& s1 = enum_values<Color&>();
REQUIRE(s1 == std::array<Color, 3>{{Color::RED, Color::GREEN, Color::BLUE}});
auto s2 = enum_values<Numbers>();
constexpr auto& s2 = enum_values<Numbers>();
REQUIRE(s2 == std::array<Numbers, 4>{{Numbers::one, Numbers::two, Numbers::three, Numbers::many}});
constexpr auto s3 = enum_values<const Directions>();
constexpr auto& s3 = enum_values<const Directions>();
REQUIRE(s3 == std::array<Directions, 4>{{Directions::Left, Directions::Down, Directions::Up, Directions::Right}});
auto s4 = enum_values<number>();
constexpr auto& s4 = enum_values<number>();
REQUIRE(s4 == std::array<number, 4>{{number::one, number::two, number::three, number::four}});
}
@ -504,13 +502,13 @@ TEST_CASE("enum_count") {
constexpr auto s1 = enum_count<Color&>();
REQUIRE(s1 == 3);
auto s2 = enum_count<Numbers>();
constexpr auto s2 = enum_count<Numbers>();
REQUIRE(s2 == 4);
constexpr auto s3 = enum_count<const Directions>();
REQUIRE(s3 == 4);
auto s4 = enum_count<number>();
constexpr auto s4 = enum_count<number>();
REQUIRE(s4 == 4);
}
@ -561,32 +559,32 @@ 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>&>);
constexpr auto s1 = enum_names<Color&>();
constexpr auto& s1 = enum_names<Color&>();
REQUIRE(s1 == std::array<std::string_view, 3>{{"RED", "GREEN", "BLUE"}});
auto s2 = enum_names<Numbers>();
constexpr auto& s2 = enum_names<Numbers>();
REQUIRE(s2 == std::array<std::string_view, 4>{{"one", "two", "three", "many"}});
constexpr auto s3 = enum_names<const Directions>();
constexpr auto& s3 = enum_names<const Directions>();
REQUIRE(s3 == std::array<std::string_view, 4>{{"Left", "Down", "Up", "Right"}});
auto s4 = enum_names<number>();
constexpr auto& s4 = enum_names<number>();
REQUIRE(s4 == std::array<std::string_view, 4>{{"one", "two", "three", "four"}});
}
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>&>);
constexpr auto s1 = enum_entries<Color&>();
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"}}});
auto s2 = enum_entries<Numbers>();
constexpr auto& s2 = enum_entries<Numbers>();
REQUIRE(s2 == std::array<std::pair<Numbers, std::string_view>, 4>{{{Numbers::one, "one"}, {Numbers::two, "two"}, {Numbers::three, "three"}, {Numbers::many, "many"}}});
constexpr auto s3 = enum_entries<Directions&>();
constexpr auto& s3 = enum_entries<Directions&>();
REQUIRE(s3 == std::array<std::pair<Directions, std::string_view>, 4>{{{Directions::Left, "Left"}, {Directions::Down, "Down"}, {Directions::Up, "Up"}, {Directions::Right, "Right"}}});
auto s4 = enum_entries<number>();
constexpr auto& s4 = enum_entries<number>();
REQUIRE(s4 == std::array<std::pair<number, std::string_view>, 4>{{{number::one, "one"}, {number::two, "two"}, {number::three, "three"}, {number::four, "four"}}});
}