Skip to content

Commit

Permalink
Add UTF and other utility unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
est31 committed Jun 14, 2015
1 parent 60f31ad commit d105bf2
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/unittest/test_utilities.cpp
Expand Up @@ -37,11 +37,13 @@ class TestUtilities : public TestBase {
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();
Expand All @@ -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);
Expand Down Expand Up @@ -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 ") == "");
}
Expand Down Expand Up @@ -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()
{
Expand Down Expand Up @@ -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()
{
Expand Down

0 comments on commit d105bf2

Please sign in to comment.