Esempio n. 1
0
void TestMustache::testSetDelimiters()
{
	// test changing the markers within a template
	QVariantHash map;
	map["name"] = "John Smith";
	map["phone"] = "01234 567890";

	QString _template =
	    "{{=<% %>=}}"
	    "<%name%>{{ }}<%phone%>"
	    "<%={{ }}=%>"
	    " {{name}}<% %>{{phone}}";

	QString expectedOutput = "John Smith{{ }}01234 567890 John Smith<% %>01234 567890";

	Mustache::Renderer renderer;
	Mustache::QtVariantContext context(map);
	QString output = renderer.render(_template, &context);

	QCOMPARE(output, expectedOutput);

	// test changing the default markers
	renderer.setTagMarkers("%", "%");
	output = renderer.render("%name%'s phone number is %phone%", &context);
	QCOMPARE(output, QString("John Smith's phone number is 01234 567890"));
}