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

Add missing tests for ASTNodeFunctionExpressionBuilder

parent 37a273b3
No related branches found
No related tags found
1 merge request!104Add missing tests for ASTNodeBuiltinFunctionExpressionBuilder
This commit is part of merge request !104. Comments created here will be created in the context of that merge request.
......@@ -523,9 +523,11 @@ ASTNodeFunctionExpressionBuilder::ASTNodeFunctionExpressionBuilder(ASTNode& node
case ASTNodeDataType::type_id_t: {
return ASTNodeDataType::build<ASTNodeDataType::type_id_t>(image_domain_node.m_data_type.nameOfTypeId());
}
// LCOV_EXCL_START
default: {
throw UnexpectedError("invalid function return type");
}
// LCOV_EXCL_STOP
}
}();
......@@ -546,9 +548,11 @@ ASTNodeFunctionExpressionBuilder::ASTNodeFunctionExpressionBuilder(ASTNode& node
case ASTNodeDataType::type_id_t: {
return ASTNodeDataType::build<ASTNodeDataType::type_id_t>(function_image_domain.m_data_type.nameOfTypeId());
}
// LCOV_EXCL_START
default: {
throw UnexpectedError("invalid function return type");
}
// LCOV_EXCL_STOP
}
}();
......
......@@ -9,11 +9,19 @@
#include <language/ast/ASTNodeFunctionExpressionBuilder.hpp>
#include <language/ast/ASTNodeTypeCleaner.hpp>
#include <language/ast/ASTSymbolTableBuilder.hpp>
#include <language/utils/ASTNodeDataTypeTraits.hpp>
#include <language/utils/ASTPrinter.hpp>
#include <language/utils/BasicAffectationRegistrerFor.hpp>
#include <language/utils/TypeDescriptor.hpp>
#include <utils/Demangle.hpp>
#include <pegtl/string_input.hpp>
template <>
inline ASTNodeDataType ast_node_data_type_from<std::shared_ptr<const double>> =
ASTNodeDataType::build<ASTNodeDataType::type_id_t>("builtin_t");
const auto builtin_data_type = ast_node_data_type_from<std::shared_ptr<const double>>;
#define CHECK_AST(data, expected_output) \
{ \
static_assert(std::is_same_v<std::decay_t<decltype(data)>, std::string_view>); \
......@@ -24,7 +32,19 @@
auto ast = ASTBuilder::build(input); \
\
ASTModulesImporter{*ast}; \
BasicAffectationRegisterFor<EmbeddedData>{ASTNodeDataType::build<ASTNodeDataType::type_id_t>("builtin_t")}; \
\
ASTNodeTypeCleaner<language::import_instruction>{*ast}; \
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())); \
\
ASTSymbolTableBuilder{*ast}; \
ASTNodeDataTypeBuilder{*ast}; \
......@@ -938,6 +958,27 @@ f(2,(1,2,3),(2,3,-1,1.3));
}
}
SECTION("return a builtin_t")
{
SECTION("builtin_t argument")
{
std::string_view data = R"(
let foo : builtin_t -> builtin_t, b -> b;
let b0 : builtin_t;
foo(b0);
)";
std::string_view result = R"(
(root:ASTNodeListProcessor)
`-(language::function_evaluation:FunctionProcessor)
+-(language::name:foo:NameProcessor)
`-(language::name:b0:NameProcessor)
)";
CHECK_AST(data, result);
}
}
SECTION("errors")
{
SECTION("wrong argument number")
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment