-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathtest.hpp
186 lines (156 loc) · 5.83 KB
/
test.hpp
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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
/*=============================================================================
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)
=============================================================================*/
#if !defined(BOOST_SPIRIT_TEST_FEBRUARY_01_2007_0605PM)
#define BOOST_SPIRIT_TEST_FEBRUARY_01_2007_0605PM
//~ #include <boost/spirit/include/qi_parse.hpp>
//~ #include <boost/spirit/include/qi_what.hpp>
//~ #include <boost/variant/apply_visitor.hpp>
//~ #include <boost/foreach.hpp>
#include <boost/spirit/home/x3/core/parse.hpp>
#include <iostream>
namespace spirit_test
{
template <typename Char, typename Parser>
bool test(Char const* in, Parser const& p, bool full_match = true)
{
Char const* last = in;
while (*last)
last++;
return boost::spirit::x3::parse(in, last, p)
&& (!full_match || (in == last));
}
template <typename Char, typename Parser, typename Skipper>
bool test(Char const* in, Parser const& p
, Skipper const& s, bool full_match = true)
{
Char const* last = in;
while (*last)
last++;
return boost::spirit::x3::phrase_parse(in, last, p, s)
&& (!full_match || (in == last));
}
template <typename Char, typename Parser>
bool test_failure(Char const* in, Parser const& p)
{
char const * const start = in;
Char const* last = in;
while (*last)
last++;
return !boost::spirit::x3::parse(in, last, p) && (in == start);
}
//~ template <typename Char, typename Parser>
//~ bool binary_test(Char const* in, std::size_t size, Parser const& p,
//~ bool full_match = true)
//~ {
//~ // we don't care about the result of the "what" function.
//~ // we only care that all parsers have it:
//~ boost::spirit::x3::what(p);
//~ Char const* last = in + size;
//~ return boost::spirit::qi::parse(in, last, p)
//~ && (!full_match || (in == last));
//~ }
//~ template <typename Char, typename Parser, typename Skipper>
//~ bool binary_test(Char const* in, std::size_t size, Parser const& p,
//~ Skipper const& s, bool full_match = true)
//~ {
//~ // we don't care about the result of the "what" function.
//~ // we only care that all parsers have it:
//~ boost::spirit::x3::what(p);
//~ Char const* last = in + size;
//~ return boost::spirit::x3::phrase_parse(in, last, p, s)
//~ && (!full_match || (in == last));
//~ }
template <typename Char, typename Parser, typename Attr>
bool test_attr(Char const* in, Parser const& p
, Attr& attr, bool full_match = true)
{
Char const* last = in;
while (*last)
last++;
return boost::spirit::x3::parse(in, last, p, attr)
&& (!full_match || (in == last));
}
template <typename Char, typename Parser, typename Attr, typename Skipper>
bool test_attr(Char const* in, Parser const& p
, Attr& attr, Skipper const& s, bool full_match = true)
{
Char const* last = in;
while (*last)
last++;
return boost::spirit::x3::phrase_parse(in, last, p, s, attr)
&& (!full_match || (in == last));
}
//~ template <typename Char, typename Parser, typename Attr>
//~ bool binary_test_attr(Char const* in, std::size_t size, Parser const& p,
//~ Attr& attr, bool full_match = true)
//~ {
//~ // we don't care about the result of the "what" function.
//~ // we only care that all parsers have it:
//~ boost::spirit::x3::what(p);
//~ Char const* last = in + size;
//~ return boost::spirit::x3::parse(in, last, p, attr)
//~ && (!full_match || (in == last));
//~ }
//~ template <typename Char, typename Parser, typename Attr, typename Skipper>
//~ bool binary_test_attr(Char const* in, std::size_t size, Parser const& p,
//~ Attr& attr, Skipper const& s, bool full_match = true)
//~ {
//~ // we don't care about the result of the "what" function.
//~ // we only care that all parsers have it:
//~ boost::spirit::x3::what(p);
//~ Char const* last = in + size;
//~ return boost::spirit::x3::phrase_parse(in, last, p, s, attr)
//~ && (!full_match || (in == last));
//~ }
//~ struct printer
//~ {
//~ typedef boost::spirit::x3::utf8_string string;
//~ void element(string const& tag, string const& value, int depth) const
//~ {
//~ for (int i = 0; i < (depth*4); ++i) // indent to depth
//~ std::cout << ' ';
//~ std::cout << "tag: " << tag;
//~ if (value != "")
//~ std::cout << ", value: " << value;
//~ std::cout << std::endl;
//~ }
//~ };
//~ void print_info(boost::spirit::x3::info const& what)
//~ {
//~ using boost::spirit::x3::basic_info_walker;
//~ printer pr;
//~ basic_info_walker<printer> walker(pr, what.tag, 0);
//~ boost::apply_visitor(walker, what.value);
//~ }
}
#include <fstream>
#include <iterator>
#include <algorithm>
#include "LibertyLibrary.hpp"
class Sample2LateFilenameFixture
{
protected:
Sample2LateFilenameFixture()
{
#ifndef LIBERTY_TEST_RESOURCE_PATH
static_assert(1!=1, "Please set -DLIBERTY_TEST_RESOURCE_PATH");
#endif
}
virtual ~Sample2LateFilenameFixture()
{
}
static const char test_filename[];
};
class ParsingApiFixture: public Sample2LateFilenameFixture
{
public:
ParsingApiFixture();
protected:
bool result;
std::vector<char> buffer;
liberty::ast::Library library;
};
#endif