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
cb440ba6
Commit
cb440ba6
authored
5 years ago
by
Stéphane Del Pino
Browse files
Options
Downloads
Patches
Plain Diff
Add tests for ASTNodeEmptyBlockCleaner
parent
da6f7ec9
No related branches found
No related tags found
1 merge request
!37
Feature/language
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
tests/CMakeLists.txt
+1
-0
1 addition, 0 deletions
tests/CMakeLists.txt
tests/test_ASTNodeEmptyBlockCleaner.cpp
+149
-0
149 additions, 0 deletions
tests/test_ASTNodeEmptyBlockCleaner.cpp
with
150 additions
and
0 deletions
tests/CMakeLists.txt
+
1
−
0
View file @
cb440ba6
...
@@ -17,6 +17,7 @@ add_executable (unit_tests
...
@@ -17,6 +17,7 @@ add_executable (unit_tests
test_ASTNodeDataTypeBuilder.cpp
test_ASTNodeDataTypeBuilder.cpp
test_ASTNodeDataTypeChecker.cpp
test_ASTNodeDataTypeChecker.cpp
test_ASTNodeDeclarationToAffectationConverter.cpp
test_ASTNodeDeclarationToAffectationConverter.cpp
test_ASTNodeEmptyBlockCleaner.cpp
test_ASTNodeExpressionBuilder.cpp
test_ASTNodeExpressionBuilder.cpp
test_ASTNodeFunctionEvaluationExpressionBuilder.cpp
test_ASTNodeFunctionEvaluationExpressionBuilder.cpp
test_ASTNodeIncDecExpressionBuilder.cpp
test_ASTNodeIncDecExpressionBuilder.cpp
...
...
This diff is collapsed.
Click to expand it.
tests/test_ASTNodeEmptyBlockCleaner.cpp
0 → 100644
+
149
−
0
View file @
cb440ba6
#include
<catch2/catch.hpp>
#include
<ASTNodeValueBuilder.hpp>
#include
<ASTBuilder.hpp>
#include
<ASTNodeDataTypeBuilder.hpp>
#include
<ASTNodeDeclarationToAffectationConverter.hpp>
#include
<ASTNodeTypeCleaner.hpp>
#include
<ASTNodeEmptyBlockCleaner.hpp>
#include
<ASTNodeExpressionBuilder.hpp>
#include
<ASTSymbolTableBuilder.hpp>
#include
<ASTPrinter.hpp>
#include
<PEGGrammar.hpp>
#include
<Demangle.hpp>
#define CHECK_AST(data, expected_output) \
{ \
static_assert(std::is_same_v<std::decay_t<decltype(data)>, std::string_view>); \
static_assert((std::is_same_v<std::decay_t<decltype(expected_output)>, std::string_view>) or \
(std::is_same_v<std::decay_t<decltype(expected_output)>, std::string>)); \
\
string_input input{data, "test.pgs"}; \
auto ast = ASTBuilder::build(input); \
\
ASTSymbolTableBuilder{*ast}; \
ASTNodeDataTypeBuilder{*ast}; \
ASTNodeValueBuilder{*ast}; \
\
ASTNodeDeclarationToAffectationConverter{*ast}; \
ASTNodeTypeCleaner<language::declaration>{*ast}; \
\
ASTNodeEmptyBlockCleaner{*ast}; \
\
ASTNodeExpressionBuilder{*ast}; \
std::stringstream ast_output; \
ast_output << '\n' << ASTPrinter{*ast, ASTPrinter::Format::raw, {ASTPrinter::Info::exec_type}}; \
\
REQUIRE(ast_output.str() == expected_output); \
}
TEST_CASE
(
"ASTNodeEmptyBlockCleaner"
,
"[language]"
)
{
SECTION
(
"empty file"
)
{
std
::
string_view
data
=
R"(
)"
;
std
::
string_view
result
=
R"(
(root:ASTNodeListProcessor)
)"
;
CHECK_AST
(
data
,
result
);
}
SECTION
(
"keep non-empty block"
)
{
std
::
string_view
data
=
R"(
{
R x = 3;
}
)"
;
std
::
string_view
result
=
R"(
(root:ASTNodeListProcessor)
`-(language::block:ASTNodeListProcessor)
`-(language::eq_op:AffectationProcessor<language::eq_op, double, long>)
+-(language::name:x:NameProcessor)
`-(language::integer:3:FakeProcessor)
)"
;
CHECK_AST
(
data
,
result
);
}
SECTION
(
"remove empty block"
)
{
std
::
string_view
data
=
R"(
{
R x;
}
)"
;
std
::
string_view
result
=
R"(
(root:ASTNodeListProcessor)
)"
;
CHECK_AST
(
data
,
result
);
}
SECTION
(
"remove nested empty blocks"
)
{
std
::
string_view
data
=
R"(
{
R x;
{
R y;
}
{
R z;
{
R w;
}
}
}
)"
;
std
::
string_view
result
=
R"(
(root:ASTNodeListProcessor)
)"
;
CHECK_AST
(
data
,
result
);
}
SECTION
(
"remove nested empty blocks"
)
{
std
::
string_view
data
=
R"(
{
R x;
{
R y;
}
{
R z;
{
R w = 4;
}
}
}
)"
;
std
::
string_view
result
=
R"(
(root:ASTNodeListProcessor)
`-(language::block:ASTNodeListProcessor)
`-(language::block:ASTNodeListProcessor)
`-(language::block:ASTNodeListProcessor)
`-(language::eq_op:AffectationProcessor<language::eq_op, double, long>)
+-(language::name:w:NameProcessor)
`-(language::integer:4:FakeProcessor)
)"
;
CHECK_AST
(
data
,
result
);
}
}
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