1 // Copyright Abel Sinkovics (abel@sinkovics.hu) 2014.
2 // Distributed under the Boost Software License, Version 1.0.
3 // (See accompanying file LICENSE_1_0.txt or copy at
4 // http://www.boost.org/LICENSE_1_0.txt)
5
6 #include <boost/metaparse/accept.hpp>
7 #include <boost/metaparse/start.hpp>
8 #include <boost/metaparse/string.hpp>
9 #include <boost/metaparse/get_result.hpp>
10 #include <boost/metaparse/get_position.hpp>
11 #include <boost/metaparse/get_remaining.hpp>
12
13 #include <boost/mpl/assert.hpp>
14
15 #include <boost/type_traits.hpp>
16
17 #include "test_case.hpp"
18
19 namespace
20 {
21 template <class T>
22 struct returns
23 {
24 typedef T type;
25 };
26
27 template <class T>
28 struct gets_foo
29 {
30 typedef typename T::foo type;
31 };
32 }
33
BOOST_METAPARSE_TEST_CASE(accept)34 BOOST_METAPARSE_TEST_CASE(accept)
35 {
36 using boost::metaparse::accept;
37 using boost::metaparse::start;
38 using boost::metaparse::string;
39 using boost::metaparse::get_result;
40 using boost::metaparse::get_position;
41 using boost::metaparse::get_remaining;
42
43 using boost::is_same;
44
45 typedef string<'H','e','l','l','o'> s;
46
47 // test_accept_is_metaprogramming_value
48 BOOST_MPL_ASSERT((
49 is_same<accept<int, s, start>, accept<int, s, start>::type>
50 ));
51
52 // test_accept_is_not_lazy
53 BOOST_MPL_ASSERT((
54 is_same<
55 accept<gets_foo<int>, s, start>,
56 accept<gets_foo<int>, returns<s>, returns<start> >::type
57 >
58 ));
59
60 // test_get_result_of_accept
61 BOOST_MPL_ASSERT((is_same<int, get_result<accept<int, s, start> >::type>));
62
63 // test_get_remaining_of_accept
64 BOOST_MPL_ASSERT((is_same<s, get_remaining<accept<int, s, start> >::type>));
65
66 // test_get_position_of_accept
67 BOOST_MPL_ASSERT((
68 is_same<start, get_position<accept<int, s, start> >::type>
69 ));
70 }
71
72