reference impl with boost

This commit is contained in:
2019-11-21 03:49:32 +07:00
parent 2b18d09dc8
commit 0be74b835a
3 changed files with 94 additions and 148 deletions

View File

@@ -41,41 +41,6 @@ namespace some_namespace
};
}
TEST_CASE("enum_pp") {
SECTION("seq_head") {
REQUIRE("head"sv == ENUM_HPP_PP_SEQ_HEAD(("head")));
REQUIRE("head"sv == ENUM_HPP_PP_SEQ_HEAD(("head")("tail")));
REQUIRE("head"sv == ENUM_HPP_PP_SEQ_HEAD(("head")("tail1")("tail2")));
}
SECTION("seq_tail") {
const auto tail0 = [](){ return true; };
REQUIRE(tail0 ENUM_HPP_PP_SEQ_TAIL(("head")));
const auto tail1 = [](auto t){
REQUIRE("tail"sv == t);
return true;
};
REQUIRE(tail1 ENUM_HPP_PP_SEQ_TAIL(("head")("tail")));
const auto tail2 = [](auto t1){
REQUIRE("tail1"sv == t1);
return [](auto t2){
REQUIRE("tail2"sv == t2);
return true;
};
};
REQUIRE(tail2 ENUM_HPP_PP_SEQ_TAIL(("head")("tail1")("tail2")));
}
SECTION("seq_size") {
STATIC_REQUIRE(ENUM_HPP_PP_SEQ_SIZE() == 0);
STATIC_REQUIRE(ENUM_HPP_PP_SEQ_SIZE((a)) == 1);
STATIC_REQUIRE(ENUM_HPP_PP_SEQ_SIZE((a)(b)) == 2);
STATIC_REQUIRE(ENUM_HPP_PP_SEQ_SIZE((a)(b)(c)) == 3);
}
}
TEST_CASE("enum") {
namespace sn = some_namespace;
@@ -85,90 +50,90 @@ TEST_CASE("enum") {
std::underlying_type_t<sn::color>,
unsigned>);
// REQUIRE(enum_to_underlying(sn::color::red) == 2);
// REQUIRE(enum_to_underlying(sn::color::green) == 3);
// REQUIRE(enum_to_underlying(sn::color::blue) == 6);
REQUIRE(enum_to_underlying(sn::color::red) == 2);
REQUIRE(enum_to_underlying(sn::color::green) == 3);
REQUIRE(enum_to_underlying(sn::color::blue) == 6);
}
{
STATIC_REQUIRE(std::is_same_v<
std::underlying_type_t<sn::render::mask>,
unsigned char>);
// REQUIRE(enum_to_underlying(sn::render::mask::none) == 0);
// REQUIRE(enum_to_underlying(sn::render::mask::color) == 1);
// REQUIRE(enum_to_underlying(sn::render::mask::alpha) == 2);
// REQUIRE(enum_to_underlying(sn::render::mask::all) == 3);
REQUIRE(enum_to_underlying(sn::render::mask::none) == 0);
REQUIRE(enum_to_underlying(sn::render::mask::color) == 1);
REQUIRE(enum_to_underlying(sn::render::mask::alpha) == 2);
REQUIRE(enum_to_underlying(sn::render::mask::all) == 3);
}
}
SECTION("size") {
{
REQUIRE(sn::color_traits::size == 3);
// REQUIRE(sn::color_traits::size == std::size(sn::color_traits::names));
// REQUIRE(sn::color_traits::size == std::size(sn::color_traits::values));
REQUIRE(sn::color_traits::size == std::size(sn::color_traits::names));
REQUIRE(sn::color_traits::size == std::size(sn::color_traits::values));
}
{
REQUIRE(sn::render::mask_traits::size == 4);
// REQUIRE(sn::render::mask_traits::size == std::size(sn::render::mask_traits::names));
// REQUIRE(sn::render::mask_traits::size == std::size(sn::render::mask_traits::values));
REQUIRE(sn::render::mask_traits::size == std::size(sn::render::mask_traits::names));
REQUIRE(sn::render::mask_traits::size == std::size(sn::render::mask_traits::values));
}
}
SECTION("to_string") {
{
// 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(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(sn::render::mask_traits_traits::to_string(sn::render::mask::none) == "none");
// STATIC_REQUIRE(sn::render::mask_traits_traits::to_string(sn::render::mask::color) == "color");
// STATIC_REQUIRE(sn::render::mask_traits_traits::to_string(sn::render::mask::alpha) == "alpha");
// STATIC_REQUIRE(sn::render::mask_traits_traits::to_string(sn::render::mask::all) == "all");
STATIC_REQUIRE(sn::render::mask_traits::to_string(sn::render::mask::none) == "none");
STATIC_REQUIRE(sn::render::mask_traits::to_string(sn::render::mask::color) == "color");
STATIC_REQUIRE(sn::render::mask_traits::to_string(sn::render::mask::alpha) == "alpha");
STATIC_REQUIRE(sn::render::mask_traits::to_string(sn::render::mask::all) == "all");
}
}
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);
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);
}
{
// REQUIRE(sn::render::mask_traits_traits::from_string("none") == sn::render::mask_traits::none);
// REQUIRE(sn::render::mask_traits_traits::from_string("color") == sn::render::mask_traits::color);
// REQUIRE(sn::render::mask_traits_traits::from_string("alpha") == sn::render::mask_traits::alpha);
// REQUIRE(sn::render::mask_traits_traits::from_string("all") == sn::render::mask_traits::all);
// REQUIRE_THROWS_AS(sn::render::mask_traits_traits::from_string("42"), enum_hpp::exception);
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);
}
}
SECTION("from_string_nothrow") {
{
// sn::color result{42};
// STATIC_REQUIRE(sn::color_traits::from_string_nothrow("red", result));
// STATIC_REQUIRE(result == sn::color::red);
// STATIC_REQUIRE(sn::color_traits::from_string_nothrow("green", result));
// STATIC_REQUIRE(result == sn::color::green);
// STATIC_REQUIRE(sn::color_traits::from_string_nothrow("blue", result));
// STATIC_REQUIRE(result == sn::color::blue);
// STATIC_REQUIRE_FALSE(sn::color_traits::from_string_nothrow("42", result));
// STATIC_REQUIRE(result == sn::color::blue);
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};
// STATIC_REQUIRE(sn::render::mask_traits::from_string_nothrow("none", result));
// STATIC_REQUIRE(result == sn::render::mask::none);
// STATIC_REQUIRE(sn::render::mask_traits::from_string_nothrow("color", result));
// STATIC_REQUIRE(result == sn::render::mask::color);
// STATIC_REQUIRE(sn::render::mask_traits::from_string_nothrow("alpha", result));
// STATIC_REQUIRE(result == sn::render::mask::alpha);
// STATIC_REQUIRE(sn::render::mask_traits::from_string_nothrow("all", result));
// STATIC_REQUIRE(result == sn::render::mask::all);
// STATIC_REQUIRE_FALSE(sn::render::mask_traits::from_string_nothrow("42", result));
// STATIC_REQUIRE(result == sn::render::mask::all);
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);
}
}
}