test/cli_argument_parser: rename everything to have nice long descriptive names
This is in preparation for adding more tests that require the same kinds of components.BodgeMaster-unfinished
parent
efa4fa560e
commit
8835b90398
|
@ -33,127 +33,127 @@ int main(int argc, char* argv[]) {
|
||||||
// simulated command line:
|
// simulated command line:
|
||||||
// test -0 -ab -12345 --long-flag -cconcatenated -d separate-value -efdouble-concatenated "positional argument 0" -gh concatenated-separate-value --long-argument-with-value-included="included value" --long-argument-with-value-separated "separate value" "positional argument 1" "positional argument 2"
|
// test -0 -ab -12345 --long-flag -cconcatenated -d separate-value -efdouble-concatenated "positional argument 0" -gh concatenated-separate-value --long-argument-with-value-included="included value" --long-argument-with-value-separated "separate value" "positional argument 1" "positional argument 2"
|
||||||
|
|
||||||
std::vector<CLI::Flag> flags;
|
std::vector<CLI::Flag> validTestFlags;
|
||||||
flags.push_back(CLI::Flag('0', "00000", "a short flag on its own"));
|
validTestFlags.push_back(CLI::Flag('0', "00000", "a short flag on its own"));
|
||||||
flags.push_back(CLI::Flag('a', "aaaaa", "concatenated short flags"));
|
validTestFlags.push_back(CLI::Flag('a', "aaaaa", "concatenated short flags"));
|
||||||
flags.push_back(CLI::Flag('b', "bbbbb", "concatenated short flags"));
|
validTestFlags.push_back(CLI::Flag('b', "bbbbb", "concatenated short flags"));
|
||||||
flags.push_back(CLI::Flag('1', "11111", "more than two concatenated short flags"));
|
validTestFlags.push_back(CLI::Flag('1', "11111", "more than two concatenated short flags"));
|
||||||
flags.push_back(CLI::Flag('2', "22222", "more than two concatenated short flags"));
|
validTestFlags.push_back(CLI::Flag('2', "22222", "more than two concatenated short flags"));
|
||||||
flags.push_back(CLI::Flag('3', "33333", "more than two concatenated short flags"));
|
validTestFlags.push_back(CLI::Flag('3', "33333", "more than two concatenated short flags"));
|
||||||
flags.push_back(CLI::Flag('4', "44444", "more than two concatenated short flags"));
|
validTestFlags.push_back(CLI::Flag('4', "44444", "more than two concatenated short flags"));
|
||||||
flags.push_back(CLI::Flag('5', "55555", "more than two concatenated short flags"));
|
validTestFlags.push_back(CLI::Flag('5', "55555", "more than two concatenated short flags"));
|
||||||
flags.push_back(CLI::Flag('l', "long-flag", "long flags"));
|
validTestFlags.push_back(CLI::Flag('l', "long-flag", "long flags"));
|
||||||
flags.push_back(CLI::Flag('e', "eeeee", "short flags concatenated with an argument that is concatenated with its value"));
|
validTestFlags.push_back(CLI::Flag('e', "eeeee", "short flags concatenated with an argument that is concatenated with its value"));
|
||||||
flags.push_back(CLI::Flag('g', "ggggg", "short flags concatenated with an argument that has a separate value"));
|
validTestFlags.push_back(CLI::Flag('g', "ggggg", "short flags concatenated with an argument that has a separate value"));
|
||||||
flags.push_back(CLI::Flag('6', "66666", "unused flag"));
|
validTestFlags.push_back(CLI::Flag('6', "66666", "unused flag"));
|
||||||
|
|
||||||
std::vector<CLI::UnpositionalArgument> unpositionalArguments;
|
std::vector<CLI::UnpositionalArgument> validTestUnpositionalArguments;
|
||||||
unpositionalArguments.push_back(CLI::UnpositionalArgument('c', "ccccc", "VALUE", "short argument concatenated with its value"));
|
validTestUnpositionalArguments.push_back(CLI::UnpositionalArgument('c', "ccccc", "VALUE", "short argument concatenated with its value"));
|
||||||
unpositionalArguments.push_back(CLI::UnpositionalArgument('d', "ddddd", " VALUE", "short argument with separate value"));
|
validTestUnpositionalArguments.push_back(CLI::UnpositionalArgument('d', "ddddd", " VALUE", "short argument with separate value"));
|
||||||
unpositionalArguments.push_back(CLI::UnpositionalArgument('f', "fffff", "VALUE", "short argument concatenated with a flag and its value"));
|
validTestUnpositionalArguments.push_back(CLI::UnpositionalArgument('f', "fffff", "VALUE", "short argument concatenated with a flag and its value"));
|
||||||
unpositionalArguments.push_back(CLI::UnpositionalArgument('h', "hhhhh", " VALUE", "short argument concatenated with a flag with separate value"));
|
validTestUnpositionalArguments.push_back(CLI::UnpositionalArgument('h', "hhhhh", " VALUE", "short argument concatenated with a flag with separate value"));
|
||||||
unpositionalArguments.push_back(CLI::UnpositionalArgument('x', "long-argument-with-value-included", "VALUE", "long argument with its value included using ="));
|
validTestUnpositionalArguments.push_back(CLI::UnpositionalArgument('x', "long-argument-with-value-included", "VALUE", "long argument with its value included using ="));
|
||||||
unpositionalArguments.push_back(CLI::UnpositionalArgument('y', "long-argument-with-value-separated", " VALUE", "long argument with separate value"));
|
validTestUnpositionalArguments.push_back(CLI::UnpositionalArgument('y', "long-argument-with-value-separated", " VALUE", "long argument with separate value"));
|
||||||
unpositionalArguments.push_back(CLI::UnpositionalArgument('z', "zzzzz", "NOPE", "unused argument"));
|
validTestUnpositionalArguments.push_back(CLI::UnpositionalArgument('z', "zzzzz", "NOPE", "unused argument"));
|
||||||
|
|
||||||
std::vector<CLI::PositionalArgument> positionalArguments;
|
std::vector<CLI::PositionalArgument> validTestPositionalArguments;
|
||||||
positionalArguments.push_back(CLI::PositionalArgument("argument0", "positional argument between optional parameters"));
|
validTestPositionalArguments.push_back(CLI::PositionalArgument("argument0", "positional argument between optional parameters"));
|
||||||
positionalArguments.push_back(CLI::PositionalArgument("argument1", "positional argument"));
|
validTestPositionalArguments.push_back(CLI::PositionalArgument("argument1", "positional argument"));
|
||||||
positionalArguments.push_back(CLI::PositionalArgument("argument2", "positional argument"));
|
validTestPositionalArguments.push_back(CLI::PositionalArgument("argument2", "positional argument"));
|
||||||
|
|
||||||
const char** validParameterList = new const char*[17];
|
const char** validTestParameterList = new const char*[17];
|
||||||
validParameterList[ 0] = "test";
|
validTestParameterList[ 0] = "test";
|
||||||
validParameterList[ 1] = "-0";
|
validTestParameterList[ 1] = "-0";
|
||||||
validParameterList[ 2] = "-ab";
|
validTestParameterList[ 2] = "-ab";
|
||||||
validParameterList[ 3] = "-12345";
|
validTestParameterList[ 3] = "-12345";
|
||||||
validParameterList[ 4] = "--long-flag";
|
validTestParameterList[ 4] = "--long-flag";
|
||||||
validParameterList[ 5] = "-cconcatenated";
|
validTestParameterList[ 5] = "-cconcatenated";
|
||||||
validParameterList[ 6] = "-d";
|
validTestParameterList[ 6] = "-d";
|
||||||
validParameterList[ 7] = "separate-value";
|
validTestParameterList[ 7] = "separate-value";
|
||||||
validParameterList[ 8] = "-efdouble-concatenated";
|
validTestParameterList[ 8] = "-efdouble-concatenated";
|
||||||
validParameterList[ 9] = "positional argument 0";
|
validTestParameterList[ 9] = "positional argument 0";
|
||||||
validParameterList[10] = "-gh";
|
validTestParameterList[10] = "-gh";
|
||||||
validParameterList[11] = "concatenated-separate-value";
|
validTestParameterList[11] = "concatenated-separate-value";
|
||||||
validParameterList[12] = "--long-argument-with-value-included=included value";
|
validTestParameterList[12] = "--long-argument-with-value-included=included value";
|
||||||
validParameterList[13] = "--long-argument-with-value-separated";
|
validTestParameterList[13] = "--long-argument-with-value-separated";
|
||||||
validParameterList[14] = "separate value";
|
validTestParameterList[14] = "separate value";
|
||||||
validParameterList[15] = "positional argument 1";
|
validTestParameterList[15] = "positional argument 1";
|
||||||
validParameterList[16] = "positional argument 2";
|
validTestParameterList[16] = "positional argument 2";
|
||||||
int validParameterCount = 17;
|
int validTestParameterCount = 17;
|
||||||
|
|
||||||
CLI::ArgumentsParser parser = CLI::ArgumentsParser(validParameterCount, validParameterList, flags, unpositionalArguments, positionalArguments);
|
CLI::ArgumentsParser validTestParameterParser = CLI::ArgumentsParser(validTestParameterCount, validTestParameterList, validTestFlags, validTestUnpositionalArguments, validTestPositionalArguments);
|
||||||
|
|
||||||
ASSERT(!parser.wrongUsage);
|
ASSERT(!validTestParameterParser.wrongUsage);
|
||||||
ASSERT(parser.programName == std::string("test"));
|
ASSERT(validTestParameterParser.programName == std::string("test"));
|
||||||
ASSERT(!parser.getFlag('0').isError);
|
ASSERT(!validTestParameterParser.getFlag('0').isError);
|
||||||
ASSERT(parser.getFlag('0').value);
|
ASSERT(validTestParameterParser.getFlag('0').value);
|
||||||
ASSERT(parser.getFlag(std::string("00000")).value);
|
ASSERT(validTestParameterParser.getFlag(std::string("00000")).value);
|
||||||
ASSERT(!parser.getFlag('a').isError);
|
ASSERT(!validTestParameterParser.getFlag('a').isError);
|
||||||
ASSERT(parser.getFlag('a').value);
|
ASSERT(validTestParameterParser.getFlag('a').value);
|
||||||
ASSERT(parser.getFlag(std::string("aaaaa")).value);
|
ASSERT(validTestParameterParser.getFlag(std::string("aaaaa")).value);
|
||||||
ASSERT(!parser.getFlag('b').isError);
|
ASSERT(!validTestParameterParser.getFlag('b').isError);
|
||||||
ASSERT(parser.getFlag('b').value);
|
ASSERT(validTestParameterParser.getFlag('b').value);
|
||||||
ASSERT(parser.getFlag(std::string("bbbbb")).value);
|
ASSERT(validTestParameterParser.getFlag(std::string("bbbbb")).value);
|
||||||
ASSERT(!parser.getFlag('1').isError);
|
ASSERT(!validTestParameterParser.getFlag('1').isError);
|
||||||
ASSERT(parser.getFlag('1').value);
|
ASSERT(validTestParameterParser.getFlag('1').value);
|
||||||
ASSERT(parser.getFlag(std::string("11111")).value);
|
ASSERT(validTestParameterParser.getFlag(std::string("11111")).value);
|
||||||
ASSERT(!parser.getFlag('2').isError);
|
ASSERT(!validTestParameterParser.getFlag('2').isError);
|
||||||
ASSERT(parser.getFlag('2').value);
|
ASSERT(validTestParameterParser.getFlag('2').value);
|
||||||
ASSERT(parser.getFlag(std::string("22222")).value);
|
ASSERT(validTestParameterParser.getFlag(std::string("22222")).value);
|
||||||
ASSERT(!parser.getFlag('3').isError);
|
ASSERT(!validTestParameterParser.getFlag('3').isError);
|
||||||
ASSERT(parser.getFlag('3').value);
|
ASSERT(validTestParameterParser.getFlag('3').value);
|
||||||
ASSERT(parser.getFlag(std::string("33333")).value);
|
ASSERT(validTestParameterParser.getFlag(std::string("33333")).value);
|
||||||
ASSERT(!parser.getFlag('4').isError);
|
ASSERT(!validTestParameterParser.getFlag('4').isError);
|
||||||
ASSERT(parser.getFlag('4').value);
|
ASSERT(validTestParameterParser.getFlag('4').value);
|
||||||
ASSERT(parser.getFlag(std::string("44444")).value);
|
ASSERT(validTestParameterParser.getFlag(std::string("44444")).value);
|
||||||
ASSERT(!parser.getFlag('5').isError);
|
ASSERT(!validTestParameterParser.getFlag('5').isError);
|
||||||
ASSERT(parser.getFlag('5').value);
|
ASSERT(validTestParameterParser.getFlag('5').value);
|
||||||
ASSERT(parser.getFlag(std::string("55555")).value);
|
ASSERT(validTestParameterParser.getFlag(std::string("55555")).value);
|
||||||
ASSERT(!parser.getFlag(std::string("long-flag")).isError);
|
ASSERT(!validTestParameterParser.getFlag(std::string("long-flag")).isError);
|
||||||
ASSERT(parser.getFlag('l').value);
|
ASSERT(validTestParameterParser.getFlag('l').value);
|
||||||
ASSERT(parser.getFlag(std::string("long-flag")).value);
|
ASSERT(validTestParameterParser.getFlag(std::string("long-flag")).value);
|
||||||
ASSERT(!parser.getFlag('6').isError);
|
ASSERT(!validTestParameterParser.getFlag('6').isError);
|
||||||
ASSERT(!parser.getFlag('6').value);
|
ASSERT(!validTestParameterParser.getFlag('6').value);
|
||||||
ASSERT(!parser.getFlag(std::string("66666")).value);
|
ASSERT(!validTestParameterParser.getFlag(std::string("66666")).value);
|
||||||
ASSERT(!parser.getUnpositionalArgument('c').isError);
|
ASSERT(!validTestParameterParser.getUnpositionalArgument('c').isError);
|
||||||
ASSERT(parser.getUnpositionalArgument('c').value==std::string("concatenated"));
|
ASSERT(validTestParameterParser.getUnpositionalArgument('c').value==std::string("concatenated"));
|
||||||
ASSERT(parser.getUnpositionalArgument(std::string("ccccc")).value==std::string("concatenated"));
|
ASSERT(validTestParameterParser.getUnpositionalArgument(std::string("ccccc")).value==std::string("concatenated"));
|
||||||
ASSERT(!parser.getUnpositionalArgument('d').isError);
|
ASSERT(!validTestParameterParser.getUnpositionalArgument('d').isError);
|
||||||
ASSERT(parser.getUnpositionalArgument('d').value==std::string("separate-value"));
|
ASSERT(validTestParameterParser.getUnpositionalArgument('d').value==std::string("separate-value"));
|
||||||
ASSERT(parser.getUnpositionalArgument(std::string("ddddd")).value==std::string("separate-value"));
|
ASSERT(validTestParameterParser.getUnpositionalArgument(std::string("ddddd")).value==std::string("separate-value"));
|
||||||
ASSERT(!parser.getFlag('e').isError);
|
ASSERT(!validTestParameterParser.getFlag('e').isError);
|
||||||
ASSERT(parser.getFlag('e').value);
|
ASSERT(validTestParameterParser.getFlag('e').value);
|
||||||
ASSERT(parser.getFlag(std::string("eeeee")).value);
|
ASSERT(validTestParameterParser.getFlag(std::string("eeeee")).value);
|
||||||
ASSERT(!parser.getUnpositionalArgument('f').isError);
|
ASSERT(!validTestParameterParser.getUnpositionalArgument('f').isError);
|
||||||
ASSERT(parser.getUnpositionalArgument('f').value==std::string("double-concatenated"));
|
ASSERT(validTestParameterParser.getUnpositionalArgument('f').value==std::string("double-concatenated"));
|
||||||
ASSERT(parser.getUnpositionalArgument(std::string("fffff")).value==std::string("double-concatenated"));
|
ASSERT(validTestParameterParser.getUnpositionalArgument(std::string("fffff")).value==std::string("double-concatenated"));
|
||||||
ASSERT(!parser.getPositionalArgument(0).isError);
|
ASSERT(!validTestParameterParser.getPositionalArgument(0).isError);
|
||||||
ASSERT(parser.getPositionalArgument(0).value=="positional argument 0");
|
ASSERT(validTestParameterParser.getPositionalArgument(0).value=="positional argument 0");
|
||||||
ASSERT(!parser.getFlag('g').isError);
|
ASSERT(!validTestParameterParser.getFlag('g').isError);
|
||||||
ASSERT(parser.getFlag('g').value);
|
ASSERT(validTestParameterParser.getFlag('g').value);
|
||||||
ASSERT(parser.getFlag(std::string("ggggg")).value);
|
ASSERT(validTestParameterParser.getFlag(std::string("ggggg")).value);
|
||||||
ASSERT(!parser.getUnpositionalArgument('h').isError);
|
ASSERT(!validTestParameterParser.getUnpositionalArgument('h').isError);
|
||||||
ASSERT(parser.getUnpositionalArgument('h').value==std::string("concatenated-separate-value"));
|
ASSERT(validTestParameterParser.getUnpositionalArgument('h').value==std::string("concatenated-separate-value"));
|
||||||
ASSERT(parser.getUnpositionalArgument(std::string("hhhhh")).value==std::string("concatenated-separate-value"));
|
ASSERT(validTestParameterParser.getUnpositionalArgument(std::string("hhhhh")).value==std::string("concatenated-separate-value"));
|
||||||
ASSERT(!parser.getUnpositionalArgument('x').isError);
|
ASSERT(!validTestParameterParser.getUnpositionalArgument('x').isError);
|
||||||
ASSERT(parser.getUnpositionalArgument('x').value==std::string("included value"));
|
ASSERT(validTestParameterParser.getUnpositionalArgument('x').value==std::string("included value"));
|
||||||
ASSERT(parser.getUnpositionalArgument(std::string("long-argument-with-value-included")).value==std::string("included value"));
|
ASSERT(validTestParameterParser.getUnpositionalArgument(std::string("long-argument-with-value-included")).value==std::string("included value"));
|
||||||
ASSERT(!parser.getUnpositionalArgument('y').isError);
|
ASSERT(!validTestParameterParser.getUnpositionalArgument('y').isError);
|
||||||
ASSERT(parser.getUnpositionalArgument('y').value==std::string("separate value"));
|
ASSERT(validTestParameterParser.getUnpositionalArgument('y').value==std::string("separate value"));
|
||||||
ASSERT(parser.getUnpositionalArgument(std::string("long-argument-with-value-separated")).value==std::string("separate value"));
|
ASSERT(validTestParameterParser.getUnpositionalArgument(std::string("long-argument-with-value-separated")).value==std::string("separate value"));
|
||||||
ASSERT(!parser.getPositionalArgument(1).isError);
|
ASSERT(!validTestParameterParser.getPositionalArgument(1).isError);
|
||||||
ASSERT(parser.getPositionalArgument(1).value=="positional argument 1");
|
ASSERT(validTestParameterParser.getPositionalArgument(1).value=="positional argument 1");
|
||||||
ASSERT(!parser.getPositionalArgument(2).isError);
|
ASSERT(!validTestParameterParser.getPositionalArgument(2).isError);
|
||||||
ASSERT(parser.getPositionalArgument(2).value=="positional argument 2");
|
ASSERT(validTestParameterParser.getPositionalArgument(2).value=="positional argument 2");
|
||||||
ASSERT(!parser.getUnpositionalArgument('z').isError);
|
ASSERT(!validTestParameterParser.getUnpositionalArgument('z').isError);
|
||||||
ASSERT(parser.getUnpositionalArgument('z').errorCode == ErrorCodes::NOT_PRESENT);
|
ASSERT(validTestParameterParser.getUnpositionalArgument('z').errorCode == ErrorCodes::NOT_PRESENT);
|
||||||
ASSERT(parser.getUnpositionalArgument('z').value == std::string(""));
|
ASSERT(validTestParameterParser.getUnpositionalArgument('z').value == std::string(""));
|
||||||
|
|
||||||
|
delete[] validTestParameterList;
|
||||||
std::cout << "Passed valid input test." << std::endl;
|
std::cout << "Passed valid input test." << std::endl;
|
||||||
|
|
||||||
//TODO add tests for invalid input
|
//TODO add tests for invalid input
|
||||||
std::cerr << "TODO: invalid input tests" << std::endl;
|
std::cerr << "TODO: invalid input tests" << std::endl;
|
||||||
|
|
||||||
delete[] validParameterList;
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue