1 // Copyright Abel Sinkovics (abel@sinkovics.hu) 2015.
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/foldl_reject_incomplete_start_with_parser.hpp>
7 #include <boost/metaparse/start.hpp>
8 #include <boost/metaparse/string.hpp>
9 #include <boost/metaparse/is_error.hpp>
10 #include <boost/metaparse/get_result.hpp>
11 #include <boost/metaparse/return_.hpp>
12 #include <boost/metaparse/sequence.hpp>
13 #include <boost/metaparse/v1/impl/back_inserter.hpp>
14
15 #include "common.hpp"
16
17 #include <boost/mpl/apply_wrap.hpp>
18 #include <boost/mpl/char.hpp>
19 #include <boost/mpl/assert.hpp>
20
21 #include "test_case.hpp"
22
23 namespace
24 {
25 struct keep_state
26 {
27 typedef keep_state type;
28
29 template <class S, class C>
30 struct apply : S {};
31 };
32 }
33
BOOST_METAPARSE_TEST_CASE(foldl_reject_incomplete_start_with_parser)34 BOOST_METAPARSE_TEST_CASE(foldl_reject_incomplete_start_with_parser)
35 {
36 using boost::metaparse::foldl_reject_incomplete_start_with_parser;
37 using boost::metaparse::start;
38 using boost::metaparse::is_error;
39 using boost::metaparse::lit_c;
40 using boost::metaparse::get_result;
41 using boost::metaparse::sequence;
42
43 using boost::mpl::equal_to;
44 using boost::mpl::apply_wrap2;
45 using boost::mpl::char_;
46
47 typedef sequence<lit_c<'a'>, lit_c<'a'> > aa;
48
49 typedef
50 foldl_reject_incomplete_start_with_parser<aa, lit_c<'b'>, keep_state>
51 p;
52
53 // test_b
54 BOOST_MPL_ASSERT((
55 equal_to<get_result<apply_wrap2<p, str_b, start> >::type, char_<'b'> >
56 ));
57
58 // test_ba
59 BOOST_MPL_ASSERT(( is_error<apply_wrap2<p, str_ba, start> > ));
60
61 // test_baaaa
62 BOOST_MPL_ASSERT((
63 equal_to<get_result<apply_wrap2<p, str_baaaa, start> >::type, char_<'b'> >
64 ));
65
66 // test_c
67 BOOST_MPL_ASSERT((is_error<apply_wrap2<p, str_c, start> >));
68
69 // test_ca
70 BOOST_MPL_ASSERT((is_error<apply_wrap2<p, str_ca, start> >));
71 }
72
73 // Test foldl_reject_incomplete_start_with_parser as a normal fold
74
75 using boost::metaparse::foldl_reject_incomplete_start_with_parser;
76 using boost::metaparse::return_;
77 using boost::metaparse::v1::impl::back_inserter;
78
79 using boost::mpl::vector;
80
81 namespace
82 {
83 template <class P>
84 struct repeated_reject_incomplete :
85 foldl_reject_incomplete_start_with_parser<
86 P,
87 return_<vector<> >,
88 back_inserter
89 >
90 {};
91 }
92
93 #define TEST_NAME \
94 foldl_reject_incomplete_start_with_parser_as_foldl_reject_incomplete
95
96 #include "repeated_reject_incomplete_test.hpp"
97
98