21#ifndef INSERTLIBRARYTEST_H
22#define INSERTLIBRARYTEST_H
27#include "coverageobject.h"
29#include "cutelee_paths.h"
33#include "taglibraryinterface.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;
61class TestLibraryTag :
public Node
65 explicit TestLibraryTag(
Parser *parser =
nullptr) :
Node(parser) {}
79 *stream << QStringLiteral(TESTLIBRARYTAG_RENDER_VALUE);
116void TestInsertLibrary::initTestCase()
118 m_engine =
new Engine(
this);
121 m_loader = std::shared_ptr<InMemoryTemplateLoader>(
new InMemoryTemplateLoader());
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));
131void TestInsertLibrary::cleanupTestCase()
136void 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));
147void TestInsertLibrary::testLoadInsertedLibraryTag()
151 auto t1 = m_engine->newTemplate(QStringLiteral(
"{% test_load_library_tag %}"), QStringLiteral(
"testLoadInsertedLibraryTag1"));
153 const QString result1 = t1->render(&context);
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"
AbstractNodeFactory(QObject *parent={})
The Context class holds the context to render a Template with.
Cutelee::Engine is the main entry point for creating Cutelee Templates.
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.
QObject * parent() const const
bool isEmpty() const const