1
0
forked from Alepha/Alepha

Some cleanup and tests for Enum and constexpr strings.

This commit is contained in:
2024-04-04 00:53:12 -04:00
parent 38df35ebc4
commit 29575e7e30
5 changed files with 70 additions and 13 deletions

61
Enum.test/0.cc Normal file
View 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
View File

@ -0,0 +1 @@
unit_test( 0 )