Add tests for newline handling in String (#125)

This commit is contained in:
Lukáš Lalinský
2013-04-15 10:45:33 +02:00
parent a3352fd899
commit 53c5a97b4c

View File

@ -42,6 +42,7 @@ class TestString : public CppUnit::TestFixture
CPPUNIT_TEST(testAppendStringDetach);
CPPUNIT_TEST(testToInt);
CPPUNIT_TEST(testSubstr);
CPPUNIT_TEST(testNewline);
CPPUNIT_TEST_SUITE_END();
public:
@ -201,6 +202,22 @@ public:
CPPUNIT_ASSERT_EQUAL(String("123456"), String("0123456").substr(1, 200));
}
void testNewline()
{
ByteVector cr("abc\x0dxyz", 7);
ByteVector lf("abc\x0axyz", 7);
ByteVector crlf("abc\x0d\x0axyz", 8);
CPPUNIT_ASSERT_EQUAL(uint(7), String(cr).size());
CPPUNIT_ASSERT_EQUAL(uint(7), String(lf).size());
CPPUNIT_ASSERT_EQUAL(uint(8), String(crlf).size());
CPPUNIT_ASSERT_EQUAL(L'\x0d', String(cr)[3]);
CPPUNIT_ASSERT_EQUAL(L'\x0a', String(lf)[3]);
CPPUNIT_ASSERT_EQUAL(L'\x0d', String(crlf)[3]);
CPPUNIT_ASSERT_EQUAL(L'\x0a', String(crlf)[4]);
}
};
CPPUNIT_TEST_SUITE_REGISTRATION(TestString);