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
b29173e4
Commit
b29173e4
authored
Sep 3, 2019
by
Stéphane Del Pino
Browse files
Options
Downloads
Patches
Plain Diff
Add tests for IfProcessor
parent
c982485b
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/node_processor/IfProcessor.hpp
+2
-2
2 additions, 2 deletions
src/language/node_processor/IfProcessor.hpp
tests/CMakeLists.txt
+1
-0
1 addition, 0 deletions
tests/CMakeLists.txt
tests/test_IfProcessor.cpp
+103
-0
103 additions, 0 deletions
tests/test_IfProcessor.cpp
with
106 additions
and
2 deletions
src/language/node_processor/IfProcessor.hpp
+
2
−
2
View file @
b29173e4
...
@@ -13,13 +13,13 @@ class IfProcessor final : public INodeProcessor
...
@@ -13,13 +13,13 @@ class IfProcessor final : public INodeProcessor
execute
(
ExecUntilBreakOrContinue
&
exec_policy
)
execute
(
ExecUntilBreakOrContinue
&
exec_policy
)
{
{
m_node
.
children
[
0
]
->
execute
(
exec_policy
);
m_node
.
children
[
0
]
->
execute
(
exec_policy
);
const
bool
is_true
=
static_cast
<
bool
>
(
std
::
visit
(
const
bool
is_true
=
static_cast
<
bool
>
(
std
::
visit
(
// LCOV_EXCL_LINE (false negative)
[](
const
auto
&
value
)
->
bool
{
[](
const
auto
&
value
)
->
bool
{
using
T
=
std
::
decay_t
<
decltype
(
value
)
>
;
using
T
=
std
::
decay_t
<
decltype
(
value
)
>
;
if
constexpr
(
std
::
is_arithmetic_v
<
T
>
)
{
if
constexpr
(
std
::
is_arithmetic_v
<
T
>
)
{
return
value
;
return
value
;
}
else
{
}
else
{
return
false
;
return
false
;
// LCOV_EXCL_LINE (only there for compilation purpose unreachable)
}
}
},
},
m_node
.
children
[
0
]
->
m_value
));
m_node
.
children
[
0
]
->
m_value
));
...
...
This diff is collapsed.
Click to expand it.
tests/CMakeLists.txt
+
1
−
0
View file @
b29173e4
...
@@ -32,6 +32,7 @@ add_executable (unit_tests
...
@@ -32,6 +32,7 @@ add_executable (unit_tests
test_CRSMatrix.cpp
test_CRSMatrix.cpp
test_ExecUntilBreakOrContinue.cpp
test_ExecUntilBreakOrContinue.cpp
test_FakeProcessor.cpp
test_FakeProcessor.cpp
test_IfProcessor.cpp
test_IncDecExpressionProcessor.cpp
test_IncDecExpressionProcessor.cpp
test_INodeProcessor.cpp
test_INodeProcessor.cpp
test_ItemType.cpp
test_ItemType.cpp
...
...
This diff is collapsed.
Click to expand it.
tests/test_IfProcessor.cpp
0 → 100644
+
103
−
0
View file @
b29173e4
#include
<catch2/catch.hpp>
#include
<ASTNodeValueBuilder.hpp>
#include
<ASTBuilder.hpp>
#include
<ASTNodeDataTypeBuilder.hpp>
#include
<ASTNodeDeclarationCleaner.hpp>
#include
<ASTNodeDeclarationToAffectationConverter.hpp>
#include
<ASTNodeExpressionBuilder.hpp>
#include
<ASTNodeAffectationExpressionBuilder.hpp>
#include
<ASTSymbolTableBuilder.hpp>
#include
<ASTPrinter.hpp>
#include
<Demangle.hpp>
#include
<PEGGrammar.hpp>
#include
<sstream>
#define CHECK_IF_PROCESSOR_RESULT(data, variable_name, expected_value) \
{ \
string_input input{data, "test.pgs"}; \
auto ast = ASTBuilder::build(input); \
\
ASTSymbolTableBuilder{*ast}; \
ASTNodeDataTypeBuilder{*ast}; \
ASTNodeValueBuilder{*ast}; \
\
ASTNodeDeclarationToAffectationConverter{*ast}; \
ASTNodeDeclarationCleaner{*ast}; \
\
ASTNodeExpressionBuilder{*ast}; \
ExecUntilBreakOrContinue exec_policy; \
ast->execute(exec_policy); \
\
auto symbol_table = ast->m_symbol_table; \
\
using namespace TAO_PEGTL_NAMESPACE; \
position use_position{internal::iterator{"fixture"}, "fixture"}; \
use_position.byte = 10000; \
auto [symbol, found] = symbol_table->find(variable_name, use_position); \
\
auto attribute = symbol->second; \
auto value = std::get<decltype(expected_value)>(attribute.value()); \
\
REQUIRE(value == expected_value); \
}
TEST_CASE
(
"IfProcessor"
,
"[language]"
)
{
SECTION
(
"simple if(true)"
)
{
std
::
string_view
data
=
R"(
N i = 0;
if(true) {
i = 1;
}
)"
;
CHECK_IF_PROCESSOR_RESULT
(
data
,
"i"
,
1ul
);
}
SECTION
(
"simple if(false)"
)
{
std
::
string_view
data
=
R"(
N i = 0;
if(false) {
i = 1;
}
)"
;
CHECK_IF_PROCESSOR_RESULT
(
data
,
"i"
,
0ul
);
}
SECTION
(
"simple if(true)else"
)
{
std
::
string_view
data
=
R"(
N i = 0;
if(true) {
i = 1;
} else {
i = 2;
}
)"
;
CHECK_IF_PROCESSOR_RESULT
(
data
,
"i"
,
1ul
);
}
SECTION
(
"simple if(false)"
)
{
std
::
string_view
data
=
R"(
N i = 0;
if(false) {
i = 1;
} else {
i = 2;
}
)"
;
CHECK_IF_PROCESSOR_RESULT
(
data
,
"i"
,
2ul
);
}
}
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