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/detail/lightweight_test.hpp>
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/spirit/include/phoenix_core.hpp>
20 #include <boost/spirit/include/phoenix_operator.hpp>
21 #include <boost/spirit/include/phoenix_statement.hpp>
22 
23 #include <string>
24 #include <iostream>
25 #include "test.hpp"
26 
27 int
main()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         try
38         {
39             BOOST_TEST((test("aa", char_ > char_)));
40             BOOST_TEST((test("aaa", char_ > char_ > char_('a'))));
41             BOOST_TEST((test("xi", char_('x') > char_('i'))));
42             BOOST_TEST((!test("xi", char_('y') > char_('o')))); // should not throw!
43             BOOST_TEST((test("xin", char_('x') > char_('i') > char_('n'))));
44             BOOST_TEST((!test("xi", char_('x') > char_('o'))));
45         }
46         catch (expectation_failure<char const*> const& x)
47         {
48             std::cout << "expected: "; print_info(x.what_);
49             std::cout << "got: \"" << x.first << '"' << std::endl;
50 
51             BOOST_TEST(boost::get<std::string>(x.what_.value) == "o");
52             BOOST_TEST(std::string(x.first, x.last) == "i");
53         }
54     }
55 
56     {
57         try
58         {
59             BOOST_TEST((test(" a a", char_ > char_, space)));
60             BOOST_TEST((test(" x i", char_('x') > char_('i'), space)));
61             BOOST_TEST((!test(" x i", char_('x') > char_('o'), space)));
62         }
63         catch (expectation_failure<char const*> const& x)
64         {
65             std::cout << "expected: "; print_info(x.what_);
66             std::cout << "got: \"" << x.first << '"' << std::endl;
67 
68             BOOST_TEST(boost::get<std::string>(x.what_.value) == "o");
69             BOOST_TEST(std::string(x.first, x.last) == "i");
70         }
71     }
72 
73     {
74         try
75         {
76             BOOST_TEST((test("aA", no_case[char_('a') > 'a'])));
77             BOOST_TEST((test("BEGIN END", no_case[lit("begin") > "end"], space)));
78             BOOST_TEST((!test("BEGIN END", no_case[lit("begin") > "nend"], space)));
79         }
80         catch (expectation_failure<char const*> const& x)
81         {
82             std::cout << "expected: "; print_info(x.what_);
83             std::cout << "got: \"" << x.first << '"' << std::endl;
84 
85             BOOST_TEST(x.what_.tag == "no-case-literal-string");
86             BOOST_TEST(boost::get<std::string>(x.what_.value) == "nend");
87             BOOST_TEST(std::string(x.first, x.last) == "END");
88         }
89     }
90 
91     {
92         using boost::spirit::qi::rule;
93         using boost::spirit::eps;
94         rule<const wchar_t*, void(int)> r;
95         r = eps > eps(_r1);
96     }
97 
98     return boost::report_errors();
99 }
100 
101