diff --git a/include/ss/parser.hpp b/include/ss/parser.hpp index 02295ec..5c74510 100644 --- a/include/ss/parser.hpp +++ b/include/ss/parser.hpp @@ -45,7 +45,6 @@ public: if constexpr (ignore_header) { ignore_next(); } else { - // TODO read header after use_fields is called header_ = reader_.get_header(); } } else { @@ -462,7 +461,7 @@ private: constexpr static auto error_msg = " could not be opened"; if constexpr (string_error) { - error_.append(file_name_).append(" could not be opened"); + error_.append(file_name_).append(error_msg); } else if constexpr (throw_on_error) { throw ss::exception{file_name_ + error_msg}; } else { @@ -471,10 +470,10 @@ private: } void set_error_eof_reached() { - constexpr static auto error_msg = " reached end of file"; + constexpr static auto error_msg = " read on end of file"; if constexpr (string_error) { - error_.append(file_name_).append(" reached end of file"); + error_.append(file_name_).append(error_msg); } else if constexpr (throw_on_error) { throw ss::exception{file_name_ + error_msg}; } else { diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 47c2998..aadeda3 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -12,6 +12,12 @@ if(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang") target_compile_options(ssp INTERFACE -Wall -Wextra) endif() +if (MSVC) + add_compile_options(/bigobj) +else () + add_compile_options(-Wa,-mbig-obj) +endif () + include(FetchContent) FetchContent_Declare( DOCTEST diff --git a/test/test_parser2.cpp b/test/test_parser2.cpp index cfbda12..abf3317 100644 --- a/test/test_parser2.cpp +++ b/test/test_parser2.cpp @@ -264,6 +264,8 @@ void write_to_file(const std::vector& data, } out << line << std::endl; + // out.close(); + // system(("unix2dos " + file_name).c_str()); } #define CHECK_EQ_CRLF(V1, V2) \ @@ -272,7 +274,24 @@ void write_to_file(const std::vector& data, auto tmp2 = V2; \ replace_all2(tmp1, "\r\n", "\n"); \ replace_all2(tmp2, "\r\n", "\n"); \ + \ CHECK(tmp1 == tmp2); \ + \ + if (tmp1 != tmp2) { \ + replace_all2(tmp1, "\r", "(r)"); \ + replace_all2(tmp2, "\r", "(r)"); \ + \ + replace_all2(tmp1, "\n", "(n)"); \ + replace_all2(tmp2, "\n", "(n)"); \ + \ + replace_all2(tmp1, " ", "_"); \ + replace_all2(tmp2, " ", "_"); \ + \ + std::cout << "<" << tmp1 << ">" << std::endl; \ + std::cout << "<" << tmp2 << ">" << std::endl; \ + std::cout << "----------------" << std::endl; \ + } \ + \ } else { \ CHECK(V1 == V2); \ } @@ -280,8 +299,7 @@ void write_to_file(const std::vector& data, template void test_combinations(const std::vector& input_data, const std::string& delim, bool include_header) { - // TODO test without string_error - using setup = ss::setup; + using setup = ss::setup; unique_file_name f{"test_parser2"}; std::vector> expected_data; @@ -366,7 +384,11 @@ void test_combinations(const std::vector& input_data, p.use_fields(fields); if (!p.valid()) { - std::cout << p.error_msg() << std::endl; + if constexpr (setup::string_error) { + std::cout << p.error_msg() << std::endl; + } else { + std::cout << "use_fields failed" << std::endl; + } } REQUIRE(p.valid()); @@ -375,97 +397,109 @@ void test_combinations(const std::vector& input_data, auto check_error = [&p] { CHECK(p.valid()); if (!p.valid()) { - std::cout << p.error_msg() << std::endl; + if constexpr (setup::string_error) { + std::cout << p.error_msg() << std::endl; + } } }; int num_columns = layout.size(); for (size_t i = 0; i < n + 1; ++i) { - switch (num_columns) { - case 1: { - auto s0 = p.template get_next(); - if (i < n) { - check_error(); - // std::cout << s0 << std::endl; - CHECK_EQ_CRLF(s0, expected_data[i][layout[0]].value); - } else { - CHECK(p.eof()); - CHECK(!p.valid()); + try { + switch (num_columns) { + case 1: { + auto s0 = p.template get_next(); + if (i < n) { + check_error(); + // std::cout << s0 << std::endl; + CHECK_EQ_CRLF(s0, expected_data[i][layout[0]].value); + } else { + CHECK(p.eof()); + CHECK(!p.valid()); + } + break; } - break; - } - case 2: { - auto [s0, s1] = p.template get_next(); - if (i < n) { - check_error(); - // std::cout << s0 << ' ' << s1 << std::endl; - CHECK_EQ_CRLF(s0, expected_data[i][layout[0]].value); - CHECK_EQ_CRLF(s1, expected_data[i][layout[1]].value); - } else { - CHECK(p.eof()); - CHECK(!p.valid()); + case 2: { + auto [s0, s1] = + p.template get_next(); + if (i < n) { + check_error(); + // std::cout << s0 << ' ' << s1 << std::endl; + CHECK_EQ_CRLF(s0, expected_data[i][layout[0]].value); + CHECK_EQ_CRLF(s1, expected_data[i][layout[1]].value); + } else { + CHECK(p.eof()); + CHECK(!p.valid()); + } + break; } - break; - } - case 3: { - auto [s0, s1, s2] = - p.template get_next(); - if (i < n) { - check_error(); - // std::cout << s0 << ' ' << s1 << ' ' << s2 << std::endl; - CHECK_EQ_CRLF(s0, expected_data[i][layout[0]].value); - CHECK_EQ_CRLF(s1, expected_data[i][layout[1]].value); - CHECK_EQ_CRLF(s2, expected_data[i][layout[2]].value); - } else { - CHECK(p.eof()); - CHECK(!p.valid()); + case 3: { + auto [s0, s1, s2] = + p.template get_next(); + if (i < n) { + check_error(); + // std::cout << s0 << ' ' << s1 << ' ' << s2 << + // std::endl; + CHECK_EQ_CRLF(s0, expected_data[i][layout[0]].value); + CHECK_EQ_CRLF(s1, expected_data[i][layout[1]].value); + CHECK_EQ_CRLF(s2, expected_data[i][layout[2]].value); + } else { + CHECK(p.eof()); + CHECK(!p.valid()); + } + break; } - break; - } - case 4: { - auto [s0, s1, s2, s3] = - p.template get_next(); - if (i < n) { - check_error(); - /* - std::cout << s0 << ' ' << s1 << ' ' << s2 << ' ' << s3 - << std::endl; - */ - CHECK_EQ_CRLF(s0, expected_data[i][layout[0]].value); - CHECK_EQ_CRLF(s1, expected_data[i][layout[1]].value); - CHECK_EQ_CRLF(s2, expected_data[i][layout[2]].value); - CHECK_EQ_CRLF(s3, expected_data[i][layout[3]].value); - } else { - CHECK(p.eof()); - CHECK(!p.valid()); + case 4: { + auto [s0, s1, s2, s3] = + p.template get_next(); + if (i < n) { + check_error(); + /* + std::cout << s0 << ' ' << s1 << ' ' << s2 << ' ' << s3 + << std::endl; + */ + CHECK_EQ_CRLF(s0, expected_data[i][layout[0]].value); + CHECK_EQ_CRLF(s1, expected_data[i][layout[1]].value); + CHECK_EQ_CRLF(s2, expected_data[i][layout[2]].value); + CHECK_EQ_CRLF(s3, expected_data[i][layout[3]].value); + } else { + CHECK(p.eof()); + CHECK(!p.valid()); + } + break; } - break; - } - case 5: { - auto [s0, s1, s2, s3, s4] = - p.template get_next(); - if (i < n) { - check_error(); - // std::cout << s0 << ' ' << s1 << ' ' << s2 << ' ' << s3 - // << ' ' << s4 << std::endl; - CHECK_EQ_CRLF(s0, expected_data[i][layout[0]].value); - CHECK_EQ_CRLF(s1, expected_data[i][layout[1]].value); - CHECK_EQ_CRLF(s2, expected_data[i][layout[2]].value); - CHECK_EQ_CRLF(s3, expected_data[i][layout[3]].value); - CHECK_EQ_CRLF(s4, expected_data[i][layout[4]].value); - } else { - CHECK(p.eof()); - CHECK(!p.valid()); + case 5: { + auto [s0, s1, s2, s3, s4] = + p.template get_next(); + if (i < n) { + check_error(); + // std::cout << s0 << ' ' << s1 << ' ' << s2 << ' ' << + // s3 + // << ' ' << s4 << std::endl; + CHECK_EQ_CRLF(s0, expected_data[i][layout[0]].value); + CHECK_EQ_CRLF(s1, expected_data[i][layout[1]].value); + CHECK_EQ_CRLF(s2, expected_data[i][layout[2]].value); + CHECK_EQ_CRLF(s3, expected_data[i][layout[3]].value); + CHECK_EQ_CRLF(s4, expected_data[i][layout[4]].value); + } else { + CHECK(p.eof()); + CHECK(!p.valid()); + } + break; + } + default: + FAIL(("Invalid number of columns: " + + std::to_string(num_columns))); + break; + } + } catch (const std::exception& e) { + if (i < n) { + throw; } - break; - } - default: - FAIL(("Invalid number of columns: " + - std::to_string(num_columns))); - break; } } } @@ -521,54 +555,58 @@ void test_combinations_impl() { for (const auto& columns : {columns0, columns1, columns2, columns3, columns4, columns5, columns6, columns7}) { - test_combinations(columns, delimiter, false); - test_combinations(columns, delimiter, true); + try { + test_combinations(columns, delimiter, false); + test_combinations(columns, delimiter, true); + } catch (std::exception& e) { + std::cout << typeid(ss::parser).name() << std::endl; + FAIL_CHECK(std::string{e.what()}); + } } } } } + +template +void test_combinations_with_error_options() { + test_combinations_impl(); + test_combinations_impl(); + test_combinations_impl(); +} + +template +void test_combinations_with_trim_and_error_options() { + using trim = ss::trim<' '>; + using trimr = ss::trim_right<' '>; + using triml = ss::trim_left<' '>; + + test_combinations_with_error_options(); + test_combinations_with_error_options(); + test_combinations_with_error_options(); + test_combinations_with_error_options(); +} + } /* namespace */ TEST_CASE("parser test various cases version 2") { using quote = ss::quote<'"'>; using escape = ss::escape<'\\'>; - using trim = ss::trim<' '>; - using triml = ss::trim_left<' '>; - using trimr = ss::trim_right<' '>; using multiline = ss::multiline; - test_combinations_impl<>(); - test_combinations_impl(); - test_combinations_impl(); - test_combinations_impl(); +// TODO uncomment +// #ifdef CMAKE_GITHUB_CI +#if 0 + using multiline_r = ss::multiline_restricted<10>; - test_combinations_impl(); - test_combinations_impl(); - test_combinations_impl(); - test_combinations_impl(); - - test_combinations_impl(); - test_combinations_impl(); - test_combinations_impl(); - test_combinations_impl(); - - test_combinations_impl(); - test_combinations_impl(); - test_combinations_impl(); - test_combinations_impl(); - - test_combinations_impl(); - test_combinations_impl(); - test_combinations_impl(); - test_combinations_impl(); - - test_combinations_impl(); - test_combinations_impl(); - test_combinations_impl(); - test_combinations_impl(); - - test_combinations_impl(); - test_combinations_impl(); - test_combinations_impl(); - test_combinations_impl(); + test_combinations_with_trim_and_error_options<>(); + test_combinations_with_trim_and_error_options(); + test_combinations_with_trim_and_error_options(); + test_combinations_with_trim_and_error_options(); + test_combinations_with_trim_and_error_options(); + test_combinations_with_trim_and_error_options(); + test_combinations_with_trim_and_error_options(); + test_combinations_with_trim_and_error_options(); +#else + test_combinations_with_trim_and_error_options(); +#endif }