Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r56580 - in trunk/libs/spirit/test: karma qi
From: hartmut.kaiser_at_[hidden]
Date: 2009-10-04 16:38:33


Author: hkaiser
Date: 2009-10-04 16:38:32 EDT (Sun, 04 Oct 2009)
New Revision: 56580
URL: http://svn.boost.org/trac/boost/changeset/56580

Log:
Spirit: rule's have intrinsic attribute transformation now, added more tests
Text files modified:
   trunk/libs/spirit/test/karma/attribute.cpp | 36 ++++++++++++++++++++++++++++++------
   trunk/libs/spirit/test/qi/attribute.cpp | 40 ++++++++++++++++++++++++++++++++--------
   2 files changed, 62 insertions(+), 14 deletions(-)

Modified: trunk/libs/spirit/test/karma/attribute.cpp
==============================================================================
--- trunk/libs/spirit/test/karma/attribute.cpp (original)
+++ trunk/libs/spirit/test/karma/attribute.cpp 2009-10-04 16:38:32 EDT (Sun, 04 Oct 2009)
@@ -101,10 +101,8 @@
         v.push_back(d1);
         v.push_back(d2);
 
- karma::rule<output_iterator<char>::type, test_data()> r =
- karma::attr_cast<test_data, test_view>(
- karma::string << karma::string << karma::double_
- );
+ karma::rule<output_iterator<char>::type, test_view()> r =
+ karma::string << karma::string << karma::double_;
 
         BOOST_TEST(test("s11s122.5\ns21s223.4", r % karma::eol, v));
         BOOST_TEST(test_delimited("s11s122.5\n s21s223.4",
@@ -122,7 +120,7 @@
         test_int_data1 d[] = {{ 1 }, { 2 }};
         std::vector<test_int_data1> v;
         v.push_back(d[0]);
- v.push_back(d[1] );
+ v.push_back(d[1]);
 
         BOOST_TEST(test("1,2", karma::attr_cast(karma::int_) % ',', v));
         BOOST_TEST(test("1,2"
@@ -135,6 +133,16 @@
         test_int_data1 d[] = {{ 1 }, { 2 }};
         std::vector<test_int_data1> v;
         v.push_back(d[0]);
+ v.push_back(d[1]);
+
+ karma::rule<output_iterator<char>::type, int()> r = karma::int_;
+ BOOST_TEST(test("1,2", r % ',', v));
+ }
+
+ {
+ test_int_data1 d[] = {{ 1 }, { 2 }};
+ std::vector<test_int_data1> v;
+ v.push_back(d[0]);
         v.push_back(d[1] );
 
 // this won't compile as there is no defined transformation for
@@ -145,6 +153,9 @@
 
         BOOST_TEST(test("1.0,2.0"
           , karma::attr_cast<test_int_data1, int>(karma::double_) % ',', v));
+
+ karma::rule<output_iterator<char>::type, int()> r = karma::double_;
+ BOOST_TEST(test("1.0,2.0", r % ',', v));
     }
 
     {
@@ -158,7 +169,7 @@
         test_int_data2 d[] = {{ 1 }, { 2 }};
         std::vector<test_int_data2> v;
         v.push_back(d[0]);
- v.push_back(d[1] );
+ v.push_back(d[1]);
 
         BOOST_TEST(test("1,2", karma::attr_cast(karma::int_) % ',', v));
         BOOST_TEST(test("1,2"
@@ -171,6 +182,16 @@
         test_int_data2 d[] = {{ 1 }, { 2 }};
         std::vector<test_int_data2> v;
         v.push_back(d[0]);
+ v.push_back(d[1]);
+
+ karma::rule<output_iterator<char>::type, int()> r = karma::int_;
+ BOOST_TEST(test("1,2", r % ',', v));
+ }
+
+ {
+ test_int_data2 d[] = {{ 1 }, { 2 }};
+ std::vector<test_int_data2> v;
+ v.push_back(d[0]);
         v.push_back(d[1] );
 
 // this won't compile as there is no defined transformation for
@@ -181,6 +202,9 @@
 
         BOOST_TEST(test("1.0,2.0"
           , karma::attr_cast<test_int_data2, int>(karma::double_) % ',', v));
+
+ karma::rule<output_iterator<char>::type, int()> r = karma::double_;
+ BOOST_TEST(test("1.0,2.0", r % ',', v));
     }
 
     return boost::report_errors();

Modified: trunk/libs/spirit/test/qi/attribute.cpp
==============================================================================
--- trunk/libs/spirit/test/qi/attribute.cpp (original)
+++ trunk/libs/spirit/test/qi/attribute.cpp 2009-10-04 16:38:32 EDT (Sun, 04 Oct 2009)
@@ -123,20 +123,16 @@
             test_view;
         std::vector<test_data> v;
 
- qi::rule<char const*, test_data()> r1 =
- qi::attr_cast<test_data, test_view>(
- *(qi::char_ - ',') >> ',' >> qi::int_ >> ',' >> qi::double_
- );
+ qi::rule<char const*, test_view()> r1 =
+ *(qi::char_ - ',') >> ',' >> qi::int_ >> ',' >> qi::double_;
 
         BOOST_TEST(test_attr("s1,2,1.5\ns2,4,3.5", r1 % qi::eol, v));
         BOOST_TEST(v.size() == 2 &&
             v[0].i1 == 2 && v[0].s1 == "s1" && v[0].d1 == 1.5 &&
             v[1].i1 == 4 && v[1].s1 == "s2" && v[1].d1 == 3.5);
 
- qi::rule<char const*, test_data(), qi::blank_type> r2 =
- qi::attr_cast<test_data, test_view>(
- *(qi::char_ - ',') >> ',' >> qi::int_ >> ',' >> qi::double_
- );
+ qi::rule<char const*, test_view(), qi::blank_type> r2 =
+ *(qi::char_ - ',') >> ',' >> qi::int_ >> ',' >> qi::double_;
 
         v.clear();
         BOOST_TEST(test_attr("s1, 2, 1.5 \n s2, 4, 3.5", r2 % qi::eol, v, qi::blank));
@@ -175,6 +171,14 @@
 
     {
         std::vector<test_int_data1> v;
+ qi::rule<char const*, int()> r = qi::int_;
+
+ BOOST_TEST(test_attr("1,2", r % ',', v));
+ BOOST_TEST(v.size() == 2 && v[0].i == 1 && v[1].i == 2);
+ }
+
+ {
+ std::vector<test_int_data1> v;
 
 // this won't compile as there is no defined transformation for
 // test_int_data1 and double
@@ -185,6 +189,12 @@
         BOOST_TEST(test_attr("1.0,2.2"
           , qi::attr_cast<test_int_data1, int>(qi::double_) % ',', v));
         BOOST_TEST(v.size() == 2 && v[0].i == 1 && v[1].i == 2);
+
+ qi::rule<char const*, int()> r = qi::double_;
+
+ v.clear();
+ BOOST_TEST(test_attr("1.0,2.0", r % ',', v));
+ BOOST_TEST(v.size() == 2 && v[0].i == 1 && v[1].i == 2);
     }
 
     // testing explicit transformation if attribute is taken by reference
@@ -217,6 +227,14 @@
 
     {
         std::vector<test_int_data2> v;
+ qi::rule<char const*, int()> r = qi::int_;
+
+ BOOST_TEST(test_attr("1,2", r % ',', v));
+ BOOST_TEST(v.size() == 2 && v[0].i == 1 && v[1].i == 2);
+ }
+
+ {
+ std::vector<test_int_data2> v;
 
 // this won't compile as there is no defined transformation for
 // test_int_data2 and double
@@ -227,6 +245,12 @@
         BOOST_TEST(test_attr("1.0,2.2"
           , qi::attr_cast<test_int_data2, int>(qi::double_) % ',', v));
         BOOST_TEST(v.size() == 2 && v[0].i == 1 && v[1].i == 2);
+
+ qi::rule<char const*, int()> r = qi::double_;
+
+ v.clear();
+ BOOST_TEST(test_attr("1.0,2.0", r % ',', v));
+ BOOST_TEST(v.size() == 2 && v[0].i == 1 && v[1].i == 2);
     }
 
     return boost::report_errors();


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