token.cpp 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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/token.hpp>
  6. #include <boost/metaparse/keyword.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/get_remaining.hpp>
  11. #include "common.hpp"
  12. #include <boost/mpl/equal_to.hpp>
  13. #include <boost/mpl/apply.hpp>
  14. #include <boost/mpl/equal.hpp>
  15. #include <boost/mpl/assert.hpp>
  16. #include "test_case.hpp"
  17. namespace
  18. {
  19. using boost::metaparse::keyword;
  20. using boost::metaparse::token;
  21. using boost::mpl::list_c;
  22. typedef list_c<char, 'h', 'e', 'l', 'l', 'o', ' ', '\t'> str_hello_t;
  23. typedef keyword<str_hello, int13> test_parser;
  24. typedef token<test_parser> a_test_token;
  25. }
  26. BOOST_METAPARSE_TEST_CASE(token)
  27. {
  28. using boost::metaparse::get_result;
  29. using boost::metaparse::start;
  30. using boost::metaparse::get_remaining;
  31. using boost::metaparse::is_error;
  32. using boost::mpl::equal_to;
  33. using boost::mpl::apply_wrap2;
  34. using boost::mpl::equal;
  35. // test_no_space
  36. BOOST_MPL_ASSERT((
  37. equal_to<
  38. get_result<apply_wrap2<a_test_token, str_hello, start> >::type,
  39. get_result<apply_wrap2<test_parser, str_hello, start> >::type
  40. >
  41. ));
  42. // test_spaces
  43. BOOST_MPL_ASSERT((
  44. equal_to<
  45. get_result<apply_wrap2<a_test_token, str_hello_t, start> >::type,
  46. get_result<apply_wrap2<test_parser, str_hello, start> >::type
  47. >
  48. ));
  49. // test_spaces_consumed
  50. BOOST_MPL_ASSERT((
  51. equal<
  52. get_remaining<apply_wrap2<a_test_token, str_hello_t, start> >::type,
  53. str_
  54. >
  55. ));
  56. // test_fail
  57. BOOST_MPL_ASSERT((is_error<apply_wrap2<a_test_token, str_, start> >));
  58. }