X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/e70833fb1dfa271e7b0c9dec11ad644880e03c6f..9f41fa227b8f3f0671d22216e2aa93c27840a597:/tests/regex/regex.cpp diff --git a/tests/regex/regex.cpp b/tests/regex/regex.cpp index 733e5aed69..f8097554d5 100644 --- a/tests/regex/regex.cpp +++ b/tests/regex/regex.cpp @@ -22,18 +22,13 @@ // test --verbose regex // // The tests here are for the builtin library, tests for wxRegEx in general -// should go in another module. +// should go in wxregex.cpp // // The tests are generated from Henry Spencer's reg.test, additional test // can be added in wxreg.test. These test files are then turned into a C++ // include file 'regex.inc' (included below) using a script 'regex.pl'. // -#if defined(__GNUG__) && !defined(__APPLE__) - #pragma implementation - #pragma interface -#endif - // For compilers that support precompilation, includes "wx/wx.h". #include "wx/wxprec.h" @@ -48,7 +43,6 @@ #include "wx/regex.h" #include "wx/cppunit.h" -#include #include using namespace std; @@ -85,7 +79,6 @@ private: wxString Conv(const char *str); void parseFlags(const wxString& flags); void doTest(int flavor); - static size_t matchCount(const wxString& expr, int flags); static wxString quote(const wxString& arg); const wxChar *convError() const { return _T(""); } @@ -225,24 +218,30 @@ void RegExTestCase::doTest(int flavor) wxRegEx re(m_pattern, m_compileFlags | flavor); // 'e' - test that the pattern fails to compile - if (m_mode == 'e') - return failIf(re.IsValid(), _T("compile suceeded (should fail)")); + if (m_mode == 'e') { + failIf(re.IsValid(), _T("compile succeeded (should fail)")); + return; + } failIf(!re.IsValid(), _T("compile failed")); bool matches = re.Matches(m_data, m_matchFlags); // 'f' or 'p' - test that the pattern does not match - if (m_mode == 'f' || m_mode == 'p') - return failIf(matches, _T("match suceeded (should fail)")); + if (m_mode == 'f' || m_mode == 'p') { + failIf(matches, _T("match succeeded (should fail)")); + return; + } // otherwise 'm' or 'i' - test the pattern does match failIf(!matches, _T("match failed")); - // Check that wxRegEx is going to allocate a large enough array for the - // results we are supposed to get - failIf(m_expected.size() > matchCount(m_pattern, m_compileFlags | flavor), - _T("wxRegEx has not allocated a large enough array for the ") - _T("number of results expected")); + if (m_compileFlags & wxRE_NOSUB) + return; + + // check wxRegEx has correctly counted the number of subexpressions + failIf(m_expected.size() != re.GetMatchCount(), + wxString::Format(_T("GetMatchCount() == %d, expected %d"), + re.GetMatchCount(), m_expected.size())); wxString result; size_t start, len; @@ -317,70 +316,18 @@ wxString RegExTestCase::quote(const wxString& arg) str : _T("\"") + str + _T("\""); } -// Count the number of subexpressions (taken from wxRegExImpl::Compile) -// -size_t RegExTestCase::matchCount(const wxString& expr, int flags) -{ - // there is always one for the whole expression - size_t nMatches = 1; - - // and some more for bracketed subexperessions - for ( const wxChar *cptr = expr; *cptr; cptr++ ) - { - if ( *cptr == _T('\\') ) - { - // in basic RE syntax groups are inside \(...\) - if ( *++cptr == _T('(') && (flags & wxRE_BASIC) ) - { - nMatches++; - } - } - else if ( *cptr == _T('(') && !(flags & wxRE_BASIC) ) - { - // we know that the previous character is not an unquoted - // backslash because it would have been eaten above, so we - // have a bar '(' and this indicates a group start for the - // extended syntax - nMatches++; - } - } - - return nMatches; -} - /////////////////////////////////////////////////////////////////////////////// // Test suite -// -// In a non-unicode build the regex is affected by the current locale, so -// this derived TestSuite is used. It sets the locale in it's run() method -// for the duration of the regex tests. class RegExTestSuite : public TestSuite { public: - RegExTestSuite(string name); - void run(TestResult *result); + RegExTestSuite(string name) : TestSuite(name) { } void add(const char *mode, const char *id, const char *flags, const char *pattern, const char *data, const char *expected, ...); }; -// constructor, sets the locale so that it is set when the tests are added -// -RegExTestSuite::RegExTestSuite(string name) : TestSuite(name) -{ - setlocale(LC_ALL, ""); -} - -// run the test suite, sets the locale again since it may have been changed -// by another test since this suite was crated -// -void RegExTestSuite::run(TestResult *result) -{ - setlocale(LC_ALL, ""); - TestSuite::run(result); -} - // Add a testcase to the suite // void RegExTestSuite::add(