]>
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/one_of.hpp> | |
7 | #include <boost/metaparse/one_char.hpp> | |
8 | #include <boost/metaparse/fail.hpp> | |
9 | #include <boost/metaparse/is_error.hpp> | |
10 | #include <boost/metaparse/start.hpp> | |
11 | #include <boost/metaparse/get_result.hpp> | |
12 | #include <boost/metaparse/sequence.hpp> | |
13 | #include <boost/metaparse/get_position.hpp> | |
14 | #include <boost/metaparse/next_char.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 | BOOST_METAPARSE_TEST_CASE(one_of) | |
25 | { | |
26 | using boost::metaparse::is_error; | |
27 | using boost::metaparse::one_of; | |
28 | using boost::metaparse::start; | |
29 | using boost::metaparse::get_result; | |
30 | using boost::metaparse::one_char; | |
31 | using boost::metaparse::fail; | |
32 | using boost::metaparse::sequence; | |
33 | using boost::metaparse::get_position; | |
34 | using boost::metaparse::next_char; | |
35 | ||
36 | using boost::mpl::apply_wrap2; | |
37 | using boost::mpl::equal_to; | |
38 | ||
39 | typedef fail<test_failure> test_fail; | |
40 | typedef sequence<one_char, test_fail> test_fail_later; | |
41 | ||
42 | // test_1_with_good | |
43 | BOOST_MPL_ASSERT(( | |
44 | equal_to< | |
45 | get_result<apply_wrap2<one_of<one_char>, str_hello, start> >::type, | |
46 | char_h | |
47 | > | |
48 | )); | |
49 | ||
50 | // test_1_with_bad | |
51 | BOOST_MPL_ASSERT(( | |
52 | is_error<apply_wrap2<one_of<test_fail>, str_hello, start> > | |
53 | )); | |
54 | ||
55 | // test_2_with_two_good | |
56 | BOOST_MPL_ASSERT(( | |
57 | equal_to< | |
58 | get_result< | |
59 | apply_wrap2<one_of<one_char, one_char>, str_hello, start> | |
60 | >::type, | |
61 | char_h | |
62 | > | |
63 | )); | |
64 | ||
65 | // test_2_with_first_good | |
66 | BOOST_MPL_ASSERT(( | |
67 | equal_to< | |
68 | get_result< | |
69 | apply_wrap2<one_of<one_char, test_fail>, str_hello, start> | |
70 | >::type, | |
71 | char_h | |
72 | > | |
73 | )); | |
74 | ||
75 | // test_2_with_second_good | |
76 | BOOST_MPL_ASSERT(( | |
77 | equal_to< | |
78 | get_result< | |
79 | apply_wrap2<one_of<test_fail, one_char>, str_hello, start> | |
80 | >::type, | |
81 | char_h | |
82 | > | |
83 | )); | |
84 | ||
85 | // test_2_with_two_bad | |
86 | BOOST_MPL_ASSERT(( | |
87 | is_error<apply_wrap2<one_of<test_fail, test_fail>, str_hello, start> > | |
88 | )); | |
89 | ||
90 | ||
91 | ||
92 | ||
93 | ||
94 | // test | |
95 | BOOST_MPL_ASSERT((is_error<apply_wrap2<one_of< >, str_hello, start> >)); | |
96 | ||
97 | // test_with_good | |
98 | BOOST_MPL_ASSERT(( | |
99 | equal_to< | |
100 | get_result<apply_wrap2<one_of<one_char>, str_hello, start> >::type, | |
101 | char_h | |
102 | > | |
103 | )); | |
104 | ||
105 | // test_with_bad | |
106 | BOOST_MPL_ASSERT((is_error<apply_wrap2<one_of<test_fail>,str_hello,start> >)); | |
107 | ||
108 | // test_with_two_good | |
109 | BOOST_MPL_ASSERT(( | |
110 | equal_to< | |
111 | get_result< | |
112 | apply_wrap2<one_of<one_char, one_char>, str_hello, start> | |
113 | >::type, | |
114 | char_h | |
115 | > | |
116 | )); | |
117 | ||
118 | // test_with_first_good | |
119 | BOOST_MPL_ASSERT(( | |
120 | equal_to< | |
121 | get_result< | |
122 | apply_wrap2<one_of<one_char, test_fail>, str_hello, start> | |
123 | >::type, | |
124 | char_h | |
125 | > | |
126 | )); | |
127 | ||
128 | // test_with_second_good | |
129 | BOOST_MPL_ASSERT(( | |
130 | equal_to< | |
131 | get_result< | |
132 | apply_wrap2<one_of<test_fail, one_char>, str_hello, start> | |
133 | >::type, | |
134 | char_h | |
135 | > | |
136 | )); | |
137 | ||
138 | // test_with_two_bad | |
139 | BOOST_MPL_ASSERT(( | |
140 | is_error<apply_wrap2<one_of<test_fail, test_fail>, str_hello, start> > | |
141 | )); | |
142 | ||
143 | // test_error_is_the_last_error | |
144 | BOOST_MPL_ASSERT(( | |
145 | equal_to< | |
146 | next_char<start, char_h>::type, | |
147 | get_position< | |
148 | apply_wrap2< | |
149 | one_of<test_fail, test_fail_later>, | |
150 | str_hello, | |
151 | start | |
152 | > | |
153 | >::type | |
154 | > | |
155 | )); | |
156 | } | |
157 | ||
158 |