Skip to content

Commit 4718929

Browse files
committed
Add unit tests for inserting symbols with (non-)empty modules
1 parent 639d4ed commit 4718929

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

unit/util/symbol_table.cpp

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,58 @@ SCENARIO(
9292
}
9393
}
9494

95+
SCENARIO(
96+
"symbol_table_symbol_module_map",
97+
"[core][utils][symbol_table_symbol_module_map]")
98+
{
99+
GIVEN("A valid symbol table")
100+
{
101+
symbol_tablet symbol_table;
102+
WHEN("Inserting a symbol with non-empty module")
103+
{
104+
symbolt symbol;
105+
symbol.name = "TestName";
106+
symbol.module = "TestModule";
107+
symbol_table.insert(std::move(symbol));
108+
THEN("The symbol module map contains an entry for the symbol")
109+
{
110+
REQUIRE(symbol_table.symbol_module_map.size() == 1);
111+
const auto entry = symbol_table.symbol_module_map.begin();
112+
REQUIRE(id2string(entry->first) == "TestModule");
113+
REQUIRE(id2string(entry->second) == "TestName");
114+
}
115+
WHEN("Removing the symbol again")
116+
{
117+
symbol_table.remove("TestName");
118+
THEN("The symbol module map no longer contains an entry for the symbol")
119+
{
120+
REQUIRE(symbol_table.symbol_module_map.size() == 0);
121+
}
122+
}
123+
}
124+
WHEN("Inserting a symbol with empty module")
125+
{
126+
symbolt symbol;
127+
symbol.name = "TestName";
128+
symbol_table.insert(std::move(symbol));
129+
THEN("The symbol module map does not contain an entry for the symbol")
130+
{
131+
REQUIRE(symbol_table.symbol_module_map.size() == 0);
132+
}
133+
WHEN("Removing the symbol again")
134+
{
135+
symbol_table.remove("TestName");
136+
THEN(
137+
"The symbol module map still does not contain an entry for the "
138+
"symbol")
139+
{
140+
REQUIRE(symbol_table.symbol_module_map.size() == 0);
141+
}
142+
}
143+
}
144+
}
145+
}
146+
95147
SCENARIO("journalling_symbol_table_writer",
96148
"[core][utils][journalling_symbol_table_writer]")
97149
{

0 commit comments

Comments
 (0)