add to_string_or_throw and to_index_or_throw traits functions

This commit is contained in:
2019-11-22 05:08:42 +07:00
parent 080acf3611
commit c0497c2e5d
2 changed files with 49 additions and 0 deletions

View File

@@ -138,8 +138,13 @@ TEST_CASE("enum") {
STATIC_REQUIRE(sn::color_traits::to_string_or_empty(sn::color::green) == "green");
STATIC_REQUIRE(sn::color_traits::to_string_or_empty(sn::color::blue) == "blue");
REQUIRE(sn::color_traits::to_string_or_throw(sn::color::red) == "red");
REQUIRE(sn::color_traits::to_string_or_throw(sn::color::green) == "green");
REQUIRE(sn::color_traits::to_string_or_throw(sn::color::blue) == "blue");
STATIC_REQUIRE_FALSE(sn::color_traits::to_string(sn::color(42)));
STATIC_REQUIRE(sn::color_traits::to_string_or_empty(sn::color(42)) == "");
REQUIRE_THROWS_AS(sn::color_traits::to_string_or_throw(sn::color(42)), enum_hpp::exception);
}
{
STATIC_REQUIRE(sn::render::mask_traits::to_string(sn::render::mask::none) == "none");
@@ -151,6 +156,11 @@ TEST_CASE("enum") {
STATIC_REQUIRE(sn::render::mask_traits::to_string_or_empty(sn::render::mask::color) == "color");
STATIC_REQUIRE(sn::render::mask_traits::to_string_or_empty(sn::render::mask::alpha) == "alpha");
STATIC_REQUIRE(sn::render::mask_traits::to_string_or_empty(sn::render::mask::all) == "all");
REQUIRE(sn::render::mask_traits::to_string_or_throw(sn::render::mask::none) == "none");
REQUIRE(sn::render::mask_traits::to_string_or_throw(sn::render::mask::color) == "color");
REQUIRE(sn::render::mask_traits::to_string_or_throw(sn::render::mask::alpha) == "alpha");
REQUIRE(sn::render::mask_traits::to_string_or_throw(sn::render::mask::all) == "all");
}
{
STATIC_REQUIRE(sn::numbers_traits::to_string(sn::_0) == "_0");
@@ -161,8 +171,13 @@ TEST_CASE("enum") {
STATIC_REQUIRE(sn::numbers_traits::to_string_or_empty(sn::_180) == "_180");
STATIC_REQUIRE(sn::numbers_traits::to_string_or_empty(sn::_240) == "_240");
REQUIRE(sn::numbers_traits::to_string_or_throw(sn::_0) == "_0");
REQUIRE(sn::numbers_traits::to_string_or_throw(sn::_180) == "_180");
REQUIRE(sn::numbers_traits::to_string_or_throw(sn::_240) == "_240");
STATIC_REQUIRE_FALSE(sn::numbers_traits::to_string(sn::numbers(100500)));
STATIC_REQUIRE(sn::numbers_traits::to_string_or_empty(sn::numbers(100500)) == "");
REQUIRE_THROWS_AS(sn::numbers_traits::to_string_or_throw(sn::numbers(100500)), enum_hpp::exception);
}
}
@@ -197,8 +212,13 @@ TEST_CASE("enum") {
STATIC_REQUIRE(sn::color_traits::to_index_or_invalid(sn::color::green) == 1u);
STATIC_REQUIRE(sn::color_traits::to_index_or_invalid(sn::color::blue) == 2u);
REQUIRE(sn::color_traits::to_index_or_throw(sn::color::red) == 0u);
REQUIRE(sn::color_traits::to_index_or_throw(sn::color::green) == 1u);
REQUIRE(sn::color_traits::to_index_or_throw(sn::color::blue) == 2u);
STATIC_REQUIRE_FALSE(sn::color_traits::to_index(sn::color(42)));
STATIC_REQUIRE(sn::color_traits::to_index_or_invalid(sn::color(42)) == enum_hpp::invalid_index);
REQUIRE_THROWS_AS(sn::color_traits::to_index_or_throw(sn::color(42)), enum_hpp::exception);
}
{
STATIC_REQUIRE(sn::render::mask_traits::to_index(sn::render::mask::none) == 0u);
@@ -210,6 +230,11 @@ TEST_CASE("enum") {
STATIC_REQUIRE(sn::render::mask_traits::to_index_or_invalid(sn::render::mask::color) == 1u);
STATIC_REQUIRE(sn::render::mask_traits::to_index_or_invalid(sn::render::mask::alpha) == 2u);
STATIC_REQUIRE(sn::render::mask_traits::to_index_or_invalid(sn::render::mask::all) == 3u);
REQUIRE(sn::render::mask_traits::to_index_or_throw(sn::render::mask::none) == 0u);
REQUIRE(sn::render::mask_traits::to_index_or_throw(sn::render::mask::color) == 1u);
REQUIRE(sn::render::mask_traits::to_index_or_throw(sn::render::mask::alpha) == 2u);
REQUIRE(sn::render::mask_traits::to_index_or_throw(sn::render::mask::all) == 3u);
}
{
STATIC_REQUIRE(sn::numbers_traits::to_index(sn::_0) == 0u);
@@ -220,8 +245,13 @@ TEST_CASE("enum") {
STATIC_REQUIRE(sn::numbers_traits::to_index_or_invalid(sn::_180) == 180u);
STATIC_REQUIRE(sn::numbers_traits::to_index_or_invalid(sn::_240) == 240u);
REQUIRE(sn::numbers_traits::to_index_or_throw(sn::_0) == 0u);
REQUIRE(sn::numbers_traits::to_index_or_throw(sn::_180) == 180u);
REQUIRE(sn::numbers_traits::to_index_or_throw(sn::_240) == 240u);
STATIC_REQUIRE_FALSE(sn::numbers_traits::to_index(sn::numbers(100500)));
STATIC_REQUIRE(sn::numbers_traits::to_index_or_invalid(sn::numbers(100500)) == enum_hpp::invalid_index);
REQUIRE_THROWS_AS(sn::numbers_traits::to_index_or_throw(sn::numbers(100500)), enum_hpp::exception);
}
}