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

Add tests for ConcatExpressionProcessor

parent 7308cb1a
No related branches found
No related tags found
1 merge request!37Feature/language
...@@ -9,7 +9,7 @@ class ConcatExpressionProcessor final : public INodeProcessor ...@@ -9,7 +9,7 @@ class ConcatExpressionProcessor final : public INodeProcessor
private: private:
ASTNode& m_node; ASTNode& m_node;
PUGS_INLINE auto PUGS_INLINE void
_eval(const std::string& a, const ASTNodeDataVariant& b, ASTNodeDataVariant& value) _eval(const std::string& a, const ASTNodeDataVariant& b, ASTNodeDataVariant& value)
{ {
if constexpr (std::is_same_v<B_DataT, std::string>) { if constexpr (std::is_same_v<B_DataT, std::string>) {
......
...@@ -29,6 +29,7 @@ add_executable (unit_tests ...@@ -29,6 +29,7 @@ add_executable (unit_tests
test_BreakProcessor.cpp test_BreakProcessor.cpp
test_BiCGStab.cpp test_BiCGStab.cpp
test_ContinueProcessor.cpp test_ContinueProcessor.cpp
test_ConcatExpressionProcessor.cpp
test_CRSMatrix.cpp test_CRSMatrix.cpp
test_DoWhileProcessor.cpp test_DoWhileProcessor.cpp
test_ExecUntilBreakOrContinue.cpp test_ExecUntilBreakOrContinue.cpp
......
#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"});
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment