tests: unit: add 'csv' tests
Simple tests for a simple library.
This commit is contained in:
parent
9d862c6a62
commit
697f941cb2
|
@ -3,13 +3,14 @@ find_package(GTest)
|
||||||
if (${GTest_FOUND})
|
if (${GTest_FOUND})
|
||||||
include(GoogleTest)
|
include(GoogleTest)
|
||||||
|
|
||||||
add_executable(base_test base.cc)
|
add_executable(csv_test csv.cc)
|
||||||
target_link_libraries(base_test PRIVATE common_options)
|
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
|
||||||
GTest::gtest_main
|
GTest::gtest_main
|
||||||
)
|
)
|
||||||
|
|
||||||
gtest_discover_tests(base_test)
|
gtest_discover_tests(csv_test)
|
||||||
endif (${GTest_FOUND})
|
endif (${GTest_FOUND})
|
||||||
|
|
|
@ -1,5 +0,0 @@
|
||||||
#include <gtest/gtest.h>
|
|
||||||
|
|
||||||
TEST(misc, passing) {
|
|
||||||
ASSERT_EQ(1, 1);
|
|
||||||
}
|
|
38
tests/unit/csv.cc
Normal file
38
tests/unit/csv.cc
Normal file
|
@ -0,0 +1,38 @@
|
||||||
|
#include <gtest/gtest.h>
|
||||||
|
|
||||||
|
#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);
|
||||||
|
}
|
Loading…
Reference in a new issue