public void testImmutableList() throws IOException { Object object = new Object() { List<String> people = singletonList("Test"); }; StringWriter sw = execute("isempty.html", singletonList(object)); assertEquals(getContents(root, "isempty.txt"), sw.toString()); }
public void testImplicitIteratorNoScope() throws IOException { Mustache test = new DefaultMustacheFactory().compile(new StringReader("{{.}}"), "test"); StringWriter sw = new StringWriter(); test.execute(sw, "").close(); assertEquals("", sw.toString()); StringWriter sw2 = new StringWriter(); test.execute(sw2, new Object[0]).close(); assertEquals("", sw2.toString()); }
public void testChainedInheritance() throws IOException { StringWriter sw = execute("page.html", new Object() { Object test = new Object() { boolean test = false; }; }); assertEquals(getContents(root, "page.txt"), sw.toString()); }
public void testRecursionWithInheritance() throws IOException { StringWriter sw = execute("recursion_with_inheritance.html", new Object() { Object value = new Object() { boolean value = false; }; }); assertEquals(getContents(root, "recursion.txt"), sw.toString()); }
public void testIsNotEmpty() throws IOException { Object object = new Object() { List<String> people = singletonList("Test"); }; StringWriter sw = execute("isempty.html", object); assertEquals(getContents(root, "isempty.txt"), sw.toString()); }
public void testPartialRecursionWithInheritance() throws IOException { StringWriter sw = execute("recursive_partial_inheritance.html", new Object() { Object test = new Object() { boolean test = false; }; }); assertEquals(getContents(root, "recursive_partial_inheritance.txt"), sw.toString()); }
public void testObjectArray() throws IOException { MustacheFactory mf = createMustacheFactory(); Mustache m = mf.compile(new StringReader("{{#values}}{{.}}{{/values}}{{^values}}Test2{{/values}}"), "testObjectArray"); StringWriter sw = new StringWriter(); m.execute(sw, new Object() { Integer[] values = new Integer[]{1, 2, 3}; }).close(); assertEquals("123", sw.toString()); }
public void testSuperField() throws IOException { MustacheFactory mf = createMustacheFactory(); Mustache m = mf.compile(new StringReader("{{#values}}Test1{{/values}}{{^values}}Test2{{/values}}"), "testIterator"); StringWriter sw = new StringWriter(); m.execute(sw, new SuperClass() { }).close(); // Values ignored as if it didn't exist at all assertEquals("Test1", sw.toString()); }
public void testComment() throws IOException { MustacheFactory c = createMustacheFactory(); Mustache m = c.compile(new StringReader("{{#process}}{{!comment}}{{/process}}"), ""); StringWriter sw = new StringWriter(); m.execute(sw, new Object() { TemplateFunction process = s -> s.replace("{", "["); }); assertEquals("[[!comment}}", sw.toString()); }
public void testRelativePathsDotDotDirOverride() throws IOException { MustacheFactory mf = new DefaultMustacheFactory(root) { @Override public String resolvePartialPath(String dir, String name, String extension) { return name + extension; } }; Mustache compile = mf.compile("relative/nonrelative.html"); StringWriter sw = new StringWriter(); compile.execute(sw, "").close(); assertEquals(getContents(root, "nonrelative.html"), sw.toString()); }
public void testOutputDelimiters() { String template = "{{=## ##=}}{{##={{ }}=####"; Mustache mustache = new DefaultMustacheFactory().compile(new StringReader(template), "test"); StringWriter sw = new StringWriter(); mustache.execute(sw, new Object[0]); assertEquals("{{##", sw.toString()); }
public void testRelativePathsSameDir() throws IOException { MustacheFactory mf = createMustacheFactory(); Mustache compile = mf.compile("relative/paths.html"); StringWriter sw = new StringWriter(); compile.execute(sw, "").close(); assertEquals(getContents(root, "relative/paths.txt"), sw.toString()); }
public void testRelativePathsDotDotDir() throws IOException { MustacheFactory mf = createMustacheFactory(); Mustache compile = mf.compile("relative/dotdot.html"); StringWriter sw = new StringWriter(); compile.execute(sw, "").close(); assertEquals(getContents(root, "uninterestingpartial.html"), sw.toString()); }
public void testRelativePathsRootDir() throws IOException { MustacheFactory mf = createMustacheFactory(); Mustache compile = mf.compile("relative/rootpath.html"); StringWriter sw = new StringWriter(); compile.execute(sw, "").close(); assertEquals(getContents(root, "relative/paths.txt"), sw.toString()); }
public void testPathsWithExtension() throws IOException { MustacheFactory mf = createMustacheFactory(); Mustache compile = mf.compile("relative/extension.html"); StringWriter sw = new StringWriter(); compile.execute(sw, "").close(); assertEquals(getContents(root, "relative/paths.txt"), sw.toString()); }
public void testReadme() throws MustacheException, IOException { MustacheFactory c = createMustacheFactory(); Mustache m = c.compile("items.html"); StringWriter sw = new StringWriter(); long start = System.currentTimeMillis(); m.execute(sw, new Context()); long diff = System.currentTimeMillis() - start; assertEquals(getContents(root, "items.txt"), sw.toString()); }
public void testReadmeParallel() throws MustacheException, IOException { MustacheFactory c = initParallel(); Mustache m = c.compile("items2.html"); StringWriter sw = new StringWriter(); long start = System.currentTimeMillis(); m.execute(sw, new Context()).close(); long diff = System.currentTimeMillis() - start; assertEquals(getContents(root, "items.txt"), sw.toString()); assertTrue("Should be a little bit more than 1 second: " + diff, diff > 999 && diff < 2000); }
public void testComplexParallel() throws MustacheException, IOException { MustacheFactory c = initParallel(); Mustache m = c.compile("complex.html"); StringWriter sw = new StringWriter(); m.execute(sw, new ParallelComplexObject()).close(); assertEquals(getContents(root, "complex.txt"), sw.toString()); }
public void testImproperlyClosedVariable() throws IOException { try { new DefaultMustacheFactory().compile(new StringReader("{{{#containers}} {{/containers}}"), "example"); fail("Should have throw MustacheException"); } catch (MustacheException actual) { assertEquals("Improperly closed variable in example:1 @[example:1]", actual.getMessage()); } }
public void testMustacheNotFoundException() { String nonExistingMustache = "404"; try { new DefaultMustacheFactory().compile(nonExistingMustache); fail("Didn't throw an exception"); } catch (MustacheNotFoundException e) { assertEquals(nonExistingMustache, e.getName()); } }