Skip to content
Snippets Groups Projects
Commit 11a52edf authored by Stéphane Del Pino's avatar Stéphane Del Pino
Browse files

Add initialization checker tests for functions

parent cb440ba6
No related branches found
No related tags found
1 merge request!37Feature/language
......@@ -69,6 +69,28 @@ m = n;
REQUIRE(not symbol_z->attributes().isInitialized());
}
SECTION("Declarative initialization")
{
std::string_view data = R"(
let f: R->R, x->x+1;
)";
string_input input{data, "test.pgs"};
auto ast = ASTBuilder::build(input);
ASTSymbolTableBuilder{*ast};
ASTSymbolInitializationChecker{*ast};
position position{internal::iterator{"fixture"}, "fixture"};
position.byte = data.size(); // ensure that variables are declared at this point
auto [symbol_m, found_m] = ast->m_symbol_table->find("f", position);
REQUIRE(found_m);
REQUIRE(symbol_m->attributes().isInitialized());
}
SECTION("errors")
{
SECTION("used uninitialized")
{
std::string_view data = R"(
......@@ -82,4 +104,19 @@ N m = n;
ASTSymbolTableBuilder{*ast};
REQUIRE_THROWS_AS(ASTSymbolInitializationChecker{*ast}, parse_error);
}
SECTION("used uninitialized in function")
{
std::string_view data = R"(
R y;
let f : R->R, x->x+y;
)";
string_input input{data, "test.pgs"};
auto ast = ASTBuilder::build(input);
ASTSymbolTableBuilder{*ast};
REQUIRE_THROWS_AS(ASTSymbolInitializationChecker{*ast}, parse_error);
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment