mirror of
https://github.com/CLIUtils/CLI11.git
synced 2025-04-30 12:43:52 +00:00
Adding a few more tests
This commit is contained in:
parent
3c57be7adf
commit
da5e8ee4a9
@ -281,7 +281,7 @@ class App {
|
||||
variable.emplace_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);
|
||||
|
@ -420,6 +420,47 @@ TEST_F(TApp, InSet) {
|
||||
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) {
|
||||
|
||||
int choice;
|
||||
@ -491,6 +532,20 @@ TEST_F(TApp, VectorFixedString) {
|
||||
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) {
|
||||
std::vector<std::string> strvec;
|
||||
std::vector<std::string> answer{"mystring", "mystring2", "mystring3"};
|
||||
|
Loading…
x
Reference in New Issue
Block a user