diff options
author | est31 <MTest31@outlook.com> | 2015-06-14 12:00:06 +0200 |
---|---|---|
committer | est31 <MTest31@outlook.com> | 2015-06-14 12:07:51 +0200 |
commit | d105bf27dd9f570754f470c3bb6a46369c4aaaad (patch) | |
tree | aa95e7920c0e0c65b1b35e596feeb0164060d412 /src | |
parent | 60f31ad52348c53209701d0112f9f809018f7188 (diff) | |
download | minetest-d105bf27dd9f570754f470c3bb6a46369c4aaaad.tar.gz minetest-d105bf27dd9f570754f470c3bb6a46369c4aaaad.tar.bz2 minetest-d105bf27dd9f570754f470c3bb6a46369c4aaaad.zip |
Add UTF and other utility unit tests
Diffstat (limited to 'src')
-rw-r--r-- | src/unittest/test_utilities.cpp | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/src/unittest/test_utilities.cpp b/src/unittest/test_utilities.cpp index 07108706a..6a731c662 100644 --- a/src/unittest/test_utilities.cpp +++ b/src/unittest/test_utilities.cpp @@ -37,11 +37,13 @@ public: void testUrlEncode(); void testUrlDecode(); void testPadString(); + void testStartsWith(); void testStrEqual(); void testStringTrim(); void testStrToIntConversion(); void testStringReplace(); void testStringAllowed(); + void testUTF8(); void testWrapRows(); void testIsNumber(); void testIsPowerOfTwo(); @@ -60,11 +62,13 @@ void TestUtilities::runTests(IGameDef *gamedef) TEST(testUrlEncode); TEST(testUrlDecode); TEST(testPadString); + TEST(testStartsWith); TEST(testStrEqual); TEST(testStringTrim); TEST(testStrToIntConversion); TEST(testStringReplace); TEST(testStringAllowed); + TEST(testUTF8); TEST(testWrapRows); TEST(testIsNumber); TEST(testIsPowerOfTwo); @@ -123,6 +127,8 @@ void TestUtilities::testLowercase() void TestUtilities::testTrim() { + UASSERT(trim("") == ""); + UASSERT(trim("dirt_with_grass") == "dirt_with_grass"); UASSERT(trim("\n \t\r Foo bAR \r\n\t\t ") == "Foo bAR"); UASSERT(trim("\n \t\r \r\n\t\t ") == ""); } @@ -169,6 +175,19 @@ void TestUtilities::testPadString() UASSERT(padStringRight("hello", 8) == "hello "); } +void TestUtilities::testStartsWith() +{ + UASSERT(str_starts_with(std::string(), std::string()) == true); + UASSERT(str_starts_with(std::string("the sharp pickaxe"), + std::string()) == true); + UASSERT(str_starts_with(std::string("the sharp pickaxe"), + std::string("the")) == true); + UASSERT(str_starts_with(std::string("the sharp pickaxe"), + std::string("The")) == false); + UASSERT(str_starts_with(std::string("the sharp pickaxe"), + std::string("The"), true) == true); + UASSERT(str_starts_with(std::string("T"), std::string("The")) == false); +} void TestUtilities::testStrEqual() { @@ -213,6 +232,12 @@ void TestUtilities::testStringAllowed() UASSERT(string_allowed_blacklist("hello123", "123") == false); } +void TestUtilities::testUTF8() +{ + UASSERT(wide_to_utf8(utf8_to_wide("")) == ""); + UASSERT(wide_to_utf8(utf8_to_wide("the shovel dug a crumbly node!")) + == "the shovel dug a crumbly node!"); +} void TestUtilities::testWrapRows() { |