From d887dff82a09ac56ebf978670bc1c40f790973e3 Mon Sep 17 00:00:00 2001 From: ado Date: Mon, 1 Feb 2021 00:56:42 +0100 Subject: [PATCH] get rid of maybe-uninitialized warnings --- include/ss/converter.hpp | 24 ++---- include/ss/parser.hpp | 5 -- include/ss/splitter.hpp | 4 +- test/test_converter.cpp | 164 +++++++++++++++++++-------------------- test/test_parser.cpp | 6 -- test/test_splitter.cpp | 2 - 6 files changed, 88 insertions(+), 117 deletions(-) diff --git a/include/ss/converter.hpp b/include/ss/converter.hpp index 2e95ac9..c3614a4 100644 --- a/include/ss/converter.hpp +++ b/include/ss/converter.hpp @@ -127,12 +127,11 @@ public: no_void_validator_tup_t convert( line_ptr_type line, const std::string& delim = default_delimiter) { input_ = split(line, delim); - /* TODO if (!splitter_.valid()) { - // set error - return {}; + set_error_line_not_split(); + no_void_validator_tup_t ret{}; + return ret; } - */ return convert(input_); } @@ -235,19 +234,10 @@ private: return error; } - void set_error_invalid_quotation() { + void set_error_line_not_split() { if (error_mode_ == error_mode::error_string) { string_error_.clear(); - string_error_.append("invalid quotation"); - } else { - bool_error_ = true; - } - } - - void set_error_unterminated_quote() { - if (error_mode_ == error_mode::error_string) { - string_error_.clear(); - string_error_.append("unterminated quote"); + string_error_.append("line not split correctly"); } else { bool_error_ = true; } @@ -293,9 +283,9 @@ private: template no_void_validator_tup_t convert_impl(const split_input& elems) { clear_error(); - no_void_validator_tup_t ret{}; if (sizeof...(Ts) != elems.size()) { set_error_number_of_colums(sizeof...(Ts), elems.size()); + no_void_validator_tup_t ret{}; return ret; } return extract_tuple(elems); @@ -368,7 +358,7 @@ private: no_void_validator_tup_t extract_tuple(const split_input& elems) { static_assert(!all_of::value, "at least one parameter must be non void"); - no_void_validator_tup_t ret; + no_void_validator_tup_t ret{}; extract_multiple<0, 0, Ts...>(ret, elems); return ret; } diff --git a/include/ss/parser.hpp b/include/ss/parser.hpp index 4f7dcd6..a94c71c 100644 --- a/include/ss/parser.hpp +++ b/include/ss/parser.hpp @@ -9,9 +9,6 @@ #include #include -// TODO remove -#include - namespace ss { template @@ -262,7 +259,6 @@ private: bool crlf; bool escaped_eol(size_t size) { - // escaped new line if constexpr (setup::escape::enabled) { const char* curr; for (curr = next_line_buffer_ + size - 1; @@ -277,7 +273,6 @@ private: } bool unterminated_quote() { - // unterimated quote if constexpr (ss::setup::quote::enabled) { if (next_line_converter_.unterminated_quote()) { return true; diff --git a/include/ss/splitter.hpp b/include/ss/splitter.hpp index e73b825..ae77ff2 100644 --- a/include/ss/splitter.hpp +++ b/include/ss/splitter.hpp @@ -428,8 +428,8 @@ private: std::vector output_; std::string string_error_; - bool bool_error_; - bool unterminated_quote_; + bool bool_error_{false}; + bool unterminated_quote_{false}; enum error_mode error_mode_ { error_mode::error_bool }; line_ptr_type begin_; line_ptr_type curr_; diff --git a/test/test_converter.cpp b/test/test_converter.cpp index fa2fab7..14c28ea 100644 --- a/test/test_converter.cpp +++ b/test/test_converter.cpp @@ -13,7 +13,7 @@ TEST_CASE("testing split") { {"x\t-\ty", {"x", "y"}, "\t-\t"}, {"x", {"x"}, ","}} // clang-format on ) { - auto split = c.split(buff(s), delim); + auto split = c.split(s, delim); CHECK(split.size() == expected.size()); for (size_t i = 0; i < split.size(); ++i) { auto s = std::string(split[i].first, split[i].second); @@ -26,84 +26,83 @@ TEST_CASE("testing valid conversions") { ss::converter c; { - auto tup = c.convert(buff("5")); + auto tup = c.convert("5"); REQUIRE(c.valid()); CHECK(tup == 5); } { - auto tup = c.convert(buff("5,junk")); + auto tup = c.convert("5,junk"); REQUIRE(c.valid()); CHECK(tup == 5); } { - auto tup = c.convert(buff("junk,5")); + auto tup = c.convert("junk,5"); REQUIRE(c.valid()); CHECK(tup == 5); } { - auto tup = c.convert(buff("5\njunk\njunk"), "\n"); + auto tup = c.convert("5\njunk\njunk", "\n"); REQUIRE(c.valid()); CHECK(tup == 5); } { - auto tup = c.convert(buff("junk 5 junk"), " "); + auto tup = c.convert("junk 5 junk", " "); REQUIRE(c.valid()); CHECK(tup == 5); } { - auto tup = c.convert(buff("junk\tjunk\t5"), "\t"); + auto tup = c.convert("junk\tjunk\t5", "\t"); REQUIRE(c.valid()); CHECK(tup == 5); } { auto tup = - c.convert>(buff("junk\tjunk\t5"), - "\t"); + c.convert>("junk\tjunk\t5", "\t"); REQUIRE(c.valid()); REQUIRE(tup.has_value()); CHECK(tup == 5); } { - auto tup = c.convert(buff("5,6.6,junk")); + auto tup = c.convert("5,6.6,junk"); REQUIRE(c.valid()); CHECK(tup == std::make_tuple(5, 6.6)); } { - auto tup = c.convert(buff("5,junk,6.6")); + auto tup = c.convert("5,junk,6.6"); REQUIRE(c.valid()); CHECK(tup == std::make_tuple(5, 6.6)); } { - auto tup = c.convert(buff("junk;5;6.6"), ";"); + auto tup = c.convert("junk;5;6.6", ";"); REQUIRE(c.valid()); CHECK(tup == std::make_tuple(5, 6.6)); } { auto tup = - c.convert, double>(buff("junk;5;6.6"), - ";"); + c.convert, double>("junk;5;6.6", ";"); REQUIRE(c.valid()); REQUIRE(std::get<0>(tup).has_value()); CHECK(tup == std::make_tuple(5, 6.6)); } { auto tup = - c.convert, double>(buff("junk;5.4;6.6"), - ";"); + c.convert, double>("junk;5.4;6.6", ";"); REQUIRE(c.valid()); REQUIRE(!std::get<0>(tup).has_value()); CHECK(tup == std::make_tuple(std::optional{}, 6.6)); } { - auto tup = c.convert, - double>(buff("junk;5;6.6"), ";"); + auto tup = + c.convert, double>("junk;5;6.6", + ";"); REQUIRE(c.valid()); REQUIRE(std::holds_alternative(std::get<0>(tup))); CHECK(tup == std::make_tuple(std::variant{5}, 6.6)); } { - auto tup = c.convert, - double>(buff("junk;5.5;6.6"), ";"); + auto tup = + c.convert, double>("junk;5.5;6.6", + ";"); REQUIRE(c.valid()); REQUIRE(std::holds_alternative(std::get<0>(tup))); CHECK(tup == std::make_tuple(std::variant{5.5}, 6.6)); @@ -113,63 +112,60 @@ TEST_CASE("testing valid conversions") { TEST_CASE("testing invalid conversions") { ss::converter c; - c.convert(buff("")); + c.convert(""); REQUIRE(!c.valid()); - c.convert(buff("")); + c.convert(""); REQUIRE(!c.valid()); - c.convert(buff(",junk")); + c.convert(",junk"); REQUIRE(!c.valid()); - c.convert(buff("junk,")); + c.convert("junk,"); REQUIRE(!c.valid()); - c.convert(buff("x")); + c.convert("x"); REQUIRE(!c.valid()); - c.convert(buff("x")); + c.convert("x"); REQUIRE(!c.valid()); - c.convert(buff("x,junk")); + c.convert("x,junk"); REQUIRE(!c.valid()); - c.convert(buff("junk,x")); + c.convert("junk,x"); REQUIRE(!c.valid()); - c.convert, double>(buff("junk;.5.5;6"), - ";"); + c.convert, double>("junk;.5.5;6", ";"); REQUIRE(!c.valid()); } TEST_CASE("testing ss:ax restriction (all except)") { ss::converter c; - c.convert>(buff("0")); + c.convert>("0"); REQUIRE(!c.valid()); - c.convert>(buff("1")); + c.convert>("1"); REQUIRE(!c.valid()); - c.convert>(buff("junk,c,1")); + c.convert>("junk,c,1"); REQUIRE(!c.valid()); - c.convert, char>(buff("1,c")); + c.convert, char>("1,c"); REQUIRE(!c.valid()); { - int tup = c.convert>(buff("3")); + int tup = c.convert>("3"); REQUIRE(c.valid()); CHECK(tup == 3); } { - std::tuple tup = - c.convert>(buff("c,3")); + std::tuple tup = c.convert>("c,3"); REQUIRE(c.valid()); CHECK(tup == std::make_tuple('c', 3)); } { - std::tuple tup = - c.convert, char>(buff("3,c")); + std::tuple tup = c.convert, char>("3,c"); REQUIRE(c.valid()); CHECK(tup == std::make_tuple(3, 'c')); } @@ -178,33 +174,32 @@ TEST_CASE("testing ss:ax restriction (all except)") { TEST_CASE("testing ss:nx restriction (none except)") { ss::converter c; - c.convert>(buff("3")); + c.convert>("3"); REQUIRE(!c.valid()); - c.convert>(buff("c,3")); + c.convert>("c,3"); REQUIRE(!c.valid()); - c.convert, char>(buff("3,c")); + c.convert, char>("3,c"); REQUIRE(!c.valid()); { - auto tup = c.convert>(buff("3")); + auto tup = c.convert>("3"); REQUIRE(c.valid()); CHECK(tup == 3); } { - auto tup = c.convert>(buff("2")); + auto tup = c.convert>("2"); REQUIRE(c.valid()); CHECK(tup == 2); } { - auto tup = - c.convert>(buff("c,junk,1")); + auto tup = c.convert>("c,junk,1"); REQUIRE(c.valid()); CHECK(tup == std::make_tuple('c', 1)); } { - auto tup = c.convert, char>(buff("1,c")); + auto tup = c.convert, char>("1,c"); REQUIRE(c.valid()); CHECK(tup == std::make_tuple(1, 'c')); } @@ -213,32 +208,32 @@ TEST_CASE("testing ss:nx restriction (none except)") { TEST_CASE("testing ss:ir restriction (in range)") { ss::converter c; - c.convert>(buff("3")); + c.convert>("3"); REQUIRE(!c.valid()); - c.convert>(buff("c,3")); + c.convert>("c,3"); REQUIRE(!c.valid()); - c.convert, char>(buff("3,c")); + c.convert, char>("3,c"); REQUIRE(!c.valid()); { - auto tup = c.convert>(buff("3")); + auto tup = c.convert>("3"); REQUIRE(c.valid()); CHECK(tup == 3); } { - auto tup = c.convert>(buff("2")); + auto tup = c.convert>("2"); REQUIRE(c.valid()); CHECK(tup == 2); } { - auto tup = c.convert>(buff("c,junk,1")); + auto tup = c.convert>("c,junk,1"); REQUIRE(c.valid()); CHECK(tup == std::make_tuple('c', 1)); } { - auto tup = c.convert, char>(buff("1,c")); + auto tup = c.convert, char>("1,c"); REQUIRE(c.valid()); CHECK(tup == std::make_tuple(1, 'c')); } @@ -247,32 +242,32 @@ TEST_CASE("testing ss:ir restriction (in range)") { TEST_CASE("testing ss:oor restriction (out of range)") { ss::converter c; - c.convert>(buff("3")); + c.convert>("3"); REQUIRE(!c.valid()); - c.convert>(buff("2")); + c.convert>("2"); REQUIRE(!c.valid()); - c.convert, void>(buff("c,1,junk")); + c.convert, void>("c,1,junk"); REQUIRE(!c.valid()); - c.convert, char>(buff("1,c")); + c.convert, char>("1,c"); REQUIRE(!c.valid()); { - auto tup = c.convert>(buff("3")); + auto tup = c.convert>("3"); REQUIRE(c.valid()); CHECK(tup == 3); } { - auto tup = c.convert>(buff("c,junk,3")); + auto tup = c.convert>("c,junk,3"); REQUIRE(c.valid()); CHECK(tup == std::make_tuple('c', 3)); } { - auto tup = c.convert, char>(buff("3,c")); + auto tup = c.convert, char>("3,c"); REQUIRE(c.valid()); CHECK(tup == std::make_tuple(3, 'c')); } @@ -294,34 +289,33 @@ inline bool ss::extract(const char* begin, const char* end, TEST_CASE("testing ss:ne restriction (not empty)") { ss::converter c; - c.convert>(buff("")); + c.convert>(""); REQUIRE(!c.valid()); - c.convert>(buff("3,")); + c.convert>("3,"); REQUIRE(!c.valid()); - c.convert, int>(buff(",3")); + c.convert, int>(",3"); REQUIRE(!c.valid()); - c.convert, int>(buff("junk,,3")); + c.convert, int>("junk,,3"); REQUIRE(!c.valid()); - c.convert>>(buff("")); + c.convert>>(""); REQUIRE(!c.valid()); { - auto tup = c.convert>(buff("s")); + auto tup = c.convert>("s"); REQUIRE(c.valid()); CHECK(tup == "s"); } { - auto tup = - c.convert, ss::ne>(buff("1,s")); + auto tup = c.convert, ss::ne>("1,s"); REQUIRE(c.valid()); CHECK(tup == std::make_tuple(1, "s")); } { - auto tup = c.convert>>(buff("{1 2 3}")); + auto tup = c.convert>>("{1 2 3}"); REQUIRE(c.valid()); CHECK(tup == extracted_vector); } @@ -330,56 +324,56 @@ TEST_CASE("testing ss:ne restriction (not empty)") { TEST_CASE("testing ss:lt ss::lte ss::gt ss::gte restriction (in range)") { ss::converter c; - c.convert>(buff("3")); + c.convert>("3"); REQUIRE(!c.valid()); - c.convert>(buff("3")); + c.convert>("3"); REQUIRE(!c.valid()); - c.convert>(buff("3")); + c.convert>("3"); REQUIRE(!c.valid()); - c.convert>(buff("3")); + c.convert>("3"); REQUIRE(!c.valid()); - c.convert>(buff("3")); + c.convert>("3"); REQUIRE(!c.valid()); - c.convert>(buff("3")); + c.convert>("3"); REQUIRE(!c.valid()); { - auto tup = c.convert>(buff("3")); + auto tup = c.convert>("3"); REQUIRE(c.valid()); CHECK(tup == 3); } { - auto tup = c.convert>(buff("3")); + auto tup = c.convert>("3"); REQUIRE(c.valid()); CHECK(tup == 3); } { - auto tup = c.convert>(buff("3")); + auto tup = c.convert>("3"); REQUIRE(c.valid()); CHECK(tup == 3); } { - auto tup = c.convert>(buff("3")); + auto tup = c.convert>("3"); REQUIRE(c.valid()); CHECK(tup == 3); } { - auto tup = c.convert>(buff("3")); + auto tup = c.convert>("3"); REQUIRE(c.valid()); CHECK(tup == 3); } { - auto tup = c.convert>(buff("3")); + auto tup = c.convert>("3"); REQUIRE(c.valid()); CHECK(tup == 3); } @@ -388,12 +382,12 @@ TEST_CASE("testing ss:lt ss::lte ss::gt ss::gte restriction (in range)") { TEST_CASE("testing error mode") { ss::converter c; - c.convert(buff("junk")); + c.convert("junk"); CHECK(!c.valid()); CHECK(c.error_msg().empty()); c.set_error_mode(ss::error_mode::error_string); - c.convert(buff("junk")); + c.convert("junk"); CHECK(!c.valid()); CHECK(!c.error_msg().empty()); } @@ -421,7 +415,7 @@ TEST_CASE("testing converter with quotes spacing and escaping") { ss::converter> c; auto tup = c.convert( - R"( just , some , 12.3 ,a )"); + buff(R"( just , some , 12.3 ,a )")); REQUIRE(c.valid()); CHECK(tup == std::make_tuple("just", "some", 12.3, 'a')); } diff --git a/test/test_parser.cpp b/test/test_parser.cpp index 905f1a2..896f0b9 100644 --- a/test/test_parser.cpp +++ b/test/test_parser.cpp @@ -541,9 +541,6 @@ TEST_CASE("testing csv on multiple lines with quotes") { while (!p.eof()) { auto a = p.get_next(); - auto [x, y, z] = a; - std::cout << "=====================" << std::endl; - std::cout << x << ' ' << y << ' ' << z << std::endl; i.emplace_back(ss::to_object(a)); } @@ -575,9 +572,6 @@ TEST_CASE("testing csv on multiple lines with escapes") { while (!p.eof()) { auto a = p.get_next(); - auto [x, y, z] = a; - std::cout << "=====================" << std::endl; - std::cout << x << ' ' << y << ' ' << z << std::endl; i.emplace_back(ss::to_object(a)); } diff --git a/test/test_splitter.cpp b/test/test_splitter.cpp index c2376ef..de1ff6f 100644 --- a/test/test_splitter.cpp +++ b/test/test_splitter.cpp @@ -4,8 +4,6 @@ #include #include -// TODO make ss::quote accept only one argument - namespace { constexpr static auto combinations_size_default = 4; size_t combinations_size = combinations_size_default;