#include "../../extern/doctest.hpp" #include "../../src/Parser/Lexer/Lexer.hpp" using namespace MalachScript::Parser; #define LEX_TEST(script, ...) \ TEST_CASE("Lex: " script) { \ MalachScript::Diagnostics::Logger diag; \ auto lexer = Lexer(script, script, &diag); \ const auto* token = lexer.Lex(); \ CHECK(diag.GetMessages().empty()); \ std::vector vec = {__VA_ARGS__, LexTokenKind::EndOfFile}; \ const auto* current = token; \ auto pos = 0; \ while (current != nullptr) { \ CHECK_MESSAGE(current->GetKind() == vec[pos], "position: " << pos); \ pos++; \ current = current->GetNext().get(); \ } \ } LEX_TEST("1 + 1", LexTokenKind::IntegerLiteral, LexTokenKind::Whitespace, LexTokenKind::PlusSymbol, LexTokenKind::Whitespace, LexTokenKind::IntegerLiteral); LEX_TEST("private foo = \"foobar\"", LexTokenKind::PrivateKeyword, LexTokenKind::Whitespace, LexTokenKind::Identifier, LexTokenKind::Whitespace, LexTokenKind::EqualsSymbol, LexTokenKind::Whitespace, LexTokenKind::StringLiteral);