forked from Alepha/Alepha
Some cleanup and tests for Enum and constexpr strings.
This commit is contained in:
61
Enum.test/0.cc
Normal file
61
Enum.test/0.cc
Normal file
@ -0,0 +1,61 @@
|
||||
static_assert( __cplusplus > 2020'99 );
|
||||
|
||||
#include "../Enum.h"
|
||||
|
||||
#include <Alepha/Testing/test.h>
|
||||
#include <Alepha/Testing/TableTest.h>
|
||||
|
||||
#include <Alepha/Utility/evaluation_helpers.h>
|
||||
|
||||
#include <Alepha/IOStreams/String.h>
|
||||
|
||||
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" } },
|
||||
};
|
||||
};
|
1
Enum.test/CMakeLists.txt
Normal file
1
Enum.test/CMakeLists.txt
Normal file
@ -0,0 +1 @@
|
||||
unit_test( 0 )
|
Reference in New Issue
Block a user