middle_of.cpp 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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/middle_of.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/get_message.hpp>
  10. #include <boost/metaparse/error/unpaired.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(middle_of)
  19. {
  20. using boost::metaparse::get_result;
  21. using boost::metaparse::middle_of;
  22. using boost::metaparse::start;
  23. using boost::metaparse::is_error;
  24. using boost::metaparse::get_message;
  25. using boost::metaparse::error::unpaired;
  26. using boost::metaparse::error::literal_expected;
  27. using boost::is_same;
  28. using boost::mpl::equal_to;
  29. using boost::mpl::apply_wrap2;
  30. // test_three_chars
  31. BOOST_MPL_ASSERT((
  32. equal_to<
  33. get_result<
  34. apply_wrap2<middle_of<lit_h, lit_e, lit_l>, str_hello, start>
  35. >::type,
  36. char_e
  37. >
  38. ));
  39. // test_first_fails
  40. BOOST_MPL_ASSERT((
  41. is_error<apply_wrap2<middle_of<lit_x, lit_e, lit_l>, str_hello, start> >
  42. ));
  43. // test_second_fails
  44. BOOST_MPL_ASSERT((
  45. is_error<apply_wrap2<middle_of<lit_h, lit_x, lit_l>, str_hello, start> >
  46. ));
  47. // test_third_fails
  48. BOOST_MPL_ASSERT((
  49. is_error<apply_wrap2<middle_of<lit_h, lit_e, lit_x>, str_hello, start> >
  50. ));
  51. // test_error_message_when_third_fails
  52. BOOST_MPL_ASSERT((
  53. is_same<
  54. unpaired<1, 1, literal_expected<'x'> >,
  55. get_message<
  56. apply_wrap2<middle_of<lit_h, lit_e, lit_x>, str_hello, start>
  57. >::type
  58. >
  59. ));
  60. // test_empty_input
  61. BOOST_MPL_ASSERT((
  62. is_error<apply_wrap2<middle_of<lit_h, lit_e, lit_l>, str_, start> >
  63. ));
  64. }