get rid of maybe-uninitialized warnings

This commit is contained in:
ado
2021-02-01 00:56:42 +01:00
parent 035e27c5ab
commit d887dff82a
6 changed files with 88 additions and 117 deletions

View File

@@ -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<int>(buff("5"));
auto tup = c.convert<int>("5");
REQUIRE(c.valid());
CHECK(tup == 5);
}
{
auto tup = c.convert<int, void>(buff("5,junk"));
auto tup = c.convert<int, void>("5,junk");
REQUIRE(c.valid());
CHECK(tup == 5);
}
{
auto tup = c.convert<void, int>(buff("junk,5"));
auto tup = c.convert<void, int>("junk,5");
REQUIRE(c.valid());
CHECK(tup == 5);
}
{
auto tup = c.convert<int, void, void>(buff("5\njunk\njunk"), "\n");
auto tup = c.convert<int, void, void>("5\njunk\njunk", "\n");
REQUIRE(c.valid());
CHECK(tup == 5);
}
{
auto tup = c.convert<void, int, void>(buff("junk 5 junk"), " ");
auto tup = c.convert<void, int, void>("junk 5 junk", " ");
REQUIRE(c.valid());
CHECK(tup == 5);
}
{
auto tup = c.convert<void, void, int>(buff("junk\tjunk\t5"), "\t");
auto tup = c.convert<void, void, int>("junk\tjunk\t5", "\t");
REQUIRE(c.valid());
CHECK(tup == 5);
}
{
auto tup =
c.convert<void, void, std::optional<int>>(buff("junk\tjunk\t5"),
"\t");
c.convert<void, void, std::optional<int>>("junk\tjunk\t5", "\t");
REQUIRE(c.valid());
REQUIRE(tup.has_value());
CHECK(tup == 5);
}
{
auto tup = c.convert<int, double, void>(buff("5,6.6,junk"));
auto tup = c.convert<int, double, void>("5,6.6,junk");
REQUIRE(c.valid());
CHECK(tup == std::make_tuple(5, 6.6));
}
{
auto tup = c.convert<int, void, double>(buff("5,junk,6.6"));
auto tup = c.convert<int, void, double>("5,junk,6.6");
REQUIRE(c.valid());
CHECK(tup == std::make_tuple(5, 6.6));
}
{
auto tup = c.convert<void, int, double>(buff("junk;5;6.6"), ";");
auto tup = c.convert<void, int, double>("junk;5;6.6", ";");
REQUIRE(c.valid());
CHECK(tup == std::make_tuple(5, 6.6));
}
{
auto tup =
c.convert<void, std::optional<int>, double>(buff("junk;5;6.6"),
";");
c.convert<void, std::optional<int>, 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<void, std::optional<int>, double>(buff("junk;5.4;6.6"),
";");
c.convert<void, std::optional<int>, double>("junk;5.4;6.6", ";");
REQUIRE(c.valid());
REQUIRE(!std::get<0>(tup).has_value());
CHECK(tup == std::make_tuple(std::optional<int>{}, 6.6));
}
{
auto tup = c.convert<void, std::variant<int, double>,
double>(buff("junk;5;6.6"), ";");
auto tup =
c.convert<void, std::variant<int, double>, double>("junk;5;6.6",
";");
REQUIRE(c.valid());
REQUIRE(std::holds_alternative<int>(std::get<0>(tup)));
CHECK(tup == std::make_tuple(std::variant<int, double>{5}, 6.6));
}
{
auto tup = c.convert<void, std::variant<int, double>,
double>(buff("junk;5.5;6.6"), ";");
auto tup =
c.convert<void, std::variant<int, double>, double>("junk;5.5;6.6",
";");
REQUIRE(c.valid());
REQUIRE(std::holds_alternative<double>(std::get<0>(tup)));
CHECK(tup == std::make_tuple(std::variant<int, double>{5.5}, 6.6));
@@ -113,63 +112,60 @@ TEST_CASE("testing valid conversions") {
TEST_CASE("testing invalid conversions") {
ss::converter c;
c.convert<int>(buff(""));
c.convert<int>("");
REQUIRE(!c.valid());
c.convert<int, void>(buff(""));
c.convert<int, void>("");
REQUIRE(!c.valid());
c.convert<int, void>(buff(",junk"));
c.convert<int, void>(",junk");
REQUIRE(!c.valid());
c.convert<void, int>(buff("junk,"));
c.convert<void, int>("junk,");
REQUIRE(!c.valid());
c.convert<int>(buff("x"));
c.convert<int>("x");
REQUIRE(!c.valid());
c.convert<int, void>(buff("x"));
c.convert<int, void>("x");
REQUIRE(!c.valid());
c.convert<int, void>(buff("x,junk"));
c.convert<int, void>("x,junk");
REQUIRE(!c.valid());
c.convert<void, int>(buff("junk,x"));
c.convert<void, int>("junk,x");
REQUIRE(!c.valid());
c.convert<void, std::variant<int, double>, double>(buff("junk;.5.5;6"),
";");
c.convert<void, std::variant<int, double>, double>("junk;.5.5;6", ";");
REQUIRE(!c.valid());
}
TEST_CASE("testing ss:ax restriction (all except)") {
ss::converter c;
c.convert<ss::ax<int, 0>>(buff("0"));
c.convert<ss::ax<int, 0>>("0");
REQUIRE(!c.valid());
c.convert<ss::ax<int, 0, 1, 2>>(buff("1"));
c.convert<ss::ax<int, 0, 1, 2>>("1");
REQUIRE(!c.valid());
c.convert<void, char, ss::ax<int, 0, 1, 2>>(buff("junk,c,1"));
c.convert<void, char, ss::ax<int, 0, 1, 2>>("junk,c,1");
REQUIRE(!c.valid());
c.convert<ss::ax<int, 1>, char>(buff("1,c"));
c.convert<ss::ax<int, 1>, char>("1,c");
REQUIRE(!c.valid());
{
int tup = c.convert<ss::ax<int, 1>>(buff("3"));
int tup = c.convert<ss::ax<int, 1>>("3");
REQUIRE(c.valid());
CHECK(tup == 3);
}
{
std::tuple<char, int> tup =
c.convert<char, ss::ax<int, 1>>(buff("c,3"));
std::tuple<char, int> tup = c.convert<char, ss::ax<int, 1>>("c,3");
REQUIRE(c.valid());
CHECK(tup == std::make_tuple('c', 3));
}
{
std::tuple<int, char> tup =
c.convert<ss::ax<int, 1>, char>(buff("3,c"));
std::tuple<int, char> tup = c.convert<ss::ax<int, 1>, 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<ss::nx<int, 1>>(buff("3"));
c.convert<ss::nx<int, 1>>("3");
REQUIRE(!c.valid());
c.convert<char, ss::nx<int, 1, 2, 69>>(buff("c,3"));
c.convert<char, ss::nx<int, 1, 2, 69>>("c,3");
REQUIRE(!c.valid());
c.convert<ss::nx<int, 1>, char>(buff("3,c"));
c.convert<ss::nx<int, 1>, char>("3,c");
REQUIRE(!c.valid());
{
auto tup = c.convert<ss::nx<int, 3>>(buff("3"));
auto tup = c.convert<ss::nx<int, 3>>("3");
REQUIRE(c.valid());
CHECK(tup == 3);
}
{
auto tup = c.convert<ss::nx<int, 0, 1, 2>>(buff("2"));
auto tup = c.convert<ss::nx<int, 0, 1, 2>>("2");
REQUIRE(c.valid());
CHECK(tup == 2);
}
{
auto tup =
c.convert<char, void, ss::nx<int, 0, 1, 2>>(buff("c,junk,1"));
auto tup = c.convert<char, void, ss::nx<int, 0, 1, 2>>("c,junk,1");
REQUIRE(c.valid());
CHECK(tup == std::make_tuple('c', 1));
}
{
auto tup = c.convert<ss::nx<int, 1>, char>(buff("1,c"));
auto tup = c.convert<ss::nx<int, 1>, 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<ss::ir<int, 0, 2>>(buff("3"));
c.convert<ss::ir<int, 0, 2>>("3");
REQUIRE(!c.valid());
c.convert<char, ss::ir<int, 4, 69>>(buff("c,3"));
c.convert<char, ss::ir<int, 4, 69>>("c,3");
REQUIRE(!c.valid());
c.convert<ss::ir<int, 1, 2>, char>(buff("3,c"));
c.convert<ss::ir<int, 1, 2>, char>("3,c");
REQUIRE(!c.valid());
{
auto tup = c.convert<ss::ir<int, 1, 5>>(buff("3"));
auto tup = c.convert<ss::ir<int, 1, 5>>("3");
REQUIRE(c.valid());
CHECK(tup == 3);
}
{
auto tup = c.convert<ss::ir<int, 0, 2>>(buff("2"));
auto tup = c.convert<ss::ir<int, 0, 2>>("2");
REQUIRE(c.valid());
CHECK(tup == 2);
}
{
auto tup = c.convert<char, void, ss::ir<int, 0, 1>>(buff("c,junk,1"));
auto tup = c.convert<char, void, ss::ir<int, 0, 1>>("c,junk,1");
REQUIRE(c.valid());
CHECK(tup == std::make_tuple('c', 1));
}
{
auto tup = c.convert<ss::ir<int, 1, 20>, char>(buff("1,c"));
auto tup = c.convert<ss::ir<int, 1, 20>, 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<ss::oor<int, 1, 5>>(buff("3"));
c.convert<ss::oor<int, 1, 5>>("3");
REQUIRE(!c.valid());
c.convert<ss::oor<int, 0, 2>>(buff("2"));
c.convert<ss::oor<int, 0, 2>>("2");
REQUIRE(!c.valid());
c.convert<char, ss::oor<int, 0, 1>, void>(buff("c,1,junk"));
c.convert<char, ss::oor<int, 0, 1>, void>("c,1,junk");
REQUIRE(!c.valid());
c.convert<ss::oor<int, 1, 20>, char>(buff("1,c"));
c.convert<ss::oor<int, 1, 20>, char>("1,c");
REQUIRE(!c.valid());
{
auto tup = c.convert<ss::oor<int, 0, 2>>(buff("3"));
auto tup = c.convert<ss::oor<int, 0, 2>>("3");
REQUIRE(c.valid());
CHECK(tup == 3);
}
{
auto tup = c.convert<char, void, ss::oor<int, 4, 69>>(buff("c,junk,3"));
auto tup = c.convert<char, void, ss::oor<int, 4, 69>>("c,junk,3");
REQUIRE(c.valid());
CHECK(tup == std::make_tuple('c', 3));
}
{
auto tup = c.convert<ss::oor<int, 1, 2>, char>(buff("3,c"));
auto tup = c.convert<ss::oor<int, 1, 2>, 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<ss::ne<std::string>>(buff(""));
c.convert<ss::ne<std::string>>("");
REQUIRE(!c.valid());
c.convert<int, ss::ne<std::string>>(buff("3,"));
c.convert<int, ss::ne<std::string>>("3,");
REQUIRE(!c.valid());
c.convert<ss::ne<std::string>, int>(buff(",3"));
c.convert<ss::ne<std::string>, int>(",3");
REQUIRE(!c.valid());
c.convert<void, ss::ne<std::string>, int>(buff("junk,,3"));
c.convert<void, ss::ne<std::string>, int>("junk,,3");
REQUIRE(!c.valid());
c.convert<ss::ne<std::vector<int>>>(buff(""));
c.convert<ss::ne<std::vector<int>>>("");
REQUIRE(!c.valid());
{
auto tup = c.convert<ss::ne<std::string>>(buff("s"));
auto tup = c.convert<ss::ne<std::string>>("s");
REQUIRE(c.valid());
CHECK(tup == "s");
}
{
auto tup =
c.convert<std::optional<int>, ss::ne<std::string>>(buff("1,s"));
auto tup = c.convert<std::optional<int>, ss::ne<std::string>>("1,s");
REQUIRE(c.valid());
CHECK(tup == std::make_tuple(1, "s"));
}
{
auto tup = c.convert<ss::ne<std::vector<int>>>(buff("{1 2 3}"));
auto tup = c.convert<ss::ne<std::vector<int>>>("{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<ss::lt<int, 3>>(buff("3"));
c.convert<ss::lt<int, 3>>("3");
REQUIRE(!c.valid());
c.convert<ss::lt<int, 2>>(buff("3"));
c.convert<ss::lt<int, 2>>("3");
REQUIRE(!c.valid());
c.convert<ss::gt<int, 3>>(buff("3"));
c.convert<ss::gt<int, 3>>("3");
REQUIRE(!c.valid());
c.convert<ss::gt<int, 4>>(buff("3"));
c.convert<ss::gt<int, 4>>("3");
REQUIRE(!c.valid());
c.convert<ss::lte<int, 2>>(buff("3"));
c.convert<ss::lte<int, 2>>("3");
REQUIRE(!c.valid());
c.convert<ss::gte<int, 4>>(buff("3"));
c.convert<ss::gte<int, 4>>("3");
REQUIRE(!c.valid());
{
auto tup = c.convert<ss::lt<int, 4>>(buff("3"));
auto tup = c.convert<ss::lt<int, 4>>("3");
REQUIRE(c.valid());
CHECK(tup == 3);
}
{
auto tup = c.convert<ss::gt<int, 2>>(buff("3"));
auto tup = c.convert<ss::gt<int, 2>>("3");
REQUIRE(c.valid());
CHECK(tup == 3);
}
{
auto tup = c.convert<ss::lte<int, 4>>(buff("3"));
auto tup = c.convert<ss::lte<int, 4>>("3");
REQUIRE(c.valid());
CHECK(tup == 3);
}
{
auto tup = c.convert<ss::lte<int, 3>>(buff("3"));
auto tup = c.convert<ss::lte<int, 3>>("3");
REQUIRE(c.valid());
CHECK(tup == 3);
}
{
auto tup = c.convert<ss::gte<int, 2>>(buff("3"));
auto tup = c.convert<ss::gte<int, 2>>("3");
REQUIRE(c.valid());
CHECK(tup == 3);
}
{
auto tup = c.convert<ss::gte<int, 3>>(buff("3"));
auto tup = c.convert<ss::gte<int, 3>>("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<int>(buff("junk"));
c.convert<int>("junk");
CHECK(!c.valid());
CHECK(c.error_msg().empty());
c.set_error_mode(ss::error_mode::error_string);
c.convert<int>(buff("junk"));
c.convert<int>("junk");
CHECK(!c.valid());
CHECK(!c.error_msg().empty());
}
@@ -421,7 +415,7 @@ TEST_CASE("testing converter with quotes spacing and escaping") {
ss::converter<ss::trim<' '>> c;
auto tup = c.convert<std::string, std::string, double, char>(
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'));
}

View File

@@ -541,9 +541,6 @@ TEST_CASE("testing csv on multiple lines with quotes") {
while (!p.eof()) {
auto a = p.get_next<int, double, std::string>();
auto [x, y, z] = a;
std::cout << "=====================" << std::endl;
std::cout << x << ' ' << y << ' ' << z << std::endl;
i.emplace_back(ss::to_object<X>(a));
}
@@ -575,9 +572,6 @@ TEST_CASE("testing csv on multiple lines with escapes") {
while (!p.eof()) {
auto a = p.get_next<int, double, std::string>();
auto [x, y, z] = a;
std::cout << "=====================" << std::endl;
std::cout << x << ' ' << y << ' ' << z << std::endl;
i.emplace_back(ss::to_object<X>(a));
}

View File

@@ -4,8 +4,6 @@
#include <iostream>
#include <ss/splitter.hpp>
// TODO make ss::quote accept only one argument
namespace {
constexpr static auto combinations_size_default = 4;
size_t combinations_size = combinations_size_default;