match_manip1.cpp 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. /*=============================================================================
  2. Copyright (c) 2001-2010 Hartmut Kaiser
  3. Copyright (c) 2001-2010 Joel de Guzman
  4. Distributed under the Boost Software License, Version 1.0. (See accompanying
  5. file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  6. =============================================================================*/
  7. #include "match_manip.hpp"
  8. int
  9. main()
  10. {
  11. using boost::spirit::qi::_1;
  12. using boost::spirit::qi::_2;
  13. using boost::spirit::qi::match;
  14. using boost::spirit::qi::phrase_match;
  15. using boost::spirit::qi::typed_stream;
  16. using boost::spirit::qi::stream;
  17. using boost::spirit::qi::int_;
  18. using namespace boost::spirit::ascii;
  19. namespace fusion = boost::fusion;
  20. namespace phx = boost::phoenix;
  21. {
  22. char c = '\0';
  23. BOOST_TEST(test( "a",
  24. char_[phx::ref(c) = _1]
  25. ) && c == 'a');
  26. c = '\0';
  27. BOOST_TEST(test( "a",
  28. match(char_[phx::ref(c) = _1])
  29. ) && c == 'a');
  30. c = '\0';
  31. BOOST_TEST(test( " a",
  32. phrase_match(char_[phx::ref(c) = _1], space)
  33. ) && c == 'a');
  34. c = '\0';
  35. BOOST_TEST(test( "a",
  36. match(char_, c)
  37. ) && c == 'a');
  38. c = '\0';
  39. BOOST_TEST(test( " a",
  40. phrase_match(char_, space, c)
  41. ) && c == 'a');
  42. }
  43. {
  44. ///////////////////////////////////////////////////////////////////////
  45. typedef typed_stream<char> char_stream_type;
  46. char_stream_type const char_stream = char_stream_type();
  47. typedef typed_stream<int> int_stream_type;
  48. int_stream_type const int_stream = int_stream_type();
  49. ///////////////////////////////////////////////////////////////////////
  50. char c = '\0';
  51. BOOST_TEST(test( "a",
  52. char_stream[phx::ref(c) = _1]
  53. ) && c == 'a');
  54. c = '\0';
  55. BOOST_TEST(test( "a",
  56. match(char_stream[phx::ref(c) = _1])
  57. ) && c == 'a');
  58. c = '\0';
  59. BOOST_TEST(test( " a",
  60. phrase_match(char_stream[phx::ref(c) = _1], space)
  61. ) && c == 'a');
  62. int i = 0;
  63. BOOST_TEST(test( "42",
  64. int_stream[phx::ref(i) = _1]
  65. ) && i == 42);
  66. i = 0;
  67. BOOST_TEST(test( "42",
  68. match(int_stream[phx::ref(i) = _1])
  69. ) && i == 42);
  70. i = 0;
  71. BOOST_TEST(test( " 42",
  72. phrase_match(int_stream[phx::ref(i) = _1], space)
  73. ) && i == 42);
  74. ///////////////////////////////////////////////////////////////////////
  75. c = '\0';
  76. BOOST_TEST(test( "a",
  77. match(stream, c)
  78. ) && c == 'a');
  79. c = '\0';
  80. BOOST_TEST(test( " a",
  81. phrase_match(stream, space, c)
  82. ) && c == 'a');
  83. i = 0;
  84. BOOST_TEST(test( "42",
  85. match(stream, i)
  86. ) && i == 42);
  87. i = 0;
  88. BOOST_TEST(test( " 42",
  89. phrase_match(stream, space, i)
  90. ) && i == 42);
  91. }
  92. return boost::report_errors();
  93. }