diff options
Diffstat (limited to 'src/unittest/test_utilities.cpp')
-rw-r--r-- | src/unittest/test_utilities.cpp | 35 |
1 files changed, 34 insertions, 1 deletions
diff --git a/src/unittest/test_utilities.cpp b/src/unittest/test_utilities.cpp index df90d37bd..d73975b9f 100644 --- a/src/unittest/test_utilities.cpp +++ b/src/unittest/test_utilities.cpp @@ -43,7 +43,9 @@ public: void testStrToIntConversion(); void testStringReplace(); void testStringAllowed(); + void testAsciiPrintableHelper(); void testUTF8(); + void testRemoveEscapes(); void testWrapRows(); void testIsNumber(); void testIsPowerOfTwo(); @@ -68,7 +70,9 @@ void TestUtilities::runTests(IGameDef *gamedef) TEST(testStrToIntConversion); TEST(testStringReplace); TEST(testStringAllowed); + TEST(testAsciiPrintableHelper); TEST(testUTF8); + TEST(testRemoveEscapes); TEST(testWrapRows); TEST(testIsNumber); TEST(testIsPowerOfTwo); @@ -232,6 +236,18 @@ void TestUtilities::testStringAllowed() UASSERT(string_allowed_blacklist("hello123", "123") == false); } +void TestUtilities::testAsciiPrintableHelper() +{ + UASSERT(IS_ASCII_PRINTABLE_CHAR('e') == true); + UASSERT(IS_ASCII_PRINTABLE_CHAR('\0') == false); + + // Ensures that there is no cutting off going on... + // If there were, 331 would be cut to 75 in this example + // and 73 is a valid ASCII char. + int ch = 331; + UASSERT(IS_ASCII_PRINTABLE_CHAR(ch) == false); +} + void TestUtilities::testUTF8() { UASSERT(wide_to_utf8(utf8_to_wide("")) == ""); @@ -239,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"); @@ -282,7 +315,7 @@ void TestUtilities::testIsPowerOfTwo() UASSERT(is_power_of_two((1 << exponent)) == true); UASSERT(is_power_of_two((1 << exponent) + 1) == false); } - UASSERT(is_power_of_two((u32)-1) == false); + UASSERT(is_power_of_two(U32_MAX) == false); } void TestUtilities::testMyround() |