Files
jmustache/src/test/java/com/samskivert/mustache/specs/SpecTest.java
T
Michael Bayne 6e53f924ba Enable more tests, we pass many of them. Woo!
This also improves failure reporting for specs tests.
2014-12-16 09:45:48 -08:00

47 lines
1.4 KiB
Java

//
// JMustache - A Java implementation of the Mustache templating language
// http://github.com/samskivert/jmustache/blob/master/LICENSE
package com.samskivert.mustache.specs;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.runner.RunWith;
import com.samskivert.mustache.Mustache;
import com.samskivert.mustache.Template;
/**
* @author Yoryos Valotasios
*/
@RunWith(SpecRunner.class)
public class SpecTest
{
private static Mustache.Compiler compiler;
private static SpecAwareTemplateLoader loader;
@BeforeClass
public static void setUp () {
loader = new SpecAwareTemplateLoader();
compiler = Mustache.compiler().defaultValue("").withLoader(loader);
}
public void test (Spec spec) {
loader.setSpec(spec);
String tmpl = spec.getTemplate();
String desc = String.format("Template: '''%s'''\nData: '%s'\n",
uncrlf(tmpl), uncrlf(spec.getData().toString()));
try {
Template t = compiler.compile(spec.getTemplate());
String out = t.execute(spec.getData());
Assert.assertEquals(desc, uncrlf(spec.getExpectedOutput()), uncrlf(out));
} catch (Exception e) {
Assert.fail(desc + ": " + e);
}
}
private static String uncrlf (String text) {
return (text == null) ? null : text.replace("\r", "\\r").replace("\n", "\\n");
}
}