• 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_incomplete<letter_pair>
47     repeated_reject_incomplete_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     equal<
63       get_result<
64         apply_wrap2<repeated_reject_incomplete_letter_pair, str_, start>
65       >::type,
66       vector<>
67     >
68   ));
69 
70   // test0
71   BOOST_MPL_ASSERT_NOT((
72     is_error<
73       apply_wrap2<repeated_reject_incomplete_letter_pair, chars0, start>
74     >
75   ));
76 
77   // test_with_a_failing_item
78   BOOST_MPL_ASSERT((
79     is_error<
80       apply_wrap2<repeated_reject_incomplete_letter_pair, chars1, start>
81     >
82   ));
83 
84   // test1_pair
85   BOOST_MPL_ASSERT((
86     equal<
87       get_result<
88         apply_wrap2<repeated_reject_incomplete_letter_pair, chars2, start>
89       >::type,
90       vector<vector_c<char, 'h', 'e'> >,
91       equal_sequences
92     >
93   ));
94 
95   // test2_pairs
96   BOOST_MPL_ASSERT((
97     equal<
98       get_result<
99         apply_wrap2<repeated_reject_incomplete_letter_pair, chars4, start>
100       >::type,
101       vector<vector_c<char, 'h','e'>, vector_c<char, 'l','l'> >,
102       equal_sequences
103     >
104   ));
105 
106   // test3_pairs
107   BOOST_MPL_ASSERT((
108     equal<
109       get_result<
110         apply_wrap2<repeated_reject_incomplete_letter_pair, chars6, start>
111       >::type,
112       vector<
113         vector_c<char, 'h','e'>,
114         vector_c<char, 'l','l'>,
115         vector_c<char, 'o','w'>
116       >,
117       equal_sequences
118     >
119   ));
120 
121   // test4_pairs
122   BOOST_MPL_ASSERT((
123     equal<
124       get_result<
125         apply_wrap2<repeated_reject_incomplete_letter_pair, chars8, start>
126       >::type,
127       vector<
128         vector_c<char, 'h','e'>,
129         vector_c<char, 'l','l'>,
130         vector_c<char, 'o','w'>,
131         vector_c<char, 'o','r'>
132       >,
133       equal_sequences
134     >
135   ));
136 
137   // test5
138   BOOST_MPL_ASSERT((
139     equal<
140       get_result<
141         apply_wrap2<repeated_reject_incomplete_letter_pair, chars10, start>
142       >::type,
143       vector<
144         vector_c<char, 'h','e'>,
145         vector_c<char, 'l','l'>,
146         vector_c<char, 'o','w'>,
147         vector_c<char, 'o','r'>,
148         vector_c<char, 'l','d'>
149       >,
150       equal_sequences
151     >
152   ));
153 
154   // test_length
155   BOOST_MPL_ASSERT((
156     equal_to<
157       size<
158         get_result<
159           apply_wrap2<repeated_reject_incomplete_letter_pair, chars6, start>
160         >::type
161       >::type,
162       int3
163     >
164   ));
165 
166   // test_no_extra_evaluation
167   BOOST_MPL_ASSERT((
168     equal<
169       get_result<
170         apply_wrap2<repeated_reject_incomplete<always_int>, str_ca, start>
171       >::type,
172       vector<int, int>
173     >
174   ));
175 }
176 
177