21 #ifndef INSERTLIBRARYTEST_H
22 #define INSERTLIBRARYTEST_H
27 #include "coverageobject.h"
29 #include "cutelee_paths.h"
33 #include "taglibraryinterface.h"
34 #include "exception.h"
36 #define TESTLIBRARYTAG_RENDER_VALUE "Hello World!"
46 void cleanupTestCase();
48 void testInsertedLibraryTag();
49 void testLoadInsertedLibraryTag();
52 std::shared_ptr<InMemoryTemplateLoader> m_loader;
53 Engine *m_engine =
nullptr;
79 *stream << QStringLiteral(TESTLIBRARYTAG_RENDER_VALUE);
87 explicit TestLibrary(QObject *parent =
nullptr) : QObject(parent) {}
92 QHash<QString, AbstractNodeFactory*> ret{
104 explicit TestLoadLibrary(QObject *parent =
nullptr) : QObject(parent) {}
109 QHash<QString, AbstractNodeFactory*> ret{
116 void TestInsertLibrary::initTestCase()
118 m_engine =
new Engine(
this);
122 m_engine->addTemplateLoader(m_loader);
124 m_engine->setPluginPaths({QStringLiteral(CUTELEE_PLUGIN_PATH)});
126 m_engine->insertDefaultLibrary(QStringLiteral(
"test_library"),
new TestLibrary(m_engine));
128 m_engine->insertLibrary(QStringLiteral(
"test_load_library"),
new TestLoadLibrary(m_engine));
131 void TestInsertLibrary::cleanupTestCase()
136 void TestInsertLibrary::testInsertedLibraryTag()
138 auto t = m_engine->newTemplate(QStringLiteral(
"{% test_library_tag %}"), QStringLiteral(
"testInsertedLibraryTag"));
142 const QString result = t->render(&context);
144 QCOMPARE(result, QStringLiteral(TESTLIBRARYTAG_RENDER_VALUE));
147 void TestInsertLibrary::testLoadInsertedLibraryTag()
151 auto t1 = m_engine->newTemplate(QStringLiteral(
"{% test_load_library_tag %}"), QStringLiteral(
"testLoadInsertedLibraryTag1"));
153 const QString result1 = t1->render(&context);
155 QVERIFY(result1.isEmpty());
157 auto t2 = m_engine->newTemplate(QStringLiteral(
"{% load test_load_library %}{% test_load_library_tag %}"), QStringLiteral(
"testLoadInsertedLibraryTag2"));
159 const QString result2 = t2->render(&context);
161 QCOMPARE(result2, QStringLiteral(TESTLIBRARYTAG_RENDER_VALUE));
166 #include "testinsertlibrary.moc"
Base class for all NodeFactories.
The Context class holds the context to render a Template with.
Cutelee::Engine is the main entry point for creating Cutelee Templates.
The InMemoryTemplateLoader loads Templates set dynamically in memory.
Base class for all nodes.
The OutputStream class is used to render templates to a QTextStream.
The Parser class processes a string template into a tree of nodes.
The TagLibraryInterface returns available tags and filters from libraries.
void render(Cutelee::OutputStream *stream, Cutelee::Context *gc) const override
virtual QHash< QString, AbstractNodeFactory * > nodeFactories(const QString &name=QString()) override
virtual QHash< QString, AbstractNodeFactory * > nodeFactories(const QString &name=QString()) override
The Cutelee namespace holds all public Cutelee API.