1
0
mirror of https://github.com/CLIUtils/CLI11.git synced 2025-04-29 20:23:55 +00:00

Fix for spaces in names issue

This commit is contained in:
Henry Fredrick Schreiner 2017-09-05 17:38:02 -04:00 committed by Henry Schreiner
parent 93311928d7
commit c6ddbeb281
4 changed files with 27 additions and 2 deletions

View File

@ -44,10 +44,10 @@ inline std::vector<std::string> split_names(std::string current) {
std::vector<std::string> output;
size_t val;
while((val = current.find(",")) != std::string::npos) {
output.push_back(current.substr(0, val));
output.push_back(trim_copy(current.substr(0, val)));
current = current.substr(val + 1);
}
output.push_back(current);
output.push_back(trim_copy(current));
return output;
}

View File

@ -260,6 +260,7 @@ TEST_F(TApp, Positionals) {
EXPECT_EQ("thing2", posit2);
}
TEST_F(TApp, ForcedPositional) {
std::vector<std::string> posit;
auto one = app.add_flag("--one");

View File

@ -230,3 +230,24 @@ TEST_F(TApp, CheckNameNoCase) {
EXPECT_TRUE(pos2->check_name("pOs2"));
EXPECT_TRUE(pos2->check_name("pos2"));
}
TEST_F(TApp, PreSpaces) {
int x;
auto myapp = app.add_option(" -a, --long, other", x);
EXPECT_TRUE(myapp->check_lname("long"));
EXPECT_TRUE(myapp->check_sname("a"));
EXPECT_TRUE(myapp->check_name("other"));
}
TEST_F(TApp, AllSpaces) {
int x;
auto myapp = app.add_option(" -a , --long , other ", x);
EXPECT_TRUE(myapp->check_lname("long"));
EXPECT_TRUE(myapp->check_sname("a"));
EXPECT_TRUE(myapp->check_name("other"));
}

View File

@ -179,6 +179,9 @@ TEST(Split, StringList) {
std::vector<std::string> results{"a", "long", "--lone", "-q"};
EXPECT_EQ(results, CLI::detail::split_names("a,long,--lone,-q"));
EXPECT_EQ(results, CLI::detail::split_names(" a, long, --lone, -q"));
EXPECT_EQ(results, CLI::detail::split_names(" a , long , --lone , -q "));
EXPECT_EQ(results, CLI::detail::split_names(" a , long , --lone , -q "));
EXPECT_EQ(std::vector<std::string>({"one"}), CLI::detail::split_names("one"));
}