transform_error.cpp 1.5 KB

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