forked from boostorg/regex
Added new experimental captures support.
[SVN r21243]
This commit is contained in:
23
test/Jamfile
23
test/Jamfile
@ -4,6 +4,7 @@ subproject libs/regex/test ;
|
||||
|
||||
# bring in the rules for testing
|
||||
import testing ;
|
||||
subinclude libs/regex/test/captures ;
|
||||
|
||||
#
|
||||
# this template defines the options common to
|
||||
@ -130,6 +131,24 @@ test-suite regex
|
||||
]
|
||||
[ compile concepts/wide_concept_check.cpp
|
||||
]
|
||||
|
||||
[ run
|
||||
# sources
|
||||
captures/captures_test.cpp
|
||||
<template>../build/regex-options
|
||||
# dependencies
|
||||
<lib>captures/boost_regex_extra
|
||||
<lib>../../test/build/boost_test_exec_monitor
|
||||
: # additional args
|
||||
: # test-files
|
||||
: # requirements
|
||||
<threading>multi
|
||||
<define>BOOST_REGEX_MATCH_EXTRA=1
|
||||
<define>BOOST_REGEX_NO_LIB=1
|
||||
: # test name
|
||||
captures_test
|
||||
]
|
||||
|
||||
;
|
||||
|
||||
|
||||
@ -139,3 +158,7 @@ test-suite regex
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
16
test/captures/Jamfile
Normal file
16
test/captures/Jamfile
Normal file
@ -0,0 +1,16 @@
|
||||
# copyright John Maddock 2003
|
||||
|
||||
subproject libs/regex/test/captures ;
|
||||
|
||||
EX_SOURCES = c_regex_traits c_regex_traits_common cpp_regex_traits
|
||||
cregex fileiter posix_api regex regex_debug
|
||||
regex_synch w32_regex_traits wide_posix_api instances winstances ;
|
||||
|
||||
lib boost_regex_extra : ../../src/$(EX_SOURCES).cpp <template>../../build/regex-options
|
||||
:
|
||||
<define>BOOST_REGEX_MATCH_EXTRA=1
|
||||
:
|
||||
;
|
||||
|
||||
|
||||
|
90
test/captures/captures_test.cpp
Normal file
90
test/captures/captures_test.cpp
Normal file
@ -0,0 +1,90 @@
|
||||
|
||||
#include <boost/regex.hpp>
|
||||
#include <boost/test/test_tools.hpp>
|
||||
#include <boost/array.hpp>
|
||||
|
||||
#define ARRAY_SIZE(x) (sizeof(x) / sizeof(x[0]))
|
||||
|
||||
template <class T>
|
||||
void test_captures(const std::string& regx, const std::string& text, T& expected)
|
||||
{
|
||||
boost::regex e(regx);
|
||||
boost::smatch what;
|
||||
if(boost::regex_match(text, what, e, boost::match_extra))
|
||||
{
|
||||
unsigned i, j;
|
||||
BOOST_TEST(what.size() == ARRAY_SIZE(expected));
|
||||
for(i = 0; i < what.size(); ++i)
|
||||
{
|
||||
BOOST_TEST(what.captures(i).size() <= ARRAY_SIZE(expected[i]));
|
||||
for(j = 0; j < what.captures(i).size(); ++j)
|
||||
{
|
||||
BOOST_TEST(what.captures(i)[j] == expected[i][j]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int test_main(int , char* [])
|
||||
{
|
||||
typedef const char* pchar;
|
||||
pchar e1[4][5] =
|
||||
{
|
||||
{ "aBBcccDDDDDeeeeeeee", },
|
||||
{ "a", "BB", "ccc", "DDDDD", "eeeeeeee", },
|
||||
{ "a", "ccc", "eeeeeeee", },
|
||||
{ "BB", "DDDDD", },
|
||||
};
|
||||
test_captures("(([[:lower:]]+)|([[:upper:]]+))+", "aBBcccDDDDDeeeeeeee", e1);
|
||||
pchar e2[4][2] =
|
||||
{
|
||||
{ "abd" },
|
||||
{ "b", "" },
|
||||
{ "" },
|
||||
};
|
||||
test_captures("a(b+|((c)*))+d", "abd", e2);
|
||||
pchar e3[3][1] =
|
||||
{
|
||||
{ "abcbar" },
|
||||
{ "abc" },
|
||||
};
|
||||
test_captures("(.*)bar|(.*)bah", "abcbar", e3);
|
||||
pchar e4[3][1] =
|
||||
{
|
||||
{ "abcbah" },
|
||||
{ 0, },
|
||||
{ "abc" },
|
||||
};
|
||||
test_captures("(.*)bar|(.*)bah", "abcbah", e4);
|
||||
pchar e5[2][16] =
|
||||
{
|
||||
{ "now is the time for all good men to come to the aid of the party" },
|
||||
{ "now", "is", "the", "time", "for", "all", "good", "men", "to", "come", "to", "the", "aid", "of", "the", "party" },
|
||||
};
|
||||
test_captures("^(?:(\\w+)|(?>\\W+))*$", "now is the time for all good men to come to the aid of the party", e5);
|
||||
pchar e6[2][16] =
|
||||
{
|
||||
{ "now is the time for all good men to come to the aid of the party" },
|
||||
{ "now", "is", "the", "time", "for", "all", "good", "men", "to", "come", "to", "the", "aid", "of", "the", "party" },
|
||||
};
|
||||
test_captures("^(?>(\\w+)\\W*)*$", "now is the time for all good men to come to the aid of the party", e6);
|
||||
pchar e7[4][14] =
|
||||
{
|
||||
{ "now is the time for all good men to come to the aid of the party" },
|
||||
{ "now" },
|
||||
{ "is", "the", "time", "for", "all", "good", "men", "to", "come", "to", "the", "aid", "of", "the" },
|
||||
{ "party" },
|
||||
};
|
||||
test_captures("^(\\w+)\\W+(?>(\\w+)\\W+)*(\\w+)$", "now is the time for all good men to come to the aid of the party", e7);
|
||||
pchar e8[5][9] =
|
||||
{
|
||||
{ "now is the time for all good men to come to the aid of the party" } ,
|
||||
{ "now" },
|
||||
{ "is", "for", "men", "to", "of" },
|
||||
{ "the", "time", "all", "good", "to", "come", "the", "aid", "the" },
|
||||
{ "party" },
|
||||
};
|
||||
test_captures("^(\\w+)\\W+(?>(\\w+)\\W+(?:(\\w+)\\W+){0,2})*(\\w+)$", "now is the time for all good men to come to the aid of the party", e8);
|
||||
return 0;
|
||||
}
|
||||
|
@ -88,6 +88,7 @@ flag_info flag_data[] = {
|
||||
{ BOOST_RE_STR("match_continuous"), 16, match_continuous, 3 },
|
||||
{ BOOST_RE_STR("match_partial"), 13, match_partial, 3 },
|
||||
{ BOOST_RE_STR("match_nosubs"), 12, match_nosubs, 3 },
|
||||
{ BOOST_RE_STR("match_single_line"), 17, match_single_line, 3 },
|
||||
|
||||
{ BOOST_RE_STR("format_all"), 10, format_all, 3 },
|
||||
{ BOOST_RE_STR("format_sed"), 10, format_sed, 3 },
|
||||
|
@ -283,7 +283,7 @@ struct debug_iterator
|
||||
|
||||
debug_iterator(T c, T f, T l)
|
||||
: cur(c), first(f), last(l) {}
|
||||
debug_iterator() : cur(), first(), last() {}
|
||||
debug_iterator(int = 0) : cur(), first(), last() {}
|
||||
debug_iterator(const debug_iterator& x)
|
||||
: cur(x.cur), first(x.first), last(x.last) {}
|
||||
debug_iterator& operator=(const debug_iterator& x)
|
||||
|
@ -292,6 +292,22 @@ ab$ ab -1 -1
|
||||
ab$ abxx -1 -1
|
||||
ab$ ab\nzz 0 2
|
||||
|
||||
; line anchors, single line mode
|
||||
- match_default normal match_single_line REG_NO_POSIX_TEST
|
||||
^ab ab 0 2
|
||||
^ab xxabxx -1 -1
|
||||
^ab xx\nabzz -1 -1
|
||||
ab$ ab 0 2
|
||||
ab$ abxx -1 -1
|
||||
ab$ ab\nzz -1 -1
|
||||
- match_default match_not_bol match_not_eol normal REG_NO_POSIX_TEST match_single_line
|
||||
^ab ab -1 -1
|
||||
^ab xxabxx -1 -1
|
||||
^ab xx\nabzz -1 -1
|
||||
ab$ ab -1 -1
|
||||
ab$ abxx -1 -1
|
||||
ab$ ab\nzz -1 -1
|
||||
|
||||
; back references
|
||||
- match_default normal REG_PERL
|
||||
a(b)\2c !
|
||||
|
Reference in New Issue
Block a user