forked from boostorg/regex
Almost complete implementation...
[SVN r22669]
This commit is contained in:
1 parent
50b5391c8f
commit
641d60b059
20 files changed
+1378
-592
No files matched your search
+568
-540
File diff suppressed because it is too large.
Load diff
@@ -14,6 +14,14 @@ int cpp_main(int argc, char * argv[])
|
||||
test_character_escapes();
|
||||
test_assertion_escapes();
|
||||
test_tricky_cases();
|
||||
test_tricky_cases2();
|
||||
test_grep();
|
||||
test_replace();
|
||||
test_non_greedy_repeats();
|
||||
test_non_marking_paren();
|
||||
test_partial_match();
|
||||
test_forward_lookahead_asserts();
|
||||
test_fast_repeats();
|
||||
return error_count;
|
||||
}
|
||||
|
||||
|
||||
+48
-1
@@ -4,6 +4,7 @@
|
||||
#define BOOST_REGEX_REGRESS_TEST_HPP
|
||||
#include "test_not_regex.hpp"
|
||||
#include "test_regex_search.hpp"
|
||||
#include "test_regex_replace.hpp"
|
||||
|
||||
|
||||
//
|
||||
@@ -81,6 +82,45 @@ const int* make_array(int first, ...);
|
||||
TEST_REGEX_SEARCH_N(s, f, t, m, a);\
|
||||
TEST_REGEX_SEARCH_W(BOOST_JOIN(L, s), f, BOOST_JOIN(L, t), m, a)
|
||||
|
||||
//
|
||||
// define macros for testing regex replaces:
|
||||
//
|
||||
#define TEST_REGEX_REPLACE_N(s, f, t, m, fs, r)\
|
||||
do{\
|
||||
const char e[] = { s };\
|
||||
std::string se(e, sizeof(e) - 1);\
|
||||
const char st[] = { t };\
|
||||
std::string sst(st, sizeof(st) - 1);\
|
||||
const char ft[] = { fs };\
|
||||
std::string sft(ft, sizeof(ft) - 1);\
|
||||
const char rt[] = { r };\
|
||||
std::string srt(rt, sizeof(rt) - 1);\
|
||||
test_info<char>::set_info(__FILE__, __LINE__, se, f, sst, m, 0, sft, srt);\
|
||||
test(char(0), test_regex_replace_tag());\
|
||||
}while(0)
|
||||
|
||||
#ifndef BOOST_NO_WREGEX
|
||||
#define TEST_REGEX_REPLACE_W(s, f, t, m, fs, r)\
|
||||
do{\
|
||||
const wchar_t e[] = { s };\
|
||||
std::wstring se(e, (sizeof(e) / sizeof(wchar_t)) - 1);\
|
||||
const wchar_t st[] = { t };\
|
||||
std::wstring sst(st, (sizeof(st) / sizeof(wchar_t)) - 1);\
|
||||
const wchar_t ft[] = { fs };\
|
||||
std::wstring sft(ft, (sizeof(ft) / sizeof(wchar_t)) - 1);\
|
||||
const wchar_t rt[] = { r };\
|
||||
std::wstring srt(rt, (sizeof(rt) / sizeof(wchar_t)) - 1);\
|
||||
test_info<wchar_t>::set_info(__FILE__, __LINE__, se, f, sst, m, 0, sft, srt);\
|
||||
test(wchar_t(0), test_regex_replace_tag());\
|
||||
}while(0)
|
||||
#else
|
||||
#define TEST_REGEX_REPLACE_W(s, f, t, m, fs, r)
|
||||
#endif
|
||||
|
||||
#define TEST_REGEX_REPLACE(s, f, t, m, fs, r)\
|
||||
TEST_REGEX_REPLACE_N(s, f, t, m, fs, r);\
|
||||
TEST_REGEX_REPLACE_W(BOOST_JOIN(L, s), f, BOOST_JOIN(L, t), m, BOOST_JOIN(L, fs), BOOST_JOIN(L, r))
|
||||
|
||||
//
|
||||
// define the test group proceedures:
|
||||
//
|
||||
@@ -92,6 +132,13 @@ void test_backrefs();
|
||||
void test_character_escapes();
|
||||
void test_assertion_escapes();
|
||||
void test_tricky_cases();
|
||||
|
||||
void test_grep();
|
||||
void test_replace();
|
||||
void test_non_greedy_repeats();
|
||||
void test_non_marking_paren();
|
||||
void test_partial_match();
|
||||
void test_forward_lookahead_asserts();
|
||||
void test_fast_repeats();
|
||||
void test_tricky_cases2();
|
||||
|
||||
#endif
|
||||
@@ -16,7 +16,10 @@ void test_sub_match(const boost::sub_match<BidirectionalIterator>& sub, Bidirect
|
||||
#pragma warning(disable:4244)
|
||||
#endif
|
||||
typedef typename boost::sub_match<BidirectionalIterator>::value_type charT;
|
||||
if(sub.matched == 0)
|
||||
if((sub.matched == 0)
|
||||
&&
|
||||
!((i == 0)
|
||||
&& (test_info<charT>::match_options() & boost::match_partial)) )
|
||||
{
|
||||
if(answer_table[2*i] >= 0)
|
||||
{
|
||||
@@ -80,6 +83,101 @@ void test_simple_search(boost::basic_regex<charT, traits>& r)
|
||||
}
|
||||
}
|
||||
|
||||
template<class charT, class traits>
|
||||
void test_regex_iterator(boost::basic_regex<charT, traits>& r)
|
||||
{
|
||||
typedef typename std::basic_string<charT>::const_iterator const_iterator;
|
||||
typedef boost::regex_iterator<const_iterator> test_iterator;
|
||||
const std::basic_string<charT>& search_text = test_info<charT>::search_text();
|
||||
boost::regex_constants::match_flag_type opts = test_info<charT>::match_options();
|
||||
const int* answer_table = test_info<charT>::answer_table();
|
||||
test_iterator start(search_text.begin(), search_text.end(), r, opts), end;
|
||||
while(start != end)
|
||||
{
|
||||
test_result(*start, search_text.begin(), answer_table);
|
||||
++start;
|
||||
// move on the answer table to next set of answers;
|
||||
while(*answer_table++ != -2){}
|
||||
}
|
||||
if(answer_table[0] >= 0)
|
||||
{
|
||||
// we should have had a match but didn't:
|
||||
BOOST_REGEX_TEST_ERROR("Expected match was not found.", charT);
|
||||
}
|
||||
}
|
||||
|
||||
template <class charT, class traits>
|
||||
struct grep_test_predicate
|
||||
{
|
||||
typedef typename std::basic_string<charT>::const_iterator test_iter;
|
||||
|
||||
grep_test_predicate(test_iter b, const int* a)
|
||||
: m_base(b), m_table(a)
|
||||
{}
|
||||
bool operator()(const boost::match_results<test_iter>& what)
|
||||
{
|
||||
test_result(what, m_base, m_table);
|
||||
// move on the answer table to next set of answers;
|
||||
while(*m_table++ != -2){}
|
||||
return true;
|
||||
}
|
||||
private:
|
||||
test_iter m_base;
|
||||
const int* m_table;
|
||||
};
|
||||
|
||||
template<class charT, class traits>
|
||||
void test_regex_grep(boost::basic_regex<charT, traits>& r)
|
||||
{
|
||||
typedef typename std::basic_string<charT>::const_iterator const_iterator;
|
||||
const std::basic_string<charT>& search_text = test_info<charT>::search_text();
|
||||
boost::regex_constants::match_flag_type opts = test_info<charT>::match_options();
|
||||
const int* answer_table = test_info<charT>::answer_table();
|
||||
grep_test_predicate<charT, traits> pred(search_text.begin(), answer_table);
|
||||
boost::regex_grep(pred, search_text, r, opts);
|
||||
}
|
||||
|
||||
template<class charT, class traits>
|
||||
void test_regex_match(boost::basic_regex<charT, traits>& r)
|
||||
{
|
||||
typedef typename std::basic_string<charT>::const_iterator const_iterator;
|
||||
const std::basic_string<charT>& search_text = test_info<charT>::search_text();
|
||||
boost::regex_constants::match_flag_type opts = test_info<charT>::match_options();
|
||||
const int* answer_table = test_info<charT>::answer_table();
|
||||
boost::match_results<const_iterator> what;
|
||||
if(answer_table[0] < 0)
|
||||
{
|
||||
if(boost::regex_match(search_text, r, opts))
|
||||
{
|
||||
BOOST_REGEX_TEST_ERROR("boost::regex_match found a match when it should not have done so.", charT);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if((answer_table[0] > 0) && boost::regex_match(search_text, r, opts))
|
||||
{
|
||||
BOOST_REGEX_TEST_ERROR("boost::regex_match found a match when it should not have done so.", charT);
|
||||
}
|
||||
else if((answer_table[0] == 0) && (answer_table[1] == search_text.size()))
|
||||
{
|
||||
if(boost::regex_match(
|
||||
search_text.begin(),
|
||||
search_text.end(),
|
||||
what,
|
||||
r,
|
||||
opts))
|
||||
{
|
||||
test_result(what, search_text.begin(), answer_table);
|
||||
}
|
||||
else if(answer_table[0] >= 0)
|
||||
{
|
||||
// we should have had a match but didn't:
|
||||
BOOST_REGEX_TEST_ERROR("Expected match was not found.", charT);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template<class charT, class traits>
|
||||
void test(boost::basic_regex<charT, traits>& r, const test_regex_search_tag&)
|
||||
{
|
||||
@@ -88,6 +186,9 @@ void test(boost::basic_regex<charT, traits>& r, const test_regex_search_tag&)
|
||||
try{
|
||||
r.assign(expression, syntax_options);
|
||||
test_simple_search(r);
|
||||
test_regex_iterator(r);
|
||||
test_regex_grep(r);
|
||||
test_regex_match(r);
|
||||
}
|
||||
catch(const boost::bad_expression& e)
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user