one_char_test.hpp 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. // Copyright Abel Sinkovics (abel@sinkovics.hu) 2010 - 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/is_error.hpp>
  7. #include <boost/metaparse/start.hpp>
  8. #include <boost/metaparse/get_result.hpp>
  9. #include <boost/metaparse/get_remaining.hpp>
  10. #include <boost/metaparse/get_position.hpp>
  11. #include <boost/metaparse/get_line.hpp>
  12. #include <boost/metaparse/iterate_c.hpp>
  13. #include "common.hpp"
  14. #include <boost/mpl/equal_to.hpp>
  15. #include <boost/mpl/apply_wrap.hpp>
  16. #include <boost/mpl/assert.hpp>
  17. #include "test_case.hpp"
  18. namespace
  19. {
  20. using boost::metaparse::start;
  21. using boost::mpl::list_c;
  22. using boost::mpl::apply_wrap2;
  23. typedef list_c<char, 'a','\n','b'> unix_multi_line_text;
  24. typedef list_c<char, 'a','\r','\n','b'> dos_multi_line_text;
  25. typedef list_c<char, 'a','\r','b'> mac_multi_line_text;
  26. typedef apply_wrap2<oc, str_hello, start> parse_first_char;
  27. }
  28. BOOST_METAPARSE_TEST_CASE(TEST_NAME)
  29. {
  30. using boost::metaparse::get_result;
  31. using boost::metaparse::get_remaining;
  32. using boost::metaparse::get_position;
  33. using boost::metaparse::is_error;
  34. using boost::metaparse::iterate_c;
  35. using boost::metaparse::get_line;
  36. using boost::mpl::equal_to;
  37. // test_for_non_empty_string
  38. BOOST_MPL_ASSERT((equal_to<get_result<parse_first_char>::type, char_h>));
  39. // test_for_non_empty_string_second
  40. BOOST_MPL_ASSERT((
  41. equal_to<
  42. get_result<
  43. apply_wrap2<
  44. oc,
  45. get_remaining<parse_first_char>::type,
  46. get_position<parse_first_char>::type
  47. >
  48. >::type,
  49. char_e
  50. >
  51. ));
  52. // test_for_empty_string
  53. BOOST_MPL_ASSERT((is_error<apply_wrap2<oc, str_, start> >));
  54. // test_unix_multi_line_text
  55. BOOST_MPL_ASSERT((
  56. equal_to<
  57. int2,
  58. get_line<
  59. get_position<
  60. apply_wrap2<iterate_c<oc, 2>, unix_multi_line_text, start>
  61. >
  62. >
  63. >
  64. ));
  65. // test_dos_multi_line_text
  66. BOOST_MPL_ASSERT((
  67. equal_to<
  68. int2,
  69. get_line<
  70. get_position<apply_wrap2<iterate_c<oc, 3>, dos_multi_line_text, start> >
  71. >
  72. >
  73. ));
  74. // test_mac_multi_line_text
  75. BOOST_MPL_ASSERT((
  76. equal_to<
  77. int2,
  78. get_line<
  79. get_position<apply_wrap2<iterate_c<oc, 2>, mac_multi_line_text, start> >
  80. >
  81. >
  82. ));
  83. }