Repository: incubator-freemarker Updated Branches: refs/heads/2.3-gae 0df2c1878 -> 21219f611
get_optional_template message typos and test improvements Project: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/commit/21219f61 Tree: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/tree/21219f61 Diff: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/diff/21219f61 Branch: refs/heads/2.3-gae Commit: 21219f6116f75856565e2e9cef51d217fc863eb5 Parents: 0df2c18 Author: ddekany <ddek...@apache.org> Authored: Fri Mar 2 13:03:30 2018 +0100 Committer: ddekany <ddek...@apache.org> Committed: Fri Mar 2 13:03:30 2018 +0100 ---------------------------------------------------------------------- .../freemarker/core/GetOptionalTemplateMethod.java | 4 ++-- .../java/freemarker/core/GetOptionalTemplateTest.java | 14 ++++++++++---- 2 files changed, 12 insertions(+), 6 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/21219f61/src/main/java/freemarker/core/GetOptionalTemplateMethod.java ---------------------------------------------------------------------- diff --git a/src/main/java/freemarker/core/GetOptionalTemplateMethod.java b/src/main/java/freemarker/core/GetOptionalTemplateMethod.java index 090341b..c6ba7f3 100644 --- a/src/main/java/freemarker/core/GetOptionalTemplateMethod.java +++ b/src/main/java/freemarker/core/GetOptionalTemplateMethod.java @@ -143,7 +143,7 @@ class GetOptionalTemplateMethod implements TemplateMethodModelEx { SimpleHash result = new SimpleHash(env.getObjectWrapper()); result.put(RESULT_EXISTS, template != null); - // If the template is missing, result.include and such will be missing to, so that a default can be + // If the template is missing, result.include and such will be missing too, so that a default can be // conveniently provided like in <@optTemp.include!myDefaultMacro />. if (template != null) { result.put(RESULT_INCLUDE, new TemplateDirectiveModel() { @@ -156,7 +156,7 @@ class GetOptionalTemplateMethod implements TemplateMethodModelEx { throw new TemplateException("This directive supports no loop variables.", env); } if (body != null) { - throw new TemplateException("This directive supports no nested conetnt.", env); + throw new TemplateException("This directive supports no nested content.", env); } env.include(template); http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/21219f61/src/test/java/freemarker/core/GetOptionalTemplateTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/freemarker/core/GetOptionalTemplateTest.java b/src/test/java/freemarker/core/GetOptionalTemplateTest.java index 4ceb3e4..68ef84d 100644 --- a/src/test/java/freemarker/core/GetOptionalTemplateTest.java +++ b/src/test/java/freemarker/core/GetOptionalTemplateTest.java @@ -110,16 +110,16 @@ public class GetOptionalTemplateTest extends TemplateTest { public void testRelativeAndAbsolutePath() throws Exception { addTemplate("lib/inc.ftl", "included"); - addTemplate("test1.ftl", "<#include 'lib/inc.ftl'>"); + addTemplate("test1.ftl", "<@.getOptionalTemplate('lib/inc.ftl').include />"); assertOutputForNamed("test1.ftl", "included"); - addTemplate("lib/test2.ftl", "<#include '/lib/inc.ftl'>"); + addTemplate("lib/test2.ftl", "<@.getOptionalTemplate('/lib/inc.ftl').include />"); assertOutputForNamed("lib/test2.ftl", "included"); - addTemplate("lib/test3.ftl", "<#include 'inc.ftl'>"); + addTemplate("lib/test3.ftl", "<@.getOptionalTemplate('inc.ftl').include />"); assertOutputForNamed("lib/test3.ftl", "included"); - addTemplate("sub/test4.ftl", "<#include '../lib/inc.ftl'>"); + addTemplate("sub/test4.ftl", "<@.getOptionalTemplate('../lib/inc.ftl').include />"); assertOutputForNamed("sub/test4.ftl", "included"); } @@ -174,6 +174,12 @@ public class GetOptionalTemplateTest extends TemplateTest { "#2", "parse", "number", "boolean"); assertErrorContains("<#assign t = .getOptionalTemplate('x', { 'encoding': 1 })>", "#2", "encoding", "number", "string"); + + addTemplate("inc.ftl", "Exists..."); + assertErrorContains("<@.getOptionalTemplate('inc.ftl').include x=1 />", "no parameters"); + assertErrorContains("<@.getOptionalTemplate('inc.ftl').include>x</@>", "no nested content"); + assertErrorContains("<@.getOptionalTemplate('inc.ftl').include; x />", "no loop variables"); + assertErrorContains("<#assign x = .getOptionalTemplate('inc.ftl').import(1)>", "no parameters"); } }