forked from Alepha/Alepha
93 lines
1.9 KiB
C++
93 lines
1.9 KiB
C++
static_assert( __cplusplus > 2023'00 );
|
|
|
|
#include "../UnifiedEnum.h"
|
|
|
|
#include <Alepha/Testing/test.h>
|
|
#include <Alepha/Testing/TableTest.h>
|
|
|
|
#include <Alepha/Utility/evaluation_helpers.h>
|
|
|
|
#include <Alepha/IOStreams/String.h>
|
|
|
|
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 BirdMeat= Alepha::Enum< "Chicken"_value, "Duck"_value, "Quail"_value >;
|
|
using LandMeat= Alepha::Enum< "Beef"_value, "Chicken"_value, "Pork"_value >;
|
|
|
|
using MyEnum= Alepha::UnifiedEnum< BirdMeat, LandMeat >;
|
|
|
|
MyEnum e;
|
|
|
|
"Can Unified Enum be constructed from a base enum (left base)?"_test <=TableTest
|
|
<
|
|
[]( const BirdMeat &bm ) -> MyEnum
|
|
{
|
|
return MyEnum( bm );
|
|
}
|
|
>
|
|
::Cases
|
|
{
|
|
{ "Chicken", { "Chicken"_value }, "Chicken"_value },
|
|
{ "Duck", { "Duck"_value }, "Duck"_value },
|
|
{ "Quail", { "Quail"_value }, "Quail"_value },
|
|
};
|
|
|
|
"Unified 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
|
|
{
|
|
{ "Beef", { "Beef" }, "Beef" },
|
|
{ "Chicken", { "Chicken" }, "Chicken" },
|
|
{ "Duck", { "Duck" }, "Duck" },
|
|
{ "Unicorn", { "Unicorn" }, std::type_identity< Alepha::EnumTextMismatchError >{} },
|
|
};
|
|
|
|
"Unified 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
|
|
{
|
|
{ "Unicorn", { "Unicorn" }, { "Chicken", "Duck", "Quail", "Beef", "Chicken", "Pork" } },
|
|
};
|
|
};
|
|
|