lit.cpp 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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/is_error.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 <boost/metaparse/get_message.hpp>
  11. #include <boost/metaparse/error/literal_expected.hpp>
  12. #include "common.hpp"
  13. #include <boost/mpl/equal_to.hpp>
  14. #include <boost/mpl/apply_wrap.hpp>
  15. #include <boost/mpl/assert.hpp>
  16. #include <boost/type_traits/is_same.hpp>
  17. #include "test_case.hpp"
  18. BOOST_METAPARSE_TEST_CASE(lit)
  19. {
  20. using boost::metaparse::get_result;
  21. using boost::metaparse::start;
  22. using boost::metaparse::is_error;
  23. using boost::metaparse::get_remaining;
  24. using boost::metaparse::get_position;
  25. using boost::metaparse::get_message;
  26. using boost::metaparse::error::literal_expected;
  27. using boost::mpl::equal_to;
  28. using boost::mpl::apply_wrap2;
  29. using boost::is_same;
  30. // test_accept
  31. BOOST_MPL_ASSERT((
  32. equal_to<get_result<apply_wrap2<lit_h, str_hello, start> >::type, char_h>
  33. ));
  34. // test_reject
  35. BOOST_MPL_ASSERT((is_error<apply_wrap2<lit_h, str_bello, start> >));
  36. // test_with_empty_string
  37. BOOST_MPL_ASSERT((is_error<apply_wrap2<lit_h, str_, start> >));
  38. // test_error_with_empty_string
  39. BOOST_MPL_ASSERT((
  40. is_same<
  41. literal_expected<'h'>,
  42. get_message<apply_wrap2<lit_h, str_, start> >::type
  43. >
  44. ));
  45. // test_remaining_string
  46. BOOST_MPL_ASSERT((
  47. equal_to<
  48. get_result<
  49. apply_wrap2<
  50. lit_e,
  51. get_remaining<apply_wrap2<lit_h, str_hello, start> >::type,
  52. get_position<apply_wrap2<lit_h, str_hello, start> >::type
  53. >
  54. >::type,
  55. char_e
  56. >
  57. ));
  58. }