Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion include/CLI/impl/Config_inl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ inline std::vector<ConfigItem> ConfigBase::from_config(std::istream &input) cons
}
}
items_buffer = {item};
} else if(item.size() > 1 && item.front() == aStart) {
} else if(!item.empty() && item.front() == aStart) {
for(std::string multiline; item.back() != aEnd && std::getline(input, multiline);) {
detail::trim(multiline);
item += multiline;
Expand Down
75 changes: 75 additions & 0 deletions tests/ConfigFileTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1510,6 +1510,57 @@ TEST_CASE_METHOD(TApp, "TOMLVector", "[config]") {
CHECK(three == std::vector<int>({1, 2, 3}));
}

TEST_CASE_METHOD(TApp, "TOMLMultiLineVector", "[config]") {

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=[\n";
out << " 2, 3\n";
out << "]\n";
out << "three=[\n\t1,\n\t2,\n\t3\n]\n";
}

std::vector<int> two, three;
app.add_option("--two", two)->expected(2)->required();
app.add_option("--three", three)->required();

run();

CHECK(two == std::vector<int>({2, 3}));
CHECK(three == std::vector<int>({1, 2, 3}));
}

TEST_CASE_METHOD(TApp, "TOMLMultiLineVector2", "[config]") {

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=[\n";
out << " 2, 3]\n";
out << "three=[\n\t1,\n\t2,\n\t3\n]\n";
}

std::vector<int> two, three;
app.add_option("--two", two)->expected(2)->required();
app.add_option("--three", three)->required();

run();

CHECK(two == std::vector<int>({2, 3}));
CHECK(three == std::vector<int>({1, 2, 3}));
}

TEST_CASE_METHOD(TApp, "ColonValueSep", "[config]") {

TempFile tmpini{"TestIniTmp.ini"};
Expand Down Expand Up @@ -1700,6 +1751,30 @@ TEST_CASE_METHOD(TApp, "TOMLStringVector", "[config]") {
CHECK(three == std::vector<std::string>({"1", "2", "3"}));
}

TEST_CASE_METHOD(TApp, "TOMLStringVectorMultiline", "[config]") {

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=[\n\t\t\"2\",\"3\"]\n";
out << "three=[\n \"1\",\n \"2\",\n \"3\"\n] \n";
}

std::vector<std::string> two, three;

app.add_option("--two", two)->required();
app.add_option("--three", three)->required();

run();
CHECK(two == std::vector<std::string>({"2", "3"}));
CHECK(three == std::vector<std::string>({"1", "2", "3"}));
}

TEST_CASE_METHOD(TApp, "IniVectorCsep", "[config]") {

TempFile tmpini{"TestIniTmp.ini"};
Expand Down
Loading