From ca90e97a9da4457790262c53515cb5ab58a2ce4f Mon Sep 17 00:00:00 2001 From: Lexi Winter Date: Sat, 21 Jun 2025 13:53:10 +0100 Subject: add command_map, skipws, next_word --- tests/command_map.cc | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 tests/command_map.cc (limited to 'tests/command_map.cc') diff --git a/tests/command_map.cc b/tests/command_map.cc new file mode 100644 index 0000000..75b6f0d --- /dev/null +++ b/tests/command_map.cc @@ -0,0 +1,41 @@ +/* + * This source code is released into the public domain. + */ + +#include + +#include + +import nihil; + +namespace { + +auto cmd_sub1_called = false; +auto cmd_sub1 = nihil::command("cmd sub1", [](int, int, char **) -> int +{ + cmd_sub1_called = true; + return 0; +}); + +} // anonymous namespace + +TEST_CASE("command_map: basic", "[command_map]") +{ + auto args = std::vector{ + "cmd", "sub1", nullptr + }; + auto argv = const_cast(args.data()); + nihil::dispatch_command(0, args.size(), argv); + REQUIRE(cmd_sub1_called == true); +} + +TEST_CASE("command_map: unknown command", "[command_map]") +{ + auto args = std::vector{ + "cmd", "nonesuch", nullptr + }; + auto argv = const_cast(args.data()); + + REQUIRE_THROWS_AS(nihil::dispatch_command(0, args.size(), argv), + nihil::usage_error); +} -- cgit v1.2.3