Imported Upstream version 1.57.0
[platform/upstream/boost.git] / libs / spirit / test / x3 / attr.cpp
1 /*=============================================================================
2     Copyright (c) 2001-2013 Joel de Guzman
3
4     Distributed under the Boost Software License, Version 1. (See accompanying
5     file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6 =============================================================================*/
7 #include <boost/detail/lightweight_test.hpp>
8 #include <boost/spirit/home/x3.hpp>
9
10 #include <boost/fusion/include/std_pair.hpp>
11 #include <vector>
12
13 #include "test.hpp"
14
15 int
16 main()
17 {
18     using spirit_test::test_attr;
19     using boost::spirit::x3::attr;
20     using boost::spirit::x3::int_;
21
22     {
23         int d = 0;
24         BOOST_TEST(test_attr("", attr(1), d) && d == 1);
25
26         int d1 = 1;
27         BOOST_TEST(test_attr("", attr(d1), d) && d == 1);
28
29         std::pair<int, int> p;
30         BOOST_TEST(test_attr("1", int_ >> attr(1), p) && 
31             p.first == 1 && p.second == 1);
32
33         char c = '\0';
34         BOOST_TEST(test_attr("", attr('a'), c) && c == 'a');
35
36         // $$$ Needs some special is_convertible support, or
37         // str ends up with an explicit null-terminator... $$$
38         //~ std::string str;
39         //~ BOOST_TEST(test_attr("", attr("test"), str) && str == "test");
40         
41         int array[] = {0, 1, 2};
42         std::vector<int> vec;
43         BOOST_TEST(test_attr("", attr(array), vec) && vec.size() == 3 &&
44             vec[0] == 0 && vec[1] == 1 && vec[2] == 2);
45     }
46
47     //~ {   // testing lazy constructs
48         //~ using boost::phoenix::val;
49         //~ using boost::phoenix::ref;
50
51         //~ int d = 0;
52         //~ BOOST_TEST(test_attr("", attr(val(1)), d) && d == 1);
53
54         //~ int d1 = 2;
55         //~ BOOST_TEST(test_attr("", attr(ref(d1)), d) && d == 2);
56     //~ }
57
58     {
59         std::string s;
60         BOOST_TEST(test_attr("s", "s" >> attr(std::string("123")), s) && 
61             s == "123");
62     }
63
64     return boost::report_errors();
65 }