From 1a694a8b26a441b12547057d6e0be61a111cced3 Mon Sep 17 00:00:00 2001 From: Spartan322 Date: Sat, 15 Jun 2024 09:40:31 -0400 Subject: Add unit tests Make github action tests run explicit Fix dropping annotation list for Errors Fix potential empty get_errors crashes Fix incorrect csv error behavior Add use_sep for `LineObject` and `std::vector` Remove constexpr of load_from_buffer and load_from_string for parsers Add snitch-org/snitch@d6632123cc8d13bdbc5cd60fd6741b9e0f635e82 Make versioned submodules ignore dirty Add tests/bin/* to gitignore --- src/openvic-dataloader/csv/Parser.cpp | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) (limited to 'src/openvic-dataloader/csv') diff --git a/src/openvic-dataloader/csv/Parser.cpp b/src/openvic-dataloader/csv/Parser.cpp index 5dbee32..8fe8b17 100644 --- a/src/openvic-dataloader/csv/Parser.cpp +++ b/src/openvic-dataloader/csv/Parser.cpp @@ -3,6 +3,7 @@ #include #include +#include #include #include #include @@ -15,6 +16,8 @@ #include #include +#include + #include "CsvGrammar.hpp" #include "CsvParseState.hpp" #include "detail/NullBuff.hpp" @@ -53,6 +56,13 @@ struct Parser::ParseHandler final : detail::BasicFileParseHandler return _lines; } + Parser::error_range get_errors() { + using iterator = typename decltype(std::declval()->children())::iterator; + if (!is_valid()) + return dryad::make_node_range(iterator::from_ptr(nullptr), iterator::from_ptr(nullptr)); + return parse_state().logger().get_errors(); + } + private: std::vector _lines; }; @@ -126,19 +136,19 @@ constexpr void Parser::_run_load_func(detail::LoadCallback encoding_fallback) { +Parser& Parser::load_from_buffer(const char* data, std::size_t size, std::optional encoding_fallback) { // Type can't be deduced? _run_load_func(std::mem_fn(&ParseHandler::load_buffer_size), data, size, encoding_fallback); return *this; } -constexpr Parser& Parser::load_from_buffer(const char* start, const char* end, std::optional encoding_fallback) { +Parser& Parser::load_from_buffer(const char* start, const char* end, std::optional encoding_fallback) { // Type can't be deduced? _run_load_func(std::mem_fn(&ParseHandler::load_buffer), start, end, encoding_fallback); return *this; } -constexpr Parser& Parser::load_from_string(const std::string_view string, std::optional encoding_fallback) { +Parser& Parser::load_from_string(const std::string_view string, std::optional encoding_fallback) { return load_from_buffer(string.data(), string.size(), encoding_fallback); } @@ -166,7 +176,7 @@ bool Parser::parse_csv(bool handle_strings) { }(); _has_error = _parse_handler->parse_state().logger().errored(); _has_warning = _parse_handler->parse_state().logger().warned(); - if (!errors->empty()) { + if (errors && !errors->empty()) { _has_error = true; _has_fatal_error = true; if (&_error_stream.get() != &detail::cnull) { @@ -182,7 +192,7 @@ const std::vector& Parser::get_lines() const { } typename Parser::error_range Parser::get_errors() const { - return _parse_handler->parse_state().logger().get_errors(); + return _parse_handler->get_errors(); } const FilePosition Parser::get_error_position(const error::Error* error) const { -- cgit v1.2.3-56-ga3b1