spaces.cpp 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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/spaces.hpp>
  6. #include <boost/metaparse/is_error.hpp>
  7. #include <boost/metaparse/start.hpp>
  8. #include <boost/metaparse/get_remaining.hpp>
  9. #include "common.hpp"
  10. #include <boost/mpl/equal_to.hpp>
  11. #include <boost/mpl/apply_wrap.hpp>
  12. #include <boost/mpl/not.hpp>
  13. #include <boost/mpl/equal.hpp>
  14. #include <boost/mpl/assert.hpp>
  15. #include "test_case.hpp"
  16. namespace
  17. {
  18. using boost::mpl::list_c;
  19. typedef list_c<char, 'e', 'l', 'l', 'o'> str_ello;
  20. typedef
  21. list_c<char, ' ', '\t', '\n', '\r', 'e', 'l', 'l', 'o'>
  22. str_____ello;
  23. }
  24. BOOST_METAPARSE_TEST_CASE(spaces)
  25. {
  26. using boost::metaparse::is_error;
  27. using boost::metaparse::spaces;
  28. using boost::metaparse::start;
  29. using boost::metaparse::get_remaining;
  30. using boost::mpl::apply_wrap2;
  31. using boost::mpl::not_;
  32. using boost::mpl::equal;
  33. // test_reject_no_space
  34. BOOST_MPL_ASSERT((
  35. is_error<apply_wrap2<spaces, str_hello, start> >
  36. ));
  37. // test_accept_one_space
  38. BOOST_MPL_ASSERT((
  39. not_<is_error<apply_wrap2<spaces, str__ello, start> > >
  40. ));
  41. // test_accept_only_space
  42. BOOST_MPL_ASSERT((
  43. equal<get_remaining<apply_wrap2<spaces, str__ello, start> >::type, str_ello>
  44. ));
  45. // test_accept_all_spaces
  46. BOOST_MPL_ASSERT((not_<is_error<apply_wrap2<spaces, str_____ello,start> > >));
  47. // test_consume_all_spaces
  48. BOOST_MPL_ASSERT((
  49. equal<
  50. get_remaining<apply_wrap2<spaces, str_____ello, start> >::type,
  51. str_ello
  52. >
  53. ));
  54. }