transform_error_message.cpp 1.7 KB

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