Merge changes in Trunk.

[SVN r50499]
This commit is contained in:
John Maddock
2009-01-07 13:19:32 +00:00
parent 3b3a3ce6d1
commit e81f710567
116 changed files with 4794 additions and 4419 deletions

View File

@ -42,7 +42,8 @@ void basic_tests()
TEST_REGEX_SEARCH("()", perl, "zzz", match_default, make_array(0, 0, 0, 0, -2, 1, 1, 1, 1, -2, 2, 2, 2, 2, -2, 3, 3, 3, 3, -2, -2));
TEST_REGEX_SEARCH("()", perl, "", match_default, make_array(0, 0, 0, 0, -2, -2));
TEST_INVALID_REGEX("(", perl);
TEST_INVALID_REGEX("", perl);
TEST_INVALID_REGEX("", perl|no_empty_expressions);
TEST_REGEX_SEARCH("", perl, "abc", match_default, make_array(0, 0, -2, 1, 1, -2, 2, 2, -2, 3, 3, -2, -2));
TEST_INVALID_REGEX(")", perl);
TEST_INVALID_REGEX("(aa", perl);
TEST_INVALID_REGEX("aa)", perl);

View File

@ -33,38 +33,43 @@ int* get_array_data();
int error_count = 0;
#define RUN_TESTS(name) \
std::cout << "Running test case \"" #name "\".\n";\
name();
void run_tests()
{
basic_tests();
test_simple_repeats();
test_alt();
test_sets();
test_sets2();
test_anchors();
test_backrefs();
test_character_escapes();
test_assertion_escapes();
test_tricky_cases();
test_grep();
test_replace();
test_non_greedy_repeats();
test_non_marking_paren();
test_partial_match();
test_forward_lookahead_asserts();
test_fast_repeats();
test_fast_repeats2();
test_independent_subs();
test_nosubs();
test_conditionals();
test_options();
test_options2();
RUN_TESTS(basic_tests);
RUN_TESTS(test_simple_repeats);
RUN_TESTS(test_alt);
RUN_TESTS(test_sets);
RUN_TESTS(test_sets2);
RUN_TESTS(test_anchors);
RUN_TESTS(test_backrefs);
RUN_TESTS(test_character_escapes);
RUN_TESTS(test_assertion_escapes);
RUN_TESTS(test_tricky_cases);
RUN_TESTS(test_grep);
RUN_TESTS(test_replace);
RUN_TESTS(test_non_greedy_repeats);
RUN_TESTS(test_non_marking_paren);
RUN_TESTS(test_partial_match);
RUN_TESTS(test_forward_lookahead_asserts);
RUN_TESTS(test_fast_repeats);
RUN_TESTS(test_fast_repeats2);
RUN_TESTS(test_independent_subs);
RUN_TESTS(test_nosubs);
RUN_TESTS(test_conditionals);
RUN_TESTS(test_options);
RUN_TESTS(test_options2);
#ifndef TEST_THREADS
test_en_locale();
RUN_TESTS(test_en_locale);
#endif
test_emacs();
test_operators();
test_overloads();
test_unicode();
RUN_TESTS(test_emacs);
RUN_TESTS(test_operators);
RUN_TESTS(test_overloads);
RUN_TESTS(test_unicode);
}
int cpp_main(int /*argc*/, char * /*argv*/[])

View File

@ -29,11 +29,16 @@ void test_alt()
TEST_REGEX_SEARCH("a(b|c)", perl, "ad", match_default, make_array(-2, -2));
TEST_REGEX_SEARCH("(a|b|c)", perl, "c", match_default, make_array(0, 1, 0, 1, -2, -2));
TEST_REGEX_SEARCH("(a|(b)|.)", perl, "b", match_default, make_array(0, 1, 0, 1, 0, 1, -2, -2));
TEST_INVALID_REGEX("|c", perl);
TEST_INVALID_REGEX("c|", perl);
TEST_INVALID_REGEX("(|)", perl);
TEST_INVALID_REGEX("(a|)", perl);
TEST_INVALID_REGEX("(|a)", perl);
TEST_INVALID_REGEX("|c", perl|no_empty_expressions);
TEST_REGEX_SEARCH("|c", perl, " c", match_default, make_array(0, 0, -2, 1, 1, -2, 1, 2, -2, 2, 2, -2, -2));
TEST_INVALID_REGEX("c|", perl|no_empty_expressions);
TEST_REGEX_SEARCH("c|", perl, " c", match_default, make_array(0, 0, -2, 1, 2, -2, 2, 2, -2, -2));
TEST_INVALID_REGEX("(|)", perl|no_empty_expressions);
TEST_REGEX_SEARCH("(|)", perl, " c", match_default, make_array(0, 0, 0, 0, -2, 1, 1, 1, 1, -2, 2, 2, 2, 2, -2, -2));
TEST_INVALID_REGEX("(a|)", perl|no_empty_expressions);
TEST_REGEX_SEARCH("(a|)", perl, " a", match_default, make_array(0, 0, 0, 0, -2, 1, 2, 1, 2, -2, 2, 2, 2, 2, -2, -2));
TEST_INVALID_REGEX("(|a)", perl|no_empty_expressions);
TEST_REGEX_SEARCH("(|a)", perl, " a", match_default, make_array(0, 0, 0, 0, -2, 1, 1, 1, 1, -2, 1, 2, 1, 2, -2, 2, 2, 2, 2, -2, -2));
TEST_REGEX_SEARCH("a\\|", perl, "a|", match_default, make_array(0, 2, -2, -2));
TEST_REGEX_SEARCH("a|", basic, "a|", match_default, make_array(0, 2, -2, -2));

View File

@ -38,7 +38,7 @@ int get_posix_compile_options(boost::regex_constants::syntax_option_type opts)
{
case regbase::perl:
result = (opts & regbase::no_perl_ex) ? REG_EXTENDED : REG_PERL;
if(opts & (regbase::no_bk_refs|regbase::no_mod_m|regbase::mod_x|regbase::mod_s|regbase::no_mod_s|regbase::no_escape_in_lists))
if(opts & (regbase::no_bk_refs|regbase::no_mod_m|regbase::mod_x|regbase::mod_s|regbase::no_mod_s|regbase::no_escape_in_lists|regbase::no_empty_expressions))
return -1;
break;
case regbase::basic:

View File

@ -471,6 +471,38 @@ void test(boost::basic_regex<charT, traits>& r, const test_regex_search_tag&)
test_regex_token_iterator(r);
test_regex_grep(r);
test_regex_match(r);
//
// Verify sub-expression locations:
//
if((syntax_options & boost::regbase::save_subexpression_location) == 0)
{
bool have_except = false;
try
{
r.subexpression(1);
}
catch(const std::out_of_range&)
{
have_except = true;
}
if(!have_except)
{
BOOST_REGEX_TEST_ERROR("Expected std::out_of_range error was not found.", charT);
}
}
r.assign(expression, syntax_options | boost::regbase::save_subexpression_location);
for(std::size_t i = 1; i < r.mark_count(); ++i)
{
std::pair<const charT*, const charT*> p = r.subexpression(i);
if(*p.first != '(')
{
BOOST_REGEX_TEST_ERROR("Starting location of sub-expression " << i << " iterator was invalid.", charT);
}
if(*p.second != ')')
{
BOOST_REGEX_TEST_ERROR("Ending location of sub-expression " << i << " iterator was invalid.", charT);
}
}
}
catch(const boost::bad_expression& e)
{

View File

@ -116,5 +116,15 @@ void test_replace()
TEST_REGEX_REPLACE("x", literal|icase, "xx", match_default|format_all, "a", "aa");
// literals:
TEST_REGEX_REPLACE("(a(c)?)|(b)", perl, "acab", match_default|format_literal, "\\&$", "\\&$\\&$\\&$");
// Bracketed sub expressions:
TEST_REGEX_REPLACE("a+", perl, "...aaa,,,", match_default, "$", "...$,,,");
TEST_REGEX_REPLACE("a+", perl, "...aaa,,,", match_default, "${", "...${,,,");
TEST_REGEX_REPLACE("a+", perl, "...aaa,,,", match_default, "${2", "...${2,,,");
TEST_REGEX_REPLACE("a+", perl, "...aaa,,,", match_default, "${23", "...${23,,,");
TEST_REGEX_REPLACE("a+", perl, "...aaa,,,", match_default, "${d}", "...${d},,,");
TEST_REGEX_REPLACE("(a+)", perl, "...aaa,,,", match_default, "/${1}/", ".../aaa/,,,");
TEST_REGEX_REPLACE("(a+)", perl, "...aaa,,,", match_default, "/${10}/", "...//,,,");
TEST_REGEX_REPLACE("((((((((((a+))))))))))", perl, "...aaa,,,", match_default, "/${10}/", ".../aaa/,,,");
TEST_REGEX_REPLACE("(a+)", perl, "...aaa,,,", match_default, "/${1}0/", ".../aaa0/,,,");
}