]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | // Copyright Abel Sinkovics (abel@sinkovics.hu) 2010. |
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/keyword.hpp> | |
7 | #include <boost/metaparse/is_error.hpp> | |
8 | #include <boost/metaparse/start.hpp> | |
9 | #include <boost/metaparse/get_result.hpp> | |
10 | #include <boost/metaparse/get_remaining.hpp> | |
11 | ||
12 | #include "common.hpp" | |
13 | ||
14 | #include <boost/mpl/equal_to.hpp> | |
15 | #include <boost/mpl/apply_wrap.hpp> | |
16 | #include <boost/mpl/equal.hpp> | |
17 | #include <boost/mpl/assert.hpp> | |
18 | ||
19 | #include "test_case.hpp" | |
20 | ||
21 | namespace | |
22 | { | |
23 | using boost::metaparse::keyword; | |
24 | ||
25 | using boost::mpl::list_c; | |
26 | ||
27 | typedef | |
28 | list_c<char, 'h','e','l','l','o',' ','w','o','r','l','d'> | |
29 | str_hello_world; | |
30 | ||
31 | typedef list_c<char, 'h','e','l','l','x'> str_hellx; | |
32 | typedef list_c<char, 'h','x','l','l','o'> str_hxllo; | |
33 | ||
34 | typedef keyword<str_hello> keyword_hello; | |
35 | } | |
36 | ||
37 | BOOST_METAPARSE_TEST_CASE(keyword) | |
38 | { | |
39 | using boost::metaparse::get_result; | |
40 | using boost::metaparse::start; | |
41 | using boost::metaparse::is_error; | |
42 | using boost::metaparse::get_remaining; | |
43 | ||
44 | using boost::mpl::equal_to; | |
45 | using boost::mpl::apply_wrap2; | |
46 | using boost::mpl::equal; | |
47 | ||
48 | // test_result_type | |
49 | BOOST_MPL_ASSERT(( | |
50 | equal_to< | |
51 | get_result< | |
52 | apply_wrap2<keyword<str_hello, char_l>, str_hello, start> | |
53 | >::type, | |
54 | char_l | |
55 | > | |
56 | )); | |
57 | ||
58 | // test_empty_keyword | |
59 | BOOST_MPL_ASSERT(( | |
60 | equal_to< | |
61 | get_result<apply_wrap2<keyword<str_, char_l>, str_hello, start> >::type, | |
62 | char_l | |
63 | > | |
64 | )); | |
65 | ||
66 | // test_empty_input | |
67 | BOOST_MPL_ASSERT((is_error<apply_wrap2<keyword_hello, str_, start> >)); | |
68 | ||
69 | // test_itself | |
70 | BOOST_MPL_ASSERT(( | |
71 | equal< | |
72 | get_remaining<apply_wrap2<keyword_hello, str_hello, start> >::type, | |
73 | str_ | |
74 | > | |
75 | )); | |
76 | ||
77 | // test_more_than_itself | |
78 | BOOST_MPL_ASSERT(( | |
79 | equal< | |
80 | get_remaining<apply_wrap2<keyword_hello, str_hello_world, start> >::type, | |
81 | list_c<char, ' ', 'w', 'o', 'r', 'l', 'd'> | |
82 | > | |
83 | )); | |
84 | ||
85 | // test_no_match_at_end | |
86 | BOOST_MPL_ASSERT((is_error<apply_wrap2<keyword_hello, str_hellx, start> >)); | |
87 | ||
88 | // test_no_match_in_the_middle | |
89 | BOOST_MPL_ASSERT((is_error<apply_wrap2<keyword_hello, str_hxllo, start> >)); | |
90 | } | |
91 |