1
0
mirror of https://github.com/CLIUtils/CLI11.git synced 2025-04-30 20:53:52 +00:00

Adding a few more tests

This commit is contained in:
Henry Fredrick Schreiner 2017-06-05 09:10:04 -04:00
parent 3c57be7adf
commit da5e8ee4a9
2 changed files with 56 additions and 1 deletions

View File

@ -281,7 +281,7 @@ class App {
variable.emplace_back(); variable.emplace_back();
retval &= detail::lexical_cast(a, variable.back()); retval &= detail::lexical_cast(a, variable.back());
} }
return variable.size() > 0 && retval; return (!variable.empty()) && retval;
}; };
Option *opt = add_option(name, fun, description, false); Option *opt = add_option(name, fun, description, false);

View File

@ -420,6 +420,47 @@ TEST_F(TApp, InSet) {
EXPECT_THROW(run(), CLI::ConversionError); EXPECT_THROW(run(), CLI::ConversionError);
} }
TEST_F(TApp, InSetWithDefault) {
std::string choice = "one";
app.add_set("-q,--quick", choice, {"one", "two", "three"}, "", true);
run();
EXPECT_EQ("one", choice);
app.reset();
args = {"--quick", "two"};
run();
EXPECT_EQ("two", choice);
app.reset();
args = {"--quick", "four"};
EXPECT_THROW(run(), CLI::ConversionError);
}
TEST_F(TApp, InCaselessSetWithDefault) {
std::string choice = "one";
app.add_set_ignore_case("-q,--quick", choice, {"one", "two", "three"}, "", true);
run();
EXPECT_EQ("one", choice);
app.reset();
args = {"--quick", "tWo"};
run();
EXPECT_EQ("two", choice);
app.reset();
args = {"--quick", "four"};
EXPECT_THROW(run(), CLI::ConversionError);
}
TEST_F(TApp, InIntSet) { TEST_F(TApp, InIntSet) {
int choice; int choice;
@ -491,6 +532,20 @@ TEST_F(TApp, VectorFixedString) {
EXPECT_EQ(answer, strvec); EXPECT_EQ(answer, strvec);
} }
TEST_F(TApp, VectorDefaultedFixedString) {
std::vector<std::string> strvec{"one"};
std::vector<std::string> answer{"mystring", "mystring2", "mystring3"};
CLI::Option *opt = app.add_option("-s,--string", strvec, "", true)->expected(3);
EXPECT_EQ(3, opt->get_expected());
args = {"--string", "mystring", "mystring2", "mystring3"};
run();
EXPECT_EQ((size_t)3, app.count("--string"));
EXPECT_EQ(answer, strvec);
}
TEST_F(TApp, VectorUnlimString) { TEST_F(TApp, VectorUnlimString) {
std::vector<std::string> strvec; std::vector<std::string> strvec;
std::vector<std::string> answer{"mystring", "mystring2", "mystring3"}; std::vector<std::string> answer{"mystring", "mystring2", "mystring3"};