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

source code of boost/libs/spirit/test/qi/match_manip1.cpp