2020-10-04 14:33:12 +00:00
|
|
|
#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
|
|
|
|
#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 14:33:12 +00:00
|
|
|
|
|
|
|
#define SYMBOL_TEST(script, symbol) \
|
|
|
|
TEST_CASE("Lex " script) { \
|
2021-01-01 22:31:30 +00:00
|
|
|
MalachScript::Diagnostics::Logger diag; \
|
2020-10-08 16:15:48 +00:00
|
|
|
auto lexer = Lexer(u8##script, u8##script, &diag); \
|
2020-10-04 14:33:12 +00:00
|
|
|
const auto* token = lexer.Lex(); \
|
2020-10-04 17:38:13 +00:00
|
|
|
CHECK(diag.GetMessages().empty()); \
|
2020-10-04 14:33:12 +00:00
|
|
|
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") {
|
2020-10-08 16:15:48 +00:00
|
|
|
auto whitespace = {u8" ", u8"\t", u8"\n", u8"\r", u8"\xef\xbb\xbf"};
|
2020-10-05 10:18:05 +00:00
|
|
|
for (const auto* v : whitespace) {
|
2021-01-01 22:31:30 +00:00
|
|
|
MalachScript::Diagnostics::Logger diag;
|
2020-10-08 16:15:48 +00:00
|
|
|
auto lexer = Lexer(u8"whitespace", v, &diag);
|
2020-10-04 14:33:12 +00:00
|
|
|
const auto* token = lexer.Lex();
|
2020-10-04 17:38:13 +00:00
|
|
|
CHECK(diag.GetMessages().empty());
|
2020-10-04 14:33:12 +00:00
|
|
|
CHECK(token->GetKind() == LexTokenKind::Whitespace);
|
|
|
|
CHECK(token->GetNext()->GetKind() == LexTokenKind::EndOfFile);
|
|
|
|
}
|
|
|
|
}
|