From 3aec1d42ccac9a4fcbf53e10c5e5e0f6a31e8e7c Mon Sep 17 00:00:00 2001 From: Edgar Espina Date: Sun, 10 Jun 2018 21:30:29 -0300 Subject: [PATCH] Add test for missing @partial-block ref #634 --- .../github/jknack/handlebars/Handlebars.java | 9 ++++-- .../jknack/handlebars/issues/Issue634.java | 28 +++++++++++++++++++ 2 files changed, 34 insertions(+), 3 deletions(-) create mode 100644 handlebars/src/test/java/com/github/jknack/handlebars/issues/Issue634.java diff --git a/handlebars/src/main/java/com/github/jknack/handlebars/Handlebars.java b/handlebars/src/main/java/com/github/jknack/handlebars/Handlebars.java index 797bbdd58..ee215a899 100644 --- a/handlebars/src/main/java/com/github/jknack/handlebars/Handlebars.java +++ b/handlebars/src/main/java/com/github/jknack/handlebars/Handlebars.java @@ -1254,7 +1254,8 @@ public Handlebars parentScopeResolution(final boolean parentScopeResolution) { *
    *     {{> @partial-block}}
    * 
- * Attention: If this is set to true, Handlebars works *much* slower! + * Attention: If this is set to true, Handlebars works *much* slower! while rendering + * partial blocks. Default is: true for compatibility reasons. * * @return If true partial blocks will be evaluated before the partial will be rendered * to allow inline block side effects. @@ -1271,7 +1272,8 @@ public boolean preEvaluatePartialBlocks() { *
    *     {{> @partial-block}}
    * 
- * Attention: If this is set to true, Handlebars works *much* slower! + * Attention: If this is set to true, Handlebars works *much* slower! while rendering + * partial blocks. Default is: true for compatibility reasons. * * @param preEvaluatePartialBlocks If true partial blocks will be evaluated before the * partial will be rendered to allow inline block side @@ -1290,7 +1292,8 @@ public void setPreEvaluatePartialBlocks(final boolean preEvaluatePartialBlocks) *
    *     {{> @partial-block}}
    * 
- * Attention: If this is set to true, Handlebars works *much* slower! + * Attention: If this is set to true, Handlebars works *much* slower! while rendering + * partial blocks. Default is: true for compatibility reasons. * * @param preEvaluatePartialBlocks If true partial blocks will be evaluated before the * partial will be rendered to allow inline block side diff --git a/handlebars/src/test/java/com/github/jknack/handlebars/issues/Issue634.java b/handlebars/src/test/java/com/github/jknack/handlebars/issues/Issue634.java new file mode 100644 index 000000000..0fa47d632 --- /dev/null +++ b/handlebars/src/test/java/com/github/jknack/handlebars/issues/Issue634.java @@ -0,0 +1,28 @@ +package com.github.jknack.handlebars.issues; + +import com.github.jknack.handlebars.HandlebarsException; +import com.github.jknack.handlebars.v4Test; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; +import org.junit.Test; + +public class Issue634 extends v4Test { + + @Test + public void shouldThrowHandlebarsExceptionWhenPartialBlockIsMissing() throws Exception { + try { + shouldCompileTo("{{> my-partial}}", + $("partials", $("my-partial", "Hello {{> @partial-block}}")), null); + fail("Must throw HandlebarsException"); + } catch (HandlebarsException x) { + assertTrue(x.getMessage().contains("does not provide a @partial-block")); + } + } + + @Test + public void shouldNotThrowHandlebarsException() throws Exception { + shouldCompileTo("{{#> my-partial}}634{{/my-partial}}", + $("partials", $("my-partial", "Hello {{> @partial-block}}")), "Hello 634"); + } + +}