Commit c6ddbeb2814ac0eb0331f3e7c10f7b49af91d1c7
Committed by
Henry Schreiner
1 parent
93311928
Fix for spaces in names issue
Showing
4 changed files
with
27 additions
and
2 deletions
include/CLI/Split.hpp
| @@ -44,10 +44,10 @@ inline std::vector<std::string> split_names(std::string current) { | @@ -44,10 +44,10 @@ inline std::vector<std::string> split_names(std::string current) { | ||
| 44 | std::vector<std::string> output; | 44 | std::vector<std::string> output; |
| 45 | size_t val; | 45 | size_t val; |
| 46 | while((val = current.find(",")) != std::string::npos) { | 46 | while((val = current.find(",")) != std::string::npos) { |
| 47 | - output.push_back(current.substr(0, val)); | 47 | + output.push_back(trim_copy(current.substr(0, val))); |
| 48 | current = current.substr(val + 1); | 48 | current = current.substr(val + 1); |
| 49 | } | 49 | } |
| 50 | - output.push_back(current); | 50 | + output.push_back(trim_copy(current)); |
| 51 | return output; | 51 | return output; |
| 52 | } | 52 | } |
| 53 | 53 |
tests/AppTest.cpp
| @@ -260,6 +260,7 @@ TEST_F(TApp, Positionals) { | @@ -260,6 +260,7 @@ TEST_F(TApp, Positionals) { | ||
| 260 | EXPECT_EQ("thing2", posit2); | 260 | EXPECT_EQ("thing2", posit2); |
| 261 | } | 261 | } |
| 262 | 262 | ||
| 263 | + | ||
| 263 | TEST_F(TApp, ForcedPositional) { | 264 | TEST_F(TApp, ForcedPositional) { |
| 264 | std::vector<std::string> posit; | 265 | std::vector<std::string> posit; |
| 265 | auto one = app.add_flag("--one"); | 266 | auto one = app.add_flag("--one"); |
tests/CreationTest.cpp
| @@ -230,3 +230,24 @@ TEST_F(TApp, CheckNameNoCase) { | @@ -230,3 +230,24 @@ TEST_F(TApp, CheckNameNoCase) { | ||
| 230 | EXPECT_TRUE(pos2->check_name("pOs2")); | 230 | EXPECT_TRUE(pos2->check_name("pOs2")); |
| 231 | EXPECT_TRUE(pos2->check_name("pos2")); | 231 | EXPECT_TRUE(pos2->check_name("pos2")); |
| 232 | } | 232 | } |
| 233 | + | ||
| 234 | + | ||
| 235 | +TEST_F(TApp, PreSpaces) { | ||
| 236 | + int x; | ||
| 237 | + auto myapp = app.add_option(" -a, --long, other", x); | ||
| 238 | + | ||
| 239 | + EXPECT_TRUE(myapp->check_lname("long")); | ||
| 240 | + EXPECT_TRUE(myapp->check_sname("a")); | ||
| 241 | + EXPECT_TRUE(myapp->check_name("other")); | ||
| 242 | + | ||
| 243 | +} | ||
| 244 | + | ||
| 245 | +TEST_F(TApp, AllSpaces) { | ||
| 246 | + int x; | ||
| 247 | + auto myapp = app.add_option(" -a , --long , other ", x); | ||
| 248 | + | ||
| 249 | + EXPECT_TRUE(myapp->check_lname("long")); | ||
| 250 | + EXPECT_TRUE(myapp->check_sname("a")); | ||
| 251 | + EXPECT_TRUE(myapp->check_name("other")); | ||
| 252 | + | ||
| 253 | +} |
tests/HelpersTest.cpp
| @@ -179,6 +179,9 @@ TEST(Split, StringList) { | @@ -179,6 +179,9 @@ TEST(Split, StringList) { | ||
| 179 | 179 | ||
| 180 | std::vector<std::string> results{"a", "long", "--lone", "-q"}; | 180 | std::vector<std::string> results{"a", "long", "--lone", "-q"}; |
| 181 | EXPECT_EQ(results, CLI::detail::split_names("a,long,--lone,-q")); | 181 | EXPECT_EQ(results, CLI::detail::split_names("a,long,--lone,-q")); |
| 182 | + EXPECT_EQ(results, CLI::detail::split_names(" a, long, --lone, -q")); | ||
| 183 | + EXPECT_EQ(results, CLI::detail::split_names(" a , long , --lone , -q ")); | ||
| 184 | + EXPECT_EQ(results, CLI::detail::split_names(" a , long , --lone , -q ")); | ||
| 182 | 185 | ||
| 183 | EXPECT_EQ(std::vector<std::string>({"one"}), CLI::detail::split_names("one")); | 186 | EXPECT_EQ(std::vector<std::string>({"one"}), CLI::detail::split_names("one")); |
| 184 | } | 187 | } |