Add Option tests.
authorRafał Długołęcki <rafal@dlugolecki.net.pl>
Tue, 5 May 2015 22:17:54 +0000 (00:17 +0200)
committerRafał Długołęcki <rafal@dlugolecki.net.pl>
Tue, 5 May 2015 22:17:54 +0000 (00:17 +0200)
tests/Makefile.am
tests/option/should_match_exact_name.cpp [new file with mode: 0644]

index f126d88c8572bb76001f188c982189d8989e6fd3..85a8a466e5270d2c4f76fd5371731c51adf99972 100644 (file)
@@ -17,7 +17,8 @@ TESTS = \
        option_handles_float_value.test \
        option_handles_negative_float_value.test \
        option_handles_boolean_value.test \
-       option_handles_void_value.test
+       option_handles_void_value.test \
+       option_should_match_exact_name.test
 
 noinst_PROGRAMS = $(TESTS)
 
@@ -44,3 +45,4 @@ option_handles_float_value_test_SOURCES  = option/handles_float_value.cpp
 option_handles_negative_float_value_test_SOURCES  = option/handles_negative_float_value.cpp
 option_handles_boolean_value_test_SOURCES  = option/handles_boolean_value.cpp
 option_handles_void_value_test_SOURCES  = option/handles_void_value.cpp
+option_should_match_exact_name_test_SOURCES  = option/should_match_exact_name.cpp
diff --git a/tests/option/should_match_exact_name.cpp b/tests/option/should_match_exact_name.cpp
new file mode 100644 (file)
index 0000000..81f3778
--- /dev/null
@@ -0,0 +1,36 @@
+#include <iostream>
+#include <vector>
+
+#include "option.h"
+
+#define NAME "test"
+
+using namespace std;
+using namespace command;
+
+void function(void) { }
+
+int main() {
+    std::vector<std::string> badOptions;
+    badOptions.push_back("--test");
+    badOptions.push_back("-test");
+    badOptions.push_back("tes");
+    badOptions.push_back("te");
+    badOptions.push_back("t");
+
+    Option<void> option(NAME, "Option should match only exact name", function);
+    for (std::string bad : badOptions) {
+        if (option.understand(bad)) {
+            std::cout << option.describe() << " but '" << NAME << "' was matched as same to '" << bad << "'\n";
+        }
+    }
+
+    if (option.understand(NAME)) {
+        std::cout << option.describe() << " and it understands it correctly\n";
+        return 0;
+    }
+
+    std::cout << option.describe() << " but no name was found\n";
+
+    return 1;
+}