1 | /*============================================================================= |
2 | Copyright (c) 2001-2010 Joel de Guzman |
3 | |
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 <boost/spirit/include/qi_expect.hpp> |
8 | |
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 | |
19 | #include <boost/core/lightweight_test.hpp> |
20 | #include <boost/fusion/include/vector.hpp> |
21 | #include <boost/fusion/include/at.hpp> |
22 | #include <boost/phoenix/core.hpp> |
23 | #include <boost/phoenix/operator.hpp> |
24 | #include <boost/phoenix/statement.hpp> |
25 | |
26 | #include <string> |
27 | #include <iostream> |
28 | #include "test.hpp" |
29 | |
30 | int |
31 | main() |
32 | { |
33 | using namespace boost::spirit; |
34 | using namespace boost::spirit::ascii; |
35 | using spirit_test::test; |
36 | using spirit_test::print_info; |
37 | using boost::spirit::qi::expectation_failure; |
38 | |
39 | { |
40 | try |
41 | { |
42 | BOOST_TEST((test("aa" , char_ > char_))); |
43 | BOOST_TEST((test("aaa" , char_ > char_ > char_('a')))); |
44 | BOOST_TEST((test("xi" , char_('x') > char_('i')))); |
45 | BOOST_TEST((!test("xi" , char_('y') > char_('o')))); // should not throw! |
46 | BOOST_TEST((test("xin" , char_('x') > char_('i') > char_('n')))); |
47 | BOOST_TEST((!test("xi" , char_('x') > char_('o')))); |
48 | } |
49 | catch (expectation_failure<char const*> const& x) |
50 | { |
51 | std::cout << "expected: " ; print_info(what: x.what_); |
52 | std::cout << "got: \"" << x.first << '"' << std::endl; |
53 | |
54 | BOOST_TEST(boost::get<std::string>(x.what_.value) == "o" ); |
55 | BOOST_TEST(std::string(x.first, x.last) == "i" ); |
56 | } |
57 | } |
58 | |
59 | { |
60 | try |
61 | { |
62 | BOOST_TEST((test(" a a" , char_ > char_, space))); |
63 | BOOST_TEST((test(" x i" , char_('x') > char_('i'), space))); |
64 | BOOST_TEST((!test(" x i" , char_('x') > char_('o'), space))); |
65 | } |
66 | catch (expectation_failure<char const*> const& x) |
67 | { |
68 | std::cout << "expected: " ; print_info(what: x.what_); |
69 | std::cout << "got: \"" << x.first << '"' << std::endl; |
70 | |
71 | BOOST_TEST(boost::get<std::string>(x.what_.value) == "o" ); |
72 | BOOST_TEST(std::string(x.first, x.last) == "i" ); |
73 | } |
74 | } |
75 | |
76 | { |
77 | try |
78 | { |
79 | BOOST_TEST((test("aA" , no_case[char_('a') > 'a']))); |
80 | BOOST_TEST((test("BEGIN END" , no_case[lit("begin" ) > "end" ], space))); |
81 | BOOST_TEST((!test("BEGIN END" , no_case[lit("begin" ) > "nend" ], space))); |
82 | } |
83 | catch (expectation_failure<char const*> const& x) |
84 | { |
85 | std::cout << "expected: " ; print_info(what: x.what_); |
86 | std::cout << "got: \"" << x.first << '"' << std::endl; |
87 | |
88 | BOOST_TEST(x.what_.tag == "no-case-literal-string" ); |
89 | BOOST_TEST(boost::get<std::string>(x.what_.value) == "nend" ); |
90 | BOOST_TEST(std::string(x.first, x.last) == "END" ); |
91 | } |
92 | } |
93 | |
94 | { |
95 | using boost::spirit::qi::rule; |
96 | using boost::spirit::eps; |
97 | rule<const wchar_t*, void(int)> r; |
98 | r = eps > eps(_r1); |
99 | } |
100 | |
101 | return boost::report_errors(); |
102 | } |
103 | |
104 | |