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/repeated_one_of1.hpp>
7 #include <boost/metaparse/one_char.hpp>
8 #include <boost/metaparse/fail.hpp>
9 #include <boost/metaparse/keyword.hpp>
10 #include <boost/metaparse/is_error.hpp>
11 #include <boost/metaparse/start.hpp>
12 #include <boost/metaparse/get_result.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/list.hpp>
19 #include <boost/mpl/vector_c.hpp>
20 #include <boost/mpl/equal.hpp>
21 #include <boost/mpl/assert.hpp>
22
23 #include "test_case.hpp"
24
BOOST_METAPARSE_TEST_CASE(repeated_one_of1)25 BOOST_METAPARSE_TEST_CASE(repeated_one_of1)
26 {
27 using boost::metaparse::fail;
28 using boost::metaparse::is_error;
29 using boost::metaparse::repeated_one_of1;
30 using boost::metaparse::start;
31 using boost::metaparse::get_result;
32 using boost::metaparse::one_char;
33 using boost::metaparse::keyword;
34
35 using boost::mpl::apply_wrap2;
36 using boost::mpl::equal;
37 using boost::mpl::list;
38 using boost::mpl::vector_c;
39
40 typedef fail<test_failure> test_fail;
41
42 // test0
43 BOOST_MPL_ASSERT((
44 is_error<apply_wrap2<repeated_one_of1< >, str_hello, start> >
45 ));
46
47 // test_good_sequence
48 BOOST_MPL_ASSERT((
49 equal<
50 get_result<
51 apply_wrap2<repeated_one_of1<one_char>, str_hello, start>
52 >::type,
53 vector_c<char, 'h', 'e', 'l', 'l', 'o'>
54 >
55 ));
56
57 // test_1_with_bad
58 BOOST_MPL_ASSERT((
59 is_error<apply_wrap2<repeated_one_of1<test_fail>, str_hello, start> >
60 ));
61
62 // test_2_with_first_good
63 BOOST_MPL_ASSERT((
64 equal<
65 get_result<
66 apply_wrap2<repeated_one_of1<one_char, test_fail>, str_hello, start>
67 >::type,
68 vector_c<char, 'h', 'e', 'l', 'l', 'o'>
69 >
70 ));
71
72 // test_2_with_second_good
73 BOOST_MPL_ASSERT((
74 equal<
75 get_result<
76 apply_wrap2<repeated_one_of1<test_fail, one_char>, str_hello, start>
77 >::type,
78 vector_c<char, 'h', 'e', 'l', 'l', 'o'>
79 >
80 ));
81
82 typedef keyword<str_h, char_h> keyword_h;
83 typedef keyword<str_e, char_e> keyword_e;
84 typedef keyword<str_l, char_l> keyword_l;
85
86 // test_accept_any_argument
87 BOOST_MPL_ASSERT((
88 equal<
89 get_result<
90 apply_wrap2<
91 repeated_one_of1<keyword_h, keyword_e, keyword_l>,
92 str_hello,
93 start
94 >
95 >::type,
96 list<char_h, char_e, char_l, char_l>
97 >
98 ));
99 }
100
101