Skip to content

Commit

Permalink
Add tests for separator validation
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelS239 committed Dec 22, 2023
1 parent 7ca4b05 commit 9ce5ca8
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions src/tests/test_util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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<TestSeparatorValidationParam> {};

TEST_P(TestSeparatorValidation, Default) {
TestSeparatorValidationParam const& p = GetParam();
std::optional<char> 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

0 comments on commit 9ce5ca8

Please sign in to comment.