X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/0c7db140c582e66be907160ae2d3a781c6d1353c..81e0b3d978a3f560cd8cb48e2f698cb58effd2a8:/tests/strings/strings.cpp diff --git a/tests/strings/strings.cpp b/tests/strings/strings.cpp index 09e0dca52c..3542704e49 100644 --- a/tests/strings/strings.cpp +++ b/tests/strings/strings.cpp @@ -59,6 +59,8 @@ private: CPPUNIT_TEST( CStrDataOperators ); CPPUNIT_TEST( CStrDataImplicitConversion ); CPPUNIT_TEST( ExplicitConversion ); + CPPUNIT_TEST( IndexedAccess ); + CPPUNIT_TEST( BeforeAndAfter ); CPPUNIT_TEST_SUITE_END(); void String(); @@ -89,6 +91,8 @@ private: void CStrDataOperators(); void CStrDataImplicitConversion(); void ExplicitConversion(); + void IndexedAccess(); + void BeforeAndAfter(); DECLARE_NO_COPY_CLASS(StringTestCase) }; @@ -333,6 +337,8 @@ void StringTestCase::Replace() TEST_WXREPLACE( _T("null\0dehar"), 10, _T("de"), _T("c"), true, _T("null\0char"), 9 ); + TEST_WXREPLACE( "life", 4, "f", "", false, "lie", 3 ); + #undef TEST_WXREPLACE #undef TEST_NULLCHARREPLACE #undef TEST_REPLACE @@ -824,3 +830,37 @@ void StringTestCase::ExplicitConversion() CPPUNIT_ASSERT( CheckStrConstWChar(s, s.wc_str()) ); CPPUNIT_ASSERT( CheckStrWChar(s, s.wchar_str()) ); } + +void StringTestCase::IndexedAccess() +{ + wxString s("bar"); + CPPUNIT_ASSERT_EQUAL( 'r', s[2] ); + + // this tests for a possible bug in UTF-8 based wxString implementation: + // the 3rd character of the underlying byte string is going to change, but + // the 3rd character of wxString should remain the same + s[0] = L'\u00e9'; + CPPUNIT_ASSERT_EQUAL( 'r', s[2] ); +} + +void StringTestCase::BeforeAndAfter() +{ + const wxString s(L"letter=\u00e9;\u00e7a=l\u00e0"); + + CPPUNIT_ASSERT_EQUAL( "letter", s.BeforeFirst('=') ); + CPPUNIT_ASSERT_EQUAL( s, s.BeforeFirst('!') ); + CPPUNIT_ASSERT_EQUAL( L"letter=\u00e9", s.BeforeFirst(';') ); + + CPPUNIT_ASSERT_EQUAL( L"letter=\u00e9;\u00e7a", s.BeforeLast('=') ); + CPPUNIT_ASSERT_EQUAL( "", s.BeforeLast('!') ); + CPPUNIT_ASSERT_EQUAL( L"letter=\u00e9", s.BeforeLast(';') ); + + CPPUNIT_ASSERT_EQUAL( L"\u00e9;\u00e7a=l\u00e0", s.AfterFirst('=') ); + CPPUNIT_ASSERT_EQUAL( "", s.AfterFirst('!') ); + CPPUNIT_ASSERT_EQUAL( L"\u00e7a=l\u00e0", s.AfterFirst(';') ); + + CPPUNIT_ASSERT_EQUAL( L"l\u00e0", s.AfterLast('=') ); + CPPUNIT_ASSERT_EQUAL( s, s.AfterLast('!') ); + CPPUNIT_ASSERT_EQUAL( L"\u00e7a=l\u00e0", s.AfterLast(';') ); +} +