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);
return convert<Ts...>(splitter_.split_data_);
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();