• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 // This header file contains code that is reused by other cpp files
7 
8 #include <boost/metaparse/letter.hpp>
9 #include <boost/metaparse/sequence.hpp>
10 #include <boost/metaparse/start.hpp>
11 #include <boost/metaparse/get_result.hpp>
12 #include <boost/metaparse/is_error.hpp>
13 #include <boost/metaparse/always.hpp>
14 #include <boost/metaparse/one_char.hpp>
15 
16 #include "common.hpp"
17 
18 #include <boost/mpl/apply_wrap.hpp>
19 #include <boost/mpl/equal.hpp>
20 #include <boost/mpl/equal_to.hpp>
21 #include <boost/mpl/size.hpp>
22 #include <boost/mpl/vector_c.hpp>
23 #include <boost/mpl/assert.hpp>
24 
25 #include "test_case.hpp"
26 
BOOST_METAPARSE_TEST_CASE(TEST_NAME)27 BOOST_METAPARSE_TEST_CASE(TEST_NAME)
28 {
29   using boost::metaparse::get_result;
30   using boost::metaparse::letter;
31   using boost::metaparse::start;
32   using boost::metaparse::is_error;
33   using boost::metaparse::sequence;
34   using boost::metaparse::always;
35   using boost::metaparse::one_char;
36 
37   using boost::mpl::equal;
38   using boost::mpl::equal_to;
39   using boost::mpl::apply_wrap2;
40   using boost::mpl::vector_c;
41   using boost::mpl::vector;
42   using boost::mpl::size;
43 
44   typedef sequence<letter, letter> letter_pair;
45   typedef
46     repeated_reject_incomplete1<letter_pair>
47     repeated_reject_incomplete1_letter_pair;
48   typedef always<one_char, int> always_int;
49 
50   typedef boost::mpl::vector_c<char, 'h','e','l','l','o','w','0'> chars6;
51 
52   typedef
53     boost::mpl::vector_c<char, 'h','e','l','l','o','w','o','r','0'>
54     chars8;
55 
56   typedef
57     boost::mpl::vector_c<char, 'h','e','l','l','o','w','o','r','l','d','0'>
58     chars10;
59 
60   // test_empty_input
61   BOOST_MPL_ASSERT((
62     is_error<
63       apply_wrap2<repeated_reject_incomplete1_letter_pair, str_, start>
64     >
65   ));
66 
67   // test0
68   BOOST_MPL_ASSERT((
69     is_error<
70       apply_wrap2<repeated_reject_incomplete1_letter_pair, chars0, start>
71     >
72   ));
73 
74   // test1_pair
75   BOOST_MPL_ASSERT((
76     equal<
77       get_result<
78         apply_wrap2<repeated_reject_incomplete1_letter_pair, chars2, start>
79       >::type,
80       vector<vector_c<char, 'h', 'e'> >,
81       equal_sequences
82     >
83   ));
84 
85   // test_with_a_failing_item
86   BOOST_MPL_ASSERT((
87     is_error<
88       apply_wrap2<repeated_reject_incomplete1_letter_pair, chars3, start>
89     >
90   ));
91 
92    // test2_pairs
93   BOOST_MPL_ASSERT((
94     equal<
95       get_result<
96         apply_wrap2<repeated_reject_incomplete1_letter_pair, chars4, start>
97       >::type,
98       vector<vector_c<char, 'h','e'>, vector_c<char, 'l','l'> >,
99       equal_sequences
100     >
101   ));
102 
103   // test3_pairs
104   BOOST_MPL_ASSERT((
105     equal<
106       get_result<
107         apply_wrap2<repeated_reject_incomplete1_letter_pair, chars6, start>
108       >::type,
109       vector<
110         vector_c<char, 'h','e'>,
111         vector_c<char, 'l','l'>,
112         vector_c<char, 'o','w'>
113       >,
114       equal_sequences
115     >
116   ));
117 
118   // test4_pairs
119   BOOST_MPL_ASSERT((
120     equal<
121       get_result<
122         apply_wrap2<repeated_reject_incomplete1_letter_pair, chars8, start>
123       >::type,
124       vector<
125         vector_c<char, 'h','e'>,
126         vector_c<char, 'l','l'>,
127         vector_c<char, 'o','w'>,
128         vector_c<char, 'o','r'>
129       >,
130       equal_sequences
131     >
132   ));
133 
134   // test5
135   BOOST_MPL_ASSERT((
136     equal<
137       get_result<
138         apply_wrap2<repeated_reject_incomplete1_letter_pair, chars10, start>
139       >::type,
140       vector<
141         vector_c<char, 'h','e'>,
142         vector_c<char, 'l','l'>,
143         vector_c<char, 'o','w'>,
144         vector_c<char, 'o','r'>,
145         vector_c<char, 'l','d'>
146       >,
147       equal_sequences
148     >
149   ));
150 
151   // test_length
152   BOOST_MPL_ASSERT((
153     equal_to<
154       size<
155         get_result<
156           apply_wrap2<repeated_reject_incomplete1_letter_pair, chars6, start>
157         >::type
158       >::type,
159       int3
160     >
161   ));
162 
163   // test_no_extra_evaluation
164   BOOST_MPL_ASSERT((
165     equal<
166       get_result<
167         apply_wrap2<repeated_reject_incomplete1<always_int>, str_ca, start>
168       >::type,
169       vector<int, int>
170     >
171   ));
172 }
173 
174