one_of_c.cpp 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. // Copyright Abel Sinkovics (abel@sinkovics.hu) 2013.
  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/one_of_c.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(one_of_c)
  15. {
  16. using boost::metaparse::is_error;
  17. using boost::metaparse::one_of_c;
  18. using boost::metaparse::start;
  19. using boost::metaparse::get_result;
  20. using boost::mpl::apply_wrap2;
  21. using boost::mpl::equal_to;
  22. // test0
  23. BOOST_MPL_ASSERT((is_error<apply_wrap2<one_of_c< >, str_hello, start> >));
  24. // test_1_with_good
  25. BOOST_MPL_ASSERT((
  26. equal_to<
  27. get_result<apply_wrap2<one_of_c<'h'>, str_hello, start> >::type,
  28. char_h
  29. >
  30. ));
  31. // test_1_with_bad
  32. BOOST_MPL_ASSERT((
  33. is_error<apply_wrap2<one_of_c<'x'>, str_hello, start> >
  34. ));
  35. // test_2_with_two_good
  36. BOOST_MPL_ASSERT((
  37. equal_to<
  38. get_result<apply_wrap2<one_of_c<'h', 'x'>, str_hello, start> >::type,
  39. char_h
  40. >
  41. ));
  42. // test_2_with_first_good
  43. BOOST_MPL_ASSERT((
  44. equal_to<
  45. get_result<apply_wrap2<one_of_c<'h', 'x'>, str_hello, start> >::type,
  46. char_h
  47. >
  48. ));
  49. // test_2_with_second_good
  50. BOOST_MPL_ASSERT((
  51. equal_to<
  52. get_result<apply_wrap2<one_of_c<'x', 'h'>, str_hello, start> >::type,
  53. char_h
  54. >
  55. ));
  56. // test_2_with_two_bad
  57. BOOST_MPL_ASSERT((
  58. is_error<apply_wrap2<one_of_c<'x', 'y'>, str_hello, start> >
  59. ));
  60. }