create seperate header for the splitter, move splitter tests to different cpp file

This commit is contained in:
ado
2021-01-17 02:15:06 +01:00
parent 69d6df12be
commit 263dba7626
5 changed files with 391 additions and 441 deletions

View File

@@ -16,105 +16,7 @@ public:
}
};
buffer buff;
TEST_CASE("testing splitter with escaping") {
std::vector<std::string> values{"10", "he\\\"llo",
"\\\"", "\\\"a\\,a\\\"",
"3.33", "a\\\""};
char buff[128];
// with quote
ss::splitter<ss::quote<'"'>, ss::escape<'\\'>> s;
std::string delim = ",";
for (size_t i = 0; i < values.size() * values.size(); ++i) {
std::string input1;
std::string input2;
for (size_t j = 0; j < values.size(); ++j) {
if (i & (1 << j) && j != 2 && j != 3) {
input1.append(values[j]);
input2.append(values.at(values.size() - 1 - j));
} else {
input1.append("\"" + values[j] + "\"");
input2.append("\"" + values.at(values.size() - 1 - j) + "\"");
}
input1.append(delim);
input2.append(delim);
}
input1.pop_back();
input2.pop_back();
input1.append("\0\"");
input2.append("\0\"");
memcpy(buff, input1.c_str(), input1.size() + 1);
auto tup1 = s.split(buff, delim);
CHECK(tup1.size() == 6);
memcpy(buff, input2.c_str(), input2.size() + 1);
auto tup2 = s.split(buff, delim);
CHECK(tup2.size() == 6);
}
}
/*
TEST_CASE("testing quoting without escaping") {
std::vector<std::string> values{"10", "hello", ",", "a,a", "3.33", "a"};
// with quote
ss::converter c;
for (size_t i = 0; i < values.size() * values.size(); ++i) {
std::string input1;
std::string input2;
for (size_t j = 0; j < values.size(); ++j) {
if (i & (1 << j) && j != 2 && j != 3) {
input1.append(values[j]);
input2.append(values.at(values.size() - 1 - j));
} else {
input1.append("\"" + values[j] + "\"");
input2.append("\"" + values.at(values.size() - 1 - j) + "\"");
}
input1.append("__");
input1.push_back(',');
input1.append("__");
input2.push_back(',');
}
input1.pop_back();
input1.pop_back();
input1.pop_back();
input2.pop_back();
input1.append("\0\"");
input2.append("\0\"");
auto tup1 = c.convert<int, std::string, std::string, std::string,
double, char>(input1.c_str(), ",");
if (!c.valid()) {
FAIL("invalid: " + input1);
} else {
auto [a, b, c, d, e, f] = tup1;
CHECK(a == 10);
CHECK(b == "hello");
CHECK(c == ",");
CHECK(d == "a,a");
CHECK(e == 3.33);
CHECK(f == 'a');
}
auto tup2 = c.convert<char, double, std::string, std::string,
std::string, int>(input2.c_str(), ",");
if (!c.valid()) {
FAIL("invalid: " + input2);
} else {
auto [f, e, d, c, b, a] = tup2;
CHECK(a == 10);
CHECK(b == "hello");
CHECK(c == ",");
CHECK(d == "a,a");
CHECK(e == 3.33);
CHECK(f == 'a');
}
}
}
*/
static buffer buff;
TEST_CASE("testing split") {
ss::converter c;