83 lines
3.6 KiB
C++
83 lines
3.6 KiB
C++
#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
|
|
#include "../../extern/doctest.hpp"
|
|
#include "../../src/Parser/Lexer/Lexer.hpp"
|
|
|
|
using namespace MalachScript::Parser;
|
|
|
|
#define SYMBOL_TEST(script, symbol) \
|
|
TEST_CASE("Lex " script) { \
|
|
MalachScript::Diagnostics::Logger diag; \
|
|
auto lexer = Lexer(u8##script, u8##script, &diag); \
|
|
const auto* token = lexer.Lex(); \
|
|
CHECK(diag.GetMessages().empty()); \
|
|
CHECK(token->GetKind() == LexTokenKind::symbol); \
|
|
CHECK(token->GetNext()->GetKind() == LexTokenKind::EndOfFile); \
|
|
}
|
|
|
|
SYMBOL_TEST("*", StarSymbol)
|
|
SYMBOL_TEST("**", StarStarSymbol)
|
|
SYMBOL_TEST("*=", StarEqualsSymbol)
|
|
SYMBOL_TEST("**=", StarStarEqualsSymbol)
|
|
SYMBOL_TEST("/", SlashSymbol)
|
|
SYMBOL_TEST("/=", SlashEqualsSymbol)
|
|
SYMBOL_TEST("%", PercentSymbol)
|
|
SYMBOL_TEST("%=", PercentEqualsSymbol)
|
|
SYMBOL_TEST("+", PlusSymbol)
|
|
SYMBOL_TEST("+=", PlusEqualsSymbol)
|
|
SYMBOL_TEST("++", PlusPlusSymbol)
|
|
SYMBOL_TEST("-", MinusSymbol)
|
|
SYMBOL_TEST("-=", MinusEqualsSymbol)
|
|
SYMBOL_TEST("--", MinusMinusSymbol)
|
|
SYMBOL_TEST("<", LessThanSymbol)
|
|
SYMBOL_TEST("<=", LessThanEqualsSymbol)
|
|
SYMBOL_TEST("<<", LessThanLessThanSymbol)
|
|
SYMBOL_TEST("<<=", LessThanLessThanEqualsSymbol)
|
|
SYMBOL_TEST(">", GreaterThanSymbol)
|
|
SYMBOL_TEST(">=", GreaterThanEqualsSymbol)
|
|
SYMBOL_TEST(">>", GreaterThanGreaterThanSymbol)
|
|
SYMBOL_TEST(">>=", GreaterThanGreaterThanEqualsSymbol)
|
|
SYMBOL_TEST(">>>", GreaterThanGreaterThanGreaterThanSymbol)
|
|
SYMBOL_TEST(">>>=", GreaterThanGreaterThanGreaterThanEqualsSymbol)
|
|
SYMBOL_TEST("(", OpenParenthesisSymbol)
|
|
SYMBOL_TEST(")", CloseParenthesisSymbol)
|
|
SYMBOL_TEST("=", EqualsSymbol)
|
|
SYMBOL_TEST("==", EqualsEqualsSymbol)
|
|
SYMBOL_TEST("!", ExclamationMarkSymbol)
|
|
SYMBOL_TEST("!=", ExclamationMarkEqualsSymbol)
|
|
SYMBOL_TEST("!is", ExclamationMarkIsSymbol)
|
|
SYMBOL_TEST("?", QuestionMarkSymbol)
|
|
SYMBOL_TEST(":", ColonSymbol)
|
|
SYMBOL_TEST("::", ColonColonSymbol)
|
|
SYMBOL_TEST("&", AmpersandSymbol)
|
|
SYMBOL_TEST("&=", AmpersandEqualsSymbol)
|
|
SYMBOL_TEST("&&", AmpersandAmpersandSymbol)
|
|
SYMBOL_TEST(",", CommaSymbol)
|
|
SYMBOL_TEST("{", OpenCurlyParenthesisSymbol)
|
|
SYMBOL_TEST("}", CloseCurlyParenthesisSymbol)
|
|
SYMBOL_TEST(";", SemicolonSymbol)
|
|
SYMBOL_TEST("|", VerticalLineSymbol)
|
|
SYMBOL_TEST("|=", VerticalLineEqualsSymbol)
|
|
SYMBOL_TEST("||", VerticalLineVerticalLineSymbol)
|
|
SYMBOL_TEST("^", CaretSymbol)
|
|
SYMBOL_TEST("^=", CaretEqualsSymbol)
|
|
SYMBOL_TEST("^^", CaretCaretSymbol)
|
|
SYMBOL_TEST("~", TildeSymbol)
|
|
SYMBOL_TEST(".", DotSymbol)
|
|
SYMBOL_TEST("[", OpenBlockParenthesisSymbol)
|
|
SYMBOL_TEST("]", CloseBlockParenthesisSymbol)
|
|
SYMBOL_TEST("@", AtSymbol)
|
|
SYMBOL_TEST(" ", Whitespace)
|
|
|
|
#undef SYMBOL_TEST
|
|
|
|
TEST_CASE("Lex whitespace") {
|
|
auto whitespace = {u8" ", u8"\t", u8"\n", u8"\r", u8"\xef\xbb\xbf"};
|
|
for (const auto* v : whitespace) {
|
|
MalachScript::Diagnostics::Logger diag;
|
|
auto lexer = Lexer(u8"whitespace", v, &diag);
|
|
const auto* token = lexer.Lex();
|
|
CHECK(diag.GetMessages().empty());
|
|
CHECK(token->GetKind() == LexTokenKind::Whitespace);
|
|
CHECK(token->GetNext()->GetKind() == LexTokenKind::EndOfFile);
|
|
}
|
|
} |