summaryrefslogtreecommitdiff
path: root/test/argparser_test.cc
diff options
context:
space:
mode:
Diffstat (limited to 'test/argparser_test.cc')
-rw-r--r--test/argparser_test.cc49
1 files changed, 49 insertions, 0 deletions
diff --git a/test/argparser_test.cc b/test/argparser_test.cc
new file mode 100644
index 0000000..842b214
--- /dev/null
+++ b/test/argparser_test.cc
@@ -0,0 +1,49 @@
+#include <uunit.h>
+
+#include <argparser.h>
+
+#include <iostream>
+#include <string>
+
+class ArgParserTest
+ : public uUnit
+{
+public:
+ ArgParserTest()
+ {
+ uTEST(ArgParserTest::test);
+ }
+
+ void test()
+ {
+ const char* argv[] =
+ {
+ "app-name",
+ "-x",
+ "42"
+ };
+ int argc = sizeof(argv)/sizeof(*argv);
+ ArgParser<int, std::optional<int>> args;
+
+ args.add("-x", "--some-x",
+ std::function([](int i)
+ {
+ std::cout << "int: " << i << "\n";
+ return 0;
+ }),
+ "Helptext for -x,--some-x");
+
+ args.add("-X", "--opt-x",
+ std::function([](std::optional<int> i)
+ {
+ std::cout << "opt<int>: " << (i?std::to_string(*i):"none") << "\n";
+ return 0;
+ }),
+ "Helptext for -X,--opt-x");
+
+ args.parse(argc, argv);
+ }
+};
+
+// Registers the fixture into the 'registry'
+static ArgParserTest test;