From 577fc0845718ed8ad5bebf02a277c0579a817f77 Mon Sep 17 00:00:00 2001 From: Felix Morgner Date: Fri, 17 May 2024 17:58:38 +0200 Subject: wanda: restructure source layout --- source/apps/tests/wandac/cli.cpp | 80 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 source/apps/tests/wandac/cli.cpp (limited to 'source/apps/tests/wandac/cli.cpp') diff --git a/source/apps/tests/wandac/cli.cpp b/source/apps/tests/wandac/cli.cpp new file mode 100644 index 0000000..57d2a8f --- /dev/null +++ b/source/apps/tests/wandac/cli.cpp @@ -0,0 +1,80 @@ +#include "wanda/wandac/cli.hpp" + +#include +#include +#include + +#include +#include + +using namespace std::string_literals; + +namespace wanda::tests::app::wandac +{ + + template + auto make_argument_list(Ts const & ... args) -> lyra::args + { + return {"wanda"s, static_cast(args)...}; + } + + SCENARIO("Empty argument list parsing", "[app][client][cli]") + { + GIVEN("A fresh cli instance and error stream") + { + auto cli = ::wandac::cli{}; + auto error_stream = std::ostringstream{}; + + WHEN("invoking parse without any program arguments") + { + auto result = cli.parse(make_argument_list(), error_stream); + + THEN("the return value is false") { REQUIRE_FALSE(result); } + THEN("the error stream is not empty") { REQUIRE_FALSE(error_stream.view().empty()); } + THEN("the help flag is not set") { REQUIRE_FALSE(cli.help); } + THEN("the command is empty") { REQUIRE(cli.command.empty()); } + } + } + } + + SCENARIO("Valid argument list parsing", "[app][client][cli]") + { + GIVEN("A fresh cli instance and error stream") + { + auto cli = ::wandac::cli{}; + auto error_stream = std::ostringstream{}; + + AND_GIVEN("'-h' in the argument list") + { + auto argument_list = make_argument_list("-h"); + + WHEN("invoking parse without additional arguments") + { + auto result = cli.parse(argument_list, error_stream); + + THEN("the return value is true") { REQUIRE(result); } + THEN("the error stream is empty") { REQUIRE(error_stream.view().empty()); } + THEN("the help flag is set") { REQUIRE(cli.help); } + THEN("the command is empty") { REQUIRE(cli.command.empty()); } + } + } + + AND_GIVEN("'change' in the argument list") + { + auto argument_list = make_argument_list("change"); + + WHEN("invoking parse without additional arguments") + { + auto result = cli.parse(argument_list, error_stream); + + THEN("the return valis is true") { REQUIRE(result); } + THEN("the error stream is empty") { REQUIRE(error_stream.view().empty()); } + THEN("the help flag is not set") { REQUIRE_FALSE(cli.help); } + THEN("the command is not empty") { REQUIRE_FALSE(cli.command.empty()); } + THEN("the command is 'change'") { REQUIRE(cli.command == "change"); } + } + } + } + } + +} // namespace wanda::tests::app::wandac -- cgit v1.2.3