last_of.cpp 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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/last_of.hpp>
  6. #include <boost/metaparse/is_error.hpp>
  7. #include <boost/metaparse/start.hpp>
  8. #include <boost/metaparse/get_result.hpp>
  9. #include "common.hpp"
  10. #include <boost/mpl/equal_to.hpp>
  11. #include <boost/mpl/apply_wrap.hpp>
  12. #include <boost/mpl/assert.hpp>
  13. #include "test_case.hpp"
  14. BOOST_METAPARSE_TEST_CASE(last_of)
  15. {
  16. using boost::metaparse::get_result;
  17. using boost::metaparse::last_of;
  18. using boost::metaparse::start;
  19. using boost::metaparse::is_error;
  20. using boost::mpl::equal_to;
  21. using boost::mpl::apply_wrap2;
  22. // test_one_char
  23. BOOST_MPL_ASSERT((
  24. equal_to<
  25. get_result<apply_wrap2<last_of<lit_h>, str_hello, start> >::type,
  26. char_h
  27. >
  28. ));
  29. // test_two_chars
  30. BOOST_MPL_ASSERT((
  31. equal_to<
  32. get_result<apply_wrap2<last_of<lit_h, lit_e>, str_hello, start> >::type,
  33. char_e
  34. >
  35. ));
  36. // test_first_fails
  37. BOOST_MPL_ASSERT((
  38. is_error<apply_wrap2<last_of<lit_x, lit_e>, str_hello, start> >
  39. ));
  40. // test_second_fails
  41. BOOST_MPL_ASSERT((
  42. is_error<apply_wrap2<last_of<lit_h, lit_x>, str_hello, start> >
  43. ));
  44. // test_empty_input
  45. BOOST_MPL_ASSERT((
  46. is_error<apply_wrap2<last_of<lit_h, lit_e>, str_, start> >
  47. ));
  48. // test_three_chars
  49. BOOST_MPL_ASSERT((
  50. equal_to<
  51. get_result<
  52. apply_wrap2<last_of<lit_h, lit_e, lit_l>, str_hello, start>
  53. >::type,
  54. char_l
  55. >
  56. ));
  57. }