repeated_test.hpp 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. // Copyright Abel Sinkovics (abel@sinkovics.hu) 2011.
  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. // This header file contains code that is reused by other cpp files
  6. #include <boost/metaparse/letter.hpp>
  7. #include <boost/metaparse/start.hpp>
  8. #include <boost/metaparse/get_result.hpp>
  9. #include <boost/metaparse/always.hpp>
  10. #include <boost/metaparse/one_char.hpp>
  11. #include "common.hpp"
  12. #include <boost/mpl/apply_wrap.hpp>
  13. #include <boost/mpl/equal.hpp>
  14. #include <boost/mpl/equal_to.hpp>
  15. #include <boost/mpl/size.hpp>
  16. #include <boost/mpl/vector.hpp>
  17. #include <boost/mpl/vector_c.hpp>
  18. #include <boost/mpl/assert.hpp>
  19. #include "test_case.hpp"
  20. BOOST_METAPARSE_TEST_CASE(TEST_NAME)
  21. {
  22. using boost::metaparse::get_result;
  23. using boost::metaparse::letter;
  24. using boost::metaparse::start;
  25. using boost::metaparse::one_char;
  26. using boost::metaparse::always;
  27. using boost::mpl::equal;
  28. using boost::mpl::equal_to;
  29. using boost::mpl::apply_wrap2;
  30. using boost::mpl::vector_c;
  31. using boost::mpl::vector;
  32. using boost::mpl::list;
  33. using boost::mpl::size;
  34. typedef repeated<letter> repeated_letter;
  35. typedef always<one_char, int> always_int;
  36. // test_empty_input
  37. BOOST_MPL_ASSERT((
  38. equal<get_result<apply_wrap2<repeated_letter, str_, start> >::type, list<> >
  39. ));
  40. // test0
  41. BOOST_MPL_ASSERT((
  42. equal<
  43. get_result<apply_wrap2<repeated_letter, chars0, start> >::type,
  44. list<>
  45. >
  46. ));
  47. // test1
  48. BOOST_MPL_ASSERT((
  49. equal<
  50. get_result<apply_wrap2<repeated_letter, chars1, start> >::type,
  51. vector_c<char, 'h'>
  52. >
  53. ));
  54. // test2
  55. BOOST_MPL_ASSERT((
  56. equal<
  57. get_result<apply_wrap2<repeated_letter, chars2, start> >::type,
  58. vector_c<char, 'h', 'e'>
  59. >
  60. ));
  61. // test3
  62. BOOST_MPL_ASSERT((
  63. equal<
  64. get_result<apply_wrap2<repeated_letter, chars3, start> >::type,
  65. vector_c<char, 'h', 'e', 'l'>
  66. >
  67. ));
  68. // test4
  69. BOOST_MPL_ASSERT((
  70. equal<
  71. get_result<apply_wrap2<repeated_letter, chars4, start> >::type,
  72. vector_c<char, 'h', 'e', 'l', 'l'>
  73. >
  74. ));
  75. // test5
  76. BOOST_MPL_ASSERT((
  77. equal<
  78. get_result<apply_wrap2<repeated_letter, chars5, start> >::type,
  79. vector_c<char, 'h', 'e', 'l', 'l', 'o'>
  80. >
  81. ));
  82. // test_length
  83. BOOST_MPL_ASSERT((
  84. equal_to<
  85. size<
  86. get_result<apply_wrap2<repeated_letter, chars3, start> >::type
  87. >::type,
  88. int3
  89. >
  90. ));
  91. // test_no_extra_evaluation
  92. BOOST_MPL_ASSERT((
  93. equal<
  94. get_result<apply_wrap2<repeated<always_int>, str_ca, start> >::type,
  95. vector<int, int>
  96. >
  97. ));
  98. }