]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
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/sequence.hpp> | |
7 | #include <boost/metaparse/is_error.hpp> | |
8 | #include <boost/metaparse/start.hpp> | |
9 | #include <boost/metaparse/get_result.hpp> | |
10 | #include <boost/metaparse/always.hpp> | |
11 | #include <boost/metaparse/one_char.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/at.hpp> | |
19 | #include <boost/mpl/equal.hpp> | |
20 | #include <boost/mpl/vector_c.hpp> | |
21 | #include <boost/mpl/vector.hpp> | |
22 | #include <boost/mpl/assert.hpp> | |
23 | ||
24 | #include "test_case.hpp" | |
25 | ||
26 | BOOST_METAPARSE_TEST_CASE(sequence) | |
27 | { | |
28 | using boost::metaparse::get_result; | |
29 | using boost::metaparse::sequence; | |
30 | using boost::metaparse::start; | |
31 | using boost::metaparse::is_error; | |
32 | using boost::metaparse::always; | |
33 | using boost::metaparse::one_char; | |
34 | ||
35 | using boost::mpl::equal; | |
36 | using boost::mpl::apply_wrap2; | |
37 | using boost::mpl::list; | |
38 | using boost::mpl::equal_to; | |
39 | using boost::mpl::at_c; | |
40 | using boost::mpl::vector_c; | |
41 | using boost::mpl::vector; | |
42 | ||
43 | typedef always<one_char, int> always_int; | |
44 | ||
45 | // test_no_parser | |
46 | BOOST_MPL_ASSERT(( | |
47 | equal<get_result<apply_wrap2<sequence<>, str_hello, start> >::type, list<> > | |
48 | )); | |
49 | ||
50 | // test_one_parser | |
51 | BOOST_MPL_ASSERT(( | |
52 | equal< | |
53 | get_result<apply_wrap2<sequence<lit_h>, str_hello, start> >::type, | |
54 | vector_c<char, 'h'> | |
55 | > | |
56 | )); | |
57 | ||
58 | // test_one_failing_parser | |
59 | BOOST_MPL_ASSERT((is_error<apply_wrap2<sequence<lit_e>, str_hello, start> >)); | |
60 | ||
61 | // test_two_chars | |
62 | BOOST_MPL_ASSERT(( | |
63 | equal< | |
64 | get_result<apply_wrap2<sequence<lit_h, lit_e>, str_hello, start> >::type, | |
65 | vector_c<char, 'h', 'e'> | |
66 | > | |
67 | )); | |
68 | ||
69 | // test_first_fails | |
70 | BOOST_MPL_ASSERT(( | |
71 | is_error<apply_wrap2<sequence<lit_x, lit_e>, str_hello, start> > | |
72 | )); | |
73 | ||
74 | // test_second_fails | |
75 | BOOST_MPL_ASSERT(( | |
76 | is_error<apply_wrap2<sequence<lit_h, lit_x>, str_hello, start> > | |
77 | )); | |
78 | ||
79 | // test_empty_input | |
80 | BOOST_MPL_ASSERT((is_error<apply_wrap2<sequence<lit_h,lit_e>, str_,start> >)); | |
81 | ||
82 | // test_three_chars | |
83 | BOOST_MPL_ASSERT(( | |
84 | equal< | |
85 | get_result< | |
86 | apply_wrap2<sequence<lit_h, lit_e, lit_l>, str_hello, start> | |
87 | >::type, | |
88 | vector_c<char, 'h', 'e', 'l'> | |
89 | > | |
90 | )); | |
91 | ||
92 | // test_indexing_in_result | |
93 | BOOST_MPL_ASSERT(( | |
94 | equal_to< | |
95 | at_c< | |
96 | get_result< | |
97 | apply_wrap2<sequence<lit_h, lit_e, lit_l>, str_hello, start> | |
98 | >::type, | |
99 | 1 | |
100 | >::type, | |
101 | char_e | |
102 | > | |
103 | )); | |
104 | ||
105 | // test_no_extra_evaluation | |
106 | BOOST_MPL_ASSERT(( | |
107 | equal< | |
108 | get_result< | |
109 | apply_wrap2<sequence<always_int, always_int>, str_ca, start> | |
110 | >::type, | |
111 | vector<int, int> | |
112 | > | |
113 | )); | |
114 | } | |
115 |