MalachScript/tests/LexerTests/LexerIntegrationTests.cpp

26 lines
2.2 KiB
C++

#include "../../extern/doctest.hpp"
#include "../../src/Parser/Lexer/Lexer.hpp"
using namespace MalachScript::Parser;
#define LEX_TEST(script, ...) \
TEST_CASE("Lex: " script) { \
MalachScript::Diagnostics::Diagnostics diag; \
auto lexer = Lexer(u8##script, u8##script, &diag); \
const auto* token = lexer.Lex(); \
CHECK(diag.GetMessages().empty()); \
std::vector<LexTokenKind> 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);