diff --git a/test_parser.cpp b/test_parser.cpp index c98a8d7..37c1cab 100644 --- a/test_parser.cpp +++ b/test_parser.cpp @@ -1,40 +1,42 @@ #define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN + +#include + #include "doctest/doctest.h" #include "include/parser.hh" +template +int length(T const &x) { + return std::distance(std::begin(x), std::end(x)); +} -TEST_CASE("testing current parser functionality") +TEST_CASE("test parser functionality") { - int argc = 20; - const char * argv[20]; - argv[0] = "tests"; - argv[1] = "--flag"; - argv[2] = "--only_large"; - argv[3] = "-s"; - argv[4] = "-q"; - argv[5] = "first_short2"; - argv[6] = "--in-fil-e"; - argv[7] = "-dash"; - argv[8] = "--store_str"; - argv[9] = "qqqdash"; - argv[10] = "--store_num"; - argv[11] = "72"; - argv[12] = "--store_multy_s"; - argv[13] = "str1"; - argv[14] = "str2"; - argv[15] = "str3"; - argv[16] = "str4"; - argv[17] = "str5"; - argv[18] = "-b"; - argv[19] = "--pp"; + const char * argv[] = { + "tests", + "--flag", + "--only_large", + "-s", + "-q", "first_short2", + "--in-fil-e", + "-dash", + "--store_str", "qqqdash", + "--store_num", "72", + "--store_multy_s", "str1", "str2", "str3", "str4", "str5", + "-b", + "--pp", + "-singledash", "hellooo" + }; + + int argc = length(argv); optionparser::parser p("A test to make sure that this option parser works"); - p.add_option("--flag", "-f") .help("just flag"); p.add_option("--boolean", "-b") .help("boolean").mode(optionparser::store_true); - + p.add_option("--only_large") .help("set only large opt"); + p.add_option("-singledash") .help("singledash").mode(optionparser::store_value); p.add_option("-s") .help("set only small opt"); p.add_option("-q", "--first_short1") .help("first_short1").mode(optionparser::store_value); p.add_option("-w", "--first_short2") .help("first_short2"); @@ -47,49 +49,49 @@ TEST_CASE("testing current parser functionality") p.eat_arguments(argc, argv); - bool chech_is_flag_set = false; + bool check_is_flag_set = false; if (p.get_value("flag")) { - chech_is_flag_set = true; + check_is_flag_set = true; } - CHECK(chech_is_flag_set == true); + CHECK(check_is_flag_set == true); if (p.get_value("only_large")) { - chech_is_flag_set = true; + check_is_flag_set = true; } - CHECK(chech_is_flag_set == true); + CHECK(check_is_flag_set == true); if (p.get_value("s_option")) { - chech_is_flag_set = true; + check_is_flag_set = true; } - CHECK(chech_is_flag_set == true); + CHECK(check_is_flag_set == true); if (p.get_value("first_short1")) { - chech_is_flag_set = true; + check_is_flag_set = true; } - CHECK(chech_is_flag_set == true); + CHECK(check_is_flag_set == true); if (p.get_value("first_short2")) { - chech_is_flag_set = true; + check_is_flag_set = true; } - CHECK(chech_is_flag_set == true); + CHECK(check_is_flag_set == true); if (p.get_value("in-fil-e")) { - chech_is_flag_set = true; + check_is_flag_set = true; } - CHECK(chech_is_flag_set == true); + CHECK(check_is_flag_set == true); if (p.get_value("dash")) { - chech_is_flag_set = true; + check_is_flag_set = true; } - CHECK(chech_is_flag_set == true); + CHECK(check_is_flag_set == true); if (p.get_value("store_str")) { auto names = p.get_value>("store_str"); CHECK(names[0] == argv[9]); } - + if (p.get_value("store_num")) { CHECK(p.get_value("store_num") == 72); @@ -113,21 +115,17 @@ TEST_CASE("testing current parser functionality") } -// TEST_CASE("testingget_value_arg(arguments, argument, arg, opt ))") -// { -// get_value_arg(arguments, argument, arg, opt ); -// } - -TEST_CASE("test oo funct") +TEST_CASE("test OO functionality") { - int argc = 4; - const char * argv[4]; - argv[0] = "tests"; - argv[1] = "--flag asdsaflag"; - argv[2] = "bsadsad"; - argv[3] = "bqwewqeq"; + const char * argv[] = { + "tests", + "--flag asdsaflag", + "bsadsad", + "bqwewqeq" + }; + auto argc = length(argv); optionparser::parser p("A test to make sure that this option parser works"); @@ -136,14 +134,39 @@ TEST_CASE("test oo funct") p.eat_arguments(argc, argv); - bool chech_is_flag_set = false; + bool check_is_flag_set = false; if (p.get_value("flag")) { - chech_is_flag_set = true; + check_is_flag_set = true; auto names = p.get_value>("flag"); CHECK(names[0] == "asdsaflag"); CHECK(names[1] == "bsadsad"); CHECK(names[2] == "bqwewqeq"); } - -} \ No newline at end of file + +} + + +TEST_CASE_TEMPLATE("test typecasting functionality", T, int, double, std::string) +{ + const char * argv[] = { + "tests", + "--flag", + "2.0" + }; + + auto argc = length(argv); + + + optionparser::parser p("A test to make sure that this option parser works"); + + p.add_option("--flag", "-f") .help("just=flag").mode(optionparser::store_value); + + p.eat_arguments(argc, argv); + + CHECK(p.get_value("flag")); + + auto value = p.get_value("flag"); + + CHECK(typeid(value) == typeid(T)); +}