forked from boostorg/regex
Empty expressions, and empty alternatives are now
allowed when using the Perl regular expression syntax. This change has been added for Perl compatibility, when the new [syntax_option_type] ['no_empty_expressions] is set then the old behaviour is preserved and empty expressions are prohibited. This is issue [@https://svn.boost.org/trac/boost/ticket/1081 #1081]. Fixes #1081. [SVN r50374]
This commit is contained in:
@ -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);
|
||||
|
@ -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*/[])
|
||||
|
@ -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));
|
||||
|
@ -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:
|
||||
|
Reference in New Issue
Block a user