diff --git a/test/unittest/CMakeLists.txt b/test/unittest/CMakeLists.txt index 2f1026b..d4fff1b 100644 --- a/test/unittest/CMakeLists.txt +++ b/test/unittest/CMakeLists.txt @@ -6,8 +6,7 @@ add_executable(unittest) target_sources(unittest PRIVATE cstring_array.h - custom_a.h - custom_b.h + custom.h main.cpp test_argument_parser.cpp test_error_message.cpp diff --git a/test/unittest/custom_a.h b/test/unittest/custom.h similarity index 93% rename from test/unittest/custom_a.h rename to test/unittest/custom.h index 600884d..1218888 100644 --- a/test/unittest/custom_a.h +++ b/test/unittest/custom.h @@ -1,5 +1,5 @@ -#ifndef CUSTOMA_H -#define CUSTOMA_H +#ifndef CUSTOM_H +#define CUSTOM_H #include "argparse.hpp" #include @@ -45,4 +45,4 @@ class Converter }; } -#endif /* CUSTOMA_H */ +#endif /* CUSTOM_H */ diff --git a/test/unittest/custom_b.h b/test/unittest/custom_b.h deleted file mode 100644 index 7e51aef..0000000 --- a/test/unittest/custom_b.h +++ /dev/null @@ -1,48 +0,0 @@ -#ifndef CUSTOMB_H -#define CUSTOMB_H - -#include "argparse.hpp" -#include - - -namespace bar -{ - class Custom - { - public: - Custom() = default; - explicit Custom(std::string const & text) - : m_text(text) - { - } - - public: - std::string m_text; - }; -} - -namespace argparse -{ -template<> -class Converter -{ - public: - auto from_string(std::string const & s, bar::Custom & t) const -> bool - { - t = bar::Custom(s); - return true; - } - - auto to_string(bar::Custom const & t) const -> std::string - { - return ""; - } - - auto are_equal(bar::Custom const & lhs, bar::Custom const & rhs) const -> bool - { - return lhs.m_text == rhs.m_text; - } -}; -} - -#endif /* CUSTOMB_H */ diff --git a/test/unittest/test_parsing_optional.cpp b/test/unittest/test_parsing_optional.cpp index fa7e701..743ac8a 100644 --- a/test/unittest/test_parsing_optional.cpp +++ b/test/unittest/test_parsing_optional.cpp @@ -1,8 +1,7 @@ #include "argparse.hpp" #include "cstring_array.h" -#include "custom_a.h" -#include "custom_b.h" +#include "custom.h" #include "doctest.h" @@ -19,13 +18,6 @@ inline auto operator==(Custom const & lhs, Custom const & rhs) -> bool return lhs.m_text == rhs.m_text; } } -namespace bar -{ -inline auto operator==(Custom const & lhs, Custom const & rhs) -> bool -{ - return lhs.m_text == rhs.m_text; -} -} TEST_CASE("Parsing an optional argument yields false when it's missing") { @@ -95,7 +87,7 @@ TEST_CASE("Parsing an optional argument with store false action yields false whe CHECK(args.get_value("o") == false); } -TEST_CASE_TEMPLATE("Parsing an optional argument with store const action yields false when it's missing", T, char, signed char, unsigned char, short int, unsigned short int, int, unsigned int, long int, unsigned long int, long long int, unsigned long long int, float, double, long double, std::string, foo::Custom, bar::Custom) +TEST_CASE_TEMPLATE("Parsing an optional argument with store const action yields false when it's missing", T, char, signed char, unsigned char, short int, unsigned short int, int, unsigned int, long int, unsigned long int, long long int, unsigned long long int, float, double, long double, std::string, foo::Custom) { auto parser = argparse::ArgumentParser(); @@ -117,7 +109,7 @@ TEST_CASE_TEMPLATE("Parsing an optional argument with store const action yields CHECK(!args.get("o")); } -TEST_CASE_TEMPLATE("Parsing an optional argument with store const action yields const value", T, char, signed char, unsigned char, short int, unsigned short int, int, unsigned int, long int, unsigned long int, long long int, unsigned long long int, float, double, long double, std::string, foo::Custom, bar::Custom) +TEST_CASE_TEMPLATE("Parsing an optional argument with store const action yields const value", T, char, signed char, unsigned char, short int, unsigned short int, int, unsigned int, long int, unsigned long int, long long int, unsigned long long int, float, double, long double, std::string, foo::Custom) { auto parser = argparse::ArgumentParser(); @@ -248,7 +240,7 @@ TEST_CASE("Parsing an optional argument with append action yields a list of argu CHECK(args.get_value>("a") == std::vector{"one", "two", "three"}); } -TEST_CASE_TEMPLATE("Parsing an optional argument with append action yields its requested type", T, char, signed char, unsigned char, short int, unsigned short int, int, unsigned int, long int, unsigned long int, long long int, unsigned long long int, float, double, long double, foo::Custom, bar::Custom) +TEST_CASE_TEMPLATE("Parsing an optional argument with append action yields its requested type", T, char, signed char, unsigned char, short int, unsigned short int, int, unsigned int, long int, unsigned long int, long long int, unsigned long long int, float, double, long double, foo::Custom) { auto parser = argparse::ArgumentParser(); parser.add_argument("-a").action(argparse::append).type(); @@ -339,7 +331,7 @@ TEST_CASE("Optional argument can be used with its long name") CHECK(args.get_value("option") == "val"); } -TEST_CASE_TEMPLATE("Parsing an optional argument yields its requested type", T, char, signed char, unsigned char, short int, unsigned short int, int, unsigned int, long int, unsigned long int, long long int, unsigned long long int, float, double, long double, foo::Custom, bar::Custom) +TEST_CASE_TEMPLATE("Parsing an optional argument yields its requested type", T, char, signed char, unsigned char, short int, unsigned short int, int, unsigned int, long int, unsigned long int, long long int, unsigned long long int, float, double, long double, foo::Custom) { auto parser = argparse::ArgumentParser(); parser.add_argument("-o").type(); @@ -379,7 +371,7 @@ TEST_CASE("Parsing an optional argument with invalid value throws an exception") CHECK_THROWS_WITH_AS(parser.parse_args(3, cstr_arr{"prog", "-o", "10gibberish"}), "argument -o: invalid value: '10gibberish'", argparse::parsing_error); } -TEST_CASE_TEMPLATE("Parsing an optional argument with default value yields the default value when it's missing", T, char, signed char, unsigned char, short int, unsigned short int, int, unsigned int, long int, unsigned long int, long long int, unsigned long long int, float, double, long double, std::string, foo::Custom, bar::Custom) +TEST_CASE_TEMPLATE("Parsing an optional argument with default value yields the default value when it's missing", T, char, signed char, unsigned char, short int, unsigned short int, int, unsigned int, long int, unsigned long int, long long int, unsigned long long int, float, double, long double, std::string, foo::Custom) { auto parser = argparse::ArgumentParser(); @@ -412,7 +404,7 @@ TEST_CASE_TEMPLATE("Parsing an optional argument with default value yields the d } } -TEST_CASE_TEMPLATE("Parsing an optional argument with default value yields value of the argument's type", T, char, signed char, unsigned char, short int, unsigned short int, int, unsigned int, long int, unsigned long int, long long int, unsigned long long int, float, double, long double, std::string, foo::Custom, bar::Custom) +TEST_CASE_TEMPLATE("Parsing an optional argument with default value yields value of the argument's type", T, char, signed char, unsigned char, short int, unsigned short int, int, unsigned int, long int, unsigned long int, long long int, unsigned long long int, float, double, long double, std::string, foo::Custom) { auto parser = argparse::ArgumentParser(); @@ -525,7 +517,7 @@ TEST_CASE("Parsing a missing optional argument with required false does not thro CHECK_NOTHROW(parser.parse_args(1, cstr_arr{"prog"})); } -TEST_CASE_TEMPLATE("Parsing an optional argument with choices set accepts one of the values", T, char, signed char, unsigned char, short int, unsigned short int, int, unsigned int, long int, unsigned long int, long long int, unsigned long long int, float, double, long double, std::string, foo::Custom, bar::Custom) +TEST_CASE_TEMPLATE("Parsing an optional argument with choices set accepts one of the values", T, char, signed char, unsigned char, short int, unsigned short int, int, unsigned int, long int, unsigned long int, long long int, unsigned long long int, float, double, long double, std::string, foo::Custom) { auto parser = argparse::ArgumentParser().handle(argparse::Handle::none); @@ -559,7 +551,7 @@ TEST_CASE_TEMPLATE("Parsing an optional argument with choices set accepts one of } } -TEST_CASE_TEMPLATE("Parsing an optional argument with choices set throws an exception on incorrect value", T, char, signed char, unsigned char, short int, unsigned short int, int, unsigned int, long int, unsigned long int, long long int, unsigned long long int, float, double, long double, std::string, foo::Custom, bar::Custom) +TEST_CASE_TEMPLATE("Parsing an optional argument with choices set throws an exception on incorrect value", T, char, signed char, unsigned char, short int, unsigned short int, int, unsigned int, long int, unsigned long int, long long int, unsigned long long int, float, double, long double, std::string, foo::Custom) { auto parser = argparse::ArgumentParser().handle(argparse::Handle::none); @@ -2568,7 +2560,7 @@ TEST_CASE("Parsing long option with joined argument yields its value") CHECK(args.get_value("long") == "value"); } -TEST_CASE_TEMPLATE("Parsing long option with joined argument yields its value", T, char, signed char, unsigned char, short int, unsigned short int, int, unsigned int, long int, unsigned long int, long long int, unsigned long long int, float, double, long double, foo::Custom, bar::Custom) +TEST_CASE_TEMPLATE("Parsing long option with joined argument yields its value", T, char, signed char, unsigned char, short int, unsigned short int, int, unsigned int, long int, unsigned long int, long long int, unsigned long long int, float, double, long double, foo::Custom) { auto parser = argparse::ArgumentParser(); parser.add_argument("--long").type(); @@ -2639,7 +2631,7 @@ TEST_CASE("Parsing short option with joined argument yields its value") CHECK(args.get_value("o") == "value"); } -TEST_CASE_TEMPLATE("Parsing short option with joined argument yields its value", T, char, signed char, unsigned char, short int, unsigned short int, int, unsigned int, long int, unsigned long int, long long int, unsigned long long int, float, double, long double, foo::Custom, bar::Custom) +TEST_CASE_TEMPLATE("Parsing short option with joined argument yields its value", T, char, signed char, unsigned char, short int, unsigned short int, int, unsigned int, long int, unsigned long int, long long int, unsigned long long int, float, double, long double, foo::Custom) { auto parser = argparse::ArgumentParser(); parser.add_argument("-o").type(); diff --git a/test/unittest/test_parsing_positional.cpp b/test/unittest/test_parsing_positional.cpp index 8da177e..a797ef3 100644 --- a/test/unittest/test_parsing_positional.cpp +++ b/test/unittest/test_parsing_positional.cpp @@ -1,8 +1,7 @@ #include "argparse.hpp" #include "cstring_array.h" -#include "custom_a.h" -#include "custom_b.h" +#include "custom.h" #include "doctest.h" @@ -19,13 +18,6 @@ inline auto operator==(Custom const & lhs, Custom const & rhs) -> bool return lhs.m_text == rhs.m_text; } } -namespace bar -{ -inline auto operator==(Custom const & lhs, Custom const & rhs) -> bool -{ - return lhs.m_text == rhs.m_text; -} -} TEST_CASE("Parsing a positional argument yields its value") { @@ -37,7 +29,7 @@ TEST_CASE("Parsing a positional argument yields its value") CHECK(args.get_value("p1") == "v1"); } -TEST_CASE_TEMPLATE("Parsing a positional argument yields its requested type", T, char, signed char, unsigned char, short int, unsigned short int, int, unsigned int, long int, unsigned long int, long long int, unsigned long long int, float, double, long double, foo::Custom, bar::Custom) +TEST_CASE_TEMPLATE("Parsing a positional argument yields its requested type", T, char, signed char, unsigned char, short int, unsigned short int, int, unsigned int, long int, unsigned long int, long long int, unsigned long long int, float, double, long double, foo::Custom) { auto parser = argparse::ArgumentParser(); parser.add_argument("pos").type(); @@ -147,7 +139,7 @@ TEST_CASE("The resulting attribute name for positional argument is based on dest CHECK(args.get("bar")); } -TEST_CASE_TEMPLATE("Parsing a positional argument with choices set accepts one of the values", T, char, signed char, unsigned char, short int, unsigned short int, int, unsigned int, long int, unsigned long int, long long int, unsigned long long int, float, double, long double, std::string, foo::Custom, bar::Custom) +TEST_CASE_TEMPLATE("Parsing a positional argument with choices set accepts one of the values", T, char, signed char, unsigned char, short int, unsigned short int, int, unsigned int, long int, unsigned long int, long long int, unsigned long long int, float, double, long double, std::string, foo::Custom) { auto parser = argparse::ArgumentParser().handle(argparse::Handle::none); @@ -181,7 +173,7 @@ TEST_CASE_TEMPLATE("Parsing a positional argument with choices set accepts one o } } -TEST_CASE_TEMPLATE("Parsing a positional argument with choices set throws an exception on incorrect value", T, char, signed char, unsigned char, short int, unsigned short int, int, unsigned int, long int, unsigned long int, long long int, unsigned long long int, float, double, long double, std::string, foo::Custom, bar::Custom) +TEST_CASE_TEMPLATE("Parsing a positional argument with choices set throws an exception on incorrect value", T, char, signed char, unsigned char, short int, unsigned short int, int, unsigned int, long int, unsigned long int, long long int, unsigned long long int, float, double, long double, std::string, foo::Custom) { auto parser = argparse::ArgumentParser().handle(argparse::Handle::none);