Skip to content

Commit d105bf2

Browse files
committedJun 14, 2015
Add UTF and other utility unit tests
1 parent 60f31ad commit d105bf2

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed
 

Diff for: ‎src/unittest/test_utilities.cpp

+25
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,13 @@ class TestUtilities : public TestBase {
3737
void testUrlEncode();
3838
void testUrlDecode();
3939
void testPadString();
40+
void testStartsWith();
4041
void testStrEqual();
4142
void testStringTrim();
4243
void testStrToIntConversion();
4344
void testStringReplace();
4445
void testStringAllowed();
46+
void testUTF8();
4547
void testWrapRows();
4648
void testIsNumber();
4749
void testIsPowerOfTwo();
@@ -60,11 +62,13 @@ void TestUtilities::runTests(IGameDef *gamedef)
6062
TEST(testUrlEncode);
6163
TEST(testUrlDecode);
6264
TEST(testPadString);
65+
TEST(testStartsWith);
6366
TEST(testStrEqual);
6467
TEST(testStringTrim);
6568
TEST(testStrToIntConversion);
6669
TEST(testStringReplace);
6770
TEST(testStringAllowed);
71+
TEST(testUTF8);
6872
TEST(testWrapRows);
6973
TEST(testIsNumber);
7074
TEST(testIsPowerOfTwo);
@@ -123,6 +127,8 @@ void TestUtilities::testLowercase()
123127

124128
void TestUtilities::testTrim()
125129
{
130+
UASSERT(trim("") == "");
131+
UASSERT(trim("dirt_with_grass") == "dirt_with_grass");
126132
UASSERT(trim("\n \t\r Foo bAR \r\n\t\t ") == "Foo bAR");
127133
UASSERT(trim("\n \t\r \r\n\t\t ") == "");
128134
}
@@ -169,6 +175,19 @@ void TestUtilities::testPadString()
169175
UASSERT(padStringRight("hello", 8) == "hello ");
170176
}
171177

178+
void TestUtilities::testStartsWith()
179+
{
180+
UASSERT(str_starts_with(std::string(), std::string()) == true);
181+
UASSERT(str_starts_with(std::string("the sharp pickaxe"),
182+
std::string()) == true);
183+
UASSERT(str_starts_with(std::string("the sharp pickaxe"),
184+
std::string("the")) == true);
185+
UASSERT(str_starts_with(std::string("the sharp pickaxe"),
186+
std::string("The")) == false);
187+
UASSERT(str_starts_with(std::string("the sharp pickaxe"),
188+
std::string("The"), true) == true);
189+
UASSERT(str_starts_with(std::string("T"), std::string("The")) == false);
190+
}
172191

173192
void TestUtilities::testStrEqual()
174193
{
@@ -213,6 +232,12 @@ void TestUtilities::testStringAllowed()
213232
UASSERT(string_allowed_blacklist("hello123", "123") == false);
214233
}
215234

235+
void TestUtilities::testUTF8()
236+
{
237+
UASSERT(wide_to_utf8(utf8_to_wide("")) == "");
238+
UASSERT(wide_to_utf8(utf8_to_wide("the shovel dug a crumbly node!"))
239+
== "the shovel dug a crumbly node!");
240+
}
216241

217242
void TestUtilities::testWrapRows()
218243
{

0 commit comments

Comments
 (0)
Please sign in to comment.