Repository: incubator-freemarker
Updated Branches:
  refs/heads/2.3-gae ca1ecf78e -> eb6781b44


Changed Configuration.xxx_INTERPOLATION_SYNTAX int values so that they don't 
overlap with ..._TAG_SYNTAX values. Also, added test case to ConfigurationTest 
for tag_syntax, fixing incorrect error message along the way.


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

Branch: refs/heads/2.3-gae
Commit: eb6781b4444d774c536f3da235972f1c34cd68bd
Parents: ca1ecf7
Author: ddekany <ddek...@apache.org>
Authored: Fri Mar 16 18:46:11 2018 +0100
Committer: ddekany <ddek...@apache.org>
Committed: Fri Mar 16 18:46:11 2018 +0100

----------------------------------------------------------------------
 .../java/freemarker/template/Configuration.java |  6 +--
 .../java/freemarker/template/_TemplateAPI.java  |  4 +-
 .../freemarker/template/ConfigurationTest.java  | 44 +++++++++++++++++++-
 3 files changed, 48 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/eb6781b4/src/main/java/freemarker/template/Configuration.java
----------------------------------------------------------------------
diff --git a/src/main/java/freemarker/template/Configuration.java 
b/src/main/java/freemarker/template/Configuration.java
index 34b055e..53fcd49 100644
--- a/src/main/java/freemarker/template/Configuration.java
+++ b/src/main/java/freemarker/template/Configuration.java
@@ -381,11 +381,11 @@ public class Configuration extends Configurable 
implements Cloneable, ParserConf
     public static final int SQUARE_BRACKET_TAG_SYNTAX = 2;
 
     /** <code>${expression}</code> and the deprecated <code>#{expression; 
numFormat}</code> @since 2.3.28 */
-    public static final int LEGACY_INTERPOLATION_SYNTAX = 0;
+    public static final int LEGACY_INTERPOLATION_SYNTAX = 20;
     /** <code>${expression}</code> only (not <code>#{expression; 
numFormat}</code>) @since 2.3.28 */
-    public static final int DOLLAR_INTERPOLATION_SYNTAX = 1;
+    public static final int DOLLAR_INTERPOLATION_SYNTAX = 21;
     /** <code>[=expression]</code> @since 2.3.28 */
-    public static final int SQUARE_BRACKET_INTERPOLATION_SYNTAX = 2;
+    public static final int SQUARE_BRACKET_INTERPOLATION_SYNTAX = 22;
     
     public static final int AUTO_DETECT_NAMING_CONVENTION = 10;
     public static final int LEGACY_NAMING_CONVENTION = 11;

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/eb6781b4/src/main/java/freemarker/template/_TemplateAPI.java
----------------------------------------------------------------------
diff --git a/src/main/java/freemarker/template/_TemplateAPI.java 
b/src/main/java/freemarker/template/_TemplateAPI.java
index 9b2c22d..124677a 100644
--- a/src/main/java/freemarker/template/_TemplateAPI.java
+++ b/src/main/java/freemarker/template/_TemplateAPI.java
@@ -154,8 +154,8 @@ public class _TemplateAPI {
             && tagSyntax != Configuration.SQUARE_BRACKET_TAG_SYNTAX
             && tagSyntax != Configuration.ANGLE_BRACKET_TAG_SYNTAX) {
             throw new IllegalArgumentException("\"tag_syntax\" can only be set 
to one of these: "
-                    + "Configuration.AUTO_DETECT_TAG_SYNTAX, 
Configuration.ANGLE_BRACKET_SYNTAX, "
-                    + "or Configuration.SQUARE_BRACKET_SYNTAX");
+                    + "Configuration.AUTO_DETECT_TAG_SYNTAX, 
Configuration.ANGLE_BRACKET_TAG_SYNTAX, "
+                    + "or Configuration.SQUARE_BRACKET_TAG_SYNTAX");
         }
     }
 

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/eb6781b4/src/test/java/freemarker/template/ConfigurationTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/freemarker/template/ConfigurationTest.java 
b/src/test/java/freemarker/template/ConfigurationTest.java
index fa6b508..72c1291 100644
--- a/src/test/java/freemarker/template/ConfigurationTest.java
+++ b/src/test/java/freemarker/template/ConfigurationTest.java
@@ -1616,6 +1616,41 @@ public class ConfigurationTest extends TestCase {
         assertEquals(Configuration.AUTO_DETECT_NAMING_CONVENTION, 
cfg.getNamingConvention());
     }
 
+    public void testTagSyntaxSetting() throws TemplateException {
+        Configuration cfg = new Configuration(Configuration.VERSION_2_3_28);
+
+        // Default is "angle brackets":
+        assertEquals(Configuration.ANGLE_BRACKET_TAG_SYNTAX, 
cfg.getTagSyntax());
+
+        cfg.setSetting("tag_syntax", "angle_bracket");
+        assertEquals(Configuration.ANGLE_BRACKET_TAG_SYNTAX, 
cfg.getTagSyntax());
+        
+        cfg.setSetting("tag_syntax", "square_bracket");
+        assertEquals(Configuration.SQUARE_BRACKET_TAG_SYNTAX, 
cfg.getTagSyntax());
+        
+        cfg.setSetting("tag_syntax", "auto_detect");
+        assertEquals(Configuration.AUTO_DETECT_TAG_SYNTAX, cfg.getTagSyntax());
+        
+        // Camel case:
+        cfg.setSetting("tagSyntax", "squareBracket");
+        assertEquals(Configuration.SQUARE_BRACKET_TAG_SYNTAX, 
cfg.getTagSyntax());
+        
+        try {
+            cfg.setSetting("tag_syntax", "no_such_syntax");
+            fail();
+        } catch (TemplateException e) {
+            assertThat(e.getMessage(), containsString("no_such_syntax"));
+        }
+        
+        // Catch an oversight that's easy to do:
+        try {
+            
cfg.setTagSyntax(Configuration.SQUARE_BRACKET_INTERPOLATION_SYNTAX);
+            fail();
+        } catch (IllegalArgumentException e) {
+            assertThat(e.getMessage(), 
containsString("SQUARE_BRACKET_TAG_SYNTAX"));
+        }
+    }
+    
     public void testInterpolationSyntaxSetting() throws TemplateException {
         Configuration cfg = new Configuration(Configuration.VERSION_2_3_28);
 
@@ -1641,7 +1676,14 @@ public class ConfigurationTest extends TestCase {
         } catch (TemplateException e) {
             assertThat(e.getMessage(), containsString("no_such_syntax"));
         }
-        
+
+        // Catch an oversight that's easy to do:
+        try {
+            
cfg.setInterpolationSyntax(Configuration.SQUARE_BRACKET_TAG_SYNTAX);
+            fail();
+        } catch (IllegalArgumentException e) {
+            assertThat(e.getMessage(), 
containsString("SQUARE_BRACKET_INTERPOLATION_SYNTAX"));
+        }
     }
     
     public void testLazyImportsSetSetting() throws TemplateException {

Reply via email to