diff --git a/test/test_parser.cpp b/test/test_parser.cpp index 865c3de..d1fc036 100644 --- a/test/test_parser.cpp +++ b/test/test_parser.cpp @@ -110,7 +110,12 @@ std::string make_buffer(const std::string& file_name) { out.reserve(sizeof(out) + 1); while (in >> tmp) { out += tmp; - out.append("\n"); + if (in.peek() == '\n') { + out += "\n"; + } + if (in.peek() == '\r') { + out += "\r\n"; + } } return out; } @@ -760,14 +765,28 @@ TEST_CASE("parser throw on error mode") { out << "junk" << std::endl; } - ss::parser p(f.name, ","); + { + auto [p, _] = make_parser(f.name, ","); - REQUIRE_FALSE(p.eof()); - try { - p.get_next(); - FAIL("Expected exception..."); - } catch (const std::exception& e) { - CHECK_FALSE(std::string{e.what()}.empty()); + REQUIRE_FALSE(p.eof()); + try { + p.get_next(); + FAIL("Expected exception..."); + } catch (const std::exception& e) { + CHECK_FALSE(std::string{e.what()}.empty()); + } + } + + { + auto [p, _] = make_parser(f.name, ","); + + REQUIRE_FALSE(p.eof()); + try { + p.get_next(); + FAIL("Expected exception..."); + } catch (const std::exception& e) { + CHECK_FALSE(std::string{e.what()}.empty()); + } } } @@ -778,7 +797,7 @@ static inline std::string no_quote(const std::string& s) { return s; } -template +template void test_quote_multiline() { unique_file_name f{"test_parser"}; std::vector data = {{1, 2, "\"x\r\nx\nx\""}, @@ -799,7 +818,10 @@ void test_quote_multiline() { } } - ss::parser, Ts...> p{f.name, ","}; + auto [p, buff] = + make_parser, Ts...>(f.name, + ","); + std::vector i; while (!p.eof()) { @@ -812,9 +834,10 @@ void test_quote_multiline() { } CHECK_EQ(i, data); - ss::parser, Ts...> p_no_multiline{f.name, ","}; + auto [p_no_multiline, __] = + make_parser, Ts...>(f.name, ","); while (!p.eof()) { - auto command = [&] { + auto command = [&p_no_multiline = p_no_multiline] { p_no_multiline.template get_next(); }; expect_error_on_command(p_no_multiline, command); @@ -822,9 +845,12 @@ void test_quote_multiline() { } TEST_CASE("parser test csv on multiple lines with quotes") { - test_quote_multiline(); - test_quote_multiline(); - test_quote_multiline(); + test_quote_multiline(); + test_quote_multiline(); + test_quote_multiline(); + test_quote_multiline(); + test_quote_multiline(); + test_quote_multiline(); } static inline std::string no_escape(std::string& s) { @@ -1743,4 +1769,3 @@ TEST_CASE("parser test various cases with empty lines") { test_ignore_empty({}); } -