return_.cpp 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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/return_.hpp>
  6. #include <boost/metaparse/start.hpp>
  7. #include <boost/metaparse/get_result.hpp>
  8. #include <boost/metaparse/get_remaining.hpp>
  9. #include <boost/metaparse/get_position.hpp>
  10. #include "common.hpp"
  11. #include <boost/mpl/equal_to.hpp>
  12. #include <boost/mpl/apply_wrap.hpp>
  13. #include <boost/mpl/assert.hpp>
  14. #include "test_case.hpp"
  15. namespace
  16. {
  17. using boost::metaparse::return_;
  18. using boost::mpl::apply_wrap2;
  19. typedef apply_wrap2<return_<int1>, int2, int3> acc;
  20. typedef return_<char_x> return_x;
  21. }
  22. BOOST_METAPARSE_TEST_CASE(return)
  23. {
  24. using boost::metaparse::get_result;
  25. using boost::metaparse::get_remaining;
  26. using boost::metaparse::get_position;
  27. using boost::metaparse::start;
  28. using boost::mpl::equal_to;
  29. // test_for_non_empty_string
  30. BOOST_MPL_ASSERT((
  31. equal_to<get_result<apply_wrap2<return_x, str_hello, start> >::type, char_x>
  32. ));
  33. // test_for_empty_string
  34. BOOST_MPL_ASSERT((
  35. equal_to<get_result<apply_wrap2<return_x, str_, start> >::type, char_x>
  36. ));
  37. // test_get_result
  38. BOOST_MPL_ASSERT((equal_to<int1, get_result<acc>::type>));
  39. // test_get_remaining
  40. BOOST_MPL_ASSERT((equal_to<int2, get_remaining<acc>::type>));
  41. // test_get_position
  42. BOOST_MPL_ASSERT((equal_to<int3, get_position<acc>::type>));
  43. }