repeated_one_of1.cpp 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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/repeated_one_of1.hpp>
  6. #include <boost/metaparse/one_char.hpp>
  7. #include <boost/metaparse/fail.hpp>
  8. #include <boost/metaparse/keyword.hpp>
  9. #include <boost/metaparse/is_error.hpp>
  10. #include <boost/metaparse/start.hpp>
  11. #include <boost/metaparse/get_result.hpp>
  12. #include "common.hpp"
  13. #include <boost/mpl/equal_to.hpp>
  14. #include <boost/mpl/apply_wrap.hpp>
  15. #include <boost/mpl/list.hpp>
  16. #include <boost/mpl/vector_c.hpp>
  17. #include <boost/mpl/equal.hpp>
  18. #include <boost/mpl/assert.hpp>
  19. #include "test_case.hpp"
  20. BOOST_METAPARSE_TEST_CASE(repeated_one_of1)
  21. {
  22. using boost::metaparse::fail;
  23. using boost::metaparse::is_error;
  24. using boost::metaparse::repeated_one_of1;
  25. using boost::metaparse::start;
  26. using boost::metaparse::get_result;
  27. using boost::metaparse::one_char;
  28. using boost::metaparse::keyword;
  29. using boost::mpl::apply_wrap2;
  30. using boost::mpl::equal;
  31. using boost::mpl::list;
  32. using boost::mpl::vector_c;
  33. typedef fail<test_failure> test_fail;
  34. // test0
  35. BOOST_MPL_ASSERT((
  36. is_error<apply_wrap2<repeated_one_of1< >, str_hello, start> >
  37. ));
  38. // test_good_sequence
  39. BOOST_MPL_ASSERT((
  40. equal<
  41. get_result<
  42. apply_wrap2<repeated_one_of1<one_char>, str_hello, start>
  43. >::type,
  44. vector_c<char, 'h', 'e', 'l', 'l', 'o'>
  45. >
  46. ));
  47. // test_1_with_bad
  48. BOOST_MPL_ASSERT((
  49. is_error<apply_wrap2<repeated_one_of1<test_fail>, str_hello, start> >
  50. ));
  51. // test_2_with_first_good
  52. BOOST_MPL_ASSERT((
  53. equal<
  54. get_result<
  55. apply_wrap2<repeated_one_of1<one_char, test_fail>, str_hello, start>
  56. >::type,
  57. vector_c<char, 'h', 'e', 'l', 'l', 'o'>
  58. >
  59. ));
  60. // test_2_with_second_good
  61. BOOST_MPL_ASSERT((
  62. equal<
  63. get_result<
  64. apply_wrap2<repeated_one_of1<test_fail, one_char>, str_hello, start>
  65. >::type,
  66. vector_c<char, 'h', 'e', 'l', 'l', 'o'>
  67. >
  68. ));
  69. typedef keyword<str_h, char_h> keyword_h;
  70. typedef keyword<str_e, char_e> keyword_e;
  71. typedef keyword<str_l, char_l> keyword_l;
  72. // test_accept_any_argument
  73. BOOST_MPL_ASSERT((
  74. equal<
  75. get_result<
  76. apply_wrap2<
  77. repeated_one_of1<keyword_h, keyword_e, keyword_l>,
  78. str_hello,
  79. start
  80. >
  81. >::type,
  82. list<char_h, char_e, char_l, char_l>
  83. >
  84. ));
  85. }