space.cpp 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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/space.hpp>
  6. #include <boost/metaparse/is_error.hpp>
  7. #include <boost/metaparse/start.hpp>
  8. #include <boost/metaparse/get_result.hpp>
  9. #include "common.hpp"
  10. #include <boost/mpl/equal_to.hpp>
  11. #include <boost/mpl/apply_wrap.hpp>
  12. #include <boost/mpl/char.hpp>
  13. #include <boost/mpl/assert.hpp>
  14. #include "test_case.hpp"
  15. namespace
  16. {
  17. using boost::mpl::list_c;
  18. typedef list_c<char, '\t', 'e', 'l', 'l', 'o'> str_with_t;
  19. typedef list_c<char, '\n', 'e', 'l', 'l', 'o'> str_with_n;
  20. typedef list_c<char, '\r', 'e', 'l', 'l', 'o'> str_with_r;
  21. }
  22. BOOST_METAPARSE_TEST_CASE(space)
  23. {
  24. using boost::metaparse::is_error;
  25. using boost::metaparse::space;
  26. using boost::metaparse::start;
  27. using boost::metaparse::get_result;
  28. using boost::mpl::apply_wrap2;
  29. using boost::mpl::equal_to;
  30. using boost::mpl::char_;
  31. // test_with_text
  32. BOOST_MPL_ASSERT((is_error<apply_wrap2<space, str_hello, start> >));
  33. // test_with_space
  34. BOOST_MPL_ASSERT((
  35. equal_to<
  36. get_result<apply_wrap2<space, str__ello, start> >::type,
  37. char_<' '>
  38. >
  39. ));
  40. // test_with_tab
  41. BOOST_MPL_ASSERT((
  42. equal_to<
  43. get_result<apply_wrap2<space, str_with_t, start> >::type,
  44. char_<'\t'>
  45. >
  46. ));
  47. // test_with_line_feed
  48. BOOST_MPL_ASSERT((
  49. equal_to<
  50. get_result<apply_wrap2<space, str_with_n, start> >::type,
  51. char_<'\n'>
  52. >
  53. ));
  54. // test_with_c_return
  55. BOOST_MPL_ASSERT((
  56. equal_to<
  57. get_result<apply_wrap2<space, str_with_r, start> >::type,
  58. char_<'\r'>
  59. >
  60. ));
  61. // test_with_empty_string
  62. BOOST_MPL_ASSERT((is_error<apply_wrap2<space, str_, start> >));
  63. }