Skip to content
Snippets Groups Projects
Commit 0b40832d authored by Stéphane Del Pino's avatar Stéphane Del Pino
Browse files

Add missing test for ASTNodeDataTypeFlattener

parent 9abc092f
No related branches found
No related tags found
1 merge request!89Add missing compatibility check when affecting lists to R^d or R^dxd
...@@ -8,6 +8,8 @@ ...@@ -8,6 +8,8 @@
#include <language/ast/ASTNodeTypeCleaner.hpp> #include <language/ast/ASTNodeTypeCleaner.hpp>
#include <language/ast/ASTSymbolTableBuilder.hpp> #include <language/ast/ASTSymbolTableBuilder.hpp>
#include <test_BuiltinFunctionRegister.hpp>
#include <pegtl/string_input.hpp> #include <pegtl/string_input.hpp>
// clazy:excludeall=non-pod-global-static // clazy:excludeall=non-pod-global-static
...@@ -155,5 +157,36 @@ f(2); ...@@ -155,5 +157,36 @@ f(2);
REQUIRE(flattened_datatype_list[1].m_data_type == ASTNodeDataType::vector_t); REQUIRE(flattened_datatype_list[1].m_data_type == ASTNodeDataType::vector_t);
REQUIRE(flattened_datatype_list[1].m_data_type.dimension() == 3); REQUIRE(flattened_datatype_list[1].m_data_type.dimension() == 3);
} }
SECTION("builtin_function -> R*R")
{
std::string_view data = R"(
sum_vector(2,3);
)";
TAO_PEGTL_NAMESPACE::string_input input{data, "test.pgs"};
auto root_node = ASTBuilder::build(input);
test_only::test_BuiltinFunctionRegister{*root_node};
ASTSymbolTableBuilder{*root_node};
ASTNodeDataTypeBuilder{*root_node};
// optimizations
ASTNodeDeclarationToAffectationConverter{*root_node};
ASTNodeTypeCleaner<language::var_declaration>{*root_node};
ASTNodeTypeCleaner<language::fct_declaration>{*root_node};
REQUIRE(root_node->children[0]->is_type<language::function_evaluation>());
ASTNodeDataTypeFlattener::FlattenedDataTypeList flattened_datatype_list;
ASTNodeDataTypeFlattener{*root_node->children[0], flattened_datatype_list};
REQUIRE(flattened_datatype_list.size() == 2);
REQUIRE(flattened_datatype_list[0].m_data_type == ASTNodeDataType::double_t);
REQUIRE(flattened_datatype_list[1].m_data_type == ASTNodeDataType::vector_t);
REQUIRE(flattened_datatype_list[1].m_data_type.dimension() == 2);
}
} }
} }
...@@ -159,6 +159,14 @@ class test_BuiltinFunctionRegister ...@@ -159,6 +159,14 @@ class test_BuiltinFunctionRegister
std::make_pair("tuple_R33ToR:(R^3x3...)", std::make_pair("tuple_R33ToR:(R^3x3...)",
std::make_shared<BuiltinFunctionEmbedder<double(const std::vector<TinyMatrix<3>>)>>( std::make_shared<BuiltinFunctionEmbedder<double(const std::vector<TinyMatrix<3>>)>>(
[](const std::vector<TinyMatrix<3>>&) -> double { return 0; }))); [](const std::vector<TinyMatrix<3>>&) -> double { return 0; })));
m_name_builtin_function_map.insert(
std::make_pair("sum_vector:R*R^2",
std::make_shared<
BuiltinFunctionEmbedder<std::tuple<double, TinyVector<2>>(const double, const double)>>(
[](const double& x, const double& y) -> std::tuple<double, TinyVector<2>> {
return std::make_tuple(x + y, TinyVector<2>{x, y});
})));
} }
void void
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment