forked from Alepha/Alepha
This permits naming operators via an enhanced enum and then looking them up. This is a useful component for quick scripting language functionalities.
32 lines
848 B
C++
32 lines
848 B
C++
static_assert( __cplusplus > 2023'00 );
|
|
|
|
#include "../NamedOperator.h"
|
|
|
|
#include <Alepha/Testing/test.h>
|
|
#include <Alepha/Testing/TableTest.h>
|
|
|
|
#include <Alepha/Utility/enroll.h>
|
|
|
|
static auto init= Alepha::Utility::enroll <=[]
|
|
{
|
|
using namespace Alepha::Testing::exports;
|
|
using namespace Alepha::Utility::NamedOperator_m;
|
|
using namespace Alepha::literals::enum_literals;
|
|
|
|
"Does the named operator system have the expected basic functionality?"_test <= TableTest
|
|
<
|
|
[]( const int lhs, const OperatorName name, const int rhs )
|
|
{
|
|
return getOperatorMap< int >().at( name )( lhs, rhs );
|
|
}
|
|
>
|
|
::Cases
|
|
{
|
|
{ "addition", { 1, "add"_value, 1 }, 2 },
|
|
{ "subtraction", { 1, "sub"_value, 1 }, 0 },
|
|
{ "multiplication", { 5, "mul"_value, 5 }, 25 },
|
|
{ "modulus", { 9, "mod"_value, 5 }, 4 },
|
|
{ "division", { 5, "idiv"_value, 3 }, 1 },
|
|
};
|
|
};
|