transform.cpp 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. #include <boost/metaparse/transform.hpp>
  6. #include <boost/metaparse/is_error.hpp>
  7. #include <boost/metaparse/start.hpp>
  8. #include <boost/metaparse/get_result.hpp>
  9. #include <boost/metaparse/repeated.hpp>
  10. #include <boost/metaparse/one_char.hpp>
  11. #include "common.hpp"
  12. #include <boost/mpl/equal_to.hpp>
  13. #include <boost/mpl/always.hpp>
  14. #include <boost/mpl/apply_wrap.hpp>
  15. #include <boost/mpl/front.hpp>
  16. #include <boost/mpl/assert.hpp>
  17. #include "test_case.hpp"
  18. namespace
  19. {
  20. using boost::metaparse::repeated;
  21. using boost::metaparse::one_char;
  22. using boost::mpl::always;
  23. typedef always<char_x> f;
  24. typedef repeated<one_char> repeated_one_char;
  25. struct get_front
  26. {
  27. typedef get_front type;
  28. template <class C>
  29. struct apply : boost::mpl::front<C> {};
  30. };
  31. }
  32. BOOST_METAPARSE_TEST_CASE(transform)
  33. {
  34. using boost::metaparse::get_result;
  35. using boost::metaparse::transform;
  36. using boost::metaparse::start;
  37. using boost::metaparse::is_error;
  38. using boost::mpl::equal_to;
  39. using boost::mpl::apply_wrap2;
  40. // test_normal_case
  41. BOOST_MPL_ASSERT((
  42. equal_to<
  43. get_result<apply_wrap2<transform<lit_h, f>, str_hello, start> >::type,
  44. char_x
  45. >
  46. ));
  47. // test_parser_fails
  48. BOOST_MPL_ASSERT((
  49. is_error<apply_wrap2<transform<lit_x, f>, str_hello, start> >
  50. ));
  51. // test_empty_input
  52. BOOST_MPL_ASSERT((is_error<apply_wrap2<transform<lit_h, f>, str_, start> >));
  53. // test_tranformation_functions_arg
  54. BOOST_MPL_ASSERT((
  55. equal_to<
  56. get_result<
  57. apply_wrap2<transform<repeated_one_char, get_front>, str_hello, start>
  58. >::type,
  59. char_h
  60. >
  61. ));
  62. }