Skip to content

Commit 4307ce3

Browse files
author
Thomas Kiley
committed
Add tests for iterators for symbol_tablet and symbol_table_baset
Check that both const and non-const iterators work as expected.
1 parent 736b397 commit 4307ce3

File tree

1 file changed

+45
-6
lines changed

1 file changed

+45
-6
lines changed

unit/util/symbol_table.cpp

Lines changed: 45 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,53 @@ TEST_CASE("Iterating through a symbol table", "[core][utils][symbol_tablet]")
1717

1818
symbol_table.insert(symbol);
1919

20-
int counter = 0;
21-
for(auto &entry : symbol_table)
20+
SECTION("Non const iterator")
2221
{
23-
(void)entry; // we are just testing iteration here
24-
++counter;
22+
int counter = 0;
23+
for(auto &entry : symbol_table)
24+
{
25+
(void)entry; // we are just testing iteration here
26+
++counter;
27+
}
28+
REQUIRE(counter == 1);
29+
}
30+
SECTION("Const iterator")
31+
{
32+
int counter = 0;
33+
for(const auto &entry : symbol_table)
34+
{
35+
(void)entry; // we are just testing iteration here
36+
++counter;
37+
}
38+
REQUIRE(counter == 1);
39+
}
40+
SECTION("Polymorphic access")
41+
{
42+
SECTION("Non-const iterator")
43+
{
44+
symbol_table_baset &base_st = symbol_table;
45+
REQUIRE(std::distance(base_st.begin(), base_st.end()) == 1);
46+
int counter = 0;
47+
for(auto &entry : base_st)
48+
{
49+
(void)entry; // we are just testing iteration here
50+
++counter;
51+
}
52+
REQUIRE(counter == 1);
53+
}
54+
SECTION("Const iterator")
55+
{
56+
const symbol_table_baset &base_st = symbol_table;
57+
REQUIRE(std::distance(base_st.begin(), base_st.end()) == 1);
58+
int counter = 0;
59+
for(const auto &entry : base_st)
60+
{
61+
(void)entry; // we are just testing iteration here
62+
++counter;
63+
}
64+
REQUIRE(counter == 1);
65+
}
2566
}
26-
27-
REQUIRE(counter == 1);
2867
}
2968

3069
SCENARIO(

0 commit comments

Comments
 (0)