2020-10-04 19:05:51 +00:00
|
|
|
#include "../../extern/doctest.hpp"
|
|
|
|
#include "../../src/Parser/Lexer/Lexer.hpp"
|
|
|
|
|
2020-10-05 15:45:00 +00:00
|
|
|
using namespace MalachScript::Parser;
|
2020-10-04 19:05:51 +00:00
|
|
|
|
|
|
|
#define LEX_TEST(script, ...) \
|
|
|
|
TEST_CASE("Lex: " script) { \
|
2021-01-01 22:31:30 +00:00
|
|
|
MalachScript::Diagnostics::Logger diag; \
|
2020-11-01 12:50:35 +00:00
|
|
|
auto lexer = Lexer(u8##script, u8##script, &diag); \
|
2020-10-04 19:05:51 +00:00
|
|
|
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);
|