Update of /cvsroot/boost/boost/libs/xpressive/test
In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv27878

Modified Files:
        Jamfile.v2 
Added Files:
        test_dynamic_grammar.cpp 
Log Message:
add test for dynamic grammars

--- NEW FILE: test_dynamic_grammar.cpp ---
//////////////////////////////////////////////////////////////////////////////
// test_dynamic_grammar.cpp
//
//  (C) Copyright Eric Niebler 2004.
//  Use, modification and distribution are subject to the
//  Boost Software License, Version 1.0. (See accompanying file
//  LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

/*
 Revision history:
   5 March 2007 : Initial version.
*/

// defining this causes regex_impl objects to be counted, allowing us to detect
// leaks portably.
#define BOOST_XPRESSIVE_DEBUG_CYCLE_TEST

#include <boost/xpressive/xpressive.hpp>
#include <boost/test/unit_test.hpp>

void test_dynamic_grammar()
{
    using namespace boost::xpressive;

    {
        sregex expr;
        {
             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);
        }

        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 1 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;

///////////////////////////////////////////////////////////////////////////////
// init_unit_test_suite
//
test_suite* init_unit_test_suite( int argc, char* argv[] )
{
    test_suite *test = BOOST_TEST_SUITE("testing dynamic grammars");
    test->add(BOOST_TEST_CASE(&test_dynamic_grammar));
    return test;
}

Index: Jamfile.v2
===================================================================
RCS file: /cvsroot/boost/boost/libs/xpressive/test/Jamfile.v2,v
retrieving revision 1.25
retrieving revision 1.26
diff -u -d -r1.25 -r1.26
--- Jamfile.v2  12 Feb 2007 17:39:04 -0000      1.25
+++ Jamfile.v2  5 Mar 2007 20:45:53 -0000       1.26
@@ -49,6 +49,7 @@
          [ run test_non_char.cpp ]
          [ run test_static.cpp ]
          [ run test_dynamic.cpp ]
+         [ run test_dynamic_grammar.cpp ]
          [ link multiple_defs1.cpp multiple_defs2.cpp : : multiple_defs ]
          [ compile test_basic_regex.cpp ]
          [ compile test_match_results.cpp ]


-------------------------------------------------------------------------
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

Reply via email to