|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r71631 - in trunk/libs/spirit/test: . qi
From: hartmut.kaiser_at_[hidden]
Date: 2011-04-30 13:34:31
Author: hkaiser
Date: 2011-04-30 13:34:30 EDT (Sat, 30 Apr 2011)
New Revision: 71631
URL: http://svn.boost.org/trac/boost/changeset/71631
Log:
Spirit: fixing an issue in Qi with adapted ADTs, added test
Added:
trunk/libs/spirit/test/qi/regression_adapt_adt.cpp (contents, props changed)
Text files modified:
trunk/libs/spirit/test/Jamfile | 13 ++++++++-----
1 files changed, 8 insertions(+), 5 deletions(-)
Modified: trunk/libs/spirit/test/Jamfile
==============================================================================
--- trunk/libs/spirit/test/Jamfile (original)
+++ trunk/libs/spirit/test/Jamfile 2011-04-30 13:34:30 EDT (Sat, 30 Apr 2011)
@@ -144,10 +144,15 @@
###########################################################################
test-suite spirit_v2/qi_regressions :
+ [ compile qi/pass_container3.cpp : : qi_pass_container3 ]
[ compile qi/regression_attr_with_action.cpp : : qi_regression_attr_with_action ]
+ [ compile qi/regression_container_attribute.cpp : : qi_regression_container_attribute ]
[ compile qi/regression_debug_optional.cpp : : qi_regression_debug_optional ]
+ [ compile qi/regression_fusion_proto_spirit.cpp : : qi_regression_fusion_proto_spirit ]
[ compile qi/regression_one_element_fusion_sequence.cpp : : qi_regression_one_element_fusion_sequence ]
[ compile qi/regression_one_element_sequence_attribute.cpp : : qi_regression_one_element_sequence_attribute ]
+
+ [ run qi/regression_adapt_adt.cpp : : : : qi_regression_adapt_adt ]
[ run qi/regression_clear.cpp : : : : qi_regression_clear ]
#[ run qi/regression_float_fraction.cpp : : : : qi_regression_float_fraction ]
[ run qi/regression_lazy_repeat.cpp : : : : qi_regression_lazy_repeat ]
@@ -155,9 +160,6 @@
[ run qi/regression_reorder.cpp : : : : qi_regression_reorder ]
[ run qi/regression_repeat.cpp : : : : qi_regression_repeat ]
[ run qi/regression_transform_assignment.cpp : : : : qi_regression_transform_assignment ]
- [ compile qi/regression_fusion_proto_spirit.cpp : : qi_regression_fusion_proto_spirit ]
- [ compile qi/pass_container3.cpp : : qi_pass_container3 ]
- [ compile qi/regression_container_attribute.cpp : : qi_regression_container_attribute ]
;
###########################################################################
@@ -239,11 +241,12 @@
###########################################################################
test-suite spirit_v2/karma_regressions :
+ [ compile karma/regression_const_real_policies.cpp : : regression_const_real_policies ]
+
+ [ run karma/regression_adapt_adt.cpp : : : : karma_regression_adapt_adt ]
[ run karma/regression_optional_double.cpp : : : : karma_regression_optional_double ]
[ run karma/regression_semantic_action_attribute.cpp : : : : karma_regression_semantic_action_attribute ]
[ run karma/regression_real_scientific.cpp : : : : karma_regression_real_scientific ]
- [ compile karma/regression_const_real_policies.cpp : : regression_const_real_policies ]
- [ run karma/regression_adapt_adt.cpp : : : : karma_regression_adapt_adt ]
;
Added: trunk/libs/spirit/test/qi/regression_adapt_adt.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/spirit/test/qi/regression_adapt_adt.cpp 2011-04-30 13:34:30 EDT (Sat, 30 Apr 2011)
@@ -0,0 +1,57 @@
+// Copyright (c) 2011 Roji Philip
+// Copyright (c) 2001-2011 Hartmut Kaiser
+//
+// 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 <boost/config/warning_disable.hpp>
+#include <boost/detail/lightweight_test.hpp>
+
+#include <boost/fusion/include/adapt_adt.hpp>
+#include <boost/optional.hpp>
+
+#include <boost/spirit/include/qi.hpp>
+#include <boost/spirit/include/support_adapt_adt_attributes.hpp>
+
+#include "test.hpp"
+
+///////////////////////////////////////////////////////////////////////////////
+struct test
+{
+ unsigned var;
+ boost::optional<unsigned> opt;
+
+ unsigned const& getvar() const { return var; }
+ void setvar(unsigned val) { var = val; }
+
+ boost::optional<unsigned> const& getopt() const { return opt; }
+ void setopt(boost::optional<unsigned> const& val) { opt = val; }
+};
+
+BOOST_FUSION_ADAPT_ADT(
+ test,
+ (unsigned const&, unsigned const&, obj.getvar(), obj.setvar(val) )
+ (boost::optional<unsigned> const&, boost::optional<unsigned> const&,
+ obj.getopt(), obj.setopt(val) )
+)
+
+///////////////////////////////////////////////////////////////////////////////
+int main()
+{
+ using spirit_test::test_attr;
+ namespace qi = boost::spirit::qi;
+
+ {
+ test data;
+ BOOST_TEST(test_attr("123_at_999", qi::uint_ >> -('@' >> qi::uint_), data) &&
+ data.var == 123 && data.opt && data.opt.get() == 999);
+ }
+
+ {
+ test data;
+ BOOST_TEST(test_attr("123", qi::uint_ >> -('@' >> qi::uint_), data) &&
+ data.var == 123 && !data.opt);
+ }
+
+ 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