2022-03-12 00:08:38 +01:00
|
|
|
#include <gtest/gtest.h>
|
|
|
|
|
|
|
|
#include "csv/read-csv.hh"
|
|
|
|
|
|
|
|
// Allow namespace pollution in tests for convenience
|
|
|
|
using namespace kraken::csv;
|
|
|
|
|
2022-03-12 00:32:05 +01:00
|
|
|
TEST(read_csv, empty) {
|
2022-03-12 00:08:38 +01:00
|
|
|
auto const expected = csv_type{};
|
|
|
|
ASSERT_EQ(read_csv(""), expected);
|
|
|
|
}
|
|
|
|
|
2022-03-12 00:32:05 +01:00
|
|
|
TEST(read_csv, skip_header) {
|
2022-03-12 00:08:38 +01:00
|
|
|
auto const expected = csv_type{};
|
|
|
|
ASSERT_EQ(read_csv("a,b,c"), expected);
|
|
|
|
}
|
|
|
|
|
2022-03-12 00:32:05 +01:00
|
|
|
TEST(read_csv, do_not_skip_header) {
|
2022-03-12 00:08:38 +01:00
|
|
|
auto const expected = csv_type{
|
|
|
|
{"a", "b", "c"},
|
|
|
|
};
|
|
|
|
ASSERT_EQ(read_csv("a,b,c", CsvHeader::KEEP), expected);
|
|
|
|
}
|
|
|
|
|
2022-03-12 00:32:05 +01:00
|
|
|
TEST(read_csv, single_line) {
|
2022-03-12 00:08:38 +01:00
|
|
|
auto const expected = csv_type{
|
|
|
|
{"1", "2", "3"},
|
|
|
|
};
|
|
|
|
ASSERT_EQ(read_csv("a,b,c\n1,2,3"), expected);
|
|
|
|
}
|
|
|
|
|
2022-03-12 00:32:05 +01:00
|
|
|
TEST(read_csv, single_line_with_header) {
|
2022-03-12 00:08:38 +01:00
|
|
|
auto const expected = csv_type{
|
|
|
|
{"a", "b", "c"},
|
|
|
|
{"1", "2", "3"},
|
|
|
|
};
|
|
|
|
ASSERT_EQ(read_csv("a,b,c\n1,2,3", CsvHeader::KEEP), expected);
|
|
|
|
}
|