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/nth_of.hpp>
7 #include <boost/metaparse/nth_of_c.hpp>
8 #include <boost/metaparse/is_error.hpp>
9 #include <boost/metaparse/get_result.hpp>
10 #include <boost/metaparse/start.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/assert.hpp>
17
18 #include "test_case.hpp"
19
BOOST_METAPARSE_TEST_CASE(nth_of)20 BOOST_METAPARSE_TEST_CASE(nth_of)
21 {
22 using boost::metaparse::get_result;
23 using boost::metaparse::nth_of_c;
24 using boost::metaparse::start;
25 using boost::metaparse::nth_of;
26 using boost::metaparse::is_error;
27
28 using boost::mpl::equal_to;
29 using boost::mpl::apply_wrap2;
30
31 namespace mpl = boost::mpl;
32 namespace mp = boost::metaparse;
33
34 // test_first_of_one
35 BOOST_MPL_ASSERT((
36 equal_to<
37 get_result<apply_wrap2<nth_of_c<0, lit_h>, str_hello, start> >::type,
38 char_h
39 >
40 ));
41
42 // test_first_of_two
43 BOOST_MPL_ASSERT((
44 equal_to<
45 get_result<
46 apply_wrap2<nth_of_c<0, lit_h, lit_e>, str_hello, start>
47 >::type,
48 char_h
49 >
50 ));
51
52 // test_second_of_two
53 BOOST_MPL_ASSERT((
54 equal_to<
55 get_result<
56 apply_wrap2<nth_of<int1, lit_h, lit_e>, str_hello, start>
57 >::type,
58 char_e
59 >
60 ));
61
62 // test_nothing
63 BOOST_MPL_ASSERT((
64 is_error<apply_wrap2<nth_of_c<1, lit_x, lit_e>, str_hello, start> >
65 ));
66
67 // test_first_of_none
68 BOOST_MPL_ASSERT((
69 is_error<apply_wrap2<nth_of_c<0>, str_hello, start> >
70 ));
71
72 // test_n_is_less_than_zero
73 BOOST_MPL_ASSERT((
74 is_error<apply_wrap2<nth_of_c<-1, lit_h, lit_e>, str_hello, start> >
75 ));
76
77 // test_n_is_greater_than_the_number_of_parsers
78 BOOST_MPL_ASSERT((
79 is_error<apply_wrap2<nth_of_c<2, lit_h, lit_e>, str_hello, start> >
80 ));
81
82 // test_error_before_the_nth
83 BOOST_MPL_ASSERT((
84 is_error<apply_wrap2<nth_of_c<1, lit_x, lit_e, lit_l>, str_hello, start> >
85 ));
86
87 // test_error_at_the_nth
88 BOOST_MPL_ASSERT((
89 is_error<apply_wrap2<nth_of_c<1, lit_h, lit_x, lit_l>, str_hello, start> >
90 ));
91
92 // test_error_after_the_nth
93 BOOST_MPL_ASSERT((
94 is_error<apply_wrap2<nth_of_c<1, lit_h, lit_e, lit_x>, str_hello, start> >
95 ));
96 }
97
98