1*0a6a1f1dSLionel Sambuc //
2*0a6a1f1dSLionel Sambuc // Automated Testing Framework (atf)
3*0a6a1f1dSLionel Sambuc //
4*0a6a1f1dSLionel Sambuc // Copyright (c) 2007 The NetBSD Foundation, Inc.
5*0a6a1f1dSLionel Sambuc // All rights reserved.
6*0a6a1f1dSLionel Sambuc //
7*0a6a1f1dSLionel Sambuc // Redistribution and use in source and binary forms, with or without
8*0a6a1f1dSLionel Sambuc // modification, are permitted provided that the following conditions
9*0a6a1f1dSLionel Sambuc // are met:
10*0a6a1f1dSLionel Sambuc // 1. Redistributions of source code must retain the above copyright
11*0a6a1f1dSLionel Sambuc // notice, this list of conditions and the following disclaimer.
12*0a6a1f1dSLionel Sambuc // 2. Redistributions in binary form must reproduce the above copyright
13*0a6a1f1dSLionel Sambuc // notice, this list of conditions and the following disclaimer in the
14*0a6a1f1dSLionel Sambuc // documentation and/or other materials provided with the distribution.
15*0a6a1f1dSLionel Sambuc //
16*0a6a1f1dSLionel Sambuc // THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND
17*0a6a1f1dSLionel Sambuc // CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
18*0a6a1f1dSLionel Sambuc // INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
19*0a6a1f1dSLionel Sambuc // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20*0a6a1f1dSLionel Sambuc // IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY
21*0a6a1f1dSLionel Sambuc // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22*0a6a1f1dSLionel Sambuc // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
23*0a6a1f1dSLionel Sambuc // GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24*0a6a1f1dSLionel Sambuc // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
25*0a6a1f1dSLionel Sambuc // IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
26*0a6a1f1dSLionel Sambuc // OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
27*0a6a1f1dSLionel Sambuc // IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28*0a6a1f1dSLionel Sambuc //
29*0a6a1f1dSLionel Sambuc
30*0a6a1f1dSLionel Sambuc #include <sstream>
31*0a6a1f1dSLionel Sambuc
32*0a6a1f1dSLionel Sambuc #include <atf-c++.hpp>
33*0a6a1f1dSLionel Sambuc
34*0a6a1f1dSLionel Sambuc #include "parser.hpp"
35*0a6a1f1dSLionel Sambuc #include "test_helpers.hpp"
36*0a6a1f1dSLionel Sambuc
37*0a6a1f1dSLionel Sambuc // ------------------------------------------------------------------------
38*0a6a1f1dSLionel Sambuc // Tests for the "parse_error" class.
39*0a6a1f1dSLionel Sambuc // ------------------------------------------------------------------------
40*0a6a1f1dSLionel Sambuc
41*0a6a1f1dSLionel Sambuc ATF_TEST_CASE(parse_error_to_string);
ATF_TEST_CASE_HEAD(parse_error_to_string)42*0a6a1f1dSLionel Sambuc ATF_TEST_CASE_HEAD(parse_error_to_string)
43*0a6a1f1dSLionel Sambuc {
44*0a6a1f1dSLionel Sambuc set_md_var("descr", "Tests the parse_error conversion to strings");
45*0a6a1f1dSLionel Sambuc }
ATF_TEST_CASE_BODY(parse_error_to_string)46*0a6a1f1dSLionel Sambuc ATF_TEST_CASE_BODY(parse_error_to_string)
47*0a6a1f1dSLionel Sambuc {
48*0a6a1f1dSLionel Sambuc using tools::parser::parse_error;
49*0a6a1f1dSLionel Sambuc
50*0a6a1f1dSLionel Sambuc const parse_error e(123, "This is the message");
51*0a6a1f1dSLionel Sambuc ATF_REQUIRE_EQ("123: This is the message", std::string(e));
52*0a6a1f1dSLionel Sambuc }
53*0a6a1f1dSLionel Sambuc
54*0a6a1f1dSLionel Sambuc // ------------------------------------------------------------------------
55*0a6a1f1dSLionel Sambuc // Tests for the "parse_errors" class.
56*0a6a1f1dSLionel Sambuc // ------------------------------------------------------------------------
57*0a6a1f1dSLionel Sambuc
58*0a6a1f1dSLionel Sambuc ATF_TEST_CASE(parse_errors_what);
ATF_TEST_CASE_HEAD(parse_errors_what)59*0a6a1f1dSLionel Sambuc ATF_TEST_CASE_HEAD(parse_errors_what)
60*0a6a1f1dSLionel Sambuc {
61*0a6a1f1dSLionel Sambuc set_md_var("descr", "Tests the parse_errors description");
62*0a6a1f1dSLionel Sambuc }
ATF_TEST_CASE_BODY(parse_errors_what)63*0a6a1f1dSLionel Sambuc ATF_TEST_CASE_BODY(parse_errors_what)
64*0a6a1f1dSLionel Sambuc {
65*0a6a1f1dSLionel Sambuc using tools::parser::parse_error;
66*0a6a1f1dSLionel Sambuc using tools::parser::parse_errors;
67*0a6a1f1dSLionel Sambuc
68*0a6a1f1dSLionel Sambuc parse_errors es;
69*0a6a1f1dSLionel Sambuc es.push_back(parse_error(2, "Second error"));
70*0a6a1f1dSLionel Sambuc es.push_back(parse_error(1, "First error"));
71*0a6a1f1dSLionel Sambuc
72*0a6a1f1dSLionel Sambuc ATF_REQUIRE_EQ("2: Second error\n1: First error", std::string(es.what()));
73*0a6a1f1dSLionel Sambuc }
74*0a6a1f1dSLionel Sambuc
75*0a6a1f1dSLionel Sambuc // ------------------------------------------------------------------------
76*0a6a1f1dSLionel Sambuc // Tests for the "token" class.
77*0a6a1f1dSLionel Sambuc // ------------------------------------------------------------------------
78*0a6a1f1dSLionel Sambuc
79*0a6a1f1dSLionel Sambuc ATF_TEST_CASE(token_getters);
ATF_TEST_CASE_HEAD(token_getters)80*0a6a1f1dSLionel Sambuc ATF_TEST_CASE_HEAD(token_getters)
81*0a6a1f1dSLionel Sambuc {
82*0a6a1f1dSLionel Sambuc set_md_var("descr", "Tests the token getters");
83*0a6a1f1dSLionel Sambuc }
ATF_TEST_CASE_BODY(token_getters)84*0a6a1f1dSLionel Sambuc ATF_TEST_CASE_BODY(token_getters)
85*0a6a1f1dSLionel Sambuc {
86*0a6a1f1dSLionel Sambuc using tools::parser::token;
87*0a6a1f1dSLionel Sambuc
88*0a6a1f1dSLionel Sambuc {
89*0a6a1f1dSLionel Sambuc token t(10, 0);
90*0a6a1f1dSLionel Sambuc ATF_REQUIRE_EQ(t.lineno(), 10);
91*0a6a1f1dSLionel Sambuc ATF_REQUIRE_EQ(t.type(), 0);
92*0a6a1f1dSLionel Sambuc ATF_REQUIRE(t.text().empty());
93*0a6a1f1dSLionel Sambuc }
94*0a6a1f1dSLionel Sambuc
95*0a6a1f1dSLionel Sambuc {
96*0a6a1f1dSLionel Sambuc token t(10, 0, "foo");
97*0a6a1f1dSLionel Sambuc ATF_REQUIRE_EQ(t.lineno(), 10);
98*0a6a1f1dSLionel Sambuc ATF_REQUIRE_EQ(t.type(), 0);
99*0a6a1f1dSLionel Sambuc ATF_REQUIRE_EQ(t.text(), "foo");
100*0a6a1f1dSLionel Sambuc }
101*0a6a1f1dSLionel Sambuc
102*0a6a1f1dSLionel Sambuc {
103*0a6a1f1dSLionel Sambuc token t(20, 1);
104*0a6a1f1dSLionel Sambuc ATF_REQUIRE_EQ(t.lineno(), 20);
105*0a6a1f1dSLionel Sambuc ATF_REQUIRE_EQ(t.type(), 1);
106*0a6a1f1dSLionel Sambuc ATF_REQUIRE(t.text().empty());
107*0a6a1f1dSLionel Sambuc }
108*0a6a1f1dSLionel Sambuc
109*0a6a1f1dSLionel Sambuc {
110*0a6a1f1dSLionel Sambuc token t(20, 1, "bar");
111*0a6a1f1dSLionel Sambuc ATF_REQUIRE_EQ(t.lineno(), 20);
112*0a6a1f1dSLionel Sambuc ATF_REQUIRE_EQ(t.type(), 1);
113*0a6a1f1dSLionel Sambuc ATF_REQUIRE_EQ(t.text(), "bar");
114*0a6a1f1dSLionel Sambuc }
115*0a6a1f1dSLionel Sambuc }
116*0a6a1f1dSLionel Sambuc
117*0a6a1f1dSLionel Sambuc // ------------------------------------------------------------------------
118*0a6a1f1dSLionel Sambuc // Tests for the "tokenizer" class.
119*0a6a1f1dSLionel Sambuc // ------------------------------------------------------------------------
120*0a6a1f1dSLionel Sambuc
121*0a6a1f1dSLionel Sambuc #define EXPECT(tkz, ttype, ttext) \
122*0a6a1f1dSLionel Sambuc do { \
123*0a6a1f1dSLionel Sambuc tools::parser::token t = tkz.next(); \
124*0a6a1f1dSLionel Sambuc ATF_REQUIRE(t.type() == ttype); \
125*0a6a1f1dSLionel Sambuc ATF_REQUIRE_EQ(t.text(), ttext); \
126*0a6a1f1dSLionel Sambuc } while (false);
127*0a6a1f1dSLionel Sambuc
128*0a6a1f1dSLionel Sambuc namespace minimal {
129*0a6a1f1dSLionel Sambuc
130*0a6a1f1dSLionel Sambuc static const tools::parser::token_type eof_type = 0;
131*0a6a1f1dSLionel Sambuc static const tools::parser::token_type nl_type = 1;
132*0a6a1f1dSLionel Sambuc static const tools::parser::token_type word_type = 2;
133*0a6a1f1dSLionel Sambuc
134*0a6a1f1dSLionel Sambuc class tokenizer : public tools::parser::tokenizer< std::istream > {
135*0a6a1f1dSLionel Sambuc public:
tokenizer(std::istream & is,bool skipws)136*0a6a1f1dSLionel Sambuc tokenizer(std::istream& is, bool skipws) :
137*0a6a1f1dSLionel Sambuc tools::parser::tokenizer< std::istream >
138*0a6a1f1dSLionel Sambuc (is, skipws, eof_type, nl_type, word_type)
139*0a6a1f1dSLionel Sambuc {
140*0a6a1f1dSLionel Sambuc }
141*0a6a1f1dSLionel Sambuc };
142*0a6a1f1dSLionel Sambuc
143*0a6a1f1dSLionel Sambuc }
144*0a6a1f1dSLionel Sambuc
145*0a6a1f1dSLionel Sambuc namespace delims {
146*0a6a1f1dSLionel Sambuc
147*0a6a1f1dSLionel Sambuc static const tools::parser::token_type eof_type = 0;
148*0a6a1f1dSLionel Sambuc static const tools::parser::token_type nl_type = 1;
149*0a6a1f1dSLionel Sambuc static const tools::parser::token_type word_type = 2;
150*0a6a1f1dSLionel Sambuc static const tools::parser::token_type plus_type = 3;
151*0a6a1f1dSLionel Sambuc static const tools::parser::token_type minus_type = 4;
152*0a6a1f1dSLionel Sambuc static const tools::parser::token_type equal_type = 5;
153*0a6a1f1dSLionel Sambuc
154*0a6a1f1dSLionel Sambuc class tokenizer : public tools::parser::tokenizer< std::istream > {
155*0a6a1f1dSLionel Sambuc public:
tokenizer(std::istream & is,bool skipws)156*0a6a1f1dSLionel Sambuc tokenizer(std::istream& is, bool skipws) :
157*0a6a1f1dSLionel Sambuc tools::parser::tokenizer< std::istream >
158*0a6a1f1dSLionel Sambuc (is, skipws, eof_type, nl_type, word_type)
159*0a6a1f1dSLionel Sambuc {
160*0a6a1f1dSLionel Sambuc add_delim('+', plus_type);
161*0a6a1f1dSLionel Sambuc add_delim('-', minus_type);
162*0a6a1f1dSLionel Sambuc add_delim('=', equal_type);
163*0a6a1f1dSLionel Sambuc }
164*0a6a1f1dSLionel Sambuc };
165*0a6a1f1dSLionel Sambuc
166*0a6a1f1dSLionel Sambuc }
167*0a6a1f1dSLionel Sambuc
168*0a6a1f1dSLionel Sambuc namespace keywords {
169*0a6a1f1dSLionel Sambuc
170*0a6a1f1dSLionel Sambuc static const tools::parser::token_type eof_type = 0;
171*0a6a1f1dSLionel Sambuc static const tools::parser::token_type nl_type = 1;
172*0a6a1f1dSLionel Sambuc static const tools::parser::token_type word_type = 2;
173*0a6a1f1dSLionel Sambuc static const tools::parser::token_type var_type = 3;
174*0a6a1f1dSLionel Sambuc static const tools::parser::token_type loop_type = 4;
175*0a6a1f1dSLionel Sambuc static const tools::parser::token_type endloop_type = 5;
176*0a6a1f1dSLionel Sambuc
177*0a6a1f1dSLionel Sambuc class tokenizer : public tools::parser::tokenizer< std::istream > {
178*0a6a1f1dSLionel Sambuc public:
tokenizer(std::istream & is,bool skipws)179*0a6a1f1dSLionel Sambuc tokenizer(std::istream& is, bool skipws) :
180*0a6a1f1dSLionel Sambuc tools::parser::tokenizer< std::istream >
181*0a6a1f1dSLionel Sambuc (is, skipws, eof_type, nl_type, word_type)
182*0a6a1f1dSLionel Sambuc {
183*0a6a1f1dSLionel Sambuc add_keyword("var", var_type);
184*0a6a1f1dSLionel Sambuc add_keyword("loop", loop_type);
185*0a6a1f1dSLionel Sambuc add_keyword("endloop", endloop_type);
186*0a6a1f1dSLionel Sambuc }
187*0a6a1f1dSLionel Sambuc };
188*0a6a1f1dSLionel Sambuc
189*0a6a1f1dSLionel Sambuc }
190*0a6a1f1dSLionel Sambuc
191*0a6a1f1dSLionel Sambuc namespace quotes {
192*0a6a1f1dSLionel Sambuc
193*0a6a1f1dSLionel Sambuc static const tools::parser::token_type eof_type = 0;
194*0a6a1f1dSLionel Sambuc static const tools::parser::token_type nl_type = 1;
195*0a6a1f1dSLionel Sambuc static const tools::parser::token_type word_type = 2;
196*0a6a1f1dSLionel Sambuc static const tools::parser::token_type dblquote_type = 3;
197*0a6a1f1dSLionel Sambuc
198*0a6a1f1dSLionel Sambuc class tokenizer : public tools::parser::tokenizer< std::istream > {
199*0a6a1f1dSLionel Sambuc public:
tokenizer(std::istream & is,bool skipws)200*0a6a1f1dSLionel Sambuc tokenizer(std::istream& is, bool skipws) :
201*0a6a1f1dSLionel Sambuc tools::parser::tokenizer< std::istream >
202*0a6a1f1dSLionel Sambuc (is, skipws, eof_type, nl_type, word_type)
203*0a6a1f1dSLionel Sambuc {
204*0a6a1f1dSLionel Sambuc add_quote('"', dblquote_type);
205*0a6a1f1dSLionel Sambuc }
206*0a6a1f1dSLionel Sambuc };
207*0a6a1f1dSLionel Sambuc
208*0a6a1f1dSLionel Sambuc }
209*0a6a1f1dSLionel Sambuc
210*0a6a1f1dSLionel Sambuc ATF_TEST_CASE(tokenizer_minimal_nows);
ATF_TEST_CASE_HEAD(tokenizer_minimal_nows)211*0a6a1f1dSLionel Sambuc ATF_TEST_CASE_HEAD(tokenizer_minimal_nows)
212*0a6a1f1dSLionel Sambuc {
213*0a6a1f1dSLionel Sambuc set_md_var("descr", "Tests the tokenizer class using a minimal parser "
214*0a6a1f1dSLionel Sambuc "and not skipping whitespace");
215*0a6a1f1dSLionel Sambuc }
ATF_TEST_CASE_BODY(tokenizer_minimal_nows)216*0a6a1f1dSLionel Sambuc ATF_TEST_CASE_BODY(tokenizer_minimal_nows)
217*0a6a1f1dSLionel Sambuc {
218*0a6a1f1dSLionel Sambuc using namespace minimal;
219*0a6a1f1dSLionel Sambuc
220*0a6a1f1dSLionel Sambuc {
221*0a6a1f1dSLionel Sambuc std::istringstream iss("");
222*0a6a1f1dSLionel Sambuc tokenizer mt(iss, false);
223*0a6a1f1dSLionel Sambuc
224*0a6a1f1dSLionel Sambuc EXPECT(mt, eof_type, "<<EOF>>");
225*0a6a1f1dSLionel Sambuc EXPECT(mt, eof_type, "<<EOF>>");
226*0a6a1f1dSLionel Sambuc }
227*0a6a1f1dSLionel Sambuc
228*0a6a1f1dSLionel Sambuc {
229*0a6a1f1dSLionel Sambuc std::istringstream iss("\n");
230*0a6a1f1dSLionel Sambuc tokenizer mt(iss, false);
231*0a6a1f1dSLionel Sambuc
232*0a6a1f1dSLionel Sambuc EXPECT(mt, nl_type, "<<NEWLINE>>");
233*0a6a1f1dSLionel Sambuc EXPECT(mt, eof_type, "<<EOF>>");
234*0a6a1f1dSLionel Sambuc EXPECT(mt, eof_type, "<<EOF>>");
235*0a6a1f1dSLionel Sambuc }
236*0a6a1f1dSLionel Sambuc
237*0a6a1f1dSLionel Sambuc {
238*0a6a1f1dSLionel Sambuc std::istringstream iss("\n\n\n");
239*0a6a1f1dSLionel Sambuc tokenizer mt(iss, false);
240*0a6a1f1dSLionel Sambuc
241*0a6a1f1dSLionel Sambuc EXPECT(mt, nl_type, "<<NEWLINE>>");
242*0a6a1f1dSLionel Sambuc EXPECT(mt, nl_type, "<<NEWLINE>>");
243*0a6a1f1dSLionel Sambuc EXPECT(mt, nl_type, "<<NEWLINE>>");
244*0a6a1f1dSLionel Sambuc EXPECT(mt, eof_type, "<<EOF>>");
245*0a6a1f1dSLionel Sambuc EXPECT(mt, eof_type, "<<EOF>>");
246*0a6a1f1dSLionel Sambuc }
247*0a6a1f1dSLionel Sambuc
248*0a6a1f1dSLionel Sambuc {
249*0a6a1f1dSLionel Sambuc std::istringstream iss("line 1");
250*0a6a1f1dSLionel Sambuc tokenizer mt(iss, false);
251*0a6a1f1dSLionel Sambuc
252*0a6a1f1dSLionel Sambuc EXPECT(mt, word_type, "line 1");
253*0a6a1f1dSLionel Sambuc EXPECT(mt, eof_type, "<<EOF>>");
254*0a6a1f1dSLionel Sambuc EXPECT(mt, eof_type, "<<EOF>>");
255*0a6a1f1dSLionel Sambuc }
256*0a6a1f1dSLionel Sambuc
257*0a6a1f1dSLionel Sambuc {
258*0a6a1f1dSLionel Sambuc std::istringstream iss("line 1\n");
259*0a6a1f1dSLionel Sambuc tokenizer mt(iss, false);
260*0a6a1f1dSLionel Sambuc
261*0a6a1f1dSLionel Sambuc EXPECT(mt, word_type, "line 1");
262*0a6a1f1dSLionel Sambuc EXPECT(mt, nl_type, "<<NEWLINE>>");
263*0a6a1f1dSLionel Sambuc EXPECT(mt, eof_type, "<<EOF>>");
264*0a6a1f1dSLionel Sambuc EXPECT(mt, eof_type, "<<EOF>>");
265*0a6a1f1dSLionel Sambuc }
266*0a6a1f1dSLionel Sambuc
267*0a6a1f1dSLionel Sambuc {
268*0a6a1f1dSLionel Sambuc std::istringstream iss("line 1\nline 2");
269*0a6a1f1dSLionel Sambuc tokenizer mt(iss, false);
270*0a6a1f1dSLionel Sambuc
271*0a6a1f1dSLionel Sambuc EXPECT(mt, word_type, "line 1");
272*0a6a1f1dSLionel Sambuc EXPECT(mt, nl_type, "<<NEWLINE>>");
273*0a6a1f1dSLionel Sambuc EXPECT(mt, word_type, "line 2");
274*0a6a1f1dSLionel Sambuc EXPECT(mt, eof_type, "<<EOF>>");
275*0a6a1f1dSLionel Sambuc EXPECT(mt, eof_type, "<<EOF>>");
276*0a6a1f1dSLionel Sambuc }
277*0a6a1f1dSLionel Sambuc
278*0a6a1f1dSLionel Sambuc {
279*0a6a1f1dSLionel Sambuc std::istringstream iss("line 1\nline 2\nline 3\n");
280*0a6a1f1dSLionel Sambuc tokenizer mt(iss, false);
281*0a6a1f1dSLionel Sambuc
282*0a6a1f1dSLionel Sambuc EXPECT(mt, word_type, "line 1");
283*0a6a1f1dSLionel Sambuc EXPECT(mt, nl_type, "<<NEWLINE>>");
284*0a6a1f1dSLionel Sambuc EXPECT(mt, word_type, "line 2");
285*0a6a1f1dSLionel Sambuc EXPECT(mt, nl_type, "<<NEWLINE>>");
286*0a6a1f1dSLionel Sambuc EXPECT(mt, word_type, "line 3");
287*0a6a1f1dSLionel Sambuc EXPECT(mt, nl_type, "<<NEWLINE>>");
288*0a6a1f1dSLionel Sambuc EXPECT(mt, eof_type, "<<EOF>>");
289*0a6a1f1dSLionel Sambuc EXPECT(mt, eof_type, "<<EOF>>");
290*0a6a1f1dSLionel Sambuc }
291*0a6a1f1dSLionel Sambuc }
292*0a6a1f1dSLionel Sambuc
293*0a6a1f1dSLionel Sambuc ATF_TEST_CASE(tokenizer_minimal_ws);
ATF_TEST_CASE_HEAD(tokenizer_minimal_ws)294*0a6a1f1dSLionel Sambuc ATF_TEST_CASE_HEAD(tokenizer_minimal_ws)
295*0a6a1f1dSLionel Sambuc {
296*0a6a1f1dSLionel Sambuc set_md_var("descr", "Tests the tokenizer class using a minimal parser "
297*0a6a1f1dSLionel Sambuc "and skipping whitespace");
298*0a6a1f1dSLionel Sambuc }
ATF_TEST_CASE_BODY(tokenizer_minimal_ws)299*0a6a1f1dSLionel Sambuc ATF_TEST_CASE_BODY(tokenizer_minimal_ws)
300*0a6a1f1dSLionel Sambuc {
301*0a6a1f1dSLionel Sambuc using namespace minimal;
302*0a6a1f1dSLionel Sambuc
303*0a6a1f1dSLionel Sambuc {
304*0a6a1f1dSLionel Sambuc std::istringstream iss("");
305*0a6a1f1dSLionel Sambuc minimal::tokenizer mt(iss, true);
306*0a6a1f1dSLionel Sambuc
307*0a6a1f1dSLionel Sambuc EXPECT(mt, eof_type, "<<EOF>>");
308*0a6a1f1dSLionel Sambuc EXPECT(mt, eof_type, "<<EOF>>");
309*0a6a1f1dSLionel Sambuc }
310*0a6a1f1dSLionel Sambuc
311*0a6a1f1dSLionel Sambuc {
312*0a6a1f1dSLionel Sambuc std::istringstream iss(" \t ");
313*0a6a1f1dSLionel Sambuc tokenizer mt(iss, true);
314*0a6a1f1dSLionel Sambuc
315*0a6a1f1dSLionel Sambuc EXPECT(mt, eof_type, "<<EOF>>");
316*0a6a1f1dSLionel Sambuc EXPECT(mt, eof_type, "<<EOF>>");
317*0a6a1f1dSLionel Sambuc }
318*0a6a1f1dSLionel Sambuc
319*0a6a1f1dSLionel Sambuc {
320*0a6a1f1dSLionel Sambuc std::istringstream iss("\n");
321*0a6a1f1dSLionel Sambuc tokenizer mt(iss, true);
322*0a6a1f1dSLionel Sambuc
323*0a6a1f1dSLionel Sambuc EXPECT(mt, nl_type, "<<NEWLINE>>");
324*0a6a1f1dSLionel Sambuc EXPECT(mt, eof_type, "<<EOF>>");
325*0a6a1f1dSLionel Sambuc EXPECT(mt, eof_type, "<<EOF>>");
326*0a6a1f1dSLionel Sambuc }
327*0a6a1f1dSLionel Sambuc
328*0a6a1f1dSLionel Sambuc {
329*0a6a1f1dSLionel Sambuc std::istringstream iss(" \t \n \t ");
330*0a6a1f1dSLionel Sambuc tokenizer mt(iss, true);
331*0a6a1f1dSLionel Sambuc
332*0a6a1f1dSLionel Sambuc EXPECT(mt, nl_type, "<<NEWLINE>>");
333*0a6a1f1dSLionel Sambuc EXPECT(mt, eof_type, "<<EOF>>");
334*0a6a1f1dSLionel Sambuc EXPECT(mt, eof_type, "<<EOF>>");
335*0a6a1f1dSLionel Sambuc }
336*0a6a1f1dSLionel Sambuc
337*0a6a1f1dSLionel Sambuc {
338*0a6a1f1dSLionel Sambuc std::istringstream iss("\n\n\n");
339*0a6a1f1dSLionel Sambuc tokenizer mt(iss, true);
340*0a6a1f1dSLionel Sambuc
341*0a6a1f1dSLionel Sambuc EXPECT(mt, nl_type, "<<NEWLINE>>");
342*0a6a1f1dSLionel Sambuc EXPECT(mt, nl_type, "<<NEWLINE>>");
343*0a6a1f1dSLionel Sambuc EXPECT(mt, nl_type, "<<NEWLINE>>");
344*0a6a1f1dSLionel Sambuc EXPECT(mt, eof_type, "<<EOF>>");
345*0a6a1f1dSLionel Sambuc EXPECT(mt, eof_type, "<<EOF>>");
346*0a6a1f1dSLionel Sambuc }
347*0a6a1f1dSLionel Sambuc
348*0a6a1f1dSLionel Sambuc {
349*0a6a1f1dSLionel Sambuc std::istringstream iss("line 1");
350*0a6a1f1dSLionel Sambuc tokenizer mt(iss, true);
351*0a6a1f1dSLionel Sambuc
352*0a6a1f1dSLionel Sambuc EXPECT(mt, word_type, "line");
353*0a6a1f1dSLionel Sambuc EXPECT(mt, word_type, "1");
354*0a6a1f1dSLionel Sambuc EXPECT(mt, eof_type, "<<EOF>>");
355*0a6a1f1dSLionel Sambuc EXPECT(mt, eof_type, "<<EOF>>");
356*0a6a1f1dSLionel Sambuc }
357*0a6a1f1dSLionel Sambuc
358*0a6a1f1dSLionel Sambuc {
359*0a6a1f1dSLionel Sambuc std::istringstream iss(" \tline\t 1\t");
360*0a6a1f1dSLionel Sambuc tokenizer mt(iss, true);
361*0a6a1f1dSLionel Sambuc
362*0a6a1f1dSLionel Sambuc EXPECT(mt, word_type, "line");
363*0a6a1f1dSLionel Sambuc EXPECT(mt, word_type, "1");
364*0a6a1f1dSLionel Sambuc EXPECT(mt, eof_type, "<<EOF>>");
365*0a6a1f1dSLionel Sambuc EXPECT(mt, eof_type, "<<EOF>>");
366*0a6a1f1dSLionel Sambuc }
367*0a6a1f1dSLionel Sambuc
368*0a6a1f1dSLionel Sambuc {
369*0a6a1f1dSLionel Sambuc std::istringstream iss("line 1\n");
370*0a6a1f1dSLionel Sambuc tokenizer mt(iss, true);
371*0a6a1f1dSLionel Sambuc
372*0a6a1f1dSLionel Sambuc EXPECT(mt, word_type, "line");
373*0a6a1f1dSLionel Sambuc EXPECT(mt, word_type, "1");
374*0a6a1f1dSLionel Sambuc EXPECT(mt, nl_type, "<<NEWLINE>>");
375*0a6a1f1dSLionel Sambuc EXPECT(mt, eof_type, "<<EOF>>");
376*0a6a1f1dSLionel Sambuc EXPECT(mt, eof_type, "<<EOF>>");
377*0a6a1f1dSLionel Sambuc }
378*0a6a1f1dSLionel Sambuc
379*0a6a1f1dSLionel Sambuc {
380*0a6a1f1dSLionel Sambuc std::istringstream iss("line 1\nline 2");
381*0a6a1f1dSLionel Sambuc tokenizer mt(iss, true);
382*0a6a1f1dSLionel Sambuc
383*0a6a1f1dSLionel Sambuc EXPECT(mt, word_type, "line");
384*0a6a1f1dSLionel Sambuc EXPECT(mt, word_type, "1");
385*0a6a1f1dSLionel Sambuc EXPECT(mt, nl_type, "<<NEWLINE>>");
386*0a6a1f1dSLionel Sambuc EXPECT(mt, word_type, "line");
387*0a6a1f1dSLionel Sambuc EXPECT(mt, word_type, "2");
388*0a6a1f1dSLionel Sambuc EXPECT(mt, eof_type, "<<EOF>>");
389*0a6a1f1dSLionel Sambuc EXPECT(mt, eof_type, "<<EOF>>");
390*0a6a1f1dSLionel Sambuc }
391*0a6a1f1dSLionel Sambuc
392*0a6a1f1dSLionel Sambuc {
393*0a6a1f1dSLionel Sambuc std::istringstream iss("line 1\nline 2\nline 3\n");
394*0a6a1f1dSLionel Sambuc tokenizer mt(iss, true);
395*0a6a1f1dSLionel Sambuc
396*0a6a1f1dSLionel Sambuc EXPECT(mt, word_type, "line");
397*0a6a1f1dSLionel Sambuc EXPECT(mt, word_type, "1");
398*0a6a1f1dSLionel Sambuc EXPECT(mt, nl_type, "<<NEWLINE>>");
399*0a6a1f1dSLionel Sambuc EXPECT(mt, word_type, "line");
400*0a6a1f1dSLionel Sambuc EXPECT(mt, word_type, "2");
401*0a6a1f1dSLionel Sambuc EXPECT(mt, nl_type, "<<NEWLINE>>");
402*0a6a1f1dSLionel Sambuc EXPECT(mt, word_type, "line");
403*0a6a1f1dSLionel Sambuc EXPECT(mt, word_type, "3");
404*0a6a1f1dSLionel Sambuc EXPECT(mt, nl_type, "<<NEWLINE>>");
405*0a6a1f1dSLionel Sambuc EXPECT(mt, eof_type, "<<EOF>>");
406*0a6a1f1dSLionel Sambuc EXPECT(mt, eof_type, "<<EOF>>");
407*0a6a1f1dSLionel Sambuc }
408*0a6a1f1dSLionel Sambuc
409*0a6a1f1dSLionel Sambuc {
410*0a6a1f1dSLionel Sambuc std::istringstream iss(" \t line \t 1\n\tline\t2\n line 3 \n");
411*0a6a1f1dSLionel Sambuc tokenizer mt(iss, true);
412*0a6a1f1dSLionel Sambuc
413*0a6a1f1dSLionel Sambuc EXPECT(mt, word_type, "line");
414*0a6a1f1dSLionel Sambuc EXPECT(mt, word_type, "1");
415*0a6a1f1dSLionel Sambuc EXPECT(mt, nl_type, "<<NEWLINE>>");
416*0a6a1f1dSLionel Sambuc EXPECT(mt, word_type, "line");
417*0a6a1f1dSLionel Sambuc EXPECT(mt, word_type, "2");
418*0a6a1f1dSLionel Sambuc EXPECT(mt, nl_type, "<<NEWLINE>>");
419*0a6a1f1dSLionel Sambuc EXPECT(mt, word_type, "line");
420*0a6a1f1dSLionel Sambuc EXPECT(mt, word_type, "3");
421*0a6a1f1dSLionel Sambuc EXPECT(mt, nl_type, "<<NEWLINE>>");
422*0a6a1f1dSLionel Sambuc EXPECT(mt, eof_type, "<<EOF>>");
423*0a6a1f1dSLionel Sambuc EXPECT(mt, eof_type, "<<EOF>>");
424*0a6a1f1dSLionel Sambuc }
425*0a6a1f1dSLionel Sambuc }
426*0a6a1f1dSLionel Sambuc
427*0a6a1f1dSLionel Sambuc ATF_TEST_CASE(tokenizer_delims_nows);
ATF_TEST_CASE_HEAD(tokenizer_delims_nows)428*0a6a1f1dSLionel Sambuc ATF_TEST_CASE_HEAD(tokenizer_delims_nows)
429*0a6a1f1dSLionel Sambuc {
430*0a6a1f1dSLionel Sambuc set_md_var("descr", "Tests the tokenizer class using a parser with some "
431*0a6a1f1dSLionel Sambuc "additional delimiters and not skipping whitespace");
432*0a6a1f1dSLionel Sambuc }
ATF_TEST_CASE_BODY(tokenizer_delims_nows)433*0a6a1f1dSLionel Sambuc ATF_TEST_CASE_BODY(tokenizer_delims_nows)
434*0a6a1f1dSLionel Sambuc {
435*0a6a1f1dSLionel Sambuc using namespace delims;
436*0a6a1f1dSLionel Sambuc
437*0a6a1f1dSLionel Sambuc {
438*0a6a1f1dSLionel Sambuc std::istringstream iss("+-=");
439*0a6a1f1dSLionel Sambuc tokenizer mt(iss, false);
440*0a6a1f1dSLionel Sambuc
441*0a6a1f1dSLionel Sambuc EXPECT(mt, plus_type, "+");
442*0a6a1f1dSLionel Sambuc EXPECT(mt, minus_type, "-");
443*0a6a1f1dSLionel Sambuc EXPECT(mt, equal_type, "=");
444*0a6a1f1dSLionel Sambuc EXPECT(mt, eof_type, "<<EOF>>");
445*0a6a1f1dSLionel Sambuc EXPECT(mt, eof_type, "<<EOF>>");
446*0a6a1f1dSLionel Sambuc }
447*0a6a1f1dSLionel Sambuc
448*0a6a1f1dSLionel Sambuc {
449*0a6a1f1dSLionel Sambuc std::istringstream iss("+++");
450*0a6a1f1dSLionel Sambuc tokenizer mt(iss, false);
451*0a6a1f1dSLionel Sambuc
452*0a6a1f1dSLionel Sambuc EXPECT(mt, plus_type, "+");
453*0a6a1f1dSLionel Sambuc EXPECT(mt, plus_type, "+");
454*0a6a1f1dSLionel Sambuc EXPECT(mt, plus_type, "+");
455*0a6a1f1dSLionel Sambuc EXPECT(mt, eof_type, "<<EOF>>");
456*0a6a1f1dSLionel Sambuc EXPECT(mt, eof_type, "<<EOF>>");
457*0a6a1f1dSLionel Sambuc }
458*0a6a1f1dSLionel Sambuc
459*0a6a1f1dSLionel Sambuc {
460*0a6a1f1dSLionel Sambuc std::istringstream iss("\n+\n++\n");
461*0a6a1f1dSLionel Sambuc tokenizer mt(iss, false);
462*0a6a1f1dSLionel Sambuc
463*0a6a1f1dSLionel Sambuc EXPECT(mt, nl_type, "<<NEWLINE>>");
464*0a6a1f1dSLionel Sambuc EXPECT(mt, plus_type, "+");
465*0a6a1f1dSLionel Sambuc EXPECT(mt, nl_type, "<<NEWLINE>>");
466*0a6a1f1dSLionel Sambuc EXPECT(mt, plus_type, "+");
467*0a6a1f1dSLionel Sambuc EXPECT(mt, plus_type, "+");
468*0a6a1f1dSLionel Sambuc EXPECT(mt, nl_type, "<<NEWLINE>>");
469*0a6a1f1dSLionel Sambuc EXPECT(mt, eof_type, "<<EOF>>");
470*0a6a1f1dSLionel Sambuc EXPECT(mt, eof_type, "<<EOF>>");
471*0a6a1f1dSLionel Sambuc }
472*0a6a1f1dSLionel Sambuc
473*0a6a1f1dSLionel Sambuc {
474*0a6a1f1dSLionel Sambuc std::istringstream iss("foo+bar=baz");
475*0a6a1f1dSLionel Sambuc tokenizer mt(iss, false);
476*0a6a1f1dSLionel Sambuc
477*0a6a1f1dSLionel Sambuc EXPECT(mt, word_type, "foo");
478*0a6a1f1dSLionel Sambuc EXPECT(mt, plus_type, "+");
479*0a6a1f1dSLionel Sambuc EXPECT(mt, word_type, "bar");
480*0a6a1f1dSLionel Sambuc EXPECT(mt, equal_type, "=");
481*0a6a1f1dSLionel Sambuc EXPECT(mt, word_type, "baz");
482*0a6a1f1dSLionel Sambuc EXPECT(mt, eof_type, "<<EOF>>");
483*0a6a1f1dSLionel Sambuc EXPECT(mt, eof_type, "<<EOF>>");
484*0a6a1f1dSLionel Sambuc }
485*0a6a1f1dSLionel Sambuc
486*0a6a1f1dSLionel Sambuc {
487*0a6a1f1dSLionel Sambuc std::istringstream iss(" foo\t+\tbar = baz ");
488*0a6a1f1dSLionel Sambuc tokenizer mt(iss, false);
489*0a6a1f1dSLionel Sambuc
490*0a6a1f1dSLionel Sambuc EXPECT(mt, word_type, " foo\t");
491*0a6a1f1dSLionel Sambuc EXPECT(mt, plus_type, "+");
492*0a6a1f1dSLionel Sambuc EXPECT(mt, word_type, "\tbar ");
493*0a6a1f1dSLionel Sambuc EXPECT(mt, equal_type, "=");
494*0a6a1f1dSLionel Sambuc EXPECT(mt, word_type, " baz ");
495*0a6a1f1dSLionel Sambuc EXPECT(mt, eof_type, "<<EOF>>");
496*0a6a1f1dSLionel Sambuc EXPECT(mt, eof_type, "<<EOF>>");
497*0a6a1f1dSLionel Sambuc }
498*0a6a1f1dSLionel Sambuc }
499*0a6a1f1dSLionel Sambuc
500*0a6a1f1dSLionel Sambuc ATF_TEST_CASE(tokenizer_delims_ws);
ATF_TEST_CASE_HEAD(tokenizer_delims_ws)501*0a6a1f1dSLionel Sambuc ATF_TEST_CASE_HEAD(tokenizer_delims_ws)
502*0a6a1f1dSLionel Sambuc {
503*0a6a1f1dSLionel Sambuc set_md_var("descr", "Tests the tokenizer class using a parser with some "
504*0a6a1f1dSLionel Sambuc "additional delimiters and skipping whitespace");
505*0a6a1f1dSLionel Sambuc }
ATF_TEST_CASE_BODY(tokenizer_delims_ws)506*0a6a1f1dSLionel Sambuc ATF_TEST_CASE_BODY(tokenizer_delims_ws)
507*0a6a1f1dSLionel Sambuc {
508*0a6a1f1dSLionel Sambuc using namespace delims;
509*0a6a1f1dSLionel Sambuc
510*0a6a1f1dSLionel Sambuc {
511*0a6a1f1dSLionel Sambuc std::istringstream iss(" foo\t+\tbar = baz ");
512*0a6a1f1dSLionel Sambuc tokenizer mt(iss, true);
513*0a6a1f1dSLionel Sambuc
514*0a6a1f1dSLionel Sambuc EXPECT(mt, word_type, "foo");
515*0a6a1f1dSLionel Sambuc EXPECT(mt, plus_type, "+");
516*0a6a1f1dSLionel Sambuc EXPECT(mt, word_type, "bar");
517*0a6a1f1dSLionel Sambuc EXPECT(mt, equal_type, "=");
518*0a6a1f1dSLionel Sambuc EXPECT(mt, word_type, "baz");
519*0a6a1f1dSLionel Sambuc EXPECT(mt, eof_type, "<<EOF>>");
520*0a6a1f1dSLionel Sambuc EXPECT(mt, eof_type, "<<EOF>>");
521*0a6a1f1dSLionel Sambuc }
522*0a6a1f1dSLionel Sambuc }
523*0a6a1f1dSLionel Sambuc
524*0a6a1f1dSLionel Sambuc ATF_TEST_CASE(tokenizer_keywords_nows);
ATF_TEST_CASE_HEAD(tokenizer_keywords_nows)525*0a6a1f1dSLionel Sambuc ATF_TEST_CASE_HEAD(tokenizer_keywords_nows)
526*0a6a1f1dSLionel Sambuc {
527*0a6a1f1dSLionel Sambuc set_md_var("descr", "Tests the tokenizer class using a parser with some "
528*0a6a1f1dSLionel Sambuc "additional keywords and not skipping whitespace");
529*0a6a1f1dSLionel Sambuc }
ATF_TEST_CASE_BODY(tokenizer_keywords_nows)530*0a6a1f1dSLionel Sambuc ATF_TEST_CASE_BODY(tokenizer_keywords_nows)
531*0a6a1f1dSLionel Sambuc {
532*0a6a1f1dSLionel Sambuc using namespace keywords;
533*0a6a1f1dSLionel Sambuc
534*0a6a1f1dSLionel Sambuc {
535*0a6a1f1dSLionel Sambuc std::istringstream iss("var");
536*0a6a1f1dSLionel Sambuc tokenizer mt(iss, false);
537*0a6a1f1dSLionel Sambuc
538*0a6a1f1dSLionel Sambuc EXPECT(mt, var_type, "var");
539*0a6a1f1dSLionel Sambuc EXPECT(mt, eof_type, "<<EOF>>");
540*0a6a1f1dSLionel Sambuc EXPECT(mt, eof_type, "<<EOF>>");
541*0a6a1f1dSLionel Sambuc }
542*0a6a1f1dSLionel Sambuc
543*0a6a1f1dSLionel Sambuc {
544*0a6a1f1dSLionel Sambuc std::istringstream iss("va");
545*0a6a1f1dSLionel Sambuc tokenizer mt(iss, false);
546*0a6a1f1dSLionel Sambuc
547*0a6a1f1dSLionel Sambuc EXPECT(mt, word_type, "va");
548*0a6a1f1dSLionel Sambuc EXPECT(mt, eof_type, "<<EOF>>");
549*0a6a1f1dSLionel Sambuc EXPECT(mt, eof_type, "<<EOF>>");
550*0a6a1f1dSLionel Sambuc }
551*0a6a1f1dSLionel Sambuc
552*0a6a1f1dSLionel Sambuc {
553*0a6a1f1dSLionel Sambuc std::istringstream iss("vara");
554*0a6a1f1dSLionel Sambuc tokenizer mt(iss, false);
555*0a6a1f1dSLionel Sambuc
556*0a6a1f1dSLionel Sambuc EXPECT(mt, word_type, "vara");
557*0a6a1f1dSLionel Sambuc EXPECT(mt, eof_type, "<<EOF>>");
558*0a6a1f1dSLionel Sambuc EXPECT(mt, eof_type, "<<EOF>>");
559*0a6a1f1dSLionel Sambuc }
560*0a6a1f1dSLionel Sambuc
561*0a6a1f1dSLionel Sambuc {
562*0a6a1f1dSLionel Sambuc std::istringstream iss("var ");
563*0a6a1f1dSLionel Sambuc tokenizer mt(iss, false);
564*0a6a1f1dSLionel Sambuc
565*0a6a1f1dSLionel Sambuc EXPECT(mt, word_type, "var ");
566*0a6a1f1dSLionel Sambuc EXPECT(mt, eof_type, "<<EOF>>");
567*0a6a1f1dSLionel Sambuc EXPECT(mt, eof_type, "<<EOF>>");
568*0a6a1f1dSLionel Sambuc }
569*0a6a1f1dSLionel Sambuc
570*0a6a1f1dSLionel Sambuc {
571*0a6a1f1dSLionel Sambuc std::istringstream iss("var\nloop\nendloop");
572*0a6a1f1dSLionel Sambuc tokenizer mt(iss, false);
573*0a6a1f1dSLionel Sambuc
574*0a6a1f1dSLionel Sambuc EXPECT(mt, var_type, "var");
575*0a6a1f1dSLionel Sambuc EXPECT(mt, nl_type, "<<NEWLINE>>");
576*0a6a1f1dSLionel Sambuc EXPECT(mt, loop_type, "loop");
577*0a6a1f1dSLionel Sambuc EXPECT(mt, nl_type, "<<NEWLINE>>");
578*0a6a1f1dSLionel Sambuc EXPECT(mt, endloop_type, "endloop");
579*0a6a1f1dSLionel Sambuc EXPECT(mt, eof_type, "<<EOF>>");
580*0a6a1f1dSLionel Sambuc EXPECT(mt, eof_type, "<<EOF>>");
581*0a6a1f1dSLionel Sambuc }
582*0a6a1f1dSLionel Sambuc }
583*0a6a1f1dSLionel Sambuc
584*0a6a1f1dSLionel Sambuc ATF_TEST_CASE(tokenizer_keywords_ws);
ATF_TEST_CASE_HEAD(tokenizer_keywords_ws)585*0a6a1f1dSLionel Sambuc ATF_TEST_CASE_HEAD(tokenizer_keywords_ws)
586*0a6a1f1dSLionel Sambuc {
587*0a6a1f1dSLionel Sambuc set_md_var("descr", "Tests the tokenizer class using a parser with some "
588*0a6a1f1dSLionel Sambuc "additional keywords and not skipping whitespace");
589*0a6a1f1dSLionel Sambuc }
ATF_TEST_CASE_BODY(tokenizer_keywords_ws)590*0a6a1f1dSLionel Sambuc ATF_TEST_CASE_BODY(tokenizer_keywords_ws)
591*0a6a1f1dSLionel Sambuc {
592*0a6a1f1dSLionel Sambuc using namespace keywords;
593*0a6a1f1dSLionel Sambuc
594*0a6a1f1dSLionel Sambuc {
595*0a6a1f1dSLionel Sambuc std::istringstream iss("var ");
596*0a6a1f1dSLionel Sambuc tokenizer mt(iss, true);
597*0a6a1f1dSLionel Sambuc
598*0a6a1f1dSLionel Sambuc EXPECT(mt, var_type, "var");
599*0a6a1f1dSLionel Sambuc EXPECT(mt, eof_type, "<<EOF>>");
600*0a6a1f1dSLionel Sambuc EXPECT(mt, eof_type, "<<EOF>>");
601*0a6a1f1dSLionel Sambuc }
602*0a6a1f1dSLionel Sambuc
603*0a6a1f1dSLionel Sambuc {
604*0a6a1f1dSLionel Sambuc std::istringstream iss(" var \n\tloop\t\n \tendloop \t");
605*0a6a1f1dSLionel Sambuc tokenizer mt(iss, true);
606*0a6a1f1dSLionel Sambuc
607*0a6a1f1dSLionel Sambuc EXPECT(mt, var_type, "var");
608*0a6a1f1dSLionel Sambuc EXPECT(mt, nl_type, "<<NEWLINE>>");
609*0a6a1f1dSLionel Sambuc EXPECT(mt, loop_type, "loop");
610*0a6a1f1dSLionel Sambuc EXPECT(mt, nl_type, "<<NEWLINE>>");
611*0a6a1f1dSLionel Sambuc EXPECT(mt, endloop_type, "endloop");
612*0a6a1f1dSLionel Sambuc EXPECT(mt, eof_type, "<<EOF>>");
613*0a6a1f1dSLionel Sambuc EXPECT(mt, eof_type, "<<EOF>>");
614*0a6a1f1dSLionel Sambuc }
615*0a6a1f1dSLionel Sambuc
616*0a6a1f1dSLionel Sambuc {
617*0a6a1f1dSLionel Sambuc std::istringstream iss("var loop endloop");
618*0a6a1f1dSLionel Sambuc tokenizer mt(iss, true);
619*0a6a1f1dSLionel Sambuc
620*0a6a1f1dSLionel Sambuc EXPECT(mt, var_type, "var");
621*0a6a1f1dSLionel Sambuc EXPECT(mt, loop_type, "loop");
622*0a6a1f1dSLionel Sambuc EXPECT(mt, endloop_type, "endloop");
623*0a6a1f1dSLionel Sambuc EXPECT(mt, eof_type, "<<EOF>>");
624*0a6a1f1dSLionel Sambuc EXPECT(mt, eof_type, "<<EOF>>");
625*0a6a1f1dSLionel Sambuc }
626*0a6a1f1dSLionel Sambuc }
627*0a6a1f1dSLionel Sambuc
628*0a6a1f1dSLionel Sambuc ATF_TEST_CASE(tokenizer_quotes_nows);
ATF_TEST_CASE_HEAD(tokenizer_quotes_nows)629*0a6a1f1dSLionel Sambuc ATF_TEST_CASE_HEAD(tokenizer_quotes_nows)
630*0a6a1f1dSLionel Sambuc {
631*0a6a1f1dSLionel Sambuc set_md_var("descr", "Tests the tokenizer class using a parser with "
632*0a6a1f1dSLionel Sambuc "quoted strings and not skipping whitespace");
633*0a6a1f1dSLionel Sambuc }
ATF_TEST_CASE_BODY(tokenizer_quotes_nows)634*0a6a1f1dSLionel Sambuc ATF_TEST_CASE_BODY(tokenizer_quotes_nows)
635*0a6a1f1dSLionel Sambuc {
636*0a6a1f1dSLionel Sambuc using namespace quotes;
637*0a6a1f1dSLionel Sambuc
638*0a6a1f1dSLionel Sambuc {
639*0a6a1f1dSLionel Sambuc std::istringstream iss("var");
640*0a6a1f1dSLionel Sambuc tokenizer mt(iss, false);
641*0a6a1f1dSLionel Sambuc
642*0a6a1f1dSLionel Sambuc EXPECT(mt, word_type, "var");
643*0a6a1f1dSLionel Sambuc EXPECT(mt, eof_type, "<<EOF>>");
644*0a6a1f1dSLionel Sambuc EXPECT(mt, eof_type, "<<EOF>>");
645*0a6a1f1dSLionel Sambuc }
646*0a6a1f1dSLionel Sambuc
647*0a6a1f1dSLionel Sambuc {
648*0a6a1f1dSLionel Sambuc std::istringstream iss("\"var\"");
649*0a6a1f1dSLionel Sambuc tokenizer mt(iss, false);
650*0a6a1f1dSLionel Sambuc
651*0a6a1f1dSLionel Sambuc EXPECT(mt, word_type, "var");
652*0a6a1f1dSLionel Sambuc EXPECT(mt, eof_type, "<<EOF>>");
653*0a6a1f1dSLionel Sambuc EXPECT(mt, eof_type, "<<EOF>>");
654*0a6a1f1dSLionel Sambuc }
655*0a6a1f1dSLionel Sambuc
656*0a6a1f1dSLionel Sambuc {
657*0a6a1f1dSLionel Sambuc std::istringstream iss("var1\"var2\"");
658*0a6a1f1dSLionel Sambuc tokenizer mt(iss, false);
659*0a6a1f1dSLionel Sambuc
660*0a6a1f1dSLionel Sambuc EXPECT(mt, word_type, "var1");
661*0a6a1f1dSLionel Sambuc EXPECT(mt, word_type, "var2");
662*0a6a1f1dSLionel Sambuc EXPECT(mt, eof_type, "<<EOF>>");
663*0a6a1f1dSLionel Sambuc EXPECT(mt, eof_type, "<<EOF>>");
664*0a6a1f1dSLionel Sambuc }
665*0a6a1f1dSLionel Sambuc
666*0a6a1f1dSLionel Sambuc {
667*0a6a1f1dSLionel Sambuc std::istringstream iss("var1\" var2 \"");
668*0a6a1f1dSLionel Sambuc tokenizer mt(iss, false);
669*0a6a1f1dSLionel Sambuc
670*0a6a1f1dSLionel Sambuc EXPECT(mt, word_type, "var1");
671*0a6a1f1dSLionel Sambuc EXPECT(mt, word_type, " var2 ");
672*0a6a1f1dSLionel Sambuc EXPECT(mt, eof_type, "<<EOF>>");
673*0a6a1f1dSLionel Sambuc EXPECT(mt, eof_type, "<<EOF>>");
674*0a6a1f1dSLionel Sambuc }
675*0a6a1f1dSLionel Sambuc }
676*0a6a1f1dSLionel Sambuc
677*0a6a1f1dSLionel Sambuc ATF_TEST_CASE(tokenizer_quotes_ws);
ATF_TEST_CASE_HEAD(tokenizer_quotes_ws)678*0a6a1f1dSLionel Sambuc ATF_TEST_CASE_HEAD(tokenizer_quotes_ws)
679*0a6a1f1dSLionel Sambuc {
680*0a6a1f1dSLionel Sambuc set_md_var("descr", "Tests the tokenizer class using a parser with "
681*0a6a1f1dSLionel Sambuc "quoted strings and skipping whitespace");
682*0a6a1f1dSLionel Sambuc }
ATF_TEST_CASE_BODY(tokenizer_quotes_ws)683*0a6a1f1dSLionel Sambuc ATF_TEST_CASE_BODY(tokenizer_quotes_ws)
684*0a6a1f1dSLionel Sambuc {
685*0a6a1f1dSLionel Sambuc using namespace quotes;
686*0a6a1f1dSLionel Sambuc
687*0a6a1f1dSLionel Sambuc {
688*0a6a1f1dSLionel Sambuc std::istringstream iss(" var ");
689*0a6a1f1dSLionel Sambuc tokenizer mt(iss, true);
690*0a6a1f1dSLionel Sambuc
691*0a6a1f1dSLionel Sambuc EXPECT(mt, word_type, "var");
692*0a6a1f1dSLionel Sambuc EXPECT(mt, eof_type, "<<EOF>>");
693*0a6a1f1dSLionel Sambuc EXPECT(mt, eof_type, "<<EOF>>");
694*0a6a1f1dSLionel Sambuc }
695*0a6a1f1dSLionel Sambuc
696*0a6a1f1dSLionel Sambuc {
697*0a6a1f1dSLionel Sambuc std::istringstream iss(" \"var\" ");
698*0a6a1f1dSLionel Sambuc tokenizer mt(iss, true);
699*0a6a1f1dSLionel Sambuc
700*0a6a1f1dSLionel Sambuc EXPECT(mt, word_type, "var");
701*0a6a1f1dSLionel Sambuc EXPECT(mt, eof_type, "<<EOF>>");
702*0a6a1f1dSLionel Sambuc EXPECT(mt, eof_type, "<<EOF>>");
703*0a6a1f1dSLionel Sambuc }
704*0a6a1f1dSLionel Sambuc
705*0a6a1f1dSLionel Sambuc {
706*0a6a1f1dSLionel Sambuc std::istringstream iss(" var1 \"var2\" ");
707*0a6a1f1dSLionel Sambuc tokenizer mt(iss, true);
708*0a6a1f1dSLionel Sambuc
709*0a6a1f1dSLionel Sambuc EXPECT(mt, word_type, "var1");
710*0a6a1f1dSLionel Sambuc EXPECT(mt, word_type, "var2");
711*0a6a1f1dSLionel Sambuc EXPECT(mt, eof_type, "<<EOF>>");
712*0a6a1f1dSLionel Sambuc EXPECT(mt, eof_type, "<<EOF>>");
713*0a6a1f1dSLionel Sambuc }
714*0a6a1f1dSLionel Sambuc
715*0a6a1f1dSLionel Sambuc {
716*0a6a1f1dSLionel Sambuc std::istringstream iss(" var1 \" var2 \" ");
717*0a6a1f1dSLionel Sambuc tokenizer mt(iss, true);
718*0a6a1f1dSLionel Sambuc
719*0a6a1f1dSLionel Sambuc EXPECT(mt, word_type, "var1");
720*0a6a1f1dSLionel Sambuc EXPECT(mt, word_type, " var2 ");
721*0a6a1f1dSLionel Sambuc EXPECT(mt, eof_type, "<<EOF>>");
722*0a6a1f1dSLionel Sambuc EXPECT(mt, eof_type, "<<EOF>>");
723*0a6a1f1dSLionel Sambuc }
724*0a6a1f1dSLionel Sambuc }
725*0a6a1f1dSLionel Sambuc
726*0a6a1f1dSLionel Sambuc // ------------------------------------------------------------------------
727*0a6a1f1dSLionel Sambuc // Tests for the headers parser.
728*0a6a1f1dSLionel Sambuc // ------------------------------------------------------------------------
729*0a6a1f1dSLionel Sambuc
730*0a6a1f1dSLionel Sambuc class header_reader {
731*0a6a1f1dSLionel Sambuc std::istream& m_is;
732*0a6a1f1dSLionel Sambuc
733*0a6a1f1dSLionel Sambuc public:
header_reader(std::istream & is)734*0a6a1f1dSLionel Sambuc header_reader(std::istream& is) :
735*0a6a1f1dSLionel Sambuc m_is(is)
736*0a6a1f1dSLionel Sambuc {
737*0a6a1f1dSLionel Sambuc }
738*0a6a1f1dSLionel Sambuc
739*0a6a1f1dSLionel Sambuc void
read(void)740*0a6a1f1dSLionel Sambuc read(void)
741*0a6a1f1dSLionel Sambuc {
742*0a6a1f1dSLionel Sambuc std::pair< size_t, tools::parser::headers_map > hml =
743*0a6a1f1dSLionel Sambuc tools::parser::read_headers(m_is, 1);
744*0a6a1f1dSLionel Sambuc tools::parser::validate_content_type(hml.second,
745*0a6a1f1dSLionel Sambuc "application/X-atf-headers-test", 1234);
746*0a6a1f1dSLionel Sambuc }
747*0a6a1f1dSLionel Sambuc
748*0a6a1f1dSLionel Sambuc std::vector< std::string > m_calls;
749*0a6a1f1dSLionel Sambuc };
750*0a6a1f1dSLionel Sambuc
751*0a6a1f1dSLionel Sambuc ATF_TEST_CASE_WITHOUT_HEAD(headers_1);
ATF_TEST_CASE_BODY(headers_1)752*0a6a1f1dSLionel Sambuc ATF_TEST_CASE_BODY(headers_1)
753*0a6a1f1dSLionel Sambuc {
754*0a6a1f1dSLionel Sambuc const char* input =
755*0a6a1f1dSLionel Sambuc ""
756*0a6a1f1dSLionel Sambuc ;
757*0a6a1f1dSLionel Sambuc
758*0a6a1f1dSLionel Sambuc const char* exp_calls[] = {
759*0a6a1f1dSLionel Sambuc NULL
760*0a6a1f1dSLionel Sambuc };
761*0a6a1f1dSLionel Sambuc
762*0a6a1f1dSLionel Sambuc const char* exp_errors[] = {
763*0a6a1f1dSLionel Sambuc "1: Unexpected token `<<EOF>>'; expected a header name",
764*0a6a1f1dSLionel Sambuc NULL
765*0a6a1f1dSLionel Sambuc };
766*0a6a1f1dSLionel Sambuc
767*0a6a1f1dSLionel Sambuc do_parser_test< header_reader >(input, exp_calls, exp_errors);
768*0a6a1f1dSLionel Sambuc }
769*0a6a1f1dSLionel Sambuc
770*0a6a1f1dSLionel Sambuc ATF_TEST_CASE_WITHOUT_HEAD(headers_2);
ATF_TEST_CASE_BODY(headers_2)771*0a6a1f1dSLionel Sambuc ATF_TEST_CASE_BODY(headers_2)
772*0a6a1f1dSLionel Sambuc {
773*0a6a1f1dSLionel Sambuc const char* input =
774*0a6a1f1dSLionel Sambuc "Content-Type\n"
775*0a6a1f1dSLionel Sambuc ;
776*0a6a1f1dSLionel Sambuc
777*0a6a1f1dSLionel Sambuc const char* exp_calls[] = {
778*0a6a1f1dSLionel Sambuc NULL
779*0a6a1f1dSLionel Sambuc };
780*0a6a1f1dSLionel Sambuc
781*0a6a1f1dSLionel Sambuc const char* exp_errors[] = {
782*0a6a1f1dSLionel Sambuc "1: Unexpected token `<<NEWLINE>>'; expected `:'",
783*0a6a1f1dSLionel Sambuc NULL
784*0a6a1f1dSLionel Sambuc };
785*0a6a1f1dSLionel Sambuc
786*0a6a1f1dSLionel Sambuc do_parser_test< header_reader >(input, exp_calls, exp_errors);
787*0a6a1f1dSLionel Sambuc }
788*0a6a1f1dSLionel Sambuc
789*0a6a1f1dSLionel Sambuc ATF_TEST_CASE_WITHOUT_HEAD(headers_3);
ATF_TEST_CASE_BODY(headers_3)790*0a6a1f1dSLionel Sambuc ATF_TEST_CASE_BODY(headers_3)
791*0a6a1f1dSLionel Sambuc {
792*0a6a1f1dSLionel Sambuc const char* input =
793*0a6a1f1dSLionel Sambuc "Content-Type:\n"
794*0a6a1f1dSLionel Sambuc ;
795*0a6a1f1dSLionel Sambuc
796*0a6a1f1dSLionel Sambuc const char* exp_calls[] = {
797*0a6a1f1dSLionel Sambuc NULL
798*0a6a1f1dSLionel Sambuc };
799*0a6a1f1dSLionel Sambuc
800*0a6a1f1dSLionel Sambuc const char* exp_errors[] = {
801*0a6a1f1dSLionel Sambuc "1: Unexpected token `<<NEWLINE>>'; expected a textual value",
802*0a6a1f1dSLionel Sambuc NULL
803*0a6a1f1dSLionel Sambuc };
804*0a6a1f1dSLionel Sambuc
805*0a6a1f1dSLionel Sambuc do_parser_test< header_reader >(input, exp_calls, exp_errors);
806*0a6a1f1dSLionel Sambuc }
807*0a6a1f1dSLionel Sambuc
808*0a6a1f1dSLionel Sambuc ATF_TEST_CASE_WITHOUT_HEAD(headers_4);
ATF_TEST_CASE_BODY(headers_4)809*0a6a1f1dSLionel Sambuc ATF_TEST_CASE_BODY(headers_4)
810*0a6a1f1dSLionel Sambuc {
811*0a6a1f1dSLionel Sambuc const char* input =
812*0a6a1f1dSLionel Sambuc "Content-Type: application/X-atf-headers-test\n"
813*0a6a1f1dSLionel Sambuc ;
814*0a6a1f1dSLionel Sambuc
815*0a6a1f1dSLionel Sambuc const char* exp_calls[] = {
816*0a6a1f1dSLionel Sambuc NULL
817*0a6a1f1dSLionel Sambuc };
818*0a6a1f1dSLionel Sambuc
819*0a6a1f1dSLionel Sambuc const char* exp_errors[] = {
820*0a6a1f1dSLionel Sambuc "2: Unexpected token `<<EOF>>'; expected a header name",
821*0a6a1f1dSLionel Sambuc NULL
822*0a6a1f1dSLionel Sambuc };
823*0a6a1f1dSLionel Sambuc
824*0a6a1f1dSLionel Sambuc do_parser_test< header_reader >(input, exp_calls, exp_errors);
825*0a6a1f1dSLionel Sambuc }
826*0a6a1f1dSLionel Sambuc
827*0a6a1f1dSLionel Sambuc ATF_TEST_CASE_WITHOUT_HEAD(headers_5);
ATF_TEST_CASE_BODY(headers_5)828*0a6a1f1dSLionel Sambuc ATF_TEST_CASE_BODY(headers_5)
829*0a6a1f1dSLionel Sambuc {
830*0a6a1f1dSLionel Sambuc const char* input =
831*0a6a1f1dSLionel Sambuc "Content-Type: application/X-atf-headers-test;\n"
832*0a6a1f1dSLionel Sambuc ;
833*0a6a1f1dSLionel Sambuc
834*0a6a1f1dSLionel Sambuc const char* exp_calls[] = {
835*0a6a1f1dSLionel Sambuc NULL
836*0a6a1f1dSLionel Sambuc };
837*0a6a1f1dSLionel Sambuc
838*0a6a1f1dSLionel Sambuc const char* exp_errors[] = {
839*0a6a1f1dSLionel Sambuc "1: Unexpected token `<<NEWLINE>>'; expected an attribute name",
840*0a6a1f1dSLionel Sambuc NULL
841*0a6a1f1dSLionel Sambuc };
842*0a6a1f1dSLionel Sambuc
843*0a6a1f1dSLionel Sambuc do_parser_test< header_reader >(input, exp_calls, exp_errors);
844*0a6a1f1dSLionel Sambuc }
845*0a6a1f1dSLionel Sambuc
846*0a6a1f1dSLionel Sambuc ATF_TEST_CASE_WITHOUT_HEAD(headers_6);
ATF_TEST_CASE_BODY(headers_6)847*0a6a1f1dSLionel Sambuc ATF_TEST_CASE_BODY(headers_6)
848*0a6a1f1dSLionel Sambuc {
849*0a6a1f1dSLionel Sambuc const char* input =
850*0a6a1f1dSLionel Sambuc "Content-Type: application/X-atf-headers-test; version\n"
851*0a6a1f1dSLionel Sambuc ;
852*0a6a1f1dSLionel Sambuc
853*0a6a1f1dSLionel Sambuc const char* exp_calls[] = {
854*0a6a1f1dSLionel Sambuc NULL
855*0a6a1f1dSLionel Sambuc };
856*0a6a1f1dSLionel Sambuc
857*0a6a1f1dSLionel Sambuc const char* exp_errors[] = {
858*0a6a1f1dSLionel Sambuc "1: Unexpected token `<<NEWLINE>>'; expected `='",
859*0a6a1f1dSLionel Sambuc NULL
860*0a6a1f1dSLionel Sambuc };
861*0a6a1f1dSLionel Sambuc
862*0a6a1f1dSLionel Sambuc do_parser_test< header_reader >(input, exp_calls, exp_errors);
863*0a6a1f1dSLionel Sambuc }
864*0a6a1f1dSLionel Sambuc
865*0a6a1f1dSLionel Sambuc ATF_TEST_CASE_WITHOUT_HEAD(headers_7);
ATF_TEST_CASE_BODY(headers_7)866*0a6a1f1dSLionel Sambuc ATF_TEST_CASE_BODY(headers_7)
867*0a6a1f1dSLionel Sambuc {
868*0a6a1f1dSLionel Sambuc const char* input =
869*0a6a1f1dSLionel Sambuc "Content-Type: application/X-atf-headers-test; version=\n"
870*0a6a1f1dSLionel Sambuc ;
871*0a6a1f1dSLionel Sambuc
872*0a6a1f1dSLionel Sambuc const char* exp_calls[] = {
873*0a6a1f1dSLionel Sambuc NULL
874*0a6a1f1dSLionel Sambuc };
875*0a6a1f1dSLionel Sambuc
876*0a6a1f1dSLionel Sambuc const char* exp_errors[] = {
877*0a6a1f1dSLionel Sambuc "1: Unexpected token `<<NEWLINE>>'; expected word or quoted string",
878*0a6a1f1dSLionel Sambuc NULL
879*0a6a1f1dSLionel Sambuc };
880*0a6a1f1dSLionel Sambuc
881*0a6a1f1dSLionel Sambuc do_parser_test< header_reader >(input, exp_calls, exp_errors);
882*0a6a1f1dSLionel Sambuc }
883*0a6a1f1dSLionel Sambuc
884*0a6a1f1dSLionel Sambuc ATF_TEST_CASE_WITHOUT_HEAD(headers_8);
ATF_TEST_CASE_BODY(headers_8)885*0a6a1f1dSLionel Sambuc ATF_TEST_CASE_BODY(headers_8)
886*0a6a1f1dSLionel Sambuc {
887*0a6a1f1dSLionel Sambuc const char* input =
888*0a6a1f1dSLionel Sambuc "Content-Type: application/X-atf-headers-test; version=\"1234\n"
889*0a6a1f1dSLionel Sambuc ;
890*0a6a1f1dSLionel Sambuc
891*0a6a1f1dSLionel Sambuc const char* exp_calls[] = {
892*0a6a1f1dSLionel Sambuc NULL
893*0a6a1f1dSLionel Sambuc };
894*0a6a1f1dSLionel Sambuc
895*0a6a1f1dSLionel Sambuc const char* exp_errors[] = {
896*0a6a1f1dSLionel Sambuc "1: Missing double quotes before end of line",
897*0a6a1f1dSLionel Sambuc NULL
898*0a6a1f1dSLionel Sambuc };
899*0a6a1f1dSLionel Sambuc
900*0a6a1f1dSLionel Sambuc do_parser_test< header_reader >(input, exp_calls, exp_errors);
901*0a6a1f1dSLionel Sambuc }
902*0a6a1f1dSLionel Sambuc
903*0a6a1f1dSLionel Sambuc ATF_TEST_CASE_WITHOUT_HEAD(headers_9);
ATF_TEST_CASE_BODY(headers_9)904*0a6a1f1dSLionel Sambuc ATF_TEST_CASE_BODY(headers_9)
905*0a6a1f1dSLionel Sambuc {
906*0a6a1f1dSLionel Sambuc const char* input =
907*0a6a1f1dSLionel Sambuc "Content-Type: application/X-atf-headers-test; version=1234\"\n"
908*0a6a1f1dSLionel Sambuc ;
909*0a6a1f1dSLionel Sambuc
910*0a6a1f1dSLionel Sambuc const char* exp_calls[] = {
911*0a6a1f1dSLionel Sambuc NULL
912*0a6a1f1dSLionel Sambuc };
913*0a6a1f1dSLionel Sambuc
914*0a6a1f1dSLionel Sambuc const char* exp_errors[] = {
915*0a6a1f1dSLionel Sambuc "1: Missing double quotes before end of line",
916*0a6a1f1dSLionel Sambuc NULL
917*0a6a1f1dSLionel Sambuc };
918*0a6a1f1dSLionel Sambuc
919*0a6a1f1dSLionel Sambuc do_parser_test< header_reader >(input, exp_calls, exp_errors);
920*0a6a1f1dSLionel Sambuc }
921*0a6a1f1dSLionel Sambuc
922*0a6a1f1dSLionel Sambuc ATF_TEST_CASE_WITHOUT_HEAD(headers_10);
ATF_TEST_CASE_BODY(headers_10)923*0a6a1f1dSLionel Sambuc ATF_TEST_CASE_BODY(headers_10)
924*0a6a1f1dSLionel Sambuc {
925*0a6a1f1dSLionel Sambuc const char* input =
926*0a6a1f1dSLionel Sambuc "Content-Type: application/X-atf-headers-test; version=1234\n"
927*0a6a1f1dSLionel Sambuc ;
928*0a6a1f1dSLionel Sambuc
929*0a6a1f1dSLionel Sambuc const char* exp_calls[] = {
930*0a6a1f1dSLionel Sambuc NULL
931*0a6a1f1dSLionel Sambuc };
932*0a6a1f1dSLionel Sambuc
933*0a6a1f1dSLionel Sambuc const char* exp_errors[] = {
934*0a6a1f1dSLionel Sambuc "2: Unexpected token `<<EOF>>'; expected a header name",
935*0a6a1f1dSLionel Sambuc NULL
936*0a6a1f1dSLionel Sambuc };
937*0a6a1f1dSLionel Sambuc
938*0a6a1f1dSLionel Sambuc do_parser_test< header_reader >(input, exp_calls, exp_errors);
939*0a6a1f1dSLionel Sambuc }
940*0a6a1f1dSLionel Sambuc
941*0a6a1f1dSLionel Sambuc ATF_TEST_CASE_WITHOUT_HEAD(headers_11);
ATF_TEST_CASE_BODY(headers_11)942*0a6a1f1dSLionel Sambuc ATF_TEST_CASE_BODY(headers_11)
943*0a6a1f1dSLionel Sambuc {
944*0a6a1f1dSLionel Sambuc const char* input =
945*0a6a1f1dSLionel Sambuc "Content-Type: application/X-atf-headers-test; version=\"1234\"\n"
946*0a6a1f1dSLionel Sambuc ;
947*0a6a1f1dSLionel Sambuc
948*0a6a1f1dSLionel Sambuc const char* exp_calls[] = {
949*0a6a1f1dSLionel Sambuc NULL
950*0a6a1f1dSLionel Sambuc };
951*0a6a1f1dSLionel Sambuc
952*0a6a1f1dSLionel Sambuc const char* exp_errors[] = {
953*0a6a1f1dSLionel Sambuc "2: Unexpected token `<<EOF>>'; expected a header name",
954*0a6a1f1dSLionel Sambuc NULL
955*0a6a1f1dSLionel Sambuc };
956*0a6a1f1dSLionel Sambuc
957*0a6a1f1dSLionel Sambuc do_parser_test< header_reader >(input, exp_calls, exp_errors);
958*0a6a1f1dSLionel Sambuc }
959*0a6a1f1dSLionel Sambuc
960*0a6a1f1dSLionel Sambuc ATF_TEST_CASE_WITHOUT_HEAD(headers_12);
ATF_TEST_CASE_BODY(headers_12)961*0a6a1f1dSLionel Sambuc ATF_TEST_CASE_BODY(headers_12)
962*0a6a1f1dSLionel Sambuc {
963*0a6a1f1dSLionel Sambuc const char* input =
964*0a6a1f1dSLionel Sambuc "Content-Type: application/X-atf-headers-test; version=\"1234\"\n"
965*0a6a1f1dSLionel Sambuc "a b\n"
966*0a6a1f1dSLionel Sambuc "a-b:\n"
967*0a6a1f1dSLionel Sambuc "a-b: foo;\n"
968*0a6a1f1dSLionel Sambuc "a-b: foo; var\n"
969*0a6a1f1dSLionel Sambuc "a-b: foo; var=\n"
970*0a6a1f1dSLionel Sambuc "a-b: foo; var=\"a\n"
971*0a6a1f1dSLionel Sambuc "a-b: foo; var=a\"\n"
972*0a6a1f1dSLionel Sambuc "a-b: foo; var=\"a\";\n"
973*0a6a1f1dSLionel Sambuc "a-b: foo; var=\"a\"; second\n"
974*0a6a1f1dSLionel Sambuc "a-b: foo; var=\"a\"; second=\n"
975*0a6a1f1dSLionel Sambuc "a-b: foo; var=\"a\"; second=\"b\n"
976*0a6a1f1dSLionel Sambuc "a-b: foo; var=\"a\"; second=b\"\n"
977*0a6a1f1dSLionel Sambuc "a-b: foo; var=\"a\"; second=\"b\"\n"
978*0a6a1f1dSLionel Sambuc ;
979*0a6a1f1dSLionel Sambuc
980*0a6a1f1dSLionel Sambuc const char* exp_calls[] = {
981*0a6a1f1dSLionel Sambuc NULL
982*0a6a1f1dSLionel Sambuc };
983*0a6a1f1dSLionel Sambuc
984*0a6a1f1dSLionel Sambuc const char* exp_errors[] = {
985*0a6a1f1dSLionel Sambuc "2: Unexpected token `b'; expected `:'",
986*0a6a1f1dSLionel Sambuc "3: Unexpected token `<<NEWLINE>>'; expected a textual value",
987*0a6a1f1dSLionel Sambuc "4: Unexpected token `<<NEWLINE>>'; expected an attribute name",
988*0a6a1f1dSLionel Sambuc "5: Unexpected token `<<NEWLINE>>'; expected `='",
989*0a6a1f1dSLionel Sambuc "6: Unexpected token `<<NEWLINE>>'; expected word or quoted string",
990*0a6a1f1dSLionel Sambuc "7: Missing double quotes before end of line",
991*0a6a1f1dSLionel Sambuc "8: Missing double quotes before end of line",
992*0a6a1f1dSLionel Sambuc "9: Unexpected token `<<NEWLINE>>'; expected an attribute name",
993*0a6a1f1dSLionel Sambuc "10: Unexpected token `<<NEWLINE>>'; expected `='",
994*0a6a1f1dSLionel Sambuc "11: Unexpected token `<<NEWLINE>>'; expected word or quoted string",
995*0a6a1f1dSLionel Sambuc "12: Missing double quotes before end of line",
996*0a6a1f1dSLionel Sambuc "13: Missing double quotes before end of line",
997*0a6a1f1dSLionel Sambuc NULL
998*0a6a1f1dSLionel Sambuc };
999*0a6a1f1dSLionel Sambuc
1000*0a6a1f1dSLionel Sambuc do_parser_test< header_reader >(input, exp_calls, exp_errors);
1001*0a6a1f1dSLionel Sambuc }
1002*0a6a1f1dSLionel Sambuc
1003*0a6a1f1dSLionel Sambuc // ------------------------------------------------------------------------
1004*0a6a1f1dSLionel Sambuc // Main.
1005*0a6a1f1dSLionel Sambuc // ------------------------------------------------------------------------
1006*0a6a1f1dSLionel Sambuc
ATF_INIT_TEST_CASES(tcs)1007*0a6a1f1dSLionel Sambuc ATF_INIT_TEST_CASES(tcs)
1008*0a6a1f1dSLionel Sambuc {
1009*0a6a1f1dSLionel Sambuc // Add test cases for the "parse_error" class.
1010*0a6a1f1dSLionel Sambuc ATF_ADD_TEST_CASE(tcs, parse_error_to_string);
1011*0a6a1f1dSLionel Sambuc
1012*0a6a1f1dSLionel Sambuc // Add test cases for the "parse_errors" class.
1013*0a6a1f1dSLionel Sambuc ATF_ADD_TEST_CASE(tcs, parse_errors_what);
1014*0a6a1f1dSLionel Sambuc
1015*0a6a1f1dSLionel Sambuc // Add test cases for the "token" class.
1016*0a6a1f1dSLionel Sambuc ATF_ADD_TEST_CASE(tcs, token_getters);
1017*0a6a1f1dSLionel Sambuc
1018*0a6a1f1dSLionel Sambuc // Add test cases for the "tokenizer" class.
1019*0a6a1f1dSLionel Sambuc ATF_ADD_TEST_CASE(tcs, tokenizer_minimal_nows);
1020*0a6a1f1dSLionel Sambuc ATF_ADD_TEST_CASE(tcs, tokenizer_minimal_ws);
1021*0a6a1f1dSLionel Sambuc ATF_ADD_TEST_CASE(tcs, tokenizer_delims_nows);
1022*0a6a1f1dSLionel Sambuc ATF_ADD_TEST_CASE(tcs, tokenizer_delims_ws);
1023*0a6a1f1dSLionel Sambuc ATF_ADD_TEST_CASE(tcs, tokenizer_keywords_nows);
1024*0a6a1f1dSLionel Sambuc ATF_ADD_TEST_CASE(tcs, tokenizer_keywords_ws);
1025*0a6a1f1dSLionel Sambuc ATF_ADD_TEST_CASE(tcs, tokenizer_quotes_nows);
1026*0a6a1f1dSLionel Sambuc ATF_ADD_TEST_CASE(tcs, tokenizer_quotes_ws);
1027*0a6a1f1dSLionel Sambuc
1028*0a6a1f1dSLionel Sambuc // Add the tests for the headers parser.
1029*0a6a1f1dSLionel Sambuc
1030*0a6a1f1dSLionel Sambuc // Add the test cases for the header file.
1031*0a6a1f1dSLionel Sambuc ATF_ADD_TEST_CASE(tcs, headers_1);
1032*0a6a1f1dSLionel Sambuc ATF_ADD_TEST_CASE(tcs, headers_2);
1033*0a6a1f1dSLionel Sambuc ATF_ADD_TEST_CASE(tcs, headers_3);
1034*0a6a1f1dSLionel Sambuc ATF_ADD_TEST_CASE(tcs, headers_4);
1035*0a6a1f1dSLionel Sambuc ATF_ADD_TEST_CASE(tcs, headers_5);
1036*0a6a1f1dSLionel Sambuc ATF_ADD_TEST_CASE(tcs, headers_6);
1037*0a6a1f1dSLionel Sambuc ATF_ADD_TEST_CASE(tcs, headers_7);
1038*0a6a1f1dSLionel Sambuc ATF_ADD_TEST_CASE(tcs, headers_8);
1039*0a6a1f1dSLionel Sambuc ATF_ADD_TEST_CASE(tcs, headers_9);
1040*0a6a1f1dSLionel Sambuc ATF_ADD_TEST_CASE(tcs, headers_10);
1041*0a6a1f1dSLionel Sambuc ATF_ADD_TEST_CASE(tcs, headers_11);
1042*0a6a1f1dSLionel Sambuc ATF_ADD_TEST_CASE(tcs, headers_12);
1043*0a6a1f1dSLionel Sambuc }
1044