1
0
mirror of synced 2024-11-12 10:10:53 +01:00

tests: Improved pattern unit tests

This commit is contained in:
WerWolv 2021-10-20 11:06:24 +02:00
parent 9ccfadfb54
commit d6f9ec3f8f
4 changed files with 8 additions and 9 deletions

View File

@ -17,10 +17,10 @@ namespace hex::pl {
Lexer() = default;
std::optional<std::vector<Token>> lex(const std::string& code);
const LexerError& getError() { return this->m_error; }
const std::optional<LexerError>& getError() { return this->m_error; }
private:
LexerError m_error;
std::optional<LexerError> m_error;
[[noreturn]] void throwLexerError(const std::string &error, u32 lineNumber) const {
throw LexerError(lineNumber, "Lexer: " + error);

View File

@ -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<EvaluateError>& getLastHardError() { return this->m_lastHardError; };
private:
std::vector<std::pair<Level, std::string>> m_consoleLog;
EvaluateError m_lastHardError;
std::optional<EvaluateError> m_lastHardError;
};
}

View File

@ -22,10 +22,10 @@ namespace hex::pl {
~Parser() = default;
std::optional<std::vector<ASTNode*>> parse(const std::vector<Token> &tokens);
const ParseError& getError() { return this->m_error; }
const std::optional<ParseError>& getError() { return this->m_error; }
private:
ParseError m_error;
std::optional<ParseError> m_error;
TokenIter m_curr;
TokenIter m_originalPosition;

View File

@ -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;
}