repeated1_test.hpp 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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/is_error.hpp>
  8. #include <boost/metaparse/start.hpp>
  9. #include <boost/metaparse/get_result.hpp>
  10. #include <boost/metaparse/always.hpp>
  11. #include <boost/metaparse/one_char.hpp>
  12. #include "common.hpp"
  13. #include <boost/mpl/equal_to.hpp>
  14. #include <boost/mpl/apply_wrap.hpp>
  15. #include <boost/mpl/equal.hpp>
  16. #include <boost/mpl/vector_c.hpp>
  17. #include <boost/mpl/vector.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::is_error;
  26. using boost::metaparse::always;
  27. using boost::metaparse::one_char;
  28. using boost::mpl::equal;
  29. using boost::mpl::apply_wrap2;
  30. using boost::mpl::list;
  31. using boost::mpl::vector_c;
  32. using boost::mpl::vector;
  33. typedef repeated1<letter> repeated1_letter;
  34. typedef always<one_char, int> always_int;
  35. // test_empty_input
  36. BOOST_MPL_ASSERT((is_error<apply_wrap2<repeated1_letter, str_, start> >));
  37. // test0
  38. BOOST_MPL_ASSERT((is_error<apply_wrap2<repeated1_letter, chars0, start> >));
  39. // test1
  40. BOOST_MPL_ASSERT((
  41. equal<
  42. get_result<apply_wrap2<repeated1_letter, chars1, start> >::type,
  43. vector_c<char, 'h'>
  44. >
  45. ));
  46. // test2
  47. BOOST_MPL_ASSERT((
  48. equal<
  49. get_result<apply_wrap2<repeated1_letter, chars2, start> >::type,
  50. vector_c<char, 'h', 'e'>
  51. >
  52. ));
  53. // test3
  54. BOOST_MPL_ASSERT((
  55. equal<
  56. get_result<apply_wrap2<repeated1_letter, chars3, start> >::type,
  57. vector_c<char, 'h', 'e', 'l'>
  58. >
  59. ));
  60. // test4
  61. BOOST_MPL_ASSERT((
  62. equal<
  63. get_result<apply_wrap2<repeated1_letter, chars4, start> >::type,
  64. vector_c<char, 'h', 'e', 'l', 'l'>
  65. >
  66. ));
  67. // test5
  68. BOOST_MPL_ASSERT((
  69. equal<
  70. get_result<apply_wrap2<repeated1_letter, chars5, start> >::type,
  71. vector_c<char, 'h', 'e', 'l', 'l', 'o'>
  72. >
  73. ));
  74. // test_no_extra_evaluation
  75. BOOST_MPL_ASSERT((
  76. equal<
  77. get_result<apply_wrap2<repeated1<always_int>, str_ca, start> >::type,
  78. vector<int, int>
  79. >
  80. ));
  81. }