Fix GncOptionMultichoiceValue list tests

To conform to changes in 84eb084375.
This commit is contained in:
John Ralls
2023-07-20 21:24:31 -07:00
parent e5f9e4ea6d
commit c5181180ad
2 changed files with 12 additions and 6 deletions

View File

@@ -23,6 +23,7 @@
#include "gnc-option-impl.hpp" #include "gnc-option-impl.hpp"
#include "gnc-datetime.hpp" #include "gnc-datetime.hpp"
#include "gnc-option-uitype.hpp"
#include "guid.hpp" #include "guid.hpp"
#include <cassert> #include <cassert>
#include <sstream> #include <sstream>
@@ -887,11 +888,15 @@ GncOptionAccountSelValue::deserialize(const std::string& str) noexcept
std::string std::string
GncOptionMultichoiceValue::serialize() const noexcept GncOptionMultichoiceValue::serialize() const noexcept
{ {
static const std::string no_value{"No Value"}; static const std::string no_value{""};
std::string retval; std::string retval;
bool first = true; bool first = true;
bool list_context = m_ui_type == GncOptionUIType::LIST;
if (m_value.empty()) if (m_value.empty())
return no_value; return no_value;
if (list_context)
retval += '(';
for (auto index : m_value) for (auto index : m_value)
{ {
if (!first) if (!first)
@@ -899,6 +904,8 @@ GncOptionMultichoiceValue::serialize() const noexcept
first = false; first = false;
retval += std::get<0>(m_choices[index]); retval += std::get<0>(m_choices[index]);
} }
if (list_context)
retval += ')';
return retval; return retval;
} }

View File

@@ -846,12 +846,11 @@ TEST_F(GncListOption, test_set_value)
TEST_F(GncListOption, test_list_out) TEST_F(GncListOption, test_list_out)
{ {
auto vec{m_option.get_value<GncMultichoiceOptionIndexVec>()}; auto vec{m_option.get_value<GncMultichoiceOptionIndexVec>()};
std::string value{m_option.permissible_value(vec[0])}; std::ostringstream vss, oss;
value += " "; vss << '(' << m_option.permissible_value(vec[0]) << " "
value += m_option.permissible_value(vec[1]); << m_option.permissible_value(vec[1]) << ')';
std::ostringstream oss;
oss << m_option; oss << m_option;
EXPECT_EQ(oss.str(), value); EXPECT_EQ(oss.str(), vss.str());
} }
TEST_F(GncListOption, test_list_in) TEST_F(GncListOption, test_list_in)