moved the utils for the parser to a global utils

folder for the tests (that utils is includable
only by the tests and not the src code, I added a
compiler flag only for the tests in the makefile,
but the compiler_flags.txt is global for the lsp,
gotta be careful with that)
This commit is contained in:
Karma Riuk
2025-07-19 13:27:25 +02:00
parent d1dd5f9dab
commit c943380d58
11 changed files with 419 additions and 338 deletions

View File

@@ -8,7 +8,7 @@
void test_let_statement(ast::statement* stmt, const std::string name) {
REQUIRE(stmt->token_literal() == "let");
ast::let_stmt* let_stmt = cast<ast::let_stmt>(stmt);
ast::let_stmt* let_stmt = test::utils::cast<ast::let_stmt>(stmt);
REQUIRE(let_stmt->name->value == name);
REQUIRE(let_stmt->name->token_literal() == name);
@@ -17,19 +17,28 @@ void test_let_statement(ast::statement* stmt, const std::string name) {
TEST_SUITE("Parser: let") {
TEST_CASE("Malformed let statement (checking for memory leaks)") {
SUBCASE("Second token not identifier") {
test_failing_parsing("let 5 = 5;", {token::type::IDENTIFIER});
test::utils::test_failing_parsing(
"let 5 = 5;",
{token::type::IDENTIFIER}
);
}
SUBCASE("Third token not '='") {
test_failing_parsing("let five ! 5;", {token::type::ASSIGN});
test::utils::test_failing_parsing(
"let five ! 5;",
{token::type::ASSIGN}
);
}
SUBCASE("Missing both identifier and '='") {
test_failing_parsing("let 5;", {token::type::IDENTIFIER});
test::utils::test_failing_parsing(
"let 5;",
{token::type::IDENTIFIER}
);
}
SUBCASE("Multiple parsing errors") {
test_failing_parsing(
test::utils::test_failing_parsing(
"let 5; let ! = 5; let five = 5; let five 5; let;",
{token::type::IDENTIFIER,
token::type::IDENTIFIER,
@@ -40,7 +49,10 @@ TEST_SUITE("Parser: let") {
}
}
TEST_CASE_FIXTURE(ParserFixture, "Parse well formed let statements") {
TEST_CASE_FIXTURE(
test::utils::ParserFixture,
"Parse well formed let statements"
) {
setup("\
let x = 5;\
let y = 10;\