freemarker-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ddek...@apache.org
Subject [1/3] incubator-freemarker git commit: Added tests for 3 layer autoIncludes
Date Wed, 08 Jun 2016 21:09:21 GMT
Repository: incubator-freemarker
Updated Branches:
  refs/heads/2.3-gae 428b3744c -> 6c335728f


Added tests for 3 layer autoIncludes


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

Branch: refs/heads/2.3-gae
Commit: aea8cb75f05bd5be99bf331e4484b9314b782541
Parents: 428b374
Author: ddekany <ddekany@apache.org>
Authored: Wed Jun 8 20:12:27 2016 +0200
Committer: ddekany <ddekany@apache.org>
Committed: Wed Jun 8 20:12:27 2016 +0200

----------------------------------------------------------------------
 .../core/AutoImportAndIncludeTest.java          | 101 +++++++++++++++++++
 1 file changed, 101 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/aea8cb75/src/test/java/freemarker/core/AutoImportAndIncludeTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/freemarker/core/AutoImportAndIncludeTest.java b/src/test/java/freemarker/core/AutoImportAndIncludeTest.java
index ea50078..91faa4b 100644
--- a/src/test/java/freemarker/core/AutoImportAndIncludeTest.java
+++ b/src/test/java/freemarker/core/AutoImportAndIncludeTest.java
@@ -109,6 +109,107 @@ public class AutoImportAndIncludeTest extends TemplateTest {
         }
     }
 
+    @Test
+    public void test3LayerIncludesNoClashes() throws Exception {
+        Configuration cfg = getConfiguration();
+        cfg.addAutoInclude("t1.ftl");
+
+        TemplateConfiguration tc = new TemplateConfiguration();
+        tc.addAutoInclude("t2.ftl");
+        cfg.setTemplateConfigurations(
+                new ConditionalTemplateConfigurationFactory(new FileNameGlobMatcher("main.ftl"),
tc));
+
+        {
+            Template t = cfg.getTemplate("main.ftl");
+            StringWriter sw = new StringWriter();
+            Environment env = t.createProcessingEnvironment(null, sw);
+            env.addAutoInclude("t3.ftl");
+    
+            env.process();
+            assertEquals("T1;T2;T3;In main: t1;t2;t3;", sw.toString());
+        }
+
+        {
+            Template t = cfg.getTemplate("main.ftl");
+            StringWriter sw = new StringWriter();
+            Environment env = t.createProcessingEnvironment(null, sw);
+    
+            env.process();
+            assertEquals("T1;T2;In main: t1;t2;", sw.toString());
+        }
+        
+        {
+            Template t = cfg.getTemplate("main2.ftl");
+            StringWriter sw = new StringWriter();
+            Environment env = t.createProcessingEnvironment(null, sw);
+            env.addAutoInclude("t3.ftl");
+    
+            env.process();
+            assertEquals("T1;T3;In main2: t1;t3;", sw.toString());
+        }
+        
+        cfg.removeAutoInclude("t1.ftl");
+        
+        {
+            Template t = cfg.getTemplate("main.ftl");
+            StringWriter sw = new StringWriter();
+            Environment env = t.createProcessingEnvironment(null, sw);
+            env.addAutoInclude("t3.ftl");
+    
+            env.process();
+            assertEquals("T2;T3;In main: t2;t3;", sw.toString());
+        }
+    }
+    
+    @Test
+    public void test3LayerIncludesNoClashes2() throws Exception {
+        Configuration cfg = getConfiguration();
+        cfg.addAutoInclude("t1.ftl");
+        cfg.addAutoInclude("t2.ftl");
+        cfg.addAutoInclude("t3.ftl");
+
+        TemplateConfiguration tc = new TemplateConfiguration();
+        tc.addAutoInclude("t2.ftl");
+        cfg.setTemplateConfigurations(
+                new ConditionalTemplateConfigurationFactory(new FileNameGlobMatcher("main.ftl"),
tc));
+
+        {
+            Template t = cfg.getTemplate("main.ftl");
+            StringWriter sw = new StringWriter();
+            Environment env = t.createProcessingEnvironment(null, sw);
+            env.addAutoInclude("t3.ftl");
+    
+            env.process();
+            assertEquals("T1;T2;T3;T2;T3;In main: t1;t2;t3;t2;t3;", sw.toString());
+        }
+    }
+
+    @Test
+    public void test3LayerIncludesClashes() throws Exception {
+        Configuration cfg = getConfiguration();
+        cfg.addAutoInclude("t1.ftl");
+        cfg.addAutoInclude("t3.ftl");
+        cfg.addAutoInclude("t2.ftl");
+        cfg.addAutoInclude("t3.ftl");
+
+        TemplateConfiguration tc = new TemplateConfiguration();
+        tc.addAutoInclude("t2.ftl");
+        tc.addAutoInclude("t2.ftl");
+        cfg.setTemplateConfigurations(
+                new ConditionalTemplateConfigurationFactory(new FileNameGlobMatcher("main.ftl"),
tc));
+
+        {
+            Template t = cfg.getTemplate("main.ftl");
+            StringWriter sw = new StringWriter();
+            Environment env = t.createProcessingEnvironment(null, sw);
+            env.addAutoInclude("t3.ftl");
+            env.addAutoInclude("t3.ftl");
+    
+            env.process();
+            assertEquals("T1;T2;T3;T2;T3;In main: t1;t2;t3;t2;t3;", sw.toString());
+        }
+    }
+    
     @Override
     protected Configuration createConfiguration() throws Exception {
         Configuration cfg = new Configuration(Configuration.VERSION_2_3_24);


Mime
View raw message