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
0c4d733c
Commit
0c4d733c
authored
4 years ago
by
Stéphane Del Pino
Browse files
Options
Downloads
Patches
Plain Diff
Add missing tests for AffectationToTupleProcessor
parent
ac7178ab
Branches
Branches containing commit
Tags
Tags containing commit
1 merge request
!54
Feature/language coverage
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_AffectationToTupleProcessor.cpp
+165
-0
165 additions, 0 deletions
tests/test_AffectationToTupleProcessor.cpp
with
166 additions
and
0 deletions
tests/CMakeLists.txt
+
1
−
0
View file @
0c4d733c
...
...
@@ -8,6 +8,7 @@ add_executable (unit_tests
test_main.cpp
test_AffectationProcessor.cpp
test_AffectationToStringProcessor.cpp
test_AffectationToTupleProcessor.cpp
test_Array.cpp
test_ArraySubscriptProcessor.cpp
test_ArrayUtils.cpp
...
...
This diff is collapsed.
Click to expand it.
tests/test_AffectationToTupleProcessor.cpp
0 → 100644
+
165
−
0
View file @
0c4d733c
#include
<catch2/catch.hpp>
#include
<language/ast/ASTBuilder.hpp>
#include
<language/ast/ASTNodeAffectationExpressionBuilder.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
<language/utils/ASTPrinter.hpp>
#include
<utils/Demangle.hpp>
#include
<pegtl/string_input.hpp>
#include
<sstream>
#define CHECK_AFFECTATION_RESULT(data, variable_name, expected_value) \
{ \
string_input input{data, "test.pgs"}; \
auto ast = ASTBuilder::build(input); \
\
ASTSymbolTableBuilder{*ast}; \
ASTNodeDataTypeBuilder{*ast}; \
\
ASTNodeDeclarationToAffectationConverter{*ast}; \
ASTNodeTypeCleaner<language::var_declaration>{*ast}; \
\
ASTNodeExpressionBuilder{*ast}; \
ExecutionPolicy 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); \
}
// clazy:excludeall=non-pod-global-static
TEST_CASE
(
"ASTAffectationToTupleProcessor"
,
"[language]"
)
{
SECTION
(
"Affectations from value"
)
{
CHECK_AFFECTATION_RESULT
(
R"(
let s :(R); s = 2.;
)"
,
"s"
,
(
std
::
vector
<
double
>
{
2.
}));
CHECK_AFFECTATION_RESULT
(
R"(
let s :(R); s = 2;
)"
,
"s"
,
(
std
::
vector
<
double
>
{
2
}));
CHECK_AFFECTATION_RESULT
(
R"(
let s :(string); s = 2.;
)"
,
"s"
,
(
std
::
vector
<
std
::
string
>
{
std
::
to_string
(
2.
)}));
const
std
::
string
x_string
=
[]()
->
std
::
string
{
std
::
ostringstream
os
;
os
<<
TinyVector
<
3
,
double
>
{
1
,
2
,
3
}
<<
std
::
ends
;
return
os
.
str
();
}();
CHECK_AFFECTATION_RESULT
(
R"(
let x :R^3, x = (1,2,3);
let s :(string); s = x;
)"
,
"s"
,
(
std
::
vector
<
std
::
string
>
{
x_string
}));
CHECK_AFFECTATION_RESULT
(
R"(
let s :(R^1); s = 1.3;
)"
,
"s"
,
(
std
::
vector
<
TinyVector
<
1
>>
{
TinyVector
<
1
>
{
1.3
}}));
}
SECTION
(
"Affectations from list"
)
{
CHECK_AFFECTATION_RESULT
(
R"(
let t :(R); t = (2.,3);
)"
,
"t"
,
(
std
::
vector
<
double
>
{
2.
,
3
}));
CHECK_AFFECTATION_RESULT
(
R"(
let s :(string); s = (2.,3);
)"
,
"s"
,
(
std
::
vector
<
std
::
string
>
{
std
::
to_string
(
2.
),
std
::
to_string
(
3
)}));
CHECK_AFFECTATION_RESULT
(
R"(
let s :(string); s = (2.,3,"foo");
)"
,
"s"
,
(
std
::
vector
<
std
::
string
>
{
std
::
to_string
(
2.
),
std
::
to_string
(
3
),
std
::
string
{
"foo"
}}));
const
std
::
string
x_string
=
[]()
->
std
::
string
{
std
::
ostringstream
os
;
os
<<
TinyVector
<
2
,
double
>
{
1
,
2
}
<<
std
::
ends
;
return
os
.
str
();
}();
CHECK_AFFECTATION_RESULT
(
R"(
let x : R^2, x = (1,2);
let s : (string); s = (2.,3, x);
)"
,
"s"
,
(
std
::
vector
<
std
::
string
>
{
std
::
to_string
(
2.
),
std
::
to_string
(
3
),
x_string
}));
CHECK_AFFECTATION_RESULT
(
R"(
let x : R^2, x = (1,2);
let t :(R^2); t = (x,0);
)"
,
"t"
,
(
std
::
vector
<
TinyVector
<
2
>>
{
TinyVector
<
2
>
{
1
,
2
},
TinyVector
<
2
>
{
0
,
0
}}));
CHECK_AFFECTATION_RESULT
(
R"(
let t :(R^2); t = ((1,2),0);
)"
,
"t"
,
(
std
::
vector
<
TinyVector
<
2
>>
{
TinyVector
<
2
>
{
1
,
2
},
TinyVector
<
2
>
{
0
,
0
}}));
CHECK_AFFECTATION_RESULT
(
R"(
let x : R^1, x = 1;
let t :(R^1); t = (x,2);
)"
,
"t"
,
(
std
::
vector
<
TinyVector
<
1
>>
{
TinyVector
<
1
>
{
1
},
TinyVector
<
1
>
{
2
}}));
}
SECTION
(
"Affectations from tuple"
)
{
const
std
::
string
x_string
=
[]()
->
std
::
string
{
std
::
ostringstream
os
;
os
<<
TinyVector
<
3
,
double
>
{
1
,
2
,
3
}
<<
std
::
ends
;
return
os
.
str
();
}();
CHECK_AFFECTATION_RESULT
(
R"(
let x :(R^3), x = ((1,2,3));
let s :(string); s = x;
)"
,
"s"
,
(
std
::
vector
<
std
::
string
>
{
x_string
}));
CHECK_AFFECTATION_RESULT
(
R"(
let x :(R), x = (1,2,3);
let s :(string); s = x;
)"
,
"s"
,
(
std
::
vector
<
std
::
string
>
{
std
::
to_string
(
1.
),
std
::
to_string
(
2.
),
std
::
to_string
(
3.
)}));
CHECK_AFFECTATION_RESULT
(
R"(
let n :(N), n = (1,2,3);
let t :(R); t = n;
)"
,
"t"
,
(
std
::
vector
<
double
>
{
1
,
2
,
3
}));
CHECK_AFFECTATION_RESULT
(
R"(
let s :(N), s = (1,2,3);
let t :(N); t = s;
)"
,
"t"
,
(
std
::
vector
<
uint64_t
>
{
1
,
2
,
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