aboutsummaryrefslogtreecommitdiffstats
path: root/tests/command_map.cc
diff options
context:
space:
mode:
Diffstat (limited to 'tests/command_map.cc')
-rw-r--r--tests/command_map.cc41
1 files changed, 41 insertions, 0 deletions
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 <vector>
+
+#include <catch2/catch_test_macros.hpp>
+
+import nihil;
+
+namespace {
+
+auto cmd_sub1_called = false;
+auto cmd_sub1 = nihil::command<int>("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<char const *>{
+ "cmd", "sub1", nullptr
+ };
+ auto argv = const_cast<char **>(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<char const *>{
+ "cmd", "nonesuch", nullptr
+ };
+ auto argv = const_cast<char **>(args.data());
+
+ REQUIRE_THROWS_AS(nihil::dispatch_command(0, args.size(), argv),
+ nihil::usage_error);
+}