1 // Copyright Abel Sinkovics (abel@sinkovics.hu) 2010 - 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 // This header file contains code that is reused by other cpp files
7
8 #include <boost/metaparse/is_error.hpp>
9 #include <boost/metaparse/start.hpp>
10 #include <boost/metaparse/get_result.hpp>
11 #include <boost/metaparse/get_remaining.hpp>
12 #include <boost/metaparse/get_position.hpp>
13 #include <boost/metaparse/get_line.hpp>
14 #include <boost/metaparse/iterate_c.hpp>
15
16 #include "common.hpp"
17
18 #include <boost/mpl/equal_to.hpp>
19 #include <boost/mpl/apply_wrap.hpp>
20 #include <boost/mpl/assert.hpp>
21
22 #include "test_case.hpp"
23
24 namespace
25 {
26 using boost::metaparse::start;
27
28 using boost::mpl::list_c;
29 using boost::mpl::apply_wrap2;
30
31 typedef list_c<char, 'a','\n','b'> unix_multi_line_text;
32 typedef list_c<char, 'a','\r','\n','b'> dos_multi_line_text;
33 typedef list_c<char, 'a','\r','b'> mac_multi_line_text;
34
35 typedef apply_wrap2<oc, str_hello, start> parse_first_char;
36 }
37
BOOST_METAPARSE_TEST_CASE(TEST_NAME)38 BOOST_METAPARSE_TEST_CASE(TEST_NAME)
39 {
40 using boost::metaparse::get_result;
41 using boost::metaparse::get_remaining;
42 using boost::metaparse::get_position;
43 using boost::metaparse::is_error;
44 using boost::metaparse::iterate_c;
45 using boost::metaparse::get_line;
46
47 using boost::mpl::equal_to;
48
49 // test_for_non_empty_string
50 BOOST_MPL_ASSERT((equal_to<get_result<parse_first_char>::type, char_h>));
51
52 // test_for_non_empty_string_second
53 BOOST_MPL_ASSERT((
54 equal_to<
55 get_result<
56 apply_wrap2<
57 oc,
58 get_remaining<parse_first_char>::type,
59 get_position<parse_first_char>::type
60 >
61 >::type,
62 char_e
63 >
64 ));
65
66 // test_for_empty_string
67 BOOST_MPL_ASSERT((is_error<apply_wrap2<oc, str_, start> >));
68
69 // test_unix_multi_line_text
70 BOOST_MPL_ASSERT((
71 equal_to<
72 int2,
73 get_line<
74 get_position<
75 apply_wrap2<iterate_c<oc, 2>, unix_multi_line_text, start>
76 >
77 >
78 >
79 ));
80
81 // test_dos_multi_line_text
82 BOOST_MPL_ASSERT((
83 equal_to<
84 int2,
85 get_line<
86 get_position<apply_wrap2<iterate_c<oc, 3>, dos_multi_line_text, start> >
87 >
88 >
89 ));
90
91 // test_mac_multi_line_text
92 BOOST_MPL_ASSERT((
93 equal_to<
94 int2,
95 get_line<
96 get_position<apply_wrap2<iterate_c<oc, 2>, mac_multi_line_text, start> >
97 >
98 >
99 ));
100 }
101
102
103
104