forked from Alepha/Alepha
Some cleanup and tests for Enum and constexpr strings.
This commit is contained in:
@ -31,6 +31,7 @@ add_subdirectory( Utility )
|
||||
|
||||
# The local subdir tests to build
|
||||
add_subdirectory( AutoRAII.test )
|
||||
add_subdirectory( Enum.test )
|
||||
add_subdirectory( comparisons.test )
|
||||
add_subdirectory( Exception.test )
|
||||
add_subdirectory( word_wrap.test )
|
||||
|
@ -24,6 +24,11 @@ namespace Alepha::Hydrogen ::detail:: ConstexprString_m
|
||||
// benefit of the NTTP variadic list way, for compiler memory usage, is that
|
||||
// the a type using the string as a parameter has a symbol size which
|
||||
// is proportional to the number of chars in the string.
|
||||
//
|
||||
// However, NTTP parameters are pretty large in terms of memory footprint
|
||||
// of the compiler and they do tax the compiler's CPU usage a lot more.
|
||||
// As such, compile time strings of a "reasonable" size are probably the
|
||||
// best we can hope for.
|
||||
const std::size_t maxSize= 128;
|
||||
}
|
||||
|
||||
@ -47,7 +52,7 @@ namespace Alepha::Hydrogen ::detail:: ConstexprString_m
|
||||
const char *
|
||||
what() const noexcept final
|
||||
{
|
||||
return "Failure to allocate enough space for a a compile-time string.";
|
||||
return "Failure to allocate enough space for a a compile-time string.";
|
||||
}
|
||||
};
|
||||
|
||||
|
13
Enum.h
13
Enum.h
@ -19,7 +19,7 @@ static_assert( __cplusplus > 2020'99 );
|
||||
#include "ConstexprString.h"
|
||||
#include "meta.h"
|
||||
|
||||
namespace Alepha::Hydrogen ::detail:: Enum_m
|
||||
namespace Alepha::Hydrogen ::detail:: Enum_m
|
||||
{
|
||||
inline namespace exports {}
|
||||
|
||||
@ -52,13 +52,6 @@ namespace Alepha::Hydrogen ::detail:: Enum_m
|
||||
}
|
||||
}
|
||||
|
||||
template< auto value, auto ... >
|
||||
constexpr decltype( auto )
|
||||
get_first_enum_string()
|
||||
{
|
||||
return value;
|
||||
}
|
||||
|
||||
template< ConstexprString s >
|
||||
struct EnumValueString
|
||||
{
|
||||
@ -121,8 +114,6 @@ namespace Alepha::Hydrogen ::detail:: Enum_m
|
||||
|
||||
template< EnumValueString ... values >
|
||||
class exports::Enum
|
||||
//: private comparable
|
||||
// Alepha::Hydrogen comparables work differently than the one-off Cavorite form.
|
||||
{
|
||||
private:
|
||||
enum class StrictInteger : unsigned {};
|
||||
@ -197,8 +188,6 @@ namespace Alepha::Hydrogen ::detail:: Enum_m
|
||||
|
||||
constexpr unsigned get_index() const { return static_cast< unsigned >( value ); }
|
||||
|
||||
constexpr auto equality_lens() const { return value; }
|
||||
|
||||
bool operator == ( const Enum & ) const= default;
|
||||
|
||||
friend std::ostream &
|
||||
|
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