mirror of
https://github.com/red0124/ssp.git
synced 2025-01-23 13:05:20 +01:00
Update splitter tests
This commit is contained in:
parent
e316558a7b
commit
b7e5dd28b8
@ -379,7 +379,6 @@ private:
|
|||||||
return extract_tuple<Ts...>(elems);
|
return extract_tuple<Ts...>(elems);
|
||||||
}
|
}
|
||||||
|
|
||||||
// do not know how to specialize by return type :(
|
|
||||||
template <typename... Ts>
|
template <typename... Ts>
|
||||||
no_void_validator_tup_t<std::tuple<Ts...>> convert_impl(
|
no_void_validator_tup_t<std::tuple<Ts...>> convert_impl(
|
||||||
const split_data& elems, const std::tuple<Ts...>*) {
|
const split_data& elems, const std::tuple<Ts...>*) {
|
||||||
|
@ -775,6 +775,23 @@ TEST_CASE("splitter test resplit unterminated quote") {
|
|||||||
CHECK_EQ(words(vec), expected);
|
CHECK_EQ(words(vec), expected);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
ss::converter<ss::quote<'"'>, ss::escape<'\\'>, ss::multiline> c;
|
||||||
|
auto& s = c.splitter;
|
||||||
|
auto vec = expect_unterminated_quote(s, R"("just\"some","ra)");
|
||||||
|
std::vector<std::string> expected{"just\"some"};
|
||||||
|
auto w = words(vec);
|
||||||
|
w.pop_back();
|
||||||
|
CHECK_EQ(w, expected);
|
||||||
|
REQUIRE(s.unterminated_quote());
|
||||||
|
{
|
||||||
|
auto new_line = buff.append(R"(n,dom",str\"ings)");
|
||||||
|
// invalid resplit size
|
||||||
|
vec = c.resplit(new_line, 4);
|
||||||
|
CHECK(!s.valid());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("splitter test resplit unterminated quote with exceptions") {
|
TEST_CASE("splitter test resplit unterminated quote with exceptions") {
|
||||||
@ -1040,47 +1057,57 @@ TEST_CASE("splitter test resplit unterminated quote with exceptions") {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("splitter test invalid splits") {
|
template <typename... Ts>
|
||||||
ss::converter<ss::string_error, ss::quote<'"'>, ss::trim<' '>,
|
void test_invalid_splits() {
|
||||||
ss::escape<'\\'>>
|
ss::converter<ss::quote<'"'>, ss::trim<' '>, ss::escape<'\\'>, Ts...> c;
|
||||||
c;
|
|
||||||
auto& s = c.splitter;
|
auto& s = c.splitter;
|
||||||
|
|
||||||
|
auto check_error_msg = [&] {
|
||||||
|
if constexpr (ss::setup<Ts...>::string_error) {
|
||||||
|
CHECK_FALSE(s.error_msg().empty());
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
// empty delimiter
|
// empty delimiter
|
||||||
s.split(buff("some,random,strings"), "");
|
s.split(buff("some,random,strings"), "");
|
||||||
CHECK_FALSE(s.valid());
|
CHECK_FALSE(s.valid());
|
||||||
CHECK_FALSE(s.unterminated_quote());
|
CHECK_FALSE(s.unterminated_quote());
|
||||||
CHECK_FALSE(s.error_msg().empty());
|
check_error_msg();
|
||||||
|
|
||||||
// mismatched delimiter
|
// mismatched delimiter
|
||||||
s.split(buff(R"(some,"random,"strings")"));
|
s.split(buff(R"(some,"random,"strings")"));
|
||||||
CHECK_FALSE(s.valid());
|
CHECK_FALSE(s.valid());
|
||||||
CHECK_FALSE(s.unterminated_quote());
|
CHECK_FALSE(s.unterminated_quote());
|
||||||
CHECK_FALSE(s.error_msg().empty());
|
check_error_msg();
|
||||||
|
|
||||||
// unterminated escape
|
// unterminated escape
|
||||||
s.split(buff(R"(some,random,strings\)"));
|
s.split(buff(R"(some,random,strings\)"));
|
||||||
CHECK_FALSE(s.valid());
|
CHECK_FALSE(s.valid());
|
||||||
CHECK_FALSE(s.unterminated_quote());
|
CHECK_FALSE(s.unterminated_quote());
|
||||||
CHECK_FALSE(s.error_msg().empty());
|
check_error_msg();
|
||||||
|
|
||||||
// unterminated escape
|
// unterminated escape
|
||||||
s.split(buff(R"(some,random,"strings\)"));
|
s.split(buff(R"(some,random,"strings\)"));
|
||||||
CHECK_FALSE(s.valid());
|
CHECK_FALSE(s.valid());
|
||||||
CHECK_FALSE(s.unterminated_quote());
|
CHECK_FALSE(s.unterminated_quote());
|
||||||
CHECK_FALSE(s.error_msg().empty());
|
check_error_msg();
|
||||||
|
|
||||||
// unterminated quote
|
// unterminated quote
|
||||||
s.split(buff("some,random,\"strings"));
|
s.split(buff("some,random,\"strings"));
|
||||||
CHECK_FALSE(s.valid());
|
CHECK_FALSE(s.valid());
|
||||||
CHECK(s.unterminated_quote());
|
CHECK(s.unterminated_quote());
|
||||||
CHECK_FALSE(s.error_msg().empty());
|
check_error_msg();
|
||||||
|
|
||||||
// invalid resplit
|
// invalid resplit
|
||||||
char new_line[] = "some";
|
char new_line[] = "some";
|
||||||
c.resplit(new_line, strlen(new_line));
|
c.resplit(new_line, strlen(new_line));
|
||||||
CHECK_FALSE(s.valid());
|
CHECK_FALSE(s.valid());
|
||||||
CHECK_FALSE(s.error_msg().empty());
|
check_error_msg();
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE("splitter test invalid splits") {
|
||||||
|
test_invalid_splits();
|
||||||
|
test_invalid_splits<ss::string_error>();
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("splitter test invalid splits with exceptions") {
|
TEST_CASE("splitter test invalid splits with exceptions") {
|
||||||
|
Loading…
Reference in New Issue
Block a user