Commit da5e8ee4a982d889e55ffd1b19c2b48c4aea198e

Authored by Henry Fredrick Schreiner
1 parent 3c57be7a

Adding a few more tests

include/CLI/App.hpp
... ... @@ -281,7 +281,7 @@ class App {
281 281 variable.emplace_back();
282 282 retval &= detail::lexical_cast(a, variable.back());
283 283 }
284   - return variable.size() > 0 && retval;
  284 + return (!variable.empty()) && retval;
285 285 };
286 286  
287 287 Option *opt = add_option(name, fun, description, false);
... ...
tests/AppTest.cpp
... ... @@ -420,6 +420,47 @@ TEST_F(TApp, InSet) {
420 420 EXPECT_THROW(run(), CLI::ConversionError);
421 421 }
422 422  
  423 +TEST_F(TApp, InSetWithDefault) {
  424 +
  425 + std::string choice = "one";
  426 + app.add_set("-q,--quick", choice, {"one", "two", "three"}, "", true);
  427 +
  428 + run();
  429 + EXPECT_EQ("one", choice);
  430 + app.reset();
  431 +
  432 + args = {"--quick", "two"};
  433 +
  434 + run();
  435 + EXPECT_EQ("two", choice);
  436 +
  437 + app.reset();
  438 +
  439 + args = {"--quick", "four"};
  440 + EXPECT_THROW(run(), CLI::ConversionError);
  441 +}
  442 +
  443 +
  444 +TEST_F(TApp, InCaselessSetWithDefault) {
  445 +
  446 + std::string choice = "one";
  447 + app.add_set_ignore_case("-q,--quick", choice, {"one", "two", "three"}, "", true);
  448 +
  449 + run();
  450 + EXPECT_EQ("one", choice);
  451 + app.reset();
  452 +
  453 + args = {"--quick", "tWo"};
  454 +
  455 + run();
  456 + EXPECT_EQ("two", choice);
  457 +
  458 + app.reset();
  459 +
  460 + args = {"--quick", "four"};
  461 + EXPECT_THROW(run(), CLI::ConversionError);
  462 +}
  463 +
423 464 TEST_F(TApp, InIntSet) {
424 465  
425 466 int choice;
... ... @@ -491,6 +532,20 @@ TEST_F(TApp, VectorFixedString) {
491 532 EXPECT_EQ(answer, strvec);
492 533 }
493 534  
  535 +
  536 +TEST_F(TApp, VectorDefaultedFixedString) {
  537 + std::vector<std::string> strvec{"one"};
  538 + std::vector<std::string> answer{"mystring", "mystring2", "mystring3"};
  539 +
  540 + CLI::Option *opt = app.add_option("-s,--string", strvec, "", true)->expected(3);
  541 + EXPECT_EQ(3, opt->get_expected());
  542 +
  543 + args = {"--string", "mystring", "mystring2", "mystring3"};
  544 + run();
  545 + EXPECT_EQ((size_t)3, app.count("--string"));
  546 + EXPECT_EQ(answer, strvec);
  547 +}
  548 +
494 549 TEST_F(TApp, VectorUnlimString) {
495 550 std::vector<std::string> strvec;
496 551 std::vector<std::string> answer{"mystring", "mystring2", "mystring3"};
... ...