static_assert( __cplusplus > 2020'99 ); #include "../Enum.h" #include #include #include #include namespace { template< typename T > concept CanNegate= requires( const T &t ) { { not t }; }; } static auto init= Alepha::Utility::enroll <=[] { using namespace Alepha::literals::enum_literals; using namespace Alepha::Testing::literals; using namespace Alepha::Testing::exports; using MyEnum= Alepha::Enum< "Adam"_value, "Baker"_value, "Charlie"_value, "David"_value >; "Enum round trip printing test"_test <= TableTest < []( const std::string s ) -> std::string { MyEnum e; std::istringstream iss{ s }; ( iss >> e ); return Alepha::IOStreams::String{} << e; } > ::Cases { { "Adam", { "Adam" }, "Adam" }, { "Charlie", { "Charlie" }, "Charlie" }, { "Wrong", { "Wrong" }, std::type_identity< Alepha::EnumTextMismatchError >{} }, }; "Enum failure parse"_test <= TableTest < []( const std::string s ) { try { MyEnum e; std::istringstream iss{ s }; ( iss >> e ); throw "Fail"; } catch( const Alepha::EnumTextMismatchError &ex ) { return ex.expectedValues(); } } > ::Cases { { "Wrong", { "Wrong" }, { "Adam", "Baker", "Charlie", "David" } }, }; static_assert( not CanNegate< Alepha::Enum< "one"_value > > ); static_assert( CanNegate< Alepha::Enum< "one"_value, "two"_value > > ); static_assert( not CanNegate< Alepha::Enum< "one"_value, "two"_value, "three"_value > > ); "Does negation of a two form enum work?"_test <=TableTest < []( const Alepha::Enum< "No"_value, "Yes"_value > e ) { return not e; } > ::Cases { { "No -> Yes", { "No"_value }, "Yes"_value }, { "Yes -> No", { "Yes"_value }, "No"_value }, }; };