diff --git a/src/language/node_processor/ConcatExpressionProcessor.hpp b/src/language/node_processor/ConcatExpressionProcessor.hpp index 0b0d210d17884972d482d9499d544c3ec673cb16..a8249560791c2ff02423d46ba4456c87bb904bb8 100644 --- a/src/language/node_processor/ConcatExpressionProcessor.hpp +++ b/src/language/node_processor/ConcatExpressionProcessor.hpp @@ -9,7 +9,7 @@ class ConcatExpressionProcessor final : public INodeProcessor private: ASTNode& m_node; - PUGS_INLINE auto + PUGS_INLINE void _eval(const std::string& a, const ASTNodeDataVariant& b, ASTNodeDataVariant& value) { if constexpr (std::is_same_v<B_DataT, std::string>) { diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index baa29881a0efbf691c00506ce6f34571ef8b1be6..2dd4c589d6772e1eb9067a062b6a6ebeac9a4fcb 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -29,6 +29,7 @@ add_executable (unit_tests test_BreakProcessor.cpp test_BiCGStab.cpp test_ContinueProcessor.cpp + test_ConcatExpressionProcessor.cpp test_CRSMatrix.cpp test_DoWhileProcessor.cpp test_ExecUntilBreakOrContinue.cpp diff --git a/tests/test_ConcatExpressionProcessor.cpp b/tests/test_ConcatExpressionProcessor.cpp new file mode 100644 index 0000000000000000000000000000000000000000..3b44302488398fd5f8fb038b8811b55c611a72a6 --- /dev/null +++ b/tests/test_ConcatExpressionProcessor.cpp @@ -0,0 +1,80 @@ +#include <catch2/catch.hpp> + +#include <ASTNodeValueBuilder.hpp> + +#include <ASTBuilder.hpp> +#include <ASTNodeDataTypeBuilder.hpp> + +#include <ASTNodeDeclarationCleaner.hpp> +#include <ASTNodeDeclarationToAffectationConverter.hpp> + +#include <ASTNodeExpressionBuilder.hpp> + +#include <ASTNodeAffectationExpressionBuilder.hpp> + +#include <ASTSymbolTableBuilder.hpp> + +#include <ASTPrinter.hpp> + +#include <Demangle.hpp> + +#include <PEGGrammar.hpp> + +#include <sstream> + +#define CHECK_CONCAT_EXPRESSION_RESULT(data, variable_name, expected_value) \ + { \ + string_input input{data, "test.pgs"}; \ + auto ast = ASTBuilder::build(input); \ + \ + ASTSymbolTableBuilder{*ast}; \ + ASTNodeDataTypeBuilder{*ast}; \ + ASTNodeValueBuilder{*ast}; \ + \ + ASTNodeDeclarationToAffectationConverter{*ast}; \ + ASTNodeDeclarationCleaner{*ast}; \ + \ + ASTNodeExpressionBuilder{*ast}; \ + ExecUntilBreakOrContinue 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 attribute = symbol->second; \ + auto value = std::get<decltype(expected_value)>(attribute.value()); \ + \ + REQUIRE(value == expected_value); \ + } + +TEST_CASE("ConcatExpressionProcessor", "[language]") +{ + SECTION("string + string") + { + CHECK_CONCAT_EXPRESSION_RESULT(R"(string s = "foo"; s = s+"bar";)", "s", std::string{"foobar"}); + } + + SECTION("string + N") + { + CHECK_CONCAT_EXPRESSION_RESULT(R"(N n = 1; string s = "foo_"; s = s+n;)", "s", std::string{"foo_1"}); + } + + SECTION("string + Z") + { + CHECK_CONCAT_EXPRESSION_RESULT(R"(string s = "foo_"; s = s+2;)", "s", std::string{"foo_2"}); + } + + SECTION("string + R") + { + CHECK_CONCAT_EXPRESSION_RESULT(R"(string s = "foo_"; s = s+2.4;)", "s", std::string{"foo_"} + std::to_string(2.4)); + } + + SECTION("string + B") + { + CHECK_CONCAT_EXPRESSION_RESULT(R"(string s = "foo_"; s = s+true;)", "s", std::string{"foo_1"}); + } +}