35 lines
2.0 KiB
C++
35 lines
2.0 KiB
C++
#include "../../extern/doctest.hpp"
|
|
#include "../../src/Parser/Lexer/Lexer.hpp"
|
|
#include "../../src/Parser/Parser.hpp"
|
|
|
|
using namespace MalachScript;
|
|
|
|
#define PARSE_TEST(name, scriptText, asserts) \
|
|
TEST_CASE(name) { \
|
|
Diagnostics::Diagnostics diags; \
|
|
auto lexer = Parser::Lexer(u8##name, u8##scriptText, &diags); \
|
|
auto token = lexer.Lex(); \
|
|
auto parser = Parser::Parser(u8##name, token, &diags); \
|
|
auto script = parser.Parse(); \
|
|
asserts; \
|
|
delete script; \
|
|
}
|
|
|
|
PARSE_TEST("Parse class without definition", "class foobar;", {
|
|
REQUIRE(diags.GetMessages().empty());
|
|
REQUIRE(script->GetStatements().size() == 1);
|
|
REQUIRE(script->GetStatements()[0].get()->GetKind() == Parser::ParsedStatementKind::Class);
|
|
})
|
|
|
|
PARSE_TEST("Parse class with empty definition", "class foobar {}", {
|
|
REQUIRE(diags.GetMessages().empty());
|
|
REQUIRE(script->GetStatements().size() == 1);
|
|
REQUIRE(script->GetStatements()[0].get()->GetKind() == Parser::ParsedStatementKind::Class);
|
|
})
|
|
|
|
PARSE_TEST("Parse function without definition", "void foobar(int8 par1, bool &in x);", {
|
|
REQUIRE(diags.GetMessages().empty());
|
|
REQUIRE(script->GetStatements().size() == 1);
|
|
REQUIRE(script->GetStatements()[0].get()->GetKind() == Parser::ParsedStatementKind::Func);
|
|
})
|