1
0
mirror of https://github.com/CLIUtils/CLI11.git synced 2025-05-01 21:23:52 +00:00

fix: a failing test case for toml string_vector processing (#491)

This commit is contained in:
Philip Top 2020-07-27 19:10:18 -07:00 committed by GitHub
parent 34bd80971b
commit 102e201dc7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 30 additions and 1 deletions

View File

@ -310,7 +310,12 @@ inline std::vector<std::string> split_up(std::string str, char delimiter = '\0')
} }
if(end != std::string::npos) { if(end != std::string::npos) {
output.push_back(str.substr(1, end - 1)); output.push_back(str.substr(1, end - 1));
str = str.substr(end + 1); if(end + 2 < str.size()) {
str = str.substr(end + 2);
} else {
str.clear();
}
} else { } else {
output.push_back(str.substr(1)); output.push_back(str.substr(1));
str = ""; str = "";

View File

@ -770,6 +770,30 @@ TEST_F(TApp, TOMLVectordirect) {
EXPECT_EQ(std::vector<int>({1, 2, 3}), three); EXPECT_EQ(std::vector<int>({1, 2, 3}), three);
} }
TEST_F(TApp, TOMLStringVector) {
TempFile tmptoml{"TestTomlTmp.toml"};
app.set_config("--config", tmptoml);
{
std::ofstream out{tmptoml};
out << "#this is a comment line\n";
out << "[default]\n";
out << "two=[\"2\",\"3\"]\n";
out << "three=[\"1\",\"2\",\"3\"]\n";
}
std::vector<std::string> two, three;
app.add_option("--two", two)->required();
app.add_option("--three", three)->required();
run();
EXPECT_EQ(std::vector<std::string>({"2", "3"}), two);
EXPECT_EQ(std::vector<std::string>({"1", "2", "3"}), three);
}
TEST_F(TApp, IniVectorCsep) { TEST_F(TApp, IniVectorCsep) {
TempFile tmpini{"TestIniTmp.ini"}; TempFile tmpini{"TestIniTmp.ini"};