mirror of
https://github.com/BlackMATov/enum.hpp.git
synced 2025-12-13 06:59:45 +07:00
optional using instead throw and nothrow functions
This commit is contained in:
@@ -133,7 +133,7 @@ TEST_CASE("enum") {
|
||||
STATIC_REQUIRE(sn::color_traits::to_string(sn::color::red) == "red");
|
||||
STATIC_REQUIRE(sn::color_traits::to_string(sn::color::green) == "green");
|
||||
STATIC_REQUIRE(sn::color_traits::to_string(sn::color::blue) == "blue");
|
||||
STATIC_REQUIRE(sn::color_traits::to_string(sn::color(42)) == "");
|
||||
STATIC_REQUIRE_FALSE(sn::color_traits::to_string(sn::color(42)));
|
||||
}
|
||||
{
|
||||
STATIC_REQUIRE(sn::render::mask_traits::to_string(sn::render::mask::none) == "none");
|
||||
@@ -145,62 +145,28 @@ TEST_CASE("enum") {
|
||||
STATIC_REQUIRE(sn::numbers_traits::to_string(sn::_0) == "_0");
|
||||
STATIC_REQUIRE(sn::numbers_traits::to_string(sn::_180) == "_180");
|
||||
STATIC_REQUIRE(sn::numbers_traits::to_string(sn::_240) == "_240");
|
||||
STATIC_REQUIRE(sn::numbers_traits::to_string(sn::numbers(100500)) == "");
|
||||
STATIC_REQUIRE_FALSE(sn::numbers_traits::to_string(sn::numbers(100500)));
|
||||
}
|
||||
}
|
||||
|
||||
SECTION("from_string") {
|
||||
{
|
||||
REQUIRE(sn::color_traits::from_string("red") == sn::color::red);
|
||||
REQUIRE(sn::color_traits::from_string("green") == sn::color::green);
|
||||
REQUIRE(sn::color_traits::from_string("blue") == sn::color::blue);
|
||||
REQUIRE_THROWS_AS(sn::color_traits::from_string("42"), enum_hpp::exception);
|
||||
STATIC_REQUIRE(sn::color_traits::from_string("red") == sn::color::red);
|
||||
STATIC_REQUIRE(sn::color_traits::from_string("green") == sn::color::green);
|
||||
STATIC_REQUIRE(sn::color_traits::from_string("blue") == sn::color::blue);
|
||||
STATIC_REQUIRE_FALSE(sn::color_traits::from_string("42"));
|
||||
}
|
||||
{
|
||||
REQUIRE(sn::render::mask_traits::from_string("none") == sn::render::mask::none);
|
||||
REQUIRE(sn::render::mask_traits::from_string("color") == sn::render::mask::color);
|
||||
REQUIRE(sn::render::mask_traits::from_string("alpha") == sn::render::mask::alpha);
|
||||
REQUIRE(sn::render::mask_traits::from_string("all") == sn::render::mask::all);
|
||||
REQUIRE_THROWS_AS(sn::render::mask_traits::from_string("42"), enum_hpp::exception);
|
||||
STATIC_REQUIRE(sn::render::mask_traits::from_string("none") == sn::render::mask::none);
|
||||
STATIC_REQUIRE(sn::render::mask_traits::from_string("color") == sn::render::mask::color);
|
||||
STATIC_REQUIRE(sn::render::mask_traits::from_string("alpha") == sn::render::mask::alpha);
|
||||
STATIC_REQUIRE(sn::render::mask_traits::from_string("all") == sn::render::mask::all);
|
||||
STATIC_REQUIRE_FALSE(sn::render::mask_traits::from_string("42"));
|
||||
}
|
||||
{
|
||||
REQUIRE(sn::numbers_traits::from_string("_10") == sn::_10);
|
||||
REQUIRE(sn::numbers_traits::from_string("_240") == sn::_240);
|
||||
REQUIRE_THROWS_AS(sn::numbers_traits::from_string("error"), enum_hpp::exception);
|
||||
}
|
||||
}
|
||||
|
||||
SECTION("from_string_nothrow") {
|
||||
{
|
||||
sn::color result{42};
|
||||
REQUIRE(sn::color_traits::from_string_nothrow("red", result));
|
||||
REQUIRE(result == sn::color::red);
|
||||
REQUIRE(sn::color_traits::from_string_nothrow("green", result));
|
||||
REQUIRE(result == sn::color::green);
|
||||
REQUIRE(sn::color_traits::from_string_nothrow("blue", result));
|
||||
REQUIRE(result == sn::color::blue);
|
||||
REQUIRE_FALSE(sn::color_traits::from_string_nothrow("42", result));
|
||||
REQUIRE(result == sn::color::blue);
|
||||
}
|
||||
{
|
||||
sn::render::mask result{42};
|
||||
REQUIRE(sn::render::mask_traits::from_string_nothrow("none", result));
|
||||
REQUIRE(result == sn::render::mask::none);
|
||||
REQUIRE(sn::render::mask_traits::from_string_nothrow("color", result));
|
||||
REQUIRE(result == sn::render::mask::color);
|
||||
REQUIRE(sn::render::mask_traits::from_string_nothrow("alpha", result));
|
||||
REQUIRE(result == sn::render::mask::alpha);
|
||||
REQUIRE(sn::render::mask_traits::from_string_nothrow("all", result));
|
||||
REQUIRE(result == sn::render::mask::all);
|
||||
REQUIRE_FALSE(sn::render::mask_traits::from_string_nothrow("42", result));
|
||||
REQUIRE(result == sn::render::mask::all);
|
||||
}
|
||||
{
|
||||
sn::numbers result{100500};
|
||||
REQUIRE(sn::numbers_traits::from_string_nothrow("_240", result));
|
||||
REQUIRE(result == sn::_240);
|
||||
REQUIRE_FALSE(sn::numbers_traits::from_string_nothrow("error", result));
|
||||
REQUIRE(result == sn::_240);
|
||||
STATIC_REQUIRE(sn::numbers_traits::from_string("_10") == sn::_10);
|
||||
STATIC_REQUIRE(sn::numbers_traits::from_string("_240") == sn::_240);
|
||||
STATIC_REQUIRE_FALSE(sn::numbers_traits::from_string("error"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -209,7 +175,7 @@ TEST_CASE("enum") {
|
||||
STATIC_REQUIRE(sn::color_traits::to_index(sn::color::red) == 0);
|
||||
STATIC_REQUIRE(sn::color_traits::to_index(sn::color::green) == 1);
|
||||
STATIC_REQUIRE(sn::color_traits::to_index(sn::color::blue) == 2);
|
||||
STATIC_REQUIRE(sn::color_traits::to_index(sn::color(42)) == enum_hpp::invalid_index);
|
||||
STATIC_REQUIRE_FALSE(sn::color_traits::to_index(sn::color(42)));
|
||||
}
|
||||
{
|
||||
STATIC_REQUIRE(sn::render::mask_traits::to_index(sn::render::mask::none) == 0);
|
||||
@@ -221,62 +187,28 @@ TEST_CASE("enum") {
|
||||
STATIC_REQUIRE(sn::numbers_traits::to_index(sn::_0) == 0);
|
||||
STATIC_REQUIRE(sn::numbers_traits::to_index(sn::_180) == 180);
|
||||
STATIC_REQUIRE(sn::numbers_traits::to_index(sn::_240) == 240);
|
||||
STATIC_REQUIRE(sn::numbers_traits::to_index(sn::numbers(100500)) == enum_hpp::invalid_index);
|
||||
STATIC_REQUIRE_FALSE(sn::numbers_traits::to_index(sn::numbers(100500)));
|
||||
}
|
||||
}
|
||||
|
||||
SECTION("from_index") {
|
||||
{
|
||||
REQUIRE(sn::color_traits::from_index(0) == sn::color::red);
|
||||
REQUIRE(sn::color_traits::from_index(1) == sn::color::green);
|
||||
REQUIRE(sn::color_traits::from_index(2) == sn::color::blue);
|
||||
REQUIRE_THROWS_AS(sn::color_traits::from_index(42), enum_hpp::exception);
|
||||
STATIC_REQUIRE(sn::color_traits::from_index(0) == sn::color::red);
|
||||
STATIC_REQUIRE(sn::color_traits::from_index(1) == sn::color::green);
|
||||
STATIC_REQUIRE(sn::color_traits::from_index(2) == sn::color::blue);
|
||||
STATIC_REQUIRE_FALSE(sn::color_traits::from_index(42));
|
||||
}
|
||||
{
|
||||
REQUIRE(sn::render::mask_traits::from_index(0) == sn::render::mask::none);
|
||||
REQUIRE(sn::render::mask_traits::from_index(1) == sn::render::mask::color);
|
||||
REQUIRE(sn::render::mask_traits::from_index(2) == sn::render::mask::alpha);
|
||||
REQUIRE(sn::render::mask_traits::from_index(3) == sn::render::mask::all);
|
||||
REQUIRE_THROWS_AS(sn::render::mask_traits::from_index(42), enum_hpp::exception);
|
||||
STATIC_REQUIRE(sn::render::mask_traits::from_index(0) == sn::render::mask::none);
|
||||
STATIC_REQUIRE(sn::render::mask_traits::from_index(1) == sn::render::mask::color);
|
||||
STATIC_REQUIRE(sn::render::mask_traits::from_index(2) == sn::render::mask::alpha);
|
||||
STATIC_REQUIRE(sn::render::mask_traits::from_index(3) == sn::render::mask::all);
|
||||
STATIC_REQUIRE_FALSE(sn::render::mask_traits::from_index(42));
|
||||
}
|
||||
{
|
||||
REQUIRE(sn::numbers_traits::from_index(10) == sn::_10);
|
||||
REQUIRE(sn::numbers_traits::from_index(240) == sn::_240);
|
||||
REQUIRE_THROWS_AS(sn::numbers_traits::from_index(100500), enum_hpp::exception);
|
||||
}
|
||||
}
|
||||
|
||||
SECTION("from_index_nothrow") {
|
||||
{
|
||||
sn::color result{42};
|
||||
REQUIRE(sn::color_traits::from_index_nothrow(0, result));
|
||||
REQUIRE(result == sn::color::red);
|
||||
REQUIRE(sn::color_traits::from_index_nothrow(1, result));
|
||||
REQUIRE(result == sn::color::green);
|
||||
REQUIRE(sn::color_traits::from_index_nothrow(2, result));
|
||||
REQUIRE(result == sn::color::blue);
|
||||
REQUIRE_FALSE(sn::color_traits::from_index_nothrow(42, result));
|
||||
REQUIRE(result == sn::color::blue);
|
||||
}
|
||||
{
|
||||
sn::render::mask result{42};
|
||||
REQUIRE(sn::render::mask_traits::from_index_nothrow(0, result));
|
||||
REQUIRE(result == sn::render::mask::none);
|
||||
REQUIRE(sn::render::mask_traits::from_index_nothrow(1, result));
|
||||
REQUIRE(result == sn::render::mask::color);
|
||||
REQUIRE(sn::render::mask_traits::from_index_nothrow(2, result));
|
||||
REQUIRE(result == sn::render::mask::alpha);
|
||||
REQUIRE(sn::render::mask_traits::from_index_nothrow(3, result));
|
||||
REQUIRE(result == sn::render::mask::all);
|
||||
REQUIRE_FALSE(sn::render::mask_traits::from_index_nothrow(42, result));
|
||||
REQUIRE(result == sn::render::mask::all);
|
||||
}
|
||||
{
|
||||
sn::numbers result{100500};
|
||||
REQUIRE(sn::numbers_traits::from_index_nothrow(240, result));
|
||||
REQUIRE(result == sn::_240);
|
||||
REQUIRE_FALSE(sn::numbers_traits::from_index_nothrow(100500, result));
|
||||
REQUIRE(result == sn::_240);
|
||||
STATIC_REQUIRE(sn::numbers_traits::from_index(10) == sn::_10);
|
||||
STATIC_REQUIRE(sn::numbers_traits::from_index(240) == sn::_240);
|
||||
STATIC_REQUIRE_FALSE(sn::numbers_traits::from_index(100500));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user