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/spirit/include/qi_attr.hpp> |
9 | |
10 | #include <boost/spirit/include/qi_char.hpp> |
11 | #include <boost/spirit/include/qi_auxiliary.hpp> |
12 | #include <boost/spirit/include/qi_numeric.hpp> |
13 | #include <boost/spirit/include/qi_operator.hpp> |
14 | #include <boost/spirit/include/support_argument.hpp> |
15 | #include <boost/phoenix/core.hpp> |
16 | #include <boost/phoenix/operator.hpp> |
17 | #include <boost/fusion/include/std_pair.hpp> |
18 | |
19 | #include <iostream> |
20 | #include "test.hpp" |
21 | |
22 | int |
23 | main() |
24 | { |
25 | using spirit_test::test_attr; |
26 | namespace qi = boost::spirit::qi; |
27 | |
28 | using qi::attr; |
29 | using qi::double_; |
30 | |
31 | { |
32 | double d = 0.0; |
33 | BOOST_TEST(test_attr("" , attr(1.0), d) && d == 1.0); |
34 | |
35 | double d1 = 1.0; |
36 | BOOST_TEST(test_attr("" , attr(d1), d) && d == 1.0); |
37 | |
38 | std::pair<double, double> p; |
39 | BOOST_TEST(test_attr("1.0" , double_ >> attr(1.0), p) && |
40 | p.first == 1.0 && p.second == 1.0); |
41 | |
42 | char c = '\0'; |
43 | BOOST_TEST(test_attr("" , attr('a'), c) && c == 'a'); |
44 | std::string str; |
45 | BOOST_TEST(test_attr("" , attr("test" ), str) && str == "test" ); |
46 | } |
47 | |
48 | { // testing lazy constructs |
49 | using boost::phoenix::val; |
50 | using boost::phoenix::ref; |
51 | |
52 | double d = 0.0; |
53 | BOOST_TEST(test_attr("" , attr(val(1.0)), d) && d == 1.0); |
54 | |
55 | double d1 = 2.0; |
56 | BOOST_TEST(test_attr("" , attr(ref(d1)), d) && d == 2.0); |
57 | } |
58 | |
59 | { |
60 | std::string s; |
61 | BOOST_TEST(test_attr("s" , "s" >> qi::attr(std::string("123" )), s) && |
62 | s == "123" ); |
63 | } |
64 | |
65 | return boost::report_errors(); |
66 | } |
67 | |