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 authored and chernishev committed Sep 23, 2024
1 parent b4eee18 commit d9fdc83
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/tests/all_csv_configs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,4 +119,6 @@ CSVConfig const kTestDynamicFDUpdateBad3 =
CreateCsvConfig("dynamic_fd/TestDynamicUpdateBad3.csv", ',', true);
CSVConfig const kTestDynamicFDUpdateBad4 =
CreateCsvConfig("dynamic_fd/TestDynamicUpdateBad4.csv", ',', true);
CSVConfig const kTestSeparator = CreateCsvConfig("TestSeparator.csv", ',', false);
CSVConfig const kTestSeparator1 = CreateCsvConfig("TestSeparator1.csv", ',', false);
} // namespace tests
2 changes: 2 additions & 0 deletions src/tests/all_csv_configs.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,4 +99,6 @@ extern CSVConfig const kTestDynamicFDUpdateBad1;
extern CSVConfig const kTestDynamicFDUpdateBad2;
extern CSVConfig const kTestDynamicFDUpdateBad3;
extern CSVConfig const kTestDynamicFDUpdateBad4;
extern CSVConfig const kTestSeparator;
extern CSVConfig const kTestSeparator1;
} // namespace tests
32 changes: 32 additions & 0 deletions src/tests/test_util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,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"

namespace tests {

Expand Down Expand Up @@ -230,4 +231,35 @@ INSTANTIATE_TEST_SUITE_P(TestLevenshteinSuite, TestLevenshtein,
TestLevenshteinParam("", "book", 4),
TestLevenshteinParam("randomstring", "juststring", 6)));

struct TestSeparatorValidationParam {
CSVConfig csv_config;
char test_separator;
std::optional<char> expected_separator;
};

class TestSeparatorValidation : public ::testing::TestWithParam<TestSeparatorValidationParam> {};

TEST_P(TestSeparatorValidation, Default) {
TestSeparatorValidationParam const& p = GetParam();
std::optional<char> actual = util::ValidateSeparator(p.csv_config.path, p.test_separator).first;
EXPECT_EQ(actual, p.expected_separator);
}

INSTANTIATE_TEST_SUITE_P(TestSeparatorValidationSuite, TestSeparatorValidation,
::testing::Values(TestSeparatorValidationParam(kTest1, ',', ','),
TestSeparatorValidationParam(kTest1, ';', ';'),
TestSeparatorValidationParam(kTest1, '1', std::nullopt),
TestSeparatorValidationParam(kTestFD, ',', ','),
TestSeparatorValidationParam(kTestFD, ';', ','),
TestSeparatorValidationParam(kAdult, ';', ';'),
TestSeparatorValidationParam(kAdult, ',', ';'),
TestSeparatorValidationParam(kAbalone, ',', ','),
TestSeparatorValidationParam(kAbalone, '.', ','),
TestSeparatorValidationParam(kTestParse, ',', ','),
TestSeparatorValidationParam(kTestSeparator, ',', ','),
TestSeparatorValidationParam(kTestSeparator, ';', ','),
TestSeparatorValidationParam(kTestSeparator1, ',', ','),
TestSeparatorValidationParam(kTestSeparator1, ';',
';')));

} // namespace tests
3 changes: 3 additions & 0 deletions test_input_data/TestSeparator.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
"a,;b",c
"a;","b,c"
a,b;c
3 changes: 3 additions & 0 deletions test_input_data/TestSeparator1.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
,;,;,;
;,;,;,
,;,;,;

0 comments on commit d9fdc83

Please sign in to comment.