freemarker-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ddek...@apache.org
Subject [1/5] incubator-freemarker git commit: (Less confusing method name in a parser error message test.)
Date Mon, 26 Mar 2018 19:37:18 GMT
Repository: incubator-freemarker
Updated Branches:
  refs/heads/2.3 17480993a -> 5d3d608ae


(Less confusing method name in a parser error message test.)


Project: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/commit/6c292257
Tree: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/tree/6c292257
Diff: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/diff/6c292257

Branch: refs/heads/2.3
Commit: 6c2922579c3882b38c7c963d085e468a1a780e1c
Parents: 67a2ebd
Author: ddekany <ddekany@apache.org>
Authored: Sat Mar 24 09:50:04 2018 +0100
Committer: ddekany <ddekany@apache.org>
Committed: Sat Mar 24 09:50:04 2018 +0100

----------------------------------------------------------------------
 .../core/ParsingErrorMessagesTest.java          | 71 +++++++++++---------
 1 file changed, 38 insertions(+), 33 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/6c292257/src/test/java/freemarker/core/ParsingErrorMessagesTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/freemarker/core/ParsingErrorMessagesTest.java b/src/test/java/freemarker/core/ParsingErrorMessagesTest.java
index 0081662..bea6c97 100644
--- a/src/test/java/freemarker/core/ParsingErrorMessagesTest.java
+++ b/src/test/java/freemarker/core/ParsingErrorMessagesTest.java
@@ -38,62 +38,67 @@ public class ParsingErrorMessagesTest extends TemplateTest {
 
     @Test
     public void testNeedlessInterpolation() {
-        assertErrorContains("<#if ${x} == 3></#if>", "instead of ${");
-        assertErrorContains("<#if ${x == 3}></#if>", "instead of ${");
-        assertErrorContains("<@foo ${x == 3} />", "instead of ${");
+        assertErrorContainsAS("<#if ${x} == 3></#if>", "instead of ${");
+        assertErrorContainsAS("<#if ${x == 3}></#if>", "instead of ${");
+        assertErrorContainsAS("<@foo ${x == 3} />", "instead of ${");
+        getConfiguration().setInterpolationSyntax(Configuration.SQUARE_BRACKET_INTERPOLATION_SYNTAX);
     }
 
     @Test
     public void testWrongDirectiveNames() {
-        assertErrorContains("<#foo />", "nknown directive", "#foo");
-        assertErrorContains("<#set x = 1 />", "nknown directive", "#set", "#assign");
-        assertErrorContains("<#iterator></#iterator>", "nknown directive", "#iterator",
"#list");
+        assertErrorContainsAS("<#foo />", "nknown directive", "#foo");
+        assertErrorContainsAS("<#set x = 1 />", "nknown directive", "#set", "#assign");
+        assertErrorContainsAS("<#iterator></#iterator>", "nknown directive",
"#iterator", "#list");
     }
 
     @Test
     public void testBug402() {
-        assertErrorContains("<#list 1..i as k>${k}<#list>", "existing directive",
"malformed", "#list");
-        assertErrorContains("<#assign>", "existing directive", "malformed", "#assign");
-        assertErrorContains("</#if x>", "existing directive", "malformed", "#if");
-        assertErrorContains("<#compress x>", "existing directive", "malformed", "#compress");
+        assertErrorContainsAS("<#list 1..i as k>${k}<#list>", "existing directive",
"malformed", "#list");
+        assertErrorContainsAS("<#assign>", "existing directive", "malformed", "#assign");
+        assertErrorContainsAS("</#if x>", "existing directive", "malformed", "#if");
+        assertErrorContainsAS("<#compress x>", "existing directive", "malformed", "#compress");
     }
 
     @Test
     public void testUnclosedDirectives() {
-        assertErrorContains("<#macro x>", "#macro", "unclosed");
-        assertErrorContains("<#macro x></#function>", "macro end tag");
-        assertErrorContains("<#function x>", "#macro", "unclosed");
-        assertErrorContains("<#function x></#macro>", "function end tag");
-        assertErrorContains("<#assign x>", "#assign", "unclosed");
-        assertErrorContains("<#macro m><#local x>", "#local", "unclosed");
-        assertErrorContains("<#global x>", "#global", "unclosed");
-        assertErrorContains("<@foo>", "@...", "unclosed");
-        assertErrorContains("<#list xs as x>", "#list", "unclosed");
-        assertErrorContains("<#list xs as x><#if x>", "#if", "unclosed");
-        assertErrorContains("<#list xs as x><#if x><#if q><#else>",
"#if", "unclosed");
-        assertErrorContains("<#list xs as x><#if x><#if q><#else><#macro
x>qwe", "#macro", "unclosed");
-        assertErrorContains("${(blah", "\"(\"", "unclosed");
-        assertErrorContains("${blah", "\"{\"", "unclosed");
+        assertErrorContainsAS("<#macro x>", "#macro", "unclosed");
+        assertErrorContainsAS("<#macro x></#function>", "macro end tag");
+        assertErrorContainsAS("<#function x>", "#macro", "unclosed");
+        assertErrorContainsAS("<#function x></#macro>", "function end tag");
+        assertErrorContainsAS("<#assign x>", "#assign", "unclosed");
+        assertErrorContainsAS("<#macro m><#local x>", "#local", "unclosed");
+        assertErrorContainsAS("<#global x>", "#global", "unclosed");
+        assertErrorContainsAS("<@foo>", "@...", "unclosed");
+        assertErrorContainsAS("<#list xs as x>", "#list", "unclosed");
+        assertErrorContainsAS("<#list xs as x><#if x>", "#if", "unclosed");
+        assertErrorContainsAS("<#list xs as x><#if x><#if q><#else>",
"#if", "unclosed");
+        assertErrorContainsAS("<#list xs as x><#if x><#if q><#else><#macro
x>qwe", "#macro", "unclosed");
+        assertErrorContainsAS("${(blah", "\"(\"", "unclosed");
+        assertErrorContainsAS("${blah", "\"{\"", "unclosed");
     }
     
     @Test
     public void testInterpolatingClosingsErrors() throws Exception {
-        assertErrorContains("<#ftl>${x", "unclosed");
-        assertErrorContains("<#assign x = x}>", "\"}\"", "open");
+        assertErrorContainsAS("<#ftl>${x", "unclosed");
+        assertErrorContainsAS("<#assign x = x}>", "\"}\"", "open");
         assertOutput("<#assign x = '${x'>", ""); // Legacy glitch... should fail in
theory.
         
         for (int syntax : new int[] { LEGACY_INTERPOLATION_SYNTAX, DOLLAR_INTERPOLATION_SYNTAX
}) {
             getConfiguration().setInterpolationSyntax(syntax);
-            assertErrorContains("<#ftl>${'x']", "\"]\"", "open");
-            super.assertErrorContains("<#ftl>${'x'>", "end of file");
-            super.assertErrorContains("[#ftl]${'x'>", "end of file");
+            assertErrorContainsAS("<#ftl>${'x']", "\"]\"", "open");
+            assertErrorContains("<#ftl>${'x'>", "end of file");
+            assertErrorContains("[#ftl]${'x'>", "end of file");
         }
     }
     
-    protected Throwable assertErrorContains(String ftl, String... expectedSubstrings) {
-        super.assertErrorContains(ftl, expectedSubstrings);
-        ftl = ftl.replace('<', '[').replace('>', ']');
-        return super.assertErrorContains(ftl, expectedSubstrings);
+    /**
+     * "assertErrorContains" with both angle bracket and square bracket tag syntax, by converting
the input tag syntax.
+     * Beware, it uses primitive search-and-replace.
+     */
+    protected Throwable assertErrorContainsAS(String angleBracketsFtl, String... expectedSubstrings)
{
+        assertErrorContains(angleBracketsFtl, expectedSubstrings);
+        angleBracketsFtl = angleBracketsFtl.replace('<', '[').replace('>', ']');
+        return assertErrorContains(angleBracketsFtl, expectedSubstrings);
     }
 
 }


Mime
View raw message