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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
|
/*=============================================================================
Copyright (c) 2001-2013 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/home/x3.hpp>
#include <boost/fusion/include/vector.hpp>
#include <boost/fusion/include/at.hpp>
#include <string>
#include <iostream>
#include "test.hpp"
int
main()
{
using namespace boost::spirit;
using namespace boost::spirit::x3::ascii;
using boost::spirit::x3::lit;
using boost::spirit::x3::expect;
using spirit_test::test;
using spirit_test::test_attr;
using boost::spirit::x3::expectation_failure;
{
try
{
BOOST_TEST((test("aa", char_ >> expect[char_])));
BOOST_TEST((test("aaa", char_ >> expect[char_ >> char_('a')])));
BOOST_TEST((test("xi", char_('x') >> expect[char_('i')])));
BOOST_TEST((!test("xi", char_('y') >> expect[char_('o')]))); // should not throw!
BOOST_TEST((test("xin", char_('x') >> expect[char_('i') >> char_('n')])));
BOOST_TEST((!test("xi", char_('x') >> expect[char_('o')])));
}
catch (expectation_failure<char const*> const& x)
{
std::cout << "expected: " << x.which();
std::cout << " got: \"" << x.where() << '"' << std::endl;
}
}
{
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: " << x.which();
std::cout << " got: \"" << x.where() << '"' << std::endl;
}
}
{
try
{
BOOST_TEST((!test("ay:a", char_ > char_('x') >> ':' > 'a')));
}
catch (expectation_failure<char const*> const& x)
{
std::cout << "expected: " << x.which();
std::cout << " got: \"" << x.where() << '"' << std::endl;
}
}
#if defined(BOOST_CLANG)
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Woverloaded-shift-op-parentheses"
#endif
{ // Test that attributes with > (sequences) work just like >> (sequences)
using boost::fusion::vector;
using boost::fusion::at_c;
{
vector<char, char, char> attr;
BOOST_TEST((test_attr(" a\n b\n c",
char_ > char_ > char_, attr, space)));
BOOST_TEST((at_c<0>(attr) == 'a'));
BOOST_TEST((at_c<1>(attr) == 'b'));
BOOST_TEST((at_c<2>(attr) == 'c'));
}
{
vector<char, char, char> attr;
BOOST_TEST((test_attr(" a\n b\n c",
char_ > char_ >> char_, attr, space)));
BOOST_TEST((at_c<0>(attr) == 'a'));
BOOST_TEST((at_c<1>(attr) == 'b'));
BOOST_TEST((at_c<2>(attr) == 'c'));
}
{
vector<char, char, char> attr;
BOOST_TEST((test_attr(" a, b, c",
char_ >> ',' > char_ >> ',' > char_, attr, space)));
BOOST_TEST((at_c<0>(attr) == 'a'));
BOOST_TEST((at_c<1>(attr) == 'b'));
BOOST_TEST((at_c<2>(attr) == 'c'));
}
{
std::string attr;
BOOST_TEST((test_attr("'azaaz'",
"'" > *(char_("a") | char_("z")) > "'", attr, space)));
BOOST_TEST(attr == "azaaz");
}
}
#if defined(BOOST_CLANG)
#pragma clang diagnostic pop
#endif
{
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: " << x.which();
std::cout << " got: \"" << x.where() << '"' << std::endl;
}
}
{
try
{
BOOST_TEST((test("bar", expect[lit("foo")])));
}
catch (expectation_failure<char const*> const& x)
{
std::cout << "expected: " << x.which();
std::cout << " got: \"" << x.where() << '"' << std::endl;
}
}
return boost::report_errors();
}
|