• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright Abel Sinkovics (abel@sinkovics.hu) 2011.
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/source_position.hpp>
7 #include <boost/metaparse/start.hpp>
8 #include <boost/metaparse/next_char.hpp>
9 #include <boost/metaparse/next_line.hpp>
10 #include <boost/metaparse/get_prev_char.hpp>
11 #include <boost/metaparse/get_line.hpp>
12 #include <boost/metaparse/get_col.hpp>
13 
14 #include "common.hpp"
15 
16 #include <boost/mpl/equal_to.hpp>
17 #include <boost/mpl/not_equal_to.hpp>
18 #include <boost/mpl/assert.hpp>
19 #include <boost/mpl/less.hpp>
20 #include <boost/mpl/greater.hpp>
21 #include <boost/mpl/greater_equal.hpp>
22 #include <boost/mpl/less_equal.hpp>
23 #include <boost/mpl/not.hpp>
24 
25 #include "test_case.hpp"
26 
27 namespace
28 {
29   using boost::metaparse::source_position;
30   using boost::metaparse::next_char;
31   using boost::metaparse::start;
32 
33   typedef source_position<int11, int13, int1> sp;
34   typedef next_char<start, char_0> next0;
35  }
36 
BOOST_METAPARSE_TEST_CASE(source_position)37 BOOST_METAPARSE_TEST_CASE(source_position)
38 {
39   using boost::metaparse::get_line;
40   using boost::metaparse::get_col;
41   using boost::metaparse::get_prev_char;
42   using boost::metaparse::next_line;
43 
44   using boost::mpl::equal_to;
45   using boost::mpl::not_equal_to;
46 
47   using boost::mpl::not_;
48   using boost::mpl::less;
49   using boost::mpl::greater;
50   using boost::mpl::greater_equal;
51   using boost::mpl::less_equal;
52 
53   // test_get_line
54   BOOST_MPL_ASSERT((equal_to<int11, get_line<sp>::type>));
55 
56   // test_get_col
57   BOOST_MPL_ASSERT((equal_to<int13, get_col<sp>::type>));
58 
59   // test_get_prev_char
60   BOOST_MPL_ASSERT((equal_to<int1, get_prev_char<sp>::type>));
61 
62   // test_line_of_start
63   BOOST_MPL_ASSERT((equal_to<int1, get_line<start>::type>));
64 
65   // test_col_of_start
66   BOOST_MPL_ASSERT((equal_to<int1, get_col<start>::type>));
67 
68   // test_next_chars_char
69   BOOST_MPL_ASSERT((equal_to<int2, get_col<next0>::type>));
70 
71   // test_next_chars_line
72   BOOST_MPL_ASSERT((equal_to<int1, get_line<next0>::type>));
73 
74   // test_next_lines_char
75   BOOST_MPL_ASSERT((
76     equal_to<int1, get_col<next_line<next0, char_0> >::type>
77   ));
78 
79   // test_next_lines_line
80   BOOST_MPL_ASSERT((
81     equal_to<int2, get_line<next_line<start, char_0> >::type>
82   ));
83 
84   // test_next_chars_prev_char
85   BOOST_MPL_ASSERT((
86     equal_to<char_1, get_prev_char< next_char<start, char_1> >::type>
87   ));
88 
89   // test_next_lines_prev_char
90   BOOST_MPL_ASSERT((
91     equal_to<char_1, get_prev_char<next_line<start, char_1> >::type>
92   ));
93 
94   // test_equal_source_positions
95   BOOST_MPL_ASSERT((equal_to<sp, sp>));
96 
97   // test_equal_source_positions_when_prev_char_is_different
98   BOOST_MPL_ASSERT((
99     not_<
100       equal_to<
101         source_position<int11, int13, char_a>,
102         source_position<int11, int13, char_b>
103       >::type
104     >
105   ));
106 
107   // test_not_equal_source_positions_when_line_is_different
108   BOOST_MPL_ASSERT((
109     not_equal_to<
110       source_position<int11, int13, char_a>,
111       source_position<int13, int13, char_a>
112     >
113   ));
114 
115   // test_not_equal_source_positions_when_col_is_different
116   BOOST_MPL_ASSERT((
117     not_equal_to<
118       source_position<int11, int11, char_a>,
119       source_position<int11, int13, char_a>
120     >
121   ));
122 
123   // test_source_position_is_not_less_than_itself
124   BOOST_MPL_ASSERT((
125     not_<
126       less<
127         source_position<int11, int13, char_a>,
128         source_position<int11, int13, char_a>
129       >::type
130     >
131   ));
132 
133   // test_source_position_earlier_in_the_same_line_is_less
134   BOOST_MPL_ASSERT((
135     less<
136       source_position<int11, int11, char_a>,
137       source_position<int11, int13, char_a>
138     >
139   ));
140 
141   // test_source_position_later_in_the_same_line_is_not_less
142   BOOST_MPL_ASSERT((
143     not_<
144       less<
145         source_position<int11, int13, char_a>,
146         source_position<int11, int11, char_a>
147       >::type
148     >
149   ));
150 
151   // test_source_position_in_the_same_pos_with_less_char_is_less
152   BOOST_MPL_ASSERT((
153     less<
154       source_position<int11, int13, char_a>,
155       source_position<int11, int13, char_b>
156     >
157   ));
158 
159   // test_source_position_earlier_line_is_less
160   BOOST_MPL_ASSERT((
161     less<
162       source_position<int1, int28, char_a>,
163       source_position<int11, int13, char_a>
164     >
165   ));
166 
167   // test_source_position_later_line_is_not_less
168   BOOST_MPL_ASSERT((
169     not_<
170       less<
171         source_position<int28, int2, char_a>,
172         source_position<int11, int13, char_a>
173       >::type
174     >
175   ));
176 
177   // test_source_position_is_greater_equal_to_itself
178   BOOST_MPL_ASSERT((
179     greater_equal<
180       source_position<int11, int13, char_a>,
181       source_position<int11, int13, char_a>
182     >
183   ));
184 
185   // test_source_position_earlier_in_the_same_line_is_not_greater_equal
186   BOOST_MPL_ASSERT((
187     not_<
188       greater_equal<
189         source_position<int11, int11, char_a>,
190         source_position<int11, int13, char_a>
191       >::type
192     >
193   ));
194 
195   // test_source_position_later_in_the_same_line_is_greater_equal
196   BOOST_MPL_ASSERT((
197     greater_equal<
198       source_position<int11, int13, char_a>,
199       source_position<int11, int11, char_a>
200     >
201   ));
202 
203   // test_source_position_in_the_same_pos_with_less_char_is_not_greater_equal
204   BOOST_MPL_ASSERT((
205     not_<
206       greater_equal<
207         source_position<int11, int13, char_a>,
208         source_position<int11, int13, char_b>
209       >::type
210     >
211   ));
212 
213   // test_source_position_earlier_line_is_not_greater_equal
214   BOOST_MPL_ASSERT((
215     not_<
216       greater_equal<
217         source_position<int1, int28, char_a>,
218         source_position<int11, int13, char_a>
219       >::type
220     >
221   ));
222 
223   // test_source_position_later_line_is_greater_equal
224   BOOST_MPL_ASSERT((
225     greater_equal<
226       source_position<int28, int2, char_a>,
227       source_position<int11, int13, char_a>
228     >
229   ));
230 
231   // test_source_position_is_not_greater_than_itself
232   BOOST_MPL_ASSERT((
233     not_<
234       greater<
235         source_position<int11, int13, char_a>,
236         source_position<int11, int13, char_a>
237       >::type
238     >
239   ));
240 
241   // test_source_position_earlier_in_the_same_line_is_not_greater
242   BOOST_MPL_ASSERT((
243     not_<
244       greater<
245         source_position<int11, int11, char_a>,
246         source_position<int11, int13, char_a>
247       >::type
248     >
249   ));
250 
251   // test_source_position_later_in_the_same_line_is_greater
252   BOOST_MPL_ASSERT((
253     greater<
254       source_position<int11, int13, char_a>,
255       source_position<int11, int11, char_a>
256     >
257   ));
258 
259   // test_source_position_in_the_same_pos_with_less_char_is_not_greater
260   BOOST_MPL_ASSERT((
261     not_<
262       greater<
263         source_position<int11, int13, char_a>,
264         source_position<int11, int13, char_b>
265       >::type
266     >
267   ));
268 
269   // test_source_position_earlier_line_is_not_greater
270   BOOST_MPL_ASSERT((
271     not_<
272       greater<
273         source_position<int1, int28, char_a>,
274         source_position<int11, int13, char_a>
275       >::type
276     >
277   ));
278 
279   // test_source_position_later_line_is_greater
280   BOOST_MPL_ASSERT((
281     greater<
282       source_position<int28, int2, char_a>,
283       source_position<int11, int13, char_a>
284     >
285   ));
286 
287   // test_source_position_is_less_equal_to_itself
288   BOOST_MPL_ASSERT((
289     less_equal<
290       source_position<int11, int13, char_a>,
291       source_position<int11, int13, char_a>
292     >
293   ));
294 
295   // test_source_position_earlier_in_the_same_line_is_less_equal
296   BOOST_MPL_ASSERT((
297     less_equal<
298       source_position<int11, int11, char_a>,
299       source_position<int11, int13, char_a>
300     >
301   ));
302 
303   // test_source_position_later_in_the_same_line_is_not_less_equal
304   BOOST_MPL_ASSERT((
305     not_<
306       less_equal<
307         source_position<int11, int13, char_a>,
308         source_position<int11, int11, char_a>
309       >::type
310     >
311   ));
312 
313   // test_source_position_in_the_same_pos_with_less_char_is_less_equal
314   BOOST_MPL_ASSERT((
315     less_equal<
316       source_position<int11, int13, char_a>,
317       source_position<int11, int13, char_b>
318     >
319   ));
320 
321   // test_source_position_earlier_line_is_less_equal
322   BOOST_MPL_ASSERT((
323     less_equal<
324       source_position<int1, int28, char_a>,
325       source_position<int11, int13, char_a>
326     >
327   ));
328 
329   // test_source_position_later_line_is_not_less_equal
330   BOOST_MPL_ASSERT((
331     not_<
332       less_equal<
333         source_position<int28, int2, char_a>,
334         source_position<int11, int13, char_a>
335       >::type
336     >
337   ));
338 }
339 
340