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
2b86a40b
Commit
2b86a40b
authored
Sep 13, 2021
by
Stéphane Del Pino
Browse files
Options
Downloads
Patches
Plain Diff
Add missing tests for << and >> operators
parent
2703be82
No related branches found
No related tags found
1 merge request
!116
Add tests for EmbeddedIDiscreteFunctionUtils
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
tests/FixturesForBuiltinT.hpp
+12
-0
12 additions, 0 deletions
tests/FixturesForBuiltinT.hpp
tests/test_ASTNodeBinaryOperatorExpressionBuilder.cpp
+112
-0
112 additions, 0 deletions
tests/test_ASTNodeBinaryOperatorExpressionBuilder.cpp
with
124 additions
and
0 deletions
tests/FixturesForBuiltinT.hpp
+
12
−
0
View file @
2b86a40b
...
...
@@ -53,4 +53,16 @@ operator/(double, const std::shared_ptr<const double>&)
throw
std
::
runtime_error
(
"runtime error rhs"
);
}
inline
std
::
shared_ptr
<
const
double
>
operator
<<
(
const
std
::
shared_ptr
<
const
double
>&
p_a
,
const
std
::
shared_ptr
<
const
double
>&
p_b
)
{
return
std
::
make_shared
<
double
>
(
static_cast
<
int
>
(
*
p_a
)
<<
static_cast
<
int
>
(
*
p_b
));
}
inline
std
::
shared_ptr
<
const
double
>
operator
>>
(
const
std
::
shared_ptr
<
const
double
>&
p_a
,
const
std
::
shared_ptr
<
const
double
>&
p_b
)
{
return
std
::
make_shared
<
double
>
(
static_cast
<
int
>
(
*
p_a
)
>>
static_cast
<
int
>
(
*
p_b
));
}
#endif // FIXTURES_FOR_BUILTIN_T_HPP
This diff is collapsed.
Click to expand it.
tests/test_ASTNodeBinaryOperatorExpressionBuilder.cpp
+
112
−
0
View file @
2b86a40b
#include
<catch2/catch_test_macros.hpp>
#include
<catch2/matchers/catch_matchers_all.hpp>
#include
<FixturesForBuiltinT.hpp>
#include
<language/ast/ASTBuilder.hpp>
#include
<language/ast/ASTModulesImporter.hpp>
#include
<language/ast/ASTNodeBinaryOperatorExpressionBuilder.hpp>
...
...
@@ -10,6 +12,11 @@
#include
<language/ast/ASTNodeTypeCleaner.hpp>
#include
<language/ast/ASTSymbolTableBuilder.hpp>
#include
<language/utils/ASTPrinter.hpp>
#include
<language/utils/BasicAffectationRegistrerFor.hpp>
#include
<language/utils/BinaryOperatorProcessorBuilder.hpp>
#include
<language/utils/DataHandler.hpp>
#include
<language/utils/OperatorRepository.hpp>
#include
<language/utils/TypeDescriptor.hpp>
#include
<utils/Demangle.hpp>
#include
<pegtl/string_input.hpp>
...
...
@@ -1417,6 +1424,111 @@ x!=y;
}
}
SECTION
(
"shift"
)
{
#define CHECK_AST_BUILTIN_SHIFT_EXPRESSION(data, expected_output) \
{ \
TAO_PEGTL_NAMESPACE::string_input input{data, "test.pgs"}; \
auto ast = ASTBuilder::build(input); \
\
ASTModulesImporter{*ast}; \
\
BasicAffectationRegisterFor<EmbeddedData>{ASTNodeDataType::build<ASTNodeDataType::type_id_t>("builtin_t")}; \
\
OperatorRepository& repository = OperatorRepository::instance(); \
\
repository.addBinaryOperator<language::shift_left_op>( \
std::make_shared< \
BinaryOperatorProcessorBuilder<language::shift_left_op, std::shared_ptr<const double>, \
std::shared_ptr<const double>, std::shared_ptr<const double>>>()); \
\
repository.addBinaryOperator<language::shift_right_op>( \
std::make_shared< \
BinaryOperatorProcessorBuilder<language::shift_right_op, std::shared_ptr<const double>, \
std::shared_ptr<const double>, std::shared_ptr<const double>>>()); \
\
SymbolTable& symbol_table = *ast->m_symbol_table; \
auto [i_symbol, success] = symbol_table.add(builtin_data_type.nameOfTypeId(), ast->begin()); \
if (not success) { \
throw UnexpectedError("cannot add '" + builtin_data_type.nameOfTypeId() + "' type for testing"); \
} \
\
i_symbol->attributes().setDataType(ASTNodeDataType::build<ASTNodeDataType::type_name_id_t>()); \
i_symbol->attributes().setIsInitialized(); \
i_symbol->attributes().value() = symbol_table.typeEmbedderTable().size(); \
symbol_table.typeEmbedderTable().add(std::make_shared<TypeDescriptor>(builtin_data_type.nameOfTypeId())); \
\
auto [i_symbol_bt_a, success_bt_a] = symbol_table.add("bt_a", ast->begin()); \
if (not success_bt_a) { \
throw UnexpectedError("cannot add 'bt_a' of type builtin_t for testing"); \
} \
i_symbol_bt_a->attributes().setDataType(ast_node_data_type_from<std::shared_ptr<const double>>); \
i_symbol_bt_a->attributes().setIsInitialized(); \
i_symbol_bt_a->attributes().value() = \
EmbeddedData(std::make_shared<DataHandler<const double>>(std::make_shared<double>(3.2))); \
\
auto [i_symbol_bt_b, success_bt_b] = symbol_table.add("bt_b", ast->begin()); \
if (not success_bt_b) { \
throw UnexpectedError("cannot add 'bt_b' of type builtin_t for testing"); \
} \
i_symbol_bt_b->attributes().setDataType(ast_node_data_type_from<std::shared_ptr<const double>>); \
i_symbol_bt_b->attributes().setIsInitialized(); \
i_symbol_bt_b->attributes().value() = \
EmbeddedData(std::make_shared<DataHandler<const double>>(std::make_shared<double>(5.3))); \
\
ASTNodeTypeCleaner<language::import_instruction>{*ast}; \
\
ASTSymbolTableBuilder{*ast}; \
ASTNodeDataTypeBuilder{*ast}; \
\
ASTNodeDeclarationToAffectationConverter{*ast}; \
ASTNodeTypeCleaner<language::var_declaration>{*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); \
}
SECTION
(
"shift left (builtin)"
)
{
std
::
string_view
data
=
R"(
let m : builtin_t;
let n : builtin_t;
n << m;
)"
;
std
::
string_view
result
=
R"(
(root:ASTNodeListProcessor)
`-(language::shift_left_op:BinaryExpressionProcessor<language::shift_left_op, std::shared_ptr<double const>, std::shared_ptr<double const>, std::shared_ptr<double const> >)
+-(language::name:n:NameProcessor)
`-(language::name:m:NameProcessor)
)"
;
CHECK_AST_BUILTIN_SHIFT_EXPRESSION
(
data
,
result
);
}
SECTION
(
"shift right (builtin)"
)
{
std
::
string_view
data
=
R"(
let m : builtin_t;
let n : builtin_t;
n >> m;
)"
;
std
::
string_view
result
=
R"(
(root:ASTNodeListProcessor)
`-(language::shift_right_op:BinaryExpressionProcessor<language::shift_right_op, std::shared_ptr<double const>, std::shared_ptr<double const>, std::shared_ptr<double const> >)
+-(language::name:n:NameProcessor)
`-(language::name:m:NameProcessor)
)"
;
CHECK_AST_BUILTIN_SHIFT_EXPRESSION
(
data
,
result
);
}
}
SECTION
(
"Errors"
)
{
SECTION
(
"Invalid binary operator type"
)
...
...
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