• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*=============================================================================
2     Copyright (c) 2001-2011 Hartmut Kaiser
3     Copyright (c) 2001-2011 Joel de Guzman
4 
5     Distributed under the Boost Software License, Version 1.0. (See accompanying
6     file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
7 =============================================================================*/
8 #include <boost/detail/lightweight_test.hpp>
9 #include <boost/spirit/include/qi_char.hpp>
10 #include <boost/spirit/include/qi_auxiliary.hpp>
11 #include <boost/spirit/include/qi_numeric.hpp>
12 #include <boost/spirit/include/qi_operator.hpp>
13 #include <boost/spirit/include/support_argument.hpp>
14 #include <boost/spirit/include/phoenix_core.hpp>
15 #include <boost/spirit/include/phoenix_operator.hpp>
16 #include <boost/fusion/include/std_pair.hpp>
17 
18 #include <iostream>
19 #include "test.hpp"
20 
21 int
main()22 main()
23 {
24     using spirit_test::test_attr;
25     namespace qi = boost::spirit::qi;
26 
27     using qi::attr;
28     using qi::double_;
29 
30     {
31         double d = 0.0;
32         BOOST_TEST(test_attr("", attr(1.0), d) && d == 1.0);
33 
34         double d1 = 1.0;
35         BOOST_TEST(test_attr("", attr(d1), d) && d == 1.0);
36 
37         std::pair<double, double> p;
38         BOOST_TEST(test_attr("1.0", double_ >> attr(1.0), p) &&
39             p.first == 1.0 && p.second == 1.0);
40 
41         char c = '\0';
42         BOOST_TEST(test_attr("", attr('a'), c) && c == 'a');
43         std::string str;
44         BOOST_TEST(test_attr("", attr("test"), str) && str == "test");
45     }
46 
47     {   // testing lazy constructs
48         using boost::phoenix::val;
49         using boost::phoenix::ref;
50 
51         double d = 0.0;
52         BOOST_TEST(test_attr("", attr(val(1.0)), d) && d == 1.0);
53 
54         double d1 = 2.0;
55         BOOST_TEST(test_attr("", attr(ref(d1)), d) && d == 2.0);
56     }
57 
58     {
59         std::string s;
60         BOOST_TEST(test_attr("s", "s" >> qi::attr(std::string("123")), s) &&
61             s == "123");
62     }
63 
64     return boost::report_errors();
65 }
66