mirror of
https://github.com/red0124/ssp.git
synced 2025-12-14 21:59:55 +01:00
[skip ci] Update coverage.yml, add unit test for files and buffers without new line at the end of the file
This commit is contained in:
@@ -80,7 +80,8 @@ std::enable_if_t<ss::has_m_tied_t<T>, bool> operator==(const T& lhs,
|
||||
template <typename T>
|
||||
static void make_and_write(const std::string& file_name,
|
||||
const std::vector<T>& data,
|
||||
const std::vector<std::string>& header = {}) {
|
||||
const std::vector<std::string>& header = {},
|
||||
bool new_line_eof = true) {
|
||||
std::ofstream out{file_name};
|
||||
|
||||
#ifdef _WIN32
|
||||
@@ -101,7 +102,10 @@ static void make_and_write(const std::string& file_name,
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < data.size(); ++i) {
|
||||
out << data[i].to_string() << new_lines[i % new_lines.size()];
|
||||
out << data[i].to_string();
|
||||
if (new_line_eof || i + 1 < data.size()) {
|
||||
out << new_lines[i % new_lines.size()];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -551,3 +551,32 @@ TEST_CASE("parser test composite conversion") {
|
||||
test_composite_conversion<false, ss::string_error>();
|
||||
test_composite_conversion<true, ss::string_error>();
|
||||
}
|
||||
|
||||
template <bool buffer_mode>
|
||||
void test_no_new_line_at_eof_impl(const std::vector<X>& data) {
|
||||
unique_file_name f{"test_parser"};
|
||||
make_and_write(f.name, data, {}, false);
|
||||
|
||||
auto [p, _] = make_parser<buffer_mode>(f.name);
|
||||
std::vector<X> parsed_data;
|
||||
|
||||
for (const auto& el : p.template iterate<X>()) {
|
||||
parsed_data.push_back(el);
|
||||
}
|
||||
|
||||
CHECK_EQ(data, parsed_data);
|
||||
}
|
||||
|
||||
template <bool buffer_mode>
|
||||
void test_no_new_line_at_eof() {
|
||||
test_no_new_line_at_eof_impl<buffer_mode>({});
|
||||
test_no_new_line_at_eof_impl<buffer_mode>({{1, 2, "X"}});
|
||||
test_no_new_line_at_eof_impl<buffer_mode>({{1, 2, "X"}, {3, 4, "YY"}});
|
||||
test_no_new_line_at_eof_impl<buffer_mode>(
|
||||
{{1, 2, "X"}, {3, 4, "YY"}, {5, 6, "ZZZ"}, {7, 8, "UUU"}});
|
||||
}
|
||||
|
||||
TEST_CASE("test no new line at end of data") {
|
||||
test_no_new_line_at_eof<false>();
|
||||
test_no_new_line_at_eof<true>();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user