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

Check that symbol table is populate correctly

This commit adds tests for
- compound declarations `(x,y,z)` which declares `x`, `y` and `z`
- locality of arguments of functions
parent 11cc2f09
No related branches found
No related tags found
1 merge request!37Feature/language
...@@ -21,6 +21,44 @@ N n = 2; ...@@ -21,6 +21,44 @@ N n = 2;
ASTSymbolTableBuilder{*ast}; ASTSymbolTableBuilder{*ast};
} }
SECTION("Populate symbol table")
{
std::string_view data = R"(
B b;
N n;
Z z;
R x;
R*Z*N*B (c0,c1,c2,c3);
let f: R*Z*B->R, (x,n,z) -> x+n;
)";
string_input input{data, "test.pgs"};
auto ast = ASTBuilder::build(input);
ASTSymbolTableBuilder{*ast};
auto root_st = ast->m_symbol_table;
std::stringstream st_output;
st_output << '\n' << *root_st;
std::stringstream expected_output;
expected_output << '\n'
<< "-- Symbol table state -- parent : " << static_cast<SymbolTable*>(nullptr) << '\n'
<< " b: --\n"
<< " n: --\n"
<< " z: --\n"
<< " x: --\n"
<< " c0: --\n"
<< " c1: --\n"
<< " c2: --\n"
<< " c3: --\n"
<< " f: 0\n"
<< "------------------------\n";
REQUIRE(st_output.str() == expected_output.str());
}
SECTION("errors") SECTION("errors")
{ {
SECTION("Undeclared symbol") SECTION("Undeclared symbol")
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment