mirror of
https://github.com/red0124/ssp.git
synced 2025-12-14 21:59:55 +01:00
add string_error and multiline within the setup, remove set_error_mode, update unit tests, update documentation
This commit is contained in:
@@ -384,13 +384,7 @@ TEST_CASE(
|
||||
}
|
||||
|
||||
TEST_CASE("converter test error mode") {
|
||||
ss::converter c;
|
||||
|
||||
c.convert<int>("junk");
|
||||
CHECK(!c.valid());
|
||||
CHECK(c.error_msg().empty());
|
||||
|
||||
c.set_error_mode(ss::error_mode::error_string);
|
||||
ss::converter<ss::string_error> c;
|
||||
c.convert<int>("junk");
|
||||
CHECK(!c.valid());
|
||||
CHECK(!c.error_msg().empty());
|
||||
@@ -444,8 +438,9 @@ TEST_CASE("converter test converter with quotes spacing and escaping") {
|
||||
}
|
||||
|
||||
TEST_CASE("converter test invalid split conversions") {
|
||||
ss::converter<ss::escape<'\\'>, ss::trim<' '>, ss::quote<'"'>> c;
|
||||
c.set_error_mode(ss::error_mode::error_string);
|
||||
ss::converter<ss::string_error, ss::escape<'\\'>, ss::trim<' '>,
|
||||
ss::quote<'"'>>
|
||||
c;
|
||||
|
||||
{
|
||||
// mismatched quote
|
||||
@@ -453,6 +448,7 @@ TEST_CASE("converter test invalid split conversions") {
|
||||
buff(R"( "just , some , "12.3","a" )"));
|
||||
CHECK(!c.valid());
|
||||
CHECK(!c.unterminated_quote());
|
||||
CHECK(!c.error_msg().empty());
|
||||
}
|
||||
|
||||
{
|
||||
@@ -461,5 +457,6 @@ TEST_CASE("converter test invalid split conversions") {
|
||||
buff(R"( ju\,st , "so,me" , 12.34 , "str""ings)"));
|
||||
CHECK(!c.valid());
|
||||
CHECK(c.unterminated_quote());
|
||||
CHECK(!c.error_msg().empty());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,7 +59,6 @@ TEST_CASE("parser test various cases") {
|
||||
ss::parser p0{std::move(p)};
|
||||
p = std::move(p0);
|
||||
|
||||
p.set_error_mode(ss::error_mode::error_string);
|
||||
std::vector<X> i;
|
||||
|
||||
while (!p.eof()) {
|
||||
@@ -190,8 +189,7 @@ TEST_CASE("parser test composite conversion") {
|
||||
}
|
||||
}
|
||||
|
||||
ss::parser p{f.name, ","};
|
||||
p.set_error_mode(ss::error_mode::error_string);
|
||||
ss::parser<ss::string_error> p{f.name, ","};
|
||||
auto fail = [] { FAIL(""); };
|
||||
auto expect_error = [](auto error) { CHECK(!error.empty()); };
|
||||
|
||||
@@ -503,14 +501,7 @@ TEST_CASE("parser test error mode") {
|
||||
out << "junk" << std::endl;
|
||||
}
|
||||
|
||||
ss::parser p(f.name, ",");
|
||||
|
||||
REQUIRE(!p.eof());
|
||||
p.get_next<int>();
|
||||
CHECK(!p.valid());
|
||||
CHECK(p.error_msg().empty());
|
||||
|
||||
p.set_error_mode(ss::error_mode::error_string);
|
||||
ss::parser<ss::string_error> p(f.name, ",");
|
||||
|
||||
REQUIRE(!p.eof());
|
||||
p.get_next<int>();
|
||||
@@ -538,8 +529,7 @@ TEST_CASE("parser test csv on multiple lines with quotes") {
|
||||
}
|
||||
}
|
||||
|
||||
ss::parser<ss::quote<'"'>> p{f.name, ","};
|
||||
p.set_error_mode(ss::error_mode::error_string);
|
||||
ss::parser<ss::multiline, ss::quote<'"'>> p{f.name, ","};
|
||||
std::vector<X> i;
|
||||
|
||||
while (!p.eof()) {
|
||||
@@ -548,6 +538,12 @@ TEST_CASE("parser test csv on multiple lines with quotes") {
|
||||
}
|
||||
|
||||
CHECK(std::equal(i.begin(), i.end(), data.begin()));
|
||||
|
||||
ss::parser<ss::quote<'"'>> p_no_multiline{f.name, ","};
|
||||
while (!p.eof()) {
|
||||
auto a = p_no_multiline.get_next<int, double, std::string>();
|
||||
CHECK(!p.valid());
|
||||
}
|
||||
}
|
||||
|
||||
std::string no_escape(std::string& s) {
|
||||
@@ -569,8 +565,7 @@ TEST_CASE("parser test csv on multiple lines with escapes") {
|
||||
}
|
||||
}
|
||||
|
||||
ss::parser<ss::escape<'\\'>> p{f.name, ","};
|
||||
p.set_error_mode(ss::error_mode::error_string);
|
||||
ss::parser<ss::multiline, ss::escape<'\\'>> p{f.name, ","};
|
||||
std::vector<X> i;
|
||||
|
||||
while (!p.eof()) {
|
||||
@@ -579,4 +574,10 @@ TEST_CASE("parser test csv on multiple lines with escapes") {
|
||||
}
|
||||
|
||||
CHECK(std::equal(i.begin(), i.end(), data.begin()));
|
||||
|
||||
ss::parser<ss::escape<'\\'>> p_no_multiline{f.name, ","};
|
||||
while (!p.eof()) {
|
||||
auto a = p_no_multiline.get_next<int, double, std::string>();
|
||||
CHECK(!p.valid());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -480,13 +480,7 @@ TEST_CASE("splitter test error mode") {
|
||||
|
||||
{
|
||||
// empty delimiter
|
||||
ss::splitter s;
|
||||
s.split(buff("just,some,strings"), "");
|
||||
CHECK(!s.valid());
|
||||
CHECK(!s.unterminated_quote());
|
||||
CHECK(s.error_msg().empty());
|
||||
|
||||
s.set_error_mode(ss::error_mode::error_string);
|
||||
ss::splitter<ss::string_error> s;
|
||||
s.split(buff("just,some,strings"), "");
|
||||
CHECK(!s.valid());
|
||||
CHECK(!s.unterminated_quote());
|
||||
@@ -495,13 +489,7 @@ TEST_CASE("splitter test error mode") {
|
||||
|
||||
{
|
||||
// unterminated quote
|
||||
ss::splitter<ss::quote<'"'>> s;
|
||||
s.split(buff("\"just"));
|
||||
CHECK(!s.valid());
|
||||
CHECK(s.unterminated_quote());
|
||||
CHECK(s.error_msg().empty());
|
||||
|
||||
s.set_error_mode(ss::error_mode::error_string);
|
||||
ss::splitter<ss::string_error, ss::quote<'"'>> s;
|
||||
s.split(buff("\"just"));
|
||||
CHECK(!s.valid());
|
||||
CHECK(s.unterminated_quote());
|
||||
@@ -691,27 +679,33 @@ TEST_CASE("splitter test unterminated quote") {
|
||||
}
|
||||
|
||||
TEST_CASE("splitter test invalid splits") {
|
||||
ss::converter<ss::quote<'"'>, ss::trim<' '>, ss::escape<'\\'>> c;
|
||||
ss::converter<ss::string_error, ss::quote<'"'>, ss::trim<' '>,
|
||||
ss::escape<'\\'>>
|
||||
c;
|
||||
auto& s = c.splitter;
|
||||
|
||||
// empty delimiter
|
||||
s.split(buff("some,random,strings"), "");
|
||||
CHECK(!s.valid());
|
||||
CHECK(!s.unterminated_quote());
|
||||
CHECK(!s.error_msg().empty());
|
||||
|
||||
// mismatched delimiter
|
||||
s.split(buff(R"(some,"random,"strings")"));
|
||||
CHECK(!s.valid());
|
||||
CHECK(!s.unterminated_quote());
|
||||
CHECK(!s.error_msg().empty());
|
||||
|
||||
// unterminated quote
|
||||
s.split(buff("some,random,\"strings"));
|
||||
CHECK(!s.valid());
|
||||
CHECK(s.unterminated_quote());
|
||||
CHECK(!s.error_msg().empty());
|
||||
|
||||
// invalid resplit
|
||||
char new_line[] = "some";
|
||||
auto a = c.resplit(new_line, strlen(new_line));
|
||||
CHECK(!s.valid());
|
||||
CHECK(!s.unterminated_quote());
|
||||
CHECK(!s.error_msg().empty());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user