]>
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/middle_of.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_message.hpp> | |
11 | #include <boost/metaparse/error/unpaired.hpp> | |
12 | #include <boost/metaparse/error/literal_expected.hpp> | |
13 | ||
14 | #include "common.hpp" | |
15 | ||
16 | #include <boost/mpl/equal_to.hpp> | |
17 | #include <boost/mpl/apply_wrap.hpp> | |
18 | #include <boost/mpl/assert.hpp> | |
19 | ||
20 | #include <boost/type_traits/is_same.hpp> | |
21 | ||
22 | #include "test_case.hpp" | |
23 | ||
24 | BOOST_METAPARSE_TEST_CASE(middle_of) | |
25 | { | |
26 | using boost::metaparse::get_result; | |
27 | using boost::metaparse::middle_of; | |
28 | using boost::metaparse::start; | |
29 | using boost::metaparse::is_error; | |
30 | using boost::metaparse::get_message; | |
31 | ||
32 | using boost::metaparse::error::unpaired; | |
33 | using boost::metaparse::error::literal_expected; | |
34 | ||
35 | using boost::is_same; | |
36 | ||
37 | using boost::mpl::equal_to; | |
38 | using boost::mpl::apply_wrap2; | |
39 | ||
40 | // test_three_chars | |
41 | BOOST_MPL_ASSERT(( | |
42 | equal_to< | |
43 | get_result< | |
44 | apply_wrap2<middle_of<lit_h, lit_e, lit_l>, str_hello, start> | |
45 | >::type, | |
46 | char_e | |
47 | > | |
48 | )); | |
49 | ||
50 | // test_first_fails | |
51 | BOOST_MPL_ASSERT(( | |
52 | is_error<apply_wrap2<middle_of<lit_x, lit_e, lit_l>, str_hello, start> > | |
53 | )); | |
54 | ||
55 | // test_second_fails | |
56 | BOOST_MPL_ASSERT(( | |
57 | is_error<apply_wrap2<middle_of<lit_h, lit_x, lit_l>, str_hello, start> > | |
58 | )); | |
59 | ||
60 | // test_third_fails | |
61 | BOOST_MPL_ASSERT(( | |
62 | is_error<apply_wrap2<middle_of<lit_h, lit_e, lit_x>, str_hello, start> > | |
63 | )); | |
64 | ||
65 | // test_error_message_when_third_fails | |
66 | BOOST_MPL_ASSERT(( | |
67 | is_same< | |
68 | unpaired<1, 1, literal_expected<'x'> >, | |
69 | get_message< | |
70 | apply_wrap2<middle_of<lit_h, lit_e, lit_x>, str_hello, start> | |
71 | >::type | |
72 | > | |
73 | )); | |
74 | ||
75 | // test_empty_input | |
76 | BOOST_MPL_ASSERT(( | |
77 | is_error<apply_wrap2<middle_of<lit_h, lit_e, lit_l>, str_, start> > | |
78 | )); | |
79 | } | |
80 | ||
81 |