From f0b514dccdc31e32f2bd4e4d63633f2b3b78b611 Mon Sep 17 00:00:00 2001 From: ADAM David Alan Martin Date: Sun, 15 Oct 2023 19:51:37 -0400 Subject: [PATCH] Add tests for string algorithms. --- CMakeLists.txt | 1 + string_algorithms.test/0.cc | 45 +++++++++++++++++++++++++++ string_algorithms.test/CMakeLists.txt | 3 ++ 3 files changed, 49 insertions(+) create mode 100644 string_algorithms.test/0.cc create mode 100644 string_algorithms.test/CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt index d6c8d28..9e0993a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -27,6 +27,7 @@ add_subdirectory( AutoRAII.test ) add_subdirectory( comparisons.test ) add_subdirectory( Exception.test ) add_subdirectory( word_wrap.test ) +add_subdirectory( string_algorithms.test ) # Sample applications add_executable( example example.cc ) diff --git a/string_algorithms.test/0.cc b/string_algorithms.test/0.cc new file mode 100644 index 0000000..810a7db --- /dev/null +++ b/string_algorithms.test/0.cc @@ -0,0 +1,45 @@ +static_assert( __cplusplus > 2020'00 ); + +#include "../string_algorithms.h" + +#include +#include + +#include + +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", + { "$H$ $$ $W$", { { "H", lambaste<="Hello" }, { "W", lambaste <="World" } }, '$' }, + "Hello $ World" + }, + }; + + "An exception should be thrown when there is a trailing unenclosed variable."_test <=[] + { + try + { + Alepha::expandVariables( "$H$ $W", { { "H", lambaste<="Hello" }, { "W", lambaste<="World" } }, '$' ); + abort(); + } + catch( ... ) {} + }; +}; diff --git a/string_algorithms.test/CMakeLists.txt b/string_algorithms.test/CMakeLists.txt new file mode 100644 index 0000000..8ef1b19 --- /dev/null +++ b/string_algorithms.test/CMakeLists.txt @@ -0,0 +1,3 @@ +link_libraries( unit-test ) + +unit_test( 0 )