From 10d44bab2553368e071c745547a4b6b8f29805ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Del=20Pino?= <stephane.delpino44@gmail.com> Date: Fri, 20 May 2022 18:02:21 +0200 Subject: [PATCH] Change concatenation to string from B expressions Following the change to the binary + operator, now the concatenated value is either the string "true" or "false" --- src/language/node_processor/AffectationProcessor.hpp | 4 ++-- tests/test_AffectationToStringProcessor.cpp | 3 +-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/language/node_processor/AffectationProcessor.hpp b/src/language/node_processor/AffectationProcessor.hpp index c172874b8..c36a74728 100644 --- a/src/language/node_processor/AffectationProcessor.hpp +++ b/src/language/node_processor/AffectationProcessor.hpp @@ -111,11 +111,11 @@ class AffectationExecutor final : public IAffectationExecutor } else { if constexpr (std::is_same_v<std::string, DataT>) { std::get<std::string>(m_lhs) += std::get<std::string>(rhs); - } else if constexpr (std::is_arithmetic_v<DataT>) { + } else if constexpr ((std::is_arithmetic_v<DataT>)and not(std::is_same_v<bool, DataT>)) { std::get<std::string>(m_lhs) += std::to_string(std::get<DataT>(rhs)); } else { std::ostringstream os; - os << std::get<DataT>(rhs); + os << std::boolalpha << std::get<DataT>(rhs); std::get<std::string>(m_lhs) += os.str(); } } diff --git a/tests/test_AffectationToStringProcessor.cpp b/tests/test_AffectationToStringProcessor.cpp index 01c7ba7b9..73337da4c 100644 --- a/tests/test_AffectationToStringProcessor.cpp +++ b/tests/test_AffectationToStringProcessor.cpp @@ -81,8 +81,7 @@ TEST_CASE("ASTAffectationToStringProcessor", "[language]") CHECK_AFFECTATION_RESULT(R"(let n : N, n = 2; let s : string, s = "foo"; s += n;)", "s", (std::string("foo") + std::to_string(2ul))); CHECK_AFFECTATION_RESULT(R"(let s : string, s = "foo"; s += -1;)", "s", (std::string("foo") + std::to_string(-1l))); - CHECK_AFFECTATION_RESULT(R"(let s : string, s = "foo"; s += true;)", "s", - (std::string("foo") + std::to_string(true))); + CHECK_AFFECTATION_RESULT(R"(let s : string, s = "foo"; s += true;)", "s", (std::string("footrue"))); CHECK_AFFECTATION_RESULT(R"(let s : string, s = "foo"; s += 2.3;)", "s", (std::string("foo") + std::to_string(2.3))); { -- GitLab