From 697f941cb26dbddd92c49071a12b01279c1e3c2f Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Sat, 12 Mar 2022 00:08:38 +0100 Subject: [PATCH] tests: unit: add 'csv' tests Simple tests for a simple library. --- tests/unit/CMakeLists.txt | 9 +++++---- tests/unit/base.cc | 5 ----- tests/unit/csv.cc | 38 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 43 insertions(+), 9 deletions(-) delete mode 100644 tests/unit/base.cc create mode 100644 tests/unit/csv.cc diff --git a/tests/unit/CMakeLists.txt b/tests/unit/CMakeLists.txt index f29fdf8..5086fb6 100644 --- a/tests/unit/CMakeLists.txt +++ b/tests/unit/CMakeLists.txt @@ -3,13 +3,14 @@ find_package(GTest) if (${GTest_FOUND}) include(GoogleTest) -add_executable(base_test base.cc) -target_link_libraries(base_test PRIVATE common_options) +add_executable(csv_test csv.cc) +target_link_libraries(csv_test PRIVATE common_options) -target_link_libraries(base_test PRIVATE +target_link_libraries(csv_test PRIVATE + csv GTest::gtest GTest::gtest_main ) -gtest_discover_tests(base_test) +gtest_discover_tests(csv_test) endif (${GTest_FOUND}) diff --git a/tests/unit/base.cc b/tests/unit/base.cc deleted file mode 100644 index 4573678..0000000 --- a/tests/unit/base.cc +++ /dev/null @@ -1,5 +0,0 @@ -#include - -TEST(misc, passing) { - ASSERT_EQ(1, 1); -} diff --git a/tests/unit/csv.cc b/tests/unit/csv.cc new file mode 100644 index 0000000..2ff87d8 --- /dev/null +++ b/tests/unit/csv.cc @@ -0,0 +1,38 @@ +#include + +#include "csv/read-csv.hh" + +// Allow namespace pollution in tests for convenience +using namespace kraken::csv; + +TEST(csv, empty) { + auto const expected = csv_type{}; + ASSERT_EQ(read_csv(""), expected); +} + +TEST(csv, skip_header) { + auto const expected = csv_type{}; + ASSERT_EQ(read_csv("a,b,c"), expected); +} + +TEST(csv, do_not_skip_header) { + auto const expected = csv_type{ + {"a", "b", "c"}, + }; + ASSERT_EQ(read_csv("a,b,c", CsvHeader::KEEP), expected); +} + +TEST(csv, single_line) { + auto const expected = csv_type{ + {"1", "2", "3"}, + }; + ASSERT_EQ(read_csv("a,b,c\n1,2,3"), expected); +} + +TEST(csv, single_line_with_header) { + auto const expected = csv_type{ + {"a", "b", "c"}, + {"1", "2", "3"}, + }; + ASSERT_EQ(read_csv("a,b,c\n1,2,3", CsvHeader::KEEP), expected); +}