#include "test_helpers.hpp" #include #include TEST_CASE("converter test split") { ss::converter c; 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]); } } } TEST_CASE("converter test split with exceptions") { ss::converter 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(std::string{e.what()}); } } TEST_CASE("converter test valid conversions") { ss::converter c; { auto tup = c.convert("5"); REQUIRE(c.valid()); CHECK_EQ(tup, 5); } { auto tup = c.convert("5,junk"); REQUIRE(c.valid()); CHECK_EQ(tup, 5); } { auto tup = c.convert("junk,5"); REQUIRE(c.valid()); CHECK_EQ(tup, 5); } { auto tup = c.convert("5\njunk\njunk", "\n"); REQUIRE(c.valid()); CHECK_EQ(tup, 5); } { auto tup = c.convert("junk 5 junk", " "); REQUIRE(c.valid()); CHECK_EQ(tup, 5); } { auto tup = c.convert("junk\tjunk\t5", "\t"); REQUIRE(c.valid()); CHECK_EQ(tup, 5); } { auto tup = c.convert>("junk\tjunk\t5", "\t"); REQUIRE(c.valid()); REQUIRE(tup.has_value()); CHECK_EQ(tup, 5); } { auto tup = c.convert("5,6.6,junk"); REQUIRE(c.valid()); CHECK_EQ(tup, std::make_tuple(5, 6.6)); } { auto tup = c.convert("5,junk,6.6"); REQUIRE(c.valid()); CHECK_EQ(tup, std::make_tuple(5, 6.6)); } { auto tup = c.convert("junk;5;6.6", ";"); REQUIRE(c.valid()); CHECK_EQ(tup, std::make_tuple(5, 6.6)); } { auto tup = c.convert, double>("junk;5;6.6", ";"); REQUIRE(c.valid()); REQUIRE(std::get<0>(tup).has_value()); CHECK_EQ(tup, std::make_tuple(5, 6.6)); } { auto tup = c.convert, 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{}, 6.6)); } { auto tup = c.convert, double>("junk;5;6.6", ";"); REQUIRE(c.valid()); REQUIRE(std::holds_alternative(std::get<0>(tup))); CHECK_EQ(tup, std::make_tuple(std::variant{5}, 6.6)); } { auto tup = c.convert, double>("junk;5.5;6.6", ";"); REQUIRE(c.valid()); REQUIRE(std::holds_alternative(std::get<0>(tup))); CHECK_EQ(tup, std::make_tuple(std::variant{5.5}, 6.6)); } { auto tup = c.convert("junk;s1;6.6;s2", ";"); REQUIRE(c.valid()); CHECK_EQ(tup, std::make_tuple(std::string_view{"s1"}, 6.6, std::string_view{"s2"})); } } TEST_CASE("converter test valid conversions with exceptions") { ss::converter c; try { auto tup = c.convert("5"); REQUIRE(c.valid()); CHECK_EQ(tup, 5); } catch (ss::exception& e) { FAIL(std::string{e.what()}); } try { auto tup = c.convert("5,junk"); REQUIRE(c.valid()); CHECK_EQ(tup, 5); } catch (ss::exception& e) { FAIL(std::string{e.what()}); } try { auto tup = c.convert("junk,5"); REQUIRE(c.valid()); CHECK_EQ(tup, 5); } catch (ss::exception& e) { FAIL(std::string{e.what()}); } try { auto tup = c.convert("5\njunk\njunk", "\n"); REQUIRE(c.valid()); CHECK_EQ(tup, 5); } catch (ss::exception& e) { FAIL(std::string{e.what()}); } try { auto tup = c.convert("junk 5 junk", " "); REQUIRE(c.valid()); CHECK_EQ(tup, 5); } catch (ss::exception& e) { FAIL(std::string{e.what()}); } try { auto tup = c.convert("junk\tjunk\t5", "\t"); REQUIRE(c.valid()); CHECK_EQ(tup, 5); } catch (ss::exception& e) { FAIL(std::string{e.what()}); } try { auto tup = c.convert>("junk\tjunk\t5", "\t"); REQUIRE(c.valid()); REQUIRE(tup.has_value()); CHECK_EQ(tup, 5); } catch (ss::exception& e) { FAIL(std::string{e.what()}); } try { auto tup = c.convert("5,6.6,junk"); REQUIRE(c.valid()); CHECK_EQ(tup, std::make_tuple(5, 6.6)); } catch (ss::exception& e) { FAIL(std::string{e.what()}); } try { auto tup = c.convert("5,junk,6.6"); REQUIRE(c.valid()); CHECK_EQ(tup, std::make_tuple(5, 6.6)); } catch (ss::exception& e) { FAIL(std::string{e.what()}); } try { auto tup = c.convert("junk;5;6.6", ";"); REQUIRE(c.valid()); CHECK_EQ(tup, std::make_tuple(5, 6.6)); } catch (ss::exception& e) { FAIL(std::string{e.what()}); } try { auto tup = c.convert, 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(std::string{e.what()}); } try { auto tup = c.convert, 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{}, 6.6)); } catch (ss::exception& e) { FAIL(std::string{e.what()}); } try { auto tup = c.convert, double>("junk;5;6.6", ";"); REQUIRE(c.valid()); REQUIRE(std::holds_alternative(std::get<0>(tup))); CHECK_EQ(tup, std::make_tuple(std::variant{5}, 6.6)); } catch (ss::exception& e) { FAIL(std::string{e.what()}); } try { auto tup = c.convert, double>("junk;5.5;6.6", ";"); REQUIRE(c.valid()); REQUIRE(std::holds_alternative(std::get<0>(tup))); CHECK_EQ(tup, std::make_tuple(std::variant{5.5}, 6.6)); } catch (ss::exception& e) { FAIL(std::string{e.what()}); } try { auto tup = c.convert("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(std::string{e.what()}); } } TEST_CASE("converter test invalid conversions") { ss::converter c; c.convert(""); REQUIRE_FALSE(c.valid()); c.convert("1", ""); REQUIRE_FALSE(c.valid()); c.convert("10", ""); REQUIRE_FALSE(c.valid()); c.convert(""); REQUIRE_FALSE(c.valid()); c.convert(",junk"); REQUIRE_FALSE(c.valid()); c.convert("junk,"); REQUIRE_FALSE(c.valid()); c.convert("x"); REQUIRE_FALSE(c.valid()); c.convert("x"); REQUIRE_FALSE(c.valid()); c.convert("x,junk"); REQUIRE_FALSE(c.valid()); c.convert("junk,x"); REQUIRE_FALSE(c.valid()); c.convert, double>("junk;.5.5;6", ";"); REQUIRE_FALSE(c.valid()); } TEST_CASE("converter test invalid conversions with exceptions") { ss::converter c; REQUIRE_EXCEPTION(c.convert("")); REQUIRE_EXCEPTION(c.convert("1", "")); REQUIRE_EXCEPTION(c.convert("10", "")); REQUIRE_EXCEPTION(c.convert("")); REQUIRE_EXCEPTION(c.convert(",junk")); REQUIRE_EXCEPTION(c.convert("junk,")); REQUIRE_EXCEPTION(c.convert("x")); REQUIRE_EXCEPTION(c.convert("x")); REQUIRE_EXCEPTION(c.convert("x,junk")); REQUIRE_EXCEPTION(c.convert("junk,x")); REQUIRE_EXCEPTION( c.convert, double>("junk;.5.5;6", ";")); } TEST_CASE("converter test ss:ax restriction (all except)") { ss::converter c; c.convert>("0"); REQUIRE_FALSE(c.valid()); c.convert>("1"); REQUIRE_FALSE(c.valid()); c.convert>("junk,c,1"); REQUIRE_FALSE(c.valid()); c.convert, char>("1,c"); REQUIRE_FALSE(c.valid()); { int tup = c.convert>("3"); REQUIRE(c.valid()); CHECK_EQ(tup, 3); } { std::tuple tup = c.convert>("c,3"); REQUIRE(c.valid()); CHECK_EQ(tup, std::make_tuple('c', 3)); } { std::tuple tup = c.convert, char>("3,c"); REQUIRE(c.valid()); CHECK_EQ(tup, std::make_tuple(3, 'c')); } } TEST_CASE("converter test ss:ax restriction (all except) with exceptions") { // TODO remove ss::string_error ss::converter c; REQUIRE_EXCEPTION(c.convert>("0")); REQUIRE_EXCEPTION(c.convert>("1")); REQUIRE_EXCEPTION(c.convert>("junk,c,1")); REQUIRE_EXCEPTION(c.convert, char>("1,c")); try { { int tup = c.convert>("3"); CHECK_EQ(tup, 3); } { std::tuple tup = c.convert>("c,3"); CHECK_EQ(tup, std::make_tuple('c', 3)); } { std::tuple tup = c.convert, char>("3,c"); CHECK_EQ(tup, std::make_tuple(3, 'c')); } } catch (ss::exception& e) { FAIL(std::string{e.what()}); } } TEST_CASE("converter test ss:nx restriction (none except)") { ss::converter c; c.convert>("3"); REQUIRE_FALSE(c.valid()); c.convert>("c,3"); REQUIRE_FALSE(c.valid()); c.convert, char>("3,c"); REQUIRE_FALSE(c.valid()); { auto tup = c.convert>("3"); REQUIRE(c.valid()); CHECK_EQ(tup, 3); } { auto tup = c.convert>("2"); REQUIRE(c.valid()); CHECK_EQ(tup, 2); } { auto tup = c.convert>("c,junk,1"); REQUIRE(c.valid()); CHECK_EQ(tup, std::make_tuple('c', 1)); } { auto tup = c.convert, char>("1,c"); REQUIRE(c.valid()); CHECK_EQ(tup, std::make_tuple(1, 'c')); } } TEST_CASE("converter test ss:nx restriction (none except) with exceptions") { // TODO remove ss::string_error ss::converter c; REQUIRE_EXCEPTION(c.convert>("3")); REQUIRE_EXCEPTION(c.convert>("c,3")); REQUIRE_EXCEPTION(c.convert, char>("3,c")); try { { auto tup = c.convert>("3"); REQUIRE(c.valid()); CHECK_EQ(tup, 3); } { auto tup = c.convert>("2"); REQUIRE(c.valid()); CHECK_EQ(tup, 2); } { auto tup = c.convert>("c,junk,1"); REQUIRE(c.valid()); CHECK_EQ(tup, std::make_tuple('c', 1)); } { auto tup = c.convert, char>("1,c"); REQUIRE(c.valid()); CHECK_EQ(tup, std::make_tuple(1, 'c')); } } catch (ss::exception& e) { FAIL(std::string{e.what()}); } } TEST_CASE("converter test ss:ir restriction (in range)") { ss::converter c; c.convert>("3"); REQUIRE_FALSE(c.valid()); c.convert>("c,3"); REQUIRE_FALSE(c.valid()); c.convert, char>("3,c"); REQUIRE_FALSE(c.valid()); { auto tup = c.convert>("3"); REQUIRE(c.valid()); CHECK_EQ(tup, 3); } { auto tup = c.convert>("2"); REQUIRE(c.valid()); CHECK_EQ(tup, 2); } { auto tup = c.convert>("c,junk,1"); REQUIRE(c.valid()); CHECK_EQ(tup, std::make_tuple('c', 1)); } { auto tup = c.convert, char>("1,c"); REQUIRE(c.valid()); CHECK_EQ(tup, std::make_tuple(1, 'c')); } } TEST_CASE("converter test ss:ir restriction (in range) with exceptions") { // TODO remove ss::string_error ss::converter c; REQUIRE_EXCEPTION(c.convert>("3")); REQUIRE_EXCEPTION(c.convert>("c,3")); REQUIRE_EXCEPTION(c.convert, char>("3,c")); try { { auto tup = c.convert>("3"); REQUIRE(c.valid()); CHECK_EQ(tup, 3); } { auto tup = c.convert>("2"); REQUIRE(c.valid()); CHECK_EQ(tup, 2); } { auto tup = c.convert>("c,junk,1"); REQUIRE(c.valid()); CHECK_EQ(tup, std::make_tuple('c', 1)); } { auto tup = c.convert, char>("1,c"); REQUIRE(c.valid()); CHECK_EQ(tup, std::make_tuple(1, 'c')); } } catch (ss::exception& e) { FAIL(std::string{e.what()}); } } TEST_CASE("converter test ss:oor restriction (out of range)") { ss::converter c; c.convert>("3"); REQUIRE_FALSE(c.valid()); c.convert>("2"); REQUIRE_FALSE(c.valid()); c.convert, void>("c,1,junk"); REQUIRE_FALSE(c.valid()); c.convert, char>("1,c"); REQUIRE_FALSE(c.valid()); { auto tup = c.convert>("3"); REQUIRE(c.valid()); CHECK_EQ(tup, 3); } { auto tup = c.convert>("c,junk,3"); REQUIRE(c.valid()); CHECK_EQ(tup, std::make_tuple('c', 3)); } { auto tup = c.convert, char>("3,c"); REQUIRE(c.valid()); CHECK_EQ(tup, std::make_tuple(3, 'c')); } } TEST_CASE("converter test ss:oor restriction (out of range) with exceptions") { // TODO remove ss::string_error ss::converter c; REQUIRE_EXCEPTION(c.convert>("3")); REQUIRE_EXCEPTION(c.convert>("2")); REQUIRE_EXCEPTION(c.convert, void>("c,1,junk")); REQUIRE_EXCEPTION(c.convert, char>("1,c")); try { { auto tup = c.convert>("3"); REQUIRE(c.valid()); CHECK_EQ(tup, 3); } { auto tup = c.convert>("c,junk,3"); REQUIRE(c.valid()); CHECK_EQ(tup, std::make_tuple('c', 3)); } { auto tup = c.convert, char>("3,c"); REQUIRE(c.valid()); CHECK_EQ(tup, std::make_tuple(3, 'c')); } } catch (ss::exception& e) { FAIL(std::string{e.what()}); } } const std::vector extracted_vector = {1, 2, 3}; // custom extract template <> inline bool ss::extract(const char* begin, const char* end, std::vector& value) { if (begin == end) { return false; } value = extracted_vector; return true; } TEST_CASE("converter test ss:ne restriction (not empty)") { ss::converter c; c.convert>(""); REQUIRE_FALSE(c.valid()); c.convert>("3,"); REQUIRE_FALSE(c.valid()); c.convert, int>(",3"); REQUIRE_FALSE(c.valid()); c.convert, int>("junk,,3"); REQUIRE_FALSE(c.valid()); c.convert>>(""); REQUIRE_FALSE(c.valid()); { auto tup = c.convert>("s"); REQUIRE(c.valid()); CHECK_EQ(tup, "s"); } { auto tup = c.convert, ss::ne>("1,s"); REQUIRE(c.valid()); CHECK_EQ(tup, std::make_tuple(1, "s")); } { auto tup = c.convert>>("{1 2 3}"); REQUIRE(c.valid()); CHECK_EQ(tup, extracted_vector); } } TEST_CASE("converter test ss:ne restriction (not empty) with exceptions") { // TODO remove ss::string_error ss::converter c; REQUIRE_EXCEPTION(c.convert>("")); REQUIRE_EXCEPTION(c.convert>("3,")); REQUIRE_EXCEPTION(c.convert, int>(",3")); REQUIRE_EXCEPTION(c.convert, int>("junk,,3")); REQUIRE_EXCEPTION(c.convert>>("")); try { { auto tup = c.convert>("s"); REQUIRE(c.valid()); CHECK_EQ(tup, "s"); } { auto tup = c.convert, ss::ne>("1,s"); REQUIRE(c.valid()); CHECK_EQ(tup, std::make_tuple(1, "s")); } { auto tup = c.convert>>("{1 2 3}"); REQUIRE(c.valid()); CHECK_EQ(tup, extracted_vector); } } catch (ss::exception& e) { FAIL(std::string{e.what()}); } } TEST_CASE( "converter test ss:lt ss::lte ss::gt ss::gte restriction (in range)") { ss::converter c; c.convert>("3"); REQUIRE_FALSE(c.valid()); c.convert>("3"); REQUIRE_FALSE(c.valid()); c.convert>("3"); REQUIRE_FALSE(c.valid()); c.convert>("3"); REQUIRE_FALSE(c.valid()); c.convert>("3"); REQUIRE_FALSE(c.valid()); c.convert>("3"); REQUIRE_FALSE(c.valid()); { auto tup = c.convert>("3"); REQUIRE(c.valid()); CHECK_EQ(tup, 3); } { auto tup = c.convert>("3"); REQUIRE(c.valid()); CHECK_EQ(tup, 3); } { auto tup = c.convert>("3"); REQUIRE(c.valid()); CHECK_EQ(tup, 3); } { auto tup = c.convert>("3"); REQUIRE(c.valid()); CHECK_EQ(tup, 3); } { auto tup = c.convert>("3"); REQUIRE(c.valid()); CHECK_EQ(tup, 3); } { auto tup = c.convert>("3"); REQUIRE(c.valid()); CHECK_EQ(tup, 3); } } TEST_CASE("converter test ss:lt ss::lte ss::gt ss::gte restriction (in range) " "with exception") { // TODO remove ss::string_error ss::converter c; REQUIRE_EXCEPTION(c.convert>("3")); REQUIRE_EXCEPTION(c.convert>("3")); REQUIRE_EXCEPTION(c.convert>("3")); REQUIRE_EXCEPTION(c.convert>("3")); REQUIRE_EXCEPTION(c.convert>("3")); REQUIRE_EXCEPTION(c.convert>("3")); try { { auto tup = c.convert>("3"); REQUIRE(c.valid()); CHECK_EQ(tup, 3); } { auto tup = c.convert>("3"); REQUIRE(c.valid()); CHECK_EQ(tup, 3); } { auto tup = c.convert>("3"); REQUIRE(c.valid()); CHECK_EQ(tup, 3); } { auto tup = c.convert>("3"); REQUIRE(c.valid()); CHECK_EQ(tup, 3); } { auto tup = c.convert>("3"); REQUIRE(c.valid()); CHECK_EQ(tup, 3); } { auto tup = c.convert>("3"); REQUIRE(c.valid()); CHECK_EQ(tup, 3); } } catch (ss::exception& e) { FAIL(std::string{e.what()}); } } TEST_CASE("converter test error mode") { ss::converter c; c.convert("junk"); CHECK_FALSE(c.valid()); CHECK_FALSE(c.error_msg().empty()); } TEST_CASE("converter test throw on error mode") { // TODO remove ss::string_error ss::converter c; REQUIRE_EXCEPTION(c.convert("junk")); } TEST_CASE("converter test converter with quotes spacing and escaping") { { ss::converter c; auto tup = c.convert( R"("just","some","strings")"); REQUIRE(c.valid()); CHECK_EQ(tup, std::make_tuple("\"just\"", "\"some\"", "\"strings\"")); } { ss::converter> c; auto tup = c.convert( buff(R"("just",some,"12.3","a")")); REQUIRE(c.valid()); CHECK_EQ(tup, std::make_tuple("just", "some", 12.3, 'a')); } { ss::converter> c; auto tup = c.convert( buff(R"( just , some , 12.3 ,a )")); REQUIRE(c.valid()); CHECK_EQ(tup, std::make_tuple("just", "some", 12.3, 'a')); } { ss::converter> c; auto tup = c.convert(buff(R"(ju\,st,strings)")); REQUIRE(c.valid()); CHECK_EQ(tup, std::make_tuple("ju,st", "strings")); } { ss::converter, ss::trim<' '>, ss::quote<'"'>> c; auto tup = c.convert( 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")); } } TEST_CASE("converter test converter with quotes spacing and escaping with " "exceptions") { // TODO remove ss::string_error on all below try { ss::converter c; auto tup = c.convert( R"("just","some","strings")"); REQUIRE(c.valid()); CHECK_EQ(tup, std::make_tuple("\"just\"", "\"some\"", "\"strings\"")); } catch (ss::exception& e) { FAIL(std::string{e.what()}); } try { ss::converter> c; auto tup = c.convert( 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(std::string{e.what()}); } try { ss::converter> c; auto tup = c.convert( 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(std::string{e.what()}); } try { ss::converter> c; auto tup = c.convert(buff(R"(ju\,st,strings)")); REQUIRE(c.valid()); CHECK_EQ(tup, std::make_tuple("ju,st", "strings")); } catch (ss::exception& e) { FAIL(std::string{e.what()}); } try { ss::converter, ss::trim<' '>, ss::quote<'"'>> c; auto tup = c.convert( 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(std::string{e.what()}); } } TEST_CASE("converter test invalid split conversions") { ss::converter, ss::trim<' '>, ss::quote<'"'>> c; { // mismatched quote c.convert( buff(R"( "just , some , "12.3","a" )")); CHECK_FALSE(c.valid()); CHECK_FALSE(c.unterminated_quote()); CHECK_FALSE(c.error_msg().empty()); } { // unterminated quote c.convert( buff(R"( ju\,st , "so,me" , 12.34 , "str""ings)")); CHECK_FALSE(c.valid()); CHECK(c.unterminated_quote()); CHECK_FALSE(c.error_msg().empty()); } { // unterminated escape c.convert( buff(R"(just,some,2,strings\)")); CHECK_FALSE(c.valid()); CHECK_FALSE(c.unterminated_quote()); CHECK_FALSE(c.error_msg().empty()); } { // unterminated escape while quoting c.convert( buff(R"(just,some,2,"strings\)")); CHECK_FALSE(c.valid()); CHECK_FALSE(c.unterminated_quote()); CHECK_FALSE(c.error_msg().empty()); } { // unterminated escaped quote c.convert( 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::trim<' '>, ss::quote<'"'>, ss::throw_on_error> c; // mismatched quote REQUIRE_EXCEPTION(c.convert( buff(R"( "just , some , "12.3","a" )"))); CHECK_FALSE(c.unterminated_quote()); // unterminated quote REQUIRE_EXCEPTION(c.convert( buff(R"( ju\,st , "so,me" , 12.34 , "str""ings)"))); CHECK(c.unterminated_quote()); // unterminated escape REQUIRE_EXCEPTION(c.convert( buff(R"(just,some,2,strings\)"))); CHECK_FALSE(c.unterminated_quote()); // unterminated escape while quoting REQUIRE_EXCEPTION(c.convert( buff(R"(just,some,2,"strings\)"))); CHECK_FALSE(c.unterminated_quote()); // unterminated escaped quote REQUIRE_EXCEPTION(c.convert( buff(R"(just,some,2,"strings\")"))); CHECK(c.unterminated_quote()); }