1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-06-27 16:36:03 +00:00

Escape more strings: formspecs, item descriptions, infotexts...

Also, change the escape character to the more standard \x1b
Thus, it can be used in the future for translation or colored text,
for example.
This commit is contained in:
Ekdohibs 2016-04-04 18:31:00 +02:00 committed by Craig Robbins
parent 21079cc8eb
commit 48939df9a5
8 changed files with 105 additions and 83 deletions

View file

@ -45,6 +45,7 @@ public:
void testStringAllowed();
void testAsciiPrintableHelper();
void testUTF8();
void testRemoveEscapes();
void testWrapRows();
void testIsNumber();
void testIsPowerOfTwo();
@ -71,6 +72,7 @@ void TestUtilities::runTests(IGameDef *gamedef)
TEST(testStringAllowed);
TEST(testAsciiPrintableHelper);
TEST(testUTF8);
TEST(testRemoveEscapes);
TEST(testWrapRows);
TEST(testIsNumber);
TEST(testIsPowerOfTwo);
@ -253,6 +255,23 @@ void TestUtilities::testUTF8()
== "the shovel dug a crumbly node!");
}
void TestUtilities::testRemoveEscapes()
{
UASSERT(unescape_enriched<wchar_t>(
L"abc\x1bXdef") == L"abcdef");
UASSERT(unescape_enriched<wchar_t>(
L"abc\x1b(escaped)def") == L"abcdef");
UASSERT(unescape_enriched<wchar_t>(
L"abc\x1b((escaped with parenthesis\\))def") == L"abcdef");
UASSERT(unescape_enriched<wchar_t>(
L"abc\x1b(incomplete") == L"abc");
UASSERT(unescape_enriched<wchar_t>(
L"escape at the end\x1b") == L"escape at the end");
// Nested escapes not supported
UASSERT(unescape_enriched<wchar_t>(
L"abc\x1b(outer \x1b(inner escape)escape)def") == L"abcescape)def");
}
void TestUtilities::testWrapRows()
{
UASSERT(wrap_rows("12345678",4) == "1234\n5678");