Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
pugs
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
code
pugs
Commits
af0a21f7
Commit
af0a21f7
authored
5 years ago
by
Stéphane Del Pino
Browse files
Options
Downloads
Patches
Plain Diff
Add tests for FunctionSymbolId and clean-up the class
parent
a6f6b05f
No related branches found
No related tags found
1 merge request
!37
Feature/language
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/language/utils/FunctionSymbolId.hpp
+9
-3
9 additions, 3 deletions
src/language/utils/FunctionSymbolId.hpp
tests/CMakeLists.txt
+1
-0
1 addition, 0 deletions
tests/CMakeLists.txt
tests/test_FunctionSymbolId.cpp
+56
-0
56 additions, 0 deletions
tests/test_FunctionSymbolId.cpp
with
66 additions
and
3 deletions
src/language/utils/FunctionSymbolId.hpp
+
9
−
3
View file @
af0a21f7
...
@@ -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
)
{}
{}
...
...
This diff is collapsed.
Click to expand it.
tests/CMakeLists.txt
+
1
−
0
View file @
af0a21f7
...
@@ -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
...
...
This diff is collapsed.
Click to expand it.
tests/test_FunctionSymbolId.cpp
0 → 100644
+
56
−
0
View file @
af0a21f7
#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
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment