• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/last_of.hpp>
7 #include <boost/metaparse/is_error.hpp>
8 #include <boost/metaparse/start.hpp>
9 #include <boost/metaparse/get_result.hpp>
10 
11 #include "common.hpp"
12 
13 #include <boost/mpl/equal_to.hpp>
14 #include <boost/mpl/apply_wrap.hpp>
15 #include <boost/mpl/assert.hpp>
16 
17 #include "test_case.hpp"
18 
BOOST_METAPARSE_TEST_CASE(last_of)19 BOOST_METAPARSE_TEST_CASE(last_of)
20 {
21   using boost::metaparse::get_result;
22   using boost::metaparse::last_of;
23   using boost::metaparse::start;
24   using boost::metaparse::is_error;
25 
26   using boost::mpl::equal_to;
27   using boost::mpl::apply_wrap2;
28 
29   // test_one_char
30   BOOST_MPL_ASSERT((
31     equal_to<
32       get_result<apply_wrap2<last_of<lit_h>, str_hello, start> >::type,
33       char_h
34     >
35   ));
36 
37   // test_two_chars
38   BOOST_MPL_ASSERT((
39     equal_to<
40       get_result<apply_wrap2<last_of<lit_h, lit_e>, str_hello, start> >::type,
41       char_e
42     >
43   ));
44 
45   // test_first_fails
46   BOOST_MPL_ASSERT((
47     is_error<apply_wrap2<last_of<lit_x, lit_e>, str_hello, start> >
48   ));
49 
50   // test_second_fails
51   BOOST_MPL_ASSERT((
52     is_error<apply_wrap2<last_of<lit_h, lit_x>, str_hello, start> >
53   ));
54 
55   // test_empty_input
56   BOOST_MPL_ASSERT((
57     is_error<apply_wrap2<last_of<lit_h, lit_e>, str_, start> >
58   ));
59 
60   // test_three_chars
61   BOOST_MPL_ASSERT((
62     equal_to<
63       get_result<
64         apply_wrap2<last_of<lit_h, lit_e, lit_l>, str_hello, start>
65       >::type,
66       char_l
67     >
68   ));
69 }
70 
71 
72