]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/spirit/test/qi/expectd.cpp
1 /*=============================================================================
2 Copyright (c) 2001-2010 Joel de Guzman
3 Copyright (c) 2016 Frank Hein, maxence business consulting gmbh
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 #include <boost/detail/lightweight_test.hpp>
9 #include <boost/spirit/include/qi_operator.hpp>
10 #include <boost/spirit/include/qi_char.hpp>
11 #include <boost/spirit/include/qi_string.hpp>
12 #include <boost/spirit/include/qi_numeric.hpp>
13 #include <boost/spirit/include/qi_directive.hpp>
14 #include <boost/spirit/include/qi_action.hpp>
15 #include <boost/spirit/include/qi_nonterminal.hpp>
16 #include <boost/spirit/include/qi_auxiliary.hpp>
17 #include <boost/spirit/include/support_argument.hpp>
18 #include <boost/fusion/include/vector.hpp>
19 #include <boost/fusion/include/at.hpp>
20 #include <boost/spirit/include/phoenix_core.hpp>
21 #include <boost/spirit/include/phoenix_operator.hpp>
22 #include <boost/spirit/include/phoenix_statement.hpp>
31 using namespace boost::spirit
;
32 using namespace boost::spirit::ascii
;
33 using spirit_test::test
;
34 using spirit_test::print_info
;
35 using boost::spirit::qi::expectation_failure
;
41 BOOST_TEST((test("aa", expect
[char_
>> char_
])));
42 BOOST_TEST((test("aaa", expect
[char_
>> char_
>> char_('a')])));
43 BOOST_TEST((test("xi", expect
[char_('x') >> char_('i')])));
44 BOOST_TEST((test("xin", expect
[char_('x') >> char_('i') >> char_('n')])));
45 BOOST_TEST((!test("xi", expect
[char_('y')]))); // should throw!
47 catch (expectation_failure
<char const*> const& x
)
49 std::cout
<< "expected: "; print_info(x
.what_
);
50 std::cout
<< "got: \"" << x
.first
<< '"' << std::endl
;
52 BOOST_TEST(boost::get
<std::string
>(x
.what_
.value
) == "y");
53 BOOST_TEST(std::string(x
.first
, x
.last
) == "xi");
60 BOOST_TEST((!test("xi", expect
[char_('x') >> char_('o')])));
62 catch (expectation_failure
<char const*> const& x
)
64 std::cout
<< "expected: "; print_info(x
.what_
);
65 std::cout
<< "got: \"" << x
.first
<< '"' << std::endl
;
67 BOOST_TEST(std::string(x
.first
, x
.last
) == "xi");
68 BOOST_TEST(x
.what_
.tag
== "sequence");
75 BOOST_TEST((!test(" x i", expect
[char_('x') >> char_('o')], space
)));
77 catch (expectation_failure
<char const*> const& x
)
79 std::cout
<< "expected: "; print_info(x
.what_
);
80 std::cout
<< "got: \"" << x
.first
<< '"' << std::endl
;
82 BOOST_TEST(std::string(x
.first
, x
.last
) == " x i");
83 BOOST_TEST(x
.what_
.tag
== "sequence");
90 BOOST_TEST((test(" a a", expect
[char_
>> char_
], space
)));
91 BOOST_TEST((test(" x i", expect
[char_('x') >> char_('i')], space
)));
92 BOOST_TEST((!test(" x i", expect
[char_('y')], space
)));
94 catch (expectation_failure
<char const*> const& x
)
96 std::cout
<< "expected: "; print_info(x
.what_
);
97 std::cout
<< "got: \"" << x
.first
<< '"' << std::endl
;
99 BOOST_TEST(boost::get
<std::string
>(x
.what_
.value
) == "y");
100 BOOST_TEST(std::string(x
.first
, x
.last
) == "x i");
107 BOOST_TEST((test("aA", expect
[no_case
[char_('a') >> 'a']])));
108 BOOST_TEST((test("BEGIN END", expect
[no_case
[lit("begin") >> "end"]], space
)));
109 BOOST_TEST((!test("BEGIN END", expect
[no_case
[lit("begin") >> "nend"]], space
)));
111 catch (expectation_failure
<char const*> const& x
)
113 std::cout
<< "expected: "; print_info(x
.what_
);
114 std::cout
<< "got: \"" << x
.first
<< '"' << std::endl
;
116 BOOST_TEST(x
.what_
.tag
== "sequence");
117 BOOST_TEST(std::string(x
.first
, x
.last
) == "BEGIN END");
122 using boost::spirit::qi::rule
;
123 using boost::spirit::eps
;
124 rule
<const wchar_t*, void(int)> r
;
125 r
= expect
[eps(_r1
)];
128 return boost::report_errors();