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