test/cli_arguments_parser: extend some tests, implement all remaining parser tests except checking for error messages

BodgeMaster-unfinished
BodgeMaster 2022-07-20 19:16:02 +02:00
parent db3b133f88
commit 0dcc579bb5
1 changed files with 321 additions and 6 deletions

View File

@ -226,6 +226,48 @@ int main(int argc, char* argv[]) {
ASSERT(unknownFlagMixedTestParser.getFlag(std::string("four")).value); ASSERT(unknownFlagMixedTestParser.getFlag(std::string("four")).value);
delete[] unknownFlagTestParameterList; delete[] unknownFlagTestParameterList;
std::vector<CLI::Flag> unknownLongFlagTestFlags;
unknownLongFlagTestFlags.push_back(CLI::Flag('0', "zero", "test flag"));
unknownLongFlagTestFlags.push_back(CLI::Flag('1', "one", "test flag"));
unknownLongFlagTestFlags.push_back(CLI::Flag('2', "two", "test flag"));
unknownLongFlagTestFlags.push_back(CLI::Flag('3', "three","test flag"));
unknownLongFlagTestFlags.push_back(CLI::Flag('4', "four", "test flag"));
unknownLongFlagTestFlags.push_back(CLI::Flag('5', "five", "test flag"));
std::vector<CLI::UnpositionalArgument> unknownLongFlagTestUnpositionalArguments;
std::vector<CLI::PositionalArgument> unknownLongFlagTestPositionalArguments;
const char** unknownLongFlagTestParameterList = new const char*[7];
unknownLongFlagTestParameterList[0] = "test";
unknownLongFlagTestParameterList[1] = "--a";
unknownLongFlagTestParameterList[2] = "-1";
unknownLongFlagTestParameterList[3] = "-2";
unknownLongFlagTestParameterList[4] = "-3";
unknownLongFlagTestParameterList[5] = "-4";
unknownLongFlagTestParameterList[6] = "-5";
int unknownLongFlagStandaloneTestParameterCount = 2;
CLI::ArgumentsParser unknownLongFlagStandaloneTestParser = CLI::ArgumentsParser(unknownLongFlagStandaloneTestParameterCount, unknownLongFlagTestParameterList, unknownLongFlagTestFlags, unknownLongFlagTestUnpositionalArguments, unknownLongFlagTestPositionalArguments);
ASSERT(unknownLongFlagStandaloneTestParser.getFlag('1').isError);
ASSERT(unknownLongFlagStandaloneTestParser.getFlag('1').errorCode == ErrorCodes::NOT_PRESENT);
ASSERT(!unknownLongFlagStandaloneTestParser.getFlag('1').value);
ASSERT(unknownLongFlagStandaloneTestParser.getFlag(std::string("four")).isError);
ASSERT(unknownLongFlagStandaloneTestParser.getFlag(std::string("four")).errorCode == ErrorCodes::NOT_PRESENT);
ASSERT(!unknownLongFlagStandaloneTestParser.getFlag(std::string("four")).value);
int unknownLongFlagMixedTestParameterCount = 7;
CLI::ArgumentsParser unknownLongFlagMixedTestParser = CLI::ArgumentsParser(unknownLongFlagMixedTestParameterCount, unknownLongFlagTestParameterList, unknownLongFlagTestFlags, unknownLongFlagTestUnpositionalArguments, unknownLongFlagTestPositionalArguments);
ASSERT(unknownLongFlagMixedTestParser.getFlag('1').isError);
ASSERT(unknownLongFlagMixedTestParser.getFlag('1').errorCode == ErrorCodes::WRONG_USAGE);
ASSERT(unknownLongFlagMixedTestParser.getFlag('1').value);
ASSERT(unknownLongFlagMixedTestParser.getFlag(std::string("four")).isError);
ASSERT(unknownLongFlagMixedTestParser.getFlag(std::string("four")).errorCode == ErrorCodes::WRONG_USAGE);
ASSERT(unknownLongFlagMixedTestParser.getFlag(std::string("four")).value);
delete[] unknownLongFlagTestParameterList;
std::cout << "Passed unknown flag test." << std::endl; std::cout << "Passed unknown flag test." << std::endl;
// unknown unpositional argument ################################### // unknown unpositional argument ###################################
@ -233,12 +275,12 @@ int main(int argc, char* argv[]) {
std::vector<CLI::Flag> unknownArgumentTestFlags; std::vector<CLI::Flag> unknownArgumentTestFlags;
std::vector<CLI::UnpositionalArgument> unknownArgumentTestUnpositionalArguments; std::vector<CLI::UnpositionalArgument> unknownArgumentTestUnpositionalArguments;
unknownArgumentTestUnpositionalArguments.push_back(CLI::UnpositionalArgument('0', "zero", "zero", "test flag")); unknownArgumentTestUnpositionalArguments.push_back(CLI::UnpositionalArgument('0', "zero", "zero", "test argument"));
unknownArgumentTestUnpositionalArguments.push_back(CLI::UnpositionalArgument('1', "one", "one", "test flag")); unknownArgumentTestUnpositionalArguments.push_back(CLI::UnpositionalArgument('1', "one", "one", "test argument"));
unknownArgumentTestUnpositionalArguments.push_back(CLI::UnpositionalArgument('2', "two", "two", "test flag")); unknownArgumentTestUnpositionalArguments.push_back(CLI::UnpositionalArgument('2', "two", "two", "test argument"));
unknownArgumentTestUnpositionalArguments.push_back(CLI::UnpositionalArgument('3', "three","three","test flag")); unknownArgumentTestUnpositionalArguments.push_back(CLI::UnpositionalArgument('3', "three","three","test argument"));
unknownArgumentTestUnpositionalArguments.push_back(CLI::UnpositionalArgument('4', "four", "four", "test flag")); unknownArgumentTestUnpositionalArguments.push_back(CLI::UnpositionalArgument('4', "four", "four", "test argument"));
unknownArgumentTestUnpositionalArguments.push_back(CLI::UnpositionalArgument('5', "five", "five", "test flag")); unknownArgumentTestUnpositionalArguments.push_back(CLI::UnpositionalArgument('5', "five", "five", "test argument"));
std::vector<CLI::PositionalArgument> unknownArgumentTestPositionalArguments; std::vector<CLI::PositionalArgument> unknownArgumentTestPositionalArguments;
@ -271,7 +313,280 @@ int main(int argc, char* argv[]) {
ASSERT(unknownArgumentMixedTestParser.getUnpositionalArgument(std::string("four")).value == "d"); ASSERT(unknownArgumentMixedTestParser.getUnpositionalArgument(std::string("four")).value == "d");
delete[] unknownArgumentTestParameterList; delete[] unknownArgumentTestParameterList;
std::vector<CLI::Flag> unknownLongArgumentTestFlags;
std::vector<CLI::UnpositionalArgument> unknownLongArgumentTestUnpositionalArguments;
unknownLongArgumentTestUnpositionalArguments.push_back(CLI::UnpositionalArgument('0', "zero", "zero", "test argument"));
unknownLongArgumentTestUnpositionalArguments.push_back(CLI::UnpositionalArgument('1', "one", "one", "test argument"));
unknownLongArgumentTestUnpositionalArguments.push_back(CLI::UnpositionalArgument('2', "two", "two", "test argument"));
unknownLongArgumentTestUnpositionalArguments.push_back(CLI::UnpositionalArgument('3', "three","three","test argument"));
unknownLongArgumentTestUnpositionalArguments.push_back(CLI::UnpositionalArgument('4', "four", "four", "test argument"));
unknownLongArgumentTestUnpositionalArguments.push_back(CLI::UnpositionalArgument('5', "five", "five", "test argument"));
std::vector<CLI::PositionalArgument> unknownLongArgumentTestPositionalArguments;
const char** unknownLongArgumentTestParameterList = new const char*[7];
unknownLongArgumentTestParameterList[0] = "test";
unknownLongArgumentTestParameterList[1] = "--a=123";
unknownLongArgumentTestParameterList[2] = "-1a";
unknownLongArgumentTestParameterList[3] = "-2b";
unknownLongArgumentTestParameterList[4] = "-3c";
unknownLongArgumentTestParameterList[5] = "-4d";
unknownLongArgumentTestParameterList[6] = "-5e";
int unknownLongArgumentStandaloneTestParameterCount = 2;
CLI::ArgumentsParser unknownLongArgumentStandaloneTestParser = CLI::ArgumentsParser(unknownLongArgumentStandaloneTestParameterCount, unknownLongArgumentTestParameterList, unknownLongArgumentTestFlags, unknownLongArgumentTestUnpositionalArguments, unknownLongArgumentTestPositionalArguments);
ASSERT(unknownLongArgumentStandaloneTestParser.getUnpositionalArgument('1').isError);
ASSERT(unknownLongArgumentStandaloneTestParser.getUnpositionalArgument('1').errorCode == ErrorCodes::NOT_PRESENT);
ASSERT(unknownLongArgumentStandaloneTestParser.getUnpositionalArgument('1').value == "");
ASSERT(unknownLongArgumentStandaloneTestParser.getUnpositionalArgument(std::string("four")).isError);
ASSERT(unknownLongArgumentStandaloneTestParser.getUnpositionalArgument(std::string("four")).errorCode == ErrorCodes::NOT_PRESENT);
ASSERT(unknownLongArgumentStandaloneTestParser.getUnpositionalArgument(std::string("four")).value == "");
int unknownLongArgumentMixedTestParameterCount = 7;
CLI::ArgumentsParser unknownLongArgumentMixedTestParser = CLI::ArgumentsParser(unknownLongArgumentMixedTestParameterCount, unknownLongArgumentTestParameterList, unknownLongArgumentTestFlags, unknownLongArgumentTestUnpositionalArguments, unknownLongArgumentTestPositionalArguments);
ASSERT(unknownLongArgumentMixedTestParser.getUnpositionalArgument('1').isError);
ASSERT(unknownLongArgumentMixedTestParser.getUnpositionalArgument('1').errorCode == ErrorCodes::WRONG_USAGE);
ASSERT(unknownLongArgumentMixedTestParser.getUnpositionalArgument('1').value == "a");
ASSERT(unknownLongArgumentMixedTestParser.getUnpositionalArgument(std::string("four")).isError);
ASSERT(unknownLongArgumentMixedTestParser.getUnpositionalArgument(std::string("four")).errorCode == ErrorCodes::WRONG_USAGE);
ASSERT(unknownLongArgumentMixedTestParser.getUnpositionalArgument(std::string("four")).value == "d");
delete[] unknownLongArgumentTestParameterList;
std::cout << "Passed unknown unpositional argument test." << std::endl; std::cout << "Passed unknown unpositional argument test." << std::endl;
// incomplete unpositional argument ###################################
std::vector<CLI::Flag> incompleteArgumentTestFlags;
std::vector<CLI::UnpositionalArgument> incompleteArgumentTestUnpositionalArguments;
incompleteArgumentTestUnpositionalArguments.push_back(CLI::UnpositionalArgument('0', "zero", "zero", "test argument"));
incompleteArgumentTestUnpositionalArguments.push_back(CLI::UnpositionalArgument('1', "one", "one", "test argument"));
incompleteArgumentTestUnpositionalArguments.push_back(CLI::UnpositionalArgument('2', "two", "two", "test argument"));
incompleteArgumentTestUnpositionalArguments.push_back(CLI::UnpositionalArgument('3', "three","three","test argument"));
incompleteArgumentTestUnpositionalArguments.push_back(CLI::UnpositionalArgument('4', "four", "four", "test argument"));
incompleteArgumentTestUnpositionalArguments.push_back(CLI::UnpositionalArgument('5', "five", "five", "test argument"));
std::vector<CLI::PositionalArgument> incompleteArgumentTestPositionalArguments;
const char** incompleteArgumentTestParameterList = new const char*[6];
incompleteArgumentTestParameterList[0] = "test";
incompleteArgumentTestParameterList[1] = "-1";
incompleteArgumentTestParameterList[2] = "-2b";
incompleteArgumentTestParameterList[3] = "-3c";
incompleteArgumentTestParameterList[4] = "-4";
incompleteArgumentTestParameterList[5] = "-5e";
int incompleteArgumentStandaloneTestParameterCount = 2;
CLI::ArgumentsParser incompleteArgumentStandaloneTestParser = CLI::ArgumentsParser(incompleteArgumentStandaloneTestParameterCount, incompleteArgumentTestParameterList, incompleteArgumentTestFlags, incompleteArgumentTestUnpositionalArguments, incompleteArgumentTestPositionalArguments);
ASSERT(incompleteArgumentStandaloneTestParser.getUnpositionalArgument('1').isError);
ASSERT(incompleteArgumentStandaloneTestParser.getUnpositionalArgument('1').errorCode == ErrorCodes::WRONG_USAGE);
ASSERT(incompleteArgumentStandaloneTestParser.getUnpositionalArgument('1').value == "");
ASSERT(incompleteArgumentStandaloneTestParser.getUnpositionalArgument(std::string("four")).isError);
ASSERT(incompleteArgumentStandaloneTestParser.getUnpositionalArgument(std::string("four")).errorCode == ErrorCodes::NOT_PRESENT);
ASSERT(incompleteArgumentStandaloneTestParser.getUnpositionalArgument(std::string("four")).value == "");
int incompleteArgumentMixedTestParameterCount = 6;
CLI::ArgumentsParser incompleteArgumentMixedTestParser = CLI::ArgumentsParser(incompleteArgumentMixedTestParameterCount, incompleteArgumentTestParameterList, incompleteArgumentTestFlags, incompleteArgumentTestUnpositionalArguments, incompleteArgumentTestPositionalArguments);
ASSERT(incompleteArgumentMixedTestParser.getUnpositionalArgument('1').isError);
ASSERT(incompleteArgumentMixedTestParser.getUnpositionalArgument('1').errorCode == ErrorCodes::WRONG_USAGE);
ASSERT(incompleteArgumentMixedTestParser.getUnpositionalArgument('1').value == "");
ASSERT(incompleteArgumentMixedTestParser.getUnpositionalArgument(std::string("four")).isError);
ASSERT(incompleteArgumentMixedTestParser.getUnpositionalArgument(std::string("four")).errorCode == ErrorCodes::WRONG_USAGE);
ASSERT(incompleteArgumentMixedTestParser.getUnpositionalArgument(std::string("four")).value == "");
ASSERT(incompleteArgumentMixedTestParser.getUnpositionalArgument('5').isError);
ASSERT(incompleteArgumentMixedTestParser.getUnpositionalArgument('5').errorCode == ErrorCodes::WRONG_USAGE);
ASSERT(incompleteArgumentMixedTestParser.getUnpositionalArgument('5').value == "e");
delete[] incompleteArgumentTestParameterList;
std::vector<CLI::Flag> incompleteLongArgumentTestFlags;
std::vector<CLI::UnpositionalArgument> incompleteLongArgumentTestUnpositionalArguments;
incompleteLongArgumentTestUnpositionalArguments.push_back(CLI::UnpositionalArgument('0', "zero", "zero", "test argument"));
incompleteLongArgumentTestUnpositionalArguments.push_back(CLI::UnpositionalArgument('1', "one", "one", "test argument"));
incompleteLongArgumentTestUnpositionalArguments.push_back(CLI::UnpositionalArgument('2', "two", "two", "test argument"));
incompleteLongArgumentTestUnpositionalArguments.push_back(CLI::UnpositionalArgument('3', "three","three","test argument"));
incompleteLongArgumentTestUnpositionalArguments.push_back(CLI::UnpositionalArgument('4', "four", "four", "test argument"));
incompleteLongArgumentTestUnpositionalArguments.push_back(CLI::UnpositionalArgument('5', "five", "five", "test argument"));
std::vector<CLI::PositionalArgument> incompleteLongArgumentTestPositionalArguments;
const char** incompleteLongArgumentTestParameterList = new const char*[8];
incompleteLongArgumentTestParameterList[0] = "test";
incompleteLongArgumentTestParameterList[1] = "--one";
incompleteLongArgumentTestParameterList[2] = "--two";
incompleteLongArgumentTestParameterList[3] = "b";
incompleteLongArgumentTestParameterList[4] = "-3c";
incompleteLongArgumentTestParameterList[5] = "positional_arg";
incompleteLongArgumentTestParameterList[6] = "--four";
incompleteLongArgumentTestParameterList[7] = "--five=e";
int incompleteLongArgumentStandaloneTestParameterCount = 2;
CLI::ArgumentsParser incompleteLongArgumentStandaloneTestParser = CLI::ArgumentsParser(incompleteLongArgumentStandaloneTestParameterCount, incompleteLongArgumentTestParameterList, incompleteLongArgumentTestFlags, incompleteLongArgumentTestUnpositionalArguments, incompleteLongArgumentTestPositionalArguments);
ASSERT(incompleteLongArgumentStandaloneTestParser.getUnpositionalArgument('1').isError);
ASSERT(incompleteLongArgumentStandaloneTestParser.getUnpositionalArgument('1').errorCode == ErrorCodes::WRONG_USAGE);
ASSERT(incompleteLongArgumentStandaloneTestParser.getUnpositionalArgument('1').value == "");
ASSERT(incompleteLongArgumentStandaloneTestParser.getUnpositionalArgument(std::string("four")).isError);
ASSERT(incompleteLongArgumentStandaloneTestParser.getUnpositionalArgument(std::string("four")).errorCode == ErrorCodes::NOT_PRESENT);
ASSERT(incompleteLongArgumentStandaloneTestParser.getUnpositionalArgument(std::string("four")).value == "");
int incompleteLongArgumentMixedTestParameterCount = 8;
CLI::ArgumentsParser incompleteLongArgumentMixedTestParser = CLI::ArgumentsParser(incompleteLongArgumentMixedTestParameterCount, incompleteLongArgumentTestParameterList, incompleteLongArgumentTestFlags, incompleteLongArgumentTestUnpositionalArguments, incompleteLongArgumentTestPositionalArguments);
ASSERT(incompleteLongArgumentMixedTestParser.getUnpositionalArgument('1').isError);
ASSERT(incompleteLongArgumentMixedTestParser.getUnpositionalArgument('1').errorCode == ErrorCodes::WRONG_USAGE);
ASSERT(incompleteLongArgumentMixedTestParser.getUnpositionalArgument('1').value == "");
ASSERT(incompleteLongArgumentMixedTestParser.getUnpositionalArgument('2').isError);
ASSERT(incompleteLongArgumentMixedTestParser.getUnpositionalArgument('2').errorCode == ErrorCodes::WRONG_USAGE);
ASSERT(incompleteLongArgumentMixedTestParser.getUnpositionalArgument('2').value == "b");
ASSERT(incompleteLongArgumentMixedTestParser.getUnpositionalArgument(std::string("four")).isError);
ASSERT(incompleteLongArgumentMixedTestParser.getUnpositionalArgument(std::string("four")).errorCode == ErrorCodes::WRONG_USAGE);
ASSERT(incompleteLongArgumentMixedTestParser.getUnpositionalArgument(std::string("four")).value == "");
ASSERT(incompleteLongArgumentMixedTestParser.getUnpositionalArgument('5').isError);
ASSERT(incompleteLongArgumentMixedTestParser.getUnpositionalArgument('5').errorCode == ErrorCodes::WRONG_USAGE);
ASSERT(incompleteLongArgumentMixedTestParser.getUnpositionalArgument('5').value == "e");
delete[] incompleteLongArgumentTestParameterList;
std::cout << "Passed incomplete unpositional argument test." << std::endl;
// too few positional arguments
std::vector<CLI::Flag> tooFewArgumentsTestFlags;
tooFewArgumentsTestFlags.push_back(CLI::Flag('a', "aaaaa", "test flag"));
std::vector<CLI::UnpositionalArgument> tooFewArgumentsTestUnpositionalArguments;
tooFewArgumentsTestUnpositionalArguments.push_back(CLI::UnpositionalArgument('b', "bbbbb", "b", "test argument"));
tooFewArgumentsTestUnpositionalArguments.push_back(CLI::UnpositionalArgument('c', "ccccc", "c", "test argument"));
tooFewArgumentsTestUnpositionalArguments.push_back(CLI::UnpositionalArgument('d', "ddddd", "d", "test argument"));
std::vector<CLI::PositionalArgument> tooFewArgumentsTestPositionalArguments;
tooFewArgumentsTestPositionalArguments.push_back(CLI::PositionalArgument("argument0", "test argument"));
tooFewArgumentsTestPositionalArguments.push_back(CLI::PositionalArgument("argument1", "test argument"));
tooFewArgumentsTestPositionalArguments.push_back(CLI::PositionalArgument("argument2", "test argument"));
tooFewArgumentsTestPositionalArguments.push_back(CLI::PositionalArgument("argument3", "test argument"));
const char** tooFewArgumentsTestParameterList = new const char*[10];
tooFewArgumentsTestParameterList[0] = "test";
tooFewArgumentsTestParameterList[1] = "positional_arg_0";
tooFewArgumentsTestParameterList[2] = "-a";//
tooFewArgumentsTestParameterList[3] = "-b";
tooFewArgumentsTestParameterList[4] = "1";
tooFewArgumentsTestParameterList[5] = "-c5";
tooFewArgumentsTestParameterList[6] = "positional_arg_1";
tooFewArgumentsTestParameterList[7] = "--ddddd";
tooFewArgumentsTestParameterList[8] = "ddd";
tooFewArgumentsTestParameterList[9] = "positional_arg_2";
int tooFewArgumentsStandaloneTestParameterCount = 2;
CLI::ArgumentsParser tooFewArgumentsStandaloneTestParser = CLI::ArgumentsParser(tooFewArgumentsStandaloneTestParameterCount, tooFewArgumentsTestParameterList, tooFewArgumentsTestFlags, tooFewArgumentsTestUnpositionalArguments, tooFewArgumentsTestPositionalArguments);
ASSERT(tooFewArgumentsStandaloneTestParser.getPositionalArgument(0).isError);
ASSERT(tooFewArgumentsStandaloneTestParser.getPositionalArgument(0).errorCode == ErrorCodes::WRONG_USAGE);
ASSERT(tooFewArgumentsStandaloneTestParser.getPositionalArgument(0).value == "positional_arg_0");
ASSERT(tooFewArgumentsStandaloneTestParser.getPositionalArgument(1).isError);
ASSERT(tooFewArgumentsStandaloneTestParser.getPositionalArgument(1).errorCode == ErrorCodes::NOT_PRESENT);
ASSERT(tooFewArgumentsStandaloneTestParser.getPositionalArgument(1).value == "");
ASSERT(tooFewArgumentsStandaloneTestParser.getUnpositionalArgument('b').isError);
ASSERT(tooFewArgumentsStandaloneTestParser.getUnpositionalArgument('b').errorCode == ErrorCodes::NOT_PRESENT);
ASSERT(tooFewArgumentsStandaloneTestParser.getUnpositionalArgument('b').value == "");
ASSERT(tooFewArgumentsStandaloneTestParser.getUnpositionalArgument('c').isError);
ASSERT(tooFewArgumentsStandaloneTestParser.getUnpositionalArgument('c').errorCode == ErrorCodes::NOT_PRESENT);
ASSERT(tooFewArgumentsStandaloneTestParser.getUnpositionalArgument('c').value == "");
ASSERT(tooFewArgumentsStandaloneTestParser.getUnpositionalArgument('d').isError);
ASSERT(tooFewArgumentsStandaloneTestParser.getUnpositionalArgument('d').errorCode == ErrorCodes::NOT_PRESENT);
ASSERT(tooFewArgumentsStandaloneTestParser.getUnpositionalArgument('d').value == "");
int tooFewArgumentsMixedTestParameterCount = 10;
CLI::ArgumentsParser tooFewArgumentsMixedTestParser = CLI::ArgumentsParser(tooFewArgumentsMixedTestParameterCount, tooFewArgumentsTestParameterList, tooFewArgumentsTestFlags, tooFewArgumentsTestUnpositionalArguments, tooFewArgumentsTestPositionalArguments);
ASSERT(tooFewArgumentsMixedTestParser.getPositionalArgument(0).isError);
ASSERT(tooFewArgumentsMixedTestParser.getPositionalArgument(0).errorCode == ErrorCodes::WRONG_USAGE);
ASSERT(tooFewArgumentsMixedTestParser.getPositionalArgument(0).value == "positional_arg_0");
ASSERT(tooFewArgumentsMixedTestParser.getPositionalArgument(1).isError);
ASSERT(tooFewArgumentsMixedTestParser.getPositionalArgument(1).errorCode == ErrorCodes::WRONG_USAGE);
ASSERT(tooFewArgumentsMixedTestParser.getPositionalArgument(1).value == "positional_arg_1");
ASSERT(tooFewArgumentsMixedTestParser.getPositionalArgument(2).isError);
ASSERT(tooFewArgumentsMixedTestParser.getPositionalArgument(2).errorCode == ErrorCodes::WRONG_USAGE);
ASSERT(tooFewArgumentsMixedTestParser.getPositionalArgument(2).value == "positional_arg_2");
ASSERT(tooFewArgumentsMixedTestParser.getPositionalArgument(3).isError);
ASSERT(tooFewArgumentsMixedTestParser.getPositionalArgument(3).errorCode == ErrorCodes::NOT_PRESENT);
ASSERT(tooFewArgumentsMixedTestParser.getPositionalArgument(3).value == "");
ASSERT(tooFewArgumentsMixedTestParser.getUnpositionalArgument('b').isError);
ASSERT(tooFewArgumentsMixedTestParser.getUnpositionalArgument('b').errorCode == ErrorCodes::WRONG_USAGE);
ASSERT(tooFewArgumentsMixedTestParser.getUnpositionalArgument('b').value == "1");
ASSERT(tooFewArgumentsMixedTestParser.getUnpositionalArgument('c').isError);
ASSERT(tooFewArgumentsMixedTestParser.getUnpositionalArgument('c').errorCode == ErrorCodes::WRONG_USAGE);
ASSERT(tooFewArgumentsMixedTestParser.getUnpositionalArgument('c').value == "5");
ASSERT(tooFewArgumentsMixedTestParser.getUnpositionalArgument('d').isError);
ASSERT(tooFewArgumentsMixedTestParser.getUnpositionalArgument('d').errorCode == ErrorCodes::WRONG_USAGE);
ASSERT(tooFewArgumentsMixedTestParser.getUnpositionalArgument('d').value == "ddd");
delete[] tooFewArgumentsTestParameterList;
std::cout << "Passed too few positional arguments test." << std::endl;
// too many positional arguments
std::vector<CLI::Flag> tooManyArgumentsTestFlags;
tooManyArgumentsTestFlags.push_back(CLI::Flag('a', "aaaaa", "test flag"));
std::vector<CLI::UnpositionalArgument> tooManyArgumentsTestUnpositionalArguments;
tooManyArgumentsTestUnpositionalArguments.push_back(CLI::UnpositionalArgument('b', "bbbbb", "b", "test argument"));
tooManyArgumentsTestUnpositionalArguments.push_back(CLI::UnpositionalArgument('c', "ccccc", "c", "test argument"));
tooManyArgumentsTestUnpositionalArguments.push_back(CLI::UnpositionalArgument('d', "ddddd", "d", "test argument"));
std::vector<CLI::PositionalArgument> tooManyArgumentsTestPositionalArguments;
tooManyArgumentsTestPositionalArguments.push_back(CLI::PositionalArgument("argument0", "test argument"));
const char** tooManyArgumentsTestParameterList = new const char*[10];
tooManyArgumentsTestParameterList[0] = "test";
tooManyArgumentsTestParameterList[1] = "positional_arg_0";
tooManyArgumentsTestParameterList[2] = "positional_arg_1";
tooManyArgumentsTestParameterList[3] = "-a";//
tooManyArgumentsTestParameterList[4] = "-b";
tooManyArgumentsTestParameterList[5] = "1";
tooManyArgumentsTestParameterList[6] = "-c5";
tooManyArgumentsTestParameterList[7] = "--ddddd";
tooManyArgumentsTestParameterList[8] = "ddd";
tooManyArgumentsTestParameterList[9] = "positional_arg_2";
int tooManyArgumentsStandaloneTestParameterCount = 3;
CLI::ArgumentsParser tooManyArgumentsStandaloneTestParser = CLI::ArgumentsParser(tooManyArgumentsStandaloneTestParameterCount, tooManyArgumentsTestParameterList, tooManyArgumentsTestFlags, tooManyArgumentsTestUnpositionalArguments, tooManyArgumentsTestPositionalArguments);
ASSERT(tooManyArgumentsStandaloneTestParser.getPositionalArgument(0).isError);
ASSERT(tooManyArgumentsStandaloneTestParser.getPositionalArgument(0).errorCode == ErrorCodes::WRONG_USAGE);
ASSERT(tooManyArgumentsStandaloneTestParser.getPositionalArgument(0).value == "positional_arg_0");
ASSERT(tooManyArgumentsStandaloneTestParser.getUnpositionalArgument('b').isError);
ASSERT(tooManyArgumentsStandaloneTestParser.getUnpositionalArgument('b').errorCode == ErrorCodes::NOT_PRESENT);
ASSERT(tooManyArgumentsStandaloneTestParser.getUnpositionalArgument('b').value == "");
ASSERT(tooManyArgumentsStandaloneTestParser.getUnpositionalArgument('c').isError);
ASSERT(tooManyArgumentsStandaloneTestParser.getUnpositionalArgument('c').errorCode == ErrorCodes::NOT_PRESENT);
ASSERT(tooManyArgumentsStandaloneTestParser.getUnpositionalArgument('c').value == "");
ASSERT(tooManyArgumentsStandaloneTestParser.getUnpositionalArgument('d').isError);
ASSERT(tooManyArgumentsStandaloneTestParser.getUnpositionalArgument('d').errorCode == ErrorCodes::NOT_PRESENT);
ASSERT(tooManyArgumentsStandaloneTestParser.getUnpositionalArgument('d').value == "");
int tooManyArgumentsMixedTestParameterCount = 10;
CLI::ArgumentsParser tooManyArgumentsMixedTestParser = CLI::ArgumentsParser(tooManyArgumentsMixedTestParameterCount, tooManyArgumentsTestParameterList, tooManyArgumentsTestFlags, tooManyArgumentsTestUnpositionalArguments, tooManyArgumentsTestPositionalArguments);
ASSERT(tooManyArgumentsMixedTestParser.getPositionalArgument(0).isError);
ASSERT(tooManyArgumentsMixedTestParser.getPositionalArgument(0).errorCode == ErrorCodes::WRONG_USAGE);
ASSERT(tooManyArgumentsMixedTestParser.getPositionalArgument(0).value == "positional_arg_0");
ASSERT(tooManyArgumentsMixedTestParser.getUnpositionalArgument('b').isError);
ASSERT(tooManyArgumentsMixedTestParser.getUnpositionalArgument('b').errorCode == ErrorCodes::WRONG_USAGE);
ASSERT(tooManyArgumentsMixedTestParser.getUnpositionalArgument('b').value == "1");
ASSERT(tooManyArgumentsMixedTestParser.getUnpositionalArgument('c').isError);
ASSERT(tooManyArgumentsMixedTestParser.getUnpositionalArgument('c').errorCode == ErrorCodes::WRONG_USAGE);
ASSERT(tooManyArgumentsMixedTestParser.getUnpositionalArgument('c').value == "5");
ASSERT(tooManyArgumentsMixedTestParser.getUnpositionalArgument('d').isError);
ASSERT(tooManyArgumentsMixedTestParser.getUnpositionalArgument('d').errorCode == ErrorCodes::WRONG_USAGE);
ASSERT(tooManyArgumentsMixedTestParser.getUnpositionalArgument('d').value == "ddd");
delete[] tooManyArgumentsTestParameterList;
std::cout << "Passed too many positional arguments test." << std::endl;
return 0; return 0;
} }