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
6675ff79
Commit
6675ff79
authored
5 years ago
by
Stéphane Del Pino
Browse files
Options
Downloads
Patches
Plain Diff
Begin CFunctionProcessor tests
parent
e2dc76af
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_CFunctionProcessor.cpp
+86
-0
86 additions, 0 deletions
tests/test_CFunctionProcessor.cpp
with
87 additions
and
0 deletions
tests/CMakeLists.txt
+
1
−
0
View file @
6675ff79
...
...
@@ -39,6 +39,7 @@ add_executable (unit_tests
test_BiCGStab.cpp
test_CFunctionEmbedder.cpp
test_CFunctionEmbedderTable.cpp
test_CFunctionProcessor.cpp
test_CMathModule.cpp
test_ContinueProcessor.cpp
test_ConcatExpressionProcessor.cpp
...
...
This diff is collapsed.
Click to expand it.
tests/test_CFunctionProcessor.cpp
0 → 100644
+
86
−
0
View file @
6675ff79
#include
<catch2/catch.hpp>
#include
<ASTNodeValueBuilder.hpp>
#include
<ASTBuilder.hpp>
#include
<ASTNodeDataTypeBuilder.hpp>
#include
<ASTNodeDeclarationToAffectationConverter.hpp>
#include
<ASTNodeTypeCleaner.hpp>
#include
<ASTModulesImporter.hpp>
#include
<ASTNodeExpressionBuilder.hpp>
#include
<ASTNodeAffectationExpressionBuilder.hpp>
#include
<ASTSymbolTableBuilder.hpp>
#include
<ASTPrinter.hpp>
#include
<Demangle.hpp>
#include
<PEGGrammar.hpp>
#include
<sstream>
#define CHECK_CFUNCTION_EVALUATION_RESULT(data, variable_name, expected_value) \
{ \
string_input input{data, "test.pgs"}; \
auto ast = ASTBuilder::build(input); \
\
ASTModulesImporter{*ast}; \
ASTNodeTypeCleaner<language::import_instruction>{*ast}; \
\
ASTSymbolTableBuilder{*ast}; \
ASTNodeDataTypeBuilder{*ast}; \
ASTNodeValueBuilder{*ast}; \
\
ASTNodeDeclarationToAffectationConverter{*ast}; \
ASTNodeTypeCleaner<language::declaration>{*ast}; \
ASTNodeTypeCleaner<language::let_declaration>{*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 attributes = symbol->attributes(); \
auto value = std::get<decltype(expected_value)>(attributes.value()); \
\
REQUIRE(value == expected_value); \
}
TEST_CASE
(
"CFunctionProcessor"
,
"[language]"
)
{
SECTION
(
"math module functions"
)
{
// @note HERE we do not use SECTION to be able to count tests and to check
// that all math functions are actually tested
std
::
set
<
std
::
string
>
tested_function_set
;
{
// sqrt
tested_function_set
.
insert
(
"sqrt"
);
std
::
string_view
data
=
R"(
import math;
R x = sqrt(4);
)"
;
CHECK_CFUNCTION_EVALUATION_RESULT
(
data
,
"x"
,
double
{
std
::
sqrt
(
4l
)});
}
{
// sin
tested_function_set
.
insert
(
"sin"
);
std
::
string_view
data
=
R"(
import math;
R x = sin(1.3);
)"
;
CHECK_CFUNCTION_EVALUATION_RESULT
(
data
,
"x"
,
double
{
std
::
sin
(
1.3
)});
}
}
}
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