gnucash stable: Fix GncOptionMultichoiceValue list tests

John Ralls jralls at code.gnucash.org
Fri Jul 21 00:25:32 EDT 2023


Updated	 via  https://github.com/Gnucash/gnucash/commit/c5181180 (commit)
	from  https://github.com/Gnucash/gnucash/commit/e5f9e4ea (commit)



commit c5181180ad12f2809a06fe11a556469f80f79fc4
Author: John Ralls <jralls at ceridwen.us>
Date:   Thu Jul 20 21:24:31 2023 -0700

    Fix GncOptionMultichoiceValue list tests
    
    To conform to changes in 84eb084375.

diff --git a/libgnucash/engine/gnc-option-impl.cpp b/libgnucash/engine/gnc-option-impl.cpp
index 8d268f447a..bb34a6553f 100644
--- a/libgnucash/engine/gnc-option-impl.cpp
+++ b/libgnucash/engine/gnc-option-impl.cpp
@@ -23,6 +23,7 @@
 
 #include "gnc-option-impl.hpp"
 #include "gnc-datetime.hpp"
+#include "gnc-option-uitype.hpp"
 #include "guid.hpp"
 #include <cassert>
 #include <sstream>
@@ -887,11 +888,15 @@ GncOptionAccountSelValue::deserialize(const std::string& str) noexcept
 std::string
 GncOptionMultichoiceValue::serialize() const noexcept
 {
-    static const std::string no_value{"No Value"};
+    static const std::string no_value{""};
     std::string retval;
     bool first = true;
+    bool list_context = m_ui_type == GncOptionUIType::LIST;
     if (m_value.empty())
         return no_value;
+
+    if (list_context)
+        retval += '(';
     for (auto index : m_value)
     {
         if (!first)
@@ -899,6 +904,8 @@ GncOptionMultichoiceValue::serialize() const noexcept
         first = false;
         retval += std::get<0>(m_choices[index]);
     }
+    if (list_context)
+        retval += ')';
     return retval;
 }
 
diff --git a/libgnucash/engine/test/gtest-gnc-option.cpp b/libgnucash/engine/test/gtest-gnc-option.cpp
index 6d2005b602..81700ea701 100644
--- a/libgnucash/engine/test/gtest-gnc-option.cpp
+++ b/libgnucash/engine/test/gtest-gnc-option.cpp
@@ -846,12 +846,11 @@ TEST_F(GncListOption, test_set_value)
 TEST_F(GncListOption, test_list_out)
 {
     auto vec{m_option.get_value<GncMultichoiceOptionIndexVec>()};
-    std::string value{m_option.permissible_value(vec[0])};
-    value += " ";
-    value += m_option.permissible_value(vec[1]);
-    std::ostringstream oss;
+    std::ostringstream vss, oss;
+    vss << '(' << m_option.permissible_value(vec[0]) << " "
+        << m_option.permissible_value(vec[1]) << ')';
     oss << m_option;
-    EXPECT_EQ(oss.str(), value);
+    EXPECT_EQ(oss.str(), vss.str());
 }
 
 TEST_F(GncListOption, test_list_in)



Summary of changes:
 libgnucash/engine/gnc-option-impl.cpp       | 9 ++++++++-
 libgnucash/engine/test/gtest-gnc-option.cpp | 9 ++++-----
 2 files changed, 12 insertions(+), 6 deletions(-)



More information about the gnucash-changes mailing list