1
0
forked from Alepha/Alepha
Files

87 lines
2.7 KiB
C++

static_assert( __cplusplus > 2020'00 );
#include "../string_algorithms.h"
#include <Alepha/Testing/test.h>
#include <Alepha/Testing/TableTest.h>
#include <Alepha/Utility/evaluation_helpers.h>
namespace
{
using namespace Alepha::Testing::literals::test_literals;
using namespace Alepha::Testing::exports;
using Alepha::Utility::exports::enroll;
using Alepha::Utility::exports::lambaste;
}
static auto init= enroll <=[]
{
"Some simple substitution tests"_test <=TableTest< Alepha::expandVariables >::Cases
{
{
"Hello World",
{ "$H$ $W$", { { "H", lambaste<="Hello" }, { "W", lambaste<="World" } }, '$' },
"Hello World"
},
{
"Hello World (with some spaces)",
{ "$with space$ $can-expand$", { { "with space", lambaste<="Hello" }, { "can-expand", lambaste<="World" } }, '$' },
"Hello World"
},
{
"Hello $$ World",
{ "$H$ $$ $W$", { { "H", lambaste<="Hello" }, { "W", lambaste <="World" } }, '$' },
"Hello $ World"
},
};
"An exception should be thrown when there is a trailing unenclosed variable."_test <=TableTest< Alepha::expandVariables >::Cases
{
{ "Complete var",
{ "$H$ $W$", { { "H", lambaste<="Hello" }, { "W", lambaste<="World" } }, '$' },
std::nothrow
},
{ "Complete var",
{ "$H$ $W$", { { "H", lambaste<="Hello" }, { "W", lambaste<="World" } }, '$' },
"Hello World"
},
{ "Incomplete var",
{ "$H$ $W", { { "H", lambaste<="Hello" }, { "W", lambaste<="World" } }, '$' },
std::runtime_error{ "Unterminated variable `W` in expansion." }
},
{ "Missing var",
{ "$H$ $W$", { { "W", lambaste<="World" } }, '$' },
std::runtime_error{ "No such variable: `H`" }
},
};
"Does the `split` function handle simple cases correctly?"_test <=TableTest
<
[] ( const std::string text, const char delim ) { return Alepha::split( text, delim ); }
>
::Cases
{
{ "Empty string", { "", ':' }, { "" } },
{ "Single token", { "item", ':' }, { "item" } },
{ "Two tokens", { "first:second", ':' }, { "first", "second" } },
{ "Empty string many tokens", { ":::", ':' }, { "", "", "", "" } },
};
"Does the `split` function over multi-token-delimiters handle simple cases correctly?"_test <=TableTest
<
[] ( const std::string text, const std::string delim ) { return Alepha::split( text, delim ); }
>
::Cases
{
{ "Empty string", { "", "::" }, { "" } },
{ "Single token", { "item", "::" }, { "item" } },
{ "Two tokens", { "first::second", "::" }, { "first", "second" } },
{ "Empty string many tokens", { "::::::", "::" }, { "", "", "", "" } },
{ "Alphabet string many tokens", { "a::b::c::d", "::" }, { "a", "b", "c", "d" } },
{ "Alphabet string many tokens", { "::a::b::c::d::", "::" }, { "", "a", "b", "c", "d", "" } },
};
};