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

Add missing tests for ASTNodeListAffectationExpressionBuilder

parent f96425ff
Branches
Tags
1 merge request!104Add missing tests for ASTNodeBuiltinFunctionExpressionBuilder
...@@ -133,7 +133,8 @@ ASTNodeListAffectationExpressionBuilder::_buildAffectationProcessor( ...@@ -133,7 +133,8 @@ ASTNodeListAffectationExpressionBuilder::_buildAffectationProcessor(
// LCOV_EXCL_STOP // LCOV_EXCL_STOP
} }
} else { } else {
throw ParseError("unexpected error: undefined operator type for string affectation", std::vector{m_node.begin()}); throw ParseError("unexpected error: undefined operator type for embedded data affectation",
std::vector{m_node.begin()});
} }
}; };
...@@ -286,11 +287,11 @@ ASTNodeListAffectationExpressionBuilder::_buildAffectationProcessor( ...@@ -286,11 +287,11 @@ ASTNodeListAffectationExpressionBuilder::_buildAffectationProcessor(
if (optional_processor_builder.has_value()) { if (optional_processor_builder.has_value()) {
add_affectation_processor_for_value(value_node.m_data_type, rhs_node_sub_data_type); add_affectation_processor_for_value(value_node.m_data_type, rhs_node_sub_data_type);
} else { } else {
// LCOV_EXCL_START
std::ostringstream error_message; std::ostringstream error_message;
error_message << "undefined affectation type: "; error_message << "undefined affectation type: " << rang::fgB::red << affectation_name << rang::fg::reset;
error_message << rang::fgB::red << affectation_name << rang::fg::reset; throw UnexpectedError(error_message.str());
// LCOV_EXCL_STOP
throw ParseError(error_message.str(), std::vector{m_node.children[0]->begin()});
} }
} }
......
...@@ -9,11 +9,19 @@ ...@@ -9,11 +9,19 @@
#include <language/ast/ASTNodeListAffectationExpressionBuilder.hpp> #include <language/ast/ASTNodeListAffectationExpressionBuilder.hpp>
#include <language/ast/ASTNodeTypeCleaner.hpp> #include <language/ast/ASTNodeTypeCleaner.hpp>
#include <language/ast/ASTSymbolTableBuilder.hpp> #include <language/ast/ASTSymbolTableBuilder.hpp>
#include <language/utils/ASTNodeDataTypeTraits.hpp>
#include <language/utils/ASTPrinter.hpp> #include <language/utils/ASTPrinter.hpp>
#include <language/utils/BasicAffectationRegistrerFor.hpp>
#include <language/utils/TypeDescriptor.hpp>
#include <utils/Demangle.hpp> #include <utils/Demangle.hpp>
#include <pegtl/string_input.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) \ #define CHECK_AST(data, expected_output) \
{ \ { \
static_assert(std::is_same_v<std::decay_t<decltype(data)>, std::string_view>); \ static_assert(std::is_same_v<std::decay_t<decltype(data)>, std::string_view>); \
...@@ -24,7 +32,19 @@ ...@@ -24,7 +32,19 @@
auto ast = ASTBuilder::build(input); \ auto ast = ASTBuilder::build(input); \
\ \
ASTModulesImporter{*ast}; \ ASTModulesImporter{*ast}; \
BasicAffectationRegisterFor<EmbeddedData>{ASTNodeDataType::build<ASTNodeDataType::type_id_t>("builtin_t")}; \
\
ASTNodeTypeCleaner<language::import_instruction>{*ast}; \ 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}; \ ASTSymbolTableBuilder{*ast}; \
ASTNodeDataTypeBuilder{*ast}; \ ASTNodeDataTypeBuilder{*ast}; \
...@@ -375,6 +395,26 @@ let (r,s,t,u) : string*string*string*string, ...@@ -375,6 +395,26 @@ let (r,s,t,u) : string*string*string*string,
CHECK_AST(data, result); CHECK_AST(data, result);
} }
SECTION("embedded data")
{
std::string_view data = R"(
let (b0,b1): builtin_t*builtin_t, (b0,b1) = (b0,b1);
)";
std::string_view result = R"(
(root:ASTNodeListProcessor)
`-(language::eq_op:ListAffectationProcessor<language::eq_op>)
+-(language::name_list:FakeProcessor)
| +-(language::name:b0:NameProcessor)
| `-(language::name:b1:NameProcessor)
`-(language::expression_list:ASTNodeExpressionListProcessor)
+-(language::name:b0:NameProcessor)
`-(language::name:b1:NameProcessor)
)";
CHECK_AST(data, result);
}
} }
SECTION("Errors") SECTION("Errors")
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment