|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r61308 - in trunk/libs/spirit/test: karma qi
From: hartmut.kaiser_at_[hidden]
Date: 2010-04-15 22:48:13
Author: hkaiser
Date: 2010-04-15 22:48:12 EDT (Thu, 15 Apr 2010)
New Revision: 61308
URL: http://svn.boost.org/trac/boost/changeset/61308
Log:
Spirit: added more tests
Text files modified:
trunk/libs/spirit/test/karma/sequence.cpp | 12 +++++++
trunk/libs/spirit/test/karma/symbols.cpp | 62 ++++++++++++++++++++++++++++++++++++++++
trunk/libs/spirit/test/qi/sequence.cpp | 7 ++++
3 files changed, 81 insertions(+), 0 deletions(-)
Modified: trunk/libs/spirit/test/karma/sequence.cpp
==============================================================================
--- trunk/libs/spirit/test/karma/sequence.cpp (original)
+++ trunk/libs/spirit/test/karma/sequence.cpp 2010-04-15 22:48:12 EDT (Thu, 15 Apr 2010)
@@ -52,6 +52,18 @@
}
{
+ // a single element
+ char attr = 'a';
+ BOOST_TEST((test("ab", char_ << 'b', attr)));
+ }
+
+ {
+ // a single element fusion sequence
+ fusion::vector<char> attr = 'a';
+ BOOST_TEST((test("ab", char_ << 'b', attr)));
+ }
+
+ {
fusion::vector<char, char, std::string> p ('a', 'b', "cdefg");
BOOST_TEST(test("abcdefg", char_ << char_ << string, p));
BOOST_TEST(test_delimited("a b cdefg ",
Modified: trunk/libs/spirit/test/karma/symbols.cpp
==============================================================================
--- trunk/libs/spirit/test/karma/symbols.cpp (original)
+++ trunk/libs/spirit/test/karma/symbols.cpp 2010-04-15 22:48:12 EDT (Thu, 15 Apr 2010)
@@ -18,6 +18,16 @@
namespace fusion = boost::fusion;
+template <typename T>
+inline std::vector<T>
+make_vector(T const& t1, T const& t2)
+{
+ std::vector<T> v;
+ v.push_back(t1);
+ v.push_back(t2);
+ return v;
+}
+
int main()
{
using spirit_test::test;
@@ -175,6 +185,58 @@
BOOST_TEST((!test("", sym, 'h')));
}
+ { // more advanced
+ using boost::spirit::karma::rule;
+ using boost::spirit::karma::lit;
+ using boost::spirit::karma::char_;
+
+ typedef spirit_test::output_iterator<char>::type output_iterator_type;
+
+ symbols<char, rule<output_iterator_type, char()> > sym;
+ rule<output_iterator_type, char()> r1 = char_;
+
+ sym.add
+ ('j', r1.alias())
+ ('h', r1.alias())
+ ('t', r1.alias())
+ ('k', r1.alias())
+ ;
+
+ boost::mpl::true_ f =
+ boost::mpl::bool_<boost::spirit::traits::is_generator<
+ symbols<char, rule<output_iterator_type, char()> > >::value>();
+
+ // silence stupid compiler warnings
+ // i.e. MSVC warning C4189: 'f' : local variable is initialized but not referenced
+ BOOST_TEST((f.value));
+
+ BOOST_TEST((test("J", sym, make_vector('j', 'J'))));
+ BOOST_TEST((test("H", sym, make_vector('h', 'H'))));
+ BOOST_TEST((test("T", sym, make_vector('t', 'T'))));
+ BOOST_TEST((test("K", sym, make_vector('k', 'K'))));
+ BOOST_TEST((!test("", sym, 'x')));
+
+ // test copy
+ symbols<char, rule<output_iterator_type, char()> > sym2;
+ sym2 = sym;
+ BOOST_TEST((test("J", sym2, make_vector('j', 'J'))));
+ BOOST_TEST((test("H", sym2, make_vector('h', 'H'))));
+ BOOST_TEST((test("T", sym2, make_vector('t', 'T'))));
+ BOOST_TEST((test("K", sym2, make_vector('k', 'K'))));
+ BOOST_TEST((!test("", sym2, 'x')));
+
+ // make sure it plays well with other generators
+ BOOST_TEST((test("Jyo", sym << "yo", make_vector('j', 'J'))));
+
+ sym.remove
+ ('j')
+ ('h')
+ ;
+
+ BOOST_TEST((!test("", sym, 'j')));
+ BOOST_TEST((!test("", sym, 'h')));
+ }
+
{ // basics
symbols<std::string> sym;
Modified: trunk/libs/spirit/test/qi/sequence.cpp
==============================================================================
--- trunk/libs/spirit/test/qi/sequence.cpp (original)
+++ trunk/libs/spirit/test/qi/sequence.cpp 2010-04-15 22:48:12 EDT (Thu, 15 Apr 2010)
@@ -106,6 +106,13 @@
}
{
+ // a single element fusion sequence
+ vector<char> attr;
+ BOOST_TEST((test_attr("ab", char_ >> 'b', attr)));
+ BOOST_TEST((at_c<0>(attr) == 'a'));
+ }
+
+ {
// make sure single element tuples get passed through if the rhs
// has a single element tuple as its attribute
vector<double, int> fv;
Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk