From d6f9ec3f8fdd3fc25852ca1ab24889576f784226 Mon Sep 17 00:00:00 2001 From: WerWolv Date: Wed, 20 Oct 2021 11:06:24 +0200 Subject: [PATCH] tests: Improved pattern unit tests --- plugins/libimhex/include/hex/pattern_language/lexer.hpp | 4 ++-- .../libimhex/include/hex/pattern_language/log_console.hpp | 4 ++-- plugins/libimhex/include/hex/pattern_language/parser.hpp | 4 ++-- tests/pattern_language/source/main.cpp | 5 ++--- 4 files changed, 8 insertions(+), 9 deletions(-) diff --git a/plugins/libimhex/include/hex/pattern_language/lexer.hpp b/plugins/libimhex/include/hex/pattern_language/lexer.hpp index bc66d7844..3317c82d6 100644 --- a/plugins/libimhex/include/hex/pattern_language/lexer.hpp +++ b/plugins/libimhex/include/hex/pattern_language/lexer.hpp @@ -17,10 +17,10 @@ namespace hex::pl { Lexer() = default; std::optional> lex(const std::string& code); - const LexerError& getError() { return this->m_error; } + const std::optional& getError() { return this->m_error; } private: - LexerError m_error; + std::optional m_error; [[noreturn]] void throwLexerError(const std::string &error, u32 lineNumber) const { throw LexerError(lineNumber, "Lexer: " + error); diff --git a/plugins/libimhex/include/hex/pattern_language/log_console.hpp b/plugins/libimhex/include/hex/pattern_language/log_console.hpp index d86470177..fbc6da852 100644 --- a/plugins/libimhex/include/hex/pattern_language/log_console.hpp +++ b/plugins/libimhex/include/hex/pattern_language/log_console.hpp @@ -55,11 +55,11 @@ namespace hex::pl { void setHardError(const EvaluateError &error) { this->m_lastHardError = error; } [[nodiscard]] - const LogConsole::EvaluateError& getLastHardError() { return this->m_lastHardError; }; + const std::optional& getLastHardError() { return this->m_lastHardError; }; private: std::vector> m_consoleLog; - EvaluateError m_lastHardError; + std::optional m_lastHardError; }; } \ No newline at end of file diff --git a/plugins/libimhex/include/hex/pattern_language/parser.hpp b/plugins/libimhex/include/hex/pattern_language/parser.hpp index c40b63692..1f95f0b6c 100644 --- a/plugins/libimhex/include/hex/pattern_language/parser.hpp +++ b/plugins/libimhex/include/hex/pattern_language/parser.hpp @@ -22,10 +22,10 @@ namespace hex::pl { ~Parser() = default; std::optional> parse(const std::vector &tokens); - const ParseError& getError() { return this->m_error; } + const std::optional& getError() { return this->m_error; } private: - ParseError m_error; + std::optional m_error; TokenIter m_curr; TokenIter m_originalPosition; diff --git a/tests/pattern_language/source/main.cpp b/tests/pattern_language/source/main.cpp index e21dbf6c8..5cbee911f 100644 --- a/tests/pattern_language/source/main.cpp +++ b/tests/pattern_language/source/main.cpp @@ -64,9 +64,8 @@ int test(int argc, char **argv) { if (auto error = language.getError(); error.has_value()) hex::log::info("Compile error: {} : {}", error->first, error->second); - else - for (auto &[level, message] : language.getConsoleLog()) - hex::log::info("Evaluate error: {}", message); + for (auto &[level, message] : language.getConsoleLog()) + hex::log::info("Evaluate error: {}", message); return failing ? EXIT_SUCCESS : EXIT_FAILURE; }