From 6ee4e5b5546202d5cb0148ef576377aa45d43dd2 Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Sat, 12 Mar 2022 00:43:00 +0100 Subject: [PATCH] tests: unit: csv: add 'write_csv' suite The disabled tests are expected failures (which GTest does not support), once fixed they will be enabled. --- tests/unit/csv.cc | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/tests/unit/csv.cc b/tests/unit/csv.cc index fcb27da..2135081 100644 --- a/tests/unit/csv.cc +++ b/tests/unit/csv.cc @@ -1,6 +1,9 @@ +#include + #include #include "csv/read-csv.hh" +#include "csv/write-csv.hh" // Allow namespace pollution in tests for convenience using namespace kraken::csv; @@ -36,3 +39,32 @@ TEST(read_csv, single_line_with_header) { }; ASSERT_EQ(read_csv("a,b,c\n1,2,3", CsvHeader::KEEP), expected); } + +TEST(write_csv, empty) { + auto const csv = csv_type{}; + auto const expected = ""; + auto output = std::ostringstream{}; + write_csv(output, csv); + ASSERT_EQ(output.str(), expected); +} + +TEST(write_csv, DISABLED_single_line) { + auto const csv = csv_type{ + {"a", "b", "c"}, + }; + auto const expected = "a,b,c\n"; + auto output = std::ostringstream{}; + write_csv(output, csv); + ASSERT_EQ(output.str(), expected); +} + +TEST(write_csv, DISABLED_multiple_lines) { + auto const csv = csv_type{ + {"a", "b", "c"}, + {"1", "2", "3"}, + }; + auto const expected = "a,b,c\n1,2,3\n"; + auto output = std::ostringstream{}; + write_csv(output, csv); + ASSERT_EQ(output.str(), expected); +}