repeated_one_of.cpp 2.5 KB

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