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
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
code
pugs
Commits
e59df8f8
Commit
e59df8f8
authored
7 months ago
by
Stéphane Del Pino
Browse files
Options
Downloads
Patches
Plain Diff
Add tests for ASTExecutionStack
parent
0887dbcc
Branches
Branches containing commit
No related tags found
1 merge request
!199
Integrate checkpointing
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_ASTExecutionStack.cpp
+82
-0
82 additions, 0 deletions
tests/test_ASTExecutionStack.cpp
with
83 additions
and
0 deletions
tests/CMakeLists.txt
+
1
−
0
View file @
e59df8f8
...
...
@@ -19,6 +19,7 @@ add_executable (unit_tests
test_ArraySubscriptProcessor.cpp
test_ASTBuilder.cpp
test_ASTDotPrinter.cpp
test_ASTExecutionStack.cpp
test_ASTModulesImporter.cpp
test_ASTNode.cpp
test_ASTNodeAffectationExpressionBuilder.cpp
...
...
This diff is collapsed.
Click to expand it.
tests/test_ASTExecutionStack.cpp
0 → 100644
+
82
−
0
View file @
e59df8f8
#include
<catch2/catch_test_macros.hpp>
#include
<catch2/matchers/catch_matchers_all.hpp>
#include
<language/ast/ASTBuilder.hpp>
#include
<language/ast/ASTExecutionStack.hpp>
#include
<language/ast/ASTModulesImporter.hpp>
#include
<language/ast/ASTNodeDataTypeBuilder.hpp>
#include
<language/ast/ASTNodeDeclarationToAffectationConverter.hpp>
#include
<language/ast/ASTNodeExpressionBuilder.hpp>
#include
<language/ast/ASTNodeTypeCleaner.hpp>
#include
<language/ast/ASTSymbolTableBuilder.hpp>
#include
<pegtl/string_input.hpp>
#include
<sstream>
// clazy:excludeall=non-pod-global-static
TEST_CASE
(
"ASTExecutionStack"
,
"[language]"
)
{
REQUIRE_NOTHROW
(
ASTExecutionStack
::
create
());
REQUIRE_THROWS_WITH
(
ASTExecutionStack
::
create
(),
"unexpected error: ASTExecutionStack was already created!"
);
#ifndef NDEBUG
REQUIRE_THROWS_WITH
(
ASTExecutionStack
::
getInstance
().
sourceLocation
(),
"stack.size() > 0"
);
#endif // NDEBUG
REQUIRE_NOTHROW
(
ASTExecutionStack
::
destroy
());
std
::
string
data
=
R"(
import math;
for (let i:N, i=0; i<5; ++i) {
cout << 2 * i << "\n";
i += 1;
}
)"
;
auto
input
=
std
::
make_shared
<
TAO_PEGTL_NAMESPACE
::
string_input
<>>
(
data
,
"test.pgs"
);
ASTExecutionStack
::
create
(
input
,
data
);
REQUIRE_THROWS_WITH
(
ASTExecutionStack
::
create
(
input
,
data
),
"unexpected error: ASTExecutionStack was already created!"
);
auto
ast
=
ASTBuilder
::
build
(
*
input
);
ASTModulesImporter
{
*
ast
};
ASTNodeTypeCleaner
<
language
::
import_instruction
>
{
*
ast
};
ASTSymbolTableBuilder
{
*
ast
};
ASTNodeDataTypeBuilder
{
*
ast
};
ASTNodeDeclarationToAffectationConverter
{
*
ast
};
ASTNodeTypeCleaner
<
language
::
var_declaration
>
{
*
ast
};
ASTNodeExpressionBuilder
{
*
ast
};
REQUIRE
(
ASTExecutionStack
::
getInstance
().
errorMessageAt
(
"error_msg"
)
==
"error_msg"
);
ASTExecutionStack
::
getInstance
().
push
(
ast
->
children
[
0
].
get
());
ASTExecutionStack
::
getInstance
().
push
(
ast
->
children
[
0
]
->
children
[
3
]
->
children
[
1
].
get
());
REQUIRE
(
ASTExecutionStack
::
getInstance
().
errorMessageAt
(
"error_msg"
)
==
R"(test.pgs:6:5: error_msg
i += 1;
^
)"
);
auto
source_location
=
ASTExecutionStack
::
getInstance
().
sourceLocation
();
REQUIRE
(
source_location
.
filename
()
==
"test.pgs"
);
REQUIRE
(
source_location
.
line
()
==
6
);
REQUIRE
(
source_location
.
column
()
==
5
);
REQUIRE
(
source_location
.
function
()
==
""
);
ASTExecutionStack
::
getInstance
().
pop
();
ASTExecutionStack
::
getInstance
().
pop
();
ast
->
m_symbol_table
->
clearValues
();
REQUIRE_NOTHROW
(
ASTExecutionStack
::
destroy
());
REQUIRE_THROWS_WITH
(
ASTExecutionStack
::
destroy
(),
"unexpected error: ASTExecutionStack was not created!"
);
}
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