21#ifndef DEFAULTTAGSTEST_H
22#define DEFAULTTAGSTEST_H
24#include <QtCore/QDebug>
25#include <QtTest/QTest>
28#include "coverageobject.h"
30#include "cutelee_paths.h"
41class FakeTemplateLoader : public
Cutelee::InMemoryTemplateLoader
46 m_existingMedia << QStringLiteral(
"existing_image.png")
47 << QStringLiteral(
"another_existing_image.png")
48 << QStringLiteral(
"this&that.png");
53 if (m_existingMedia.contains(fileName))
54 return {QStringLiteral(
"/path/to/"), fileName};
68 enum Animals { Lions, Tigers, Bears };
80 void cleanupTestCase();
82 void testCommentTag_data();
83 void testCommentTag() { doTest(); }
85 void testFirstOfTag_data();
86 void testFirstOfTag() { doTest(); }
88 void testIfTag_data();
89 void testIfTag() { doTest(); }
91 void testForTag_data();
92 void testForTag() { doTest(); }
94 void testIfEqualTag_data();
95 void testIfEqualTag() { doTest(); }
97 void testIfNotEqualTag_data();
98 void testIfNotEqualTag() { doTest(); }
100 void testTemplateTagTag_data();
101 void testTemplateTagTag() { doTest(); }
103 void testWithTag_data();
104 void testWithTag() { doTest(); }
106 void testCycleTag_data();
107 void testCycleTag() { doTest(); }
109 void testWidthRatioTag_data();
110 void testWidthRatioTag() { doTest(); }
112 void testFilterTag_data();
113 void testFilterTag() { doTest(); }
115 void testNowTag_data();
116 void testNowTag() { doTest(); }
118 void testSpacelessTag_data();
119 void testSpacelessTag() { doTest(); }
121 void testRegroupTag_data();
122 void testRegroupTag() { doTest(); }
124 void testIfChangedTag_data();
125 void testIfChangedTag() { doTest(); }
127 void testAutoescapeTag_data();
128 void testAutoescapeTag() { doTest(); }
130 void testMediaFinderTag_data();
131 void testMediaFinderTag() { doTest(); }
133 void testRangeTag_data();
134 void testRangeTag() { doTest(); }
136 void testDebugTag_data();
137 void testDebugTag() { doTest(); }
139 void testLoadTag_data();
140 void testLoadTag() { doTest(); }
142 void testUrlTypes_data();
145 void testRelativePaths_data();
146 void testRelativePaths();
154void TestDefaultTags::initTestCase()
156 m_engine =
new Engine(
this);
159 auto loader1 = std::shared_ptr<FakeTemplateLoader>(
new FakeTemplateLoader());
161 m_engine->addTemplateLoader(loader1);
164void TestDefaultTags::cleanupTestCase() {
delete m_engine; }
166void TestDefaultTags::doTest()
168 QFETCH(QString, input);
170 QFETCH(QString, output);
173 auto t = m_engine->newTemplate(input, QLatin1String(QTest::currentDataTag()));
175 if (t->error() != NoError) {
176 if (t->error() != error)
177 qDebug() << t->errorString();
178 QCOMPARE(t->error(), error);
182 Context context(dict);
184 auto result = t->render(&context);
186 if (t->error() != NoError) {
187 if (t->error() != error)
188 qDebug() << t->errorString();
189 QCOMPARE(t->error(), error);
194 QCOMPARE(NoError, error);
196 QCOMPARE(t->error(), NoError);
198 QCOMPARE(result, output);
200 if (!result.isEmpty()
202 == QStringLiteral(
"testMediaFinderTag")) {
203 QVERIFY(!context.externalMedia().isEmpty());
207void TestDefaultTags::testCommentTag_data()
209 QTest::addColumn<QString>(
"input");
210 QTest::addColumn<Dict>(
"dict");
211 QTest::addColumn<QString>(
"output");
212 QTest::addColumn<Cutelee::Error>(
"error");
216 QTest::newRow(
"comment-tag01")
217 << QStringLiteral(
"{% comment %}this is hidden{% endcomment %}hello")
218 << dict << QStringLiteral(
"hello") << NoError;
220 QTest::newRow(
"comment-tag02")
221 << QStringLiteral(
"{% comment %}this is hidden{% endcomment %}hello{% "
222 "comment %}foo{% endcomment %}")
223 << dict << QStringLiteral(
"hello") << NoError;
225 QTest::newRow(
"comment-tag03")
226 << QStringLiteral(
"foo{% comment %} {% if %} {% endcomment %}") << dict
227 << QStringLiteral(
"foo") << NoError;
228 QTest::newRow(
"comment-tag04")
229 << QStringLiteral(
"foo{% comment %} {% endblock %} {% endcomment %}")
230 << dict << QStringLiteral(
"foo") << NoError;
231 QTest::newRow(
"comment-tag05")
232 << QStringLiteral(
"foo{% comment %} {% somerandomtag %} {% endcomment %}")
233 << dict << QStringLiteral(
"foo") << NoError;
234 QTest::newRow(
"comment-tag06") << QStringLiteral(
"{% comment %}yes") << dict
235 << QString() << UnclosedBlockTagError;
238void TestDefaultTags::testFirstOfTag_data()
240 QTest::addColumn<QString>(
"input");
241 QTest::addColumn<Dict>(
"dict");
242 QTest::addColumn<QString>(
"output");
243 QTest::addColumn<Cutelee::Error>(
"error");
246 dict.
insert(QStringLiteral(
"a"), 0);
247 dict.
insert(QStringLiteral(
"b"), 0);
248 dict.
insert(QStringLiteral(
"c"), 0);
249 QTest::newRow(
"firstof01")
250 << QStringLiteral(
"{% firstof a b c %}") << dict << QString() << NoError;
253 dict.
insert(QStringLiteral(
"a"), 1);
254 dict.
insert(QStringLiteral(
"b"), 0);
255 dict.
insert(QStringLiteral(
"c"), 0);
256 QTest::newRow(
"firstof02") << QStringLiteral(
"{% firstof a b c %}") << dict
257 << QStringLiteral(
"1") << NoError;
260 dict.
insert(QStringLiteral(
"a"), 0);
261 dict.
insert(QStringLiteral(
"b"), 2);
262 dict.
insert(QStringLiteral(
"c"), 0);
263 QTest::newRow(
"firstof03") << QStringLiteral(
"{% firstof a b c %}") << dict
264 << QStringLiteral(
"2") << NoError;
267 dict.
insert(QStringLiteral(
"a"), 0);
268 dict.
insert(QStringLiteral(
"b"), 0);
269 dict.
insert(QStringLiteral(
"c"), 3);
270 QTest::newRow(
"firstof04") << QStringLiteral(
"{% firstof a b c %}") << dict
271 << QStringLiteral(
"3") << NoError;
274 dict.
insert(QStringLiteral(
"a"), 1);
275 dict.
insert(QStringLiteral(
"b"), 2);
276 dict.
insert(QStringLiteral(
"c"), 3);
277 QTest::newRow(
"firstof05") << QStringLiteral(
"{% firstof a b c %}") << dict
278 << QStringLiteral(
"1") << NoError;
281 dict.
insert(QStringLiteral(
"b"), 0);
282 dict.
insert(QStringLiteral(
"c"), 3);
283 QTest::newRow(
"firstof06") << QStringLiteral(
"{% firstof a b c %}") << dict
284 << QStringLiteral(
"3") << NoError;
287 dict.
insert(QStringLiteral(
"a"), 0);
288 QTest::newRow(
"firstof07")
289 <<
"{% firstof a b \"c\" %}" << dict << QStringLiteral(
"c") << NoError;
292 dict.
insert(QStringLiteral(
"a"), 0);
293 dict.
insert(QStringLiteral(
"b"), 0);
294 QTest::newRow(
"firstof08") <<
"{% firstof a b \"c and d\" %}" << dict
295 << QStringLiteral(
"c and d") << NoError;
296 QTest::newRow(
"firstof09") << QStringLiteral(
"{% firstof %}") << dict
297 << QStringLiteral(
"a") << TagSyntaxError;
304 Q_PROPERTY(
bool isFalse READ isFalse CONSTANT)
309 bool isTrue()
const {
return true; }
311 bool isFalse()
const {
return false; }
319 bool isBadCalled() {
return mIsBadCalled; }
322 mutable bool mIsBadCalled;
325void TestDefaultTags::testIfTag_data()
327 QTest::addColumn<QString>(
"input");
328 QTest::addColumn<Dict>(
"dict");
329 QTest::addColumn<QString>(
"output");
330 QTest::addColumn<Cutelee::Error>(
"error");
334 dict.
insert(QStringLiteral(
"foo"),
true);
336 QTest::newRow(
"if-tag01")
337 << QStringLiteral(
"{% if foo %}yes{% else %}no{% endif %}") << dict
338 << QStringLiteral(
"yes") << NoError;
341 dict.
insert(QStringLiteral(
"foo"),
false);
342 QTest::newRow(
"if-tag02")
343 << QStringLiteral(
"{% if foo %}yes{% else %}no{% endif %}") << dict
344 << QStringLiteral(
"no") << NoError;
347 QTest::newRow(
"if-tag03")
348 << QStringLiteral(
"{% if foo %}yes{% else %}no{% endif %}") << dict
349 << QStringLiteral(
"no") << NoError;
352 dict.
insert(QStringLiteral(
"foo"),
true);
353 QTest::newRow(
"if-tag04")
354 << QStringLiteral(
"{% if foo %}foo{% elif bar %}bar{% endif %}") << dict
355 << QStringLiteral(
"foo") << NoError;
358 dict.
insert(QStringLiteral(
"bar"),
true);
359 QTest::newRow(
"if-tag05")
360 << QStringLiteral(
"{% if foo %}foo{% elif bar %}bar{% endif %}") << dict
361 << QStringLiteral(
"bar") << NoError;
364 QTest::newRow(
"if-tag06")
365 << QStringLiteral(
"{% if foo %}foo{% elif bar %}bar{% endif %}") << dict
369 dict.
insert(QStringLiteral(
"foo"),
true);
370 QTest::newRow(
"if-tag07") << QStringLiteral(
371 "{% if foo %}foo{% elif bar %}bar{% else %}nothing{% endif %}")
372 << dict << QStringLiteral(
"foo") << NoError;
375 dict.
insert(QStringLiteral(
"bar"),
true);
376 QTest::newRow(
"if-tag08") << QStringLiteral(
377 "{% if foo %}foo{% elif bar %}bar{% else %}nothing{% endif %}")
378 << dict << QStringLiteral(
"bar") << NoError;
381 QTest::newRow(
"if-tag09") << QStringLiteral(
382 "{% if foo %}foo{% elif bar %}bar{% else %}nothing{% endif %}")
383 << dict << QStringLiteral(
"nothing") << NoError;
386 dict.
insert(QStringLiteral(
"foo"),
true);
387 QTest::newRow(
"if-tag10")
388 << QStringLiteral(
"{% if foo %}foo{% elif bar %}bar{% elif baz %}baz{% "
389 "else %}nothing{% endif %}")
390 << dict << QStringLiteral(
"foo") << NoError;
393 dict.
insert(QStringLiteral(
"bar"),
true);
394 QTest::newRow(
"if-tag11")
395 << QStringLiteral(
"{% if foo %}foo{% elif bar %}bar{% elif baz %}baz{% "
396 "else %}nothing{% endif %}")
397 << dict << QStringLiteral(
"bar") << NoError;
400 dict.
insert(QStringLiteral(
"baz"),
true);
401 QTest::newRow(
"if-tag12")
402 << QStringLiteral(
"{% if foo %}foo{% elif bar %}bar{% elif baz %}baz{% "
403 "else %}nothing{% endif %}")
404 << dict << QStringLiteral(
"baz") << NoError;
407 QTest::newRow(
"if-tag13")
408 << QStringLiteral(
"{% if foo %}foo{% elif bar %}bar{% elif baz %}baz{% "
409 "else %}nothing{% endif %}")
410 << dict << QStringLiteral(
"nothing") << NoError;
415 dict.
insert(QStringLiteral(
"foo"), QStringLiteral(
"abcde"));
416 QTest::newRow(
"if-tag-filter01")
417 << QStringLiteral(
"{% if foo|length == 5 %}yes{% else %}{{ foo|length }}{% endif %}")
418 << dict << QStringLiteral(
"yes") << NoError;
421 QTest::newRow(
"if-tag-filter02") << QStringLiteral(
422 "{% if foo|upper == \'ABC\' %}yes{% else %}no{% endif %}")
423 << dict << QStringLiteral(
"no") << NoError;
428 QTest::newRow(
"if-tag-eq01")
429 << QStringLiteral(
"{% if foo == bar %}yes{% else %}no{% endif %}") << dict
430 << QStringLiteral(
"yes") << NoError;
433 dict.
insert(QStringLiteral(
"foo"), 1);
434 QTest::newRow(
"if-tag-eq02")
435 << QStringLiteral(
"{% if foo == bar %}yes{% else %}no{% endif %}") << dict
436 << QStringLiteral(
"no") << NoError;
439 dict.
insert(QStringLiteral(
"foo"), 1);
440 dict.
insert(QStringLiteral(
"bar"), 1);
441 QTest::newRow(
"if-tag-eq03")
442 << QStringLiteral(
"{% if foo == bar %}yes{% else %}no{% endif %}") << dict
443 << QStringLiteral(
"yes") << NoError;
446 dict.
insert(QStringLiteral(
"foo"), 1);
447 dict.
insert(QStringLiteral(
"bar"), 2);
448 QTest::newRow(
"if-tag-eq04")
449 << QStringLiteral(
"{% if foo == bar %}yes{% else %}no{% endif %}") << dict
450 << QStringLiteral(
"no") << NoError;
453 QTest::newRow(
"if-tag-eq05")
454 << QStringLiteral(
"{% if foo == \'\' %}yes{% else %}no{% endif %}")
455 << dict << QStringLiteral(
"no") << NoError;
458 dict.
insert(QStringLiteral(
"foostring"), QStringLiteral(
"foo"));
459 QTest::newRow(
"if-tag-eq06") << QStringLiteral(
460 "{% if foostring == \'foo\' %}yes{% else %}no{% endif %}")
461 << dict << QStringLiteral(
"yes") << NoError;
464 QTest::newRow(
"if-tag-eq07")
465 << QStringLiteral(
"{% if \"foo\" == \"foo\" %}yes{% else %}no{% endif %}")
466 << dict << QStringLiteral(
"yes") << NoError;
468 dict.
insert(QStringLiteral(
"foo"), QStringLiteral(
"bar"));
469 QTest::newRow(
"if-tag-eq08")
470 << QStringLiteral(
"{% if foo == \"bar\" %}yes{% else %}no{% endif %}")
471 << dict << QStringLiteral(
"yes") << NoError;
472#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
475 dict.
insert(QStringLiteral(
"tigersEnum"),
477 QTest::newRow(
"if-tag-eq07") << QStringLiteral(
478 "{% if tigersEnum == zoo.Tigers %}yes{% else %}no{% endif %}")
479 << dict << QStringLiteral(
"yes") << NoError;
485 QTest::newRow(
"if-tag-gt-01")
486 << QStringLiteral(
"{% if 2 > 1 %}yes{% else %}no{% endif %}") << dict
487 << QStringLiteral(
"yes") << NoError;
490 QTest::newRow(
"if-tag-gt-02")
491 << QStringLiteral(
"{% if 1 > 1 %}yes{% else %}no{% endif %}") << dict
492 << QStringLiteral(
"no") << NoError;
495 QTest::newRow(
"if-tag-gte-01")
496 << QStringLiteral(
"{% if 1 >= 1 %}yes{% else %}no{% endif %}") << dict
497 << QStringLiteral(
"yes") << NoError;
500 QTest::newRow(
"if-tag-gte-02")
501 << QStringLiteral(
"{% if 1 >= 2 %}yes{% else %}no{% endif %}") << dict
502 << QStringLiteral(
"no") << NoError;
505 QTest::newRow(
"if-tag-lt-01")
506 << QStringLiteral(
"{% if 1 < 2 %}yes{% else %}no{% endif %}") << dict
507 << QStringLiteral(
"yes") << NoError;
510 QTest::newRow(
"if-tag-lt-02")
511 << QStringLiteral(
"{% if 1 < 1 %}yes{% else %}no{% endif %}") << dict
512 << QStringLiteral(
"no") << NoError;
515 QTest::newRow(
"if-tag-lte-01")
516 << QStringLiteral(
"{% if 1 <= 1 %}yes{% else %}no{% endif %}") << dict
517 << QStringLiteral(
"yes") << NoError;
520 QTest::newRow(
"if-tag-lte-02")
521 << QStringLiteral(
"{% if 2 <= 1 %}yes{% else %}no{% endif %}") << dict
522 << QStringLiteral(
"no") << NoError;
527 dict.
insert(QStringLiteral(
"x"), QVariantList{1});
528 QTest::newRow(
"if-tag-in-01")
529 << QStringLiteral(
"{% if 1 in x %}yes{% else %}no{% endif %}") << dict
530 << QStringLiteral(
"yes") << NoError;
533 dict.
insert(QStringLiteral(
"x"), QVariantList{1});
534 QTest::newRow(
"if-tag-in-02")
535 << QStringLiteral(
"{% if 2 in x %}yes{% else %}no{% endif %}") << dict
536 << QStringLiteral(
"no") << NoError;
539 dict.
insert(QStringLiteral(
"x"), QVariantList{1});
540 QTest::newRow(
"if-tag-not-in-01")
541 << QStringLiteral(
"{% if 1 not in x %}yes{% else %}no{% endif %}") << dict
542 << QStringLiteral(
"no") << NoError;
545 dict.
insert(QStringLiteral(
"x"), QVariantList{1});
546 QTest::newRow(
"if-tag-not-in-02")
547 << QStringLiteral(
"{% if 2 not in x %}yes{% else %}no{% endif %}") << dict
548 << QStringLiteral(
"yes") << NoError;
552 dict.
insert(QStringLiteral(
"colors"), QStringLiteral(
"green"));
553 QTest::newRow(
"if-tag-operator-in-string01")
555 "{% if \"green\" in colors %}yes{% else %}no{% endif %}")
556 << dict << QStringLiteral(
"yes") << NoError;
559 dict.
insert(QStringLiteral(
"colors"), QStringLiteral(
"red"));
560 QTest::newRow(
"if-tag-operator-in-string02")
562 "{% if \"green\" in colors %}yes{% else %}no{% endif %}")
563 << dict << QStringLiteral(
"no") << NoError;
566 dict.
insert(QStringLiteral(
"colors"), QStringLiteral(
"green"));
567 QTest::newRow(
"if-tag-operator-in-string03")
569 "{% if \"green\" in colors %}yes{% else %}no{% endif %}")
570 << dict << QStringLiteral(
"yes") << NoError;
573 dict.
insert(QStringLiteral(
"colors"), QStringLiteral(
"red"));
574 QTest::newRow(
"if-tag-operator-in-string04")
576 "{% if \"green\" in colors %}yes{% else %}no{% endif %}")
577 << dict << QStringLiteral(
"no") << NoError;
580 dict.
insert(QStringLiteral(
"color"), QStringLiteral(
"green"));
581 dict.
insert(QStringLiteral(
"colors"), QStringLiteral(
"green"));
582 QTest::newRow(
"if-tag-operator-in-string05")
583 << QStringLiteral(
"{% if color in colors %}yes{% else %}no{% endif %}")
584 << dict << QStringLiteral(
"yes") << NoError;
587 dict.
insert(QStringLiteral(
"color"), QStringLiteral(
"green"));
588 dict.
insert(QStringLiteral(
"colors"), QStringLiteral(
"red"));
589 QTest::newRow(
"if-tag-operator-in-string06")
590 << QStringLiteral(
"{% if color in colors %}yes{% else %}no{% endif %}")
591 << dict << QStringLiteral(
"no") << NoError;
596 dict.
insert(QStringLiteral(
"foo"),
true);
597 dict.
insert(QStringLiteral(
"bar"),
true);
598 QTest::newRow(
"if-tag-and01")
599 << QStringLiteral(
"{% if foo and bar %}yes{% else %}no{% endif %}")
600 << dict << QStringLiteral(
"yes") << NoError;
603 dict.
insert(QStringLiteral(
"foo"),
true);
604 dict.
insert(QStringLiteral(
"bar"),
false);
605 QTest::newRow(
"if-tag-and02")
606 << QStringLiteral(
"{% if foo and bar %}yes{% else %}no{% endif %}")
607 << dict << QStringLiteral(
"no") << NoError;
610 dict.
insert(QStringLiteral(
"foo"),
false);
611 dict.
insert(QStringLiteral(
"bar"),
true);
612 QTest::newRow(
"if-tag-and03")
613 << QStringLiteral(
"{% if foo and bar %}yes{% else %}no{% endif %}")
614 << dict << QStringLiteral(
"no") << NoError;
617 dict.
insert(QStringLiteral(
"foo"),
false);
618 dict.
insert(QStringLiteral(
"bar"),
false);
619 QTest::newRow(
"if-tag-and04")
620 << QStringLiteral(
"{% if foo and bar %}yes{% else %}no{% endif %}")
621 << dict << QStringLiteral(
"no") << NoError;
624 dict.
insert(QStringLiteral(
"foo"),
false);
625 QTest::newRow(
"if-tag-and05")
626 << QStringLiteral(
"{% if foo and bar %}yes{% else %}no{% endif %}")
627 << dict << QStringLiteral(
"no") << NoError;
630 dict.
insert(QStringLiteral(
"bar"),
false);
631 QTest::newRow(
"if-tag-and06")
632 << QStringLiteral(
"{% if foo and bar %}yes{% else %}no{% endif %}")
633 << dict << QStringLiteral(
"no") << NoError;
636 dict.
insert(QStringLiteral(
"foo"),
true);
637 QTest::newRow(
"if-tag-and07")
638 << QStringLiteral(
"{% if foo and bar %}yes{% else %}no{% endif %}")
639 << dict << QStringLiteral(
"no") << NoError;
642 dict.
insert(QStringLiteral(
"bar"),
true);
643 QTest::newRow(
"if-tag-and08")
644 << QStringLiteral(
"{% if foo and bar %}yes{% else %}no{% endif %}")
645 << dict << QStringLiteral(
"no") << NoError;
650 dict.
insert(QStringLiteral(
"foo"),
true);
651 dict.
insert(QStringLiteral(
"bar"),
true);
652 QTest::newRow(
"if-tag-or01")
653 << QStringLiteral(
"{% if foo or bar %}yes{% else %}no{% endif %}") << dict
654 << QStringLiteral(
"yes") << NoError;
657 dict.
insert(QStringLiteral(
"foo"),
true);
658 dict.
insert(QStringLiteral(
"bar"),
false);
659 QTest::newRow(
"if-tag-or02")
660 << QStringLiteral(
"{% if foo or bar %}yes{% else %}no{% endif %}") << dict
661 << QStringLiteral(
"yes") << NoError;
664 dict.
insert(QStringLiteral(
"foo"),
false);
665 dict.
insert(QStringLiteral(
"bar"),
true);
666 QTest::newRow(
"if-tag-or03")
667 << QStringLiteral(
"{% if foo or bar %}yes{% else %}no{% endif %}") << dict
668 << QStringLiteral(
"yes") << NoError;
671 dict.
insert(QStringLiteral(
"foo"),
false);
672 dict.
insert(QStringLiteral(
"bar"),
false);
673 QTest::newRow(
"if-tag-or04")
674 << QStringLiteral(
"{% if foo or bar %}yes{% else %}no{% endif %}") << dict
675 << QStringLiteral(
"no") << NoError;
678 dict.
insert(QStringLiteral(
"foo"),
false);
679 QTest::newRow(
"if-tag-or05")
680 << QStringLiteral(
"{% if foo or bar %}yes{% else %}no{% endif %}") << dict
681 << QStringLiteral(
"no") << NoError;
684 dict.
insert(QStringLiteral(
"bar"),
false);
685 QTest::newRow(
"if-tag-or06")
686 << QStringLiteral(
"{% if foo or bar %}yes{% else %}no{% endif %}") << dict
687 << QStringLiteral(
"no") << NoError;
690 dict.
insert(QStringLiteral(
"foo"),
true);
691 QTest::newRow(
"if-tag-or07")
692 << QStringLiteral(
"{% if foo or bar %}yes{% else %}no{% endif %}") << dict
693 << QStringLiteral(
"yes") << NoError;
696 dict.
insert(QStringLiteral(
"bar"),
true);
697 QTest::newRow(
"if-tag-or08")
698 << QStringLiteral(
"{% if foo or bar %}yes{% else %}no{% endif %}") << dict
699 << QStringLiteral(
"yes") << NoError;
702 dict.
insert(QStringLiteral(
"baz"),
true);
703 QTest::newRow(
"if-tag-or09")
704 << QStringLiteral(
"{% if foo or bar or baz %}yes{% else %}no{% endif %}")
705 << dict << QStringLiteral(
"yes") << NoError;
710 dict.
insert(QStringLiteral(
"foo"),
true);
711 QTest::newRow(
"if-tag-not01")
712 << QStringLiteral(
"{% if not foo %}no{% else %}yes{% endif %}") << dict
713 << QStringLiteral(
"yes") << NoError;
715 dict.
insert(QStringLiteral(
"foo"),
true);
716 QTest::newRow(
"if-tag-not02")
717 << QStringLiteral(
"{% if not not foo %}no{% else %}yes{% endif %}")
718 << dict << QStringLiteral(
"no") << NoError;
721 QTest::newRow(
"if-tag-not06")
722 << QStringLiteral(
"{% if foo and not bar %}yes{% else %}no{% endif %}")
723 << dict << QStringLiteral(
"no") << NoError;
726 dict.
insert(QStringLiteral(
"foo"),
true);
727 dict.
insert(QStringLiteral(
"bar"),
true);
728 QTest::newRow(
"if-tag-not07")
729 << QStringLiteral(
"{% if foo and not bar %}yes{% else %}no{% endif %}")
730 << dict << QStringLiteral(
"no") << NoError;
733 dict.
insert(QStringLiteral(
"foo"),
true);
734 dict.
insert(QStringLiteral(
"bar"),
false);
735 QTest::newRow(
"if-tag-not08")
736 << QStringLiteral(
"{% if foo and not bar %}yes{% else %}no{% endif %}")
737 << dict << QStringLiteral(
"yes") << NoError;
740 dict.
insert(QStringLiteral(
"foo"),
false);
741 dict.
insert(QStringLiteral(
"bar"),
true);
742 QTest::newRow(
"if-tag-not09")
743 << QStringLiteral(
"{% if foo and not bar %}yes{% else %}no{% endif %}")
744 << dict << QStringLiteral(
"no") << NoError;
747 dict.
insert(QStringLiteral(
"foo"),
false);
748 dict.
insert(QStringLiteral(
"bar"),
false);
749 QTest::newRow(
"if-tag-not10")
750 << QStringLiteral(
"{% if foo and not bar %}yes{% else %}no{% endif %}")
751 << dict << QStringLiteral(
"no") << NoError;
754 QTest::newRow(
"if-tag-not11")
755 << QStringLiteral(
"{% if not foo and bar %}yes{% else %}no{% endif %}")
756 << dict << QStringLiteral(
"no") << NoError;
759 dict.
insert(QStringLiteral(
"foo"),
true);
760 dict.
insert(QStringLiteral(
"bar"),
true);
761 QTest::newRow(
"if-tag-not12")
762 << QStringLiteral(
"{% if not foo and bar %}yes{% else %}no{% endif %}")
763 << dict << QStringLiteral(
"no") << NoError;
766 dict.
insert(QStringLiteral(
"foo"),
true);
767 dict.
insert(QStringLiteral(
"bar"),
false);
768 QTest::newRow(
"if-tag-not13")
769 << QStringLiteral(
"{% if not foo and bar %}yes{% else %}no{% endif %}")
770 << dict << QStringLiteral(
"no") << NoError;
773 dict.
insert(QStringLiteral(
"foo"),
false);
774 dict.
insert(QStringLiteral(
"bar"),
true);
775 QTest::newRow(
"if-tag-not14")
776 << QStringLiteral(
"{% if not foo and bar %}yes{% else %}no{% endif %}")
777 << dict << QStringLiteral(
"yes") << NoError;
780 dict.
insert(QStringLiteral(
"foo"),
false);
781 dict.
insert(QStringLiteral(
"bar"),
false);
782 QTest::newRow(
"if-tag-not15")
783 << QStringLiteral(
"{% if not foo and bar %}yes{% else %}no{% endif %}")
784 << dict << QStringLiteral(
"no") << NoError;
787 QTest::newRow(
"if-tag-not16")
788 << QStringLiteral(
"{% if foo or not bar %}yes{% else %}no{% endif %}")
789 << dict << QStringLiteral(
"yes") << NoError;
792 dict.
insert(QStringLiteral(
"foo"),
true);
793 dict.
insert(QStringLiteral(
"bar"),
true);
794 QTest::newRow(
"if-tag-not17")
795 << QStringLiteral(
"{% if foo or not bar %}yes{% else %}no{% endif %}")
796 << dict << QStringLiteral(
"yes") << NoError;
799 dict.
insert(QStringLiteral(
"foo"),
true);
800 dict.
insert(QStringLiteral(
"bar"),
false);
801 QTest::newRow(
"if-tag-not18")
802 << QStringLiteral(
"{% if foo or not bar %}yes{% else %}no{% endif %}")
803 << dict << QStringLiteral(
"yes") << NoError;
806 dict.
insert(QStringLiteral(
"foo"),
false);
807 dict.
insert(QStringLiteral(
"bar"),
true);
808 QTest::newRow(
"if-tag-not19")
809 << QStringLiteral(
"{% if foo or not bar %}yes{% else %}no{% endif %}")
810 << dict << QStringLiteral(
"no") << NoError;
813 dict.
insert(QStringLiteral(
"foo"),
false);
814 dict.
insert(QStringLiteral(
"bar"),
false);
815 QTest::newRow(
"if-tag-not20")
816 << QStringLiteral(
"{% if foo or not bar %}yes{% else %}no{% endif %}")
817 << dict << QStringLiteral(
"yes") << NoError;
820 QTest::newRow(
"if-tag-not21")
821 << QStringLiteral(
"{% if not foo or bar %}yes{% else %}no{% endif %}")
822 << dict << QStringLiteral(
"yes") << NoError;
825 dict.
insert(QStringLiteral(
"foo"),
true);
826 dict.
insert(QStringLiteral(
"bar"),
true);
827 QTest::newRow(
"if-tag-not22")
828 << QStringLiteral(
"{% if not foo or bar %}yes{% else %}no{% endif %}")
829 << dict << QStringLiteral(
"yes") << NoError;
832 dict.
insert(QStringLiteral(
"foo"),
true);
833 dict.
insert(QStringLiteral(
"bar"),
false);
834 QTest::newRow(
"if-tag-not23")
835 << QStringLiteral(
"{% if not foo or bar %}yes{% else %}no{% endif %}")
836 << dict << QStringLiteral(
"no") << NoError;
839 dict.
insert(QStringLiteral(
"foo"),
false);
840 dict.
insert(QStringLiteral(
"bar"),
true);
841 QTest::newRow(
"if-tag-not24")
842 << QStringLiteral(
"{% if not foo or bar %}yes{% else %}no{% endif %}")
843 << dict << QStringLiteral(
"yes") << NoError;
846 dict.
insert(QStringLiteral(
"foo"),
false);
847 dict.
insert(QStringLiteral(
"bar"),
false);
848 QTest::newRow(
"if-tag-not25")
849 << QStringLiteral(
"{% if not foo or bar %}yes{% else %}no{% endif %}")
850 << dict << QStringLiteral(
"yes") << NoError;
853 QTest::newRow(
"if-tag-not26") << QStringLiteral(
854 "{% if not foo and not bar %}yes{% else %}no{% endif %}")
855 << dict << QStringLiteral(
"yes") << NoError;
858 dict.
insert(QStringLiteral(
"foo"),
true);
859 dict.
insert(QStringLiteral(
"bar"),
true);
860 QTest::newRow(
"if-tag-not27") << QStringLiteral(
861 "{% if not foo and not bar %}yes{% else %}no{% endif %}")
862 << dict << QStringLiteral(
"no") << NoError;
865 dict.
insert(QStringLiteral(
"foo"),
true);
866 dict.
insert(QStringLiteral(
"bar"),
false);
867 QTest::newRow(
"if-tag-not28") << QStringLiteral(
868 "{% if not foo and not bar %}yes{% else %}no{% endif %}")
869 << dict << QStringLiteral(
"no") << NoError;
872 dict.
insert(QStringLiteral(
"foo"),
false);
873 dict.
insert(QStringLiteral(
"bar"),
true);
874 QTest::newRow(
"if-tag-not29") << QStringLiteral(
875 "{% if not foo and not bar %}yes{% else %}no{% endif %}")
876 << dict << QStringLiteral(
"no") << NoError;
879 dict.
insert(QStringLiteral(
"foo"),
false);
880 dict.
insert(QStringLiteral(
"bar"),
false);
881 QTest::newRow(
"if-tag-not30") << QStringLiteral(
882 "{% if not foo and not bar %}yes{% else %}no{% endif %}")
883 << dict << QStringLiteral(
"yes") << NoError;
886 QTest::newRow(
"if-tag-not31")
887 << QStringLiteral(
"{% if not foo or not bar %}yes{% else %}no{% endif %}")
888 << dict << QStringLiteral(
"yes") << NoError;
891 dict.
insert(QStringLiteral(
"foo"),
true);
892 dict.
insert(QStringLiteral(
"bar"),
true);
893 QTest::newRow(
"if-tag-not32")
894 << QStringLiteral(
"{% if not foo or not bar %}yes{% else %}no{% endif %}")
895 << dict << QStringLiteral(
"no") << NoError;
898 dict.
insert(QStringLiteral(
"foo"),
true);
899 dict.
insert(QStringLiteral(
"bar"),
false);
900 QTest::newRow(
"if-tag-not33")
901 << QStringLiteral(
"{% if not foo or not bar %}yes{% else %}no{% endif %}")
902 << dict << QStringLiteral(
"yes") << NoError;
905 dict.
insert(QStringLiteral(
"foo"),
false);
906 dict.
insert(QStringLiteral(
"bar"),
true);
907 QTest::newRow(
"if-tag-not34")
908 << QStringLiteral(
"{% if not foo or not bar %}yes{% else %}no{% endif %}")
909 << dict << QStringLiteral(
"yes") << NoError;
912 dict.
insert(QStringLiteral(
"foo"),
false);
913 dict.
insert(QStringLiteral(
"bar"),
false);
914 QTest::newRow(
"if-tag-not35")
915 << QStringLiteral(
"{% if not foo or not bar %}yes{% else %}no{% endif %}")
916 << dict << QStringLiteral(
"yes") << NoError;
918 QTest::newRow(
"if-tag-error01") << QStringLiteral(
"{% if %}yes{% endif %}")
919 << dict << QString() << TagSyntaxError;
922 dict.
insert(QStringLiteral(
"foo"),
true);
923 QTest::newRow(
"if-tag-error02")
924 << QStringLiteral(
"{% if foo and %}yes{% else %}no{% endif %}") << dict
925 << QString() << TagSyntaxError;
926 QTest::newRow(
"if-tag-error03")
927 << QStringLiteral(
"{% if foo or %}yes{% else %}no{% endif %}") << dict
928 << QString() << TagSyntaxError;
929 QTest::newRow(
"if-tag-error04")
930 << QStringLiteral(
"{% if not foo and %}yes{% else %}no{% endif %}")
931 << dict << QString() << TagSyntaxError;
932 QTest::newRow(
"if-tag-error05")
933 << QStringLiteral(
"{% if not foo or %}yes{% else %}no{% endif %}") << dict
934 << QString() << TagSyntaxError;
935 QTest::newRow(
"if-tag-error06")
936 << QStringLiteral(
"{% if abc def %}yes{% endif %}") << dict << QString()
938 QTest::newRow(
"if-tag-error07")
939 << QStringLiteral(
"{% if not %}yes{% endif %}") << dict << QString()
941 QTest::newRow(
"if-tag-error08")
942 << QStringLiteral(
"{% if and %}yes{% endif %}") << dict << QString()
944 QTest::newRow(
"if-tag-error09") << QStringLiteral(
"{% if or %}yes{% endif %}")
945 << dict << QString() << TagSyntaxError;
946 QTest::newRow(
"if-tag-error10") << QStringLiteral(
"{% if == %}yes{% endif %}")
947 << dict << QString() << TagSyntaxError;
948 QTest::newRow(
"if-tag-error11")
949 << QStringLiteral(
"{% if 1 == %}yes{% endif %}") << dict << QString()
951 QTest::newRow(
"if-tag-error12")
952 << QStringLiteral(
"{% if a not b %}yes{% endif %}") << dict << QString()
958 auto bio = QSharedPointer<BadIfObject>(
new BadIfObject);
960 QTest::newRow(
"if-tag-shortcircuit01")
962 "{% if x.isTrue or x.isBad %}yes{% else %}no{% endif %}")
963 << dict << QStringLiteral(
"yes") << NoError;
965 QTest::newRow(
"if-tag-shortcircuit02")
967 "{% if x.isFalse and x.isBad %}yes{% else %}no{% endif %}")
968 << dict << QStringLiteral(
"no") << NoError;
972 QTest::newRow(
"if-tag-badarg01")
973 << QStringLiteral(
"{% if x|default_if_none:y %}yes{% endif %}") << dict
974 << QString() << NoError;
977 dict.
insert(QStringLiteral(
"y"), 0);
978 QTest::newRow(
"if-tag-badarg02")
979 << QStringLiteral(
"{% if x|default_if_none:y %}yes{% endif %}") << dict
980 << QString() << NoError;
983 dict.
insert(QStringLiteral(
"y"), 1);
984 QTest::newRow(
"if-tag-badarg03")
985 << QStringLiteral(
"{% if x|default_if_none:y %}yes{% endif %}") << dict
986 << QStringLiteral(
"yes") << NoError;
989 QTest::newRow(
"if-tag-badarg04") << QStringLiteral(
990 "{% if x|default_if_none:y %}yes{% else %}no{% endif %}")
991 << dict << QStringLiteral(
"no") << NoError;
994 dict.
insert(QStringLiteral(
"foo"), 1);
995 QTest::newRow(
"if-tag-single-eq")
996 << QStringLiteral(
"{% if foo = bar %}yes{% else %}no{% endif %}") << dict
997 << QString() << TagSyntaxError;
1002 dict.
insert(QStringLiteral(
"var"), hash);
1003 QTest::newRow(
"if-truthiness01")
1004 << QStringLiteral(
"{% if var %}Yes{% else %}No{% endif %}") << dict
1005 << QStringLiteral(
"No") << NoError;
1006 hash.insert(QStringLiteral(
"foo"), QStringLiteral(
"bar"));
1007 dict.
insert(QStringLiteral(
"var"), hash);
1008 QTest::newRow(
"if-truthiness02")
1009 << QStringLiteral(
"{% if var %}Yes{% else %}No{% endif %}") << dict
1010 << QStringLiteral(
"Yes") << NoError;
1012 dict.
insert(QStringLiteral(
"var"), list);
1013 QTest::newRow(
"if-truthiness03")
1014 << QStringLiteral(
"{% if var %}Yes{% else %}No{% endif %}") << dict
1015 << QStringLiteral(
"No") << NoError;
1016 list.append(QStringLiteral(
"foo"));
1017 dict.
insert(QStringLiteral(
"var"), list);
1018 QTest::newRow(
"if-truthiness04")
1019 << QStringLiteral(
"{% if var %}Yes{% else %}No{% endif %}") << dict
1020 << QStringLiteral(
"Yes") << NoError;
1022 dict.
insert(QStringLiteral(
"var"), map);
1023 QTest::newRow(
"if-truthiness05")
1024 << QStringLiteral(
"{% if var %}Yes{% else %}No{% endif %}") << dict
1025 << QStringLiteral(
"No") << NoError;
1026 map.insert(QStringLiteral(
"foo"), QStringLiteral(
"bar"));
1027 dict.
insert(QStringLiteral(
"var"), map);
1028 QTest::newRow(
"if-truthiness06")
1029 << QStringLiteral(
"{% if var %}Yes{% else %}No{% endif %}") << dict
1030 << QStringLiteral(
"Yes") << NoError;
1034 dict.
insert(QStringLiteral(
"var"), var);
1035 QTest::newRow(
"if-truthiness07")
1036 << QStringLiteral(
"{% if var %}Yes{% else %}No{% endif %}") << dict
1037 << QStringLiteral(
"No") << NoError;
1038 var = QStringLiteral(
"foo");
1039 dict.
insert(QStringLiteral(
"var"), var);
1040 QTest::newRow(
"if-truthiness08")
1041 << QStringLiteral(
"{% if var %}Yes{% else %}No{% endif %}") << dict
1042 << QStringLiteral(
"Yes") << NoError;
1045 dict.
insert(QStringLiteral(
"var"), str);
1046 QTest::newRow(
"if-truthiness09")
1047 << QStringLiteral(
"{% if var %}Yes{% else %}No{% endif %}") << dict
1048 << QStringLiteral(
"No") << NoError;
1049 str = QStringLiteral(
"foo");
1050 dict.
insert(QStringLiteral(
"var"), str);
1051 QTest::newRow(
"if-truthiness10")
1052 << QStringLiteral(
"{% if var %}Yes{% else %}No{% endif %}") << dict
1053 << QStringLiteral(
"Yes") << NoError;
1056 dict.
insert(QStringLiteral(
"var"), i);
1057 QTest::newRow(
"if-truthiness11")
1058 << QStringLiteral(
"{% if var %}Yes{% else %}No{% endif %}") << dict
1059 << QStringLiteral(
"No") << NoError;
1061 dict.
insert(QStringLiteral(
"var"), i);
1062 QTest::newRow(
"if-truthiness12")
1063 << QStringLiteral(
"{% if var %}Yes{% else %}No{% endif %}") << dict
1064 << QStringLiteral(
"Yes") << NoError;
1067 dict.
insert(QStringLiteral(
"var"), r);
1068 QTest::newRow(
"if-truthiness13")
1069 << QStringLiteral(
"{% if var %}Yes{% else %}No{% endif %}") << dict
1070 << QStringLiteral(
"No") << NoError;
1072 dict.
insert(QStringLiteral(
"var"), r);
1073 QTest::newRow(
"if-truthiness14")
1074 << QStringLiteral(
"{% if var %}Yes{% else %}No{% endif %}") << dict
1075 << QStringLiteral(
"Yes") << NoError;
1078 QTest::newRow(
"if-tag-badarg01")
1079 << QStringLiteral(
"{% if x|default_if_none:y %}yes{% endif %}") << dict
1080 << QString() << NoError;
1082 dict.
insert(QStringLiteral(
"y"), 0);
1084 QTest::newRow(
"if-tag-badarg02")
1085 << QStringLiteral(
"{% if x|default_if_none:y %}yes{% endif %}") << dict
1086 << QString() << NoError;
1089 dict.
insert(QStringLiteral(
"y"), 1);
1091 QTest::newRow(
"if-tag-badarg03")
1092 << QStringLiteral(
"{% if x|default_if_none:y %}yes{% endif %}") << dict
1093 << QStringLiteral(
"yes") << NoError;
1096 QTest::newRow(
"if-tag-badarg04") << QStringLiteral(
1097 "{% if x|default_if_none:y %}yes{% else %}no{% endif %}")
1098 << dict << QStringLiteral(
"no") << NoError;
1101void TestDefaultTags::testForTag_data()
1103 QTest::addColumn<QString>(
"input");
1104 QTest::addColumn<Dict>(
"dict");
1105 QTest::addColumn<QString>(
"output");
1106 QTest::addColumn<Cutelee::Error>(
"error");
1110 QVariantList list{1, 2, 3};
1111 dict.
insert(QStringLiteral(
"values"), list);
1112 QTest::newRow(
"for-tag01")
1113 << QStringLiteral(
"{% for val in values %}{{ val }}{% endfor %}") << dict
1114 << QStringLiteral(
"123") << NoError;
1115 QTest::newRow(
"for-tag02")
1116 << QStringLiteral(
"{% for val in values reversed %}{{ val }}{% endfor %}")
1117 << dict << QStringLiteral(
"321") << NoError;
1119 dict.
insert(QStringLiteral(
"values"), list);
1120 QTest::newRow(
"for-tag03") << QStringLiteral(
1121 "{% for val in values %}({{ val }} sdfsdf,){% endfor %}")
1122 << dict << QString() << NoError;
1123 QStringList emails{QStringLiteral(
"one"), QStringLiteral(
"two")};
1125 obj.insert(QStringLiteral(
"emails"), emails);
1126 dict.
insert(QStringLiteral(
"contact"), obj);
1127 QTest::newRow(
"for-tag04")
1129 "{% for val in contact.emails %}({{ val }},){% endfor %}")
1130 << dict << QStringLiteral(
"(one,)(two,)") << NoError;
1132 obj.insert(QStringLiteral(
"emails"), emails);
1133 dict.
insert(QStringLiteral(
"contact"), obj);
1134 QTest::newRow(
"for-tag05") << QStringLiteral(
1135 "{% for val in contact.emails %}({{ val }},){% endfor %}")
1136 << dict << QString() << NoError;
1139 emails << QStringLiteral(
"one");
1140 dict.
insert(QStringLiteral(
"emails"), emails);
1141 QTest::newRow(
"for-tag06")
1142 << QStringLiteral(
"{% for val in emails %}({{ val }},){% endfor %}")
1143 << dict << QStringLiteral(
"(one,)") << NoError;
1147 QTest::newRow(
"for-tag07") << QStringLiteral(
"{% for %}{% endfor %}") << dict
1148 << QString() << TagSyntaxError;
1149 QTest::newRow(
"for-tag08")
1150 << QStringLiteral(
"{% for foo bar bat %}{% endfor %}") << dict
1151 << QString() << TagSyntaxError;
1152 QTest::newRow(
"for-tag09")
1153 << QStringLiteral(
"{% for foo bar '' %}{% endfor %}") << dict << QString()
1156 list << 1 << 2 << 3;
1157 dict.
insert(QStringLiteral(
"values"), list);
1158 QTest::newRow(
"for-tag-vars01") << QStringLiteral(
1159 "{% for val in values %}{{ forloop.counter }}{% endfor %}")
1160 << dict << QStringLiteral(
"123") << NoError;
1161 QTest::newRow(
"for-tag-vars02") << QStringLiteral(
1162 "{% for val in values %}{{ forloop.counter0 }}{% endfor %}")
1163 << dict << QStringLiteral(
"012") << NoError;
1164 QTest::newRow(
"for-tag-vars03") << QStringLiteral(
1165 "{% for val in values %}{{ forloop.revcounter }}{% endfor %}")
1166 << dict << QStringLiteral(
"321") << NoError;
1167 QTest::newRow(
"for-tag-vars04") << QStringLiteral(
1168 "{% for val in values %}{{ forloop.revcounter0 }}{% endfor %}")
1169 << dict << QStringLiteral(
"210") << NoError;
1170 QTest::newRow(
"for-tag-vars05")
1171 << QStringLiteral(
"{% for val in values %}{% if forloop.first %}f{% else "
1172 "%}x{% endif %}{% endfor %}")
1173 << dict << QStringLiteral(
"fxx") << NoError;
1174 QTest::newRow(
"for-tag-vars06")
1175 << QStringLiteral(
"{% for val in values %}{% if forloop.last %}l{% else "
1176 "%}x{% endif %}{% endfor %}")
1177 << dict << QStringLiteral(
"xxl") << NoError;
1181 QVariantList innerList{QStringLiteral(
"one"), 1};
1182 list.append(QVariant(innerList));
1184 innerList << QStringLiteral(
"two") << 2;
1185 list.append(QVariant(innerList));
1186 dict.
insert(QStringLiteral(
"items"), list);
1187 QTest::newRow(
"for-tag-unpack01")
1189 "{% for key,value in items %}{{ key }}:{{ value }}/{% endfor %}")
1190 << dict << QStringLiteral(
"one:1/two:2/") << NoError;
1192 QTest::newRow(
"for-tag-unpack03")
1194 "{% for key, value in items %}{{ key }}:{{ value }}/{% endfor %}")
1195 << dict << QStringLiteral(
"one:1/two:2/") << NoError;
1196 QTest::newRow(
"for-tag-unpack04")
1198 "{% for key , value in items %}{{ key }}:{{ value }}/{% endfor %}")
1199 << dict << QStringLiteral(
"one:1/two:2/") << NoError;
1200 QTest::newRow(
"for-tag-unpack05")
1202 "{% for key ,value in items %}{{ key }}:{{ value }}/{% endfor %}")
1203 << dict << QStringLiteral(
"one:1/two:2/") << NoError;
1204 QTest::newRow(
"for-tag-unpack06")
1206 "{% for key value in items %}{{ key }}:{{ value }}/{% endfor %}")
1207 << dict << QStringLiteral(
"one:1/two:2/") << NoError;
1208 QTest::newRow(
"for-tag-unpack07")
1210 "{% for key,,value in items %}{{ key }}:{{ value }}/{% endfor %}")
1211 << dict << QStringLiteral(
"one:1/two:2/") << NoError;
1212 QTest::newRow(
"for-tag-unpack08")
1214 "{% for key,value, in items %}{{ key }}:{{ value }}/{% endfor %}")
1215 << dict << QStringLiteral(
"one:1/two:2/") << NoError;
1218 QTest::newRow(
"for-tag-unpack09")
1220 "{% for val in items %}{{ val.0 }}:{{ val.1 }}/{% endfor %}")
1221 << dict << QStringLiteral(
"one:1/two:2/") << NoError;
1229 innerList << QStringLiteral(
"one") << 1 << QStringLiteral(
"carrot");
1230 list.append(QVariant(innerList));
1232 innerList << QStringLiteral(
"two") << 2 << QStringLiteral(
"orange");
1233 list.append(QVariant(innerList));
1234 dict.
insert(QStringLiteral(
"items"), list);
1236 QTest::newRow(
"for-tag-unpack10")
1237 << QStringLiteral(
"{% for x,y in items %}{{ x }}:{{ y }}/{% endfor %}")
1238 << dict << QStringLiteral(
"one:1/two:2/") << NoError;
1243 innerList << QStringLiteral(
"one") << 1;
1244 list.append(QVariant(innerList));
1246 innerList << QStringLiteral(
"two") << 2;
1247 list.append(QVariant(innerList));
1248 dict.
insert(QStringLiteral(
"items"), list);
1250 QTest::newRow(
"for-tag-unpack11")
1252 "{% for x,y,z in items %}{{ x }}:{{ y }},{{ z }}/{% endfor %}")
1253 << dict << QStringLiteral(
"one:1,/two:2,/") << NoError;
1258 innerList << QStringLiteral(
"one") << 1 << QStringLiteral(
"carrot");
1259 list.append(QVariant(innerList));
1261 innerList << QStringLiteral(
"two") << 2;
1262 list.append(QVariant(innerList));
1263 dict.
insert(QStringLiteral(
"items"), list);
1265 QTest::newRow(
"for-tag-unpack12")
1267 "{% for x,y,z in items %}{{ x }}:{{ y }},{{ z }}/{% endfor %}")
1268 << dict << QStringLiteral(
"one:1,carrot/two:2,/") << NoError;
1273 innerList << QStringLiteral(
"one") << 1 << QStringLiteral(
"carrot");
1274 list.append(QVariant(innerList));
1276 innerList << QStringLiteral(
"two") << 2 << QStringLiteral(
"cheese");
1277 list.append(QVariant(innerList));
1279 dict.
insert(QStringLiteral(
"items"), list);
1281 QTest::newRow(
"for-tag-unpack13")
1283 "{% for x,y,z in items %}{{ x }}:{{ y }},{{ z }}/{% endfor %}")
1284 << dict << QStringLiteral(
"one:1,carrot/two:2,cheese/") << NoError;
1289 dict.
insert(QStringLiteral(
"values"), QVariantList{1, 2, 3});
1290 QTest::newRow(
"for-tag-empty01") << QStringLiteral(
1291 "{% for val in values %}{{ val }}{% empty %}empty text{% endfor %}")
1292 << dict << QStringLiteral(
"123") << NoError;
1295 dict.
insert(QStringLiteral(
"values"), QVariantList());
1296 QTest::newRow(
"for-tag-empty02")
1297 << QStringLiteral(
"{% for val in values %}{{ val }}{% empty %}values "
1298 "array empty{% endfor %}")
1299 << dict << QStringLiteral(
"values array empty") << NoError;
1302 QTest::newRow(
"for-tag-empty03")
1303 << QStringLiteral(
"{% for val in values %}{{ val }}{% empty %}values "
1304 "array not found{% endfor %}")
1305 << dict << QStringLiteral(
"values array not found") << NoError;
1308void TestDefaultTags::testIfEqualTag_data()
1310 QTest::addColumn<QString>(
"input");
1311 QTest::addColumn<Dict>(
"dict");
1312 QTest::addColumn<QString>(
"output");
1313 QTest::addColumn<Cutelee::Error>(
"error");
1317 dict.
insert(QStringLiteral(
"a"), 1);
1318 dict.
insert(QStringLiteral(
"b"), 2);
1320 QTest::newRow(
"ifequal01")
1321 << QStringLiteral(
"{% ifequal a b %}yes{% endifequal %}") << dict
1322 << QString() << NoError;
1323 QTest::newRow(
"ifequal03")
1324 << QStringLiteral(
"{% ifequal a b %}yes{% else %}no{% endifequal %}")
1325 << dict << QStringLiteral(
"no") << NoError;
1328 dict.
insert(QStringLiteral(
"a"), 1);
1329 dict.
insert(QStringLiteral(
"b"), 1);
1331 QTest::newRow(
"ifequal02")
1332 << QStringLiteral(
"{% ifequal a b %}yes{% endifequal %}") << dict
1333 << QStringLiteral(
"yes") << NoError;
1334 QTest::newRow(
"ifequal04")
1335 << QStringLiteral(
"{% ifequal a b %}yes{% else %}no{% endifequal %}")
1336 << dict << QStringLiteral(
"yes") << NoError;
1339 dict.
insert(QStringLiteral(
"a"), QStringLiteral(
"test"));
1341 QTest::newRow(
"ifequal05")
1342 << QStringLiteral(
"{% ifequal a 'test' %}yes{% else %}no{% endifequal %}")
1343 << dict << QStringLiteral(
"yes") << NoError;
1346 dict.
insert(QStringLiteral(
"a"), QStringLiteral(
"no"));
1348 QTest::newRow(
"ifequal06")
1349 << QStringLiteral(
"{% ifequal a 'test' %}yes{% else %}no{% endifequal %}")
1350 << dict << QStringLiteral(
"no") << NoError;
1353 dict.
insert(QStringLiteral(
"a"), QStringLiteral(
"test"));
1355 QTest::newRow(
"ifequal07")
1356 <<
"{% ifequal a \"test\" %}yes{% else %}no{% endifequal %}" << dict
1357 << QStringLiteral(
"yes") << NoError;
1360 dict.
insert(QStringLiteral(
"a"), QStringLiteral(
"no"));
1362 QTest::newRow(
"ifequal08")
1363 <<
"{% ifequal a \"test\" %}yes{% else %}no{% endifequal %}" << dict
1364 << QStringLiteral(
"no") << NoError;
1368 QTest::newRow(
"ifequal09")
1369 <<
"{% ifequal a \"test\" %}yes{% else %}no{% endifequal %}" << dict
1370 << QStringLiteral(
"no") << NoError;
1372 QTest::newRow(
"ifequal10")
1373 << QStringLiteral(
"{% ifequal a b %}yes{% else %}no{% endifequal %}")
1374 << dict << QStringLiteral(
"yes") << NoError;
1376 QTest::newRow(
"ifequal-split01")
1377 <<
"{% ifequal a \"test man\" %}yes{% else %}no{% endifequal %}" << dict
1378 << QStringLiteral(
"no") << NoError;
1380 dict.
insert(QStringLiteral(
"a"), QStringLiteral(
"foo"));
1381 QTest::newRow(
"ifequal-split02")
1382 <<
"{% ifequal a \"test man\" %}yes{% else %}no{% endifequal %}" << dict
1383 << QStringLiteral(
"no") << NoError;
1386 dict.
insert(QStringLiteral(
"a"), QStringLiteral(
"test man"));
1387 QTest::newRow(
"ifequal-split03")
1388 <<
"{% ifequal a \"test man\" %}yes{% else %}no{% endifequal %}" << dict
1389 << QStringLiteral(
"yes") << NoError;
1390 QTest::newRow(
"ifequal-split04") << QStringLiteral(
1391 "{% ifequal a 'test man' %}yes{% else %}no{% endifequal %}")
1392 << dict << QStringLiteral(
"yes") << NoError;
1395 dict.
insert(QStringLiteral(
"a"), QStringLiteral(
""));
1396 QTest::newRow(
"ifequal-split05")
1397 <<
"{% ifequal a 'i \"love\" you' %}yes{% else %}no{% endifequal %}"
1398 << dict << QStringLiteral(
"no") << NoError;
1401 dict.
insert(QStringLiteral(
"a"), QStringLiteral(
"i \"love\" you"));
1402 QTest::newRow(
"ifequal-split06")
1403 <<
"{% ifequal a 'i \"love\" you' %}yes{% else %}no{% endifequal %}"
1404 << dict << QStringLiteral(
"yes") << NoError;
1407 dict.
insert(QStringLiteral(
"a"), QStringLiteral(
"i love you"));
1408 QTest::newRow(
"ifequal-split07")
1409 <<
"{% ifequal a 'i \"love\" you' %}yes{% else %}no{% endifequal %}"
1410 << dict << QStringLiteral(
"no") << NoError;
1413 dict.
insert(QStringLiteral(
"a"), QStringLiteral(
"I'm happy"));
1414 QTest::newRow(
"ifequal-split08")
1415 <<
"{% ifequal a 'I\\'m happy' %}yes{% else %}no{% endifequal %}" << dict
1416 << QStringLiteral(
"yes") << NoError;
1419 dict.
insert(QStringLiteral(
"a"), QStringLiteral(
"slash\\man"));
1420 QTest::newRow(
"ifequal-split09")
1421 <<
"{% ifequal a 'slash\\man' %}yes{% else %}no{% endifequal %}" << dict
1422 << QStringLiteral(
"yes") << NoError;
1425 dict.
insert(QStringLiteral(
"a"), QStringLiteral(
"slashman"));
1426 QTest::newRow(
"ifequal-split10")
1427 <<
"{% ifequal a 'slash\\man' %}yes{% else %}no{% endifequal %}" << dict
1428 << QStringLiteral(
"no") << NoError;
1432 dict.
insert(QStringLiteral(
"x"), QStringLiteral(
"5"));
1434 QTest::newRow(
"ifequal-numeric01")
1435 << QStringLiteral(
"{% ifequal x 5 %}yes{% endifequal %}") << dict
1436 << QString() << NoError;
1439 dict.
insert(QStringLiteral(
"x"), 5);
1440 QTest::newRow(
"ifequal-numeric02")
1441 << QStringLiteral(
"{% ifequal x 5 %}yes{% endifequal %}") << dict
1442 << QStringLiteral(
"yes") << NoError;
1445 dict.
insert(QStringLiteral(
"x"), 5.2);
1446 QTest::newRow(
"ifequal-numeric03")
1447 << QStringLiteral(
"{% ifequal x 5 %}yes{% endifequal %}") << dict
1448 << QString() << NoError;
1449 QTest::newRow(
"ifequal-numeric04")
1450 << QStringLiteral(
"{% ifequal x 5.2 %}yes{% endifequal %}") << dict
1451 << QStringLiteral(
"yes") << NoError;
1454 dict.
insert(QStringLiteral(
"x"), .2);
1456 QTest::newRow(
"ifequal-numeric05")
1457 << QStringLiteral(
"{% ifequal x 0.2 %}yes{% endifequal %}") << dict
1458 << QStringLiteral(
"yes") << NoError;
1459 QTest::newRow(
"ifequal-numeric06")
1460 << QStringLiteral(
"{% ifequal x .2 %}yes{% endifequal %}") << dict
1461 << QStringLiteral(
"yes") << NoError;
1464 dict.
insert(QStringLiteral(
"x"), 2);
1466 QTest::newRow(
"ifequal-numeric07")
1467 << QStringLiteral(
"{% ifequal x 2. %}yes{% endifequal %}") << dict
1468 << QString() << TagSyntaxError;
1471 dict.
insert(QStringLiteral(
"x"), 5);
1472 QTest::newRow(
"ifequal-numeric08")
1473 <<
"{% ifequal x \"5\" %}yes{% endifequal %}" << dict << QString()
1477 dict.
insert(QStringLiteral(
"x"), QStringLiteral(
"5"));
1478 QTest::newRow(
"ifequal-numeric09")
1479 <<
"{% ifequal x \"5\" %}yes{% endifequal %}" << dict
1480 << QStringLiteral(
"yes") << NoError;
1483 dict.
insert(QStringLiteral(
"x"), -5);
1484 QTest::newRow(
"ifequal-numeric10")
1485 << QStringLiteral(
"{% ifequal x -5 %}yes{% endifequal %}") << dict
1486 << QStringLiteral(
"yes") << NoError;
1489 dict.
insert(QStringLiteral(
"x"), -5.2);
1490 QTest::newRow(
"ifequal-numeric11")
1491 << QStringLiteral(
"{% ifequal x -5.2 %}yes{% endifequal %}") << dict
1492 << QStringLiteral(
"yes") << NoError;
1495 dict.
insert(QStringLiteral(
"x"), 5);
1496 QTest::newRow(
"ifequal-numeric12")
1497 << QStringLiteral(
"{% ifequal x +5 %}yes{% endifequal %}") << dict
1498 << QStringLiteral(
"yes") << NoError;
1503 dict.
insert(QStringLiteral(
"a"), QStringLiteral(
"a"));
1504 QTest::newRow(
"ifequal-filter01")
1505 <<
"{% ifequal a|upper \"A\" %}x{% endifequal %}" << dict
1506 << QStringLiteral(
"x") << NoError;
1508 QTest::newRow(
"ifequal-filter02")
1509 <<
"{% ifequal \"A\" a|upper %}x{% endifequal %}" << dict
1510 << QStringLiteral(
"x") << NoError;
1513 dict.
insert(QStringLiteral(
"a"), QStringLiteral(
"x"));
1514 dict.
insert(QStringLiteral(
"b"), QStringLiteral(
"X"));
1516 QTest::newRow(
"ifequal-filter03")
1517 << QStringLiteral(
"{% ifequal a|upper b|upper %}x{% endifequal %}")
1518 << dict << QStringLiteral(
"x") << NoError;
1521 dict.
insert(QStringLiteral(
"x"), QStringLiteral(
"aaa"));
1523 QTest::newRow(
"ifequal-filter04")
1524 <<
"{% ifequal x|slice:\"1\" \"a\" %}x{% endifequal %}" << dict
1525 << QStringLiteral(
"x") << NoError;
1528 dict.
insert(QStringLiteral(
"x"), QStringLiteral(
"aaa"));
1530 QTest::newRow(
"ifequal-filter05")
1531 <<
"{% ifequal x|slice:\"1\"|upper \"A\" %}x{% endifequal %}" << dict
1532 << QStringLiteral(
"x") << NoError;
1534 QTest::newRow(
"ifequal-error01")
1535 <<
"{% ifequal x|slice:\"1\"|upper %}x{% endifequal %}" << dict
1536 << QString() << TagSyntaxError;
1539void TestDefaultTags::testIfNotEqualTag_data()
1541 QTest::addColumn<QString>(
"input");
1542 QTest::addColumn<Dict>(
"dict");
1543 QTest::addColumn<QString>(
"output");
1544 QTest::addColumn<Cutelee::Error>(
"error");
1548 dict.
insert(QStringLiteral(
"a"), 1);
1549 dict.
insert(QStringLiteral(
"b"), 2);
1551 QTest::newRow(
"ifnotequal01")
1552 << QStringLiteral(
"{% ifnotequal a b %}yes{% endifnotequal %}") << dict
1553 << QStringLiteral(
"yes") << NoError;
1554 QTest::newRow(
"ifnotequal03") << QStringLiteral(
1555 "{% ifnotequal a b %}yes{% else %}no{% endifnotequal %}")
1556 << dict << QStringLiteral(
"yes") << NoError;
1559 dict.
insert(QStringLiteral(
"a"), 1);
1560 dict.
insert(QStringLiteral(
"b"), 1);
1562 QTest::newRow(
"ifnotequal02")
1563 << QStringLiteral(
"{% ifnotequal a b %}yes{% endifnotequal %}") << dict
1564 << QString() << NoError;
1565 QTest::newRow(
"ifnotequal04") << QStringLiteral(
1566 "{% ifnotequal a b %}yes{% else %}no{% endifnotequal %}")
1567 << dict << QStringLiteral(
"no") << NoError;
1570void TestDefaultTags::testTemplateTagTag_data()
1572 QTest::addColumn<QString>(
"input");
1573 QTest::addColumn<Dict>(
"dict");
1574 QTest::addColumn<QString>(
"output");
1575 QTest::addColumn<Cutelee::Error>(
"error");
1579 QTest::newRow(
"templatetag01")
1580 << QStringLiteral(
"{% templatetag openblock %}") << dict
1581 << QStringLiteral(
"{%") << NoError;
1582 QTest::newRow(
"templatetag02")
1583 << QStringLiteral(
"{% templatetag closeblock %}") << dict
1584 << QStringLiteral(
"%}") << NoError;
1585 QTest::newRow(
"templatetag03")
1586 << QStringLiteral(
"{% templatetag openvariable %}") << dict
1587 << QStringLiteral(
"{{") << NoError;
1588 QTest::newRow(
"templatetag04")
1589 << QStringLiteral(
"{% templatetag closevariable %}") << dict
1590 << QStringLiteral(
"}}") << NoError;
1591 QTest::newRow(
"templatetag05") << QStringLiteral(
"{% templatetag %}") << dict
1592 << QString() << TagSyntaxError;
1593 QTest::newRow(
"templatetag06") << QStringLiteral(
"{% templatetag foo %}")
1594 << dict << QString() << TagSyntaxError;
1595 QTest::newRow(
"templatetag07")
1596 << QStringLiteral(
"{% templatetag openbrace %}") << dict
1597 << QStringLiteral(
"{") << NoError;
1598 QTest::newRow(
"templatetag08")
1599 << QStringLiteral(
"{% templatetag closebrace %}") << dict
1600 << QStringLiteral(
"}") << NoError;
1601 QTest::newRow(
"templatetag09") << QStringLiteral(
1602 "{% templatetag openbrace %}{% templatetag openbrace %}")
1603 << dict << QStringLiteral(
"{{") << NoError;
1604 QTest::newRow(
"templatetag10") << QStringLiteral(
1605 "{% templatetag closebrace %}{% templatetag closebrace %}")
1606 << dict << QStringLiteral(
"}}") << NoError;
1607 QTest::newRow(
"templatetag11")
1608 << QStringLiteral(
"{% templatetag opencomment %}") << dict
1609 << QStringLiteral(
"{#") << NoError;
1610 QTest::newRow(
"templatetag12")
1611 << QStringLiteral(
"{% templatetag closecomment %}") << dict
1612 << QStringLiteral(
"#}") << NoError;
1615void TestDefaultTags::testWithTag_data()
1617 QTest::addColumn<QString>(
"input");
1618 QTest::addColumn<Dict>(
"dict");
1619 QTest::addColumn<QString>(
"output");
1620 QTest::addColumn<Cutelee::Error>(
"error");
1625 hash.
insert(QStringLiteral(
"key"), 50);
1626 dict.
insert(QStringLiteral(
"dict"), hash);
1627 QTest::newRow(
"with01") << QStringLiteral(
1628 "{% with dict.key as key %}{{ key }}{% endwith %}")
1629 << dict << QStringLiteral(
"50") << NoError;
1630 QTest::newRow(
"with02") << QStringLiteral(
1631 "{{ key }}{% with dict.key as key %}{{ key }}-{{ dict.key }}-{{ key }}{% "
1632 "endwith %}{{ key }}")
1633 << dict << QStringLiteral(
"50-50-50") << NoError;
1634 QTest::newRow(
"with03") << QStringLiteral(
1635 "{{ key }}{% with key=dict.key %}{{ key }}-{{ dict.key }}-{{ key }}{% "
1636 "endwith %}{{ key }}")
1637 << dict << QStringLiteral(
"50-50-50") << NoError;
1638 QTest::newRow(
"with04") << QStringLiteral(
1639 "{{ key1 }}{% with key1=dict.key key2=dict.key key3=dict.key %}{{ key1 }}-{{ dict.key }}-{{ key3 }}{% "
1640 "endwith %}{{ key }}")
1641 << dict << QStringLiteral(
"50-50-50") << NoError;
1642 QTest::newRow(
"with-error01")
1643 << QStringLiteral(
"{% with dict.key xx key %}{{ key }}{% endwith %}")
1644 << dict << QString() << TagSyntaxError;
1645 QTest::newRow(
"with-error02")
1646 << QStringLiteral(
"{% with dict.key as %}{{ key }}{% endwith %}") << dict
1647 << QString() << TagSyntaxError;
1650void TestDefaultTags::testCycleTag_data()
1652 QTest::addColumn<QString>(
"input");
1653 QTest::addColumn<Dict>(
"dict");
1654 QTest::addColumn<QString>(
"output");
1655 QTest::addColumn<Cutelee::Error>(
"error");
1659 QTest::newRow(
"cycle01") << QStringLiteral(
"{% cycle a %}") << dict
1660 << QString() << TagSyntaxError;
1661 QTest::newRow(
"cycle02") << QStringLiteral(
1662 "{% cycle a,b,c as abc %}{% cycle abc %}")
1663 << dict << QStringLiteral(
"ab") << NoError;
1664 QTest::newRow(
"cycle03") << QStringLiteral(
1665 "{% cycle a,b,c as abc %}{% cycle abc %}{% cycle abc %}")
1666 << dict << QStringLiteral(
"abc") << NoError;
1667 QTest::newRow(
"cycle04") << QStringLiteral(
1668 "{% cycle a,b,c as abc %}{% cycle abc %}{% cycle abc %}{% cycle abc %}")
1669 << dict << QStringLiteral(
"abca") << NoError;
1670 QTest::newRow(
"cycle05") << QStringLiteral(
"{% cycle a %}") << dict
1671 << QString() << TagSyntaxError;
1673 QTest::newRow(
"cycle06") << QStringLiteral(
"{% cycle a %}") << dict
1674 << QString() << TagSyntaxError;
1675 QTest::newRow(
"cycle07") << QStringLiteral(
1676 "{% cycle a,b,c as foo %}{% cycle bar %}")
1677 << dict << QString() << TagSyntaxError;
1678 QTest::newRow(
"cycle08") << QStringLiteral(
1679 "{% cycle a,b,c as foo %}{% cycle foo %}{{ foo }}{{ foo }}{% cycle foo "
1680 "%}{{ foo }}") << dict
1681 << QStringLiteral(
"abbbcc") << NoError;
1683 dict.
insert(QStringLiteral(
"test"), QVariantList{0, 1, 2, 3, 4});
1684 QTest::newRow(
"cycle09") << QStringLiteral(
1685 "{% for i in test %}{% cycle a,b %}{{ i }},{% endfor %}")
1686 << dict << QStringLiteral(
"a0,b1,a2,b3,a4,")
1690 QTest::newRow(
"cycle10") << QStringLiteral(
1691 "{% cycle 'a' 'b' 'c' as abc %}{% cycle abc %}")
1692 << dict << QStringLiteral(
"ab") << NoError;
1693 QTest::newRow(
"cycle11") << QStringLiteral(
1694 "{% cycle 'a' 'b' 'c' as abc %}{% cycle abc %}{% cycle abc %}")
1695 << dict << QStringLiteral(
"abc") << NoError;
1696 QTest::newRow(
"cycle12") << QStringLiteral(
1697 "{% cycle 'a' 'b' 'c' as abc %}{% cycle abc %}{% cycle abc %}{% cycle "
1698 "abc %}") << dict << QStringLiteral(
"abca")
1701 dict.
insert(QStringLiteral(
"test"), QVariantList{0, 1, 2, 3, 4});
1702 QTest::newRow(
"cycle13") << QStringLiteral(
1703 "{% for i in test %}{% cycle 'a' 'b' %}{{ i }},{% endfor %}")
1704 << dict << QStringLiteral(
"a0,b1,a2,b3,a4,")
1708 dict.
insert(QStringLiteral(
"one"), QStringLiteral(
"1"));
1709 dict.
insert(QStringLiteral(
"two"), QStringLiteral(
"2"));
1710 QTest::newRow(
"cycle14") << QStringLiteral(
1711 "{% cycle one two as foo %}{% cycle foo %}")
1712 << dict << QStringLiteral(
"12") << NoError;
1715 dict.
insert(QStringLiteral(
"test"), QVariantList{0, 1, 2, 3, 4});
1716 dict.
insert(QStringLiteral(
"aye"), QStringLiteral(
"a"));
1717 dict.
insert(QStringLiteral(
"bee"), QStringLiteral(
"b"));
1718 QTest::newRow(
"cycle15") << QStringLiteral(
1719 "{% for i in test %}{% cycle aye bee %}{{ i }},{% endfor %}")
1720 << dict << QStringLiteral(
"a0,b1,a2,b3,a4,")
1724 dict.
insert(QStringLiteral(
"one"), QStringLiteral(
"A"));
1725 dict.
insert(QStringLiteral(
"two"), QStringLiteral(
"2"));
1726 QTest::newRow(
"cycle16") << QStringLiteral(
1727 "{% cycle one|lower two as foo %}{% cycle foo %}")
1728 << dict << QStringLiteral(
"a2") << NoError;
1730 QTest::newRow(
"cycle17") << QStringLiteral(
"{% cycle %}") << dict << QString()
1732 QTest::newRow(
"cycle18") << QStringLiteral(
"{% cycle var %}") << dict
1733 << QString() << TagSyntaxError;
1735 dict.
insert(QStringLiteral(
"three"), QStringLiteral(
"B"));
1736 dict.
insert(QStringLiteral(
"four"), QStringLiteral(
"4"));
1738 QTest::newRow(
"cycle19") << QStringLiteral(
"{% cycle one two three foo %}")
1739 << dict << QStringLiteral(
"A") << NoError;
1740 QTest::newRow(
"cycle20") << QStringLiteral(
1741 "{% cycle one two as foo %}{% cycle three four as bar %}")
1742 << dict << QStringLiteral(
"AB") << NoError;
1745void TestDefaultTags::testWidthRatioTag_data()
1747 QTest::addColumn<QString>(
"input");
1748 QTest::addColumn<Dict>(
"dict");
1749 QTest::addColumn<QString>(
"output");
1750 QTest::addColumn<Cutelee::Error>(
"error");
1754 dict.
insert(QStringLiteral(
"a"), 50);
1755 dict.
insert(QStringLiteral(
"b"), 100);
1756 QTest::newRow(
"widthratio01") << QStringLiteral(
"{% widthratio a b 0 %}")
1757 << dict << QStringLiteral(
"0") << NoError;
1760 dict.
insert(QStringLiteral(
"a"), 0);
1761 dict.
insert(QStringLiteral(
"b"), 0);
1762 QTest::newRow(
"widthratio02") << QStringLiteral(
"{% widthratio a b 0 %}")
1763 << dict << QString() << NoError;
1766 dict.
insert(QStringLiteral(
"a"), 0);
1767 dict.
insert(QStringLiteral(
"b"), 100);
1768 QTest::newRow(
"widthratio03") << QStringLiteral(
"{% widthratio a b 100 %}")
1769 << dict << QStringLiteral(
"0") << NoError;
1772 dict.
insert(QStringLiteral(
"a"), 50);
1773 dict.
insert(QStringLiteral(
"b"), 100);
1774 QTest::newRow(
"widthratio04") << QStringLiteral(
"{% widthratio a b 100 %}")
1775 << dict << QStringLiteral(
"50") << NoError;
1778 dict.
insert(QStringLiteral(
"a"), 100);
1779 dict.
insert(QStringLiteral(
"b"), 100);
1780 QTest::newRow(
"widthratio05") << QStringLiteral(
"{% widthratio a b 100 %}")
1781 << dict << QStringLiteral(
"100") << NoError;
1784 dict.
insert(QStringLiteral(
"a"), 50);
1785 dict.
insert(QStringLiteral(
"b"), 80);
1786 QTest::newRow(
"widthratio06") << QStringLiteral(
"{% widthratio a b 100 %}")
1787 << dict << QStringLiteral(
"63") << NoError;
1790 dict.
insert(QStringLiteral(
"a"), 50);
1791 dict.
insert(QStringLiteral(
"b"), 70);
1792 QTest::newRow(
"widthratio07") << QStringLiteral(
"{% widthratio a b 100 %}")
1793 << dict << QStringLiteral(
"71") << NoError;
1797 QTest::newRow(
"widthratio08") << QStringLiteral(
"{% widthratio %}") << dict
1798 << QString() << TagSyntaxError;
1801 QTest::newRow(
"widthratio09") << QStringLiteral(
"{% widthratio a b %}")
1802 << dict << QString() << TagSyntaxError;
1805 dict.
insert(QStringLiteral(
"a"), 50);
1806 dict.
insert(QStringLiteral(
"b"), 100);
1807 QTest::newRow(
"widthratio10") << QStringLiteral(
"{% widthratio a b 100.0 %}")
1808 << dict << QStringLiteral(
"50") << NoError;
1811 dict.
insert(QStringLiteral(
"a"), 50);
1812 dict.
insert(QStringLiteral(
"b"), 100);
1813 dict.
insert(QStringLiteral(
"c"), 100);
1814 QTest::newRow(
"widthratio11") << QStringLiteral(
"{% widthratio a b c %}")
1815 << dict << QStringLiteral(
"50") << NoError;
1818void TestDefaultTags::testFilterTag_data()
1820 QTest::addColumn<QString>(
"input");
1821 QTest::addColumn<Dict>(
"dict");
1822 QTest::addColumn<QString>(
"output");
1823 QTest::addColumn<Cutelee::Error>(
"error");
1827 QTest::newRow(
"filter01")
1828 << QStringLiteral(
"{% filter upper %}{% endfilter %}") << dict
1829 << QString() << NoError;
1830 QTest::newRow(
"filter02")
1831 << QStringLiteral(
"{% filter upper %}django{% endfilter %}") << dict
1832 << QStringLiteral(
"DJANGO") << NoError;
1833 QTest::newRow(
"filter03")
1834 << QStringLiteral(
"{% filter upper|lower %}django{% endfilter %}") << dict
1835 << QStringLiteral(
"django") << NoError;
1837 dict.
insert(QStringLiteral(
"remove"), QStringLiteral(
"spam"));
1838 QTest::newRow(
"filter04")
1839 << QStringLiteral(
"{% filter cut:remove %}djangospam{% endfilter %}")
1840 << dict << QStringLiteral(
"django") << NoError;
1843void TestDefaultTags::testNowTag_data()
1845 QTest::addColumn<QString>(
"input");
1846 QTest::addColumn<Dict>(
"dict");
1847 QTest::addColumn<QString>(
"output");
1848 QTest::addColumn<Cutelee::Error>(
"error");
1854 QTest::newRow(
"now01") << QStringLiteral(
"{% now \"d M yyyy\"%}") << dict
1860 QTest::newRow(
"now02") << QStringLiteral(
"{% now \"d \"M\" yyyy\"%}") << dict
1861 << QString() << TagSyntaxError;
1864void TestDefaultTags::testSpacelessTag_data()
1866 QTest::addColumn<QString>(
"input");
1867 QTest::addColumn<Dict>(
"dict");
1868 QTest::addColumn<QString>(
"output");
1869 QTest::addColumn<Cutelee::Error>(
"error");
1873 QTest::newRow(
"spaceless01")
1875 "{% spaceless %} <b> <i> text </i> </b> {% endspaceless %}")
1876 << dict << QStringLiteral(
"<b><i> text </i></b>") << NoError;
1877 QTest::newRow(
"spaceless02")
1878 <<
"{% spaceless %} <b> \n <i> text </i> \n </b> {% endspaceless %}"
1879 << dict << QStringLiteral(
"<b><i> text </i></b>") << NoError;
1880 QTest::newRow(
"spaceless03")
1881 << QStringLiteral(
"{% spaceless %}<b><i>text</i></b>{% endspaceless %}")
1882 << dict << QStringLiteral(
"<b><i>text</i></b>") << NoError;
1884 dict.
insert(QStringLiteral(
"text"), QStringLiteral(
"This & that"));
1885 QTest::newRow(
"spaceless04")
1887 "{% spaceless %}<b> <i>{{ text }}</i> </b>{% endspaceless %}")
1888 << dict << QStringLiteral(
"<b><i>This & that</i></b>") << NoError;
1889 QTest::newRow(
"spaceless05")
1890 << QStringLiteral(
"{% autoescape off %}{% spaceless %}<b> <i>{{ text "
1891 "}}</i> </b>{% endspaceless %}{% endautoescape %}")
1892 << dict << QStringLiteral(
"<b><i>This & that</i></b>") << NoError;
1893 QTest::newRow(
"spaceless06") << QStringLiteral(
1894 "{% spaceless %}<b> <i>{{ text|safe }}</i> </b>{% endspaceless %}")
1896 << QStringLiteral(
"<b><i>This & that</i></b>")
1900void TestDefaultTags::testRegroupTag_data()
1902 QTest::addColumn<QString>(
"input");
1903 QTest::addColumn<Dict>(
"dict");
1904 QTest::addColumn<QString>(
"output");
1905 QTest::addColumn<Cutelee::Error>(
"error");
1912 hash.
insert(QStringLiteral(
"foo"), QStringLiteral(
"c"));
1913 hash.insert(QStringLiteral(
"bar"), 1);
1917 hash.insert(QStringLiteral(
"foo"), QStringLiteral(
"d"));
1918 hash.insert(QStringLiteral(
"bar"), 1);
1922 hash.insert(QStringLiteral(
"foo"), QStringLiteral(
"a"));
1923 hash.insert(QStringLiteral(
"bar"), 2);
1927 hash.insert(QStringLiteral(
"foo"), QStringLiteral(
"b"));
1928 hash.insert(QStringLiteral(
"bar"), 2);
1932 hash.insert(QStringLiteral(
"foo"), QStringLiteral(
"x"));
1933 hash.insert(QStringLiteral(
"bar"), 3);
1936 dict.
insert(QStringLiteral(
"data"), list);
1938 QTest::newRow(
"regroup01")
1940 "{% for group in grouped %}"
1941 "{{ group.grouper }}:"
1942 "{% for item in group.list %}"
1946 << dict << QStringLiteral(
"1:cd,2:ab,3:x,") << NoError;
1952 hash.insert(QStringLiteral(
"foo"), QStringLiteral(
"a"));
1953 hash.insert(QStringLiteral(
"bar"), 2);
1957 hash.insert(QStringLiteral(
"foo"), QStringLiteral(
"b"));
1958 hash.insert(QStringLiteral(
"bar"), 2);
1962 hash.insert(QStringLiteral(
"foo"), QStringLiteral(
"x"));
1963 hash.insert(QStringLiteral(
"bar"), 3);
1967 hash.insert(QStringLiteral(
"foo"), QStringLiteral(
"c"));
1968 hash.insert(QStringLiteral(
"bar"), 1);
1972 hash.insert(QStringLiteral(
"foo"), QStringLiteral(
"d"));
1973 hash.insert(QStringLiteral(
"bar"), 1);
1976 dict.
insert(QStringLiteral(
"data"), list);
1980 QTest::newRow(
"regroup02")
1982 "{% for group in grouped %}"
1983 "{{ group.grouper }}:"
1984 "{% for item in group.list %}"
1988 << dict << QStringLiteral(
"2:ab,3:x,1:cd,") << NoError;
1998 row.append(QStringLiteral(
"a"));
2003 row.append(QStringLiteral(
"b"));
2008 row.append(QStringLiteral(
"a"));
2013 row.append(QStringLiteral(
"c"));
2018 row.append(QStringLiteral(
"d"));
2023 QTest::newRow(
"regroup03")
2025 "{% for group in grouped %}"
2026 "{{ group.grouper }}:"
2027 "{% for item in group.list %}"
2031 << dict << QStringLiteral(
"1:ab,2:a,3:cd,") << NoError;
2034void TestDefaultTags::testIfChangedTag_data()
2036 QTest::addColumn<QString>(
"input");
2037 QTest::addColumn<Dict>(
"dict");
2038 QTest::addColumn<QString>(
"output");
2039 QTest::addColumn<Cutelee::Error>(
"error");
2043 dict.
insert(QStringLiteral(
"num"), QVariantList{1, 2, 3});
2044 QTest::newRow(
"ifchanged01") << QStringLiteral(
2045 "{% for n in num %}{% ifchanged %}{{ n }}{% endifchanged %}{% endfor %}")
2046 << dict << QStringLiteral(
"123") << NoError;
2049 dict.
insert(QStringLiteral(
"num"), QVariantList{1, 1, 3});
2050 QTest::newRow(
"ifchanged02") << QStringLiteral(
2051 "{% for n in num %}{% ifchanged %}{{ n }}{% endifchanged %}{% endfor %}")
2052 << dict << QStringLiteral(
"13") << NoError;
2055 dict.
insert(QStringLiteral(
"num"), QVariantList{1, 1, 1});
2056 QTest::newRow(
"ifchanged03") << QStringLiteral(
2057 "{% for n in num %}{% ifchanged %}{{ n }}{% endifchanged %}{% endfor %}")
2058 << dict << QStringLiteral(
"1") << NoError;
2061 dict.
insert(QStringLiteral(
"num"), QVariantList{1, 2, 3});
2062 dict.
insert(QStringLiteral(
"numx"), QVariantList{2, 2, 2});
2063 QTest::newRow(
"ifchanged04") << QStringLiteral(
2064 "{% for n in num %}{% ifchanged %}{{ n }}{% endifchanged %}{% for x in "
2065 "numx %}{% ifchanged %}{{ x }}{% endifchanged %}{% endfor %}{% endfor %}")
2066 << dict << QStringLiteral(
"122232") << NoError;
2069 dict.
insert(QStringLiteral(
"num"), QVariantList{1, 1, 1});
2070 dict.
insert(QStringLiteral(
"numx"), QVariantList{1, 2, 3});
2071 QTest::newRow(
"ifchanged05") << QStringLiteral(
2072 "{% for n in num %}{% ifchanged %}{{ n }}{% endifchanged %}{% for x in "
2073 "numx %}{% ifchanged %}{{ x }}{% endifchanged %}{% endfor %}{% endfor %}")
2074 << dict << QStringLiteral(
"1123123123")
2078 dict.
insert(QStringLiteral(
"num"), QVariantList{1, 1, 1});
2079 dict.
insert(QStringLiteral(
"numx"), QVariantList{2, 2, 2});
2080 QTest::newRow(
"ifchanged06") << QStringLiteral(
2081 "{% for n in num %}{% ifchanged %}{{ n }}{% endifchanged %}{% for x in "
2082 "numx %}{% ifchanged %}{{ x }}{% endifchanged %}{% endfor %}{% endfor %}")
2083 << dict << QStringLiteral(
"1222") << NoError;
2086 dict.
insert(QStringLiteral(
"num"), QVariantList{1, 1, 1});
2087 dict.
insert(QStringLiteral(
"numx"), QVariantList{2, 2, 2});
2088 dict.
insert(QStringLiteral(
"numy"), QVariantList{3, 3, 3});
2089 QTest::newRow(
"ifchanged07") << QStringLiteral(
2090 "{% for n in num %}{% ifchanged %}{{ n }}{% endifchanged %}{% for x in "
2091 "numx %}{% ifchanged %}{{ x }}{% endifchanged %}{% for y in numy %}{% "
2092 "ifchanged %}{{ y }}{% endifchanged %}{% endfor %}{% endfor %}{% endfor "
2093 "%}") << dict << QStringLiteral(
"1233323332333")
2095 QTest::newRow(
"ifchanged08")
2096 << QStringLiteral(
"{% ifchanged %}{{ num.0 }}{% endifchanged %}") << dict
2097 << QStringLiteral(
"1") << NoError;
2104 QVariantList innerList;
2105 QVariantList tuple{1, QStringLiteral(
"a")};
2106 innerList.append(QVariant(tuple));
2107 tuple = {1, QStringLiteral(
"a")};
2108 innerList.append(QVariant(tuple));
2109 tuple = {0, QStringLiteral(
"b")};
2110 innerList.append(QVariant(tuple));
2111 tuple = {1, QStringLiteral(
"c")};
2112 innerList.append(QVariant(tuple));
2113 list.append(QVariant(innerList));
2116 tuple = {0, QStringLiteral(
"a")};
2117 innerList.append(QVariant(tuple));
2118 tuple = {1, QStringLiteral(
"c")};
2119 innerList.append(QVariant(tuple));
2120 tuple = {1, QStringLiteral(
"d")};
2121 innerList.append(QVariant(tuple));
2122 tuple = {1, QStringLiteral(
"d")};
2123 innerList.append(QVariant(tuple));
2124 tuple = {0, QStringLiteral(
"e")};
2125 innerList.append(QVariant(tuple));
2126 list.append(QVariant(innerList));
2129 dict.
insert(QStringLiteral(
"datalist"), list);
2130 QTest::newRow(
"ifchanged08") << QStringLiteral(
2131 "{% for data in datalist %}{% for c,d in data %}{% if c %}{% ifchanged "
2132 "%}{{ d }}{% endifchanged %}{% endif %}{% endfor %}{% endfor %}")
2133 << dict << QStringLiteral(
"accd") << NoError;
2137 dict.
insert(QStringLiteral(
"num"), QVariantList{1, 2, 3});
2138 QTest::newRow(
"ifchanged-param01")
2139 << QStringLiteral(
"{% for n in num %}{% ifchanged n %}..{% endifchanged "
2140 "%}{{ n }}{% endfor %}")
2141 << dict << QStringLiteral(
"..1..2..3") << NoError;
2144 dict.
insert(QStringLiteral(
"num"), QVariantList{1, 2, 3});
2145 dict.
insert(QStringLiteral(
"numx"), QVariantList{5, 6, 7});
2146 QTest::newRow(
"ifchanged-param02")
2147 << QStringLiteral(
"{% for n in num %}{% for x in numx %}{% ifchanged n "
2148 "%}..{% endifchanged %}{{ x }}{% endfor %}{% endfor %}")
2149 << dict << QStringLiteral(
"..567..567..567") << NoError;
2154 dict.
insert(QStringLiteral(
"num"), QVariantList{1, 1, 2});
2155 dict.
insert(QStringLiteral(
"numx"), QVariantList{5, 6, 6});
2156 QTest::newRow(
"ifchanged-param03")
2158 "{% for n in num %}{{ n }}{% for x in numx %}{% ifchanged x n "
2159 "%}{{ x }}{% endifchanged %}{% endfor %}{% endfor %}")
2160 << dict << QStringLiteral(
"156156256") << NoError;
2168 hash.insert(QStringLiteral(
"day"), 1);
2169 hash.insert(QStringLiteral(
"hours"), QVariantList{1, 2, 3});
2172 hash.insert(QStringLiteral(
"day"), 2);
2173 hash.insert(QStringLiteral(
"hours"), QVariantList{3});
2175 dict.
insert(QStringLiteral(
"days"), days);
2176 QTest::newRow(
"ifchanged-param04")
2177 << QStringLiteral(
"{% for d in days %}{% ifchanged %}{{ d.day }}{% "
2178 "endifchanged %}{% for h in d.hours %}{% ifchanged d h "
2179 "%}{{ h }}{% endifchanged %}{% endfor %}{% endfor %}")
2180 << dict << QStringLiteral(
"112323") << NoError;
2185 QTest::newRow(
"ifchanged-param05") << QStringLiteral(
2186 "{% for d in days %}{% ifchanged d.day %}{{ d.day }}{% endifchanged %}{% "
2187 "for h in d.hours %}{% ifchanged d.day h %}{{ h }}{% endifchanged %}{% "
2188 "endfor %}{% endfor %}") << dict
2189 << QStringLiteral(
"112323") << NoError;
2193 dict.
insert(QStringLiteral(
"ids"), QVariantList{1, 1, 2, 2, 2, 3});
2194 QTest::newRow(
"ifchanged-else01")
2195 << QStringLiteral(
"{% for id in ids %}{{ id }}{% ifchanged id %}-first{% "
2196 "else %}-other{% endifchanged %},{% endfor %}")
2198 << QStringLiteral(
"1-first,1-other,2-first,2-other,2-other,3-first,")
2200 QTest::newRow(
"ifchanged-else02")
2202 "{% for id in ids %}{{ id }}-{% ifchanged id %}{% cycle red,blue "
2203 "%}{% else %}grey{% endifchanged %},{% endfor %}")
2204 << dict << QStringLiteral(
"1-red,1-grey,2-blue,2-grey,2-grey,3-red,")
2206 QTest::newRow(
"ifchanged-else03")
2208 "{% for id in ids %}{{ id }}{% ifchanged id %}-{% cycle red,blue "
2209 "%}{% else %}{% endifchanged %},{% endfor %}")
2210 << dict << QStringLiteral(
"1-red,1,2-blue,2,2,3-red,") << NoError;
2213 dict.
insert(QStringLiteral(
"ids"), QVariantList{1, 1, 2, 2, 2, 3, 4});
2214 QTest::newRow(
"ifchanged-else04")
2216 "{% for id in ids %}{% ifchanged %}***{{ id }}*{% else %}...{% "
2217 "endifchanged %}{{ forloop.counter }}{% endfor %}")
2218 << dict << QStringLiteral(
"***1*1...2***2*3...4...5***3*6***4*7")
2222void TestDefaultTags::testAutoescapeTag_data()
2224 QTest::addColumn<QString>(
"input");
2225 QTest::addColumn<Dict>(
"dict");
2226 QTest::addColumn<QString>(
"output");
2227 QTest::addColumn<Cutelee::Error>(
"error");
2231 QTest::newRow(
"autoescape-tag01")
2232 << QStringLiteral(
"{% autoescape off %}hello{% endautoescape %}") << dict
2233 << QStringLiteral(
"hello") << NoError;
2235 dict.
insert(QStringLiteral(
"first"), QStringLiteral(
"<b>hello</b>"));
2236 QTest::newRow(
"autoescape-tag02")
2237 << QStringLiteral(
"{% autoescape off %}{{ first }}{% endautoescape %}")
2238 << dict << QStringLiteral(
"<b>hello</b>") << NoError;
2239 QTest::newRow(
"autoescape-tag03")
2240 << QStringLiteral(
"{% autoescape on %}{{ first }}{% endautoescape %}")
2241 << dict << QStringLiteral(
"<b>hello</b>") << NoError;
2243 dict.
insert(QStringLiteral(
"first"), QStringLiteral(
"<a>"));
2244 QTest::newRow(
"autoescape-tag04")
2245 << QStringLiteral(
"{% autoescape off %}{{ first }} {% autoescape on%}{{ "
2246 "first }}{% endautoescape %}{% endautoescape %}")
2247 << dict << QStringLiteral(
"<a> <a>") << NoError;
2249 dict.
insert(QStringLiteral(
"first"), QStringLiteral(
"<b>first</b>"));
2250 QTest::newRow(
"autoescape-tag05")
2251 << QStringLiteral(
"{% autoescape on %}{{ first }}{% endautoescape %}")
2252 << dict << QStringLiteral(
"<b>first</b>") << NoError;
2255 SafeString safeString(QStringLiteral(
"<b>first</b>"));
2257 dict.
insert(QStringLiteral(
"first"), safeStringVar);
2259 QTest::newRow(
"autoescape-tag06")
2260 << QStringLiteral(
"{{ first }}") << dict << QStringLiteral(
"<b>first</b>")
2262 QTest::newRow(
"autoescape-tag07")
2263 << QStringLiteral(
"{% autoescape on %}{{ first }}{% endautoescape %}")
2264 << dict << QStringLiteral(
"<b>first</b>") << NoError;
2269 dict.
insert(QStringLiteral(
"var"), QVariant());
2270 QTest::newRow(
"autoescape-tag08")
2271 <<
"{% autoescape on %}{{ var|default_if_none:\"endquote\\\" hah\" "
2274 << dict <<
"endquote\" hah" << NoError;
2276 QTest::newRow(
"autoescape-tag09")
2277 <<
"{% autoescape on extra %}{{ var|default_if_none:\"endquote\\\" "
2279 "}}{% endautoescape %}"
2280 << dict <<
"" << TagSyntaxError;
2281 QTest::newRow(
"autoescape-tag10")
2282 <<
"{% autoescape bad %}{{ var|default_if_none:\"endquote\\\" hah\" "
2285 << dict <<
"" << TagSyntaxError;
2298 dict.
insert(QStringLiteral(
"first"), QStringLiteral(
"<a>"));
2299 QTest::newRow(
"autoescape-filtertag01")
2301 "{{ first }}{% filter safe %}{{ first }} x<y{% endfilter %}")
2302 << dict << QString() << TagSyntaxError;
2303 QTest::newRow(
"autoescape-filtertag02")
2305 "{{ first }}{% filter escape %}{{ first }} x<y{% endfilter %}")
2306 << dict << QString() << TagSyntaxError;
2309void TestDefaultTags::testMediaFinderTag_data()
2311 QTest::addColumn<QString>(
"input");
2312 QTest::addColumn<Dict>(
"dict");
2313 QTest::addColumn<QString>(
"output");
2314 QTest::addColumn<Cutelee::Error>(
"error");
2317 QTest::newRow(
"media_finder-tag01")
2318 <<
"{% media_finder \"existing_image.png\" %}" << dict
2319 << QStringLiteral(
"file:///path/to/existing_image.png") << NoError;
2320 QTest::newRow(
"media_finder-tag02")
2321 <<
"{% media_finder \"does_not_exist.png\" %}" << dict << QString()
2323 QTest::newRow(
"media_finder-tag03")
2324 <<
"{% media_finder \"existing_image.png\" \"does_not_exist.png\" %}"
2325 << dict << QStringLiteral(
"file:///path/to/existing_image.png")
2328 dict.
insert(QStringLiteral(
"existing_img"),
2329 QStringLiteral(
"existing_image.png"));
2330 dict.
insert(QStringLiteral(
"nonexisting_img"),
2331 QStringLiteral(
"does_not_exist.png"));
2333 QTest::newRow(
"media_finder-tag04") << QStringLiteral(
"{% media_finder %}")
2334 << dict << QString() << TagSyntaxError;
2335 QTest::newRow(
"media_finder-tag05")
2336 << QStringLiteral(
"{% media_finder existing_img %}") << dict
2337 << QStringLiteral(
"file:///path/to/existing_image.png") << NoError;
2338 QTest::newRow(
"media_finder-tag06")
2339 << QStringLiteral(
"{% media_finder nonexisting_img %}") << dict
2340 << QString() << NoError;
2341 QTest::newRow(
"media_finder-tag07")
2342 <<
"{% media_finder \"does_not_exist.png\" existing_img %}" << dict
2343 << QStringLiteral(
"file:///path/to/existing_image.png") << NoError;
2344 QTest::newRow(
"media_finder-tag08")
2345 << QStringLiteral(
"{% media_finder nonexisting_img existing_img %}")
2346 << dict << QStringLiteral(
"file:///path/to/existing_image.png")
2348 QTest::newRow(
"media_finder-tag09")
2349 <<
"{% media_finder \"existing_image.png\" "
2350 "\"another_existing_image.png\" %}"
2351 << dict << QStringLiteral(
"file:///path/to/existing_image.png")
2353 QTest::newRow(
"media_finder-tag10")
2354 <<
"{% media_finder \"another_existing_image.png\" "
2355 "\"existing_image.png\" %}"
2356 << dict << QStringLiteral(
"file:///path/to/another_existing_image.png")
2359 dict.
insert(QStringLiteral(
"this_and_that_img"),
2360 QStringLiteral(
"this&that.png"));
2362 QTest::newRow(
"media_finder-tag11")
2363 <<
"{% media_finder \"this&that.png\" %}" << dict
2364 << QStringLiteral(
"file:///path/to/this&that.png") << NoError;
2365 QTest::newRow(
"media_finder-tag12")
2366 <<
"{% media_finder this_and_that_img %}" << dict
2367 << QStringLiteral(
"file:///path/to/this&that.png") << NoError;
2368 QTest::newRow(
"media_finder-tag13")
2369 <<
"{% autoescape off %}{% media_finder \"this&that.png\" %}{% "
2371 << dict << QStringLiteral(
"file:///path/to/this&that.png") << NoError;
2372 QTest::newRow(
"media_finder-tag14")
2373 <<
"{% autoescape off %}{% media_finder this_and_that_img %}{% "
2375 << dict << QStringLiteral(
"file:///path/to/this&that.png") << NoError;
2378void TestDefaultTags::testRangeTag_data()
2380 QTest::addColumn<QString>(
"input");
2381 QTest::addColumn<Dict>(
"dict");
2382 QTest::addColumn<QString>(
"output");
2383 QTest::addColumn<Cutelee::Error>(
"error");
2387 QTest::newRow(
"range-tag01")
2388 << QStringLiteral(
"{% range 5 as i %}{{ i }};{% endrange %}") << dict
2389 << QStringLiteral(
"0;1;2;3;4;") << NoError;
2390 QTest::newRow(
"range-tag02")
2391 << QStringLiteral(
"{% range 1 6 as i %}{{ i }};{% endrange %}") << dict
2392 << QStringLiteral(
"1;2;3;4;5;") << NoError;
2393 QTest::newRow(
"range-tag03")
2394 << QStringLiteral(
"{% range 5 26 5 as i %}{{ i }};{% endrange %}") << dict
2395 << QStringLiteral(
"5;10;15;20;25;") << NoError;
2397 QVariantList list{10, 15, 2};
2398 dict.
insert(QStringLiteral(
"values"), list);
2400 QTest::newRow(
"range-tag04") << QStringLiteral(
2401 "{% range values.0 values.1 values.2 as i %}{{ i }};{% endrange %}")
2402 << dict << QStringLiteral(
"10;12;14;")
2405 QTest::newRow(
"range-tag05")
2406 << QStringLiteral(
"{% range 5 %}Foo;{% endrange %}") << dict
2407 << QStringLiteral(
"Foo;Foo;Foo;Foo;Foo;") << NoError;
2408 QTest::newRow(
"range-tag06")
2409 << QStringLiteral(
"{% range 5 6 %}Foo;{% endrange %}") << dict
2410 << QString() << TagSyntaxError;
2411 QTest::newRow(
"range-tag07")
2412 << QStringLiteral(
"{% range 5 6 7 %}Foo;{% endrange %}") << dict
2413 << QString() << TagSyntaxError;
2416void TestDefaultTags::testDebugTag_data()
2419 QTest::addColumn<QString>(
"input");
2420 QTest::addColumn<Dict>(
"dict");
2421 QTest::addColumn<QString>(
"output");
2422 QTest::addColumn<Cutelee::Error>(
"error");
2426 QTest::newRow(
"debug-tag01")
2427 << QStringLiteral(
"{% debug %}") << dict
2428 << QStringLiteral(
"\n\nContext:\nEnd context:\n\n") << NoError;
2429 dict.
insert(QStringLiteral(
"answer"), 42);
2430 QTest::newRow(
"debug-tag02")
2431 << QStringLiteral(
"{% debug %}") << dict
2432 << QStringLiteral(
"\n\nContext:\nkey answer, type int\nEnd context:\n\n")
2436void TestDefaultTags::testLoadTag_data()
2439 QTest::addColumn<QString>(
"input");
2440 QTest::addColumn<Dict>(
"dict");
2441 QTest::addColumn<QString>(
"output");
2442 QTest::addColumn<Cutelee::Error>(
"error");
2446 QTest::newRow(
"load-tag01") << QStringLiteral(
"{% load does_not_exist %}foo")
2447 << dict << QString() << TagSyntaxError;
2450void TestDefaultTags::testUrlTypes_data()
2452 QTest::addColumn<QString>(
"input");
2453 QTest::addColumn<Dict>(
"dict");
2454 QTest::addColumn<QPair<QString, QString>>(
"output");
2457 QTest::newRow(
"url-types01")
2458 <<
"{% media_finder \"existing_image.png\" %}" << dict
2459 << qMakePair(QStringLiteral(
"file:///path/to/"),
2460 QStringLiteral(
"existing_image.png"));
2462 QTest::newRow(
"url-types02") <<
"{% media_finder \"does_not_exist.png\" %}"
2463 << dict << qMakePair(QString(), QString());
2465 dict.insert(QStringLiteral(
"existing_img"),
2466 QStringLiteral(
"existing_image.png"));
2467 dict.insert(QStringLiteral(
"nonexisting_img"),
2468 QStringLiteral(
"does_not_exist.png"));
2470 QTest::newRow(
"url-types03")
2471 << QStringLiteral(
"{% media_finder existing_img %}") << dict
2472 << qMakePair(QStringLiteral(
"file:///path/to/"),
2473 QStringLiteral(
"existing_image.png"));
2475 QTest::newRow(
"url-types04")
2476 << QStringLiteral(
"{% media_finder nonexisting_img %}") << dict
2477 << qMakePair(QString(), QString());
2480void TestDefaultTags::testUrlTypes()
2482 QFETCH(QString, input);
2484 QFETCH(StringPair, output);
2486 auto t = m_engine->newTemplate(input, QLatin1String(QTest::currentDataTag()));
2487 QVERIFY(t->error() == NoError);
2489 auto result = t->render(&c);
2490 QVERIFY(t->error() == NoError);
2491 QVERIFY(result == output.first + output.second);
2494 result = t->render(&c);
2495 QVERIFY(t->error() == NoError);
2496 QVERIFY(result == output.second);
2499void TestDefaultTags::testRelativePaths_data()
2501 QTest::addColumn<QString>(
"input");
2502 QTest::addColumn<Dict>(
"dict");
2503 QTest::addColumn<QString>(
"output");
2506 QTest::newRow(
"relativepaths01")
2507 <<
"{% media_finder \"existing_image.png\" %}" << dict
2508 << QStringLiteral(
"existing_image.png");
2510 QTest::newRow(
"relativepaths02")
2511 <<
"{% media_finder \"does_not_exist.png\" %}" << dict << QString();
2513 dict.
insert(QStringLiteral(
"existing_img"),
2514 QStringLiteral(
"existing_image.png"));
2515 dict.
insert(QStringLiteral(
"nonexisting_img"),
2516 QStringLiteral(
"does_not_exist.png"));
2518 QTest::newRow(
"relativepaths03")
2519 << QStringLiteral(
"{% media_finder existing_img %}") << dict
2520 << QStringLiteral(
"existing_image.png");
2522 QTest::newRow(
"relativepaths04")
2523 << QStringLiteral(
"{% media_finder nonexisting_img %}") << dict
2527void TestDefaultTags::testRelativePaths()
2529 QFETCH(QString, input);
2531 QFETCH(QString, output);
2533 auto t = m_engine->newTemplate(input, QLatin1String(QTest::currentDataTag()));
2534 QVERIFY(t->error() == NoError);
2536 auto result = t->render(&c);
2537 QVERIFY(t->error() == NoError);
2538 if (!output.isEmpty())
2539 QVERIFY(result == QStringLiteral(
"file:///path/to/") + output);
2541 QVERIFY(result.isEmpty());
2544 auto relativePath = QStringLiteral(
"relative/path");
2545 c.setRelativeMediaPath(relativePath);
2546 result = t->render(&c);
2547 QVERIFY(t->error() == NoError);
2548 if (!output.isEmpty())
2549 QVERIFY(result == relativePath + QLatin1Char(
'/') + output);
2551 QVERIFY(result.isEmpty());
2555#include "testdefaulttags.moc"
@ RelativeUrls
Relative URLs should be put in the template.
Cutelee::Engine is the main entry point for creating Cutelee Templates.
void setPluginPaths(const QStringList &dirs)
The InMemoryTemplateLoader loads Templates set dynamically in memory.
std::pair< QString, QString > getMediaUri(const QString &fileName) const override
The Cutelee namespace holds all public Cutelee API.
Cutelee::SafeString markSafe(const Cutelee::SafeString &input)
QDateTime currentDateTime()
iterator insert(const Key &key, const T &value)
void append(const T &value)
QObject * parent() const const
QString fromLatin1(const char *str, int size)
QString number(int n, int base)
QVariant fromValue(const T &value)
Utility functions used throughout Cutelee.