From e32905b59d839d34b96de63558c091817d7e4fb3 Mon Sep 17 00:00:00 2001 From: ado Date: Sat, 29 Jul 2023 22:44:01 +0200 Subject: [PATCH] WIP, Continue writing additional parser tests --- test/test_parser2.cpp | 48 ++++++++++++++++++++++++++++--------------- 1 file changed, 31 insertions(+), 17 deletions(-) diff --git a/test/test_parser2.cpp b/test/test_parser2.cpp index 2115e4b..67bd8e3 100644 --- a/test/test_parser2.cpp +++ b/test/test_parser2.cpp @@ -272,6 +272,17 @@ void write_to_file(const std::vector& data, out << line; } +#define CHECK_EQ_DBG(V1, V2) \ + if (V1 != V2) { \ + auto tmp1 = V1; \ + replace_all2(tmp1, "\n", "(_)"); \ + auto tmp2 = V2; \ + replace_all2(tmp2, "\n", "(_)"); \ + std::cout << "<" << tmp1 << ">" << std::endl; \ + std::cout << "<" << tmp2 << ">" << std::endl; \ + CHECK(V1 == V2); \ + } + template void test_combinations(const std::vector& input_data, const std::string& delim, bool include_header) { @@ -315,11 +326,13 @@ void test_combinations(const std::vector& input_data, auto data = generate_csv_data(raw_data, delim); write_to_file(data, delim, f.name); + /* std::cout << "[."; for (const auto& el : data) { std::cout << el << '.'; } std::cout << "]" << std::endl; + */ } auto layout_combinations = vector_combinations(layout, layout.size()); @@ -380,7 +393,7 @@ void test_combinations(const std::vector& input_data, if (i < n) { check_error(); // std::cout << s0 << std::endl; - CHECK(s0 == expected_data[i][layout[0]].value); + CHECK_EQ_DBG(s0, expected_data[i][layout[0]].value); } else { CHECK(p.eof()); CHECK(!p.valid()); @@ -392,8 +405,8 @@ void test_combinations(const std::vector& input_data, if (i < n) { check_error(); // std::cout << s0 << ' ' << s1 << std::endl; - CHECK(s0 == expected_data[i][layout[0]].value); - CHECK(s1 == expected_data[i][layout[1]].value); + CHECK_EQ_DBG(s0, expected_data[i][layout[0]].value); + CHECK_EQ_DBG(s1, expected_data[i][layout[1]].value); } else { CHECK(p.eof()); CHECK(!p.valid()); @@ -407,9 +420,9 @@ void test_combinations(const std::vector& input_data, if (i < n) { check_error(); // std::cout << s0 << ' ' << s1 << ' ' << s2 << std::endl; - CHECK(s0 == expected_data[i][layout[0]].value); - CHECK(s1 == expected_data[i][layout[1]].value); - CHECK(s2 == expected_data[i][layout[2]].value); + CHECK_EQ_DBG(s0, expected_data[i][layout[0]].value); + CHECK_EQ_DBG(s1, expected_data[i][layout[1]].value); + CHECK_EQ_DBG(s2, expected_data[i][layout[2]].value); } else { CHECK(p.eof()); CHECK(!p.valid()); @@ -426,10 +439,10 @@ void test_combinations(const std::vector& input_data, std::cout << s0 << ' ' << s1 << ' ' << s2 << ' ' << s3 << std::endl; */ - CHECK(s0 == expected_data[i][layout[0]].value); - CHECK(s1 == expected_data[i][layout[1]].value); - CHECK(s2 == expected_data[i][layout[2]].value); - CHECK(s3 == expected_data[i][layout[3]].value); + CHECK_EQ_DBG(s0, expected_data[i][layout[0]].value); + CHECK_EQ_DBG(s1, expected_data[i][layout[1]].value); + CHECK_EQ_DBG(s2, expected_data[i][layout[2]].value); + CHECK_EQ_DBG(s3, expected_data[i][layout[3]].value); } else { CHECK(p.eof()); CHECK(!p.valid()); @@ -444,11 +457,11 @@ void test_combinations(const std::vector& input_data, check_error(); // std::cout << s0 << ' ' << s1 << ' ' << s2 << ' ' << s3 // << ' ' << s4 << std::endl; - CHECK(s0 == expected_data[i][layout[0]].value); - CHECK(s1 == expected_data[i][layout[1]].value); - CHECK(s2 == expected_data[i][layout[2]].value); - CHECK(s3 == expected_data[i][layout[3]].value); - CHECK(s4 == expected_data[i][layout[4]].value); + CHECK_EQ_DBG(s0, expected_data[i][layout[0]].value); + CHECK_EQ_DBG(s1, expected_data[i][layout[1]].value); + CHECK_EQ_DBG(s2, expected_data[i][layout[2]].value); + CHECK_EQ_DBG(s3, expected_data[i][layout[3]].value); + CHECK_EQ_DBG(s4, expected_data[i][layout[4]].value); } else { CHECK(p.eof()); CHECK(!p.valid()); @@ -542,9 +555,10 @@ TEST_CASE("parser test various cases version 2") { test_combinations_impl<>(); test_combinations_impl(); + /* TODO uncomment test_combinations_impl(); test_combinations_impl(); - /* TODO uncomment + test_combinations_impl(); test_combinations_impl(); test_combinations_impl(); @@ -569,10 +583,10 @@ TEST_CASE("parser test various cases version 2") { test_combinations_impl(); test_combinations_impl(); test_combinations_impl(); - */ test_combinations_impl(); test_combinations_impl(); test_combinations_impl(); + */ test_combinations_impl(); }