1 | /*============================================================================= |
2 | Copyright (c) 2001-2010 Joel de Guzman |
3 | Copyright (c) 2016 Frank Hein, maxence business consulting gmbh |
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 | #include <boost/spirit/include/qi_operator.hpp> |
9 | #include <boost/spirit/include/qi_char.hpp> |
10 | #include <boost/spirit/include/qi_string.hpp> |
11 | #include <boost/spirit/include/qi_numeric.hpp> |
12 | #include <boost/spirit/include/qi_directive.hpp> |
13 | #include <boost/spirit/include/qi_action.hpp> |
14 | #include <boost/spirit/include/qi_nonterminal.hpp> |
15 | #include <boost/spirit/include/qi_auxiliary.hpp> |
16 | #include <boost/spirit/include/support_argument.hpp> |
17 | #include <boost/fusion/include/vector.hpp> |
18 | #include <boost/fusion/include/at.hpp> |
19 | #include <boost/phoenix/core.hpp> |
20 | #include <boost/phoenix/operator.hpp> |
21 | #include <boost/phoenix/statement.hpp> |
22 | |
23 | #include <string> |
24 | #include <iostream> |
25 | #include "test.hpp" |
26 | |
27 | int |
28 | main() |
29 | { |
30 | using namespace boost::spirit; |
31 | using namespace boost::spirit::ascii; |
32 | using spirit_test::test; |
33 | using spirit_test::print_info; |
34 | using boost::spirit::qi::expectation_failure; |
35 | |
36 | |
37 | { |
38 | try |
39 | { |
40 | BOOST_TEST((test("aa" , expect[char_ >> char_]))); |
41 | BOOST_TEST((test("aaa" , expect[char_ >> char_ >> char_('a')]))); |
42 | BOOST_TEST((test("xi" , expect[char_('x') >> char_('i')]))); |
43 | BOOST_TEST((test("xin" , expect[char_('x') >> char_('i') >> char_('n')]))); |
44 | BOOST_TEST((!test("xi" , expect[char_('y')]))); // should throw! |
45 | } |
46 | catch (expectation_failure<char const*> const& x) |
47 | { |
48 | std::cout << "expected: " ; print_info(what: x.what_); |
49 | std::cout << "got: \"" << x.first << '"' << std::endl; |
50 | |
51 | BOOST_TEST(boost::get<std::string>(x.what_.value) == "y" ); |
52 | BOOST_TEST(std::string(x.first, x.last) == "xi" ); |
53 | } |
54 | } |
55 | |
56 | { |
57 | try |
58 | { |
59 | BOOST_TEST((!test("xi" , expect[char_('x') >> char_('o')]))); |
60 | } |
61 | catch (expectation_failure<char const*> const& x) |
62 | { |
63 | std::cout << "expected: " ; print_info(what: x.what_); |
64 | std::cout << "got: \"" << x.first << '"' << std::endl; |
65 | |
66 | BOOST_TEST(std::string(x.first, x.last) == "xi" ); |
67 | BOOST_TEST(x.what_.tag == "sequence" ); |
68 | } |
69 | } |
70 | |
71 | { |
72 | try |
73 | { |
74 | BOOST_TEST((!test(" x i" , expect[char_('x') >> char_('o')], space))); |
75 | } |
76 | catch (expectation_failure<char const*> const& x) |
77 | { |
78 | std::cout << "expected: " ; print_info(what: x.what_); |
79 | std::cout << "got: \"" << x.first << '"' << std::endl; |
80 | |
81 | BOOST_TEST(std::string(x.first, x.last) == " x i" ); |
82 | BOOST_TEST(x.what_.tag == "sequence" ); |
83 | } |
84 | } |
85 | |
86 | { |
87 | try |
88 | { |
89 | BOOST_TEST((test(" a a" , expect[char_ >> char_], space))); |
90 | BOOST_TEST((test(" x i" , expect[char_('x') >> char_('i')], space))); |
91 | BOOST_TEST((!test(" x i" , expect[char_('y')], space))); |
92 | } |
93 | catch (expectation_failure<char const*> const& x) |
94 | { |
95 | std::cout << "expected: " ; print_info(what: x.what_); |
96 | std::cout << "got: \"" << x.first << '"' << std::endl; |
97 | |
98 | BOOST_TEST(boost::get<std::string>(x.what_.value) == "y" ); |
99 | BOOST_TEST(std::string(x.first, x.last) == "x i" ); |
100 | } |
101 | } |
102 | |
103 | { |
104 | try |
105 | { |
106 | BOOST_TEST((test("aA" , expect[no_case[char_('a') >> 'a']]))); |
107 | BOOST_TEST((test("BEGIN END" , expect[no_case[lit("begin" ) >> "end" ]], space))); |
108 | BOOST_TEST((!test("BEGIN END" , expect[no_case[lit("begin" ) >> "nend" ]], space))); |
109 | } |
110 | catch (expectation_failure<char const*> const& x) |
111 | { |
112 | std::cout << "expected: " ; print_info(what: x.what_); |
113 | std::cout << "got: \"" << x.first << '"' << std::endl; |
114 | |
115 | BOOST_TEST(x.what_.tag == "sequence" ); |
116 | BOOST_TEST(std::string(x.first, x.last) == "BEGIN END" ); |
117 | } |
118 | } |
119 | |
120 | { |
121 | using boost::spirit::qi::rule; |
122 | using boost::spirit::eps; |
123 | rule<const wchar_t*, void(int)> r; |
124 | r = expect[eps(_r1)]; |
125 | } |
126 | |
127 | return boost::report_errors(); |
128 | } |
129 | |
130 | |