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 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 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 testIdentitySimple() throws MustacheException, IOException, ExecutionException, InterruptedException { MustacheFactory c = createMustacheFactory(); Mustache m = c.compile("simple.html"); StringWriter sw = new StringWriter(); m.identity(sw); assertEquals(getContents(root, "simple.html").replaceAll("\\s+", ""), sw.toString().replaceAll( "\\s+", "")); }
@Test public void testClientMethod() throws MustacheException, IOException, ExecutionException, InterruptedException { MustacheFactory c = new DefaultMustacheFactory(root); Mustache m = c.compile("client.html"); StringWriter sw = new StringWriter(); Map scope = new HashMap(); scope.put("reply", "TestReply"); scope.put("commands", Arrays.asList("a", "b")); m.execute(sw, scope); assertEquals(getContents(root, "client.txt"), sw.toString()); }
@Test public void testSubSub() throws MustacheException, IOException, ExecutionException, InterruptedException { MustacheFactory c = new DefaultMustacheFactory(root); Mustache m = c.compile("subsub.html"); StringWriter sw = new StringWriter(); Map scope = new HashMap(); scope.put("name", "Sam"); scope.put("randomid", "asdlkfj"); m.execute(sw, scope); assertEquals(getContents(root, "subsub.txt"), sw.toString()); }
@Test public void testSubInPartial() throws MustacheException, IOException, ExecutionException, InterruptedException { MustacheFactory c = new DefaultMustacheFactory(root); Mustache m = c.compile("partialsub.html"); StringWriter sw = new StringWriter(); Map scope = new HashMap(); scope.put("name", "Sam"); scope.put("randomid", "asdlkfj"); m.execute(sw, scope); assertEquals(getContents(root, "sub.txt"), 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 testIssue191() throws IOException { MustacheFactory mustacheFactory = createMustacheFactory(); Mustache mustache = mustacheFactory.compile("templates/someTemplate.mustache"); StringWriter stringWriter = new StringWriter(); mustache.execute(stringWriter, ImmutableMap.of("title", "Some title!")); assertEquals(getContents(root, "templates/someTemplate.txt"), stringWriter.toString()); }
@Test public void testOverridePage1() throws MustacheException, IOException, ExecutionException, InterruptedException { MustacheFactory c = new FallbackMustacheFactory(rootOverride, rootDefault); Mustache m = c.compile("page1.html"); StringWriter sw = new StringWriter(); Map scope = new HashMap(); scope.put("title", "My title"); m.execute(sw, scope); assertEquals(getContents(rootOverride, "page1.txt"), sw.toString()); }
@Test public void testOverridePage2() throws MustacheException, IOException, ExecutionException, InterruptedException { MustacheFactory c = new FallbackMustacheFactory(rootOverride, rootDefault); Mustache m = c.compile("page2.html"); StringWriter sw = new StringWriter(); Map scope = new HashMap(); scope.put("title", "My title"); m.execute(sw, scope); assertEquals(getContents(rootOverride, "page2.txt"), sw.toString()); }
@Test public void testMultipleExtensions() throws MustacheException, IOException, ExecutionException, InterruptedException { MustacheFactory c = new DefaultMustacheFactory(root); Mustache m = c.compile("multipleextensions.html"); StringWriter sw = new StringWriter(); m.execute(sw, new Object()); assertEquals(getContents(root, "multipleextensions.txt"), sw.toString()); }
@Test public void testFollow() throws MustacheException, IOException, ExecutionException, InterruptedException { MustacheFactory c = new DefaultMustacheFactory(root); Mustache m = c.compile("follownomenu.html"); StringWriter sw = new StringWriter(); m.execute(sw, new Object()); assertEquals(getContents(root, "follownomenu.txt"), sw.toString()); }
@Test public void testPostNullLabels() throws MustacheException, IOException, ExecutionException, InterruptedException { MustacheFactory c = new DefaultMustacheFactory(root); Mustache m = c.compile("bundles.html"); StringWriter sw = new StringWriter(); Map<String, Object> scope = new HashMap<>(); scope.put("trans", BundleFunctions.newPostTranslateNullableLabel(BUNDLE, Locale.US)); // Intentionally leave off the replacement value m.execute(sw, scope); assertEquals(getContents(root, "bundles_nulllabels.txt"), sw.toString()); }
@Test public void testTranslation() throws MustacheException, IOException, ExecutionException, InterruptedException { MustacheFactory c = new DefaultMustacheFactory(root); Mustache m = c.compile("translatebundle.html"); StringWriter sw = new StringWriter(); Map<String, Object> scope = new HashMap<>(); scope.put("trans", new TranslateBundleFunction(BUNDLE, Locale.US)); m.execute(sw, scope); assertEquals(getContents(root, "translatebundle.txt"), sw.toString()); }
@Test public void testParentReplace() throws MustacheException, IOException, ExecutionException, InterruptedException { MustacheFactory c = new DefaultMustacheFactory(root); Mustache m = c.compile("replace.html"); StringWriter sw = new StringWriter(); m.execute(sw, new Object() { String replace = "false"; }); assertEquals(getContents(root, "replace.txt"), sw.toString()); }
@Test public void testInlineCommentWithinExtendCodeBlock() throws MustacheException, IOException, ExecutionException, InterruptedException { File root = getRoot("commentWithinExtendCodeBlock.html"); MustacheFactory c = new DefaultMustacheFactory(root); Mustache m = c.compile("commentWithinExtendCodeBlock.html"); StringWriter sw = new StringWriter(); m.execute(sw, Collections.emptyList()); assertEquals(getContents(root, "commentWithinExtendCodeBlock.txt"), sw.toString()); }
@Test public void testDiffExt() throws IOException { MustacheFactory c = new DefaultMustacheFactory(root); Mustache m = c.compile("diffext.mustache.parent"); StringWriter sw = new StringWriter(); m.execute(sw, new Object() {}); assertEquals(getContents(root, "diffext.txt"), sw.toString()); }
public void testSimpleWithMap() throws MustacheException, IOException, ExecutionException, InterruptedException { StringWriter sw = execute("simple.html", new HashMap<String, Object>() {{ put("name", "Chris"); put("value", 10000); put("taxed_value", 6000); put("in_ca", true); }}); assertEquals(getContents(root, "simple.txt"), sw.toString()); }