• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*=============================================================================
2     Copyright (c) 2001-2015 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 
main()15 int main()
16 {
17     using spirit_test::test_attr;
18     using boost::spirit::x3::attr;
19     using boost::spirit::x3::int_;
20 
21     BOOST_SPIRIT_ASSERT_CONSTEXPR_CTORS(attr);
22     BOOST_SPIRIT_ASSERT_CONSTEXPR_CTORS(attr(1));
23     BOOST_SPIRIT_ASSERT_CONSTEXPR_CTORS(attr("asd"));
24     {
25         constexpr char s[] = "asd";
26         BOOST_SPIRIT_ASSERT_CONSTEXPR_CTORS(attr(s));
27     }
28 
29     {
30         int d = 0;
31         BOOST_TEST(test_attr("", attr(1), d) && d == 1);
32 
33         int d1 = 1;
34         BOOST_TEST(test_attr("", attr(d1), d) && d == 1);
35 
36         std::pair<int, int> p;
37         BOOST_TEST(test_attr("1", int_ >> attr(1), p) &&
38             p.first == 1 && p.second == 1);
39 
40         char c = '\0';
41         BOOST_TEST(test_attr("", attr('a'), c) && c == 'a');
42 
43         // $$$ Needs some special is_convertible support, or
44         // str ends up with an explicit null-terminator... $$$
45         //~ std::string str;
46         //~ BOOST_TEST(test_attr("", attr("test"), str) && str == "test");
47 
48         int array[] = {0, 1, 2};
49         std::vector<int> vec;
50         BOOST_TEST(test_attr("", attr(array), vec) && vec.size() == 3 &&
51             vec[0] == 0 && vec[1] == 1 && vec[2] == 2);
52     }
53 
54     {
55         std::string s;
56         BOOST_TEST(test_attr("s", "s" >> attr(std::string("123")), s) &&
57             s == "123");
58     }
59 
60     return boost::report_errors();
61 }
62