look_ahead.cpp 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. // Copyright Abel Sinkovics (abel@sinkovics.hu) 2011.
  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/look_ahead.hpp>
  6. #include <boost/metaparse/start.hpp>
  7. #include <boost/metaparse/get_result.hpp>
  8. #include <boost/metaparse/digit_val.hpp>
  9. #include <boost/metaparse/fail.hpp>
  10. #include <boost/metaparse/is_error.hpp>
  11. #include <boost/metaparse/get_remaining.hpp>
  12. #include "common.hpp"
  13. #include <boost/mpl/apply_wrap.hpp>
  14. #include <boost/mpl/equal_to.hpp>
  15. #include <boost/mpl/equal.hpp>
  16. #include <boost/mpl/assert.hpp>
  17. #include "test_case.hpp"
  18. BOOST_METAPARSE_TEST_CASE(look_ahead)
  19. {
  20. using boost::metaparse::get_result;
  21. using boost::metaparse::look_ahead;
  22. using boost::metaparse::digit_val;
  23. using boost::metaparse::start;
  24. using boost::metaparse::is_error;
  25. using boost::metaparse::fail;
  26. using boost::metaparse::get_remaining;
  27. using boost::mpl::equal_to;
  28. using boost::mpl::apply_wrap2;
  29. using boost::mpl::equal;
  30. // test_returns_result
  31. BOOST_MPL_ASSERT((
  32. equal_to<
  33. int1,
  34. get_result<apply_wrap2<look_ahead<digit_val>, str_1983, start> >::type
  35. >
  36. ));
  37. // test_returns_error
  38. BOOST_MPL_ASSERT((
  39. is_error<apply_wrap2<look_ahead<fail<int13> >, str_1983, start> >
  40. ));
  41. // test_doesnt_process_input
  42. BOOST_MPL_ASSERT((
  43. equal<
  44. str_1983,
  45. get_remaining<apply_wrap2<look_ahead<digit_val>, str_1983, start> >::type
  46. >
  47. ));
  48. }