added tests for the stringification of the program

This commit is contained in:
Karma Riuk
2025-07-08 11:18:54 +02:00
parent 902f5a16df
commit 83df4955d4
7 changed files with 61 additions and 0 deletions

38
test/program.cpp Normal file
View File

@@ -0,0 +1,38 @@
#include "ast/program.hpp"
#include "ast/ast.hpp"
#include "ast/statements/let.hpp"
#include "ast/statements/return.hpp"
#include "token/type.hpp"
#include <doctest.h>
TEST_SUITE("Program") {
TEST_CASE("Let string") {
ast::program program({new ast::let_stmt(
token::token(token::type::LET, "let"),
new ast::identifier(
token::token(token::type::IDENTIFIER, "myVar"),
"myVar"
),
new ast::identifier(
token::token(token::type::IDENTIFIER, "anotherVar"),
"anotherVar"
)
)});
CHECK(program.str() == "let myVar = anotherVar;");
}
TEST_CASE("Return string") {
ast::program program({new ast::return_stmt(
token::token(token::type::RETURN, "return"),
new ast::identifier(
token::token(token::type::IDENTIFIER, "myVar"),
"myVar"
)
)});
CHECK(program.str() == "return myVar;");
}
}