WIP, Continue writing additional parser tests, add big object flag to test cmake

This commit is contained in:
ado 2023-07-30 22:59:37 +02:00
parent 9bf1dd6041
commit 84a7d46cbf
3 changed files with 169 additions and 126 deletions

View File

@ -45,7 +45,6 @@ public:
if constexpr (ignore_header) { if constexpr (ignore_header) {
ignore_next(); ignore_next();
} else { } else {
// TODO read header after use_fields is called
header_ = reader_.get_header(); header_ = reader_.get_header();
} }
} else { } else {
@ -462,7 +461,7 @@ private:
constexpr static auto error_msg = " could not be opened"; constexpr static auto error_msg = " could not be opened";
if constexpr (string_error) { 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) { } else if constexpr (throw_on_error) {
throw ss::exception{file_name_ + error_msg}; throw ss::exception{file_name_ + error_msg};
} else { } else {
@ -471,10 +470,10 @@ private:
} }
void set_error_eof_reached() { 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) { 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) { } else if constexpr (throw_on_error) {
throw ss::exception{file_name_ + error_msg}; throw ss::exception{file_name_ + error_msg};
} else { } else {

View File

@ -12,6 +12,12 @@ if(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
target_compile_options(ssp INTERFACE -Wall -Wextra) target_compile_options(ssp INTERFACE -Wall -Wextra)
endif() endif()
if (MSVC)
add_compile_options(/bigobj)
else ()
add_compile_options(-Wa,-mbig-obj)
endif ()
include(FetchContent) include(FetchContent)
FetchContent_Declare( FetchContent_Declare(
DOCTEST DOCTEST

View File

@ -264,6 +264,8 @@ void write_to_file(const std::vector<std::string>& data,
} }
out << line << std::endl; out << line << std::endl;
// out.close();
// system(("unix2dos " + file_name).c_str());
} }
#define CHECK_EQ_CRLF(V1, V2) \ #define CHECK_EQ_CRLF(V1, V2) \
@ -272,7 +274,24 @@ void write_to_file(const std::vector<std::string>& data,
auto tmp2 = V2; \ auto tmp2 = V2; \
replace_all2(tmp1, "\r\n", "\n"); \ replace_all2(tmp1, "\r\n", "\n"); \
replace_all2(tmp2, "\r\n", "\n"); \ replace_all2(tmp2, "\r\n", "\n"); \
\
CHECK(tmp1 == tmp2); \ 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 { \ } else { \
CHECK(V1 == V2); \ CHECK(V1 == V2); \
} }
@ -280,8 +299,7 @@ void write_to_file(const std::vector<std::string>& data,
template <typename... Ts> template <typename... Ts>
void test_combinations(const std::vector<column>& input_data, void test_combinations(const std::vector<column>& input_data,
const std::string& delim, bool include_header) { const std::string& delim, bool include_header) {
// TODO test without string_error using setup = ss::setup<Ts...>;
using setup = ss::setup<Ts..., ss::string_error>;
unique_file_name f{"test_parser2"}; unique_file_name f{"test_parser2"};
std::vector<std::vector<field>> expected_data; std::vector<std::vector<field>> expected_data;
@ -366,7 +384,11 @@ void test_combinations(const std::vector<column>& input_data,
p.use_fields(fields); p.use_fields(fields);
if (!p.valid()) { if (!p.valid()) {
if constexpr (setup::string_error) {
std::cout << p.error_msg() << std::endl; std::cout << p.error_msg() << std::endl;
} else {
std::cout << "use_fields failed" << std::endl;
}
} }
REQUIRE(p.valid()); REQUIRE(p.valid());
@ -375,12 +397,15 @@ void test_combinations(const std::vector<column>& input_data,
auto check_error = [&p] { auto check_error = [&p] {
CHECK(p.valid()); CHECK(p.valid());
if (!p.valid()) { if (!p.valid()) {
if constexpr (setup::string_error) {
std::cout << p.error_msg() << std::endl; std::cout << p.error_msg() << std::endl;
} }
}
}; };
int num_columns = layout.size(); int num_columns = layout.size();
for (size_t i = 0; i < n + 1; ++i) { for (size_t i = 0; i < n + 1; ++i) {
try {
switch (num_columns) { switch (num_columns) {
case 1: { case 1: {
auto s0 = p.template get_next<std::string>(); auto s0 = p.template get_next<std::string>();
@ -395,7 +420,8 @@ void test_combinations(const std::vector<column>& input_data,
break; break;
} }
case 2: { case 2: {
auto [s0, s1] = p.template get_next<std::string, std::string>(); auto [s0, s1] =
p.template get_next<std::string, std::string>();
if (i < n) { if (i < n) {
check_error(); check_error();
// std::cout << s0 << ' ' << s1 << std::endl; // std::cout << s0 << ' ' << s1 << std::endl;
@ -413,7 +439,8 @@ void test_combinations(const std::vector<column>& input_data,
std::string>(); std::string>();
if (i < n) { if (i < n) {
check_error(); check_error();
// std::cout << s0 << ' ' << s1 << ' ' << s2 << std::endl; // std::cout << s0 << ' ' << s1 << ' ' << s2 <<
// std::endl;
CHECK_EQ_CRLF(s0, expected_data[i][layout[0]].value); CHECK_EQ_CRLF(s0, expected_data[i][layout[0]].value);
CHECK_EQ_CRLF(s1, expected_data[i][layout[1]].value); CHECK_EQ_CRLF(s1, expected_data[i][layout[1]].value);
CHECK_EQ_CRLF(s2, expected_data[i][layout[2]].value); CHECK_EQ_CRLF(s2, expected_data[i][layout[2]].value);
@ -425,8 +452,8 @@ void test_combinations(const std::vector<column>& input_data,
} }
case 4: { case 4: {
auto [s0, s1, s2, s3] = auto [s0, s1, s2, s3] =
p.template get_next<std::string, std::string, std::string, p.template get_next<std::string, std::string,
std::string>(); std::string, std::string>();
if (i < n) { if (i < n) {
check_error(); check_error();
/* /*
@ -445,11 +472,13 @@ void test_combinations(const std::vector<column>& input_data,
} }
case 5: { case 5: {
auto [s0, s1, s2, s3, s4] = auto [s0, s1, s2, s3, s4] =
p.template get_next<std::string, std::string, std::string, p.template get_next<std::string, std::string,
std::string, std::string>(); std::string, std::string,
std::string>();
if (i < n) { if (i < n) {
check_error(); check_error();
// std::cout << s0 << ' ' << s1 << ' ' << s2 << ' ' << s3 // std::cout << s0 << ' ' << s1 << ' ' << s2 << ' ' <<
// s3
// << ' ' << s4 << std::endl; // << ' ' << s4 << std::endl;
CHECK_EQ_CRLF(s0, expected_data[i][layout[0]].value); CHECK_EQ_CRLF(s0, expected_data[i][layout[0]].value);
CHECK_EQ_CRLF(s1, expected_data[i][layout[1]].value); CHECK_EQ_CRLF(s1, expected_data[i][layout[1]].value);
@ -467,6 +496,11 @@ void test_combinations(const std::vector<column>& input_data,
std::to_string(num_columns))); std::to_string(num_columns)));
break; break;
} }
} catch (const std::exception& e) {
if (i < n) {
throw;
}
}
} }
} }
} }
@ -521,54 +555,58 @@ void test_combinations_impl() {
for (const auto& columns : for (const auto& columns :
{columns0, columns1, columns2, columns3, columns4, columns5, {columns0, columns1, columns2, columns3, columns4, columns5,
columns6, columns7}) { columns6, columns7}) {
try {
test_combinations<Ts...>(columns, delimiter, false); test_combinations<Ts...>(columns, delimiter, false);
test_combinations<Ts...>(columns, delimiter, true); test_combinations<Ts...>(columns, delimiter, true);
} catch (std::exception& e) {
std::cout << typeid(ss::parser<Ts...>).name() << std::endl;
FAIL_CHECK(std::string{e.what()});
}
} }
} }
} }
} }
template <typename... Ts>
void test_combinations_with_error_options() {
test_combinations_impl<Ts...>();
test_combinations_impl<Ts..., ss::string_error>();
test_combinations_impl<Ts..., ss::throw_on_error>();
}
template <typename... Ts>
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<Ts...>();
test_combinations_with_error_options<Ts..., trim>();
test_combinations_with_error_options<Ts..., trimr>();
test_combinations_with_error_options<Ts..., triml>();
}
} /* namespace */ } /* namespace */
TEST_CASE("parser test various cases version 2") { TEST_CASE("parser test various cases version 2") {
using quote = ss::quote<'"'>; using quote = ss::quote<'"'>;
using escape = ss::escape<'\\'>; using escape = ss::escape<'\\'>;
using trim = ss::trim<' '>;
using triml = ss::trim_left<' '>;
using trimr = ss::trim_right<' '>;
using multiline = ss::multiline; using multiline = ss::multiline;
test_combinations_impl<>(); // TODO uncomment
test_combinations_impl<trim>(); // #ifdef CMAKE_GITHUB_CI
test_combinations_impl<triml>(); #if 0
test_combinations_impl<trimr>(); using multiline_r = ss::multiline_restricted<10>;
test_combinations_impl<escape>(); test_combinations_with_trim_and_error_options<>();
test_combinations_impl<escape, trim>(); test_combinations_with_trim_and_error_options<escape>();
test_combinations_impl<escape, triml>(); test_combinations_with_trim_and_error_options<quote>();
test_combinations_impl<escape, trimr>(); test_combinations_with_trim_and_error_options<escape, quote>();
test_combinations_with_trim_and_error_options<escape, multiline>();
test_combinations_impl<quote>(); test_combinations_with_trim_and_error_options<quote, multiline>();
test_combinations_impl<quote, trim>(); test_combinations_with_trim_and_error_options<escape, quote, multiline>();
test_combinations_impl<quote, triml>(); test_combinations_with_trim_and_error_options<escape, quote, multiline_r>();
test_combinations_impl<quote, trimr>(); #else
test_combinations_with_trim_and_error_options<escape, quote, multiline>();
test_combinations_impl<escape, quote>(); #endif
test_combinations_impl<escape, quote, trim>();
test_combinations_impl<escape, quote, triml>();
test_combinations_impl<escape, quote, trimr>();
test_combinations_impl<escape, multiline>();
test_combinations_impl<escape, multiline, trim>();
test_combinations_impl<escape, multiline, triml>();
test_combinations_impl<escape, multiline, trimr>();
test_combinations_impl<quote, multiline>();
test_combinations_impl<quote, multiline, trim>();
test_combinations_impl<quote, multiline, triml>();
test_combinations_impl<quote, multiline, trimr>();
test_combinations_impl<quote, escape, multiline>();
test_combinations_impl<quote, escape, multiline, trim>();
test_combinations_impl<quote, escape, multiline, triml>();
test_combinations_impl<quote, escape, multiline, trimr>();
} }