Skip to content

Commit

Permalink
Add --option=value test for #90, as well
Browse files Browse the repository at this point in the history
  • Loading branch information
henryiii committed Mar 26, 2018
1 parent aa7c01f commit 2b4780d
Showing 1 changed file with 46 additions and 24 deletions.
70 changes: 46 additions & 24 deletions tests/AppTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,52 @@ TEST_F(TApp, RequiredOptsDoubleNeg) {
EXPECT_EQ(strs, std::vector<std::string>({"one", "two"}));
}

// This makes sure unlimited option priority is
// correct for space vs. no space #90
TEST_F(TApp, PositionalNoSpace) {
std::vector<std::string> options;
std::string foo, bar;

app.add_option("-O", options);
app.add_option("foo", foo)->required();
app.add_option("bar", bar)->required();

args = {"-O", "Test", "param1", "param2"};
run();

EXPECT_EQ(options.size(), (size_t)1);
EXPECT_EQ(options.at(0), "Test");

app.reset();
args = {"-OTest", "param1", "param2"};
run();

EXPECT_EQ(options.size(), (size_t)1);
EXPECT_EQ(options.at(0), "Test");
}

TEST_F(TApp, PositionalNoSpaceLong) {
std::vector<std::string> options;
std::string foo, bar;

app.add_option("--option", options);
app.add_option("foo", foo)->required();
app.add_option("bar", bar)->required();

args = {"--option", "Test", "param1", "param2"};
run();

EXPECT_EQ(options.size(), (size_t)1);
EXPECT_EQ(options.at(0), "Test");

app.reset();
args = {"--option=Test", "param1", "param2"};
run();

EXPECT_EQ(options.size(), (size_t)1);
EXPECT_EQ(options.at(0), "Test");
}

TEST_F(TApp, RequiredOptsUnlimited) {

std::vector<std::string> strs;
Expand Down Expand Up @@ -707,30 +753,6 @@ TEST_F(TApp, BigPositional) {
EXPECT_EQ(args, vec);
}

// This makes sure unlimited option priority is
// correct for space vs. no space #90
TEST_F(TApp, PositionalNoSpace) {
std::vector<std::string> options;
std::string foo, bar;

app.add_option("-O", options);
app.add_option("foo", foo)->required();
app.add_option("bar", bar)->required();

args = {"-O", "Test", "param1", "param2"};
run();

EXPECT_EQ(options.size(), (size_t)1);
EXPECT_EQ(options.at(0), "Test");

app.reset();
args = {"-OTest", "param1", "param2"};
run();

EXPECT_EQ(options.size(), (size_t)1);
EXPECT_EQ(options.at(0), "Test");
}

TEST_F(TApp, Reset) {

app.add_flag("--simple");
Expand Down

0 comments on commit 2b4780d

Please sign in to comment.