mirror of
https://github.com/OpenMW/openmw.git
synced 2025-12-03 20:34:30 +00:00
Use vformat_to and add more tests
This commit is contained in:
parent
0ab0e9abd7
commit
50ffc908e8
2 changed files with 20 additions and 8 deletions
|
|
@ -138,6 +138,7 @@ set fVal to 12.34
|
|||
|
||||
MessageBox "hello world"
|
||||
MessageBox "%.0f" fVal
|
||||
MessageBox "%.f" fVal
|
||||
MessageBox "a %03.0f b" fVal
|
||||
MessageBox "%+04.0f" fVal
|
||||
MessageBox "%+4.0f" fVal
|
||||
|
|
@ -153,6 +154,8 @@ MessageBox "%#.5g" fVal
|
|||
MessageBox "%-5g" fVal
|
||||
MessageBox "%- 5g" fVal
|
||||
|
||||
MessageBox "%.1b" fVal
|
||||
|
||||
End)mwscript";
|
||||
|
||||
const std::string sIssue587 = R"mwscript(Begin stalresetScript
|
||||
|
|
@ -616,6 +619,7 @@ End)mwscript";
|
|||
constexpr std::array expected{
|
||||
"hello world"sv,
|
||||
"12"sv,
|
||||
"12"sv,
|
||||
"a 012 b"sv,
|
||||
"+012"sv,
|
||||
" +12"sv,
|
||||
|
|
@ -630,11 +634,14 @@ End)mwscript";
|
|||
"12.340"sv,
|
||||
"12.34"sv,
|
||||
" 12.34"sv,
|
||||
|
||||
"b"sv,
|
||||
};
|
||||
for (std::size_t i = 0; i < context.getMessages().size(); i++)
|
||||
const std::vector<std::string>& output = context.getMessages();
|
||||
EXPECT_EQ(expected.size(), output.size());
|
||||
for (std::size_t i = 0; i < output.size(); i++)
|
||||
{
|
||||
std::string_view message = context.getMessages()[i];
|
||||
EXPECT_EQ(expected.at(i), message);
|
||||
EXPECT_EQ(expected[i], output[i]);
|
||||
}
|
||||
}
|
||||
else
|
||||
|
|
|
|||
|
|
@ -46,7 +46,8 @@ namespace Interpreter
|
|||
else
|
||||
formatString += '>';
|
||||
formatString += "{}}";
|
||||
mFormattedMessage += std::vformat(formatString, std::make_format_args(value, width));
|
||||
std::vformat_to(
|
||||
std::back_inserter(mFormattedMessage), formatString, std::make_format_args(value, width));
|
||||
}
|
||||
}
|
||||
else
|
||||
|
|
@ -75,13 +76,17 @@ namespace Interpreter
|
|||
formatString += '}';
|
||||
const auto appendMessage = [&](auto value) {
|
||||
if (width >= 0 && precision >= 0)
|
||||
mFormattedMessage += std::vformat(formatString, std::make_format_args(value, width, precision));
|
||||
std::vformat_to(std::back_inserter(mFormattedMessage), formatString,
|
||||
std::make_format_args(value, width, precision));
|
||||
else if (width >= 0)
|
||||
mFormattedMessage += std::vformat(formatString, std::make_format_args(value, width));
|
||||
std::vformat_to(
|
||||
std::back_inserter(mFormattedMessage), formatString, std::make_format_args(value, width));
|
||||
else if (precision >= 0)
|
||||
mFormattedMessage += std::vformat(formatString, std::make_format_args(value, precision));
|
||||
std::vformat_to(std::back_inserter(mFormattedMessage), formatString,
|
||||
std::make_format_args(value, precision));
|
||||
else
|
||||
mFormattedMessage += std::vformat(formatString, std::make_format_args(value));
|
||||
std::vformat_to(
|
||||
std::back_inserter(mFormattedMessage), formatString, std::make_format_args(value));
|
||||
};
|
||||
if (placeholder == FloatPlaceholder)
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in a new issue