From 9ce5ca83e70aa7ebd460f593e899794ed0232b9e Mon Sep 17 00:00:00 2001 From: Michael Sinelnikov Date: Wed, 13 Dec 2023 18:21:26 +0300 Subject: [PATCH] Add tests for separator validation --- src/tests/test_util.cpp | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/src/tests/test_util.cpp b/src/tests/test_util.cpp index 76ba8d27a4..36f8778082 100644 --- a/src/tests/test_util.cpp +++ b/src/tests/test_util.cpp @@ -9,6 +9,7 @@ #include "model/table/agree_set_factory.h" #include "model/table/column_layout_relation_data.h" #include "model/table/identifier_set.h" +#include "separator_validator.h" #include "table_config.h" namespace tests { @@ -235,4 +236,32 @@ INSTANTIATE_TEST_SUITE_P(TestLevenshteinSuite, TestLevenshtein, TestLevenshteinParam("", "book", 4), TestLevenshteinParam("randomstring", "juststring", 6))); +struct TestSeparatorValidationParam { + std::filesystem::path csv_path; + char separator; + char expected; + + TestSeparatorValidationParam(std::filesystem::path const& path, char sep, char exp) + : csv_path(path), separator(sep), expected(exp) {} +}; + +class TestSeparatorValidation : public ::testing::TestWithParam {}; + +TEST_P(TestSeparatorValidation, Default) { + TestSeparatorValidationParam const& p = GetParam(); + std::optional actual = util::ValidateSeparator(p.csv_path, p.separator); + EXPECT_EQ(actual.value_or('\0'), p.expected); +} + +INSTANTIATE_TEST_SUITE_P( + TestSeparatorValidationSuite, TestSeparatorValidation, + ::testing::Values(TestSeparatorValidationParam(test_data_dir / "Test1.csv", ',', ','), + TestSeparatorValidationParam(test_data_dir / "Test1.csv", ';', ';'), + TestSeparatorValidationParam(test_data_dir / "Test1.csv", '1', '\0'), + TestSeparatorValidationParam(test_data_dir / "TestFD.csv", ',', ','), + TestSeparatorValidationParam(test_data_dir / "TestFD.csv", ';', ','), + TestSeparatorValidationParam(test_data_dir / "adult.csv", ';', ';'), + TestSeparatorValidationParam(test_data_dir / "abalone.csv", ',', ','), + TestSeparatorValidationParam(test_data_dir / "abalone.csv", '.', ','))); + } // namespace tests