diff options
Diffstat (limited to 'test')
| -rw-r--r-- | test/UtilTest.cc | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/test/UtilTest.cc b/test/UtilTest.cc index 5dbc6148..e6ab1a60 100644 --- a/test/UtilTest.cc +++ b/test/UtilTest.cc @@ -10,6 +10,8 @@ class UtilTest:public CppUnit::TestFixture { CPPUNIT_TEST(testTrim); CPPUNIT_TEST(testSplit); CPPUNIT_TEST(testSlice); + CPPUNIT_TEST(testEndsWith); + CPPUNIT_TEST(testReplace); CPPUNIT_TEST_SUITE_END(); private: @@ -20,6 +22,8 @@ public: void testTrim(); void testSplit(); void testSlice(); + void testEndsWith(); + void testReplace(); }; @@ -75,3 +79,45 @@ void UtilTest::testSlice() { CPPUNIT_ASSERT_EQUAL(string("name2=value2"), *itr++); CPPUNIT_ASSERT_EQUAL(string("name3=value3"), *itr++); } + +void UtilTest::testEndsWith() { + string target = "abcdefg"; + string part = "fg"; + CPPUNIT_ASSERT(Util::endsWith(target, part)); + + target = "abdefg"; + part = "g"; + CPPUNIT_ASSERT(Util::endsWith(target, part)); + + target = "abdefg"; + part = "eg"; + CPPUNIT_ASSERT(!Util::endsWith(target, part)); + + target = "g"; + part = "eg"; + CPPUNIT_ASSERT(!Util::endsWith(target, part)); + + target = "g"; + part = "g"; + CPPUNIT_ASSERT(Util::endsWith(target, part)); + + target = "g"; + part = ""; + CPPUNIT_ASSERT(Util::endsWith(target, part)); + + target = ""; + part = ""; + CPPUNIT_ASSERT(Util::endsWith(target, part)); + + target = ""; + part = "g"; + CPPUNIT_ASSERT(!Util::endsWith(target, part)); +} + +void UtilTest::testReplace() { + CPPUNIT_ASSERT_EQUAL(string("abc\n"), Util::replace("abc\r\n", "\r", "")); + CPPUNIT_ASSERT_EQUAL(string("abc"), Util::replace("abc\r\n", "\r\n", "")); + CPPUNIT_ASSERT_EQUAL(string(""), Util::replace("", "\r\n", "")); + CPPUNIT_ASSERT_EQUAL(string("abc"), Util::replace("abc", "", "a")); + CPPUNIT_ASSERT_EQUAL(string("xbc"), Util::replace("abc", "a", "x")); +} |
