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:
@@ -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
|
||||
Reference in New Issue
Block a user