From 05f87bc78b62bfc226cf91a11a904cee2cfb5241 Mon Sep 17 00:00:00 2001 From: ado Date: Sun, 25 Feb 2024 02:57:46 +0100 Subject: [PATCH] [skip ci] Fix line method --- include/ss/parser.hpp | 5 ++--- test/test_helpers.hpp | 4 ++-- test/test_parser1_1.cpp | 13 ++++++------- 3 files changed, 10 insertions(+), 12 deletions(-) diff --git a/include/ss/parser.hpp b/include/ss/parser.hpp index 50f61b0..5e6d370 100644 --- a/include/ss/parser.hpp +++ b/include/ss/parser.hpp @@ -102,7 +102,7 @@ public: } size_t line() const { - return reader_.line_number_ > 1 ? reader_.line_number_ - 1 + return reader_.line_number_ > 0 ? reader_.line_number_ - 1 : reader_.line_number_; } @@ -697,8 +697,7 @@ private: csv_data_buffer_{other.csv_data_buffer_}, csv_data_size_{other.csv_data_size_}, curr_char_{other.curr_char_}, crlf_{other.crlf_}, - line_number_{other.line_number_}, - chars_read_{other.chars_read_}, + line_number_{other.line_number_}, chars_read_{other.chars_read_}, next_line_size_{other.next_line_size_} { other.buffer_ = nullptr; other.next_line_buffer_ = nullptr; diff --git a/test/test_helpers.hpp b/test/test_helpers.hpp index 89477c8..f6a4b34 100644 --- a/test/test_helpers.hpp +++ b/test/test_helpers.hpp @@ -78,8 +78,8 @@ struct unique_file_name { unique_file_name(const std::string& test) { do { - name = "random_" + test + "_" + std::to_string(i++) + "_" + - time_now_rand() + "_file.csv"; + name = "random_file_test_" + test + "_" + std::to_string(i++) + + "_" + time_now_rand() + "_file.csv"; } while (std::filesystem::exists(name)); } diff --git a/test/test_parser1_1.cpp b/test/test_parser1_1.cpp index 681877f..42642d1 100644 --- a/test/test_parser1_1.cpp +++ b/test/test_parser1_1.cpp @@ -99,17 +99,17 @@ TEST_CASE_TEMPLATE("test position method", T, ParserOptionCombinations) { } } -// TODO uncomment -/* -TEST_CASE_TEMPLATE("test line method", BufferMode, std::true_type, - std::false_type) { - unique_file_name f{"test_parser"}; +TEST_CASE_TEMPLATE("test line method", T, ParserOptionCombinations) { + constexpr auto buffer_mode = T::BufferMode::value; + using ErrorMode = typename T::ErrorMode; + + unique_file_name f{"line_method"}; std::vector data = {{"1", "21", "x"}, {"321", "4", "y"}, {"54", "6", "zz"}, {"7", "876", "uuuu"}, {"910", "10", "v"}, {"10", "321", "ww"}}; make_and_write(f.name, data); - auto [p, buff] = make_parser(f.name); + auto [p, buff] = make_parser(f.name); auto expected_line = 0; CHECK_EQ(p.line(), expected_line); @@ -122,7 +122,6 @@ TEST_CASE_TEMPLATE("test line method", BufferMode, std::true_type, CHECK_EQ(p.line(), data.size()); } -*/ TEST_CASE_TEMPLATE("parser test various valid cases", T, ParserOptionCombinations) {