2020-10-07 20:11:18 +00:00
|
|
|
#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; \
|
2020-10-09 10:55:49 +00:00
|
|
|
auto lexer = Parser::Lexer(u8##name, u8##scriptText, &diags); \
|
2020-10-07 20:11:18 +00:00
|
|
|
auto token = lexer.Lex(); \
|
2020-10-09 10:55:49 +00:00
|
|
|
auto parser = Parser::Parser(u8##name, token, &diags); \
|
2020-10-07 20:11:18 +00:00
|
|
|
auto script = parser.Parse(); \
|
|
|
|
asserts; \
|
2020-10-09 10:55:49 +00:00
|
|
|
delete script; \
|
2020-10-07 20:11:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
2020-10-10 16:35:31 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
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);
|
|
|
|
})
|