diff options
author | Spartan322 <Megacake1234@gmail.com> | 2024-06-15 15:40:31 +0200 |
---|---|---|
committer | Spartan322 <Megacake1234@gmail.com> | 2024-06-22 13:57:49 +0200 |
commit | 1a694a8b26a441b12547057d6e0be61a111cced3 (patch) | |
tree | 51ca6d5948e92be37b9ee6674cb96801d2cd03f8 /include | |
parent | 8b623bf4087aa360842ad31145d4ab6946cee9aa (diff) |
Add unit testsadd/unit-testing
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<LineObject>`
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
Diffstat (limited to 'include')
-rw-r--r-- | include/openvic-dataloader/Error.hpp | 7 | ||||
-rw-r--r-- | include/openvic-dataloader/NodeLocation.hpp | 10 | ||||
-rw-r--r-- | include/openvic-dataloader/csv/LineObject.hpp | 50 | ||||
-rw-r--r-- | include/openvic-dataloader/csv/Parser.hpp | 6 | ||||
-rw-r--r-- | include/openvic-dataloader/v2script/AbstractSyntaxTree.hpp | 7 | ||||
-rw-r--r-- | include/openvic-dataloader/v2script/Parser.hpp | 6 |
6 files changed, 67 insertions, 19 deletions
diff --git a/include/openvic-dataloader/Error.hpp b/include/openvic-dataloader/Error.hpp index a2e13fe..343abd9 100644 --- a/include/openvic-dataloader/Error.hpp +++ b/include/openvic-dataloader/Error.hpp @@ -117,11 +117,10 @@ namespace ovdl::error { protected: explicit AnnotatedError(dryad::node_ctor ctor, ErrorKind kind) : node_base(ctor, kind) { insert_child_list_after(nullptr, AnnotationList {}); - _last_annotation = nullptr; } private: - Annotation* _last_annotation; + Annotation* _last_annotation = nullptr; }; struct ParseError : dryad::abstract_node_range<AnnotatedError, ErrorKind::FirstParseError, ErrorKind::LastParseError> { @@ -207,7 +206,7 @@ namespace ovdl::error { inline void AnnotatedError::push_back(AnnotationList p_annotations) { if (p_annotations.empty()) return; - insert_child_list_after(annotations().end().deref(), p_annotations); - _last_annotation = *p_annotations.end(); + insert_child_list_after(_last_annotation, p_annotations); + _last_annotation = p_annotations.back(); } }
\ No newline at end of file diff --git a/include/openvic-dataloader/NodeLocation.hpp b/include/openvic-dataloader/NodeLocation.hpp index ced79e6..7f7a09c 100644 --- a/include/openvic-dataloader/NodeLocation.hpp +++ b/include/openvic-dataloader/NodeLocation.hpp @@ -11,10 +11,12 @@ namespace ovdl { const char_type* _end = nullptr; BasicNodeLocation() = default; - BasicNodeLocation(const char_type* pos) : _begin(pos), - _end(pos) {} - BasicNodeLocation(const char_type* begin, const char_type* end) : _begin(begin), - _end(end) {} + BasicNodeLocation(const char_type* pos) + : _begin(pos), + _end(pos) {} + BasicNodeLocation(const char_type* begin, const char_type* end) + : _begin(begin), + _end(end) {} BasicNodeLocation(const BasicNodeLocation&) noexcept = default; BasicNodeLocation& operator=(const BasicNodeLocation&) = default; diff --git a/include/openvic-dataloader/csv/LineObject.hpp b/include/openvic-dataloader/csv/LineObject.hpp index c839be2..5de55ba 100644 --- a/include/openvic-dataloader/csv/LineObject.hpp +++ b/include/openvic-dataloader/csv/LineObject.hpp @@ -80,6 +80,15 @@ namespace ovdl::csv { constexpr std::size_t value_count() const { return _suffix_end; } + struct SepTransformer { + const LineObject& line_object; + std::string_view separator; + }; + + constexpr SepTransformer use_sep(std::string_view seperator) const { + return { *this, seperator }; + } + private: // Should be position of first valid value on line position_type _prefix_end = 0; @@ -87,6 +96,15 @@ namespace ovdl::csv { position_type _suffix_end = 0; }; + struct VectorSepTransformer { + const std::vector<LineObject>& vector; + std::string_view separator; + }; + + constexpr VectorSepTransformer use_sep(const std::vector<LineObject>& vector, std::string_view separator) { + return { vector, separator }; + } + inline std::ostream& operator<<(std::ostream& stream, const LineObject& line) { static constexpr char SEP = ';'; LineObject::position_type sep_index = 0; @@ -110,4 +128,36 @@ namespace ovdl::csv { } return stream; } + + inline std::ostream& operator<<(std::ostream& stream, const LineObject::SepTransformer& transformer) { + auto quote_check = [&transformer, is_one = transformer.separator.size() == 1](const std::string_view str) { + if (is_one) { + char SEP = transformer.separator[0]; + return std::any_of(str.begin(), str.end(), [SEP](char c) { return c == SEP || std::isspace(c); }); + } + return std::any_of(str.begin(), str.end(), [](char c) { return std::isspace(c); }) || + str.find(transformer.separator) != std::string::npos; + }; + + LineObject::position_type sep_index = 0; + for (const auto& [pos, val] : transformer.line_object) { + while (sep_index < pos) { + stream << transformer.separator; + sep_index++; + } + if (quote_check(val)) { + stream << '"' << val << '"'; + } else { + stream << val; + } + } + return stream; + } + + inline std::ostream& operator<<(std::ostream& stream, const VectorSepTransformer& transformer) { + for (const LineObject& line : transformer.vector) { + stream << line.use_sep(transformer.separator) << '\n'; + } + return stream; + } }
\ No newline at end of file diff --git a/include/openvic-dataloader/csv/Parser.hpp b/include/openvic-dataloader/csv/Parser.hpp index 35421c8..1c363c8 100644 --- a/include/openvic-dataloader/csv/Parser.hpp +++ b/include/openvic-dataloader/csv/Parser.hpp @@ -25,9 +25,9 @@ namespace ovdl::csv { static Parser from_file(const char* path, std::optional<detail::Encoding> encoding_fallback = std::nullopt); static Parser from_file(const std::filesystem::path& path, std::optional<detail::Encoding> encoding_fallback = std::nullopt); - constexpr Parser& load_from_buffer(const char* data, std::size_t size, std::optional<detail::Encoding> encoding_fallback = std::nullopt); - constexpr Parser& load_from_buffer(const char* start, const char* end, std::optional<detail::Encoding> encoding_fallback = std::nullopt); - constexpr Parser& load_from_string(const std::string_view string, std::optional<detail::Encoding> encoding_fallback = std::nullopt); + Parser& load_from_buffer(const char* data, std::size_t size, std::optional<detail::Encoding> encoding_fallback = std::nullopt); + Parser& load_from_buffer(const char* start, const char* end, std::optional<detail::Encoding> encoding_fallback = std::nullopt); + Parser& load_from_string(const std::string_view string, std::optional<detail::Encoding> encoding_fallback = std::nullopt); Parser& load_from_file(const char* path, std::optional<detail::Encoding> encoding_fallback = std::nullopt); Parser& load_from_file(const std::filesystem::path& path, std::optional<detail::Encoding> encoding_fallback = std::nullopt); diff --git a/include/openvic-dataloader/v2script/AbstractSyntaxTree.hpp b/include/openvic-dataloader/v2script/AbstractSyntaxTree.hpp index 29e7866..a582187 100644 --- a/include/openvic-dataloader/v2script/AbstractSyntaxTree.hpp +++ b/include/openvic-dataloader/v2script/AbstractSyntaxTree.hpp @@ -108,9 +108,7 @@ namespace ovdl::v2script::ast { struct ListValue : dryad::basic_node<NodeKind::ListValue, dryad::container_node<Value>> { explicit ListValue(dryad::node_ctor ctor, StatementList statements); explicit ListValue(dryad::node_ctor ctor, AssignStatementList statements); - - explicit ListValue(dryad::node_ctor ctor) : ListValue(ctor, StatementList {}) { - } + explicit ListValue(dryad::node_ctor ctor); DRYAD_CHILD_NODE_RANGE_GETTER(Statement, statements, nullptr, this->node_after(_last_statement)); @@ -167,8 +165,7 @@ namespace ovdl::v2script::ast { struct FileTree : dryad::basic_node<NodeKind::FileTree, dryad::container_node<Node>> { explicit FileTree(dryad::node_ctor ctor, StatementList statements); explicit FileTree(dryad::node_ctor ctor, AssignStatementList statements); - explicit FileTree(dryad::node_ctor ctor) : FileTree(ctor, StatementList {}) { - } + explicit FileTree(dryad::node_ctor ctor); DRYAD_CHILD_NODE_RANGE_GETTER(Statement, statements, nullptr, this->node_after(_last_node)); diff --git a/include/openvic-dataloader/v2script/Parser.hpp b/include/openvic-dataloader/v2script/Parser.hpp index 1f6b158..2518e61 100644 --- a/include/openvic-dataloader/v2script/Parser.hpp +++ b/include/openvic-dataloader/v2script/Parser.hpp @@ -33,9 +33,9 @@ namespace ovdl::v2script { static Parser from_file(const char* path, std::optional<detail::Encoding> encoding_fallback = std::nullopt); static Parser from_file(const std::filesystem::path& path, std::optional<detail::Encoding> encoding_fallback = std::nullopt); - constexpr Parser& load_from_buffer(const char* data, std::size_t size, std::optional<detail::Encoding> encoding_fallback = std::nullopt); - constexpr Parser& load_from_buffer(const char* start, const char* end, std::optional<detail::Encoding> encoding_fallback = std::nullopt); - constexpr Parser& load_from_string(const std::string_view string, std::optional<detail::Encoding> encoding_fallback = std::nullopt); + Parser& load_from_buffer(const char* data, std::size_t size, std::optional<detail::Encoding> encoding_fallback = std::nullopt); + Parser& load_from_buffer(const char* start, const char* end, std::optional<detail::Encoding> encoding_fallback = std::nullopt); + Parser& load_from_string(const std::string_view string, std::optional<detail::Encoding> encoding_fallback = std::nullopt); Parser& load_from_file(const char* path, std::optional<detail::Encoding> encoding_fallback = std::nullopt); Parser& load_from_file(const std::filesystem::path& path, std::optional<detail::Encoding> encoding_fallback = std::nullopt); |