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