keyword.cpp 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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/keyword.hpp>
  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 "common.hpp"
  11. #include <boost/mpl/equal_to.hpp>
  12. #include <boost/mpl/apply_wrap.hpp>
  13. #include <boost/mpl/equal.hpp>
  14. #include <boost/mpl/assert.hpp>
  15. #include "test_case.hpp"
  16. namespace
  17. {
  18. using boost::metaparse::keyword;
  19. using boost::mpl::list_c;
  20. typedef
  21. list_c<char, 'h','e','l','l','o',' ','w','o','r','l','d'>
  22. str_hello_world;
  23. typedef list_c<char, 'h','e','l','l','x'> str_hellx;
  24. typedef list_c<char, 'h','x','l','l','o'> str_hxllo;
  25. typedef keyword<str_hello> keyword_hello;
  26. }
  27. BOOST_METAPARSE_TEST_CASE(keyword)
  28. {
  29. using boost::metaparse::get_result;
  30. using boost::metaparse::start;
  31. using boost::metaparse::is_error;
  32. using boost::metaparse::get_remaining;
  33. using boost::mpl::equal_to;
  34. using boost::mpl::apply_wrap2;
  35. using boost::mpl::equal;
  36. // test_result_type
  37. BOOST_MPL_ASSERT((
  38. equal_to<
  39. get_result<
  40. apply_wrap2<keyword<str_hello, char_l>, str_hello, start>
  41. >::type,
  42. char_l
  43. >
  44. ));
  45. // test_empty_keyword
  46. BOOST_MPL_ASSERT((
  47. equal_to<
  48. get_result<apply_wrap2<keyword<str_, char_l>, str_hello, start> >::type,
  49. char_l
  50. >
  51. ));
  52. // test_empty_input
  53. BOOST_MPL_ASSERT((is_error<apply_wrap2<keyword_hello, str_, start> >));
  54. // test_itself
  55. BOOST_MPL_ASSERT((
  56. equal<
  57. get_remaining<apply_wrap2<keyword_hello, str_hello, start> >::type,
  58. str_
  59. >
  60. ));
  61. // test_more_than_itself
  62. BOOST_MPL_ASSERT((
  63. equal<
  64. get_remaining<apply_wrap2<keyword_hello, str_hello_world, start> >::type,
  65. list_c<char, ' ', 'w', 'o', 'r', 'l', 'd'>
  66. >
  67. ));
  68. // test_no_match_at_end
  69. BOOST_MPL_ASSERT((is_error<apply_wrap2<keyword_hello, str_hellx, start> >));
  70. // test_no_match_in_the_middle
  71. BOOST_MPL_ASSERT((is_error<apply_wrap2<keyword_hello, str_hxllo, start> >));
  72. }