Compare commits
No commits in common. "6baff11ebdcdfd3663bcea4da7c51b01f18eaf35" and "7d7ce2ba6b204be353d4ead4e50cde78f81705df" have entirely different histories.
6baff11ebd
...
7d7ce2ba6b
|
@ -144,7 +144,7 @@ namespace CLI {
|
|||
argumentWaitingForValue = argumentsByShortName[argument[j]];
|
||||
if (i+1 == argc) {
|
||||
this->wrongUsage = true;
|
||||
this->wrongUsageMessages.push_back(std::string("Argument expects value but has none: ")+this->argumentsByShortName[argument[j]]->longName);
|
||||
this->wrongUsageMessages.push_back(std::string("Argument expects value but has none: ")+argument.substr(j, 1));
|
||||
}
|
||||
} else {
|
||||
//assume the rest of the argv is a concatenated argument value
|
||||
|
@ -171,7 +171,7 @@ namespace CLI {
|
|||
this->positionalArguments.at(positionalArgumentCounter).value = argument;
|
||||
} else {
|
||||
this->wrongUsage = true;
|
||||
this->wrongUsageMessages.push_back(std::string("Too many positional arguments! Unexpected encounter of: ")+argument);
|
||||
this->wrongUsageMessages.push_back(std::string("Too many positional arguments. Unexpected encounter of: ")+argument);
|
||||
}
|
||||
positionalArgumentCounter++;
|
||||
} else {
|
||||
|
|
|
@ -148,7 +148,6 @@ int main(int argc, char* argv[]) {
|
|||
ASSERT(!validTestParameterParser.getUnpositionalArgument('z').isError);
|
||||
ASSERT(validTestParameterParser.getUnpositionalArgument('z').errorCode == ErrorCodes::NOT_PRESENT);
|
||||
ASSERT(validTestParameterParser.getUnpositionalArgument('z').value == std::string(""));
|
||||
ASSERT(validTestParameterParser.wrongUsageMessages.size() == 0);
|
||||
|
||||
delete[] validTestParameterList;
|
||||
std::cout << "Passed valid input test." << std::endl;
|
||||
|
@ -171,7 +170,6 @@ int main(int argc, char* argv[]) {
|
|||
CLI::ArgumentsParser validEmptyTestParameterParser = CLI::ArgumentsParser(emptyTestParameterCount, emptyTestParameterList, emptyTestFlags, emptyTestUnpositionalArguments, emptyTestPositionalArguments);
|
||||
ASSERT(!validEmptyTestParameterParser.wrongUsage);
|
||||
ASSERT(validEmptyTestParameterParser.programName == std::string("test"));
|
||||
ASSERT(validEmptyTestParameterParser.wrongUsageMessages.size() == 0);
|
||||
|
||||
//invalid
|
||||
emptyTestPositionalArguments.push_back(CLI::PositionalArgument("argument", "positional argument"));
|
||||
|
@ -181,8 +179,6 @@ int main(int argc, char* argv[]) {
|
|||
ASSERT(invalidEmptyTestParameterParser.programName == std::string("test"));
|
||||
ASSERT(invalidEmptyTestParameterParser.getPositionalArgument(0).isError);
|
||||
ASSERT(invalidEmptyTestParameterParser.getPositionalArgument(0).errorCode == ErrorCodes::NOT_PRESENT);
|
||||
ASSERT(invalidEmptyTestParameterParser.wrongUsageMessages.size() == 1);
|
||||
ASSERT(invalidEmptyTestParameterParser.wrongUsageMessages.at(0) == "Too few positional arguments! Missing: argument");
|
||||
|
||||
delete[] emptyTestParameterList;
|
||||
std::cout << "Passed empty input test." << std::endl;
|
||||
|
@ -218,8 +214,6 @@ int main(int argc, char* argv[]) {
|
|||
ASSERT(unknownFlagStandaloneTestParser.getFlag(std::string("four")).isError);
|
||||
ASSERT(unknownFlagStandaloneTestParser.getFlag(std::string("four")).errorCode == ErrorCodes::NOT_PRESENT);
|
||||
ASSERT(!unknownFlagStandaloneTestParser.getFlag(std::string("four")).value);
|
||||
ASSERT(unknownFlagStandaloneTestParser.wrongUsageMessages.size() == 1);
|
||||
ASSERT(unknownFlagStandaloneTestParser.wrongUsageMessages.at(0) == "Unknown argument or flag(s): a");
|
||||
|
||||
int unknownFlagMixedTestParameterCount = 7;
|
||||
|
||||
|
@ -230,8 +224,6 @@ int main(int argc, char* argv[]) {
|
|||
ASSERT(unknownFlagMixedTestParser.getFlag(std::string("four")).isError);
|
||||
ASSERT(unknownFlagMixedTestParser.getFlag(std::string("four")).errorCode == ErrorCodes::WRONG_USAGE);
|
||||
ASSERT(unknownFlagMixedTestParser.getFlag(std::string("four")).value);
|
||||
ASSERT(unknownFlagMixedTestParser.wrongUsageMessages.size() == 1);
|
||||
ASSERT(unknownFlagMixedTestParser.wrongUsageMessages.at(0) == "Unknown argument or flag(s): a");
|
||||
|
||||
delete[] unknownFlagTestParameterList;
|
||||
|
||||
|
@ -264,8 +256,6 @@ int main(int argc, char* argv[]) {
|
|||
ASSERT(unknownLongFlagStandaloneTestParser.getFlag(std::string("four")).isError);
|
||||
ASSERT(unknownLongFlagStandaloneTestParser.getFlag(std::string("four")).errorCode == ErrorCodes::NOT_PRESENT);
|
||||
ASSERT(!unknownLongFlagStandaloneTestParser.getFlag(std::string("four")).value);
|
||||
ASSERT(unknownLongFlagStandaloneTestParser.wrongUsageMessages.size() == 1);
|
||||
ASSERT(unknownLongFlagStandaloneTestParser.wrongUsageMessages.at(0) == "Unknown argument or flag: --a");
|
||||
|
||||
int unknownLongFlagMixedTestParameterCount = 7;
|
||||
|
||||
|
@ -276,8 +266,6 @@ int main(int argc, char* argv[]) {
|
|||
ASSERT(unknownLongFlagMixedTestParser.getFlag(std::string("four")).isError);
|
||||
ASSERT(unknownLongFlagMixedTestParser.getFlag(std::string("four")).errorCode == ErrorCodes::WRONG_USAGE);
|
||||
ASSERT(unknownLongFlagMixedTestParser.getFlag(std::string("four")).value);
|
||||
ASSERT(unknownLongFlagMixedTestParser.wrongUsageMessages.size() == 1);
|
||||
ASSERT(unknownLongFlagMixedTestParser.wrongUsageMessages.at(0) == "Unknown argument or flag: --a");
|
||||
|
||||
delete[] unknownLongFlagTestParameterList;
|
||||
std::cout << "Passed unknown flag test." << std::endl;
|
||||
|
@ -313,8 +301,6 @@ int main(int argc, char* argv[]) {
|
|||
ASSERT(unknownArgumentStandaloneTestParser.getUnpositionalArgument(std::string("four")).isError);
|
||||
ASSERT(unknownArgumentStandaloneTestParser.getUnpositionalArgument(std::string("four")).errorCode == ErrorCodes::NOT_PRESENT);
|
||||
ASSERT(unknownArgumentStandaloneTestParser.getUnpositionalArgument(std::string("four")).value == "");
|
||||
ASSERT(unknownArgumentStandaloneTestParser.wrongUsageMessages.size() == 1);
|
||||
ASSERT(unknownArgumentStandaloneTestParser.wrongUsageMessages.at(0) == "Unknown argument or flag(s): a123");
|
||||
|
||||
int unknownArgumentMixedTestParameterCount = 7;
|
||||
|
||||
|
@ -325,8 +311,6 @@ int main(int argc, char* argv[]) {
|
|||
ASSERT(unknownArgumentMixedTestParser.getUnpositionalArgument(std::string("four")).isError);
|
||||
ASSERT(unknownArgumentMixedTestParser.getUnpositionalArgument(std::string("four")).errorCode == ErrorCodes::WRONG_USAGE);
|
||||
ASSERT(unknownArgumentMixedTestParser.getUnpositionalArgument(std::string("four")).value == "d");
|
||||
ASSERT(unknownArgumentMixedTestParser.wrongUsageMessages.size() == 1);
|
||||
ASSERT(unknownArgumentMixedTestParser.wrongUsageMessages.at(0) == "Unknown argument or flag(s): a123");
|
||||
|
||||
delete[] unknownArgumentTestParameterList;
|
||||
|
||||
|
@ -359,8 +343,6 @@ int main(int argc, char* argv[]) {
|
|||
ASSERT(unknownLongArgumentStandaloneTestParser.getUnpositionalArgument(std::string("four")).isError);
|
||||
ASSERT(unknownLongArgumentStandaloneTestParser.getUnpositionalArgument(std::string("four")).errorCode == ErrorCodes::NOT_PRESENT);
|
||||
ASSERT(unknownLongArgumentStandaloneTestParser.getUnpositionalArgument(std::string("four")).value == "");
|
||||
ASSERT(unknownLongArgumentStandaloneTestParser.wrongUsageMessages.size() == 1);
|
||||
ASSERT(unknownLongArgumentStandaloneTestParser.wrongUsageMessages.at(0) == "Unknown argument (or it's a flag that doesn't take a value): --a=123");
|
||||
|
||||
int unknownLongArgumentMixedTestParameterCount = 7;
|
||||
|
||||
|
@ -371,8 +353,6 @@ int main(int argc, char* argv[]) {
|
|||
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");
|
||||
ASSERT(unknownLongArgumentMixedTestParser.wrongUsageMessages.size() == 1);
|
||||
ASSERT(unknownLongArgumentMixedTestParser.wrongUsageMessages.at(0) == "Unknown argument (or it's a flag that doesn't take a value): --a=123");
|
||||
|
||||
delete[] unknownLongArgumentTestParameterList;
|
||||
std::cout << "Passed unknown unpositional argument test." << std::endl;
|
||||
|
@ -394,7 +374,7 @@ int main(int argc, char* argv[]) {
|
|||
const char** incompleteArgumentTestParameterList = new const char*[6];
|
||||
incompleteArgumentTestParameterList[0] = "test";
|
||||
incompleteArgumentTestParameterList[1] = "-1";
|
||||
incompleteArgumentTestParameterList[2] = "--two="; // value ""
|
||||
incompleteArgumentTestParameterList[2] = "-2b";
|
||||
incompleteArgumentTestParameterList[3] = "-3c";
|
||||
incompleteArgumentTestParameterList[4] = "-4";
|
||||
incompleteArgumentTestParameterList[5] = "-5e";
|
||||
|
@ -407,8 +387,6 @@ int main(int argc, char* argv[]) {
|
|||
ASSERT(incompleteArgumentStandaloneTestParser.getUnpositionalArgument(std::string("four")).isError);
|
||||
ASSERT(incompleteArgumentStandaloneTestParser.getUnpositionalArgument(std::string("four")).errorCode == ErrorCodes::NOT_PRESENT);
|
||||
ASSERT(incompleteArgumentStandaloneTestParser.getUnpositionalArgument(std::string("four")).value == "");
|
||||
ASSERT(incompleteArgumentStandaloneTestParser.wrongUsageMessages.size() == 1);
|
||||
ASSERT(incompleteArgumentStandaloneTestParser.wrongUsageMessages.at(0) == "Argument expects value but has none: one");
|
||||
|
||||
int incompleteArgumentMixedTestParameterCount = 6;
|
||||
|
||||
|
@ -422,9 +400,6 @@ int main(int argc, char* argv[]) {
|
|||
ASSERT(incompleteArgumentMixedTestParser.getUnpositionalArgument('5').isError);
|
||||
ASSERT(incompleteArgumentMixedTestParser.getUnpositionalArgument('5').errorCode == ErrorCodes::WRONG_USAGE);
|
||||
ASSERT(incompleteArgumentMixedTestParser.getUnpositionalArgument('5').value == "e");
|
||||
ASSERT(incompleteArgumentMixedTestParser.wrongUsageMessages.size() == 2);
|
||||
ASSERT(incompleteArgumentMixedTestParser.wrongUsageMessages.at(0) == "Argument expects value but has none: one");
|
||||
ASSERT(incompleteArgumentMixedTestParser.wrongUsageMessages.at(1) == "Argument expects value but has none: four");
|
||||
|
||||
delete[] incompleteArgumentTestParameterList;
|
||||
|
||||
|
@ -458,11 +433,8 @@ int main(int argc, char* argv[]) {
|
|||
ASSERT(incompleteLongArgumentStandaloneTestParser.getUnpositionalArgument(std::string("four")).isError);
|
||||
ASSERT(incompleteLongArgumentStandaloneTestParser.getUnpositionalArgument(std::string("four")).errorCode == ErrorCodes::NOT_PRESENT);
|
||||
ASSERT(incompleteLongArgumentStandaloneTestParser.getUnpositionalArgument(std::string("four")).value == "");
|
||||
ASSERT(incompleteLongArgumentStandaloneTestParser.wrongUsageMessages.size() == 1);
|
||||
ASSERT(incompleteLongArgumentStandaloneTestParser.wrongUsageMessages.at(0) == "Argument expects value but has none: one");
|
||||
|
||||
int incompleteLongArgumentMixedTestParameterCount = 8;
|
||||
incompleteLongArgumentTestPositionalArguments.push_back(CLI::PositionalArgument("arg", "argument"));
|
||||
|
||||
CLI::ArgumentsParser incompleteLongArgumentMixedTestParser = CLI::ArgumentsParser(incompleteLongArgumentMixedTestParameterCount, incompleteLongArgumentTestParameterList, incompleteLongArgumentTestFlags, incompleteLongArgumentTestUnpositionalArguments, incompleteLongArgumentTestPositionalArguments);
|
||||
ASSERT(incompleteLongArgumentMixedTestParser.getUnpositionalArgument('1').isError);
|
||||
|
@ -477,9 +449,6 @@ int main(int argc, char* argv[]) {
|
|||
ASSERT(incompleteLongArgumentMixedTestParser.getUnpositionalArgument('5').isError);
|
||||
ASSERT(incompleteLongArgumentMixedTestParser.getUnpositionalArgument('5').errorCode == ErrorCodes::WRONG_USAGE);
|
||||
ASSERT(incompleteLongArgumentMixedTestParser.getUnpositionalArgument('5').value == "e");
|
||||
ASSERT(incompleteLongArgumentMixedTestParser.wrongUsageMessages.size() == 2);
|
||||
ASSERT(incompleteLongArgumentMixedTestParser.wrongUsageMessages.at(0) == "Argument expects value but has none: one");
|
||||
ASSERT(incompleteLongArgumentMixedTestParser.wrongUsageMessages.at(1) == "Argument expects value but has none: four");
|
||||
|
||||
delete[] incompleteLongArgumentTestParameterList;
|
||||
std::cout << "Passed incomplete unpositional argument test." << std::endl;
|
||||
|
@ -499,7 +468,6 @@ int main(int argc, char* argv[]) {
|
|||
tooFewArgumentsTestPositionalArguments.push_back(CLI::PositionalArgument("argument1", "test argument"));
|
||||
tooFewArgumentsTestPositionalArguments.push_back(CLI::PositionalArgument("argument2", "test argument"));
|
||||
tooFewArgumentsTestPositionalArguments.push_back(CLI::PositionalArgument("argument3", "test argument"));
|
||||
tooFewArgumentsTestPositionalArguments.push_back(CLI::PositionalArgument("argument4", "test argument"));
|
||||
|
||||
const char** tooFewArgumentsTestParameterList = new const char*[10];
|
||||
tooFewArgumentsTestParameterList[0] = "test";
|
||||
|
@ -531,11 +499,6 @@ int main(int argc, char* argv[]) {
|
|||
ASSERT(tooFewArgumentsStandaloneTestParser.getUnpositionalArgument('d').isError);
|
||||
ASSERT(tooFewArgumentsStandaloneTestParser.getUnpositionalArgument('d').errorCode == ErrorCodes::NOT_PRESENT);
|
||||
ASSERT(tooFewArgumentsStandaloneTestParser.getUnpositionalArgument('d').value == "");
|
||||
ASSERT(tooFewArgumentsStandaloneTestParser.wrongUsageMessages.size() == 4);
|
||||
ASSERT(tooFewArgumentsStandaloneTestParser.wrongUsageMessages.at(0) == "Too few positional arguments! Missing: argument1");
|
||||
ASSERT(tooFewArgumentsStandaloneTestParser.wrongUsageMessages.at(1) == "Too few positional arguments! Missing: argument2");
|
||||
ASSERT(tooFewArgumentsStandaloneTestParser.wrongUsageMessages.at(2) == "Too few positional arguments! Missing: argument3");
|
||||
ASSERT(tooFewArgumentsStandaloneTestParser.wrongUsageMessages.at(3) == "Too few positional arguments! Missing: argument4");
|
||||
|
||||
int tooFewArgumentsMixedTestParameterCount = 10;
|
||||
CLI::ArgumentsParser tooFewArgumentsMixedTestParser = CLI::ArgumentsParser(tooFewArgumentsMixedTestParameterCount, tooFewArgumentsTestParameterList, tooFewArgumentsTestFlags, tooFewArgumentsTestUnpositionalArguments, tooFewArgumentsTestPositionalArguments);
|
||||
|
@ -552,9 +515,6 @@ int main(int argc, char* argv[]) {
|
|||
ASSERT(tooFewArgumentsMixedTestParser.getPositionalArgument(3).isError);
|
||||
ASSERT(tooFewArgumentsMixedTestParser.getPositionalArgument(3).errorCode == ErrorCodes::NOT_PRESENT);
|
||||
ASSERT(tooFewArgumentsMixedTestParser.getPositionalArgument(3).value == "");
|
||||
ASSERT(tooFewArgumentsMixedTestParser.getPositionalArgument(4).isError);
|
||||
ASSERT(tooFewArgumentsMixedTestParser.getPositionalArgument(4).errorCode == ErrorCodes::NOT_PRESENT);
|
||||
ASSERT(tooFewArgumentsMixedTestParser.getPositionalArgument(4).value == "");
|
||||
ASSERT(tooFewArgumentsMixedTestParser.getUnpositionalArgument('b').isError);
|
||||
ASSERT(tooFewArgumentsMixedTestParser.getUnpositionalArgument('b').errorCode == ErrorCodes::WRONG_USAGE);
|
||||
ASSERT(tooFewArgumentsMixedTestParser.getUnpositionalArgument('b').value == "1");
|
||||
|
@ -564,9 +524,6 @@ int main(int argc, char* argv[]) {
|
|||
ASSERT(tooFewArgumentsMixedTestParser.getUnpositionalArgument('d').isError);
|
||||
ASSERT(tooFewArgumentsMixedTestParser.getUnpositionalArgument('d').errorCode == ErrorCodes::WRONG_USAGE);
|
||||
ASSERT(tooFewArgumentsMixedTestParser.getUnpositionalArgument('d').value == "ddd");
|
||||
ASSERT(tooFewArgumentsMixedTestParser.wrongUsageMessages.size() == 2);
|
||||
ASSERT(tooFewArgumentsMixedTestParser.wrongUsageMessages.at(0) == "Too few positional arguments! Missing: argument3");
|
||||
ASSERT(tooFewArgumentsMixedTestParser.wrongUsageMessages.at(1) == "Too few positional arguments! Missing: argument4");
|
||||
|
||||
delete[] tooFewArgumentsTestParameterList;
|
||||
std::cout << "Passed too few positional arguments test." << std::endl;
|
||||
|
@ -611,8 +568,6 @@ int main(int argc, char* argv[]) {
|
|||
ASSERT(tooManyArgumentsStandaloneTestParser.getUnpositionalArgument('d').isError);
|
||||
ASSERT(tooManyArgumentsStandaloneTestParser.getUnpositionalArgument('d').errorCode == ErrorCodes::NOT_PRESENT);
|
||||
ASSERT(tooManyArgumentsStandaloneTestParser.getUnpositionalArgument('d').value == "");
|
||||
ASSERT(tooManyArgumentsStandaloneTestParser.wrongUsageMessages.size() == 1);
|
||||
ASSERT(tooManyArgumentsStandaloneTestParser.wrongUsageMessages.at(0) == "Too many positional arguments! Unexpected encounter of: positional_arg_1");
|
||||
|
||||
int tooManyArgumentsMixedTestParameterCount = 10;
|
||||
CLI::ArgumentsParser tooManyArgumentsMixedTestParser = CLI::ArgumentsParser(tooManyArgumentsMixedTestParameterCount, tooManyArgumentsTestParameterList, tooManyArgumentsTestFlags, tooManyArgumentsTestUnpositionalArguments, tooManyArgumentsTestPositionalArguments);
|
||||
|
@ -629,9 +584,6 @@ int main(int argc, char* argv[]) {
|
|||
ASSERT(tooManyArgumentsMixedTestParser.getUnpositionalArgument('d').isError);
|
||||
ASSERT(tooManyArgumentsMixedTestParser.getUnpositionalArgument('d').errorCode == ErrorCodes::WRONG_USAGE);
|
||||
ASSERT(tooManyArgumentsMixedTestParser.getUnpositionalArgument('d').value == "ddd");
|
||||
ASSERT(tooManyArgumentsMixedTestParser.wrongUsageMessages.size() == 2);
|
||||
ASSERT(tooManyArgumentsMixedTestParser.wrongUsageMessages.at(0) == "Too many positional arguments! Unexpected encounter of: positional_arg_1");
|
||||
ASSERT(tooManyArgumentsMixedTestParser.wrongUsageMessages.at(1) == "Too many positional arguments! Unexpected encounter of: positional_arg_2");
|
||||
|
||||
delete[] tooManyArgumentsTestParameterList;
|
||||
std::cout << "Passed too many positional arguments test." << std::endl;
|
||||
|
|
Loading…
Reference in New Issue