mirror of
https://github.com/BlackMATov/enum.hpp.git
synced 2025-12-13 06:59:45 +07:00
add readme examples
This commit is contained in:
@@ -25,14 +25,14 @@ namespace
|
||||
|
||||
namespace some_namespace
|
||||
{
|
||||
ENUM_HPP_ENUM_CLASS(color, unsigned,
|
||||
ENUM_HPP_CLASS_DECL(color, unsigned,
|
||||
(red = 2)
|
||||
(green)
|
||||
(blue = red + 4)
|
||||
)
|
||||
|
||||
struct render {
|
||||
ENUM_HPP_ENUM_CLASS(mask, unsigned char,
|
||||
ENUM_HPP_CLASS_DECL(mask, unsigned char,
|
||||
(none)
|
||||
(color = 1 << 0)
|
||||
(alpha = 1 << 1)
|
||||
@@ -40,7 +40,7 @@ namespace some_namespace
|
||||
)
|
||||
};
|
||||
|
||||
ENUM_HPP_ENUM_CLASS(numbers, int,
|
||||
ENUM_HPP_DECL(numbers, int,
|
||||
(_0)(_1)(_2)(_3)(_4)(_5)(_6)(_7)(_8)(_9)(_10)(_11)(_12)(_13)(_14)(_15)(_16)(_17)(_18)(_19)(_20)
|
||||
(_21)(_22)(_23)(_24)(_25)(_26)(_27)(_28)(_29)(_30)(_31)(_32)(_33)(_34)(_35)(_36)(_37)(_38)(_39)(_40)
|
||||
(_41)(_42)(_43)(_44)(_45)(_46)(_47)(_48)(_49)(_50)(_51)(_52)(_53)(_54)(_55)(_56)(_57)(_58)(_59)(_60)
|
||||
@@ -83,9 +83,9 @@ TEST_CASE("enum") {
|
||||
std::underlying_type_t<sn::numbers>,
|
||||
int>);
|
||||
|
||||
REQUIRE(enum_to_underlying(sn::numbers::_0) == 0);
|
||||
REQUIRE(enum_to_underlying(sn::numbers::_100) == 100);
|
||||
REQUIRE(enum_to_underlying(sn::numbers::_240) == 240);
|
||||
REQUIRE(enum_to_underlying(sn::_0) == 0);
|
||||
REQUIRE(enum_to_underlying(sn::_100) == 100);
|
||||
REQUIRE(enum_to_underlying(sn::_240) == 240);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -121,9 +121,9 @@ TEST_CASE("enum") {
|
||||
STATIC_REQUIRE(sn::render::mask_traits::to_string(sn::render::mask::all) == "all");
|
||||
}
|
||||
{
|
||||
STATIC_REQUIRE(sn::numbers_traits::to_string(sn::numbers::_0) == "_0");
|
||||
STATIC_REQUIRE(sn::numbers_traits::to_string(sn::numbers::_180) == "_180");
|
||||
STATIC_REQUIRE(sn::numbers_traits::to_string(sn::numbers::_240) == "_240");
|
||||
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)) == "");
|
||||
}
|
||||
}
|
||||
@@ -143,8 +143,8 @@ TEST_CASE("enum") {
|
||||
REQUIRE_THROWS_AS(sn::render::mask_traits::from_string("42"), enum_hpp::exception);
|
||||
}
|
||||
{
|
||||
REQUIRE(sn::numbers_traits::from_string("_10") == sn::numbers::_10);
|
||||
REQUIRE(sn::numbers_traits::from_string("_240") == sn::numbers::_240);
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -177,9 +177,9 @@ TEST_CASE("enum") {
|
||||
{
|
||||
sn::numbers result{100500};
|
||||
REQUIRE(sn::numbers_traits::from_string_nothrow("_240", result));
|
||||
REQUIRE(result == sn::numbers::_240);
|
||||
REQUIRE(result == sn::_240);
|
||||
REQUIRE_FALSE(sn::numbers_traits::from_string_nothrow("error", result));
|
||||
REQUIRE(result == sn::numbers::_240);
|
||||
REQUIRE(result == sn::_240);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user