Skip to content

Commit

Permalink
add empty vector command line tests
Browse files Browse the repository at this point in the history
  • Loading branch information
phlptp committed Oct 24, 2021
1 parent 6f9dfb3 commit 137e2e4
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions tests/AppTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -939,6 +939,35 @@ TEST_CASE_METHOD(TApp, "RequiredOptsDouble", "[app]") {
CHECK(std::vector<std::string>({"one", "two"}) == strs);
}

TEST_CASE_METHOD(TApp, "emptyVectorReturn", "[app]") {

std::vector<std::string> strs;
std::vector<std::string> strs2;
auto opt1 = app.add_option("--str", strs)->required()->expected(0, 2);
app.add_option("--str2", strs2);
args = {"--str"};

CHECK_NOTHROW(run());
CHECK(std::vector<std::string>({""}) == strs);
args = {"--str", "one", "two"};

run();

CHECK(std::vector<std::string>({"one", "two"}) == strs);

args = {"--str", "{}", "--str2", "{}"};

run();

CHECK(std::vector<std::string>{} == strs);
CHECK(std::vector<std::string>{"{}"} == strs2);
opt1->default_str("{}");
args = {"--str"};

CHECK_NOTHROW(run());
CHECK(std::vector<std::string>{} == strs);
}

TEST_CASE_METHOD(TApp, "RequiredOptsDoubleShort", "[app]") {

std::vector<std::string> strs;
Expand Down

0 comments on commit 137e2e4

Please sign in to comment.