From 1892ff3c0db23ccdf7b0f6dc83cb1bdf4579b4ec Mon Sep 17 00:00:00 2001 From: SmallJoker Date: Wed, 22 Jan 2020 19:09:11 +0100 Subject: StaticText/EnrichedString: Styling support (#9187) * StaticText/EnrichedString: Styling support * Fix tooltip fg/bgcolor * Fix default color for substr(), add unittests --- src/unittest/test_utilities.cpp | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'src/unittest') diff --git a/src/unittest/test_utilities.cpp b/src/unittest/test_utilities.cpp index 8e8958d18..447b591e1 100644 --- a/src/unittest/test_utilities.cpp +++ b/src/unittest/test_utilities.cpp @@ -20,6 +20,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "test.h" #include +#include "util/enriched_string.h" #include "util/numeric.h" #include "util/string.h" @@ -49,6 +50,7 @@ public: void testUTF8(); void testRemoveEscapes(); void testWrapRows(); + void testEnrichedString(); void testIsNumber(); void testIsPowerOfTwo(); void testMyround(); @@ -79,6 +81,7 @@ void TestUtilities::runTests(IGameDef *gamedef) TEST(testUTF8); TEST(testRemoveEscapes); TEST(testWrapRows); + TEST(testEnrichedString); TEST(testIsNumber); TEST(testIsPowerOfTwo); TEST(testMyround); @@ -344,6 +347,23 @@ void TestUtilities::testWrapRows() } } +void TestUtilities::testEnrichedString() +{ + EnrichedString str(L"Test bar"); + irr::video::SColor color(0xFF, 0, 0, 0xFF); + + UASSERT(str.substr(1, 3).getString() == L"est"); + str += L" BUZZ"; + UASSERT(str.substr(9, std::string::npos).getString() == L"BUZZ"); + str.setDefaultColor(color); // Blue foreground + UASSERT(str.getColors()[5] == color); + // Green background, then white and yellow text + str = L"\x1b(b@#0F0)Regular \x1b(c@#FF0)yellow"; + UASSERT(str.getColors()[2] == 0xFFFFFFFF); + str.setDefaultColor(color); // Blue foreground + UASSERT(str.getColors()[13] == 0xFFFFFF00); // Still yellow text + UASSERT(str.getBackground() == 0xFF00FF00); // Green background +} void TestUtilities::testIsNumber() { -- cgit v1.2.3