Update of /cvsroot/boost/boost/libs/xpressive/test
In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv4971
Modified Files:
Jamfile.v2
Added Files:
test_actions.cpp
Log Message:
add test for actions
--- NEW FILE: test_actions.cpp ---
///////////////////////////////////////////////////////////////////////////////
// test_actions.cpp
//
// Copyright 2004 Eric Niebler. Distributed under 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)
#include <map>
#include <list>
#include <numeric>
#include <boost/xpressive/xpressive_static.hpp>
#include <boost/xpressive/regex_actions.hpp>
#include <boost/test/unit_test.hpp>
///////////////////////////////////////////////////////////////////////////////
// test1
// simple action which builds a string
void test1()
{
using namespace boost::xpressive;
std::string result;
std::string str("foo bar baz foo bar baz");
sregex rx = (+_w)[ result += _ ] >> *(' ' >> (+_w)[ result += ',' + _ ]);
if(!regex_match(str, rx))
{
BOOST_ERROR("oops");
}
else
{
BOOST_CHECK_EQUAL(result, "foo,bar,baz,foo,bar,baz");
}
}
///////////////////////////////////////////////////////////////////////////////
// test2
// test backtracking over actions
void test2()
{
using namespace boost::xpressive;
std::string result;
std::string str("foo bar baz foo bar baz");
sregex rx = (+_w)[ result += _ ] >> *(' ' >> (+_w)[ result += ',' + _ ]) >>
repeat<4>(_);
if(!regex_match(str, rx))
{
BOOST_ERROR("oops");
}
else
{
BOOST_CHECK_EQUAL(result, "foo,bar,baz,foo,bar");
}
}
///////////////////////////////////////////////////////////////////////////////
// test3
// cast string to int, push back into list
void test3()
{
using namespace boost::xpressive;
std::list<int> result;
std::string str("1 23 456 7890");
sregex rx = (+_d)[ push_back( result, as<int>(_) ) ]
>> *(' ' >> (+_w)[ push_back( result, as<int>(_) ) ]);
if(!regex_match(str, rx))
{
BOOST_ERROR("oops");
}
else
{
BOOST_REQUIRE_EQUAL(result.size(), 4);
BOOST_CHECK_EQUAL(*result.begin(), 1);
BOOST_CHECK_EQUAL(*++result.begin(), 23);
BOOST_CHECK_EQUAL(*++++result.begin(), 456);
BOOST_CHECK_EQUAL(*++++++result.begin(), 7890);
}
}
///////////////////////////////////////////////////////////////////////////////
// test4
// build a map of strings to integers
void test4()
{
using namespace boost::xpressive;
std::map<std::string, int> result;
std::string str("aaa=>1 bbb=>23 ccc=>456");
sregex pair = ( (s1= +_w) >> "=>" >> (s2= +_d) )[ var(result)[s1] =
as<int>(s2) ];
sregex rx = pair >> *(+_s >> pair);
if(!regex_match(str, rx))
{
BOOST_ERROR("oops");
}
else
{
BOOST_REQUIRE_EQUAL(result.size(), 3);
BOOST_CHECK_EQUAL(result["aaa"], 1);
BOOST_CHECK_EQUAL(result["bbb"], 23);
BOOST_CHECK_EQUAL(result["ccc"], 456);
}
}
using namespace boost::unit_test;
///////////////////////////////////////////////////////////////////////////////
// init_unit_test_suite
//
test_suite* init_unit_test_suite( int argc, char* argv[] )
{
test_suite *test = BOOST_TEST_SUITE("test_actions");
test->add(BOOST_TEST_CASE(&test1));
test->add(BOOST_TEST_CASE(&test2));
test->add(BOOST_TEST_CASE(&test3));
test->add(BOOST_TEST_CASE(&test4));
return test;
}
Index: Jamfile.v2
===================================================================
RCS file: /cvsroot/boost/boost/libs/xpressive/test/Jamfile.v2,v
retrieving revision 1.28
retrieving revision 1.29
diff -u -d -r1.28 -r1.29
--- Jamfile.v2 18 Mar 2007 18:31:32 -0000 1.28
+++ Jamfile.v2 22 Mar 2007 19:40:18 -0000 1.29
@@ -48,6 +48,7 @@
[ run test_cycles.cpp ]
[ run test_non_char.cpp ]
[ run test_static.cpp ]
+ [ run test_actions.cpp ]
[ run test_dynamic.cpp ]
[ run test_dynamic_grammar.cpp ]
[ link multiple_defs1.cpp multiple_defs2.cpp : : multiple_defs ]
-------------------------------------------------------------------------
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