23#include "cutelee_paths.h"
26#include "test_macros.h"
28#include <QtCore/QMetaType>
29#include <QtCore/QQueue>
30#include <QtCore/QStack>
31#include <QtCore/QVariant>
32#include <QtCore/QVariantHash>
36#include <QJsonDocument>
37#include <QtTest/QTest>
39#include "coverageobject.h"
45Q_DECLARE_SEQUENTIAL_CONTAINER_METATYPE(
ThreeArray)
49Q_DECLARE_SMART_POINTER_METATYPE(std::shared_ptr)
51Q_DECLARE_SEQUENTIAL_CONTAINER_METATYPE(std::deque)
61 void testGenericClassType();
62 void testSequentialContainer_Variant();
63 void testAssociativeContainer_Variant();
64 void testSequentialContainer_Type();
65 void testAssociativeContainer_Type();
66 void testSharedPointer();
67 void testThirdPartySharedPointer();
68 void testNestedContainers();
70 void testCustomQObjectDerived();
72 void propertyMacroTypes();
74 void testUnregistered();
75 void testPointerNonQObject();
77 void testGadgetMetaType();
87 Person(std::string _name,
int _age) : name(_name), age(_age)
93 bool operator==(
const Person &other)
const {
return uid == other.uid; }
103 Q_PROPERTY(
QString name MEMBER m_name)
109int qHash(
const Person &p) {
return p.uid; }
115if (property == QStringLiteral(
"name"))
117else if (property == QStringLiteral(
"age"))
122if (property == QStringLiteral(
"age"))
137 QString name()
const {
return m_name; }
138 int age()
const {
return m_age; }
145void TestGenericTypes::initTestCase()
152void TestGenericTypes::testGenericClassType()
154 Cutelee::Engine engine;
160 "Person: \nName: {{p.name}}\nAge: {{p.age}}\nUnknown: {{p.unknown}}"),
161 QStringLiteral(
"template1"));
165 Person p(
"Grant Lee", 2);
167 Cutelee::Context c(h);
168 QCOMPARE(t1->render(&c),
169 QStringLiteral(
"Person: \nName: Grant Lee\nAge: 2\nUnknown: "));
181template <
typename SequentialContainer>
184 auto people = getPeople();
187 SequentialContainer container;
188 for (; it != end; ++it)
193template <
typename AssociativeContainer>
196 auto people = getPeople();
199 AssociativeContainer container;
200 for (; it != end; ++it)
209 insertAssociatedPeopleVariants<QMap<QString, QVariant>>(c);
215 insertAssociatedPeopleVariants<QHash<QString, QVariant>>(c);
218template <
typename Container>
void testSequentialIteration(
Cutelee::Context &c)
227 "{% for person in people %}{{ person.name }},{% endfor %}"),
228 QStringLiteral(
"people_template"));
229 QCOMPARE(t1->
render(&c), QStringLiteral(
"Claire,Grant,Alan,"));
233template <
typename Container>
void testSequentialIndexing(
Cutelee::Context &c)
242 "{{ people.0.name }},{{ people.1.name }},{{ people.2.name }},"),
243 QStringLiteral(
"people_template"));
244 QCOMPARE(t1->
render(&c), QStringLiteral(
"Claire,Grant,Alan,"));
251 testSequentialIteration<Container>(c);
256 testSequentialIndexing<Container>(c);
269 "{% for person in people %}{{ person.name }},{% endfor %}"),
270 QStringLiteral(
"people_template"));
271 auto result = t1->
render(&c);
272 QStringList output{QStringLiteral(
"Claire,"), QStringLiteral(
"Grant,"),
273 QStringLiteral(
"Alan,")};
274 Q_FOREACH (
const QString &s, output) {
275 QVERIFY(result.contains(s));
278 QCOMPARE(result.length(), output.
join(
QString()).length());
287 testSequentialIteration<std::list<T>>(c);
293template <
typename Container>
void doTestSequentialContainer_Variant()
297 insertPeopleVariants<Container>(c);
299 SequentialContainerTester<Container>::iteration(c);
300 SequentialContainerTester<Container>::indexing(c);
303template <
typename Container>
312 QStringLiteral(
"{% for person in people.values %}({{ person.name }}:{{ "
313 "person.age }}),{% endfor %}"),
314 QStringLiteral(
"people_template"));
316 auto result = t1->
render(&c);
318 QCOMPARE(result, QStringLiteral(
"(Claire:23),(Grant:32),(Alan:50),"));
320 QVERIFY(result.size() == 33);
321 QVERIFY(result.contains(QStringLiteral(
"(Claire:23),")));
322 QVERIFY(result.contains(QStringLiteral(
"(Grant:32),")));
323 QVERIFY(result.contains(QStringLiteral(
"(Alan:50),")));
328template <
typename Container>
337 QStringLiteral(
"{% for item in people.items %}({{ item.1.name }}:{{ "
338 "item.1.age }}),{% endfor %}"),
339 QStringLiteral(
"people_template"));
340 auto result = t1->
render(&c);
342 QCOMPARE(result, QStringLiteral(
"(Claire:23),(Grant:32),(Alan:50),"));
344 QVERIFY(result.size() == 33);
345 QVERIFY(result.contains(QStringLiteral(
"(Claire:23),")));
346 QVERIFY(result.contains(QStringLiteral(
"(Grant:32),")));
347 QVERIFY(result.contains(QStringLiteral(
"(Alan:50),")));
352template <
typename Container>
353void doTestAssociativeContainer_Variant(
bool unordered = {})
361 insertPeopleVariants<Container>(c);
362 testAssociativeValues<Container>(c, unordered);
363 testAssociativeItems<Container>(c, unordered);
366void TestGenericTypes::testSequentialContainer_Variant()
368 doTestSequentialContainer_Variant<QVariantList>();
369 doTestSequentialContainer_Variant<QVector<QVariant>>();
370 doTestSequentialContainer_Variant<QStack<QVariant>>();
371 doTestSequentialContainer_Variant<QQueue<QVariant>>();
374void TestGenericTypes::testAssociativeContainer_Variant()
376 doTestAssociativeContainer_Variant<QVariantMap>();
377 doTestAssociativeContainer_Variant<QVariantHash>(
true);
380template <
typename SequentialContainer>
void insertPeople(
Cutelee::Context &c)
382 auto people = getPeople();
385 SequentialContainer container;
386 for (; it != end; ++it)
387 container.insert(container.end(), it.value());
393 auto people = getPeople();
397 for (; it != end; ++it)
398 container.
insert(it.value());
404 auto people = getPeople();
407 for (
auto i = 0; i < 3; ++i, ++it) {
409 container[i] = it.value();
414template <
typename AssociativeContainer>
417 auto people = getPeople();
420 AssociativeContainer container;
421 for (; it != end; ++it)
426template <
typename AssociativeContainer>
429 auto people = getPeople();
432 AssociativeContainer container;
433 for (; it != end; ++it)
434 container[it.key()] = it.
value();
438template <
typename Container>
void doTestSequentialContainer_Type()
442 insertPeople<Container>(c);
444 SequentialContainerTester<Container>::iteration(c);
445 SequentialContainerTester<Container>::indexing(c);
448template <
typename Container>
449void doTestAssociativeContainer_Type(
bool unordered = {})
457 insertAssociatedPeople<Container>(c);
458 testAssociativeValues<Container>(c, unordered);
459 testAssociativeItems<Container>(c, unordered);
462template <
typename Container>
463void doTestAssociativeContainer_Type_Number(
bool unordered = {})
471 insertAssociatedPeople_Number<Container>(c);
472 testAssociativeValues<Container>(c, unordered);
473 testAssociativeItems<Container>(c, unordered);
477 = engine.
newTemplate(QStringLiteral(
"{{ people.23.name }}"),
478 QStringLiteral(
"claire_template"));
479 auto result = t1->
render(&c);
480 QCOMPARE(result, QStringLiteral(
"Claire"));
484void TestGenericTypes::testSequentialContainer_Type()
486 doTestSequentialContainer_Type<QList<Person>>();
487 doTestSequentialContainer_Type<QVector<Person>>();
488 doTestSequentialContainer_Type<QStack<Person>>();
489 doTestSequentialContainer_Type<QQueue<Person>>();
490 doTestSequentialContainer_Type<QSet<Person>>();
491 doTestSequentialContainer_Type<std::deque<Person>>();
492 doTestSequentialContainer_Type<std::vector<Person>>();
493 doTestSequentialContainer_Type<std::list<Person>>();
494 doTestSequentialContainer_Type<ThreeArray<Person>>();
497void TestGenericTypes::testAssociativeContainer_Type()
499 doTestAssociativeContainer_Type<QMap<QString, Person>>();
500 doTestAssociativeContainer_Type_Number<QMap<qint16, Person>>();
501 doTestAssociativeContainer_Type_Number<QMap<qint32, Person>>();
502 doTestAssociativeContainer_Type_Number<QMap<qint64, Person>>();
503 doTestAssociativeContainer_Type_Number<QMap<quint16, Person>>();
504 doTestAssociativeContainer_Type_Number<QMap<quint32, Person>>();
505 doTestAssociativeContainer_Type_Number<QMap<quint64, Person>>();
506 doTestAssociativeContainer_Type<QHash<QString, Person>>(
true);
507 doTestAssociativeContainer_Type_Number<QHash<qint16, Person>>(
true);
508 doTestAssociativeContainer_Type_Number<QHash<qint32, Person>>(
true);
509 doTestAssociativeContainer_Type_Number<QHash<qint64, Person>>(
true);
510 doTestAssociativeContainer_Type_Number<QHash<quint16, Person>>(
true);
511 doTestAssociativeContainer_Type_Number<QHash<quint32, Person>>(
true);
512 doTestAssociativeContainer_Type_Number<QHash<quint64, Person>>(
true);
514 doTestAssociativeContainer_Type<std::map<QString, Person>>();
515 doTestAssociativeContainer_Type_Number<std::map<qint16, Person>>();
516 doTestAssociativeContainer_Type_Number<std::map<qint32, Person>>();
517 doTestAssociativeContainer_Type_Number<std::map<qint64, Person>>();
518 doTestAssociativeContainer_Type_Number<std::map<quint16, Person>>();
519 doTestAssociativeContainer_Type_Number<std::map<quint32, Person>>();
520 doTestAssociativeContainer_Type_Number<std::map<quint64, Person>>();
522 doTestAssociativeContainer_Type<QtUnorderedMap<QString, Person>>(
true);
523 doTestAssociativeContainer_Type_Number<QtUnorderedMap<qint16, Person>>(
true);
524 doTestAssociativeContainer_Type_Number<QtUnorderedMap<qint32, Person>>(
true);
525 doTestAssociativeContainer_Type_Number<QtUnorderedMap<qint64, Person>>(
true);
526 doTestAssociativeContainer_Type_Number<QtUnorderedMap<quint16, Person>>(
true);
527 doTestAssociativeContainer_Type_Number<QtUnorderedMap<quint32, Person>>(
true);
528 doTestAssociativeContainer_Type_Number<QtUnorderedMap<quint64, Person>>(
true);
531void TestGenericTypes::testSharedPointer()
533 Cutelee::Engine engine;
537 auto t1 = engine.
newTemplate(QStringLiteral(
"{{ p.name }} {{ p.age }}"),
538 QStringLiteral(
"template1"));
542 std::shared_ptr<PersonObject> p(
543 new PersonObject(QStringLiteral(
"Grant Lee"), 2));
545 Cutelee::Context c(h);
546 QCOMPARE(t1->
render(&c), QStringLiteral(
"Grant Lee 2"));
549void TestGenericTypes::testThirdPartySharedPointer()
551 Cutelee::Engine engine;
555 auto t1 = engine.
newTemplate(QStringLiteral(
"{{ p.name }} {{ p.age }}"),
556 QStringLiteral(
"template1"));
560 std::shared_ptr<PersonObject> p(
561 new PersonObject(QStringLiteral(
"Grant Lee"), 2));
563 Cutelee::Context c(h);
564 QCOMPARE(t1->
render(&c), QStringLiteral(
"Grant Lee 2"));
580static ListVectorInt getNumberLists()
583 for (
auto i = 0; i < 2; ++i) {
584 list.
append(getNumbers());
589static MapListVectorInt getNumberListMap()
591 MapListVectorInt map;
592 for (
auto i = 0; i < 2; ++i) {
593 map.
insert(i, getNumberLists());
598static StackMapListVectorInt getMapStack()
600 StackMapListVectorInt stack;
601 for (
auto i = 0; i < 2; ++i) {
602 stack.
push(getNumberListMap());
607void TestGenericTypes::testNestedContainers()
609 Cutelee::Engine engine;
616#if defined(Q_CC_MSVC)
619#define STRING_LITERAL QLatin1String
621#define STRING_LITERAL QStringLiteral
624 STRING_LITERAL(
"{% for map in stack %}"
625 "(M {% for key, list in map.items %}"
626 "({{ key }} : (L {% for vector in list %}"
627 "(V {% for number in vector %}"
633 QStringLiteral(
"template1"));
637 auto result = t1->
render(&c);
639 auto expectedResult = QStringLiteral(
640 "(M (0 : (L (V 1,2,),(V 3,4,),),(1 : (L (V 5,6,),(V 7,8,),),),(M (0 : (L "
641 "(V 9,10,),(V 11,12,),),(1 : (L (V 13,14,),(V 15,16,),),),");
643 QCOMPARE(result, expectedResult);
661 m_custom->setProperty(
"nestedProp", QStringLiteral(
"nestedValue"));
670void TestGenericTypes::testCustomQObjectDerived()
676 auto customObject =
new CustomObject(
this);
677 customObject->setProperty(
"someProp", QStringLiteral(
"propValue"));
683 auto t1 = engine.
newTemplate(QStringLiteral(
"{{ custom.someProp }}"),
684 QStringLiteral(
"template1"));
686 auto result = t1->
render(&c);
687 auto expectedResult = QStringLiteral(
"propValue");
689 QCOMPARE(result, expectedResult);
692 auto other =
new OtherObject(
this);
694 c.
insert(QStringLiteral(
"other"), other);
698 = engine.
newTemplate(QStringLiteral(
"{{ other.custom.nestedProp }}"),
699 QStringLiteral(
"template1"));
701 auto result = t1->
render(&c);
702 auto expectedResult = QStringLiteral(
"nestedValue");
704 QCOMPARE(result, expectedResult);
720if (property == QStringLiteral(
"property"))
724static QVariantList dummy(
const UnregisteredType &) {
return QVariantList{42}; }
728void TestGenericTypes::testUnregistered()
732 UnregisteredType unregType;
735 auto result = Cutelee::MetaType::lookup(v, QStringLiteral(
"property"));
736 QVERIFY(!result.isValid());
738 QVERIFY(!v.canConvert<QVariantList>());
744 RegisteredNotListType nonListType;
746 auto result = Cutelee::MetaType::lookup(v, QStringLiteral(
"property"));
747 QVERIFY(result.isValid());
748 QVERIFY(!v.canConvert<QVariantList>());
753 UnregisteredType unregType;
755 auto result = Cutelee::MetaType::lookup(v, QStringLiteral(
"property"));
756 QVERIFY(!result.isValid());
764Q_DECLARE_METATYPE(
Person *)
767if (property == QStringLiteral(
"name"))
769else if (property == QStringLiteral(
"age"))
773void TestGenericTypes::testPointerNonQObject()
775 auto p =
new Person(
"Adele", 21);
780 auto result = Cutelee::MetaType::lookup(v, QStringLiteral(
"name"));
782 QCOMPARE(result.toString(), QStringLiteral(
"Adele"));
790 Q_PROPERTY(
int fortyTwo READ fortyTwo)
792 int fortyTwo() {
return 42; }
795void TestGenericTypes::testQGadget()
800 auto result = Cutelee::MetaType::lookup(v, QStringLiteral(
"fortyTwo"));
802 QCOMPARE(result.value<
int>(), 42);
805void TestGenericTypes::testGadgetMetaType()
807 Cutelee::Engine engine;
811 QStringLiteral(
"Person: \nName: {{p.name}}\nAge: {{p.age}}"),
812 QStringLiteral(
"template1"));
815 p.m_name = QStringLiteral(
"Some Name");
819 QStringLiteral(
"Person: \nName: Some Name\nAge: 42"));
834 m_numberList.push_back(42);
835 m_numberList.push_back(7);
838 m_personList.push_back(
new PersonObject{QStringLiteral(
"Joe"), 20});
839 m_personList.push_back(
new PersonObject{QStringLiteral(
"Mike"), 22});
840 m_personPtrList.push_back(
842 m_personPtrList.push_back(
846 QList<int> numberList() {
return m_numberList; }
851 return m_personPtrList;
861void TestGenericTypes::propertyMacroTypes()
865 qRegisterMetaType<QList<CustomGadget>>();
869 auto objectWithProperties =
new ObjectWithProperties(
this);
872 c.
insert(QStringLiteral(
"obj"), objectWithProperties);
876 QStringLiteral(
"{{ obj.numberList.0 }}--{{ obj.numberList.1 }}"),
877 QStringLiteral(
"template1"));
879 auto result = t1->
render(&c);
880 auto expectedResult = QStringLiteral(
"42--7");
882 QCOMPARE(result, expectedResult);
888 "{{ obj.gadgetList.0.fortyTwo }}--{{ obj.gadgetList.1.fortyTwo }}"),
889 QStringLiteral(
"template1"));
891 auto result = t1->
render(&c);
892 auto expectedResult = QStringLiteral(
"42--42");
894 QCOMPARE(result, expectedResult);
900 "{{ obj.personList.0.name }}({{ obj.personList.0.age }})"
901 "--{{ obj.personList.1.name }}({{ obj.personList.1.age }})"),
902 QStringLiteral(
"template1"));
904 auto result = t1->
render(&c);
905 auto expectedResult = QStringLiteral(
"Joe(20)--Mike(22)");
907 QCOMPARE(result, expectedResult);
913 "{{ obj.personPtrList.0.name }}({{ obj.personPtrList.0.age }})"
914 "--{{ obj.personPtrList.1.name }}({{ obj.personPtrList.1.age }})"),
915 QStringLiteral(
"template1"));
917 auto result = t1->
render(&c);
918 auto expectedResult = QStringLiteral(
"Niall(23)--Dave(24)");
920 QCOMPARE(result, expectedResult);
924void TestGenericTypes::testJsonTypes()
926 Cutelee::Engine engine;
933 {QStringLiteral(
"name"), QStringLiteral(
"Joe")},
934 {QStringLiteral(
"age"), 20}
937 {QStringLiteral(
"name"), QStringLiteral(
"Mike")},
938 {QStringLiteral(
"age"), 22}
942 c.
insert(QStringLiteral(
"arr"), arr);
943 c.
insert(QStringLiteral(
"obj"), obj);
947 QStringLiteral(
"{{ arr.count }}"),
948 QStringLiteral(
"template"));
950 auto result = t->
render(&c);
951 auto expectedResult = QStringLiteral(
"2");
953 QCOMPARE(result, expectedResult);
958 QStringLiteral(
"{{ arr.1.name }}({{ arr.1.age }})"),
959 QStringLiteral(
"template"));
961 auto result = t->
render(&c);
962 auto expectedResult = QStringLiteral(
"Mike(22)");
964 QCOMPARE(result, expectedResult);
969 QStringLiteral(
"{% for person in arr %}{{ person.name }}({{ person.age }})\n{% endfor %}"),
970 QStringLiteral(
"template"));
972 auto result = t->
render(&c);
973 auto expectedResult = QStringLiteral(
"Joe(20)\nMike(22)\n");
975 QCOMPARE(result, expectedResult);
980 QStringLiteral(
"{% for name,age in arr %}{{ name }}({{ age }})\n{% endfor %}"),
981 QStringLiteral(
"template"));
983 auto result = t->
render(&c);
984 auto expectedResult = QStringLiteral(
"Joe(20)\nMike(22)\n");
986 QCOMPARE(result, expectedResult);
991 QStringLiteral(
"{{ obj.count }}"),
992 QStringLiteral(
"template"));
994 auto result = t->
render(&c);
995 auto expectedResult = QStringLiteral(
"2");
997 QCOMPARE(result, expectedResult);
1002 QStringLiteral(
"{{ obj.name }}({{ obj.age }})"),
1003 QStringLiteral(
"template"));
1005 auto result = t->
render(&c);
1006 auto expectedResult = QStringLiteral(
"Mike(22)");
1008 QCOMPARE(result, expectedResult);
1013 QStringLiteral(
"{% for key in obj.keys %}{{ key }}\n{% endfor %}"),
1014 QStringLiteral(
"template"));
1016 auto result = t->
render(&c);
1018 QVERIFY(result == QStringLiteral(
"name\nage\n") || result == QStringLiteral(
"age\nname\n"));
1023 QStringLiteral(
"{% for val in obj.values %}{{ val }}\n{% endfor %}"),
1024 QStringLiteral(
"template"));
1026 auto result = t->
render(&c);
1028 QVERIFY(result == QStringLiteral(
"Mike\n22\n") || result == QStringLiteral(
"22\nMike\n"));
1033 QStringLiteral(
"{% for item in obj.items %}{{ item.0 }}:{{ item.1 }}\n{% endfor %}"),
1034 QStringLiteral(
"template"));
1036 auto result = t->
render(&c);
1038 QVERIFY(result == QStringLiteral(
"age:22\nname:Mike\n") || result == QStringLiteral(
"name:Mike\nage:22\n"));
1041 QJsonDocument arrDoc(arr);
1042 c.
insert(QStringLiteral(
"arrDoc"), arrDoc);
1046 QStringLiteral(
"{{ arrDoc.count }}"),
1047 QStringLiteral(
"template"));
1049 auto result = t->
render(&c);
1050 auto expectedResult = QStringLiteral(
"2");
1052 QCOMPARE(result, expectedResult);
1057 QStringLiteral(
"{{ arrDoc.1.name }}({{ arrDoc.1.age }})"),
1058 QStringLiteral(
"template"));
1060 auto result = t->
render(&c);
1061 auto expectedResult = QStringLiteral(
"Mike(22)");
1063 QCOMPARE(result, expectedResult);
1068 QStringLiteral(
"{% for person in arrDoc %}{{ person.name }}({{ person.age }})\n{% endfor %}"),
1069 QStringLiteral(
"template"));
1071 auto result = t->
render(&c);
1072 auto expectedResult = QStringLiteral(
"Joe(20)\nMike(22)\n");
1074 QCOMPARE(result, expectedResult);
1079 QStringLiteral(
"{% for name,age in arrDoc %}{{ name }}({{ age }})\n{% endfor %}"),
1080 QStringLiteral(
"template"));
1082 auto result = t->
render(&c);
1083 auto expectedResult = QStringLiteral(
"Joe(20)\nMike(22)\n");
1085 QCOMPARE(result, expectedResult);
1088 QJsonDocument objDoc(obj);
1089 c.
insert(QStringLiteral(
"objDoc"), objDoc);
1093 QStringLiteral(
"{{ objDoc.count }}"),
1094 QStringLiteral(
"template"));
1096 auto result = t->
render(&c);
1097 auto expectedResult = QStringLiteral(
"2");
1099 QCOMPARE(result, expectedResult);
1104 QStringLiteral(
"{{ objDoc.name }}({{ objDoc.age }})"),
1105 QStringLiteral(
"template"));
1107 auto result = t->
render(&c);
1108 auto expectedResult = QStringLiteral(
"Mike(22)");
1110 QCOMPARE(result, expectedResult);
1115 QStringLiteral(
"{% for key in objDoc.keys %}{{ key }}\n{% endfor %}"),
1116 QStringLiteral(
"template"));
1118 auto result = t->
render(&c);
1120 QVERIFY(result == QStringLiteral(
"name\nage\n") || result == QStringLiteral(
"age\nname\n"));
1125 QStringLiteral(
"{% for val in objDoc.values %}{{ val }}\n{% endfor %}"),
1126 QStringLiteral(
"template"));
1128 auto result = t->
render(&c);
1130 QVERIFY(result == QStringLiteral(
"Mike\n22\n") || result == QStringLiteral(
"22\nMike\n"));
1135 QStringLiteral(
"{% for item in objDoc.items %}{{ item.0 }}:{{ item.1 }}\n{% endfor %}"),
1136 QStringLiteral(
"template"));
1138 auto result = t->
render(&c);
1140 QVERIFY(result == QStringLiteral(
"age:22\nname:Mike\n") || result == QStringLiteral(
"name:Mike\nage:22\n"));
1143 QJsonObject emptyObj;
1144 c.
insert(QStringLiteral(
"emptyObj"), emptyObj);
1148 QStringLiteral(
"{{ emptyObj.name }}"),
1149 QStringLiteral(
"template"));
1151 auto result = t->
render(&c);
1152 auto expectedResult = QStringLiteral(
"");
1154 QCOMPARE(result, expectedResult);
1157 QJsonArray emptyArr;
1158 c.
insert(QStringLiteral(
"emptyArr"), emptyArr);
1162 QStringLiteral(
"{{ emptyArr.1 }}"),
1163 QStringLiteral(
"template"));
1165 auto result = t->
render(&c);
1166 auto expectedResult = QStringLiteral(
"");
1168 QCOMPARE(result, expectedResult);
1171 QJsonDocument emptyDoc;
1172 c.
insert(QStringLiteral(
"emptyDoc"), emptyDoc);
1176 QStringLiteral(
"{{ emptyDoc }}"),
1177 QStringLiteral(
"template"));
1179 auto result = t->
render(&c);
1180 auto expectedResult = QStringLiteral(
"");
1182 QCOMPARE(result, expectedResult);
1185 c.
insert(QStringLiteral(
"valBool"), QJsonValue(
true));
1189 QStringLiteral(
"{{ valBool }}"),
1190 QStringLiteral(
"template"));
1192 auto result = t->
render(&c);
1193 auto expectedResult = QStringLiteral(
"true");
1195 QCOMPARE(result, expectedResult);
1198 c.
insert(QStringLiteral(
"valDouble"), QJsonValue(15));
1202 QStringLiteral(
"{{ valDouble }}"),
1203 QStringLiteral(
"template"));
1205 auto result = t->
render(&c);
1206 auto expectedResult = QStringLiteral(
"15");
1208 QCOMPARE(result, expectedResult);
1211 c.
insert(QStringLiteral(
"valString"), QJsonValue(QStringLiteral(
"Sapere aude")));
1215 QStringLiteral(
"{{ valString }}"),
1216 QStringLiteral(
"template"));
1218 auto result = t->
render(&c);
1219 auto expectedResult = QStringLiteral(
"Sapere aude");
1221 QCOMPARE(result, expectedResult);
1224 c.
insert(QStringLiteral(
"valArray"), QJsonValue(arr));
1228 QStringLiteral(
"{% for person in valArray %}{{ person.name }}({{ person.age }})\n{% endfor %}"),
1229 QStringLiteral(
"template"));
1231 auto result = t->
render(&c);
1232 auto expectedResult = QStringLiteral(
"Joe(20)\nMike(22)\n");
1234 QCOMPARE(result, expectedResult);
1237 c.
insert(QStringLiteral(
"valObj"), QJsonValue(obj));
1241 QStringLiteral(
"{{ valObj.name }}({{ valObj.age }})"),
1242 QStringLiteral(
"template"));
1244 auto result = t->
render(&c);
1245 auto expectedResult = QStringLiteral(
"Mike(22)");
1247 QCOMPARE(result, expectedResult);
1250 c.
insert(QStringLiteral(
"valNull"), QJsonValue());
1254 QStringLiteral(
"{{ valNull }}"),
1255 QStringLiteral(
"template"));
1257 auto result = t->
render(&c);
1258 auto expectedResult = QStringLiteral(
"");
1260 QCOMPARE(result, expectedResult);
1265#include "testgenerictypes.moc"
The Context class holds the context to render a Template with.
void insert(const QString &name, QObject *object)
Cutelee::Engine is the main entry point for creating Cutelee Templates.
void setPluginPaths(const QStringList &dirs)
Template newTemplate(const QString &content, const QString &name) const
The Template class is a tree of nodes which may be rendered.
QString render(Context *c) const
int registerMetaType()
Registers the type RealType with the metatype system.
void push_back(const QJsonValue &value)
void append(QList< T > &&value)
void push_back(QList< T >::parameter_type value)
const T & value() const const
QMap< Key, T >::const_iterator constBegin() const const
QMap< Key, T >::const_iterator constEnd() const const
QMap< Key, T >::iterator insert(QMap< Key, T >::const_iterator pos, const Key &key, const T &value)
QObject * parent() const const
QSet< T >::iterator insert(QSet< T >::const_iterator it, const T &value)
QString fromStdString(const std::string &str)
QString number(double n, char format, int precision)
QString join(QChar separator) const const
QVariant fromValue(T &&value)