From: Rafał Długołęcki Date: Tue, 5 May 2015 22:17:54 +0000 (+0200) Subject: Add Option tests. X-Git-Tag: v0.2~17 X-Git-Url: https://git.dlugolecki.net.pl/?p=command.git;a=commitdiff_plain;h=f689b4b00fd8853af1026cd09a059c304fb6984d Add Option tests. --- 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; +}