]> git.saurik.com Git - wxWidgets.git/blobdiff - tests/strings/tokenizer.cpp
don't test for __WIN95__ which doesn't exist any more; don't do compiler checks here...
[wxWidgets.git] / tests / strings / tokenizer.cpp
index 6205988e6a0de0281c0d6ba91a4332b6da749745..788177b9eb4bd3db0b633fea4e528105c367a4de 100644 (file)
@@ -36,11 +36,13 @@ private:
     CPPUNIT_TEST_SUITE( TokenizerTestCase );
         CPPUNIT_TEST( GetCount );
         CPPUNIT_TEST( GetPosition );
+        CPPUNIT_TEST( LastDelimiter );
         CPPUNIT_TEST( StrtokCompat );
     CPPUNIT_TEST_SUITE_END();
 
     void GetCount();
     void GetPosition();
+    void LastDelimiter();
     void StrtokCompat();
 
     DECLARE_NO_COPY_CLASS(TokenizerTestCase)
@@ -75,6 +77,13 @@ gs_testData[] =
     { _T(""),                   _T(" "),              wxTOKEN_DEFAULT,       0 },
     { _T(""),                   _T(" "),              wxTOKEN_RET_EMPTY,     0 },
     { _T(""),                   _T(" "),              wxTOKEN_RET_EMPTY_ALL, 0 },
+    { _T(""),                   _T(" "),              wxTOKEN_RET_DELIMS,    0 },
+    { _T(":"),                  _T(":"),              wxTOKEN_RET_EMPTY,     1 },
+    { _T(":"),                  _T(":"),              wxTOKEN_RET_DELIMS,    1 },
+    { _T(":"),                  _T(":"),              wxTOKEN_RET_EMPTY_ALL, 2 },
+    { _T("::"),                 _T(":"),              wxTOKEN_RET_EMPTY,     1 },
+    { _T("::"),                 _T(":"),              wxTOKEN_RET_DELIMS,    1 },
+    { _T("::"),                 _T(":"),              wxTOKEN_RET_EMPTY_ALL, 3 },
 
     { _T("Hello, world"),       _T(" "),              wxTOKEN_DEFAULT,       2 },
     { _T("Hello,   world  "),   _T(" "),              wxTOKEN_DEFAULT,       2 },
@@ -93,10 +102,10 @@ gs_testData[] =
     { _T("1:2::3:"),            _T(":"),              wxTOKEN_RET_DELIMS,    4 },
     { _T("1:2::3:"),            _T(":"),              wxTOKEN_STRTOK,        3 },
 
-    { _T("1:2::3::"),           _T(":"),              wxTOKEN_DEFAULT,       5 },
+    { _T("1:2::3::"),           _T(":"),              wxTOKEN_DEFAULT,       4 },
     { _T("1:2::3::"),           _T(":"),              wxTOKEN_RET_EMPTY,     4 },
     { _T("1:2::3::"),           _T(":"),              wxTOKEN_RET_EMPTY_ALL, 6 },
-    { _T("1:2::3::"),           _T(":"),              wxTOKEN_RET_DELIMS,    5 },
+    { _T("1:2::3::"),           _T(":"),              wxTOKEN_RET_DELIMS,    4 },
     { _T("1:2::3::"),           _T(":"),              wxTOKEN_STRTOK,        3 },
 
     { _T("1 \t3\t4  6   "),     wxDEFAULT_DELIMITERS, wxTOKEN_DEFAULT,       4 },
@@ -108,6 +117,13 @@ gs_testData[] =
     { _T("01-02/99"),           _T("/-"),             wxTOKEN_RET_DELIMS,    3 },
 };
 
+// helper function returning the string showing the index for which the test
+// fails in the diagnostic message
+static std::string Nth(size_t n)
+{
+    return wxString::Format(_T("for loop index %lu"), (unsigned long)n).mb_str();
+}
+
 // ----------------------------------------------------------------------------
 // the tests
 // ----------------------------------------------------------------------------
@@ -119,7 +135,7 @@ void TokenizerTestCase::GetCount()
         const TokenizerTestData& ttd = gs_testData[n];
 
         wxStringTokenizer tkz(ttd.str, ttd.delims, ttd.mode);
-        CPPUNIT_ASSERT_EQUAL( ttd.count, tkz.CountTokens() );
+        CPPUNIT_ASSERT_EQUAL_MESSAGE( Nth(n), ttd.count, tkz.CountTokens() );
 
         size_t count = 0;
         while ( tkz.HasMoreTokens() )
@@ -128,7 +144,7 @@ void TokenizerTestCase::GetCount()
             count++;
         }
 
-        CPPUNIT_ASSERT_EQUAL( ttd.count, count );
+        CPPUNIT_ASSERT_EQUAL_MESSAGE( Nth(n), ttd.count, count );
     }
 }
 
@@ -170,6 +186,23 @@ void TokenizerTestCase::GetPosition()
     DoTestGetPosition(_T("foo_bar_"), _T("_"), 4, 8, 0);
 }
 
+void TokenizerTestCase::LastDelimiter()
+{
+    wxStringTokenizer tkz(_T("a+-b=c"), _T("+-="));
+
+    tkz.GetNextToken();
+    CPPUNIT_ASSERT_EQUAL( _T('+'), tkz.GetLastDelimiter() );
+
+    tkz.GetNextToken();
+    CPPUNIT_ASSERT_EQUAL( _T('-'), tkz.GetLastDelimiter() );
+
+    tkz.GetNextToken();
+    CPPUNIT_ASSERT_EQUAL( _T('='), tkz.GetLastDelimiter() );
+
+    tkz.GetNextToken();
+    CPPUNIT_ASSERT_EQUAL( _T('\0'), tkz.GetLastDelimiter() );
+}
+
 void TokenizerTestCase::StrtokCompat()
 {
     for ( size_t n = 0; n < WXSIZEOF(gs_testData); n++ )