diff --git a/apps/openmw_tests/mwscript/testscripts.cpp b/apps/openmw_tests/mwscript/testscripts.cpp index b9e422daed..1cc85e40ae 100644 --- a/apps/openmw_tests/mwscript/testscripts.cpp +++ b/apps/openmw_tests/mwscript/testscripts.cpp @@ -1,4 +1,6 @@ #include + +#include #include #include "testutils.hpp" @@ -126,6 +128,31 @@ player -> addSpell "fire_bite", 645 PositionCell "Rabenfels, Taverne" 4480.000 3968.000 15820.000 0 +End)mwscript"; + + const std::string sScript5 = R"mwscript(Begin messagebox_format_script + +float fVal + +set fVal to 12.34 + +MessageBox "hello world" +MessageBox "%.0f" fVal +MessageBox "a %03.0f b" fVal +MessageBox "%+04.0f" fVal +MessageBox "%+4.0f" fVal +MessageBox "%+ 4.0f" fVal +MessageBox "%0+ 4.0f" fVal +MessageBox "%0+ #4.0f" fVal +MessageBox "%- 5.0f" fVal + +MessageBox "%g" fVal +MessageBox "%.3g" fVal +MessageBox "%.5g" fVal +MessageBox "%#.5g" fVal +MessageBox "%-5g" fVal +MessageBox "%- 5g" fVal + End)mwscript"; const std::string sIssue587 = R"mwscript(Begin stalresetScript @@ -579,6 +606,43 @@ End)mwscript"; EXPECT_FALSE(!compile(sScript4)); } + TEST_F(MWScriptTest, mwscript_test_messagebox_format) + { + if (const auto script = compile(sScript5)) + { + TestInterpreterContext context; + run(*script, context); + using std::string_view_literals::operator""sv; + constexpr std::array expected{ + "hello world"sv, + "12"sv, + "a 012 b"sv, + "+012"sv, + " +12"sv, + " +12"sv, + "+012"sv, + "+12."sv, + " 12 "sv, + + "12.34"sv, + "12.3"sv, + "12.34"sv, + "12.340"sv, + "12.34"sv, + " 12.34"sv, + }; + for (std::size_t i = 0; i < context.getMessages().size(); i++) + { + std::string_view message = context.getMessages()[i]; + EXPECT_EQ(expected.at(i), message); + } + } + else + { + FAIL(); + } + } + TEST_F(MWScriptTest, mwscript_test_587) { EXPECT_FALSE(!compile(sIssue587)); diff --git a/apps/openmw_tests/mwscript/testutils.hpp b/apps/openmw_tests/mwscript/testutils.hpp index ba22156f56..8ad571b6ee 100644 --- a/apps/openmw_tests/mwscript/testutils.hpp +++ b/apps/openmw_tests/mwscript/testutils.hpp @@ -145,8 +145,11 @@ namespace { LocalVariables mLocals; std::map mMembers; + std::vector mMessages; public: + const std::vector& getMessages() { return mMessages; } + ESM::RefId getTarget() const override { return ESM::RefId(); } int getLocalShort(int index) const override { return mLocals.getShort(index); } @@ -161,7 +164,10 @@ namespace void setLocalFloat(int index, float value) override { mLocals.setFloat(index, value); } - void messageBox(std::string_view message, const std::vector& buttons) override {} + void messageBox(std::string_view message, const std::vector& buttons) override + { + mMessages.emplace_back(message); + } void report(const std::string& message) override {}