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 #include <boost/metaparse/transform_error_message.hpp>
7 #include <boost/metaparse/start.hpp>
8 #include <boost/metaparse/string.hpp>
9 #include <boost/metaparse/reject.hpp>
10 #include <boost/metaparse/lit_c.hpp>
11 #include <boost/metaparse/get_position.hpp>
12 #include <boost/metaparse/error/literal_expected.hpp>
13
14 #include <boost/mpl/assert.hpp>
15
16 #include <boost/type_traits.hpp>
17
18 #include "test_case.hpp"
19
20 using boost::metaparse::reject;
21 using boost::metaparse::get_position;
22
23 namespace
24 {
25 template <class OldMsg>
26 struct new_message
27 {
28 typedef new_message type;
29 };
30
31 struct change_message
32 {
33 typedef change_message type;
34
35 template <class Msg>
36 struct apply : new_message<Msg> {};
37 };
38 }
39
BOOST_METAPARSE_TEST_CASE(transform_error_message)40 BOOST_METAPARSE_TEST_CASE(transform_error_message)
41 {
42 using boost::metaparse::transform_error_message;
43 using boost::metaparse::start;
44 using boost::metaparse::string;
45 using boost::metaparse::lit_c;
46 using boost::metaparse::error::literal_expected;
47
48 using boost::is_same;
49
50 typedef string<'H','e','l','l','o'> s;
51
52 // test_transform_error_message_does_not_change_accept
53 BOOST_MPL_ASSERT((
54 is_same<
55 lit_c<'H'>::apply<s, start>::type,
56 transform_error_message<lit_c<'H'>, change_message>::apply<s, start>::type
57 >
58 ));
59
60 // test_transform_is_called
61 BOOST_MPL_ASSERT((
62 is_same<
63 reject<new_message<literal_expected<'x'> >, start>,
64 transform_error_message<lit_c<'x'>, change_message>::apply<s, start>::type
65 >
66 ));
67 }
68
69