Line data Source code
1 : // Copyright (c) 2012-2024 Made to Order Software Corp. All Rights Reserved
2 : //
3 : // https://snapwebsites.org/project/eventdispatcher
4 : // contact@m2osw.com
5 : //
6 : // This program is free software: you can redistribute it and/or modify
7 : // it under the terms of the GNU General Public License as published by
8 : // the Free Software Foundation, either version 3 of the License, or
9 : // (at your option) any later version.
10 : //
11 : // This program is distributed in the hope that it will be useful,
12 : // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 : // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 : // GNU General Public License for more details.
15 : //
16 : // You should have received a copy of the GNU General Public License
17 : // along with this program. If not, see <https://www.gnu.org/licenses/>.
18 :
19 : // this diagnostic has to be turned off "globally" so the catch2 does not
20 : // generate the warning on the floating point == operator
21 : //
22 : #pragma GCC diagnostic ignored "-Wfloat-equal"
23 :
24 : // self
25 : //
26 : #include "catch_main.h"
27 :
28 :
29 : // reporter
30 : //
31 : #include <eventdispatcher/reporter/lexer.h>
32 :
33 :
34 : // eventdispatcher
35 : //
36 : #include <eventdispatcher/exception.h>
37 :
38 :
39 : // libexcept
40 : //
41 : #include <libexcept/exception.h>
42 :
43 :
44 : // snapdev
45 : //
46 : #include <snapdev/int128_literal.h>
47 : #include <snapdev/ostream_int128.h>
48 :
49 :
50 : // last include
51 : //
52 : #include <snapdev/poison.h>
53 :
54 :
55 :
56 : // make literals work
57 : //
58 : using namespace snapdev::literals;
59 :
60 : namespace
61 : {
62 :
63 :
64 :
65 : char g_white_spaces[] = {
66 : U'\r',
67 : U'\n',
68 : U' ',
69 : U'\t',
70 : U'\f',
71 : };
72 :
73 :
74 : char g_simple_tokens[] = {
75 : U'(',
76 : U')',
77 : U'{',
78 : U'}',
79 : U',',
80 : U':',
81 : //U'=',
82 : U'+',
83 : U'-',
84 : U'*',
85 : U'%',
86 : };
87 :
88 :
89 95 : std::string white_spaces(bool force = false, bool newlines = true)
90 : {
91 95 : std::string result;
92 95 : int count(rand() % 30);
93 95 : if(!force)
94 : {
95 94 : count -= 20;
96 : }
97 : else
98 : {
99 1 : ++count;
100 : }
101 95 : if(count > 0)
102 : {
103 225 : for(int i(0); i < count; ++i)
104 : {
105 193 : if(newlines)
106 : {
107 188 : int const space(rand() % sizeof(g_white_spaces));
108 188 : result += g_white_spaces[space];
109 : }
110 : else
111 : {
112 5 : int const space(rand() % (sizeof(g_white_spaces) - 2) + 2);
113 5 : result += g_white_spaces[space];
114 : }
115 : }
116 : }
117 95 : return result;
118 0 : }
119 :
120 :
121 :
122 : } // no name namespace
123 :
124 :
125 :
126 17 : CATCH_TEST_CASE("reporter_lexer", "[lexer][reporter]")
127 : {
128 17 : CATCH_START_SECTION("empty input")
129 : {
130 5 : SNAP_CATCH2_NAMESPACE::reporter::lexer l("empty.rprtr", "");
131 :
132 1 : SNAP_CATCH2_NAMESPACE::reporter::token t(l.next_token());
133 1 : CATCH_REQUIRE(t.get_token() == SNAP_CATCH2_NAMESPACE::reporter::token_t::TOKEN_EOF);
134 1 : }
135 17 : CATCH_END_SECTION()
136 :
137 17 : CATCH_START_SECTION("white spaces only input")
138 : {
139 4 : SNAP_CATCH2_NAMESPACE::reporter::lexer l("white-spaces-only.rprtr", white_spaces(true));
140 :
141 1 : SNAP_CATCH2_NAMESPACE::reporter::token t(l.next_token());
142 1 : CATCH_REQUIRE(t.get_token() == SNAP_CATCH2_NAMESPACE::reporter::token_t::TOKEN_EOF);
143 1 : }
144 17 : CATCH_END_SECTION()
145 :
146 17 : CATCH_START_SECTION("simple tokens")
147 : {
148 11 : for(auto const c : g_simple_tokens)
149 : {
150 70 : SNAP_CATCH2_NAMESPACE::reporter::lexer l("simple-token.rprtr", white_spaces() + c + white_spaces());
151 :
152 10 : SNAP_CATCH2_NAMESPACE::reporter::token t(l.next_token());
153 10 : CATCH_REQUIRE(t.get_token() == static_cast<SNAP_CATCH2_NAMESPACE::reporter::token_t>(c));
154 10 : t = l.next_token();
155 10 : CATCH_REQUIRE(t.get_token() == SNAP_CATCH2_NAMESPACE::reporter::token_t::TOKEN_EOF);
156 10 : }
157 : }
158 17 : CATCH_END_SECTION()
159 :
160 17 : CATCH_START_SECTION("divide token")
161 : {
162 1 : SNAP_CATCH2_NAMESPACE::reporter::lexer l("divide.rprtr",
163 2 : white_spaces()
164 3 : + "35.3"
165 4 : + white_spaces()
166 3 : + "/"
167 4 : + white_spaces()
168 3 : + "17.2"
169 6 : + white_spaces());
170 :
171 1 : SNAP_CATCH2_NAMESPACE::reporter::token t(l.next_token());
172 1 : CATCH_REQUIRE(t.get_token() == SNAP_CATCH2_NAMESPACE::reporter::token_t::TOKEN_FLOATING_POINT);
173 1 : CATCH_REQUIRE(t.get_floating_point() == 35.3);
174 1 : t = l.next_token();
175 1 : CATCH_REQUIRE(t.get_token() == SNAP_CATCH2_NAMESPACE::reporter::token_t::TOKEN_DIVIDE);
176 1 : t = l.next_token();
177 1 : CATCH_REQUIRE(t.get_token() == SNAP_CATCH2_NAMESPACE::reporter::token_t::TOKEN_FLOATING_POINT);
178 1 : CATCH_REQUIRE(t.get_floating_point() == 17.2);
179 1 : t = l.next_token();
180 1 : CATCH_REQUIRE(t.get_token() == SNAP_CATCH2_NAMESPACE::reporter::token_t::TOKEN_EOF);
181 1 : }
182 17 : CATCH_END_SECTION()
183 :
184 17 : CATCH_START_SECTION("simple comment")
185 : {
186 1 : SNAP_CATCH2_NAMESPACE::reporter::lexer l("float-and-comment.rprtr",
187 2 : white_spaces()
188 3 : + "45.7"
189 4 : + white_spaces()
190 3 : + "//"
191 4 : + white_spaces(false, false) // avoid newlines in those white spaces
192 3 : + "17.2"
193 6 : + white_spaces(false, false));
194 :
195 1 : SNAP_CATCH2_NAMESPACE::reporter::token t(l.next_token());
196 1 : CATCH_REQUIRE(t.get_token() == SNAP_CATCH2_NAMESPACE::reporter::token_t::TOKEN_FLOATING_POINT);
197 1 : CATCH_REQUIRE(t.get_floating_point() == 45.7);
198 1 : t = l.next_token();
199 1 : CATCH_REQUIRE(t.get_token() == SNAP_CATCH2_NAMESPACE::reporter::token_t::TOKEN_EOF);
200 1 : }
201 17 : CATCH_END_SECTION()
202 :
203 17 : CATCH_START_SECTION("divide and comments token")
204 : {
205 1 : SNAP_CATCH2_NAMESPACE::reporter::lexer l("divide-and-comments.rprtr",
206 2 : white_spaces()
207 3 : + "65.31 // this is a float\n"
208 4 : + white_spaces()
209 3 : + "/ // we want to divide it\r\n"
210 4 : + white_spaces()
211 3 : + "71.2 // by another float\n"
212 6 : + white_spaces());
213 :
214 1 : SNAP_CATCH2_NAMESPACE::reporter::token t(l.next_token());
215 1 : CATCH_REQUIRE(t.get_token() == SNAP_CATCH2_NAMESPACE::reporter::token_t::TOKEN_FLOATING_POINT);
216 1 : CATCH_REQUIRE(t.get_floating_point() == 65.31);
217 1 : t = l.next_token();
218 1 : CATCH_REQUIRE(t.get_token() == SNAP_CATCH2_NAMESPACE::reporter::token_t::TOKEN_DIVIDE);
219 1 : t = l.next_token();
220 1 : CATCH_REQUIRE(t.get_token() == SNAP_CATCH2_NAMESPACE::reporter::token_t::TOKEN_FLOATING_POINT);
221 1 : CATCH_REQUIRE(t.get_floating_point() == 71.2);
222 1 : t = l.next_token();
223 1 : CATCH_REQUIRE(t.get_token() == SNAP_CATCH2_NAMESPACE::reporter::token_t::TOKEN_EOF);
224 1 : }
225 17 : CATCH_END_SECTION()
226 :
227 17 : CATCH_START_SECTION("hexadecimal tokens")
228 : {
229 1 : SNAP_CATCH2_NAMESPACE::reporter::lexer l("divide-and-comments.rprtr",
230 : "0x4511231232abcdef\n"
231 3 : + white_spaces()
232 3 : + "0XFFFabc // we want to divide it\r\n"
233 4 : + white_spaces()
234 5 : + "0x04d4b1a2 // by another float\n");
235 :
236 1 : SNAP_CATCH2_NAMESPACE::reporter::token t(l.next_token());
237 1 : CATCH_REQUIRE(t.get_token() == SNAP_CATCH2_NAMESPACE::reporter::token_t::TOKEN_INTEGER);
238 1 : CATCH_REQUIRE(t.get_integer() == 0x4511231232abcdef);
239 1 : t = l.next_token();
240 1 : CATCH_REQUIRE(t.get_token() == SNAP_CATCH2_NAMESPACE::reporter::token_t::TOKEN_INTEGER);
241 1 : CATCH_REQUIRE(t.get_integer() == 0xFFFABC);
242 1 : t = l.next_token();
243 1 : CATCH_REQUIRE(t.get_token() == SNAP_CATCH2_NAMESPACE::reporter::token_t::TOKEN_INTEGER);
244 1 : CATCH_REQUIRE(t.get_integer() == 0x04d4b1a2);
245 1 : t = l.next_token();
246 1 : CATCH_REQUIRE(t.get_token() == SNAP_CATCH2_NAMESPACE::reporter::token_t::TOKEN_EOF);
247 1 : }
248 17 : CATCH_END_SECTION()
249 :
250 17 : CATCH_START_SECTION("compare and comments token")
251 : {
252 1 : SNAP_CATCH2_NAMESPACE::reporter::lexer l("divide-and-comments.rprtr",
253 2 : white_spaces()
254 3 : + "65.31 // this is a float\n"
255 4 : + white_spaces()
256 3 : + "<=> // we want to compare it\r\n"
257 4 : + white_spaces()
258 3 : + "-71.2 // by another float\n"
259 6 : + white_spaces());
260 :
261 1 : SNAP_CATCH2_NAMESPACE::reporter::token t(l.next_token());
262 1 : CATCH_REQUIRE(t.get_token() == SNAP_CATCH2_NAMESPACE::reporter::token_t::TOKEN_FLOATING_POINT);
263 1 : CATCH_REQUIRE(t.get_floating_point() == 65.31);
264 1 : t = l.next_token();
265 1 : CATCH_REQUIRE(t.get_token() == SNAP_CATCH2_NAMESPACE::reporter::token_t::TOKEN_COMPARE);
266 1 : t = l.next_token();
267 1 : CATCH_REQUIRE(t.get_token() == SNAP_CATCH2_NAMESPACE::reporter::token_t::TOKEN_MINUS);
268 1 : t = l.next_token();
269 1 : CATCH_REQUIRE(t.get_token() == SNAP_CATCH2_NAMESPACE::reporter::token_t::TOKEN_FLOATING_POINT);
270 1 : CATCH_REQUIRE(t.get_floating_point() == 71.2);
271 1 : t = l.next_token();
272 1 : CATCH_REQUIRE(t.get_token() == SNAP_CATCH2_NAMESPACE::reporter::token_t::TOKEN_EOF);
273 1 : }
274 17 : CATCH_END_SECTION()
275 :
276 17 : CATCH_START_SECTION("variable tokens")
277 : {
278 1 : SNAP_CATCH2_NAMESPACE::reporter::lexer l("variables.rprtr",
279 2 : white_spaces()
280 3 : + "$var // simple name\n"
281 4 : + white_spaces()
282 3 : + "$_Var123 // different characters\n"
283 4 : + white_spaces()
284 3 : + "${Quoted_Variable_3} // inside { and }\n"
285 6 : + white_spaces());
286 :
287 1 : SNAP_CATCH2_NAMESPACE::reporter::token t(l.next_token());
288 1 : CATCH_REQUIRE(t.get_token() == SNAP_CATCH2_NAMESPACE::reporter::token_t::TOKEN_VARIABLE);
289 1 : CATCH_REQUIRE(t.get_string() == "var");
290 1 : t = l.next_token();
291 1 : CATCH_REQUIRE(t.get_token() == SNAP_CATCH2_NAMESPACE::reporter::token_t::TOKEN_VARIABLE);
292 1 : CATCH_REQUIRE(t.get_string() == "_Var123");
293 1 : t = l.next_token();
294 1 : CATCH_REQUIRE(t.get_token() == SNAP_CATCH2_NAMESPACE::reporter::token_t::TOKEN_VARIABLE);
295 1 : CATCH_REQUIRE(t.get_string() == "Quoted_Variable_3");
296 1 : t = l.next_token();
297 1 : CATCH_REQUIRE(t.get_token() == SNAP_CATCH2_NAMESPACE::reporter::token_t::TOKEN_EOF);
298 1 : }
299 17 : CATCH_END_SECTION()
300 :
301 17 : CATCH_START_SECTION("date tokens")
302 : {
303 1 : SNAP_CATCH2_NAMESPACE::reporter::lexer l("dates.rprtr",
304 2 : white_spaces()
305 3 : + "@1710686374.536271827 // %s.%N timespec\n"
306 4 : + white_spaces()
307 3 : + "@\"03/17/2024 14:35:22\" // double quote %D %T\n"
308 4 : + white_spaces()
309 3 : + "@'05/29/2023 07:41:23' // single quote %D %T\n"
310 6 : + white_spaces());
311 :
312 1 : SNAP_CATCH2_NAMESPACE::reporter::token t(l.next_token());
313 1 : CATCH_REQUIRE(t.get_token() == SNAP_CATCH2_NAMESPACE::reporter::token_t::TOKEN_TIMESPEC);
314 1 : CATCH_REQUIRE(t.get_integer() == 0x65F700A6000000001FF6DBD3_int128);
315 1 : t = l.next_token();
316 1 : CATCH_REQUIRE(t.get_token() == SNAP_CATCH2_NAMESPACE::reporter::token_t::TOKEN_TIMESPEC);
317 : //std::cerr << "2024 time: " << std::hex << t.get_integer() << "\n";
318 1 : CATCH_REQUIRE(t.get_integer() == 0x65F7702A0000000000000000_int128); // TODO: support summer/winter time differences
319 1 : t = l.next_token();
320 1 : CATCH_REQUIRE(t.get_token() == SNAP_CATCH2_NAMESPACE::reporter::token_t::TOKEN_TIMESPEC);
321 : //std::cerr << "2023 time: " << std::hex << t.get_integer() << "\n";
322 1 : CATCH_REQUIRE(t.get_integer() == 0x6474B9930000000000000000_int128); // TODO: support summer/winter time differences
323 1 : t = l.next_token();
324 1 : CATCH_REQUIRE(t.get_token() == SNAP_CATCH2_NAMESPACE::reporter::token_t::TOKEN_EOF);
325 1 : }
326 17 : CATCH_END_SECTION()
327 :
328 17 : CATCH_START_SECTION("IP tokens")
329 : {
330 1 : SNAP_CATCH2_NAMESPACE::reporter::lexer l("ips.rprtr",
331 2 : white_spaces()
332 3 : + "<128.71.3.227> // IPv4 (no port means port 0)\n"
333 4 : + white_spaces()
334 3 : + "<127.0.4.127:8080> // IPv4 with a port\n"
335 4 : + white_spaces()
336 3 : + "<200.6.7.98:443> // another IPv4 with a port\n"
337 4 : + white_spaces()
338 3 : + "<*:53> // localhost IPv4/6 with a port, output as IPv6\n"
339 4 : + white_spaces()
340 3 : + "<[feff::9ab:32:1b6]:2424> // IPv6\n"
341 6 : + white_spaces());
342 :
343 1 : SNAP_CATCH2_NAMESPACE::reporter::token t(l.next_token());
344 1 : CATCH_REQUIRE(t.get_token() == SNAP_CATCH2_NAMESPACE::reporter::token_t::TOKEN_ADDRESS);
345 1 : CATCH_REQUIRE(t.get_string() == "128.71.3.227:0");
346 1 : t = l.next_token();
347 1 : CATCH_REQUIRE(t.get_token() == SNAP_CATCH2_NAMESPACE::reporter::token_t::TOKEN_ADDRESS);
348 1 : CATCH_REQUIRE(t.get_string() == "127.0.4.127:8080");
349 1 : t = l.next_token();
350 1 : CATCH_REQUIRE(t.get_token() == SNAP_CATCH2_NAMESPACE::reporter::token_t::TOKEN_ADDRESS);
351 1 : CATCH_REQUIRE(t.get_string() == "200.6.7.98:443");
352 1 : t = l.next_token();
353 1 : CATCH_REQUIRE(t.get_token() == SNAP_CATCH2_NAMESPACE::reporter::token_t::TOKEN_ADDRESS);
354 1 : CATCH_REQUIRE(t.get_string() == "[::1]:53");
355 1 : t = l.next_token();
356 1 : CATCH_REQUIRE(t.get_token() == SNAP_CATCH2_NAMESPACE::reporter::token_t::TOKEN_ADDRESS);
357 1 : CATCH_REQUIRE(t.get_string() == "[feff::9ab:32:1b6]:2424");
358 1 : t = l.next_token();
359 1 : CATCH_REQUIRE(t.get_token() == SNAP_CATCH2_NAMESPACE::reporter::token_t::TOKEN_EOF);
360 1 : }
361 17 : CATCH_END_SECTION()
362 :
363 17 : CATCH_START_SECTION("double string tokens")
364 : {
365 1 : SNAP_CATCH2_NAMESPACE::reporter::lexer l("strings.rprtr",
366 2 : white_spaces()
367 3 : + "\"\" // empty string\n"
368 4 : + white_spaces()
369 3 : + "\"simple\"\n"
370 4 : + white_spaces()
371 3 : + "\"newline \\n\"\n"
372 4 : + white_spaces()
373 3 : + "\"carriage return \\r\"\n"
374 4 : + white_spaces()
375 3 : + "\"both \\r\\n\"\n"
376 4 : + white_spaces()
377 3 : + "\"backspace \\b\"\n"
378 4 : + white_spaces()
379 3 : + "\"bell \\a\"\n"
380 4 : + white_spaces()
381 3 : + "\"formfeed \\f\"\n"
382 4 : + white_spaces()
383 3 : + "\"tab \\t\"\n"
384 4 : + white_spaces()
385 3 : + "\"vertical tab \\v\"\n"
386 4 : + white_spaces()
387 3 : + "\"others \\\\ \\\" \\' \\`\"\n"
388 6 : + white_spaces());
389 :
390 1 : SNAP_CATCH2_NAMESPACE::reporter::token t(l.next_token());
391 1 : CATCH_REQUIRE(t.get_token() == SNAP_CATCH2_NAMESPACE::reporter::token_t::TOKEN_DOUBLE_STRING);
392 1 : CATCH_REQUIRE(t.get_string() == "");
393 1 : t = l.next_token();
394 1 : CATCH_REQUIRE(t.get_token() == SNAP_CATCH2_NAMESPACE::reporter::token_t::TOKEN_DOUBLE_STRING);
395 1 : CATCH_REQUIRE(t.get_string() == "simple");
396 1 : t = l.next_token();
397 1 : CATCH_REQUIRE(t.get_token() == SNAP_CATCH2_NAMESPACE::reporter::token_t::TOKEN_DOUBLE_STRING);
398 1 : CATCH_REQUIRE(t.get_string() == "newline \n");
399 1 : t = l.next_token();
400 1 : CATCH_REQUIRE(t.get_token() == SNAP_CATCH2_NAMESPACE::reporter::token_t::TOKEN_DOUBLE_STRING);
401 1 : CATCH_REQUIRE(t.get_string() == "carriage return \r");
402 1 : t = l.next_token();
403 1 : CATCH_REQUIRE(t.get_token() == SNAP_CATCH2_NAMESPACE::reporter::token_t::TOKEN_DOUBLE_STRING);
404 1 : CATCH_REQUIRE(t.get_string() == "both \r\n");
405 1 : t = l.next_token();
406 1 : CATCH_REQUIRE(t.get_token() == SNAP_CATCH2_NAMESPACE::reporter::token_t::TOKEN_DOUBLE_STRING);
407 1 : CATCH_REQUIRE(t.get_string() == "backspace \b");
408 1 : t = l.next_token();
409 1 : CATCH_REQUIRE(t.get_token() == SNAP_CATCH2_NAMESPACE::reporter::token_t::TOKEN_DOUBLE_STRING);
410 1 : CATCH_REQUIRE(t.get_string() == "bell \a");
411 1 : t = l.next_token();
412 1 : CATCH_REQUIRE(t.get_token() == SNAP_CATCH2_NAMESPACE::reporter::token_t::TOKEN_DOUBLE_STRING);
413 1 : CATCH_REQUIRE(t.get_string() == "formfeed \f");
414 1 : t = l.next_token();
415 1 : CATCH_REQUIRE(t.get_token() == SNAP_CATCH2_NAMESPACE::reporter::token_t::TOKEN_DOUBLE_STRING);
416 1 : CATCH_REQUIRE(t.get_string() == "tab \t");
417 1 : t = l.next_token();
418 1 : CATCH_REQUIRE(t.get_token() == SNAP_CATCH2_NAMESPACE::reporter::token_t::TOKEN_DOUBLE_STRING);
419 1 : CATCH_REQUIRE(t.get_string() == "vertical tab \v");
420 1 : t = l.next_token();
421 1 : CATCH_REQUIRE(t.get_token() == SNAP_CATCH2_NAMESPACE::reporter::token_t::TOKEN_DOUBLE_STRING);
422 1 : CATCH_REQUIRE(t.get_string() == "others \\ \" ' `");
423 1 : t = l.next_token();
424 1 : CATCH_REQUIRE(t.get_token() == SNAP_CATCH2_NAMESPACE::reporter::token_t::TOKEN_EOF);
425 1 : }
426 17 : CATCH_END_SECTION()
427 :
428 17 : CATCH_START_SECTION("currently unsupported backslash tokens")
429 : {
430 : // at this point the following are not implemented
431 : //
432 1 : char unimplemented[] = {
433 : 'x', 'u', 'U',
434 : '0', '1', '2', '3', '4',
435 : '5', '6', '7', '8', '9',
436 : };
437 14 : for(auto const c : unimplemented)
438 : {
439 91 : SNAP_CATCH2_NAMESPACE::reporter::lexer l("backslashes.rprtr", std::string("test: \"\\") + c + "5\"");
440 13 : SNAP_CATCH2_NAMESPACE::reporter::token t(l.next_token());
441 13 : CATCH_REQUIRE(t.get_token() == SNAP_CATCH2_NAMESPACE::reporter::token_t::TOKEN_IDENTIFIER);
442 13 : CATCH_REQUIRE(t.get_string() == "test");
443 13 : t = l.next_token();
444 13 : CATCH_REQUIRE(t.get_token() == SNAP_CATCH2_NAMESPACE::reporter::token_t::TOKEN_COLON);
445 13 : CATCH_REQUIRE_THROWS_MATCHES(
446 : l.next_token()
447 : , libexcept::fixme
448 : , Catch::Matchers::ExceptionMessage("fixme: sorry, the \\... with a number to define a character are not yet supported."));
449 13 : }
450 : }
451 17 : CATCH_END_SECTION()
452 :
453 17 : CATCH_START_SECTION("single string tokens")
454 : {
455 1 : SNAP_CATCH2_NAMESPACE::reporter::lexer l("strings.rprtr",
456 2 : white_spaces()
457 3 : + "'' // empty string\n"
458 4 : + white_spaces()
459 3 : + "'simple'\n"
460 4 : + white_spaces()
461 3 : + "'newline \\n'\n"
462 4 : + white_spaces()
463 3 : + "'carriage return \\r'\n"
464 4 : + white_spaces()
465 3 : + "'both \\r\\n'\n"
466 4 : + white_spaces()
467 3 : + "'backspace \\b'\n"
468 4 : + white_spaces()
469 3 : + "'bell \\a'\n"
470 4 : + white_spaces()
471 3 : + "'formfeed \\f'\n"
472 4 : + white_spaces()
473 3 : + "'tab \\t'\n"
474 4 : + white_spaces()
475 3 : + "'vertical tab \\v'\n"
476 4 : + white_spaces()
477 3 : + "'others \\\\ \\\" \\' \\`'\n"
478 6 : + white_spaces());
479 :
480 1 : SNAP_CATCH2_NAMESPACE::reporter::token t(l.next_token());
481 1 : CATCH_REQUIRE(t.get_token() == SNAP_CATCH2_NAMESPACE::reporter::token_t::TOKEN_SINGLE_STRING);
482 1 : CATCH_REQUIRE(t.get_string() == "");
483 1 : t = l.next_token();
484 1 : CATCH_REQUIRE(t.get_token() == SNAP_CATCH2_NAMESPACE::reporter::token_t::TOKEN_SINGLE_STRING);
485 1 : CATCH_REQUIRE(t.get_string() == "simple");
486 1 : t = l.next_token();
487 1 : CATCH_REQUIRE(t.get_token() == SNAP_CATCH2_NAMESPACE::reporter::token_t::TOKEN_SINGLE_STRING);
488 1 : CATCH_REQUIRE(t.get_string() == "newline \n");
489 1 : t = l.next_token();
490 1 : CATCH_REQUIRE(t.get_token() == SNAP_CATCH2_NAMESPACE::reporter::token_t::TOKEN_SINGLE_STRING);
491 1 : CATCH_REQUIRE(t.get_string() == "carriage return \r");
492 1 : t = l.next_token();
493 1 : CATCH_REQUIRE(t.get_token() == SNAP_CATCH2_NAMESPACE::reporter::token_t::TOKEN_SINGLE_STRING);
494 1 : CATCH_REQUIRE(t.get_string() == "both \r\n");
495 1 : t = l.next_token();
496 1 : CATCH_REQUIRE(t.get_token() == SNAP_CATCH2_NAMESPACE::reporter::token_t::TOKEN_SINGLE_STRING);
497 1 : CATCH_REQUIRE(t.get_string() == "backspace \b");
498 1 : t = l.next_token();
499 1 : CATCH_REQUIRE(t.get_token() == SNAP_CATCH2_NAMESPACE::reporter::token_t::TOKEN_SINGLE_STRING);
500 1 : CATCH_REQUIRE(t.get_string() == "bell \a");
501 1 : t = l.next_token();
502 1 : CATCH_REQUIRE(t.get_token() == SNAP_CATCH2_NAMESPACE::reporter::token_t::TOKEN_SINGLE_STRING);
503 1 : CATCH_REQUIRE(t.get_string() == "formfeed \f");
504 1 : t = l.next_token();
505 1 : CATCH_REQUIRE(t.get_token() == SNAP_CATCH2_NAMESPACE::reporter::token_t::TOKEN_SINGLE_STRING);
506 1 : CATCH_REQUIRE(t.get_string() == "tab \t");
507 1 : t = l.next_token();
508 1 : CATCH_REQUIRE(t.get_token() == SNAP_CATCH2_NAMESPACE::reporter::token_t::TOKEN_SINGLE_STRING);
509 1 : CATCH_REQUIRE(t.get_string() == "vertical tab \v");
510 1 : t = l.next_token();
511 1 : CATCH_REQUIRE(t.get_token() == SNAP_CATCH2_NAMESPACE::reporter::token_t::TOKEN_SINGLE_STRING);
512 1 : CATCH_REQUIRE(t.get_string() == "others \\ \" ' `");
513 1 : t = l.next_token();
514 1 : CATCH_REQUIRE(t.get_token() == SNAP_CATCH2_NAMESPACE::reporter::token_t::TOKEN_EOF);
515 1 : }
516 17 : CATCH_END_SECTION()
517 :
518 17 : CATCH_START_SECTION("integer tokens")
519 : {
520 1 : SNAP_CATCH2_NAMESPACE::reporter::lexer l("integers.rprtr",
521 2 : white_spaces()
522 3 : + "0\n"
523 4 : + white_spaces()
524 3 : + "1001\n"
525 4 : + white_spaces()
526 3 : + "-34\n"
527 4 : + white_spaces()
528 3 : + "+99\n"
529 6 : + white_spaces());
530 :
531 1 : SNAP_CATCH2_NAMESPACE::reporter::token t(l.next_token());
532 1 : CATCH_REQUIRE(t.get_token() == SNAP_CATCH2_NAMESPACE::reporter::token_t::TOKEN_INTEGER);
533 1 : CATCH_REQUIRE(t.get_integer() == 0);
534 1 : t = l.next_token();
535 1 : CATCH_REQUIRE(t.get_token() == SNAP_CATCH2_NAMESPACE::reporter::token_t::TOKEN_INTEGER);
536 1 : CATCH_REQUIRE(t.get_integer() == 1001);
537 1 : t = l.next_token();
538 1 : CATCH_REQUIRE(t.get_token() == SNAP_CATCH2_NAMESPACE::reporter::token_t::TOKEN_MINUS);
539 1 : t = l.next_token();
540 1 : CATCH_REQUIRE(t.get_token() == SNAP_CATCH2_NAMESPACE::reporter::token_t::TOKEN_INTEGER);
541 1 : CATCH_REQUIRE(t.get_integer() == 34);
542 1 : t = l.next_token();
543 1 : CATCH_REQUIRE(t.get_token() == SNAP_CATCH2_NAMESPACE::reporter::token_t::TOKEN_PLUS);
544 1 : t = l.next_token();
545 1 : CATCH_REQUIRE(t.get_token() == SNAP_CATCH2_NAMESPACE::reporter::token_t::TOKEN_INTEGER);
546 1 : CATCH_REQUIRE(t.get_integer() == 99);
547 1 : t = l.next_token();
548 1 : CATCH_REQUIRE(t.get_token() == SNAP_CATCH2_NAMESPACE::reporter::token_t::TOKEN_EOF);
549 1 : }
550 17 : CATCH_END_SECTION()
551 :
552 17 : CATCH_START_SECTION("floating point tokens")
553 : {
554 1 : SNAP_CATCH2_NAMESPACE::reporter::lexer l("floating-points.rprtr",
555 2 : white_spaces()
556 3 : + "3.\n"
557 4 : + white_spaces()
558 3 : + ".7\n"
559 4 : + white_spaces()
560 3 : + "10.01\n"
561 4 : + white_spaces()
562 3 : + "-34e-34\n"
563 4 : + white_spaces()
564 3 : + "+99e+3\n"
565 6 : + white_spaces());
566 :
567 1 : SNAP_CATCH2_NAMESPACE::reporter::token t(l.next_token());
568 1 : CATCH_REQUIRE(t.get_token() == SNAP_CATCH2_NAMESPACE::reporter::token_t::TOKEN_FLOATING_POINT);
569 1 : CATCH_REQUIRE(t.get_floating_point() == 3.0);
570 1 : t = l.next_token();
571 1 : CATCH_REQUIRE(t.get_token() == SNAP_CATCH2_NAMESPACE::reporter::token_t::TOKEN_FLOATING_POINT);
572 1 : CATCH_REQUIRE(t.get_floating_point() == 0.7);
573 1 : t = l.next_token();
574 1 : CATCH_REQUIRE(t.get_token() == SNAP_CATCH2_NAMESPACE::reporter::token_t::TOKEN_FLOATING_POINT);
575 1 : CATCH_REQUIRE(t.get_floating_point() == 10.01);
576 1 : t = l.next_token();
577 1 : CATCH_REQUIRE(t.get_token() == SNAP_CATCH2_NAMESPACE::reporter::token_t::TOKEN_MINUS);
578 1 : t = l.next_token();
579 1 : CATCH_REQUIRE(t.get_token() == SNAP_CATCH2_NAMESPACE::reporter::token_t::TOKEN_FLOATING_POINT);
580 1 : CATCH_REQUIRE(t.get_floating_point() == 34e-34);
581 1 : t = l.next_token();
582 1 : CATCH_REQUIRE(t.get_token() == SNAP_CATCH2_NAMESPACE::reporter::token_t::TOKEN_PLUS);
583 1 : t = l.next_token();
584 1 : CATCH_REQUIRE(t.get_token() == SNAP_CATCH2_NAMESPACE::reporter::token_t::TOKEN_FLOATING_POINT);
585 1 : CATCH_REQUIRE(t.get_floating_point() == 99e+3);
586 1 : t = l.next_token();
587 1 : CATCH_REQUIRE(t.get_token() == SNAP_CATCH2_NAMESPACE::reporter::token_t::TOKEN_EOF);
588 1 : }
589 17 : CATCH_END_SECTION()
590 :
591 17 : CATCH_START_SECTION("identifier tokens")
592 : {
593 1 : SNAP_CATCH2_NAMESPACE::reporter::lexer l("identifiers.rprtr",
594 2 : white_spaces()
595 3 : + "simple\n"
596 4 : + white_spaces()
597 3 : + "TEST\n"
598 4 : + white_spaces()
599 3 : + "_underscore\n"
600 4 : + white_spaces()
601 3 : + "Number123\n"
602 4 : + white_spaces()
603 3 : + "Inside_Underscore\n"
604 4 : + white_spaces()
605 3 : + "End_\n"
606 6 : + white_spaces());
607 :
608 1 : SNAP_CATCH2_NAMESPACE::reporter::token t(l.next_token());
609 1 : CATCH_REQUIRE(t.get_token() == SNAP_CATCH2_NAMESPACE::reporter::token_t::TOKEN_IDENTIFIER);
610 1 : CATCH_REQUIRE(t.get_string() == "simple");
611 1 : t = l.next_token();
612 1 : CATCH_REQUIRE(t.get_token() == SNAP_CATCH2_NAMESPACE::reporter::token_t::TOKEN_IDENTIFIER);
613 1 : CATCH_REQUIRE(t.get_string() == "TEST");
614 1 : t = l.next_token();
615 1 : CATCH_REQUIRE(t.get_token() == SNAP_CATCH2_NAMESPACE::reporter::token_t::TOKEN_IDENTIFIER);
616 1 : CATCH_REQUIRE(t.get_string() == "_underscore");
617 1 : t = l.next_token();
618 1 : CATCH_REQUIRE(t.get_token() == SNAP_CATCH2_NAMESPACE::reporter::token_t::TOKEN_IDENTIFIER);
619 1 : CATCH_REQUIRE(t.get_string() == "Number123");
620 1 : t = l.next_token();
621 1 : CATCH_REQUIRE(t.get_token() == SNAP_CATCH2_NAMESPACE::reporter::token_t::TOKEN_IDENTIFIER);
622 1 : CATCH_REQUIRE(t.get_string() == "Inside_Underscore");
623 1 : t = l.next_token();
624 1 : CATCH_REQUIRE(t.get_token() == SNAP_CATCH2_NAMESPACE::reporter::token_t::TOKEN_IDENTIFIER);
625 1 : CATCH_REQUIRE(t.get_string() == "End_");
626 1 : t = l.next_token();
627 1 : CATCH_REQUIRE(t.get_token() == SNAP_CATCH2_NAMESPACE::reporter::token_t::TOKEN_EOF);
628 1 : }
629 17 : CATCH_END_SECTION()
630 17 : }
631 :
632 :
633 20 : CATCH_TEST_CASE("reporter_lexer_error", "[lexer][reporter][error]")
634 : {
635 20 : CATCH_START_SECTION("reporter_lexer_error: unterminated string")
636 : {
637 5 : SNAP_CATCH2_NAMESPACE::reporter::lexer l("unterminated-string.rprtr", "\"unterminated");
638 :
639 1 : SNAP_CATCH2_NAMESPACE::reporter::token t(l.next_token());
640 1 : CATCH_REQUIRE(t.get_token() == SNAP_CATCH2_NAMESPACE::reporter::token_t::TOKEN_ERROR);
641 1 : t = l.next_token();
642 1 : CATCH_REQUIRE(t.get_token() == SNAP_CATCH2_NAMESPACE::reporter::token_t::TOKEN_EOF);
643 1 : }
644 20 : CATCH_END_SECTION()
645 :
646 20 : CATCH_START_SECTION("reporter_lexer_error: multi-line string")
647 : {
648 5 : SNAP_CATCH2_NAMESPACE::reporter::lexer l("multi-line-string.rprtr", "\"multi\nline\"");
649 :
650 1 : SNAP_CATCH2_NAMESPACE::reporter::token t(l.next_token());
651 1 : CATCH_REQUIRE(t.get_token() == SNAP_CATCH2_NAMESPACE::reporter::token_t::TOKEN_ERROR);
652 1 : t = l.next_token();
653 1 : CATCH_REQUIRE(t.get_token() == SNAP_CATCH2_NAMESPACE::reporter::token_t::TOKEN_IDENTIFIER);
654 1 : CATCH_REQUIRE(t.get_string() == "line");
655 1 : t = l.next_token();
656 1 : CATCH_REQUIRE(t.get_token() == SNAP_CATCH2_NAMESPACE::reporter::token_t::TOKEN_ERROR);
657 1 : t = l.next_token();
658 1 : CATCH_REQUIRE(t.get_token() == SNAP_CATCH2_NAMESPACE::reporter::token_t::TOKEN_EOF);
659 1 : }
660 20 : CATCH_END_SECTION()
661 :
662 20 : CATCH_START_SECTION("reporter_lexer_error: unterminated string in backslash case")
663 : {
664 1 : SNAP_CATCH2_NAMESPACE::reporter::lexer l("unterminated-backslash.rprtr",
665 5 : "\"string with \\");
666 :
667 1 : SNAP_CATCH2_NAMESPACE::reporter::token t(l.next_token());
668 1 : CATCH_REQUIRE(t.get_token() == SNAP_CATCH2_NAMESPACE::reporter::token_t::TOKEN_ERROR);
669 1 : t = l.next_token();
670 1 : CATCH_REQUIRE(t.get_token() == SNAP_CATCH2_NAMESPACE::reporter::token_t::TOKEN_EOF);
671 1 : }
672 20 : CATCH_END_SECTION()
673 :
674 20 : CATCH_START_SECTION("reporter_lexer_error: empty unquoted variable")
675 : {
676 5 : SNAP_CATCH2_NAMESPACE::reporter::lexer l("empty-variable.rprtr", "empty $ variable name");
677 :
678 1 : SNAP_CATCH2_NAMESPACE::reporter::token t(l.next_token());
679 1 : CATCH_REQUIRE(t.get_token() == SNAP_CATCH2_NAMESPACE::reporter::token_t::TOKEN_IDENTIFIER);
680 1 : CATCH_REQUIRE(t.get_string() == "empty");
681 1 : t = l.next_token();
682 1 : CATCH_REQUIRE(t.get_token() == SNAP_CATCH2_NAMESPACE::reporter::token_t::TOKEN_ERROR);
683 1 : t = l.next_token();
684 1 : CATCH_REQUIRE(t.get_token() == SNAP_CATCH2_NAMESPACE::reporter::token_t::TOKEN_IDENTIFIER);
685 1 : CATCH_REQUIRE(t.get_string() == "variable");
686 1 : t = l.next_token();
687 1 : CATCH_REQUIRE(t.get_token() == SNAP_CATCH2_NAMESPACE::reporter::token_t::TOKEN_IDENTIFIER);
688 1 : CATCH_REQUIRE(t.get_string() == "name");
689 1 : t = l.next_token();
690 1 : CATCH_REQUIRE(t.get_token() == SNAP_CATCH2_NAMESPACE::reporter::token_t::TOKEN_EOF);
691 1 : }
692 20 : CATCH_END_SECTION()
693 :
694 20 : CATCH_START_SECTION("reporter_lexer_error: empty quoted variable")
695 : {
696 5 : SNAP_CATCH2_NAMESPACE::reporter::lexer l("empty-quoted-variable.rprtr", "empty ${} quoted variable name");
697 :
698 1 : SNAP_CATCH2_NAMESPACE::reporter::token t(l.next_token());
699 1 : CATCH_REQUIRE(t.get_token() == SNAP_CATCH2_NAMESPACE::reporter::token_t::TOKEN_IDENTIFIER);
700 1 : CATCH_REQUIRE(t.get_string() == "empty");
701 1 : t = l.next_token();
702 1 : CATCH_REQUIRE(t.get_token() == SNAP_CATCH2_NAMESPACE::reporter::token_t::TOKEN_ERROR);
703 1 : t = l.next_token();
704 1 : CATCH_REQUIRE(t.get_token() == SNAP_CATCH2_NAMESPACE::reporter::token_t::TOKEN_IDENTIFIER);
705 1 : CATCH_REQUIRE(t.get_string() == "quoted");
706 1 : t = l.next_token();
707 1 : CATCH_REQUIRE(t.get_token() == SNAP_CATCH2_NAMESPACE::reporter::token_t::TOKEN_IDENTIFIER);
708 1 : CATCH_REQUIRE(t.get_string() == "variable");
709 1 : t = l.next_token();
710 1 : CATCH_REQUIRE(t.get_token() == SNAP_CATCH2_NAMESPACE::reporter::token_t::TOKEN_IDENTIFIER);
711 1 : CATCH_REQUIRE(t.get_string() == "name");
712 1 : t = l.next_token();
713 1 : CATCH_REQUIRE(t.get_token() == SNAP_CATCH2_NAMESPACE::reporter::token_t::TOKEN_EOF);
714 1 : }
715 20 : CATCH_END_SECTION()
716 :
717 20 : CATCH_START_SECTION("reporter_lexer_error: invalid quoted variable name")
718 : {
719 5 : SNAP_CATCH2_NAMESPACE::reporter::lexer l("invalid-variable-name.rprtr", "${bad name}");
720 :
721 1 : SNAP_CATCH2_NAMESPACE::reporter::token t(l.next_token());
722 1 : CATCH_REQUIRE(t.get_token() == SNAP_CATCH2_NAMESPACE::reporter::token_t::TOKEN_ERROR);
723 1 : t = l.next_token();
724 1 : CATCH_REQUIRE(t.get_token() == SNAP_CATCH2_NAMESPACE::reporter::token_t::TOKEN_IDENTIFIER);
725 1 : CATCH_REQUIRE(t.get_string() == "name");
726 1 : t = l.next_token();
727 1 : CATCH_REQUIRE(t.get_token() == SNAP_CATCH2_NAMESPACE::reporter::token_t::TOKEN_CLOSE_CURLY_BRACE);
728 1 : t = l.next_token();
729 1 : CATCH_REQUIRE(t.get_token() == SNAP_CATCH2_NAMESPACE::reporter::token_t::TOKEN_EOF);
730 1 : }
731 20 : CATCH_END_SECTION()
732 :
733 20 : CATCH_START_SECTION("reporter_lexer_error: empty date (double quote)")
734 : {
735 5 : SNAP_CATCH2_NAMESPACE::reporter::lexer l("unterminated-date.rprtr", "@\"\"");
736 :
737 1 : SNAP_CATCH2_NAMESPACE::reporter::token t(l.next_token());
738 1 : CATCH_REQUIRE(t.get_token() == SNAP_CATCH2_NAMESPACE::reporter::token_t::TOKEN_ERROR);
739 1 : t = l.next_token();
740 1 : CATCH_REQUIRE(t.get_token() == SNAP_CATCH2_NAMESPACE::reporter::token_t::TOKEN_EOF);
741 1 : }
742 20 : CATCH_END_SECTION()
743 :
744 20 : CATCH_START_SECTION("reporter_lexer_error: empty date (single quote)")
745 : {
746 5 : SNAP_CATCH2_NAMESPACE::reporter::lexer l("unterminated-date.rprtr", "@''");
747 :
748 1 : SNAP_CATCH2_NAMESPACE::reporter::token t(l.next_token());
749 1 : CATCH_REQUIRE(t.get_token() == SNAP_CATCH2_NAMESPACE::reporter::token_t::TOKEN_ERROR);
750 1 : t = l.next_token();
751 1 : CATCH_REQUIRE(t.get_token() == SNAP_CATCH2_NAMESPACE::reporter::token_t::TOKEN_EOF);
752 1 : }
753 20 : CATCH_END_SECTION()
754 :
755 20 : CATCH_START_SECTION("reporter_lexer_error: unterminated date")
756 : {
757 5 : SNAP_CATCH2_NAMESPACE::reporter::lexer l("unterminated-date.rprtr", "@\"unterminated");
758 :
759 1 : SNAP_CATCH2_NAMESPACE::reporter::token t(l.next_token());
760 1 : CATCH_REQUIRE(t.get_token() == SNAP_CATCH2_NAMESPACE::reporter::token_t::TOKEN_ERROR);
761 1 : t = l.next_token();
762 1 : CATCH_REQUIRE(t.get_token() == SNAP_CATCH2_NAMESPACE::reporter::token_t::TOKEN_EOF);
763 1 : }
764 20 : CATCH_END_SECTION()
765 :
766 20 : CATCH_START_SECTION("reporter_lexer_error: unterminated IP")
767 : {
768 5 : SNAP_CATCH2_NAMESPACE::reporter::lexer l("unterminated-ip.rprtr", "<128.71.3.227");
769 :
770 1 : SNAP_CATCH2_NAMESPACE::reporter::token t(l.next_token());
771 1 : CATCH_REQUIRE(t.get_token() == SNAP_CATCH2_NAMESPACE::reporter::token_t::TOKEN_ERROR);
772 1 : t = l.next_token();
773 1 : CATCH_REQUIRE(t.get_token() == SNAP_CATCH2_NAMESPACE::reporter::token_t::TOKEN_EOF);
774 1 : }
775 20 : CATCH_END_SECTION()
776 :
777 20 : CATCH_START_SECTION("reporter_lexer_error: bad IP (bad name)")
778 : {
779 5 : SNAP_CATCH2_NAMESPACE::reporter::lexer l("unterminated-ip.rprtr", "<some bad IP address>");
780 :
781 1 : SNAP_CATCH2_NAMESPACE::reporter::token t(l.next_token());
782 1 : CATCH_REQUIRE(t.get_token() == SNAP_CATCH2_NAMESPACE::reporter::token_t::TOKEN_ERROR);
783 1 : t = l.next_token();
784 1 : CATCH_REQUIRE(t.get_token() == SNAP_CATCH2_NAMESPACE::reporter::token_t::TOKEN_EOF);
785 1 : }
786 20 : CATCH_END_SECTION()
787 :
788 20 : CATCH_START_SECTION("reporter_lexer_error: empty IP")
789 : {
790 5 : SNAP_CATCH2_NAMESPACE::reporter::lexer l("empty-ip.rprtr", "<>");
791 :
792 1 : SNAP_CATCH2_NAMESPACE::reporter::token t(l.next_token());
793 1 : CATCH_REQUIRE(t.get_token() == SNAP_CATCH2_NAMESPACE::reporter::token_t::TOKEN_ERROR);
794 1 : t = l.next_token();
795 1 : CATCH_REQUIRE(t.get_token() == SNAP_CATCH2_NAMESPACE::reporter::token_t::TOKEN_EOF);
796 1 : }
797 20 : CATCH_END_SECTION()
798 :
799 20 : CATCH_START_SECTION("reporter_lexer_error: IP range is not available")
800 : {
801 5 : SNAP_CATCH2_NAMESPACE::reporter::lexer l("ip-range.rprtr", "<10.0.1.0-10.0.1.255>");
802 :
803 1 : SNAP_CATCH2_NAMESPACE::reporter::token t(l.next_token());
804 1 : CATCH_REQUIRE(t.get_token() == SNAP_CATCH2_NAMESPACE::reporter::token_t::TOKEN_ERROR);
805 1 : t = l.next_token();
806 1 : CATCH_REQUIRE(t.get_token() == SNAP_CATCH2_NAMESPACE::reporter::token_t::TOKEN_EOF);
807 1 : }
808 20 : CATCH_END_SECTION()
809 :
810 20 : CATCH_START_SECTION("reporter_lexer_error: no from IP")
811 : {
812 5 : SNAP_CATCH2_NAMESPACE::reporter::lexer l("no-from-ip.rprtr", "<-10.0.1.255>");
813 :
814 1 : SNAP_CATCH2_NAMESPACE::reporter::token t(l.next_token());
815 1 : CATCH_REQUIRE(t.get_token() == SNAP_CATCH2_NAMESPACE::reporter::token_t::TOKEN_ERROR);
816 1 : t = l.next_token();
817 1 : CATCH_REQUIRE(t.get_token() == SNAP_CATCH2_NAMESPACE::reporter::token_t::TOKEN_EOF);
818 1 : }
819 20 : CATCH_END_SECTION()
820 :
821 20 : CATCH_START_SECTION("reporter_lexer_error: bad integer")
822 : {
823 1 : SNAP_CATCH2_NAMESPACE::reporter::lexer l("bad-integers.rprtr",
824 : "10000000000000000000\n"
825 : "1-1\n"
826 5 : "1+1\n");
827 :
828 1 : SNAP_CATCH2_NAMESPACE::reporter::token t(l.next_token());
829 1 : CATCH_REQUIRE(t.get_token() == SNAP_CATCH2_NAMESPACE::reporter::token_t::TOKEN_ERROR);
830 3 : for(int i(0); i < 2; ++i)
831 : {
832 2 : t = l.next_token();
833 2 : CATCH_REQUIRE(t.get_token() == SNAP_CATCH2_NAMESPACE::reporter::token_t::TOKEN_ERROR);
834 : }
835 1 : t = l.next_token();
836 1 : CATCH_REQUIRE(t.get_token() == SNAP_CATCH2_NAMESPACE::reporter::token_t::TOKEN_EOF);
837 1 : }
838 20 : CATCH_END_SECTION()
839 :
840 20 : CATCH_START_SECTION("reporter_lexer_error: bad floating points")
841 : {
842 1 : SNAP_CATCH2_NAMESPACE::reporter::lexer l("bad-floating-points.rprtr",
843 : "3.3e+\n"
844 : "3.3e++5\n"
845 : "3.3ee+5\n"
846 : "3.3EE+5\n"
847 : "3.3EE++5\n"
848 : "3e++5\n"
849 : "3ee+5\n"
850 : "3EE+5\n"
851 : "3EE++5\n"
852 : "3.3e-\n"
853 : "3.3e--5\n"
854 : "3.3ee-5\n"
855 : "3.3EE-5\n"
856 : "3.3EE--5\n"
857 : "3e--5\n"
858 : "3ee-5\n"
859 : "3EE-5\n"
860 : "3EE--5\n"
861 : "3..3e-3\n"
862 : "3.3.e-5\n"
863 : "3.3e.+6\n"
864 : "3.3e-.5\n"
865 5 : "3.3e9.\n");
866 :
867 1 : SNAP_CATCH2_NAMESPACE::reporter::token t(l.next_token());
868 1 : CATCH_REQUIRE(t.get_token() == SNAP_CATCH2_NAMESPACE::reporter::token_t::TOKEN_ERROR);
869 23 : for(int i(0); i < 22; ++i)
870 : {
871 22 : t = l.next_token();
872 22 : CATCH_REQUIRE(t.get_token() == SNAP_CATCH2_NAMESPACE::reporter::token_t::TOKEN_ERROR);
873 : }
874 1 : t = l.next_token();
875 1 : CATCH_REQUIRE(t.get_token() == SNAP_CATCH2_NAMESPACE::reporter::token_t::TOKEN_EOF);
876 1 : }
877 20 : CATCH_END_SECTION()
878 :
879 20 : CATCH_START_SECTION("reporter_lexer_error: variable name cannot start with digit")
880 : {
881 1 : SNAP_CATCH2_NAMESPACE::reporter::lexer l("unexpected-digit.rprtr",
882 : "$5var\n"
883 5 : "${0digits_allowed}\n");
884 :
885 1 : SNAP_CATCH2_NAMESPACE::reporter::token t(l.next_token());
886 1 : CATCH_REQUIRE(t.get_token() == SNAP_CATCH2_NAMESPACE::reporter::token_t::TOKEN_ERROR);
887 2 : for(int i(0); i < 1; ++i)
888 : {
889 1 : t = l.next_token();
890 1 : CATCH_REQUIRE(t.get_token() == SNAP_CATCH2_NAMESPACE::reporter::token_t::TOKEN_ERROR);
891 : }
892 1 : t = l.next_token();
893 1 : CATCH_REQUIRE(t.get_token() == SNAP_CATCH2_NAMESPACE::reporter::token_t::TOKEN_EOF);
894 1 : }
895 20 : CATCH_END_SECTION()
896 :
897 20 : CATCH_START_SECTION("reporter_lexer_error: unexpected character")
898 : {
899 1 : SNAP_CATCH2_NAMESPACE::reporter::lexer l("unexpected-character.rprtr",
900 : "\\\n"
901 5 : "#\n");
902 :
903 1 : SNAP_CATCH2_NAMESPACE::reporter::token t(l.next_token());
904 1 : CATCH_REQUIRE(t.get_token() == SNAP_CATCH2_NAMESPACE::reporter::token_t::TOKEN_ERROR);
905 2 : for(int i(0); i < 1; ++i)
906 : {
907 1 : t = l.next_token();
908 1 : CATCH_REQUIRE(t.get_token() == SNAP_CATCH2_NAMESPACE::reporter::token_t::TOKEN_ERROR);
909 : }
910 1 : t = l.next_token();
911 1 : CATCH_REQUIRE(t.get_token() == SNAP_CATCH2_NAMESPACE::reporter::token_t::TOKEN_EOF);
912 1 : }
913 20 : CATCH_END_SECTION()
914 :
915 20 : CATCH_START_SECTION("reporter_lexer_error: unsupported backslash tokens")
916 : {
917 : // there are likely never going to ever be supported
918 : //
919 1 : char unimplemented[] = {
920 : 'q', 'z',
921 : };
922 3 : for(auto const c : unimplemented)
923 : {
924 14 : SNAP_CATCH2_NAMESPACE::reporter::lexer l("backslashes.rprtr", std::string("test: \"\\") + c + "5\"");
925 2 : SNAP_CATCH2_NAMESPACE::reporter::token t(l.next_token());
926 2 : CATCH_REQUIRE(t.get_token() == SNAP_CATCH2_NAMESPACE::reporter::token_t::TOKEN_IDENTIFIER);
927 2 : CATCH_REQUIRE(t.get_string() == "test");
928 2 : t = l.next_token();
929 2 : CATCH_REQUIRE(t.get_token() == SNAP_CATCH2_NAMESPACE::reporter::token_t::TOKEN_COLON);
930 2 : CATCH_REQUIRE_THROWS_MATCHES(
931 : l.next_token()
932 : , ed::runtime_error
933 : , Catch::Matchers::ExceptionMessage(std::string("event_dispatcher_exception: invalid escape character '") + c + "'."));
934 2 : }
935 : }
936 20 : CATCH_END_SECTION()
937 :
938 20 : CATCH_START_SECTION("reporter_lexer_error: invalid hexadecimal number")
939 : {
940 : {
941 5 : SNAP_CATCH2_NAMESPACE::reporter::lexer l("backslashes.rprtr", "0x");
942 1 : CATCH_REQUIRE_THROWS_MATCHES(
943 : l.next_token()
944 : , ed::runtime_error
945 : , Catch::Matchers::ExceptionMessage("event_dispatcher_exception: invalid hexadecimal number, at least one digits was expected."));
946 1 : }
947 : {
948 5 : SNAP_CATCH2_NAMESPACE::reporter::lexer l("backslashes.rprtr", "0X");
949 1 : CATCH_REQUIRE_THROWS_MATCHES(
950 : l.next_token()
951 : , ed::runtime_error
952 : , Catch::Matchers::ExceptionMessage("event_dispatcher_exception: invalid hexadecimal number, at least one digits was expected."));
953 1 : }
954 : }
955 20 : CATCH_END_SECTION()
956 20 : }
957 :
958 :
959 : // vim: ts=4 sw=4 et
|