kraken: csv: fix comma separation logic
Unfortunately, `std::ostream_iterator` puts its separator *after* every element, not *in-between* each element.
This commit is contained in:
parent
6ee4e5b554
commit
bd072e1025
|
@ -8,8 +8,12 @@ namespace kraken::csv {
|
||||||
|
|
||||||
void write_csv(std::ostream& output, csv_type const& csv) {
|
void write_csv(std::ostream& output, csv_type const& csv) {
|
||||||
for (const auto& line : csv) {
|
for (const auto& line : csv) {
|
||||||
std::ranges::copy(line,
|
bool first = true;
|
||||||
std::ostream_iterator<std::string>{output, ","});
|
for (const auto& atom : line) {
|
||||||
|
output << (first ? "" : ",") << atom;
|
||||||
|
first = false;
|
||||||
|
};
|
||||||
|
output << '\n';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -48,7 +48,7 @@ TEST(write_csv, empty) {
|
||||||
ASSERT_EQ(output.str(), expected);
|
ASSERT_EQ(output.str(), expected);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(write_csv, DISABLED_single_line) {
|
TEST(write_csv, single_line) {
|
||||||
auto const csv = csv_type{
|
auto const csv = csv_type{
|
||||||
{"a", "b", "c"},
|
{"a", "b", "c"},
|
||||||
};
|
};
|
||||||
|
@ -58,7 +58,7 @@ TEST(write_csv, DISABLED_single_line) {
|
||||||
ASSERT_EQ(output.str(), expected);
|
ASSERT_EQ(output.str(), expected);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(write_csv, DISABLED_multiple_lines) {
|
TEST(write_csv, multiple_lines) {
|
||||||
auto const csv = csv_type{
|
auto const csv = csv_type{
|
||||||
{"a", "b", "c"},
|
{"a", "b", "c"},
|
||||||
{"1", "2", "3"},
|
{"1", "2", "3"},
|
||||||
|
|
Loading…
Reference in a new issue