mirror of
https://github.com/CLIUtils/CLI11.git
synced 2025-04-29 12:13:52 +00:00
Fix for spaces in names issue
This commit is contained in:
parent
93311928d7
commit
c6ddbeb281
@ -44,10 +44,10 @@ inline std::vector<std::string> split_names(std::string current) {
|
|||||||
std::vector<std::string> output;
|
std::vector<std::string> output;
|
||||||
size_t val;
|
size_t val;
|
||||||
while((val = current.find(",")) != std::string::npos) {
|
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);
|
current = current.substr(val + 1);
|
||||||
}
|
}
|
||||||
output.push_back(current);
|
output.push_back(trim_copy(current));
|
||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -260,6 +260,7 @@ TEST_F(TApp, Positionals) {
|
|||||||
EXPECT_EQ("thing2", posit2);
|
EXPECT_EQ("thing2", posit2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
TEST_F(TApp, ForcedPositional) {
|
TEST_F(TApp, ForcedPositional) {
|
||||||
std::vector<std::string> posit;
|
std::vector<std::string> posit;
|
||||||
auto one = app.add_flag("--one");
|
auto one = app.add_flag("--one");
|
||||||
|
@ -230,3 +230,24 @@ TEST_F(TApp, CheckNameNoCase) {
|
|||||||
EXPECT_TRUE(pos2->check_name("pOs2"));
|
EXPECT_TRUE(pos2->check_name("pOs2"));
|
||||||
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"));
|
||||||
|
|
||||||
|
}
|
||||||
|
@ -179,6 +179,9 @@ TEST(Split, StringList) {
|
|||||||
|
|
||||||
std::vector<std::string> results{"a", "long", "--lone", "-q"};
|
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(results, CLI::detail::split_names(" a , long , --lone , -q "));
|
||||||
|
|
||||||
EXPECT_EQ(std::vector<std::string>({"one"}), CLI::detail::split_names("one"));
|
EXPECT_EQ(std::vector<std::string>({"one"}), CLI::detail::split_names("one"));
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user