Add converter tests with throw_on_error

This commit is contained in:
ado 2023-07-09 17:11:52 +02:00
parent f3225b8b16
commit 41b89d1d3d
6 changed files with 527 additions and 27 deletions

View File

@ -121,7 +121,12 @@ public:
no_void_validator_tup_t<Ts...> convert(
line_ptr_type line, const std::string& delim = default_delimiter) {
split(line, delim);
if (splitter_.valid()) {
return convert<Ts...>(splitter_.split_data_);
} else {
set_error_bad_split();
return {};
}
}
// parses already split line, returns 'T' object with extracted values
@ -227,7 +232,7 @@ private:
return error;
}
void set_error_unterminated_quote() {
void set_error_bad_split() {
if constexpr (string_error) {
error_.clear();
error_.append(splitter_.error_msg());
@ -340,10 +345,11 @@ private:
template <typename... Ts>
no_void_validator_tup_t<Ts...> convert_impl(const split_data& elems) {
clear_error();
// TODO check if this is needed
using return_type = no_void_validator_tup_t<Ts...>;
if (!splitter_.valid()) {
set_error_unterminated_quote();
set_error_bad_split();
no_void_validator_tup_t<Ts...> ret{};
return ret;
}

View File

@ -250,6 +250,7 @@ public:
constexpr static bool ignore_empty = (count_ignore_empty == 1);
constexpr static bool throw_on_error = (count_throw_on_error == 1);
// TODO set string_error if throw_on_error is defined
// TODO throw_on_error should be unique
private:
#define ASSERT_MSG "cannot have the same match character in multiple matchers"

View File

@ -163,6 +163,7 @@ private:
}
void set_error_invalid_resplit() {
// TODO check this
unterminated_quote_ = false;
if constexpr (string_error) {
error_.clear();

View File

@ -22,6 +22,30 @@ TEST_CASE("converter test split") {
}
}
TEST_CASE("converter test split with exceptions") {
ss::converter<ss::throw_on_error> c;
try {
for (const auto& [s, expected, delim] :
// clang-format off
{std::make_tuple("a,b,c,d", std::vector{"a", "b", "c", "d"}, ","),
{"", {}, " "},
{" x x x x | x ", {" x x x x ", " x "}, "|"},
{"a::b::c::d", {"a", "b", "c", "d"}, "::"},
{"x\t-\ty", {"x", "y"}, "\t-\t"},
{"x", {"x"}, ","}} // clang-format on
) {
auto split = c.split(s, delim);
CHECK_EQ(split.size(), expected.size());
for (size_t i = 0; i < split.size(); ++i) {
auto s = std::string(split[i].first, split[i].second);
CHECK_EQ(s, expected[i]);
}
}
} catch (ss::exception& e) {
FAIL(e.what());
}
}
TEST_CASE("converter test valid conversions") {
ss::converter c;
@ -116,12 +140,153 @@ TEST_CASE("converter test valid conversions") {
}
}
TEST_CASE("converter test valid conversions with exceptions") {
ss::converter<ss::throw_on_error> c;
try {
auto tup = c.convert<int>("5");
REQUIRE(c.valid());
CHECK_EQ(tup, 5);
} catch (ss::exception& e) {
FAIL(e.what());
}
try {
auto tup = c.convert<int, void>("5,junk");
REQUIRE(c.valid());
CHECK_EQ(tup, 5);
} catch (ss::exception& e) {
FAIL(e.what());
}
try {
auto tup = c.convert<void, int>("junk,5");
REQUIRE(c.valid());
CHECK_EQ(tup, 5);
} catch (ss::exception& e) {
FAIL(e.what());
}
try {
auto tup = c.convert<int, void, void>("5\njunk\njunk", "\n");
REQUIRE(c.valid());
CHECK_EQ(tup, 5);
} catch (ss::exception& e) {
FAIL(e.what());
}
try {
auto tup = c.convert<void, int, void>("junk 5 junk", " ");
REQUIRE(c.valid());
CHECK_EQ(tup, 5);
} catch (ss::exception& e) {
FAIL(e.what());
}
try {
auto tup = c.convert<void, void, int>("junk\tjunk\t5", "\t");
REQUIRE(c.valid());
CHECK_EQ(tup, 5);
} catch (ss::exception& e) {
FAIL(e.what());
}
try {
auto tup =
c.convert<void, void, std::optional<int>>("junk\tjunk\t5", "\t");
REQUIRE(c.valid());
REQUIRE(tup.has_value());
CHECK_EQ(tup, 5);
} catch (ss::exception& e) {
FAIL(e.what());
}
try {
auto tup = c.convert<int, double, void>("5,6.6,junk");
REQUIRE(c.valid());
CHECK_EQ(tup, std::make_tuple(5, 6.6));
} catch (ss::exception& e) {
FAIL(e.what());
}
try {
auto tup = c.convert<int, void, double>("5,junk,6.6");
REQUIRE(c.valid());
CHECK_EQ(tup, std::make_tuple(5, 6.6));
} catch (ss::exception& e) {
FAIL(e.what());
}
try {
auto tup = c.convert<void, int, double>("junk;5;6.6", ";");
REQUIRE(c.valid());
CHECK_EQ(tup, std::make_tuple(5, 6.6));
} catch (ss::exception& e) {
FAIL(e.what());
}
try {
auto tup =
c.convert<void, std::optional<int>, double>("junk;5;6.6", ";");
REQUIRE(c.valid());
REQUIRE(std::get<0>(tup).has_value());
CHECK_EQ(tup, std::make_tuple(5, 6.6));
} catch (ss::exception& e) {
FAIL(e.what());
}
try {
auto tup =
c.convert<void, std::optional<int>, double>("junk;5.4;6.6", ";");
REQUIRE(c.valid());
REQUIRE_FALSE(std::get<0>(tup).has_value());
CHECK_EQ(tup, std::make_tuple(std::optional<int>{}, 6.6));
} catch (ss::exception& e) {
FAIL(e.what());
}
try {
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_EQ(tup, std::make_tuple(std::variant<int, double>{5}, 6.6));
} catch (ss::exception& e) {
FAIL(e.what());
}
try {
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_EQ(tup, std::make_tuple(std::variant<int, double>{5.5}, 6.6));
} catch (ss::exception& e) {
FAIL(e.what());
}
try {
auto tup = c.convert<void, std::string_view, double,
std::string_view>("junk;s1;6.6;s2", ";");
REQUIRE(c.valid());
CHECK_EQ(tup, std::make_tuple(std::string_view{"s1"}, 6.6,
std::string_view{"s2"}));
} catch (ss::exception& e) {
FAIL(e.what());
}
}
TEST_CASE("converter test invalid conversions") {
ss::converter c;
c.convert<int>("");
REQUIRE_FALSE(c.valid());
c.convert<int>("1", "");
REQUIRE_FALSE(c.valid());
c.convert<int>("10", "");
REQUIRE_FALSE(c.valid());
@ -150,6 +315,24 @@ TEST_CASE("converter test invalid conversions") {
REQUIRE_FALSE(c.valid());
}
TEST_CASE("converter test invalid conversions with exceptions") {
// TODO remove ss::string_error
ss::converter<ss::string_error, ss::throw_on_error> c;
REQUIRE_EXCEPTION(c.convert<int>(""));
REQUIRE_EXCEPTION(c.convert<int>("1", ""));
REQUIRE_EXCEPTION(c.convert<int>("10", ""));
REQUIRE_EXCEPTION(c.convert<int, void>(""));
REQUIRE_EXCEPTION(c.convert<int, void>(",junk"));
REQUIRE_EXCEPTION(c.convert<void, int>("junk,"));
REQUIRE_EXCEPTION(c.convert<int>("x"));
REQUIRE_EXCEPTION(c.convert<int, void>("x"));
REQUIRE_EXCEPTION(c.convert<int, void>("x,junk"));
REQUIRE_EXCEPTION(c.convert<void, int>("junk,x"));
REQUIRE_EXCEPTION(
c.convert<void, std::variant<int, double>, double>("junk;.5.5;6", ";"));
}
TEST_CASE("converter test ss:ax restriction (all except)") {
ss::converter c;
@ -181,6 +364,33 @@ TEST_CASE("converter test ss:ax restriction (all except)") {
}
}
TEST_CASE("converter test ss:ax restriction (all except) with exceptions") {
// TODO remove ss::string_error
ss::converter<ss::string_error, ss::throw_on_error> c;
REQUIRE_EXCEPTION(c.convert<ss::ax<int, 0>>("0"));
REQUIRE_EXCEPTION(c.convert<ss::ax<int, 0, 1, 2>>("1"));
REQUIRE_EXCEPTION(c.convert<void, char, ss::ax<int, 0, 1, 2>>("junk,c,1"));
REQUIRE_EXCEPTION(c.convert<ss::ax<int, 1>, char>("1,c"));
try {
{
int tup = c.convert<ss::ax<int, 1>>("3");
CHECK_EQ(tup, 3);
}
{
std::tuple<char, int> tup = c.convert<char, ss::ax<int, 1>>("c,3");
CHECK_EQ(tup, std::make_tuple('c', 3));
}
{
std::tuple<int, char> tup = c.convert<ss::ax<int, 1>, char>("3,c");
CHECK_EQ(tup, std::make_tuple(3, 'c'));
}
} catch (ss::exception& e) {
FAIL(e.what());
}
}
TEST_CASE("converter test ss:nx restriction (none except)") {
ss::converter c;
@ -215,6 +425,40 @@ TEST_CASE("converter test ss:nx restriction (none except)") {
}
}
TEST_CASE("converter test ss:nx restriction (none except) with exceptions") {
// TODO remove ss::string_error
ss::converter<ss::string_error, ss::throw_on_error> c;
REQUIRE_EXCEPTION(c.convert<ss::nx<int, 1>>("3"));
REQUIRE_EXCEPTION(c.convert<char, ss::nx<int, 1, 2, 69>>("c,3"));
REQUIRE_EXCEPTION(c.convert<ss::nx<int, 1>, char>("3,c"));
try {
{
auto tup = c.convert<ss::nx<int, 3>>("3");
REQUIRE(c.valid());
CHECK_EQ(tup, 3);
}
{
auto tup = c.convert<ss::nx<int, 0, 1, 2>>("2");
REQUIRE(c.valid());
CHECK_EQ(tup, 2);
}
{
auto tup = c.convert<char, void, ss::nx<int, 0, 1, 2>>("c,junk,1");
REQUIRE(c.valid());
CHECK_EQ(tup, std::make_tuple('c', 1));
}
{
auto tup = c.convert<ss::nx<int, 1>, char>("1,c");
REQUIRE(c.valid());
CHECK_EQ(tup, std::make_tuple(1, 'c'));
}
} catch (ss::exception& e) {
FAIL(e.what());
}
}
TEST_CASE("converter test ss:ir restriction (in range)") {
ss::converter c;
@ -249,6 +493,40 @@ TEST_CASE("converter test ss:ir restriction (in range)") {
}
}
TEST_CASE("converter test ss:ir restriction (in range) with exceptions") {
// TODO remove ss::string_error
ss::converter<ss::string_error, ss::throw_on_error> c;
REQUIRE_EXCEPTION(c.convert<ss::ir<int, 0, 2>>("3"));
REQUIRE_EXCEPTION(c.convert<char, ss::ir<int, 4, 69>>("c,3"));
REQUIRE_EXCEPTION(c.convert<ss::ir<int, 1, 2>, char>("3,c"));
try {
{
auto tup = c.convert<ss::ir<int, 1, 5>>("3");
REQUIRE(c.valid());
CHECK_EQ(tup, 3);
}
{
auto tup = c.convert<ss::ir<int, 0, 2>>("2");
REQUIRE(c.valid());
CHECK_EQ(tup, 2);
}
{
auto tup = c.convert<char, void, ss::ir<int, 0, 1>>("c,junk,1");
REQUIRE(c.valid());
CHECK_EQ(tup, std::make_tuple('c', 1));
}
{
auto tup = c.convert<ss::ir<int, 1, 20>, char>("1,c");
REQUIRE(c.valid());
CHECK_EQ(tup, std::make_tuple(1, 'c'));
}
} catch (ss::exception& e) {
FAIL(e.what());
}
}
TEST_CASE("converter test ss:oor restriction (out of range)") {
ss::converter c;
@ -283,6 +561,38 @@ TEST_CASE("converter test ss:oor restriction (out of range)") {
}
}
TEST_CASE("converter test ss:oor restriction (out of range) with exceptions") {
// TODO remove ss::string_error
ss::converter<ss::string_error, ss::throw_on_error> c;
REQUIRE_EXCEPTION(c.convert<ss::oor<int, 1, 5>>("3"));
REQUIRE_EXCEPTION(c.convert<ss::oor<int, 0, 2>>("2"));
REQUIRE_EXCEPTION(c.convert<char, ss::oor<int, 0, 1>, void>("c,1,junk"));
REQUIRE_EXCEPTION(c.convert<ss::oor<int, 1, 20>, char>("1,c"));
try {
{
auto tup = c.convert<ss::oor<int, 0, 2>>("3");
REQUIRE(c.valid());
CHECK_EQ(tup, 3);
}
{
auto tup = c.convert<char, void, ss::oor<int, 4, 69>>("c,junk,3");
REQUIRE(c.valid());
CHECK_EQ(tup, std::make_tuple('c', 3));
}
{
auto tup = c.convert<ss::oor<int, 1, 2>, char>("3,c");
REQUIRE(c.valid());
CHECK_EQ(tup, std::make_tuple(3, 'c'));
}
} catch (ss::exception& e) {
FAIL(e.what());
}
}
const std::vector<int> extracted_vector = {1, 2, 3};
// custom extract
@ -331,6 +641,38 @@ TEST_CASE("converter test ss:ne restriction (not empty)") {
}
}
TEST_CASE("converter test ss:ne restriction (not empty) with exceptions") {
// TODO remove ss::string_error
ss::converter<ss::string_error, ss::throw_on_error> c;
REQUIRE_EXCEPTION(c.convert<ss::ne<std::string>>(""));
REQUIRE_EXCEPTION(c.convert<int, ss::ne<std::string>>("3,"));
REQUIRE_EXCEPTION(c.convert<ss::ne<std::string>, int>(",3"));
REQUIRE_EXCEPTION(c.convert<void, ss::ne<std::string>, int>("junk,,3"));
REQUIRE_EXCEPTION(c.convert<ss::ne<std::vector<int>>>(""));
try {
{
auto tup = c.convert<ss::ne<std::string>>("s");
REQUIRE(c.valid());
CHECK_EQ(tup, "s");
}
{
auto tup =
c.convert<std::optional<int>, ss::ne<std::string>>("1,s");
REQUIRE(c.valid());
CHECK_EQ(tup, std::make_tuple(1, "s"));
}
{
auto tup = c.convert<ss::ne<std::vector<int>>>("{1 2 3}");
REQUIRE(c.valid());
CHECK_EQ(tup, extracted_vector);
}
} catch (ss::exception& e) {
FAIL(e.what());
}
}
TEST_CASE(
"converter test ss:lt ss::lte ss::gt ss::gte restriction (in range)") {
ss::converter c;
@ -390,6 +732,59 @@ TEST_CASE(
}
}
TEST_CASE("converter test ss:lt ss::lte ss::gt ss::gte restriction (in range) "
"with exception") {
// TODO remove ss::string_error
ss::converter<ss::string_error, ss::throw_on_error> c;
REQUIRE_EXCEPTION(c.convert<ss::lt<int, 3>>("3"));
REQUIRE_EXCEPTION(c.convert<ss::lt<int, 2>>("3"));
REQUIRE_EXCEPTION(c.convert<ss::gt<int, 3>>("3"));
REQUIRE_EXCEPTION(c.convert<ss::gt<int, 4>>("3"));
REQUIRE_EXCEPTION(c.convert<ss::lte<int, 2>>("3"));
REQUIRE_EXCEPTION(c.convert<ss::gte<int, 4>>("3"));
try {
{
auto tup = c.convert<ss::lt<int, 4>>("3");
REQUIRE(c.valid());
CHECK_EQ(tup, 3);
}
{
auto tup = c.convert<ss::gt<int, 2>>("3");
REQUIRE(c.valid());
CHECK_EQ(tup, 3);
}
{
auto tup = c.convert<ss::lte<int, 4>>("3");
REQUIRE(c.valid());
CHECK_EQ(tup, 3);
}
{
auto tup = c.convert<ss::lte<int, 3>>("3");
REQUIRE(c.valid());
CHECK_EQ(tup, 3);
}
{
auto tup = c.convert<ss::gte<int, 2>>("3");
REQUIRE(c.valid());
CHECK_EQ(tup, 3);
}
{
auto tup = c.convert<ss::gte<int, 3>>("3");
REQUIRE(c.valid());
CHECK_EQ(tup, 3);
}
} catch (ss::exception& e) {
FAIL(e.what());
}
}
TEST_CASE("converter test error mode") {
ss::converter<ss::string_error> c;
c.convert<int>("junk");
@ -397,6 +792,12 @@ TEST_CASE("converter test error mode") {
CHECK_FALSE(c.error_msg().empty());
}
TEST_CASE("converter test throw on error mode") {
// TODO remove ss::string_error
ss::converter<ss::string_error, ss::throw_on_error> c;
REQUIRE_EXCEPTION(c.convert<int>("junk"));
}
TEST_CASE("converter test converter with quotes spacing and escaping") {
{
ss::converter c;
@ -444,6 +845,67 @@ TEST_CASE("converter test converter with quotes spacing and escaping") {
}
}
TEST_CASE("converter test converter with quotes spacing and escaping with "
"exceptions") {
// TODO remove ss::string_error on all below
try {
ss::converter<ss::string_error, ss::throw_on_error> c;
auto tup = c.convert<std::string, std::string, std::string>(
R"("just","some","strings")");
REQUIRE(c.valid());
CHECK_EQ(tup, std::make_tuple("\"just\"", "\"some\"", "\"strings\""));
} catch (ss::exception& e) {
FAIL(e.what());
}
try {
ss::converter<ss::quote<'"'>> c;
auto tup = c.convert<std::string, std::string, double, char>(
buff(R"("just",some,"12.3","a")"));
REQUIRE(c.valid());
CHECK_EQ(tup, std::make_tuple("just", "some", 12.3, 'a'));
} catch (ss::exception& e) {
FAIL(e.what());
}
try {
ss::converter<ss::string_error, ss::throw_on_error, ss::trim<' '>> c;
auto tup = c.convert<std::string, std::string, double, char>(
buff(R"( just , some , 12.3 ,a )"));
REQUIRE(c.valid());
CHECK_EQ(tup, std::make_tuple("just", "some", 12.3, 'a'));
} catch (ss::exception& e) {
FAIL(e.what());
}
try {
ss::converter<ss::string_error, ss::throw_on_error, ss::escape<'\\'>> c;
auto tup =
c.convert<std::string, std::string>(buff(R"(ju\,st,strings)"));
REQUIRE(c.valid());
CHECK_EQ(tup, std::make_tuple("ju,st", "strings"));
} catch (ss::exception& e) {
FAIL(e.what());
}
try {
ss::converter<ss::string_error, ss::throw_on_error, ss::escape<'\\'>,
ss::trim<' '>, ss::quote<'"'>>
c;
auto tup = c.convert<std::string, std::string, double, std::string>(
buff(R"( ju\,st , "so,me" , 12.34 , "str""ings")"));
REQUIRE(c.valid());
CHECK_EQ(tup, std::make_tuple("ju,st", "so,me", 12.34, "str\"ings"));
} catch (ss::exception& e) {
FAIL(e.what());
}
}
TEST_CASE("converter test invalid split conversions") {
ss::converter<ss::string_error, ss::escape<'\\'>, ss::trim<' '>,
ss::quote<'"'>>
@ -451,7 +913,7 @@ TEST_CASE("converter test invalid split conversions") {
{
// mismatched quote
auto tup = c.convert<std::string, std::string, double, char>(
c.convert<std::string, std::string, double, char>(
buff(R"( "just , some , "12.3","a" )"));
CHECK_FALSE(c.valid());
CHECK_FALSE(c.unterminated_quote());
@ -460,7 +922,7 @@ TEST_CASE("converter test invalid split conversions") {
{
// unterminated quote
auto tup = c.convert<std::string, std::string, double, std::string>(
c.convert<std::string, std::string, double, std::string>(
buff(R"( ju\,st , "so,me" , 12.34 , "str""ings)"));
CHECK_FALSE(c.valid());
CHECK(c.unterminated_quote());
@ -469,7 +931,7 @@ TEST_CASE("converter test invalid split conversions") {
{
// unterminated escape
auto tup = c.convert<std::string, std::string, double, std::string>(
c.convert<std::string, std::string, double, std::string>(
buff(R"(just,some,2,strings\)"));
CHECK_FALSE(c.valid());
CHECK_FALSE(c.unterminated_quote());
@ -478,7 +940,7 @@ TEST_CASE("converter test invalid split conversions") {
{
// unterminated escape while quoting
auto tup = c.convert<std::string, std::string, double, std::string>(
c.convert<std::string, std::string, double, std::string>(
buff(R"(just,some,2,"strings\)"));
CHECK_FALSE(c.valid());
CHECK_FALSE(c.unterminated_quote());
@ -487,10 +949,42 @@ TEST_CASE("converter test invalid split conversions") {
{
// unterminated escaped quote
auto tup = c.convert<std::string, std::string, double, std::string>(
c.convert<std::string, std::string, double, std::string>(
buff(R"(just,some,2,"strings\")"));
CHECK_FALSE(c.valid());
CHECK(c.unterminated_quote());
CHECK_FALSE(c.error_msg().empty());
}
}
TEST_CASE("converter test invalid split conversions with exceptions") {
// TODO remove ss::string_error
ss::converter<ss::string_error, ss::escape<'\\'>, ss::trim<' '>,
ss::quote<'"'>, ss::throw_on_error>
c;
// mismatched quote
REQUIRE_EXCEPTION(c.convert<std::string, std::string, double, char>(
buff(R"( "just , some , "12.3","a" )")));
CHECK_FALSE(c.unterminated_quote());
// unterminated quote
REQUIRE_EXCEPTION(c.convert<std::string, std::string, double, std::string>(
buff(R"( ju\,st , "so,me" , 12.34 , "str""ings)")));
CHECK(c.unterminated_quote());
// unterminated escape
REQUIRE_EXCEPTION(c.convert<std::string, std::string, double, std::string>(
buff(R"(just,some,2,strings\)")));
CHECK_FALSE(c.unterminated_quote());
// unterminated escape while quoting
REQUIRE_EXCEPTION(c.convert<std::string, std::string, double, std::string>(
buff(R"(just,some,2,"strings\)")));
CHECK_FALSE(c.unterminated_quote());
// unterminated escaped quote
REQUIRE_EXCEPTION(c.convert<std::string, std::string, double, std::string>(
buff(R"(just,some,2,"strings\")")));
CHECK(c.unterminated_quote());
}

View File

@ -79,3 +79,13 @@ struct buffer {
}
#define CHECK_NOT_VARIANT(var, type) CHECK(!std::holds_alternative<type>(var));
// TODO remove
#include <iostream>
#define REQUIRE_EXCEPTION(...) \
try { \
__VA_ARGS__; \
FAIL("Expected exception"); \
} catch (ss::exception & e) { \
CHECK_FALSE(std::string{e.what()}.empty()); \
}

View File

@ -525,10 +525,8 @@ TEST_CASE("splitter test error mode") {
s.split(buff("just,some,strings"), "");
FAIL("expected exception");
} catch (ss::exception& e) {
CHECK_EQ(std::string{e.what()}, s.error_msg());
CHECK_FALSE(s.valid());
CHECK_FALSE(std::string{e.what()}.empty());
CHECK_FALSE(s.unterminated_quote());
CHECK_FALSE(s.error_msg().empty());
}
}
@ -1107,15 +1105,6 @@ TEST_CASE("splitter test invalid splits") {
CHECK_FALSE(s.error_msg().empty());
}
#define CHECK_EXCEPTION(CLASS, OPERATION) \
try { \
OPERATION; \
} catch (ss::exception & e) { \
CHECK_FALSE(CLASS.valid()); \
CHECK_FALSE(CLASS.error_msg().empty()); \
CHECK_EQ(CLASS.error_msg(), std::string{e.what()}); \
}
TEST_CASE("splitter test invalid splits with exceptions") {
ss::converter<ss::string_error, ss::quote<'"'>, ss::trim<' '>,
ss::escape<'\\'>, ss::throw_on_error>
@ -1123,28 +1112,28 @@ TEST_CASE("splitter test invalid splits with exceptions") {
auto& s = c.splitter;
// empty delimiter
CHECK_EXCEPTION(s, s.split(buff("some,random,strings"), ""));
REQUIRE_EXCEPTION(s.split(buff("some,random,strings"), ""));
CHECK_FALSE(s.unterminated_quote());
// mismatched delimiter
CHECK_EXCEPTION(s, s.split(buff(R"(some,"random,"strings")")));
REQUIRE_EXCEPTION(s.split(buff(R"(some,"random,"strings")")));
CHECK_FALSE(s.unterminated_quote());
// unterminated escape
CHECK_EXCEPTION(s, s.split(buff(R"(some,random,strings\)")));
REQUIRE_EXCEPTION(s.split(buff(R"(some,random,strings\)")));
CHECK_FALSE(s.unterminated_quote());
// unterminated escape
CHECK_EXCEPTION(s, s.split(buff(R"(some,random,"strings\)")));
REQUIRE_EXCEPTION(s.split(buff(R"(some,random,"strings\)")));
CHECK_FALSE(s.unterminated_quote());
// unterminated quote
CHECK_EXCEPTION(s, s.split(buff("some,random,\"strings")));
REQUIRE_EXCEPTION(s.split(buff("some,random,\"strings")));
CHECK(s.unterminated_quote());
// invalid resplit
char new_line[] = "some";
CHECK_EXCEPTION(s, c.resplit(new_line, strlen(new_line)));
REQUIRE_EXCEPTION(c.resplit(new_line, strlen(new_line)));
CHECK_FALSE(s.unterminated_quote());
}
@ -1248,4 +1237,3 @@ TEST_CASE("splitter test with quote and escape, trim_left and trim_right") {
ss::trim_right<'-'>>(p, delims);
}
}