Line data Source code
1 : // Copyright (c) 2015-2022 Made to Order Software Corp. All Rights Reserved
2 : //
3 : // https://snapwebsites.org/project/csspp
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 2 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 along
17 : // with this program; if not, write to the Free Software Foundation, Inc.,
18 : // 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 :
20 : /** \file
21 : * \brief Test the expression.cpp file: "=", "!=", "~=", "^=", "$=",
22 : * "*=", "|=" operators.
23 : *
24 : * This test runs a battery of tests agains the expression.cpp "=" (equal),
25 : * "!=" (not equal), "~=" (includes word), "^=" (starts with),
26 : * "$=" (ends with), "*=" (includes substring), |= (includes dashed word)
27 : * operators to ensure full coverage and that all possible left
28 : * hand side and right hand side types are checked for the equality
29 : * CSS Preprocessor extensions.
30 : *
31 : * Note that all the tests use the full chain: lexer, parser, compiler,
32 : * and assembler to make sure the results are correct. So these tests
33 : * exercise the assembler even more than the assembler tests, except that
34 : * it only checks that compressed results are correct instead of all
35 : * output modes, since its only goal is covering all the possible
36 : * expression cases and not the assembler, compiler, parser, and lexer
37 : * classes.
38 : */
39 :
40 : // csspp
41 : //
42 : #include <csspp/assembler.h>
43 : #include <csspp/compiler.h>
44 : #include <csspp/exception.h>
45 : #include <csspp/parser.h>
46 :
47 :
48 : // self
49 : //
50 : #include "catch_main.h"
51 :
52 :
53 : // C++
54 : //
55 : #include <sstream>
56 :
57 :
58 : // last include
59 : //
60 : #include <snapdev/poison.h>
61 :
62 :
63 :
64 12 : CATCH_TEST_CASE("Expression number =,!= number", "[expression] [equality]")
65 : {
66 12 : CATCH_START_SECTION("compare 10 = 3")
67 : {
68 1 : std::stringstream ss;
69 1 : ss << "div { z-index: 10 = 3 ? 9 : 5; }";
70 3 : csspp::position pos("test.css");
71 1 : csspp::lexer::pointer_t l(new csspp::lexer(ss, pos));
72 :
73 2 : csspp::parser p(l);
74 :
75 1 : csspp::node::pointer_t n(p.stylesheet());
76 :
77 1 : csspp::compiler c;
78 1 : c.set_root(n);
79 1 : c.set_date_time_variables(csspp_test::get_now());
80 1 : c.add_path(csspp_test::get_script_path());
81 1 : c.add_path(csspp_test::get_version_script_path());
82 :
83 1 : c.compile(false);
84 :
85 : //std::cerr << "Compiler result is: [" << *c.get_root() << "]\n";
86 :
87 : // to verify that the result is still an INTEGER we have to
88 : // test the root node here
89 1 : std::stringstream compiler_out;
90 1 : compiler_out << *n;
91 1 : VERIFY_TREES(compiler_out.str(),
92 :
93 : "LIST\n"
94 : + csspp_test::get_default_variables() +
95 : " COMPONENT_VALUE\n"
96 : " ARG\n"
97 : " IDENTIFIER \"div\"\n"
98 : " OPEN_CURLYBRACKET B:true\n"
99 : " DECLARATION \"z-index\"\n"
100 : " ARG\n"
101 : " INTEGER \"\" I:5\n"
102 : + csspp_test::get_close_comment(true)
103 :
104 : );
105 :
106 1 : std::stringstream assembler_out;
107 1 : csspp::assembler a(assembler_out);
108 1 : a.output(n, csspp::output_mode_t::COMPRESSED);
109 :
110 : //std::cerr << "----------------- Result is " << static_cast<csspp::output_mode_t>(i) << "\n[" << out.str() << "]\n";
111 :
112 1 : CATCH_REQUIRE(assembler_out.str() ==
113 :
114 : "div{z-index:5}\n"
115 : + csspp_test::get_close_comment()
116 :
117 : );
118 :
119 1 : CATCH_REQUIRE(c.get_root() == n);
120 1 : }
121 12 : CATCH_END_SECTION()
122 :
123 12 : CATCH_START_SECTION("compare 10 != 3")
124 : {
125 1 : std::stringstream ss;
126 : ss << "div { z-index: 10 "
127 2 : << (rand() & 1 ? "not-equal" : "!=")
128 1 : << " 3 ? 9 : 5; }";
129 3 : csspp::position pos("test.css");
130 1 : csspp::lexer::pointer_t l(new csspp::lexer(ss, pos));
131 :
132 2 : csspp::parser p(l);
133 :
134 1 : csspp::node::pointer_t n(p.stylesheet());
135 :
136 1 : csspp::compiler c;
137 1 : c.set_root(n);
138 1 : c.set_date_time_variables(csspp_test::get_now());
139 1 : c.add_path(csspp_test::get_script_path());
140 1 : c.add_path(csspp_test::get_version_script_path());
141 :
142 1 : c.compile(false);
143 :
144 : //std::cerr << "Compiler result is: [" << *c.get_root() << "]\n";
145 :
146 : // to verify that the result is still an INTEGER we have to
147 : // test the root node here
148 1 : std::stringstream compiler_out;
149 1 : compiler_out << *n;
150 1 : VERIFY_TREES(compiler_out.str(),
151 :
152 : "LIST\n"
153 : + csspp_test::get_default_variables() +
154 : " COMPONENT_VALUE\n"
155 : " ARG\n"
156 : " IDENTIFIER \"div\"\n"
157 : " OPEN_CURLYBRACKET B:true\n"
158 : " DECLARATION \"z-index\"\n"
159 : " ARG\n"
160 : " INTEGER \"\" I:9\n"
161 : + csspp_test::get_close_comment(true)
162 :
163 : );
164 :
165 1 : std::stringstream assembler_out;
166 1 : csspp::assembler a(assembler_out);
167 1 : a.output(n, csspp::output_mode_t::COMPRESSED);
168 :
169 : //std::cerr << "----------------- Result is " << static_cast<csspp::output_mode_t>(i) << "\n[" << out.str() << "]\n";
170 :
171 1 : CATCH_REQUIRE(assembler_out.str() ==
172 :
173 : "div{z-index:9}\n"
174 : + csspp_test::get_close_comment()
175 :
176 : );
177 :
178 1 : CATCH_REQUIRE(c.get_root() == n);
179 1 : }
180 12 : CATCH_END_SECTION()
181 :
182 12 : CATCH_START_SECTION("compare 10.2 = 3.1")
183 : {
184 1 : std::stringstream ss;
185 1 : ss << "div { z-index: 10.2 = 3.1 ? 9 : 5; }";
186 3 : csspp::position pos("test.css");
187 1 : csspp::lexer::pointer_t l(new csspp::lexer(ss, pos));
188 :
189 2 : csspp::parser p(l);
190 :
191 1 : csspp::node::pointer_t n(p.stylesheet());
192 :
193 1 : csspp::compiler c;
194 1 : c.set_root(n);
195 1 : c.set_date_time_variables(csspp_test::get_now());
196 1 : c.add_path(csspp_test::get_script_path());
197 1 : c.add_path(csspp_test::get_version_script_path());
198 :
199 1 : c.compile(false);
200 :
201 : //std::cerr << "Compiler result is: [" << *c.get_root() << "]\n";
202 :
203 : // to verify that the result is still an INTEGER we have to
204 : // test the root node here
205 1 : std::stringstream compiler_out;
206 1 : compiler_out << *n;
207 1 : VERIFY_TREES(compiler_out.str(),
208 :
209 : "LIST\n"
210 : + csspp_test::get_default_variables() +
211 : " COMPONENT_VALUE\n"
212 : " ARG\n"
213 : " IDENTIFIER \"div\"\n"
214 : " OPEN_CURLYBRACKET B:true\n"
215 : " DECLARATION \"z-index\"\n"
216 : " ARG\n"
217 : " INTEGER \"\" I:5\n"
218 : + csspp_test::get_close_comment(true)
219 :
220 : );
221 :
222 1 : std::stringstream assembler_out;
223 1 : csspp::assembler a(assembler_out);
224 1 : a.output(n, csspp::output_mode_t::COMPRESSED);
225 :
226 : //std::cerr << "----------------- Result is " << static_cast<csspp::output_mode_t>(i) << "\n[" << out.str() << "]\n";
227 :
228 1 : CATCH_REQUIRE(assembler_out.str() ==
229 :
230 : "div{z-index:5}\n"
231 : + csspp_test::get_close_comment()
232 :
233 : );
234 :
235 1 : CATCH_REQUIRE(c.get_root() == n);
236 1 : }
237 12 : CATCH_END_SECTION()
238 :
239 12 : CATCH_START_SECTION("compare 10.2 != 3.1")
240 : {
241 1 : std::stringstream ss;
242 1 : ss << "div { z-index: 10.2 != 3.1 ? 9 : 5; }";
243 3 : csspp::position pos("test.css");
244 1 : csspp::lexer::pointer_t l(new csspp::lexer(ss, pos));
245 :
246 2 : csspp::parser p(l);
247 :
248 1 : csspp::node::pointer_t n(p.stylesheet());
249 :
250 1 : csspp::compiler c;
251 1 : c.set_root(n);
252 1 : c.set_date_time_variables(csspp_test::get_now());
253 1 : c.add_path(csspp_test::get_script_path());
254 1 : c.add_path(csspp_test::get_version_script_path());
255 :
256 1 : c.compile(false);
257 :
258 : //std::cerr << "Compiler result is: [" << *c.get_root() << "]\n";
259 :
260 : // to verify that the result is still an INTEGER we have to
261 : // test the root node here
262 1 : std::stringstream compiler_out;
263 1 : compiler_out << *n;
264 1 : VERIFY_TREES(compiler_out.str(),
265 :
266 : "LIST\n"
267 : + csspp_test::get_default_variables() +
268 : " COMPONENT_VALUE\n"
269 : " ARG\n"
270 : " IDENTIFIER \"div\"\n"
271 : " OPEN_CURLYBRACKET B:true\n"
272 : " DECLARATION \"z-index\"\n"
273 : " ARG\n"
274 : " INTEGER \"\" I:9\n"
275 : + csspp_test::get_close_comment(true)
276 :
277 : );
278 :
279 1 : std::stringstream assembler_out;
280 1 : csspp::assembler a(assembler_out);
281 1 : a.output(n, csspp::output_mode_t::COMPRESSED);
282 :
283 : //std::cerr << "----------------- Result is " << static_cast<csspp::output_mode_t>(i) << "\n[" << out.str() << "]\n";
284 :
285 1 : CATCH_REQUIRE(assembler_out.str() ==
286 :
287 : "div{z-index:9}\n"
288 : + csspp_test::get_close_comment()
289 :
290 : );
291 :
292 1 : CATCH_REQUIRE(c.get_root() == n);
293 1 : }
294 12 : CATCH_END_SECTION()
295 :
296 12 : CATCH_START_SECTION("compare 10 = 3.1")
297 : {
298 1 : std::stringstream ss;
299 1 : ss << "div { z-index: 10 = 3.1 ? 9 : 5; }";
300 3 : csspp::position pos("test.css");
301 1 : csspp::lexer::pointer_t l(new csspp::lexer(ss, pos));
302 :
303 2 : csspp::parser p(l);
304 :
305 1 : csspp::node::pointer_t n(p.stylesheet());
306 :
307 1 : csspp::compiler c;
308 1 : c.set_root(n);
309 1 : c.set_date_time_variables(csspp_test::get_now());
310 1 : c.add_path(csspp_test::get_script_path());
311 1 : c.add_path(csspp_test::get_version_script_path());
312 :
313 1 : c.compile(false);
314 :
315 : //std::cerr << "Compiler result is: [" << *c.get_root() << "]\n";
316 :
317 : // to verify that the result is still an INTEGER we have to
318 : // test the root node here
319 1 : std::stringstream compiler_out;
320 1 : compiler_out << *n;
321 1 : VERIFY_TREES(compiler_out.str(),
322 :
323 : "LIST\n"
324 : + csspp_test::get_default_variables() +
325 : " COMPONENT_VALUE\n"
326 : " ARG\n"
327 : " IDENTIFIER \"div\"\n"
328 : " OPEN_CURLYBRACKET B:true\n"
329 : " DECLARATION \"z-index\"\n"
330 : " ARG\n"
331 : " INTEGER \"\" I:5\n"
332 : + csspp_test::get_close_comment(true)
333 :
334 : );
335 :
336 1 : std::stringstream assembler_out;
337 1 : csspp::assembler a(assembler_out);
338 1 : a.output(n, csspp::output_mode_t::COMPRESSED);
339 :
340 : //std::cerr << "----------------- Result is " << static_cast<csspp::output_mode_t>(i) << "\n[" << out.str() << "]\n";
341 :
342 1 : CATCH_REQUIRE(assembler_out.str() ==
343 :
344 : "div{z-index:5}\n"
345 : + csspp_test::get_close_comment()
346 :
347 : );
348 :
349 1 : CATCH_REQUIRE(c.get_root() == n);
350 1 : }
351 12 : CATCH_END_SECTION()
352 :
353 12 : CATCH_START_SECTION("compare 10 != 3.1")
354 : {
355 1 : std::stringstream ss;
356 1 : ss << "div { z-index: 10 not-equal 3.1 ? 9 : 5; }";
357 3 : csspp::position pos("test.css");
358 1 : csspp::lexer::pointer_t l(new csspp::lexer(ss, pos));
359 :
360 2 : csspp::parser p(l);
361 :
362 1 : csspp::node::pointer_t n(p.stylesheet());
363 :
364 1 : csspp::compiler c;
365 1 : c.set_root(n);
366 1 : c.set_date_time_variables(csspp_test::get_now());
367 1 : c.add_path(csspp_test::get_script_path());
368 1 : c.add_path(csspp_test::get_version_script_path());
369 :
370 1 : c.compile(false);
371 :
372 : //std::cerr << "Compiler result is: [" << *c.get_root() << "]\n";
373 :
374 : // to verify that the result is still an INTEGER we have to
375 : // test the root node here
376 1 : std::stringstream compiler_out;
377 1 : compiler_out << *n;
378 1 : VERIFY_TREES(compiler_out.str(),
379 :
380 : "LIST\n"
381 : + csspp_test::get_default_variables() +
382 : " COMPONENT_VALUE\n"
383 : " ARG\n"
384 : " IDENTIFIER \"div\"\n"
385 : " OPEN_CURLYBRACKET B:true\n"
386 : " DECLARATION \"z-index\"\n"
387 : " ARG\n"
388 : " INTEGER \"\" I:9\n"
389 : + csspp_test::get_close_comment(true)
390 :
391 : );
392 :
393 1 : std::stringstream assembler_out;
394 1 : csspp::assembler a(assembler_out);
395 1 : a.output(n, csspp::output_mode_t::COMPRESSED);
396 :
397 : //std::cerr << "----------------- Result is " << static_cast<csspp::output_mode_t>(i) << "\n[" << out.str() << "]\n";
398 :
399 1 : CATCH_REQUIRE(assembler_out.str() ==
400 :
401 : "div{z-index:9}\n"
402 : + csspp_test::get_close_comment()
403 :
404 : );
405 :
406 1 : CATCH_REQUIRE(c.get_root() == n);
407 1 : }
408 12 : CATCH_END_SECTION()
409 :
410 12 : CATCH_START_SECTION("compare 10.2 = 3")
411 : {
412 1 : std::stringstream ss;
413 1 : ss << "div { z-index: 10.2 = 3 ? 9 : 5; }";
414 3 : csspp::position pos("test.css");
415 1 : csspp::lexer::pointer_t l(new csspp::lexer(ss, pos));
416 :
417 2 : csspp::parser p(l);
418 :
419 1 : csspp::node::pointer_t n(p.stylesheet());
420 :
421 1 : csspp::compiler c;
422 1 : c.set_root(n);
423 1 : c.set_date_time_variables(csspp_test::get_now());
424 1 : c.add_path(csspp_test::get_script_path());
425 1 : c.add_path(csspp_test::get_version_script_path());
426 :
427 1 : c.compile(false);
428 :
429 : //std::cerr << "Compiler result is: [" << *c.get_root() << "]\n";
430 :
431 : // to verify that the result is still an INTEGER we have to
432 : // test the root node here
433 1 : std::stringstream compiler_out;
434 1 : compiler_out << *n;
435 1 : VERIFY_TREES(compiler_out.str(),
436 :
437 : "LIST\n"
438 : + csspp_test::get_default_variables() +
439 : " COMPONENT_VALUE\n"
440 : " ARG\n"
441 : " IDENTIFIER \"div\"\n"
442 : " OPEN_CURLYBRACKET B:true\n"
443 : " DECLARATION \"z-index\"\n"
444 : " ARG\n"
445 : " INTEGER \"\" I:5\n"
446 : + csspp_test::get_close_comment(true)
447 :
448 : );
449 :
450 1 : std::stringstream assembler_out;
451 1 : csspp::assembler a(assembler_out);
452 1 : a.output(n, csspp::output_mode_t::COMPRESSED);
453 :
454 : //std::cerr << "----------------- Result is " << static_cast<csspp::output_mode_t>(i) << "\n[" << out.str() << "]\n";
455 :
456 1 : CATCH_REQUIRE(assembler_out.str() ==
457 :
458 : "div{z-index:5}\n"
459 : + csspp_test::get_close_comment()
460 :
461 : );
462 :
463 1 : CATCH_REQUIRE(c.get_root() == n);
464 1 : }
465 12 : CATCH_END_SECTION()
466 :
467 12 : CATCH_START_SECTION("compare 10.2 != 3")
468 : {
469 1 : std::stringstream ss;
470 : ss << "div { z-index: 10.2 "
471 2 : << (rand() & 1 ? "not-equal" : "!=")
472 1 : << " 3 ? 9 : 5; }";
473 3 : csspp::position pos("test.css");
474 1 : csspp::lexer::pointer_t l(new csspp::lexer(ss, pos));
475 :
476 2 : csspp::parser p(l);
477 :
478 1 : csspp::node::pointer_t n(p.stylesheet());
479 :
480 1 : csspp::compiler c;
481 1 : c.set_root(n);
482 1 : c.set_date_time_variables(csspp_test::get_now());
483 1 : c.add_path(csspp_test::get_script_path());
484 1 : c.add_path(csspp_test::get_version_script_path());
485 :
486 1 : c.compile(false);
487 :
488 : //std::cerr << "Compiler result is: [" << *c.get_root() << "]\n";
489 :
490 : // to verify that the result is still an INTEGER we have to
491 : // test the root node here
492 1 : std::stringstream compiler_out;
493 1 : compiler_out << *n;
494 1 : VERIFY_TREES(compiler_out.str(),
495 :
496 : "LIST\n"
497 : + csspp_test::get_default_variables() +
498 : " COMPONENT_VALUE\n"
499 : " ARG\n"
500 : " IDENTIFIER \"div\"\n"
501 : " OPEN_CURLYBRACKET B:true\n"
502 : " DECLARATION \"z-index\"\n"
503 : " ARG\n"
504 : " INTEGER \"\" I:9\n"
505 : + csspp_test::get_close_comment(true)
506 :
507 : );
508 :
509 1 : std::stringstream assembler_out;
510 1 : csspp::assembler a(assembler_out);
511 1 : a.output(n, csspp::output_mode_t::COMPRESSED);
512 :
513 : //std::cerr << "----------------- Result is " << static_cast<csspp::output_mode_t>(i) << "\n[" << out.str() << "]\n";
514 :
515 1 : CATCH_REQUIRE(assembler_out.str() ==
516 :
517 : "div{z-index:9}\n"
518 : + csspp_test::get_close_comment()
519 :
520 : );
521 :
522 1 : CATCH_REQUIRE(c.get_root() == n);
523 1 : }
524 12 : CATCH_END_SECTION()
525 :
526 12 : CATCH_START_SECTION("compare (5 = 5) = (7.1 = 7.1)")
527 : {
528 1 : std::stringstream ss;
529 : ss << "div { z-index: (5 = 5) = (7.1 = 7.1)"
530 1 : << " ? 9 : 5; }";
531 3 : csspp::position pos("test.css");
532 1 : csspp::lexer::pointer_t l(new csspp::lexer(ss, pos));
533 :
534 2 : csspp::parser p(l);
535 :
536 1 : csspp::node::pointer_t n(p.stylesheet());
537 :
538 1 : csspp::compiler c;
539 1 : c.set_root(n);
540 1 : c.set_date_time_variables(csspp_test::get_now());
541 1 : c.add_path(csspp_test::get_script_path());
542 1 : c.add_path(csspp_test::get_version_script_path());
543 :
544 1 : c.compile(false);
545 :
546 : //std::cerr << "Compiler result is: [" << *c.get_root() << "]\n";
547 :
548 : // to verify that the result is still an INTEGER we have to
549 : // test the root node here
550 1 : std::stringstream compiler_out;
551 1 : compiler_out << *n;
552 1 : VERIFY_TREES(compiler_out.str(),
553 :
554 : "LIST\n"
555 : + csspp_test::get_default_variables() +
556 : " COMPONENT_VALUE\n"
557 : " ARG\n"
558 : " IDENTIFIER \"div\"\n"
559 : " OPEN_CURLYBRACKET B:true\n"
560 : " DECLARATION \"z-index\"\n"
561 : " ARG\n"
562 : " INTEGER \"\" I:9\n"
563 : + csspp_test::get_close_comment(true)
564 :
565 : );
566 :
567 1 : std::stringstream assembler_out;
568 1 : csspp::assembler a(assembler_out);
569 1 : a.output(n, csspp::output_mode_t::COMPRESSED);
570 :
571 : //std::cerr << "----------------- Result is " << static_cast<csspp::output_mode_t>(i) << "\n[" << out.str() << "]\n";
572 :
573 1 : CATCH_REQUIRE(assembler_out.str() ==
574 :
575 : "div{z-index:9}\n"
576 : + csspp_test::get_close_comment()
577 :
578 : );
579 :
580 1 : CATCH_REQUIRE(c.get_root() == n);
581 1 : }
582 12 : CATCH_END_SECTION()
583 :
584 12 : CATCH_START_SECTION("compare (5 = 5) != (7.1 = 7.1)")
585 : {
586 1 : std::stringstream ss;
587 : ss << "div { z-index: (5 = 5) != (7.1 = 7.1)"
588 1 : << " ? 9 : 5; }";
589 3 : csspp::position pos("test.css");
590 1 : csspp::lexer::pointer_t l(new csspp::lexer(ss, pos));
591 :
592 2 : csspp::parser p(l);
593 :
594 1 : csspp::node::pointer_t n(p.stylesheet());
595 :
596 1 : csspp::compiler c;
597 1 : c.set_root(n);
598 1 : c.set_date_time_variables(csspp_test::get_now());
599 1 : c.add_path(csspp_test::get_script_path());
600 1 : c.add_path(csspp_test::get_version_script_path());
601 :
602 1 : c.compile(false);
603 :
604 : //std::cerr << "Compiler result is: [" << *c.get_root() << "]\n";
605 :
606 : // to verify that the result is still an INTEGER we have to
607 : // test the root node here
608 1 : std::stringstream compiler_out;
609 1 : compiler_out << *n;
610 1 : VERIFY_TREES(compiler_out.str(),
611 :
612 : "LIST\n"
613 : + csspp_test::get_default_variables() +
614 : " COMPONENT_VALUE\n"
615 : " ARG\n"
616 : " IDENTIFIER \"div\"\n"
617 : " OPEN_CURLYBRACKET B:true\n"
618 : " DECLARATION \"z-index\"\n"
619 : " ARG\n"
620 : " INTEGER \"\" I:5\n"
621 : + csspp_test::get_close_comment(true)
622 :
623 : );
624 :
625 1 : std::stringstream assembler_out;
626 1 : csspp::assembler a(assembler_out);
627 1 : a.output(n, csspp::output_mode_t::COMPRESSED);
628 :
629 : //std::cerr << "----------------- Result is " << static_cast<csspp::output_mode_t>(i) << "\n[" << out.str() << "]\n";
630 :
631 1 : CATCH_REQUIRE(assembler_out.str() ==
632 :
633 : "div{z-index:5}\n"
634 : + csspp_test::get_close_comment()
635 :
636 : );
637 :
638 1 : CATCH_REQUIRE(c.get_root() == n);
639 1 : }
640 12 : CATCH_END_SECTION()
641 :
642 12 : CATCH_START_SECTION("compare 7.1% = 7.1%)")
643 : {
644 1 : std::stringstream ss;
645 1 : ss << "div { z-index: 7.1% = 7.1% ? 9 : 5; }";
646 3 : csspp::position pos("test.css");
647 1 : csspp::lexer::pointer_t l(new csspp::lexer(ss, pos));
648 :
649 2 : csspp::parser p(l);
650 :
651 1 : csspp::node::pointer_t n(p.stylesheet());
652 :
653 1 : csspp::compiler c;
654 1 : c.set_root(n);
655 1 : c.set_date_time_variables(csspp_test::get_now());
656 1 : c.add_path(csspp_test::get_script_path());
657 1 : c.add_path(csspp_test::get_version_script_path());
658 :
659 1 : c.compile(false);
660 :
661 : //std::cerr << "Compiler result is: [" << *c.get_root() << "]\n";
662 :
663 : // to verify that the result is still an INTEGER we have to
664 : // test the root node here
665 1 : std::stringstream compiler_out;
666 1 : compiler_out << *n;
667 1 : VERIFY_TREES(compiler_out.str(),
668 :
669 : "LIST\n"
670 : + csspp_test::get_default_variables() +
671 : " COMPONENT_VALUE\n"
672 : " ARG\n"
673 : " IDENTIFIER \"div\"\n"
674 : " OPEN_CURLYBRACKET B:true\n"
675 : " DECLARATION \"z-index\"\n"
676 : " ARG\n"
677 : " INTEGER \"\" I:9\n"
678 : + csspp_test::get_close_comment(true)
679 :
680 : );
681 :
682 1 : std::stringstream assembler_out;
683 1 : csspp::assembler a(assembler_out);
684 1 : a.output(n, csspp::output_mode_t::COMPRESSED);
685 :
686 : //std::cerr << "----------------- Result is " << static_cast<csspp::output_mode_t>(i) << "\n[" << out.str() << "]\n";
687 :
688 1 : CATCH_REQUIRE(assembler_out.str() ==
689 :
690 : "div{z-index:9}\n"
691 : + csspp_test::get_close_comment()
692 :
693 : );
694 :
695 1 : CATCH_REQUIRE(c.get_root() == n);
696 1 : }
697 12 : CATCH_END_SECTION()
698 :
699 12 : CATCH_START_SECTION("compare 7.1% != 7.1%)")
700 : {
701 1 : std::stringstream ss;
702 1 : ss << "div { z-index: 7.1% != 7.1% ? 9 : 5; }";
703 3 : csspp::position pos("test.css");
704 1 : csspp::lexer::pointer_t l(new csspp::lexer(ss, pos));
705 :
706 2 : csspp::parser p(l);
707 :
708 1 : csspp::node::pointer_t n(p.stylesheet());
709 :
710 1 : csspp::compiler c;
711 1 : c.set_root(n);
712 1 : c.set_date_time_variables(csspp_test::get_now());
713 1 : c.add_path(csspp_test::get_script_path());
714 1 : c.add_path(csspp_test::get_version_script_path());
715 :
716 1 : c.compile(false);
717 :
718 : //std::cerr << "Compiler result is: [" << *c.get_root() << "]\n";
719 :
720 : // to verify that the result is still an INTEGER we have to
721 : // test the root node here
722 1 : std::stringstream compiler_out;
723 1 : compiler_out << *n;
724 1 : VERIFY_TREES(compiler_out.str(),
725 :
726 : "LIST\n"
727 : + csspp_test::get_default_variables() +
728 : " COMPONENT_VALUE\n"
729 : " ARG\n"
730 : " IDENTIFIER \"div\"\n"
731 : " OPEN_CURLYBRACKET B:true\n"
732 : " DECLARATION \"z-index\"\n"
733 : " ARG\n"
734 : " INTEGER \"\" I:5\n"
735 : + csspp_test::get_close_comment(true)
736 :
737 : );
738 :
739 1 : std::stringstream assembler_out;
740 1 : csspp::assembler a(assembler_out);
741 1 : a.output(n, csspp::output_mode_t::COMPRESSED);
742 :
743 : //std::cerr << "----------------- Result is " << static_cast<csspp::output_mode_t>(i) << "\n[" << out.str() << "]\n";
744 :
745 1 : CATCH_REQUIRE(assembler_out.str() ==
746 :
747 : "div{z-index:5}\n"
748 : + csspp_test::get_close_comment()
749 :
750 : );
751 :
752 1 : CATCH_REQUIRE(c.get_root() == n);
753 1 : }
754 12 : CATCH_END_SECTION()
755 :
756 : // no error left over
757 12 : VERIFY_ERRORS("");
758 12 : }
759 :
760 3 : CATCH_TEST_CASE("Expression color =,!= color", "[expression] [equality]")
761 : {
762 3 : CATCH_START_SECTION("compare black = white")
763 : {
764 1 : std::stringstream ss;
765 1 : ss << "div { z-index: black = white ? 9 : 5; }";
766 3 : csspp::position pos("test.css");
767 1 : csspp::lexer::pointer_t l(new csspp::lexer(ss, pos));
768 :
769 2 : csspp::parser p(l);
770 :
771 1 : csspp::node::pointer_t n(p.stylesheet());
772 :
773 1 : csspp::compiler c;
774 1 : c.set_root(n);
775 1 : c.set_date_time_variables(csspp_test::get_now());
776 1 : c.add_path(csspp_test::get_script_path());
777 1 : c.add_path(csspp_test::get_version_script_path());
778 :
779 1 : c.compile(false);
780 :
781 : //std::cerr << "Compiler result is: [" << *c.get_root() << "]\n";
782 :
783 : // to verify that the result is still an INTEGER we have to
784 : // test the root node here
785 1 : std::stringstream compiler_out;
786 1 : compiler_out << *n;
787 1 : VERIFY_TREES(compiler_out.str(),
788 :
789 : "LIST\n"
790 : + csspp_test::get_default_variables() +
791 : " COMPONENT_VALUE\n"
792 : " ARG\n"
793 : " IDENTIFIER \"div\"\n"
794 : " OPEN_CURLYBRACKET B:true\n"
795 : " DECLARATION \"z-index\"\n"
796 : " ARG\n"
797 : " INTEGER \"\" I:5\n"
798 : + csspp_test::get_close_comment(true)
799 :
800 : );
801 :
802 1 : std::stringstream assembler_out;
803 1 : csspp::assembler a(assembler_out);
804 1 : a.output(n, csspp::output_mode_t::COMPRESSED);
805 :
806 : //std::cerr << "----------------- Result is " << static_cast<csspp::output_mode_t>(i) << "\n[" << out.str() << "]\n";
807 :
808 1 : CATCH_REQUIRE(assembler_out.str() ==
809 :
810 : "div{z-index:5}\n"
811 : + csspp_test::get_close_comment()
812 :
813 : );
814 :
815 1 : CATCH_REQUIRE(c.get_root() == n);
816 1 : }
817 3 : CATCH_END_SECTION()
818 :
819 3 : CATCH_START_SECTION("compare black = #000")
820 : {
821 1 : std::stringstream ss;
822 1 : ss << "div { z-index: black = #000 ? 9 : 5; }";
823 3 : csspp::position pos("test.css");
824 1 : csspp::lexer::pointer_t l(new csspp::lexer(ss, pos));
825 :
826 2 : csspp::parser p(l);
827 :
828 1 : csspp::node::pointer_t n(p.stylesheet());
829 :
830 1 : csspp::compiler c;
831 1 : c.set_root(n);
832 1 : c.set_date_time_variables(csspp_test::get_now());
833 1 : c.add_path(csspp_test::get_script_path());
834 1 : c.add_path(csspp_test::get_version_script_path());
835 :
836 1 : c.compile(false);
837 :
838 : //std::cerr << "Compiler result is: [" << *c.get_root() << "]\n";
839 :
840 : // to verify that the result is still an INTEGER we have to
841 : // test the root node here
842 1 : std::stringstream compiler_out;
843 1 : compiler_out << *n;
844 1 : VERIFY_TREES(compiler_out.str(),
845 :
846 : "LIST\n"
847 : + csspp_test::get_default_variables() +
848 : " COMPONENT_VALUE\n"
849 : " ARG\n"
850 : " IDENTIFIER \"div\"\n"
851 : " OPEN_CURLYBRACKET B:true\n"
852 : " DECLARATION \"z-index\"\n"
853 : " ARG\n"
854 : " INTEGER \"\" I:9\n"
855 : + csspp_test::get_close_comment(true)
856 :
857 : );
858 :
859 1 : std::stringstream assembler_out;
860 1 : csspp::assembler a(assembler_out);
861 1 : a.output(n, csspp::output_mode_t::COMPRESSED);
862 :
863 : //std::cerr << "----------------- Result is " << static_cast<csspp::output_mode_t>(i) << "\n[" << out.str() << "]\n";
864 :
865 1 : CATCH_REQUIRE(assembler_out.str() ==
866 :
867 : "div{z-index:9}\n"
868 : + csspp_test::get_close_comment()
869 :
870 : );
871 :
872 1 : CATCH_REQUIRE(c.get_root() == n);
873 1 : }
874 3 : CATCH_END_SECTION()
875 :
876 3 : CATCH_START_SECTION("compare rgba(r,g,b,a) = rgba(r,g,b,a)")
877 : {
878 1 : csspp::integer_t const r(rand() % 256);
879 1 : csspp::integer_t const g(rand() % 256);
880 1 : csspp::integer_t const b(rand() % 256);
881 1 : csspp::decimal_number_t const alpha(static_cast<csspp::decimal_number_t>(rand() % 1000) / 1000.0);
882 1 : std::stringstream ss;
883 1 : ss << "div { z-index: rgba("
884 1 : << r
885 1 : << ","
886 1 : << g
887 1 : << ","
888 1 : << b
889 1 : << ","
890 1 : << alpha
891 1 : << ") = rgba("
892 1 : << r
893 1 : << ","
894 1 : << g
895 1 : << ","
896 1 : << b
897 1 : << ","
898 1 : << alpha
899 1 : << ") ? 9 : 5; }";
900 3 : csspp::position pos("test.css");
901 1 : csspp::lexer::pointer_t l(new csspp::lexer(ss, pos));
902 :
903 2 : csspp::parser p(l);
904 :
905 1 : csspp::node::pointer_t n(p.stylesheet());
906 :
907 1 : csspp::compiler c;
908 1 : c.set_root(n);
909 1 : c.set_date_time_variables(csspp_test::get_now());
910 1 : c.add_path(csspp_test::get_script_path());
911 1 : c.add_path(csspp_test::get_version_script_path());
912 :
913 1 : c.compile(false);
914 :
915 : //std::cerr << "Compiler result is: [" << *c.get_root() << "]\n";
916 :
917 : // to verify that the result is still an INTEGER we have to
918 : // test the root node here
919 1 : std::stringstream compiler_out;
920 1 : compiler_out << *n;
921 1 : VERIFY_TREES(compiler_out.str(),
922 :
923 : "LIST\n"
924 : + csspp_test::get_default_variables() +
925 : " COMPONENT_VALUE\n"
926 : " ARG\n"
927 : " IDENTIFIER \"div\"\n"
928 : " OPEN_CURLYBRACKET B:true\n"
929 : " DECLARATION \"z-index\"\n"
930 : " ARG\n"
931 : " INTEGER \"\" I:9\n"
932 : + csspp_test::get_close_comment(true)
933 :
934 : );
935 :
936 1 : std::stringstream assembler_out;
937 1 : csspp::assembler a(assembler_out);
938 1 : a.output(n, csspp::output_mode_t::COMPRESSED);
939 :
940 : //std::cerr << "----------------- Result is " << static_cast<csspp::output_mode_t>(i) << "\n[" << out.str() << "]\n";
941 :
942 1 : CATCH_REQUIRE(assembler_out.str() ==
943 :
944 : "div{z-index:9}\n"
945 : + csspp_test::get_close_comment()
946 :
947 : );
948 :
949 1 : CATCH_REQUIRE(c.get_root() == n);
950 1 : }
951 3 : CATCH_END_SECTION()
952 :
953 : // no error left over
954 3 : VERIFY_ERRORS("");
955 3 : }
956 :
957 16 : CATCH_TEST_CASE("Expression string ~=,^=,$=,*=,|= string", "[expression] [equality]")
958 : {
959 16 : char const * colors[]
960 : {
961 : "bleu", "blanc", "rouge"
962 : };
963 :
964 16 : CATCH_START_SECTION("compare 'blue'/'blanc'/'rouge' ~= 'bleu blanc rouge' -- always true")
965 : {
966 4 : for(size_t idx(0); idx < sizeof(colors) / sizeof(colors[0]); ++idx)
967 : {
968 3 : std::stringstream ss;
969 : ss << "div { z-index: '"
970 : << colors[idx]
971 3 : << "' ~= 'bleu blanc rouge' ? 9 : 5; }";
972 9 : csspp::position pos("test.css");
973 3 : csspp::lexer::pointer_t l(new csspp::lexer(ss, pos));
974 :
975 6 : csspp::parser p(l);
976 :
977 3 : csspp::node::pointer_t n(p.stylesheet());
978 :
979 3 : csspp::compiler c;
980 3 : c.set_root(n);
981 3 : c.set_date_time_variables(csspp_test::get_now());
982 3 : c.add_path(csspp_test::get_script_path());
983 3 : c.add_path(csspp_test::get_version_script_path());
984 :
985 3 : c.compile(false);
986 :
987 : //std::cerr << "Compiler result is: [" << *c.get_root() << "]\n";
988 :
989 : // to verify that the result is still an INTEGER we have to
990 : // test the root node here
991 3 : std::stringstream compiler_out;
992 3 : compiler_out << *n;
993 3 : VERIFY_TREES(compiler_out.str(),
994 :
995 : "LIST\n"
996 : + csspp_test::get_default_variables() +
997 : " COMPONENT_VALUE\n"
998 : " ARG\n"
999 : " IDENTIFIER \"div\"\n"
1000 : " OPEN_CURLYBRACKET B:true\n"
1001 : " DECLARATION \"z-index\"\n"
1002 : " ARG\n"
1003 : " INTEGER \"\" I:9\n"
1004 : + csspp_test::get_close_comment(true)
1005 :
1006 : );
1007 :
1008 3 : std::stringstream assembler_out;
1009 3 : csspp::assembler a(assembler_out);
1010 3 : a.output(n, csspp::output_mode_t::COMPRESSED);
1011 :
1012 : //std::cerr << "----------------- Result is " << static_cast<csspp::output_mode_t>(i) << "\n[" << out.str() << "]\n";
1013 :
1014 3 : CATCH_REQUIRE(assembler_out.str() ==
1015 :
1016 : "div{z-index:9}\n"
1017 : + csspp_test::get_close_comment()
1018 :
1019 : );
1020 :
1021 3 : CATCH_REQUIRE(c.get_root() == n);
1022 3 : }
1023 : }
1024 16 : CATCH_END_SECTION()
1025 :
1026 16 : CATCH_START_SECTION("compare 'blue'/'blanc'/'rouge' ~= 'blue white red' -- always false")
1027 : {
1028 4 : for(size_t idx(0); idx < sizeof(colors) / sizeof(colors[0]); ++idx)
1029 : {
1030 3 : std::stringstream ss;
1031 : ss << "div { z-index: '"
1032 : << colors[idx]
1033 3 : << "' ~= 'blue white red' ? 9 : 5; }";
1034 9 : csspp::position pos("test.css");
1035 3 : csspp::lexer::pointer_t l(new csspp::lexer(ss, pos));
1036 :
1037 6 : csspp::parser p(l);
1038 :
1039 3 : csspp::node::pointer_t n(p.stylesheet());
1040 :
1041 3 : csspp::compiler c;
1042 3 : c.set_root(n);
1043 3 : c.set_date_time_variables(csspp_test::get_now());
1044 3 : c.add_path(csspp_test::get_script_path());
1045 3 : c.add_path(csspp_test::get_version_script_path());
1046 :
1047 3 : c.compile(false);
1048 :
1049 : //std::cerr << "Compiler result is: [" << *c.get_root() << "]\n";
1050 :
1051 : // to verify that the result is still an INTEGER we have to
1052 : // test the root node here
1053 3 : std::stringstream compiler_out;
1054 3 : compiler_out << *n;
1055 3 : VERIFY_TREES(compiler_out.str(),
1056 :
1057 : "LIST\n"
1058 : + csspp_test::get_default_variables() +
1059 : " COMPONENT_VALUE\n"
1060 : " ARG\n"
1061 : " IDENTIFIER \"div\"\n"
1062 : " OPEN_CURLYBRACKET B:true\n"
1063 : " DECLARATION \"z-index\"\n"
1064 : " ARG\n"
1065 : " INTEGER \"\" I:5\n"
1066 : + csspp_test::get_close_comment(true)
1067 :
1068 : );
1069 :
1070 3 : std::stringstream assembler_out;
1071 3 : csspp::assembler a(assembler_out);
1072 3 : a.output(n, csspp::output_mode_t::COMPRESSED);
1073 :
1074 : //std::cerr << "----------------- Result is " << static_cast<csspp::output_mode_t>(i) << "\n[" << out.str() << "]\n";
1075 :
1076 3 : CATCH_REQUIRE(assembler_out.str() ==
1077 :
1078 : "div{z-index:5}\n"
1079 : + csspp_test::get_close_comment()
1080 :
1081 : );
1082 :
1083 3 : CATCH_REQUIRE(c.get_root() == n);
1084 3 : }
1085 : }
1086 16 : CATCH_END_SECTION()
1087 :
1088 16 : CATCH_START_SECTION("compare 'blue blanc rouge'.substr(...) ^= 'bleu blanc rouge' -- always true")
1089 : {
1090 2 : std::string const str("bleu blanc rouge");
1091 17 : for(size_t idx(0); idx < str.length(); ++idx)
1092 : {
1093 16 : std::stringstream ss;
1094 : ss << "div { z-index: '"
1095 32 : << str.substr(0, idx)
1096 32 : << "' ^= 'bleu blanc rouge' ? 9 : 5; }";
1097 48 : csspp::position pos("test.css");
1098 16 : csspp::lexer::pointer_t l(new csspp::lexer(ss, pos));
1099 :
1100 32 : csspp::parser p(l);
1101 :
1102 16 : csspp::node::pointer_t n(p.stylesheet());
1103 :
1104 16 : csspp::compiler c;
1105 16 : c.set_root(n);
1106 16 : c.set_date_time_variables(csspp_test::get_now());
1107 16 : c.add_path(csspp_test::get_script_path());
1108 16 : c.add_path(csspp_test::get_version_script_path());
1109 :
1110 16 : c.compile(false);
1111 :
1112 : //std::cerr << "Compiler result is: [" << *c.get_root() << "]\n";
1113 :
1114 : // to verify that the result is still an INTEGER we have to
1115 : // test the root node here
1116 16 : std::stringstream compiler_out;
1117 16 : compiler_out << *n;
1118 16 : VERIFY_TREES(compiler_out.str(),
1119 :
1120 : "LIST\n"
1121 : + csspp_test::get_default_variables() +
1122 : " COMPONENT_VALUE\n"
1123 : " ARG\n"
1124 : " IDENTIFIER \"div\"\n"
1125 : " OPEN_CURLYBRACKET B:true\n"
1126 : " DECLARATION \"z-index\"\n"
1127 : " ARG\n"
1128 : " INTEGER \"\" I:9\n"
1129 : + csspp_test::get_close_comment(true)
1130 :
1131 : );
1132 :
1133 16 : std::stringstream assembler_out;
1134 16 : csspp::assembler a(assembler_out);
1135 16 : a.output(n, csspp::output_mode_t::COMPRESSED);
1136 :
1137 : //std::cerr << "----------------- Result is " << static_cast<csspp::output_mode_t>(i) << "\n[" << out.str() << "]\n";
1138 :
1139 16 : CATCH_REQUIRE(assembler_out.str() ==
1140 :
1141 : "div{z-index:9}\n"
1142 : + csspp_test::get_close_comment()
1143 :
1144 : );
1145 :
1146 16 : CATCH_REQUIRE(c.get_root() == n);
1147 16 : }
1148 1 : }
1149 16 : CATCH_END_SECTION()
1150 :
1151 16 : CATCH_START_SECTION("compare 'blue blanc rouge'.substr(...) ^= 'bleu blanc rouge' -- always false")
1152 : {
1153 2 : std::string const str("bleu blanc rouge");
1154 16 : for(size_t idx(1); idx < str.length(); ++idx)
1155 : {
1156 15 : std::stringstream ss;
1157 : ss << "div { z-index: '"
1158 30 : << str.substr(1, idx)
1159 30 : << "' ^= 'bleu blanc rouge' ? 9 : 5; }";
1160 45 : csspp::position pos("test.css");
1161 15 : csspp::lexer::pointer_t l(new csspp::lexer(ss, pos));
1162 :
1163 30 : csspp::parser p(l);
1164 :
1165 15 : csspp::node::pointer_t n(p.stylesheet());
1166 :
1167 15 : csspp::compiler c;
1168 15 : c.set_root(n);
1169 15 : c.set_date_time_variables(csspp_test::get_now());
1170 15 : c.add_path(csspp_test::get_script_path());
1171 15 : c.add_path(csspp_test::get_version_script_path());
1172 :
1173 15 : c.compile(false);
1174 :
1175 : //std::cerr << "Compiler result is: [" << *c.get_root() << "]\n";
1176 :
1177 : // to verify that the result is still an INTEGER we have to
1178 : // test the root node here
1179 15 : std::stringstream compiler_out;
1180 15 : compiler_out << *n;
1181 15 : VERIFY_TREES(compiler_out.str(),
1182 :
1183 : "LIST\n"
1184 : + csspp_test::get_default_variables() +
1185 : " COMPONENT_VALUE\n"
1186 : " ARG\n"
1187 : " IDENTIFIER \"div\"\n"
1188 : " OPEN_CURLYBRACKET B:true\n"
1189 : " DECLARATION \"z-index\"\n"
1190 : " ARG\n"
1191 : " INTEGER \"\" I:5\n"
1192 : + csspp_test::get_close_comment(true)
1193 :
1194 : );
1195 :
1196 15 : std::stringstream assembler_out;
1197 15 : csspp::assembler a(assembler_out);
1198 15 : a.output(n, csspp::output_mode_t::COMPRESSED);
1199 :
1200 : //std::cerr << "----------------- Result is " << static_cast<csspp::output_mode_t>(i) << "\n[" << out.str() << "]\n";
1201 :
1202 15 : CATCH_REQUIRE(assembler_out.str() ==
1203 :
1204 : "div{z-index:5}\n"
1205 : + csspp_test::get_close_comment()
1206 :
1207 : );
1208 :
1209 15 : CATCH_REQUIRE(c.get_root() == n);
1210 15 : }
1211 1 : }
1212 16 : CATCH_END_SECTION()
1213 :
1214 : // slight variation
1215 16 : CATCH_START_SECTION("compare 'bleue' ^= 'bleu blanc rouge' -- always false")
1216 : {
1217 1 : std::stringstream ss;
1218 1 : ss << "div { z-index: 'bleue' ^= 'bleu blanc rouge' ? 9 : 5; }";
1219 3 : csspp::position pos("test.css");
1220 1 : csspp::lexer::pointer_t l(new csspp::lexer(ss, pos));
1221 :
1222 2 : csspp::parser p(l);
1223 :
1224 1 : csspp::node::pointer_t n(p.stylesheet());
1225 :
1226 1 : csspp::compiler c;
1227 1 : c.set_root(n);
1228 1 : c.set_date_time_variables(csspp_test::get_now());
1229 1 : c.add_path(csspp_test::get_script_path());
1230 1 : c.add_path(csspp_test::get_version_script_path());
1231 :
1232 1 : c.compile(false);
1233 :
1234 : //std::cerr << "Compiler result is: [" << *c.get_root() << "]\n";
1235 :
1236 : // to verify that the result is still an INTEGER we have to
1237 : // test the root node here
1238 1 : std::stringstream compiler_out;
1239 1 : compiler_out << *n;
1240 1 : VERIFY_TREES(compiler_out.str(),
1241 :
1242 : "LIST\n"
1243 : + csspp_test::get_default_variables() +
1244 : " COMPONENT_VALUE\n"
1245 : " ARG\n"
1246 : " IDENTIFIER \"div\"\n"
1247 : " OPEN_CURLYBRACKET B:true\n"
1248 : " DECLARATION \"z-index\"\n"
1249 : " ARG\n"
1250 : " INTEGER \"\" I:5\n"
1251 : + csspp_test::get_close_comment(true)
1252 :
1253 : );
1254 :
1255 1 : std::stringstream assembler_out;
1256 1 : csspp::assembler a(assembler_out);
1257 1 : a.output(n, csspp::output_mode_t::COMPRESSED);
1258 :
1259 : //std::cerr << "----------------- Result is " << static_cast<csspp::output_mode_t>(i) << "\n[" << out.str() << "]\n";
1260 :
1261 1 : CATCH_REQUIRE(assembler_out.str() ==
1262 :
1263 : "div{z-index:5}\n"
1264 : + csspp_test::get_close_comment()
1265 :
1266 : );
1267 :
1268 1 : CATCH_REQUIRE(c.get_root() == n);
1269 1 : }
1270 16 : CATCH_END_SECTION()
1271 :
1272 : // left side larger than right side
1273 16 : CATCH_START_SECTION("compare 'bleu blanc rouge' ^= 'bleu' -- always false")
1274 : {
1275 1 : std::stringstream ss;
1276 1 : ss << "div { z-index: 'bleu blanc rouge' ^= 'bleu' ? 9 : 5; }";
1277 3 : csspp::position pos("test.css");
1278 1 : csspp::lexer::pointer_t l(new csspp::lexer(ss, pos));
1279 :
1280 2 : csspp::parser p(l);
1281 :
1282 1 : csspp::node::pointer_t n(p.stylesheet());
1283 :
1284 1 : csspp::compiler c;
1285 1 : c.set_root(n);
1286 1 : c.set_date_time_variables(csspp_test::get_now());
1287 1 : c.add_path(csspp_test::get_script_path());
1288 1 : c.add_path(csspp_test::get_version_script_path());
1289 :
1290 1 : c.compile(false);
1291 :
1292 : //std::cerr << "Compiler result is: [" << *c.get_root() << "]\n";
1293 :
1294 : // to verify that the result is still an INTEGER we have to
1295 : // test the root node here
1296 1 : std::stringstream compiler_out;
1297 1 : compiler_out << *n;
1298 1 : VERIFY_TREES(compiler_out.str(),
1299 :
1300 : "LIST\n"
1301 : + csspp_test::get_default_variables() +
1302 : " COMPONENT_VALUE\n"
1303 : " ARG\n"
1304 : " IDENTIFIER \"div\"\n"
1305 : " OPEN_CURLYBRACKET B:true\n"
1306 : " DECLARATION \"z-index\"\n"
1307 : " ARG\n"
1308 : " INTEGER \"\" I:5\n"
1309 : + csspp_test::get_close_comment(true)
1310 :
1311 : );
1312 :
1313 1 : std::stringstream assembler_out;
1314 1 : csspp::assembler a(assembler_out);
1315 1 : a.output(n, csspp::output_mode_t::COMPRESSED);
1316 :
1317 : //std::cerr << "----------------- Result is " << static_cast<csspp::output_mode_t>(i) << "\n[" << out.str() << "]\n";
1318 :
1319 1 : CATCH_REQUIRE(assembler_out.str() ==
1320 :
1321 : "div{z-index:5}\n"
1322 : + csspp_test::get_close_comment()
1323 :
1324 : );
1325 :
1326 1 : CATCH_REQUIRE(c.get_root() == n);
1327 1 : }
1328 16 : CATCH_END_SECTION()
1329 :
1330 16 : CATCH_START_SECTION("compare 'blue blanc rouge'.substr(...) $= 'bleu blanc rouge' -- always true")
1331 : {
1332 2 : std::string const str("bleu blanc rouge");
1333 17 : for(size_t idx(0); idx < str.length(); ++idx)
1334 : {
1335 16 : std::stringstream ss;
1336 : ss << "div { z-index: '"
1337 32 : << str.substr(idx)
1338 32 : << "' $= 'bleu blanc rouge' ? 9 : 5; }";
1339 48 : csspp::position pos("test.css");
1340 16 : csspp::lexer::pointer_t l(new csspp::lexer(ss, pos));
1341 :
1342 32 : csspp::parser p(l);
1343 :
1344 16 : csspp::node::pointer_t n(p.stylesheet());
1345 :
1346 16 : csspp::compiler c;
1347 16 : c.set_root(n);
1348 16 : c.set_date_time_variables(csspp_test::get_now());
1349 16 : c.add_path(csspp_test::get_script_path());
1350 16 : c.add_path(csspp_test::get_version_script_path());
1351 :
1352 16 : c.compile(false);
1353 :
1354 : //std::cerr << "Compiler result is: [" << *c.get_root() << "]\n";
1355 :
1356 : // to verify that the result is still an INTEGER we have to
1357 : // test the root node here
1358 16 : std::stringstream compiler_out;
1359 16 : compiler_out << *n;
1360 16 : VERIFY_TREES(compiler_out.str(),
1361 :
1362 : "LIST\n"
1363 : + csspp_test::get_default_variables() +
1364 : " COMPONENT_VALUE\n"
1365 : " ARG\n"
1366 : " IDENTIFIER \"div\"\n"
1367 : " OPEN_CURLYBRACKET B:true\n"
1368 : " DECLARATION \"z-index\"\n"
1369 : " ARG\n"
1370 : " INTEGER \"\" I:9\n"
1371 : + csspp_test::get_close_comment(true)
1372 :
1373 : );
1374 :
1375 16 : std::stringstream assembler_out;
1376 16 : csspp::assembler a(assembler_out);
1377 16 : a.output(n, csspp::output_mode_t::COMPRESSED);
1378 :
1379 : //std::cerr << "----------------- Result is " << static_cast<csspp::output_mode_t>(i) << "\n[" << out.str() << "]\n";
1380 :
1381 16 : CATCH_REQUIRE(assembler_out.str() ==
1382 :
1383 : "div{z-index:9}\n"
1384 : + csspp_test::get_close_comment()
1385 :
1386 : );
1387 :
1388 16 : CATCH_REQUIRE(c.get_root() == n);
1389 16 : }
1390 1 : }
1391 16 : CATCH_END_SECTION()
1392 :
1393 16 : CATCH_START_SECTION("compare 'blue blanc rouge'.substr(...) $= 'bleu blanc rouge' -- always false")
1394 : {
1395 2 : std::string const str("bleu blanc rouge");
1396 15 : for(size_t idx(1); idx < str.length() - 1; ++idx)
1397 : {
1398 14 : std::stringstream ss;
1399 : ss << "div { z-index: '"
1400 28 : << str.substr(0, idx)
1401 28 : << "' $= 'bleu blanc rouge' ? 9 : 5; }";
1402 42 : csspp::position pos("test.css");
1403 14 : csspp::lexer::pointer_t l(new csspp::lexer(ss, pos));
1404 :
1405 28 : csspp::parser p(l);
1406 :
1407 14 : csspp::node::pointer_t n(p.stylesheet());
1408 :
1409 14 : csspp::compiler c;
1410 14 : c.set_root(n);
1411 14 : c.set_date_time_variables(csspp_test::get_now());
1412 14 : c.add_path(csspp_test::get_script_path());
1413 14 : c.add_path(csspp_test::get_version_script_path());
1414 :
1415 14 : c.compile(false);
1416 :
1417 : //std::cerr << "Compiler result is: [" << *c.get_root() << "]\n";
1418 :
1419 : // to verify that the result is still an INTEGER we have to
1420 : // test the root node here
1421 14 : std::stringstream compiler_out;
1422 14 : compiler_out << *n;
1423 14 : VERIFY_TREES(compiler_out.str(),
1424 :
1425 : "LIST\n"
1426 : + csspp_test::get_default_variables() +
1427 : " COMPONENT_VALUE\n"
1428 : " ARG\n"
1429 : " IDENTIFIER \"div\"\n"
1430 : " OPEN_CURLYBRACKET B:true\n"
1431 : " DECLARATION \"z-index\"\n"
1432 : " ARG\n"
1433 : " INTEGER \"\" I:5\n"
1434 : + csspp_test::get_close_comment(true)
1435 :
1436 : );
1437 :
1438 14 : std::stringstream assembler_out;
1439 14 : csspp::assembler a(assembler_out);
1440 14 : a.output(n, csspp::output_mode_t::COMPRESSED);
1441 :
1442 : //std::cerr << "----------------- Result is " << static_cast<csspp::output_mode_t>(i) << "\n[" << out.str() << "]\n";
1443 :
1444 14 : CATCH_REQUIRE(assembler_out.str() ==
1445 :
1446 : "div{z-index:5}\n"
1447 : + csspp_test::get_close_comment()
1448 :
1449 : );
1450 :
1451 14 : CATCH_REQUIRE(c.get_root() == n);
1452 14 : }
1453 1 : }
1454 16 : CATCH_END_SECTION()
1455 :
1456 : // slight variation
1457 16 : CATCH_START_SECTION("compare 'bouge' $= 'bleu blanc rouge' -- always false")
1458 : {
1459 1 : std::stringstream ss;
1460 1 : ss << "div { z-index: 'bouge' $= 'bleu blanc rouge' ? 9 : 5; }";
1461 3 : csspp::position pos("test.css");
1462 1 : csspp::lexer::pointer_t l(new csspp::lexer(ss, pos));
1463 :
1464 2 : csspp::parser p(l);
1465 :
1466 1 : csspp::node::pointer_t n(p.stylesheet());
1467 :
1468 1 : csspp::compiler c;
1469 1 : c.set_root(n);
1470 1 : c.set_date_time_variables(csspp_test::get_now());
1471 1 : c.add_path(csspp_test::get_script_path());
1472 1 : c.add_path(csspp_test::get_version_script_path());
1473 :
1474 1 : c.compile(false);
1475 :
1476 : //std::cerr << "Compiler result is: [" << *c.get_root() << "]\n";
1477 :
1478 : // to verify that the result is still an INTEGER we have to
1479 : // test the root node here
1480 1 : std::stringstream compiler_out;
1481 1 : compiler_out << *n;
1482 1 : VERIFY_TREES(compiler_out.str(),
1483 :
1484 : "LIST\n"
1485 : + csspp_test::get_default_variables() +
1486 : " COMPONENT_VALUE\n"
1487 : " ARG\n"
1488 : " IDENTIFIER \"div\"\n"
1489 : " OPEN_CURLYBRACKET B:true\n"
1490 : " DECLARATION \"z-index\"\n"
1491 : " ARG\n"
1492 : " INTEGER \"\" I:5\n"
1493 : + csspp_test::get_close_comment(true)
1494 :
1495 : );
1496 :
1497 1 : std::stringstream assembler_out;
1498 1 : csspp::assembler a(assembler_out);
1499 1 : a.output(n, csspp::output_mode_t::COMPRESSED);
1500 :
1501 : //std::cerr << "----------------- Result is " << static_cast<csspp::output_mode_t>(i) << "\n[" << out.str() << "]\n";
1502 :
1503 1 : CATCH_REQUIRE(assembler_out.str() ==
1504 :
1505 : "div{z-index:5}\n"
1506 : + csspp_test::get_close_comment()
1507 :
1508 : );
1509 :
1510 1 : CATCH_REQUIRE(c.get_root() == n);
1511 1 : }
1512 16 : CATCH_END_SECTION()
1513 :
1514 : // left larger than right
1515 16 : CATCH_START_SECTION("compare 'bleu blanc rouge' $= 'rouge' -- always false")
1516 : {
1517 1 : std::stringstream ss;
1518 1 : ss << "div { z-index: 'bleu blanc rouge' $= 'rouge' ? 9 : 5; }";
1519 3 : csspp::position pos("test.css");
1520 1 : csspp::lexer::pointer_t l(new csspp::lexer(ss, pos));
1521 :
1522 2 : csspp::parser p(l);
1523 :
1524 1 : csspp::node::pointer_t n(p.stylesheet());
1525 :
1526 1 : csspp::compiler c;
1527 1 : c.set_root(n);
1528 1 : c.set_date_time_variables(csspp_test::get_now());
1529 1 : c.add_path(csspp_test::get_script_path());
1530 1 : c.add_path(csspp_test::get_version_script_path());
1531 :
1532 1 : c.compile(false);
1533 :
1534 : //std::cerr << "Compiler result is: [" << *c.get_root() << "]\n";
1535 :
1536 : // to verify that the result is still an INTEGER we have to
1537 : // test the root node here
1538 1 : std::stringstream compiler_out;
1539 1 : compiler_out << *n;
1540 1 : VERIFY_TREES(compiler_out.str(),
1541 :
1542 : "LIST\n"
1543 : + csspp_test::get_default_variables() +
1544 : " COMPONENT_VALUE\n"
1545 : " ARG\n"
1546 : " IDENTIFIER \"div\"\n"
1547 : " OPEN_CURLYBRACKET B:true\n"
1548 : " DECLARATION \"z-index\"\n"
1549 : " ARG\n"
1550 : " INTEGER \"\" I:5\n"
1551 : + csspp_test::get_close_comment(true)
1552 :
1553 : );
1554 :
1555 1 : std::stringstream assembler_out;
1556 1 : csspp::assembler a(assembler_out);
1557 1 : a.output(n, csspp::output_mode_t::COMPRESSED);
1558 :
1559 : //std::cerr << "----------------- Result is " << static_cast<csspp::output_mode_t>(i) << "\n[" << out.str() << "]\n";
1560 :
1561 1 : CATCH_REQUIRE(assembler_out.str() ==
1562 :
1563 : "div{z-index:5}\n"
1564 : + csspp_test::get_close_comment()
1565 :
1566 : );
1567 :
1568 1 : CATCH_REQUIRE(c.get_root() == n);
1569 1 : }
1570 16 : CATCH_END_SECTION()
1571 :
1572 16 : CATCH_START_SECTION("compare 'blue blanc rouge'.substr(...) *= 'bleu blanc rouge' -- always true")
1573 : {
1574 2 : std::string const str("bleu blanc rouge");
1575 11 : for(size_t idx(0); idx < 10; ++idx)
1576 : {
1577 10 : size_t const start(rand() % (str.length() - 1));
1578 10 : size_t len(rand() % (str.length() - start - 1) + 1);
1579 10 : std::stringstream ss;
1580 : ss << "div { z-index: '"
1581 20 : << str.substr(start, len)
1582 : << "' *= '"
1583 : << str
1584 20 : << "' ? 9 : 5; }";
1585 30 : csspp::position pos("test.css");
1586 10 : csspp::lexer::pointer_t l(new csspp::lexer(ss, pos));
1587 :
1588 20 : csspp::parser p(l);
1589 :
1590 10 : csspp::node::pointer_t n(p.stylesheet());
1591 :
1592 10 : csspp::compiler c;
1593 10 : c.set_root(n);
1594 10 : c.set_date_time_variables(csspp_test::get_now());
1595 10 : c.add_path(csspp_test::get_script_path());
1596 10 : c.add_path(csspp_test::get_version_script_path());
1597 :
1598 10 : c.compile(false);
1599 :
1600 : //std::cerr << "Compiler result is: [" << *c.get_root() << "]\n";
1601 :
1602 : // to verify that the result is still an INTEGER we have to
1603 : // test the root node here
1604 10 : std::stringstream compiler_out;
1605 10 : compiler_out << *n;
1606 10 : VERIFY_TREES(compiler_out.str(),
1607 :
1608 : "LIST\n"
1609 : + csspp_test::get_default_variables() +
1610 : " COMPONENT_VALUE\n"
1611 : " ARG\n"
1612 : " IDENTIFIER \"div\"\n"
1613 : " OPEN_CURLYBRACKET B:true\n"
1614 : " DECLARATION \"z-index\"\n"
1615 : " ARG\n"
1616 : " INTEGER \"\" I:9\n"
1617 : + csspp_test::get_close_comment(true)
1618 :
1619 : );
1620 :
1621 10 : std::stringstream assembler_out;
1622 10 : csspp::assembler a(assembler_out);
1623 10 : a.output(n, csspp::output_mode_t::COMPRESSED);
1624 :
1625 : //std::cerr << "----------------- Result is " << static_cast<csspp::output_mode_t>(i) << "\n[" << out.str() << "]\n";
1626 :
1627 10 : CATCH_REQUIRE(assembler_out.str() ==
1628 :
1629 : "div{z-index:9}\n"
1630 : + csspp_test::get_close_comment()
1631 :
1632 : );
1633 :
1634 10 : CATCH_REQUIRE(c.get_root() == n);
1635 10 : }
1636 1 : }
1637 16 : CATCH_END_SECTION()
1638 :
1639 16 : CATCH_START_SECTION("compare 'blue blanc rouge'.substr(...) *= 'bleu blanc rouge' -- always false")
1640 : {
1641 2 : std::string const str("bleu blanc rouge");
1642 11 : for(size_t idx(0); idx < 10; ++idx)
1643 : {
1644 10 : size_t const start(rand() % (str.length() - 1));
1645 10 : size_t len(rand() % (str.length() - start - 1) + 1);
1646 10 : std::stringstream ss;
1647 : ss << "div { z-index: '"
1648 30 : << str.substr(start, len)
1649 10 : << (rand() % 10 + '0') // make sure it cannot be found
1650 : << "' *= '"
1651 : << str
1652 20 : << "' ? 9 : 5; }";
1653 30 : csspp::position pos("test.css");
1654 10 : csspp::lexer::pointer_t l(new csspp::lexer(ss, pos));
1655 :
1656 20 : csspp::parser p(l);
1657 :
1658 10 : csspp::node::pointer_t n(p.stylesheet());
1659 :
1660 10 : csspp::compiler c;
1661 10 : c.set_root(n);
1662 10 : c.set_date_time_variables(csspp_test::get_now());
1663 10 : c.add_path(csspp_test::get_script_path());
1664 10 : c.add_path(csspp_test::get_version_script_path());
1665 :
1666 10 : c.compile(false);
1667 :
1668 : //std::cerr << "Compiler result is: [" << *c.get_root() << "]\n";
1669 :
1670 : // to verify that the result is still an INTEGER we have to
1671 : // test the root node here
1672 10 : std::stringstream compiler_out;
1673 10 : compiler_out << *n;
1674 10 : VERIFY_TREES(compiler_out.str(),
1675 :
1676 : "LIST\n"
1677 : + csspp_test::get_default_variables() +
1678 : " COMPONENT_VALUE\n"
1679 : " ARG\n"
1680 : " IDENTIFIER \"div\"\n"
1681 : " OPEN_CURLYBRACKET B:true\n"
1682 : " DECLARATION \"z-index\"\n"
1683 : " ARG\n"
1684 : " INTEGER \"\" I:5\n"
1685 : + csspp_test::get_close_comment(true)
1686 :
1687 : );
1688 :
1689 10 : std::stringstream assembler_out;
1690 10 : csspp::assembler a(assembler_out);
1691 10 : a.output(n, csspp::output_mode_t::COMPRESSED);
1692 :
1693 : //std::cerr << "----------------- Result is " << static_cast<csspp::output_mode_t>(i) << "\n[" << out.str() << "]\n";
1694 :
1695 10 : CATCH_REQUIRE(assembler_out.str() ==
1696 :
1697 : "div{z-index:5}\n"
1698 : + csspp_test::get_close_comment()
1699 :
1700 : );
1701 :
1702 10 : CATCH_REQUIRE(c.get_root() == n);
1703 10 : }
1704 1 : }
1705 16 : CATCH_END_SECTION()
1706 :
1707 : // slight variation
1708 16 : CATCH_START_SECTION("compare 'bouge' *= 'bleu blanc rouge' -- always false")
1709 : {
1710 1 : std::stringstream ss;
1711 1 : ss << "div { z-index: 'bouge' *= 'bleu blanc rouge' ? 9 : 5; }";
1712 3 : csspp::position pos("test.css");
1713 1 : csspp::lexer::pointer_t l(new csspp::lexer(ss, pos));
1714 :
1715 2 : csspp::parser p(l);
1716 :
1717 1 : csspp::node::pointer_t n(p.stylesheet());
1718 :
1719 1 : csspp::compiler c;
1720 1 : c.set_root(n);
1721 1 : c.set_date_time_variables(csspp_test::get_now());
1722 1 : c.add_path(csspp_test::get_script_path());
1723 1 : c.add_path(csspp_test::get_version_script_path());
1724 :
1725 1 : c.compile(false);
1726 :
1727 : //std::cerr << "Compiler result is: [" << *c.get_root() << "]\n";
1728 :
1729 : // to verify that the result is still an INTEGER we have to
1730 : // test the root node here
1731 1 : std::stringstream compiler_out;
1732 1 : compiler_out << *n;
1733 1 : VERIFY_TREES(compiler_out.str(),
1734 :
1735 : "LIST\n"
1736 : + csspp_test::get_default_variables() +
1737 : " COMPONENT_VALUE\n"
1738 : " ARG\n"
1739 : " IDENTIFIER \"div\"\n"
1740 : " OPEN_CURLYBRACKET B:true\n"
1741 : " DECLARATION \"z-index\"\n"
1742 : " ARG\n"
1743 : " INTEGER \"\" I:5\n"
1744 : + csspp_test::get_close_comment(true)
1745 :
1746 : );
1747 :
1748 1 : std::stringstream assembler_out;
1749 1 : csspp::assembler a(assembler_out);
1750 1 : a.output(n, csspp::output_mode_t::COMPRESSED);
1751 :
1752 : //std::cerr << "----------------- Result is " << static_cast<csspp::output_mode_t>(i) << "\n[" << out.str() << "]\n";
1753 :
1754 1 : CATCH_REQUIRE(assembler_out.str() ==
1755 :
1756 : "div{z-index:5}\n"
1757 : + csspp_test::get_close_comment()
1758 :
1759 : );
1760 :
1761 1 : CATCH_REQUIRE(c.get_root() == n);
1762 1 : }
1763 16 : CATCH_END_SECTION()
1764 :
1765 16 : CATCH_START_SECTION("compare 'bleu'|'blanc'|'rouge' |= 'bleu-blanc-rouge' -- always true")
1766 : {
1767 4 : for(size_t idx(0); idx < sizeof(colors) / sizeof(colors[0]); ++idx)
1768 : {
1769 3 : std::stringstream ss;
1770 : ss << "div { z-index: '"
1771 : << colors[idx]
1772 3 : << "' *= 'bleu-blanc-rouge' ? 9 : 5; }";
1773 9 : csspp::position pos("test.css");
1774 3 : csspp::lexer::pointer_t l(new csspp::lexer(ss, pos));
1775 :
1776 6 : csspp::parser p(l);
1777 :
1778 3 : csspp::node::pointer_t n(p.stylesheet());
1779 :
1780 3 : csspp::compiler c;
1781 3 : c.set_root(n);
1782 3 : c.set_date_time_variables(csspp_test::get_now());
1783 3 : c.add_path(csspp_test::get_script_path());
1784 3 : c.add_path(csspp_test::get_version_script_path());
1785 :
1786 3 : c.compile(false);
1787 :
1788 : //std::cerr << "Compiler result is: [" << *c.get_root() << "]\n";
1789 :
1790 : // to verify that the result is still an INTEGER we have to
1791 : // test the root node here
1792 3 : std::stringstream compiler_out;
1793 3 : compiler_out << *n;
1794 3 : VERIFY_TREES(compiler_out.str(),
1795 :
1796 : "LIST\n"
1797 : + csspp_test::get_default_variables() +
1798 : " COMPONENT_VALUE\n"
1799 : " ARG\n"
1800 : " IDENTIFIER \"div\"\n"
1801 : " OPEN_CURLYBRACKET B:true\n"
1802 : " DECLARATION \"z-index\"\n"
1803 : " ARG\n"
1804 : " INTEGER \"\" I:9\n"
1805 : + csspp_test::get_close_comment(true)
1806 :
1807 : );
1808 :
1809 3 : std::stringstream assembler_out;
1810 3 : csspp::assembler a(assembler_out);
1811 3 : a.output(n, csspp::output_mode_t::COMPRESSED);
1812 :
1813 : //std::cerr << "----------------- Result is " << static_cast<csspp::output_mode_t>(i) << "\n[" << out.str() << "]\n";
1814 :
1815 3 : CATCH_REQUIRE(assembler_out.str() ==
1816 :
1817 : "div{z-index:9}\n"
1818 : + csspp_test::get_close_comment()
1819 :
1820 : );
1821 :
1822 3 : CATCH_REQUIRE(c.get_root() == n);
1823 3 : }
1824 : }
1825 16 : CATCH_END_SECTION()
1826 :
1827 16 : CATCH_START_SECTION("compare 'bleu#' |= 'bleu-blanc-rouge' -- always false")
1828 : {
1829 4 : for(size_t idx(0); idx < sizeof(colors) / sizeof(colors[0]); ++idx)
1830 : {
1831 3 : std::stringstream ss;
1832 : ss << "div { z-index: '"
1833 3 : << colors[idx]
1834 3 : << (rand() % 10 + '0') // make sure it cannot be found
1835 3 : << "' |= 'bleu-blanc-rouge' ? 9 : 5; }";
1836 9 : csspp::position pos("test.css");
1837 3 : csspp::lexer::pointer_t l(new csspp::lexer(ss, pos));
1838 :
1839 6 : csspp::parser p(l);
1840 :
1841 3 : csspp::node::pointer_t n(p.stylesheet());
1842 :
1843 3 : csspp::compiler c;
1844 3 : c.set_root(n);
1845 3 : c.set_date_time_variables(csspp_test::get_now());
1846 3 : c.add_path(csspp_test::get_script_path());
1847 3 : c.add_path(csspp_test::get_version_script_path());
1848 :
1849 3 : c.compile(false);
1850 :
1851 : //std::cerr << "Compiler result is: [" << *c.get_root() << "]\n";
1852 :
1853 : // to verify that the result is still an INTEGER we have to
1854 : // test the root node here
1855 3 : std::stringstream compiler_out;
1856 3 : compiler_out << *n;
1857 3 : VERIFY_TREES(compiler_out.str(),
1858 :
1859 : "LIST\n"
1860 : + csspp_test::get_default_variables() +
1861 : " COMPONENT_VALUE\n"
1862 : " ARG\n"
1863 : " IDENTIFIER \"div\"\n"
1864 : " OPEN_CURLYBRACKET B:true\n"
1865 : " DECLARATION \"z-index\"\n"
1866 : " ARG\n"
1867 : " INTEGER \"\" I:5\n"
1868 : + csspp_test::get_close_comment(true)
1869 :
1870 : );
1871 :
1872 3 : std::stringstream assembler_out;
1873 3 : csspp::assembler a(assembler_out);
1874 3 : a.output(n, csspp::output_mode_t::COMPRESSED);
1875 :
1876 : //std::cerr << "----------------- Result is " << static_cast<csspp::output_mode_t>(i) << "\n[" << out.str() << "]\n";
1877 :
1878 3 : CATCH_REQUIRE(assembler_out.str() ==
1879 :
1880 : "div{z-index:5}\n"
1881 : + csspp_test::get_close_comment()
1882 :
1883 : );
1884 :
1885 3 : CATCH_REQUIRE(c.get_root() == n);
1886 3 : }
1887 : }
1888 16 : CATCH_END_SECTION()
1889 :
1890 : // slight variation
1891 16 : CATCH_START_SECTION("compare 'bouge' *= 'bleu-blanc-rouge' -- always false")
1892 : {
1893 1 : std::stringstream ss;
1894 1 : ss << "div { z-index: 'bouge' *= 'bleu-blanc-rouge' ? 9 : 5; }";
1895 3 : csspp::position pos("test.css");
1896 1 : csspp::lexer::pointer_t l(new csspp::lexer(ss, pos));
1897 :
1898 2 : csspp::parser p(l);
1899 :
1900 1 : csspp::node::pointer_t n(p.stylesheet());
1901 :
1902 1 : csspp::compiler c;
1903 1 : c.set_root(n);
1904 1 : c.set_date_time_variables(csspp_test::get_now());
1905 1 : c.add_path(csspp_test::get_script_path());
1906 1 : c.add_path(csspp_test::get_version_script_path());
1907 :
1908 1 : c.compile(false);
1909 :
1910 : //std::cerr << "Compiler result is: [" << *c.get_root() << "]\n";
1911 :
1912 : // to verify that the result is still an INTEGER we have to
1913 : // test the root node here
1914 1 : std::stringstream compiler_out;
1915 1 : compiler_out << *n;
1916 1 : VERIFY_TREES(compiler_out.str(),
1917 :
1918 : "LIST\n"
1919 : + csspp_test::get_default_variables() +
1920 : " COMPONENT_VALUE\n"
1921 : " ARG\n"
1922 : " IDENTIFIER \"div\"\n"
1923 : " OPEN_CURLYBRACKET B:true\n"
1924 : " DECLARATION \"z-index\"\n"
1925 : " ARG\n"
1926 : " INTEGER \"\" I:5\n"
1927 : + csspp_test::get_close_comment(true)
1928 :
1929 : );
1930 :
1931 1 : std::stringstream assembler_out;
1932 1 : csspp::assembler a(assembler_out);
1933 1 : a.output(n, csspp::output_mode_t::COMPRESSED);
1934 :
1935 : //std::cerr << "----------------- Result is " << static_cast<csspp::output_mode_t>(i) << "\n[" << out.str() << "]\n";
1936 :
1937 1 : CATCH_REQUIRE(assembler_out.str() ==
1938 :
1939 : "div{z-index:5}\n"
1940 : + csspp_test::get_close_comment()
1941 :
1942 : );
1943 :
1944 1 : CATCH_REQUIRE(c.get_root() == n);
1945 1 : }
1946 16 : CATCH_END_SECTION()
1947 :
1948 : // no error left over
1949 16 : VERIFY_ERRORS("");
1950 16 : }
1951 :
1952 3 : CATCH_TEST_CASE("Expression number/string/invalid <,<=,>,>= number/string/invalid", "[expression] [equality] [invalid]")
1953 : {
1954 3 : char const * op[] =
1955 : {
1956 : "=",
1957 : "!=",
1958 : "~=",
1959 : "^=",
1960 : "$=",
1961 : "*=",
1962 : "|="
1963 : };
1964 :
1965 3 : CATCH_START_SECTION("just ? is not a valid number")
1966 : {
1967 1 : std::stringstream ss;
1968 1 : ss << "div { border: ?; }";
1969 3 : csspp::position pos("test.css");
1970 1 : csspp::lexer::pointer_t l(new csspp::lexer(ss, pos));
1971 :
1972 2 : csspp::parser p(l);
1973 :
1974 1 : csspp::node::pointer_t n(p.stylesheet());
1975 :
1976 1 : csspp::compiler c;
1977 1 : c.set_root(n);
1978 1 : c.set_date_time_variables(csspp_test::get_now());
1979 1 : c.add_path(csspp_test::get_script_path());
1980 1 : c.add_path(csspp_test::get_version_script_path());
1981 :
1982 1 : c.compile(false);
1983 :
1984 : //std::cerr << "Compiler result is: [" << *c.get_root() << "]\n";
1985 :
1986 1 : VERIFY_ERRORS("test.css(1): error: unsupported type CONDITIONAL as a unary expression token.\n");
1987 :
1988 1 : CATCH_REQUIRE(c.get_root() == n);
1989 1 : }
1990 3 : CATCH_END_SECTION()
1991 :
1992 3 : CATCH_START_SECTION("number ?? ? is invalid")
1993 : {
1994 8 : for(size_t idx(0); idx < sizeof(op) / sizeof(op[0]); ++idx)
1995 : {
1996 7 : std::stringstream ss;
1997 : ss << "div { width: 10px "
1998 : << op[idx]
1999 7 : << " ?; }";
2000 21 : csspp::position pos("test.css");
2001 7 : csspp::lexer::pointer_t l(new csspp::lexer(ss, pos));
2002 :
2003 14 : csspp::parser p(l);
2004 :
2005 7 : csspp::node::pointer_t n(p.stylesheet());
2006 :
2007 7 : csspp::compiler c;
2008 7 : c.set_root(n);
2009 7 : c.set_date_time_variables(csspp_test::get_now());
2010 7 : c.add_path(csspp_test::get_script_path());
2011 7 : c.add_path(csspp_test::get_version_script_path());
2012 :
2013 7 : c.compile(false);
2014 :
2015 : //std::cerr << "Compiler result is: [" << *c.get_root() << "]\n";
2016 :
2017 7 : VERIFY_ERRORS("test.css(1): error: unsupported type CONDITIONAL as a unary expression token.\n");
2018 :
2019 7 : CATCH_REQUIRE(c.get_root() == n);
2020 7 : }
2021 : }
2022 3 : CATCH_END_SECTION()
2023 :
2024 3 : CATCH_START_SECTION("number ~=,^=,$=,*=,|= number is invalid")
2025 : {
2026 8 : for(size_t idx(0); idx < sizeof(op) / sizeof(op[0]); ++idx)
2027 : {
2028 7 : if(idx >= 2)
2029 : {
2030 : // enhance by adding all other types (all types except STRING
2031 : // are invalid with these operators)
2032 5 : std::stringstream ss;
2033 : ss << "div { width: 10px "
2034 : << op[idx]
2035 5 : << " 25px; }";
2036 15 : csspp::position pos("test.css");
2037 5 : csspp::lexer::pointer_t l(new csspp::lexer(ss, pos));
2038 :
2039 10 : csspp::parser p(l);
2040 :
2041 5 : csspp::node::pointer_t n(p.stylesheet());
2042 :
2043 5 : csspp::compiler c;
2044 5 : c.set_root(n);
2045 5 : c.set_date_time_variables(csspp_test::get_now());
2046 5 : c.add_path(csspp_test::get_script_path());
2047 5 : c.add_path(csspp_test::get_version_script_path());
2048 :
2049 5 : c.compile(false);
2050 :
2051 : //std::cerr << "Compiler result is: [" << *c.get_root() << "]\n";
2052 :
2053 5 : VERIFY_ERRORS("test.css(1): error: incompatible types between INTEGER and INTEGER for operator '~=', '^=', '$=', '*=', '|='.\n");
2054 :
2055 5 : CATCH_REQUIRE(c.get_root() == n);
2056 5 : }
2057 :
2058 : // mismatched dimensions are caught earlier with a different
2059 : // error
2060 : {
2061 : // enhance by adding all other types (all types except STRING
2062 : // are invalid with these operators)
2063 7 : std::stringstream ss;
2064 : ss << "div { width: 10px "
2065 : << op[idx]
2066 7 : << " 25em; }";
2067 21 : csspp::position pos("test.css");
2068 7 : csspp::lexer::pointer_t l(new csspp::lexer(ss, pos));
2069 :
2070 14 : csspp::parser p(l);
2071 :
2072 7 : csspp::node::pointer_t n(p.stylesheet());
2073 :
2074 7 : csspp::compiler c;
2075 7 : c.set_root(n);
2076 7 : c.set_date_time_variables(csspp_test::get_now());
2077 7 : c.add_path(csspp_test::get_script_path());
2078 7 : c.add_path(csspp_test::get_version_script_path());
2079 :
2080 7 : c.compile(false);
2081 :
2082 : //std::cerr << "Compiler result is: [" << *c.get_root() << "]\n";
2083 :
2084 7 : VERIFY_ERRORS("test.css(1): error: incompatible types or dimensions between INTEGER and INTEGER for operator '=', '!=', '<', '<=', '>', '>=', '~=', '^=', '$=', '*=', or '|='.\n");
2085 :
2086 7 : CATCH_REQUIRE(c.get_root() == n);
2087 7 : }
2088 : }
2089 : }
2090 3 : CATCH_END_SECTION()
2091 :
2092 : // no error left over
2093 3 : VERIFY_ERRORS("");
2094 3 : }
2095 :
2096 : // vim: ts=4 sw=4 et
|