From f689b4b00fd8853af1026cd09a059c304fb6984d Mon Sep 17 00:00:00 2001 From: =?utf8?q?Rafa=C5=82=20D=C5=82ugo=C5=82=C4=99cki?= Date: Wed, 6 May 2015 00:17:54 +0200 Subject: [PATCH] Add Option tests. --- tests/Makefile.am | 4 ++- tests/option/should_match_exact_name.cpp | 36 ++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 tests/option/should_match_exact_name.cpp diff --git a/tests/Makefile.am b/tests/Makefile.am index f126d88..85a8a46 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -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 index 0000000..81f3778 --- /dev/null +++ b/tests/option/should_match_exact_name.cpp @@ -0,0 +1,36 @@ +#include +#include + +#include "option.h" + +#define NAME "test" + +using namespace std; +using namespace command; + +void function(void) { } + +int main() { + std::vector badOptions; + badOptions.push_back("--test"); + badOptions.push_back("-test"); + badOptions.push_back("tes"); + badOptions.push_back("te"); + badOptions.push_back("t"); + + Option 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; +} -- 2.30.2