Add Option tests.
[command.git] / tests / option / handles_negative_int_value.cpp
diff --git a/tests/option/handles_negative_int_value.cpp b/tests/option/handles_negative_int_value.cpp
new file mode 100644 (file)
index 0000000..816e8da
--- /dev/null
@@ -0,0 +1,41 @@
+#include <iostream>
+#include <string>
+
+#include "option.h"
+
+using namespace std;
+using namespace command;
+
+#define NAME "test"
+#define VALUE "-1234567890"
+
+#define OPTION NAME "=" VALUE
+
+typedef int OptionType;
+
+OptionType test;
+
+void function(OptionType value) {
+    test = value;
+}
+
+int main() {
+    Option<OptionType> option(NAME, "Option as negative int", function);
+
+    if (option.understand(OPTION)) {
+        option.handle();
+    }
+    else {
+        cout << option.describe() << " do not understand " << VALUE << " value\n";
+        return 1;
+    }
+
+    if (test == std::stoi(VALUE)) {
+        cout << option.describe() << " handles negative int values\n";
+        return 0;
+    }
+
+    cout << option.describe() << " do not handle negative int values\n";
+
+    return 1;
+}