Update of /cvsroot/boost/boost/libs/xpressive/test
In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv29334/libs/xpressive/test
Modified Files:
test_dynamic_grammar.cpp
Log Message:
use regex_compiler::operator[] to register named regexes, so a dynamic regex
can invoke a static one
Index: test_dynamic_grammar.cpp
===================================================================
RCS file: /cvsroot/boost/boost/libs/xpressive/test/test_dynamic_grammar.cpp,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- test_dynamic_grammar.cpp 5 Mar 2007 20:45:53 -0000 1.1
+++ test_dynamic_grammar.cpp 13 Mar 2007 06:41:51 -0000 1.2
@@ -25,13 +25,13 @@
{
sregex expr;
{
- sregex_compiler compiler;
- regex_constants::syntax_option_type x =
regex_constants::ignore_white_space;
+ sregex_compiler compiler;
+ regex_constants::syntax_option_type x =
regex_constants::ignore_white_space;
- compiler.compile( "(? $group = ) \\( (? $expr ) \\) ", x);
- compiler.compile( "(? $factor = ) \\d+ | (? $group ) ", x);
- compiler.compile( "(? $term = ) (? $factor ) (?: \\* (?
$factor ) | / (? $factor ) )* ", x);
- expr = compiler.compile( "(? $expr = ) (? $term ) (?: \\+ (?
$term ) | - (? $term ) )* ", x);
+ compiler.compile( "(? $group = ) \\( (? $expr ) \\) ", x);
+ compiler.compile( "(? $factor = ) \\d+ | (? $group ) ", x);
+ compiler.compile( "(? $term = ) (? $factor ) (?: \\* (?
$factor ) | / (? $factor ) )* ", x);
+ expr = compiler.compile( "(? $expr = ) (? $term ) (?: \\+ (?
$term ) | - (? $term ) )* ", x);
}
std::string str("foo 9*(10+3) bar");
@@ -54,6 +54,44 @@
BOOST_CHECK_EQUAL(0,
detail::regex_impl<std::string::const_iterator>::instances);
}
+void test_dynamic_grammar2()
+{
+ using namespace boost::xpressive;
+
+ {
+ sregex expr;
+ {
+ sregex_compiler compiler;
+ regex_constants::syntax_option_type x =
regex_constants::ignore_white_space;
+
+ compiler["group"] = compiler.compile( "\\( (? $expr ) \\) ", x);
+ compiler["factor"] = compiler.compile( "\\d+ | (? $group ) ", x);
+ compiler["term"] = compiler.compile( "(? $factor ) (?: \\* (?
$factor ) | / (? $factor ) )* ", x);
+ compiler["expr"] = compiler.compile( "(? $term ) (?: \\+ (?
$term ) | - (? $term ) )* ", x);
+
+ expr = compiler["expr"];
+ }
+
+ std::string str("foo 9*(10+3) bar");
+ smatch what;
+
+ if(regex_search(str, what, expr))
+ {
+ BOOST_CHECK_EQUAL(what[0].str(), "9*(10+3)");
+ BOOST_CHECK_EQUAL((*what.nested_results().begin())[0].str(),
"9*(10+3)");
+
BOOST_CHECK_EQUAL((*(*what.nested_results().begin()).nested_results().begin())[0].str(),
"9");
+
BOOST_CHECK_EQUAL((*++(*what.nested_results().begin()).nested_results().begin())[0].str(),
"(10+3)");
+ }
+ else
+ {
+ BOOST_ERROR("regex_search test 2 failed");
+ }
+ }
+
+ // Test that all regex_impl instances have been cleaned up correctly
+ BOOST_CHECK_EQUAL(0,
detail::regex_impl<std::string::const_iterator>::instances);
+}
+
using namespace boost;
using namespace unit_test;
@@ -64,5 +102,6 @@
{
test_suite *test = BOOST_TEST_SUITE("testing dynamic grammars");
test->add(BOOST_TEST_CASE(&test_dynamic_grammar));
+ test->add(BOOST_TEST_CASE(&test_dynamic_grammar2));
return test;
}
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Boost-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/boost-cvs