mirror of
https://github.com/red0124/ssp.git
synced 2025-01-23 04:55:20 +01:00
Add invalid header usage tests
This commit is contained in:
parent
c981ed6644
commit
634abdd38b
@ -344,39 +344,6 @@ private:
|
||||
}
|
||||
}
|
||||
|
||||
void set_error_invalid_mapping() {
|
||||
constexpr static auto error_msg = "received empty mapping";
|
||||
|
||||
if constexpr (string_error) {
|
||||
error_.clear();
|
||||
error_.append(error_msg);
|
||||
} else if constexpr (throw_on_error) {
|
||||
throw ss::exception{error_msg};
|
||||
} else {
|
||||
error_ = true;
|
||||
}
|
||||
}
|
||||
|
||||
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(error_msg1)
|
||||
.append(std::to_string(maximum_index))
|
||||
.append(error_msg2)
|
||||
.append(std::to_string(number_of_columnts));
|
||||
} 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;
|
||||
}
|
||||
}
|
||||
|
||||
////////////////
|
||||
// convert implementation
|
||||
////////////////
|
||||
@ -433,19 +400,9 @@ private:
|
||||
return column_mappings_[tuple_position];
|
||||
}
|
||||
|
||||
// assumes positions are valid and the vector is not empty
|
||||
void set_column_mapping(std::vector<size_t> positions,
|
||||
size_t number_of_columns) {
|
||||
if (positions.empty()) {
|
||||
set_error_invalid_mapping();
|
||||
return;
|
||||
}
|
||||
|
||||
auto max_index = *std::max_element(positions.begin(), positions.end());
|
||||
if (max_index >= number_of_columns) {
|
||||
set_error_mapping_out_of_range(max_index, number_of_columns);
|
||||
return;
|
||||
}
|
||||
|
||||
column_mappings_ = positions;
|
||||
number_of_columns_ = number_of_columns;
|
||||
}
|
||||
|
@ -138,6 +138,12 @@ public:
|
||||
}
|
||||
|
||||
auto fields = std::vector<std::string>{fields_args...};
|
||||
|
||||
if (fields.empty()) {
|
||||
set_error_empty_mapping();
|
||||
return;
|
||||
}
|
||||
|
||||
std::vector<size_t> column_mappings;
|
||||
|
||||
for (const auto& field : fields) {
|
||||
@ -159,6 +165,7 @@ public:
|
||||
reader_.converter_.set_column_mapping(column_mappings, header_.size());
|
||||
reader_.next_line_converter_.set_column_mapping(column_mappings,
|
||||
header_.size());
|
||||
|
||||
if (line() == 0) {
|
||||
ignore_next();
|
||||
}
|
||||
@ -485,15 +492,11 @@ private:
|
||||
|
||||
void set_error_invalid_conversion() {
|
||||
if constexpr (string_error) {
|
||||
// TODO remove buffer from error msg
|
||||
error_.append(file_name_)
|
||||
.append(" ")
|
||||
.append(std::to_string(reader_.line_number_))
|
||||
.append(": ")
|
||||
.append(reader_.converter_.error_msg())
|
||||
.append(": \"")
|
||||
.append(reader_.buffer_)
|
||||
.append("\"");
|
||||
.append(reader_.converter_.error_msg());
|
||||
} else if constexpr (!throw_on_error) {
|
||||
error_ = true;
|
||||
}
|
||||
@ -538,6 +541,19 @@ private:
|
||||
}
|
||||
}
|
||||
|
||||
void set_error_empty_mapping() {
|
||||
constexpr static auto error_msg = "received empty mapping";
|
||||
|
||||
if constexpr (string_error) {
|
||||
error_.clear();
|
||||
error_.append(error_msg);
|
||||
} else if constexpr (throw_on_error) {
|
||||
throw ss::exception{error_msg};
|
||||
} else {
|
||||
error_ = true;
|
||||
}
|
||||
}
|
||||
|
||||
////////////////
|
||||
// line reading
|
||||
////////////////
|
||||
|
@ -978,3 +978,4 @@ TEST_CASE("converter test invalid split conversions with exceptions") {
|
||||
buff(R"(just,some,2,"strings\")")));
|
||||
CHECK(c.unterminated_quote());
|
||||
}
|
||||
|
||||
|
@ -1168,14 +1168,12 @@ void test_invalid_fields_impl(const std::vector<std::string>& lines,
|
||||
}
|
||||
out.close();
|
||||
|
||||
/* TODO test
|
||||
{
|
||||
// No fields specified
|
||||
ss::parser<Ts...> p{f.name, ","};
|
||||
p.use_fields();
|
||||
CHECK(!p.valid());
|
||||
auto command = [&] { p.use_fields(); };
|
||||
expect_error_on_command(p, command);
|
||||
}
|
||||
*/
|
||||
|
||||
{
|
||||
// Unknown field
|
||||
|
Loading…
Reference in New Issue
Block a user