Add ast::node and handle<T*, Error> comparison

And parser test for literals fingerscrossed
This commit is good, innit? But there will also be second one, and dessert

Signed-off-by: CHatingPython <chatingpython@gmail.com>
This commit is contained in:
CHatingPython
2026-05-26 14:11:28 +02:00
committed by CHatingPython
parent 4a58e97812
commit 48593a4350
12 changed files with 148 additions and 17 deletions
+27
View File
@@ -30,4 +30,31 @@ TEST(Parser, EmptyFunctions) {
}
}
TEST(Parser, Literals) {
parser parser("<TEMP>", R"(
func test1() { return 67; }
func test2() { return "uwu"; }
)");
auto program = parser.parse();
EXPECT_TRUE(program.present());
EXPECT_EQ(program->declarations().size(), 2);
{
auto test1 = program->declarations()[0];
EXPECT_TRUE(test1.present());
EXPECT_EQ(test1->declaration_type(), declaration_node_t::FunctionDefinition);
node_handle<function_definition_node> funcDef = test1;
EXPECT_EQ(funcDef->name()->string, "test1");
EXPECT_EQ(funcDef->body()->statements.size(), 1);
node_handle<return_statement_node> ret = funcDef->body()->statements[0];
EXPECT_EQ(ret->value(), integer_literal_node({ furc::location{ "<TEMP>", 1, 26 }, 67 }));
}
{
auto test2 = program->declarations()[1];
EXPECT_TRUE(test2.present());
EXPECT_EQ(test2->declaration_type(), declaration_node_t::FunctionDefinition);
node_handle<function_definition_node> funcDecl = test2;
EXPECT_EQ(funcDecl->name()->string, "test2");
}
}
} // namespace