Make throw_on_error and string_error separate options, update parser to have line reading a separate function with respect to splitting

This commit is contained in:
ado 2023-07-10 02:39:24 +02:00
parent 41b89d1d3d
commit a7a97b3ba8
8 changed files with 285 additions and 182 deletions

View File

@ -236,8 +236,7 @@ private:
if constexpr (string_error) {
error_.clear();
error_.append(splitter_.error_msg());
throw_if_throw_on_error<throw_on_error>(error_);
} else {
} else if constexpr (!throw_on_error) {
error_ = true;
}
}
@ -247,28 +246,46 @@ private:
error_.clear();
splitter_.set_error_unterminated_escape();
error_.append(splitter_.error_msg());
throw_if_throw_on_error<throw_on_error>(error_);
} else if constexpr (throw_on_error) {
splitter_.set_error_unterminated_escape();
} else {
error_ = true;
}
}
void set_error_unterminated_quote() {
if constexpr (string_error) {
error_.clear();
splitter_.set_error_unterminated_quote();
error_.append(splitter_.error_msg());
} else if constexpr (throw_on_error) {
splitter_.set_error_unterminated_quote();
} else {
error_ = true;
}
}
void set_error_multiline_limit_reached() {
constexpr static auto error_msg = "multiline limit reached";
if constexpr (string_error) {
error_.clear();
error_.append("multiline limit reached");
throw_if_throw_on_error<throw_on_error>(error_);
error_.append(error_msg);
} else if constexpr (throw_on_error) {
throw ss::exception{error_msg};
} else {
error_ = true;
}
}
void set_error_invalid_conversion(const string_range msg, size_t pos) {
constexpr static auto error_msg = "invalid conversion for parameter ";
if constexpr (string_error) {
error_.clear();
error_.append("invalid conversion for parameter ")
.append(error_sufix(msg, pos));
throw_if_throw_on_error<throw_on_error>(error_);
error_.append(error_msg).append(error_sufix(msg, pos));
} else if constexpr (throw_on_error) {
throw ss::exception{error_msg + error_sufix(msg, pos)};
} else {
error_ = true;
}
@ -279,20 +296,27 @@ private:
if constexpr (string_error) {
error_.clear();
error_.append(error).append(" ").append(error_sufix(msg, pos));
throw_if_throw_on_error<throw_on_error>(error_);
} else if constexpr (throw_on_error) {
throw ss::exception{error + (" " + error_sufix(msg, pos))};
} else {
error_ = true;
}
}
void set_error_number_of_columns(size_t expected_pos, size_t pos) {
constexpr static auto error_msg1 =
"invalid number of columns, expected: ";
constexpr static auto error_msg2 = ", got: ";
if constexpr (string_error) {
error_.clear();
error_.append("invalid number of columns, expected: ")
error_.append(error_msg1)
.append(std::to_string(expected_pos))
.append(", got: ")
.append(error_msg2)
.append(std::to_string(pos));
throw_if_throw_on_error<throw_on_error>(error_);
} else if constexpr (throw_on_error) {
throw ss::exception{error_msg1 + std::to_string(expected_pos) +
error_msg2 + std::to_string(pos)};
} else {
error_ = true;
}
@ -300,25 +324,32 @@ private:
void set_error_incompatible_mapping(size_t argument_size,
size_t mapping_size) {
constexpr static auto error_msg1 =
"number of arguments does not match mapping, expected: ";
constexpr static auto error_msg2 = ", got: ";
if constexpr (string_error) {
error_.clear();
error_
.append(
"number of arguments does not match mapping, expected: ")
error_.append(error_msg1)
.append(std::to_string(mapping_size))
.append(", got: ")
.append(error_msg2)
.append(std::to_string(argument_size));
throw_if_throw_on_error<throw_on_error>(error_);
} else if constexpr (throw_on_error) {
throw ss::exception{error_msg1 + std::to_string(mapping_size) +
error_msg2 + std::to_string(argument_size)};
} else {
error_ = true;
}
}
void set_error_invalid_mapping() {
constexpr static auto error_msg = "received empty mapping";
if constexpr (string_error) {
error_.clear();
error_.append("received empty mapping");
throw_if_throw_on_error<throw_on_error>(error_);
error_.append(error_msg);
} else if constexpr (throw_on_error) {
throw ss::exception{error_msg};
} else {
error_ = true;
}
@ -326,13 +357,19 @@ private:
void set_error_mapping_out_of_range(size_t maximum_index,
size_t number_of_columnts) {
constexpr static auto error_msg1 = "maximum index: ";
constexpr static auto error_msg2 = ", greater than number of columns: ";
if constexpr (string_error) {
error_.clear();
error_.append("maximum index: ")
error_.append(error_msg1)
.append(std::to_string(maximum_index))
.append(", greater then number of columns: ")
.append(error_msg2)
.append(std::to_string(number_of_columnts));
throw_if_throw_on_error<throw_on_error>(error_);
} else if constexpr (throw_on_error) {
throw ss::exception{error_msg1 + std::to_string(maximum_index) +
error_msg2 +
std::to_string(number_of_columnts)};
} else {
error_ = true;
}

View File

@ -20,11 +20,4 @@ public:
}
};
template <bool throw_on_error>
void throw_if_throw_on_error(const std::string& msg) {
if constexpr (throw_on_error) {
throw ss::exception(msg);
}
}
} /* ss */

View File

@ -87,8 +87,19 @@ public:
template <typename T, typename... Ts>
no_void_validator_tup_t<T, Ts...> get_next() {
if (!eof_) {
reader_.parse();
}
reader_.update();
if (!reader_.converter_.valid()) {
set_error_invalid_conversion();
read_line();
return {};
}
clear_error();
if (eof_) {
set_error_eof_reached();
return {};
@ -424,27 +435,36 @@ private:
}
void set_error_failed_check() {
constexpr static auto error_msg = " failed check";
if constexpr (string_error) {
error_.append(file_name_).append(" failed check");
throw_if_throw_on_error<throw_on_error>(error_);
error_.append(file_name_).append(error_msg);
} else if constexpr (throw_on_error) {
throw ss::exception{file_name_ + error_msg};
} else {
error_ = true;
}
}
void set_error_file_not_open() {
constexpr static auto error_msg = " could not be opened";
if constexpr (string_error) {
error_.append(file_name_).append(" could not be opened");
throw_if_throw_on_error<throw_on_error>(error_);
} else if constexpr (throw_on_error) {
throw ss::exception{file_name_ + error_msg};
} else {
error_ = true;
}
}
void set_error_eof_reached() {
constexpr static auto error_msg = " reached end of file";
if constexpr (string_error) {
error_.append(file_name_).append(" reached end of file");
throw_if_throw_on_error<throw_on_error>(error_);
} else if constexpr (throw_on_error) {
throw ss::exception{file_name_ + error_msg};
} else {
error_ = true;
}
@ -460,42 +480,45 @@ private:
.append(": \"")
.append(reader_.buffer_)
.append("\"");
throw_if_throw_on_error<throw_on_error>(error_);
} else {
} else if constexpr (!throw_on_error) {
error_ = true;
}
}
void set_error_header_ignored() {
constexpr static auto error_msg =
": \"the header row is ignored within the setup it cannot be "
"used\"";
if constexpr (string_error) {
error_.append(file_name_)
.append(": \"")
.append("the header row is ignored within the setup, it cannot "
"be used")
.append("\"");
throw_if_throw_on_error<throw_on_error>(error_);
error_.append(file_name_).append(error_msg);
} else if constexpr (throw_on_error) {
throw ss::exception{file_name_ + error_msg};
} else {
error_ = true;
}
}
void set_error_invalid_field(const std::string& field) {
constexpr static auto error_msg =
": header does not contain given field: ";
if constexpr (string_error) {
error_.append(file_name_)
.append(": header does not contain given field: ")
.append(field);
throw_if_throw_on_error<throw_on_error>(error_);
error_.append(file_name_).append(error_msg).append(field);
} else if constexpr (throw_on_error) {
throw ss::exception{file_name_ + error_msg + field};
} else {
error_ = true;
}
}
void set_error_field_used_multiple_times(const std::string& field) {
constexpr static auto error_msg = ": given field used multiple times: ";
if constexpr (string_error) {
error_.append(file_name_)
.append(": given field used multiple times: ")
.append(field);
throw_if_throw_on_error<throw_on_error>(error_);
error_.append(file_name_).append(error_msg).append(field);
} else if constexpr (throw_on_error) {
throw ss::exception{file_name_ + error_msg + field};
} else {
error_ = true;
}
@ -514,13 +537,15 @@ private:
: delim_{delim}, file_{fopen(file_name_.c_str(), "rb")} {
}
// TODO update for size_ and ssize_
reader(reader&& other)
: buffer_{other.buffer_},
next_line_buffer_{other.next_line_buffer_},
helper_buffer_{other.helper_buffer_}, converter_{std::move(
other.converter_)},
next_line_converter_{std::move(other.next_line_converter_)},
size_{other.size_}, next_line_size_{other.next_line_size_},
buffer_size_{other.size_},
next_line_buffer_size_{other.next_line_buffer_size_},
helper_size_{other.helper_size_}, delim_{std::move(other.delim_)},
file_{other.file_}, crlf_{other.crlf_}, line_number_{
other.line_number_} {
@ -537,8 +562,8 @@ private:
helper_buffer_ = other.helper_buffer_;
converter_ = std::move(other.converter_);
next_line_converter_ = std::move(other.next_line_converter_);
size_ = other.size_;
next_line_size_ = other.next_line_size_;
buffer_size_ = other.size_;
next_line_buffer_size_ = other.next_line_buffer_size_;
helper_size_ = other.helper_size_;
delim_ = std::move(other.delim_);
file_ = other.file_;
@ -568,16 +593,18 @@ private:
reader(const reader& other) = delete;
reader& operator=(const reader& other) = delete;
// read next line each time in order to set eof_
bool read_next() {
ssize_t ssize;
next_line_converter_.clear_error();
ssize_t ssize = 0;
size_t size = 0;
while (size == 0) {
++line_number_;
if (next_line_size_ > 0) {
if (next_line_buffer_size_ > 0) {
next_line_buffer_[0] = '\0';
}
ssize = get_line(&next_line_buffer_, &next_line_size_, file_);
ssize = get_line(&next_line_buffer_, &next_line_buffer_size_,
file_);
if (ssize == -1) {
return false;
@ -590,17 +617,24 @@ private:
}
}
size_ = size;
ssize_ = ssize;
return true;
}
void parse() {
size_t limit = 0;
if constexpr (escaped_multiline_enabled) {
while (escaped_eol(size)) {
while (escaped_eol(size_)) {
if (multiline_limit_reached(limit)) {
return true;
return;
}
if (!append_next_line_to_buffer(next_line_buffer_, size)) {
remove_eol(next_line_buffer_, ssize);
if (!append_next_line_to_buffer(next_line_buffer_, size_)) {
// remove_eol(next_line_buffer_, ssize_);
next_line_converter_.set_error_unterminated_escape();
return true;
return;
}
}
}
@ -610,38 +644,40 @@ private:
if constexpr (quoted_multiline_enabled) {
while (unterminated_quote()) {
if (multiline_limit_reached(limit)) {
return true;
return;
}
if (!append_next_line_to_buffer(next_line_buffer_, size)) {
remove_eol(next_line_buffer_, ssize);
return true;
if (!append_next_line_to_buffer(next_line_buffer_, size_)) {
// remove_eol(next_line_buffer_, ssize_);
next_line_converter_.set_error_unterminated_quote();
return;
}
if constexpr (escaped_multiline_enabled) {
while (escaped_eol(size)) {
while (escaped_eol(size_)) {
if (multiline_limit_reached(limit)) {
return true;
return;
}
if (!append_next_line_to_buffer(next_line_buffer_,
size)) {
remove_eol(next_line_buffer_, ssize);
size_)) {
// TODO not needed
// remove_eol(next_line_buffer_, ssize_);
next_line_converter_
.set_error_unterminated_escape();
return true;
return;
}
}
}
next_line_converter_.resplit(next_line_buffer_, size);
next_line_converter_.resplit(next_line_buffer_, size_);
}
}
return true;
}
void update() {
std::swap(buffer_, next_line_buffer_);
std::swap(size_, next_line_size_);
std::swap(buffer_size_, next_line_buffer_size_);
std::swap(converter_, next_line_converter_);
}
@ -666,10 +702,7 @@ private:
}
bool unterminated_quote() {
if (next_line_converter_.unterminated_quote()) {
return true;
}
return false;
return next_line_converter_.unterminated_quote();
}
void undo_remove_eol(char* buffer, size_t& string_end) {
@ -685,24 +718,29 @@ private:
}
}
size_t remove_eol(char*& buffer, size_t size) {
size_t new_size = size - 1;
if (size >= 2 && buffer[size - 2] == '\r') {
size_t remove_eol(char*& buffer, size_t ssize) {
size_t size = ssize - 1;
if (ssize >= 2 && buffer[ssize - 2] == '\r') {
crlf_ = true;
new_size--;
size--;
} else {
crlf_ = false;
}
buffer[new_size] = '\0';
return new_size;
buffer[size] = '\0';
return size;
}
void realloc_concat(char*& first, size_t& first_size,
const char* const second, size_t second_size) {
next_line_size_ = first_size + second_size + 3;
// TODO make buffer_size an argument !!!!!!
next_line_buffer_size_ = first_size + second_size + 3;
first = static_cast<char*>(
realloc(static_cast<void*>(first), next_line_size_));
realloc(static_cast<void*>(first), next_line_buffer_size_));
// TODO handle realloc
if (!first) {
exit(EXIT_FAILURE);
}
std::copy_n(second, second_size + 1, first + first_size);
first_size += second_size;
}
@ -722,8 +760,9 @@ private:
return true;
}
std::vector<std::string> get_next_row() const {
std::vector<std::string> get_next_row() {
std::vector<std::string> next_row;
next_line_converter_.split(next_line_buffer_, delim_);
auto& next_row_raw = next_line_converter_.splitter_.split_data_;
for (const auto& [begin, end] : next_row_raw) {
next_row.emplace_back(begin, end);
@ -741,8 +780,8 @@ private:
converter<Options...> converter_;
converter<Options...> next_line_converter_;
size_t size_{0};
size_t next_line_size_{0};
size_t buffer_size_{0};
size_t next_line_buffer_size_{0};
size_t helper_size_{0};
std::string delim_;
@ -750,6 +789,10 @@ private:
bool crlf_;
size_t line_number_{0};
// TODO check if needed
size_t size_{0};
ssize_t ssize_{0};
};
////////////////

View File

@ -217,7 +217,8 @@ private:
constexpr static auto count_multiline =
count_v<is_instance_of_multiline, Options...>;
constexpr static auto count_string_error = count_v<is_string_error, Options...>;
constexpr static auto count_string_error =
count_v<is_string_error, Options...>;
constexpr static auto count_ignore_header =
count_v<is_ignore_header, Options...>;
@ -225,7 +226,8 @@ private:
constexpr static auto count_throw_on_error =
count_v<is_throw_on_error, Options...>;
constexpr static auto count_ignore_empty = count_v<is_ignore_empty, Options...>;
constexpr static auto count_ignore_empty =
count_v<is_ignore_empty, Options...>;
constexpr static auto number_of_valid_setup_types =
count_matcher + count_multiline + count_string_error +
@ -249,8 +251,6 @@ public:
constexpr static bool ignore_header = (count_ignore_header == 1);
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"
@ -276,9 +276,16 @@ private:
"ambiguous trim setup");
static_assert(count_multiline <= 1, "mutliline defined multiple times");
static_assert(count_string_error <= 1,
"string_error defined multiple times");
static_assert(count_throw_on_error <= 1,
"throw_on_error defined multiple times");
static_assert(count_throw_on_error + count_string_error <= 1,
"cannot define both throw_on_error and string_error");
static_assert(number_of_valid_setup_types == sizeof...(Options),
"one or multiple invalid setup parameters defined");
};

View File

@ -25,6 +25,7 @@ private:
constexpr static auto throw_on_error = setup<Options...>::throw_on_error;
constexpr static auto is_const_line = !quote::enabled && !escape::enabled;
// TODO make error_type none if throw_on_error
using error_type = std::conditional_t<string_error, std::string, bool>;
public:
@ -77,17 +78,19 @@ private:
const std::string& delimiter = default_delimiter) {
// resplitting, continue from last slice
if (!quote::enabled || !multiline::enabled || split_data_.empty() ||
!unterminated_quote()) {
if constexpr (!quote::enabled || !multiline::enabled) {
if (split_data_.empty() || !unterminated_quote()) {
set_error_invalid_resplit();
return split_data_;
}
}
const auto [old_line, old_begin] = *std::prev(split_data_.end());
size_t begin = old_begin - old_line - 1;
// safety measure
if (new_size != -1 && static_cast<size_t>(new_size) < begin) {
unterminated_quote_ = false;
set_error_invalid_resplit();
return split_data_;
}
@ -114,62 +117,77 @@ private:
void clear_error() {
if constexpr (string_error) {
error_.clear();
} else {
} else if constexpr (!throw_on_error) {
error_ = false;
}
unterminated_quote_ = false;
}
void set_error_empty_delimiter() {
constexpr static auto error_msg = "empty delimiter";
if constexpr (string_error) {
error_.clear();
error_.append("empty delimiter");
throw_if_throw_on_error<throw_on_error>(error_);
error_.append(error_msg);
} else if constexpr (throw_on_error) {
throw ss::exception{error_msg};
} else {
error_ = true;
}
}
void set_error_mismatched_quote(size_t n) {
constexpr static auto error_msg = "mismatched quote at position: ";
if constexpr (string_error) {
error_.clear();
error_.append("mismatched quote at position: " + std::to_string(n));
throw_if_throw_on_error<throw_on_error>(error_);
error_.append(error_msg + std::to_string(n));
} else if constexpr (throw_on_error) {
throw ss::exception{error_msg + std::to_string(n)};
} else {
error_ = true;
}
}
// TODO rename with handle error
void set_error_unterminated_escape() {
constexpr static auto error_msg =
"unterminated escape at the end of the line";
if constexpr (string_error) {
error_.clear();
error_.append("unterminated escape at the end of the line");
throw_if_throw_on_error<throw_on_error>(error_);
error_.append(error_msg);
} else if constexpr (throw_on_error) {
throw ss::exception{error_msg};
} else {
error_ = true;
}
}
// TODO handle this efficiently
// TODO handle this efficiently (if multiline is enabled)
void set_error_unterminated_quote() {
unterminated_quote_ = true;
constexpr static auto error_msg = "unterminated quote";
if constexpr (string_error) {
error_.clear();
error_.append("unterminated quote");
throw_if_throw_on_error<throw_on_error>(error_);
error_.append(error_msg);
} else if constexpr (throw_on_error) {
throw ss::exception{error_msg};
} else {
error_ = true;
}
}
void set_error_invalid_resplit() {
// TODO check this
unterminated_quote_ = false;
constexpr static auto error_msg =
"invalid resplit, new line must be longer"
"than the end of the last slice";
if constexpr (string_error) {
error_.clear();
error_.append("invalid resplit, new line must be longer"
"than the end of the last slice");
throw_if_throw_on_error<throw_on_error>(error_);
error_.append(error_msg);
} else if constexpr (throw_on_error) {
throw ss::exception{error_msg};
} else {
error_ = true;
}
@ -244,7 +262,9 @@ private:
if constexpr (escape::enabled) {
if (escape::match(*curr)) {
if (curr[1] == '\0') {
if constexpr (!multiline::enabled) {
set_error_unterminated_escape();
}
done_ = true;
return;
}
@ -371,7 +391,9 @@ private:
if (end_[1] == '\0') {
// eol, unterminated escape
// eg: ... "hel\\0
if constexpr (!multiline::enabled) {
set_error_unterminated_escape();
}
done_ = true;
break;
}
@ -388,7 +410,10 @@ private:
// eg: ..."hell\0 -> quote not terminated
if (*end_ == '\0') {
shift_and_set_current();
unterminated_quote_ = true;
if constexpr (!multiline::enabled) {
set_error_unterminated_quote();
}
split_data_.emplace_back(line_, begin_);
done_ = true;
break;

View File

@ -42,7 +42,7 @@ TEST_CASE("converter test split with exceptions") {
}
}
} catch (ss::exception& e) {
FAIL(e.what());
FAIL(std::string{e.what()});
}
}
@ -148,7 +148,7 @@ TEST_CASE("converter test valid conversions with exceptions") {
REQUIRE(c.valid());
CHECK_EQ(tup, 5);
} catch (ss::exception& e) {
FAIL(e.what());
FAIL(std::string{e.what()});
}
try {
@ -156,7 +156,7 @@ TEST_CASE("converter test valid conversions with exceptions") {
REQUIRE(c.valid());
CHECK_EQ(tup, 5);
} catch (ss::exception& e) {
FAIL(e.what());
FAIL(std::string{e.what()});
}
try {
@ -164,7 +164,7 @@ TEST_CASE("converter test valid conversions with exceptions") {
REQUIRE(c.valid());
CHECK_EQ(tup, 5);
} catch (ss::exception& e) {
FAIL(e.what());
FAIL(std::string{e.what()});
}
try {
@ -172,7 +172,7 @@ TEST_CASE("converter test valid conversions with exceptions") {
REQUIRE(c.valid());
CHECK_EQ(tup, 5);
} catch (ss::exception& e) {
FAIL(e.what());
FAIL(std::string{e.what()});
}
try {
@ -180,7 +180,7 @@ TEST_CASE("converter test valid conversions with exceptions") {
REQUIRE(c.valid());
CHECK_EQ(tup, 5);
} catch (ss::exception& e) {
FAIL(e.what());
FAIL(std::string{e.what()});
}
try {
@ -188,7 +188,7 @@ TEST_CASE("converter test valid conversions with exceptions") {
REQUIRE(c.valid());
CHECK_EQ(tup, 5);
} catch (ss::exception& e) {
FAIL(e.what());
FAIL(std::string{e.what()});
}
try {
@ -198,7 +198,7 @@ TEST_CASE("converter test valid conversions with exceptions") {
REQUIRE(tup.has_value());
CHECK_EQ(tup, 5);
} catch (ss::exception& e) {
FAIL(e.what());
FAIL(std::string{e.what()});
}
try {
@ -206,7 +206,7 @@ TEST_CASE("converter test valid conversions with exceptions") {
REQUIRE(c.valid());
CHECK_EQ(tup, std::make_tuple(5, 6.6));
} catch (ss::exception& e) {
FAIL(e.what());
FAIL(std::string{e.what()});
}
try {
@ -214,7 +214,7 @@ TEST_CASE("converter test valid conversions with exceptions") {
REQUIRE(c.valid());
CHECK_EQ(tup, std::make_tuple(5, 6.6));
} catch (ss::exception& e) {
FAIL(e.what());
FAIL(std::string{e.what()});
}
try {
@ -222,7 +222,7 @@ TEST_CASE("converter test valid conversions with exceptions") {
REQUIRE(c.valid());
CHECK_EQ(tup, std::make_tuple(5, 6.6));
} catch (ss::exception& e) {
FAIL(e.what());
FAIL(std::string{e.what()});
}
try {
@ -232,7 +232,7 @@ TEST_CASE("converter test valid conversions with exceptions") {
REQUIRE(std::get<0>(tup).has_value());
CHECK_EQ(tup, std::make_tuple(5, 6.6));
} catch (ss::exception& e) {
FAIL(e.what());
FAIL(std::string{e.what()});
}
try {
@ -242,7 +242,7 @@ TEST_CASE("converter test valid conversions with exceptions") {
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());
FAIL(std::string{e.what()});
}
try {
@ -253,7 +253,7 @@ TEST_CASE("converter test valid conversions with exceptions") {
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());
FAIL(std::string{e.what()});
}
try {
@ -264,7 +264,7 @@ TEST_CASE("converter test valid conversions with exceptions") {
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());
FAIL(std::string{e.what()});
}
try {
@ -274,7 +274,7 @@ TEST_CASE("converter test valid conversions with exceptions") {
CHECK_EQ(tup, std::make_tuple(std::string_view{"s1"}, 6.6,
std::string_view{"s2"}));
} catch (ss::exception& e) {
FAIL(e.what());
FAIL(std::string{e.what()});
}
}
@ -316,8 +316,7 @@ TEST_CASE("converter test invalid conversions") {
}
TEST_CASE("converter test invalid conversions with exceptions") {
// TODO remove ss::string_error
ss::converter<ss::string_error, ss::throw_on_error> c;
ss::converter<ss::throw_on_error> c;
REQUIRE_EXCEPTION(c.convert<int>(""));
REQUIRE_EXCEPTION(c.convert<int>("1", ""));
@ -366,7 +365,7 @@ 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;
ss::converter<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"));
@ -387,7 +386,7 @@ TEST_CASE("converter test ss:ax restriction (all except) with exceptions") {
CHECK_EQ(tup, std::make_tuple(3, 'c'));
}
} catch (ss::exception& e) {
FAIL(e.what());
FAIL(std::string{e.what()});
}
}
@ -427,7 +426,7 @@ 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;
ss::converter<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"));
@ -455,7 +454,7 @@ TEST_CASE("converter test ss:nx restriction (none except) with exceptions") {
CHECK_EQ(tup, std::make_tuple(1, 'c'));
}
} catch (ss::exception& e) {
FAIL(e.what());
FAIL(std::string{e.what()});
}
}
@ -495,7 +494,7 @@ 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;
ss::converter<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"));
@ -523,7 +522,7 @@ TEST_CASE("converter test ss:ir restriction (in range) with exceptions") {
CHECK_EQ(tup, std::make_tuple(1, 'c'));
}
} catch (ss::exception& e) {
FAIL(e.what());
FAIL(std::string{e.what()});
}
}
@ -563,7 +562,7 @@ 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;
ss::converter<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"));
@ -589,7 +588,7 @@ TEST_CASE("converter test ss:oor restriction (out of range) with exceptions") {
CHECK_EQ(tup, std::make_tuple(3, 'c'));
}
} catch (ss::exception& e) {
FAIL(e.what());
FAIL(std::string{e.what()});
}
}
@ -643,7 +642,7 @@ 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;
ss::converter<ss::throw_on_error> c;
REQUIRE_EXCEPTION(c.convert<ss::ne<std::string>>(""));
REQUIRE_EXCEPTION(c.convert<int, ss::ne<std::string>>("3,"));
@ -669,7 +668,7 @@ TEST_CASE("converter test ss:ne restriction (not empty) with exceptions") {
CHECK_EQ(tup, extracted_vector);
}
} catch (ss::exception& e) {
FAIL(e.what());
FAIL(std::string{e.what()});
}
}
@ -735,7 +734,7 @@ 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;
ss::converter<ss::throw_on_error> c;
REQUIRE_EXCEPTION(c.convert<ss::lt<int, 3>>("3"));
REQUIRE_EXCEPTION(c.convert<ss::lt<int, 2>>("3"));
@ -781,7 +780,7 @@ TEST_CASE("converter test ss:lt ss::lte ss::gt ss::gte restriction (in range) "
CHECK_EQ(tup, 3);
}
} catch (ss::exception& e) {
FAIL(e.what());
FAIL(std::string{e.what()});
}
}
@ -794,7 +793,7 @@ TEST_CASE("converter test error mode") {
TEST_CASE("converter test throw on error mode") {
// TODO remove ss::string_error
ss::converter<ss::string_error, ss::throw_on_error> c;
ss::converter<ss::throw_on_error> c;
REQUIRE_EXCEPTION(c.convert<int>("junk"));
}
@ -849,14 +848,14 @@ 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;
ss::converter<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());
FAIL(std::string{e.what()});
}
try {
@ -867,34 +866,34 @@ TEST_CASE("converter test converter with quotes spacing and escaping with "
REQUIRE(c.valid());
CHECK_EQ(tup, std::make_tuple("just", "some", 12.3, 'a'));
} catch (ss::exception& e) {
FAIL(e.what());
FAIL(std::string{e.what()});
}
try {
ss::converter<ss::string_error, ss::throw_on_error, ss::trim<' '>> c;
ss::converter<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());
FAIL(std::string{e.what()});
}
try {
ss::converter<ss::string_error, ss::throw_on_error, ss::escape<'\\'>> c;
ss::converter<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());
FAIL(std::string{e.what()});
}
try {
ss::converter<ss::string_error, ss::throw_on_error, ss::escape<'\\'>,
ss::trim<' '>, ss::quote<'"'>>
ss::converter<ss::throw_on_error, ss::escape<'\\'>, ss::trim<' '>,
ss::quote<'"'>>
c;
auto tup = c.convert<std::string, std::string, double, std::string>(
@ -902,7 +901,7 @@ TEST_CASE("converter test converter with quotes spacing and escaping with "
REQUIRE(c.valid());
CHECK_EQ(tup, std::make_tuple("ju,st", "so,me", 12.34, "str\"ings"));
} catch (ss::exception& e) {
FAIL(e.what());
FAIL(std::string{e.what()});
}
}
@ -959,8 +958,8 @@ TEST_CASE("converter test invalid split conversions") {
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>
ss::converter<ss::escape<'\\'>, ss::trim<' '>, ss::quote<'"'>,
ss::throw_on_error>
c;
// mismatched quote

View File

@ -856,6 +856,7 @@ TEST_CASE("parser test multiline restricted") {
for (auto& [_, __, s] : i) {
update_if_crlf(s);
}
CHECK_EQ(i, data);
}

View File

@ -201,7 +201,7 @@ void test_combinations(matches_type& matches, std::vector<std::string> delims) {
auto vec = st.split(buff(lines[i].c_str()), delim);
CHECK_EQ(words(vec), expectations[i]);
} catch (ss::exception& e) {
FAIL(e.what());
FAIL(std::string{e.what()});
}
}
}
@ -520,8 +520,7 @@ TEST_CASE("splitter test error mode") {
CHECK_FALSE(s.error_msg().empty());
try {
// TODO remove ss::string_error
ss::splitter<ss::string_error, ss::throw_on_error> s;
ss::splitter<ss::throw_on_error> s;
s.split(buff("just,some,strings"), "");
FAIL("expected exception");
} catch (ss::exception& e) {
@ -544,12 +543,12 @@ template <typename Splitter>
auto expect_unterminated_quote(Splitter& s, const std::string& line) {
try {
auto vec = s.split(buff(line.c_str()));
CHECK_FALSE(s.valid());
CHECK(s.valid());
CHECK(s.unterminated_quote());
return vec;
} catch (ss::exception& e) {
// TODO check if this is ok
FAIL(e.what());
FAIL(std::string{e.what()});
return decltype(s.split(buff(line.c_str()))){};
}
}
@ -658,7 +657,7 @@ TEST_CASE("splitter test resplit unterminated quote") {
{
auto new_line = buff.append(R"(,dom)");
vec = c.resplit(new_line, strlen(new_line));
CHECK_FALSE(s.valid());
CHECK(s.valid());
CHECK(s.unterminated_quote());
CHECK_EQ(words(vec), expected);
}
@ -808,7 +807,6 @@ TEST_CASE("splitter test resplit unterminated quote with exceptions") {
auto vec = expect_unterminated_quote(s, R"("x)");
CHECK_EQ(vec.size(), 1);
REQUIRE(s.unterminated_quote());
{
@ -832,7 +830,7 @@ TEST_CASE("splitter test resplit unterminated quote with exceptions") {
CHECK_EQ(words(vec)[0], "xax");
}
} catch (ss::exception& e) {
FAIL(e.what());
FAIL(std::string{e.what()});
}
try {
@ -848,7 +846,7 @@ TEST_CASE("splitter test resplit unterminated quote with exceptions") {
std::vector<std::string> expected{"just", "strings"};
CHECK_EQ(words(vec), expected);
} catch (ss::exception& e) {
FAIL(e.what());
FAIL(std::string{e.what()});
}
try {
@ -865,7 +863,7 @@ TEST_CASE("splitter test resplit unterminated quote with exceptions") {
expected = {"just", "some", "random", "strings"};
CHECK_EQ(words(vec), expected);
} catch (ss::exception& e) {
FAIL(e.what());
FAIL(std::string{e.what()});
}
try {
@ -883,7 +881,7 @@ TEST_CASE("splitter test resplit unterminated quote with exceptions") {
expected = {"just", "some", "ran\",dom", "strings"};
CHECK_EQ(words(vec), expected);
} catch (ss::exception& e) {
FAIL(e.what());
FAIL(std::string{e.what()});
}
try {
@ -897,7 +895,7 @@ TEST_CASE("splitter test resplit unterminated quote with exceptions") {
{
auto new_line = buff.append(R"(,dom)");
vec = c.resplit(new_line, strlen(new_line));
CHECK_FALSE(s.valid());
CHECK(s.valid());
CHECK(s.unterminated_quote());
CHECK_EQ(words(vec), expected);
}
@ -911,7 +909,7 @@ TEST_CASE("splitter test resplit unterminated quote with exceptions") {
CHECK_EQ(words(vec), expected);
}
} catch (ss::exception& e) {
FAIL(e.what());
FAIL(std::string{e.what()});
}
try {
@ -934,7 +932,7 @@ TEST_CASE("splitter test resplit unterminated quote with exceptions") {
CHECK_EQ(words(vec), expected);
}
} catch (ss::exception& e) {
FAIL(e.what());
FAIL(std::string{e.what()});
}
try {
@ -961,7 +959,7 @@ TEST_CASE("splitter test resplit unterminated quote with exceptions") {
CHECK_EQ(words(vec), expected);
}
} catch (ss::exception& e) {
FAIL(e.what());
FAIL(std::string{e.what()});
}
try {
@ -985,7 +983,7 @@ TEST_CASE("splitter test resplit unterminated quote with exceptions") {
CHECK_EQ(words(vec), expected);
}
} catch (ss::exception& e) {
FAIL(e.what());
FAIL(std::string{e.what()});
}
try {
@ -1009,7 +1007,7 @@ TEST_CASE("splitter test resplit unterminated quote with exceptions") {
CHECK_EQ(words(vec), expected);
}
} catch (ss::exception& e) {
FAIL(e.what());
FAIL(std::string{e.what()});
}
try {
@ -1032,7 +1030,7 @@ TEST_CASE("splitter test resplit unterminated quote with exceptions") {
CHECK_EQ(words(vec), expected);
}
} catch (ss::exception& e) {
FAIL(e.what());
FAIL(std::string{e.what()});
}
try {
@ -1057,7 +1055,7 @@ TEST_CASE("splitter test resplit unterminated quote with exceptions") {
CHECK_EQ(words(vec), expected);
}
} catch (ss::exception& e) {
FAIL(e.what());
FAIL(std::string{e.what()});
}
}
@ -1106,8 +1104,8 @@ TEST_CASE("splitter test invalid splits") {
}
TEST_CASE("splitter test invalid splits with exceptions") {
ss::converter<ss::string_error, ss::quote<'"'>, ss::trim<' '>,
ss::escape<'\\'>, ss::throw_on_error>
ss::converter<ss::throw_on_error, ss::quote<'"'>, ss::trim<' '>,
ss::escape<'\\'>>
c;
auto& s = c.splitter;