1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
|
/*=============================================================================
Copyright (c) 2001-2010 Joel de Guzman
Distributed under the Boost Software License, Version 1.0. (See accompanying
file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
=============================================================================*/
#include <boost/detail/lightweight_test.hpp>
#include <boost/spirit/include/qi_operator.hpp>
#include <boost/spirit/include/qi_char.hpp>
#include <boost/spirit/include/qi_string.hpp>
#include <boost/spirit/include/qi_numeric.hpp>
#include <boost/spirit/include/qi_directive.hpp>
#include <boost/spirit/include/qi_action.hpp>
#include <boost/spirit/include/qi_nonterminal.hpp>
#include <boost/spirit/include/qi_auxiliary.hpp>
#include <boost/spirit/include/support_argument.hpp>
#include <boost/fusion/include/vector.hpp>
#include <boost/fusion/include/at.hpp>
#include <boost/spirit/include/phoenix_core.hpp>
#include <boost/spirit/include/phoenix_operator.hpp>
#include <boost/spirit/include/phoenix_statement.hpp>
#include <string>
#include <iostream>
#include "test.hpp"
int
main()
{
using namespace boost::spirit;
using namespace boost::spirit::ascii;
using spirit_test::test;
using spirit_test::print_info;
using boost::spirit::qi::expectation_failure;
{
try
{
BOOST_TEST((test("aa", char_ > char_)));
BOOST_TEST((test("aaa", char_ > char_ > char_('a'))));
BOOST_TEST((test("xi", char_('x') > char_('i'))));
BOOST_TEST((!test("xi", char_('y') > char_('o')))); // should not throw!
BOOST_TEST((test("xin", char_('x') > char_('i') > char_('n'))));
BOOST_TEST((!test("xi", char_('x') > char_('o'))));
}
catch (expectation_failure<char const*> const& x)
{
std::cout << "expected: "; print_info(x.what_);
std::cout << "got: \"" << x.first << '"' << std::endl;
BOOST_TEST(boost::get<std::string>(x.what_.value) == "o");
BOOST_TEST(std::string(x.first, x.last) == "i");
}
}
{
try
{
BOOST_TEST((test(" a a", char_ > char_, space)));
BOOST_TEST((test(" x i", char_('x') > char_('i'), space)));
BOOST_TEST((!test(" x i", char_('x') > char_('o'), space)));
}
catch (expectation_failure<char const*> const& x)
{
std::cout << "expected: "; print_info(x.what_);
std::cout << "got: \"" << x.first << '"' << std::endl;
BOOST_TEST(boost::get<std::string>(x.what_.value) == "o");
BOOST_TEST(std::string(x.first, x.last) == "i");
}
}
{
try
{
BOOST_TEST((test("aA", no_case[char_('a') > 'a'])));
BOOST_TEST((test("BEGIN END", no_case[lit("begin") > "end"], space)));
BOOST_TEST((!test("BEGIN END", no_case[lit("begin") > "nend"], space)));
}
catch (expectation_failure<char const*> const& x)
{
std::cout << "expected: "; print_info(x.what_);
std::cout << "got: \"" << x.first << '"' << std::endl;
BOOST_TEST(x.what_.tag == "no-case-literal-string");
BOOST_TEST(boost::get<std::string>(x.what_.value) == "nend");
BOOST_TEST(std::string(x.first, x.last) == "END");
}
}
{
using boost::spirit::qi::rule;
using boost::spirit::eps;
rule<const wchar_t*, void(int)> r;
r = eps > eps(_r1);
}
return boost::report_errors();
}
|