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

Add tests for FunctionSymbolId and clean-up the class

parent a6f6b05f
No related branches found
No related tags found
1 merge request!37Feature/language
...@@ -16,14 +16,13 @@ class FunctionSymbolId ...@@ -16,14 +16,13 @@ class FunctionSymbolId
std::shared_ptr<SymbolTable> m_symbol_table = nullptr; std::shared_ptr<SymbolTable> m_symbol_table = nullptr;
public: public:
PUGS_INLINE uint64_t [[nodiscard]] PUGS_INLINE uint64_t
id() const noexcept id() const noexcept
{ {
return m_function_id; return m_function_id;
} }
PUGS_INLINE [[nodiscard]] PUGS_INLINE const SymbolTable&
const SymbolTable&
symbolTable() const symbolTable() const
{ {
Assert(m_symbol_table, "FunctionSymbolId is not initialized properly"); Assert(m_symbol_table, "FunctionSymbolId is not initialized properly");
...@@ -37,7 +36,14 @@ class FunctionSymbolId ...@@ -37,7 +36,14 @@ class FunctionSymbolId
return os; return os;
} }
FunctionSymbolId& operator=(const FunctionSymbolId&) = default;
FunctionSymbolId& operator=(FunctionSymbolId&&) = default;
FunctionSymbolId() = default; FunctionSymbolId() = default;
FunctionSymbolId(const FunctionSymbolId&) = default;
FunctionSymbolId(FunctionSymbolId&&) = default;
FunctionSymbolId(uint64_t function_id, const std::shared_ptr<SymbolTable>& symbol_table) FunctionSymbolId(uint64_t function_id, const std::shared_ptr<SymbolTable>& symbol_table)
: m_function_id(function_id), m_symbol_table(symbol_table) : m_function_id(function_id), m_symbol_table(symbol_table)
{} {}
......
...@@ -58,6 +58,7 @@ add_executable (unit_tests ...@@ -58,6 +58,7 @@ add_executable (unit_tests
test_FakeProcessor.cpp test_FakeProcessor.cpp
test_ForProcessor.cpp test_ForProcessor.cpp
test_FunctionProcessor.cpp test_FunctionProcessor.cpp
test_FunctionSymbolId.cpp
test_FunctionTable.cpp test_FunctionTable.cpp
test_IfProcessor.cpp test_IfProcessor.cpp
test_IncDecExpressionProcessor.cpp test_IncDecExpressionProcessor.cpp
......
#include <catch2/catch.hpp>
#include <language/utils/FunctionSymbolId.hpp>
#include <language/utils/SymbolTable.hpp>
#include <utils/PugsAssert.hpp>
#include <sstream>
// clazy:excludeall=non-pod-global-static
TEST_CASE("FunctionSymbolId", "[language]")
{
std::shared_ptr<SymbolTable> s = std::make_shared<SymbolTable>();
const FunctionSymbolId f{2, s};
REQUIRE(f.id() == 2);
REQUIRE(&f.symbolTable() == &(*s));
{
FunctionSymbolId g{f};
REQUIRE(g.id() == 2);
}
{
FunctionSymbolId h{4, s};
FunctionSymbolId g{std::move(h)};
REQUIRE(g.id() == 4);
}
{
FunctionSymbolId g;
g = f;
REQUIRE(g.id() == 2);
}
{
FunctionSymbolId g;
FunctionSymbolId h{4, s};
g = std::move(h);
REQUIRE(g.id() == 4);
}
{
std::ostringstream sout;
sout << f;
REQUIRE(sout.str() == "2");
}
#ifndef NDEBUG
{
std::shared_ptr<SymbolTable> unset_s;
REQUIRE_THROWS_AS((FunctionSymbolId{0, unset_s}.symbolTable()), AssertError);
}
#endif
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment