1
0
Fork 0
mirror of https://github.com/Neargye/magic_enum.git synced 2026-01-10 23:44:29 +00:00

add namespace magic_enum::istream_operators

This commit is contained in:
neargye 2022-04-07 19:18:44 +04:00
parent 25d7f64dfb
commit b6bf0aa2a8
3 changed files with 93 additions and 3 deletions

View file

@ -598,7 +598,7 @@ TEST_CASE("enum_entries") {
}
TEST_CASE("ostream_operators") {
auto test_ostream = [](auto e, std::string_view name) {
auto test_ostream = [](auto e, std::string name) {
using namespace magic_enum::ostream_operators;
std::stringstream ss;
ss << e;
@ -646,6 +646,42 @@ TEST_CASE("ostream_operators") {
test_ostream(std::make_optional(static_cast<number>(0)), "0");
}
TEST_CASE("istream_operators") {
auto test_istream = [](const auto e, std::string name) {
using namespace magic_enum::istream_operators;
std::istringstream ss(name);
std::decay_t<decltype(e)> v;
ss >> v;
REQUIRE(v == e);
REQUIRE(ss);
};
test_istream(Color::GREEN, "GREEN");
test_istream(Color::BLUE, "BLUE");
test_istream(Color::BLUE | Color::RED, "RED|BLUE");
test_istream(Color::BLUE | Color::RED | Color::RED, "RED|BLUE");
test_istream(Numbers::two, "two");
test_istream(Numbers::three, "three");
test_istream(Numbers::many, "many");
test_istream(Directions::Down, "Down");
test_istream(Directions::Right, "Right");
test_istream(Directions::Left, "Left");
test_istream(Directions::Right | Directions::Left, "Left|Right");
#if defined(MAGIC_ENUM_ENABLE_NONASCII)
test_istream(Language::, "한국어");
test_istream(Language::English, "English");
test_istream(Language::😃, "😃");
#endif
test_istream(number::two, "two");
test_istream(number::three, "three");
test_istream(number::four, "four");
test_istream(number::four | number::one, "one|four");
}
TEST_CASE("bitwise_operators") {
SECTION("operator^") {
REQUIRE(enum_integer(~Color::RED) == ~enum_integer(Color::RED));