http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/8ba7883e/src/test/java/org/apache/freemarker/core/ast/HeaderParsingTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/freemarker/core/ast/HeaderParsingTest.java b/src/test/java/org/apache/freemarker/core/ast/HeaderParsingTest.java index 8e9d194..5cb4e79 100644 --- a/src/test/java/org/apache/freemarker/core/ast/HeaderParsingTest.java +++ b/src/test/java/org/apache/freemarker/core/ast/HeaderParsingTest.java @@ -28,8 +28,8 @@ import org.junit.Test; public class HeaderParsingTest extends TemplateTest { - private final Configuration cfgStripWS = new Configuration(Configuration.VERSION_2_3_21); - private final Configuration cfgNoStripWS = new Configuration(Configuration.VERSION_2_3_21); + private final Configuration cfgStripWS = new Configuration(Configuration.VERSION_3_0_0); + private final Configuration cfgNoStripWS = new Configuration(Configuration.VERSION_3_0_0); { cfgNoStripWS.setWhitespaceStripping(false); }
http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/8ba7883e/src/test/java/org/apache/freemarker/core/ast/IncludeAndImportConfigurableLayersTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/freemarker/core/ast/IncludeAndImportConfigurableLayersTest.java b/src/test/java/org/apache/freemarker/core/ast/IncludeAndImportConfigurableLayersTest.java index 06305be..b194ac8 100644 --- a/src/test/java/org/apache/freemarker/core/ast/IncludeAndImportConfigurableLayersTest.java +++ b/src/test/java/org/apache/freemarker/core/ast/IncludeAndImportConfigurableLayersTest.java @@ -24,9 +24,6 @@ import java.io.StringWriter; import org.apache.freemarker.core.Configuration; import org.apache.freemarker.core.Template; -import org.apache.freemarker.core.ast.Configurable; -import org.apache.freemarker.core.ast.Environment; -import org.apache.freemarker.core.ast.TemplateConfiguration; import org.apache.freemarker.core.templateresolver.ConditionalTemplateConfigurationFactory; import org.apache.freemarker.core.templateresolver.FileNameGlobMatcher; import org.apache.freemarker.test.TemplateTest; @@ -318,7 +315,7 @@ public class IncludeAndImportConfigurableLayersTest extends TemplateTest { @Override protected Configuration createConfiguration() throws Exception { - return new Configuration(Configuration.VERSION_2_3_24); + return new Configuration(Configuration.VERSION_3_0_0); } @Override http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/8ba7883e/src/test/java/org/apache/freemarker/core/ast/IncludeAndImportTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/freemarker/core/ast/IncludeAndImportTest.java b/src/test/java/org/apache/freemarker/core/ast/IncludeAndImportTest.java index 1681f57..dc3e266 100644 --- a/src/test/java/org/apache/freemarker/core/ast/IncludeAndImportTest.java +++ b/src/test/java/org/apache/freemarker/core/ast/IncludeAndImportTest.java @@ -31,7 +31,6 @@ import java.lang.reflect.Modifier; import org.apache.freemarker.core.Configuration; import org.apache.freemarker.core.TemplateException; import org.apache.freemarker.core.TemplateNotFoundException; -import org.apache.freemarker.core.ast.InvalidReferenceException; import org.apache.freemarker.core.ast.Environment.LazilyInitializedNamespace; import org.apache.freemarker.core.ast.Environment.Namespace; import org.apache.freemarker.core.model.WrappingTemplateModel; @@ -81,20 +80,14 @@ public class IncludeAndImportTest extends TemplateTest { + "<#import 'lib1.ftl' as lib1> ${.main.lib1???c} ${.globals.lib1???c}"; String expectedOut = "false false true true"; assertOutput(ftl, expectedOut); - // No difference: - getConfiguration().setIncompatibleImprovements(Configuration.VERSION_2_3_24); - assertOutput(ftl, expectedOut); } @Test public void importInMainCreatesGlobalBugfix() throws IOException, TemplateException { - // An import in the main namespace should create a global variable, but there's a bug where that doesn't happen - // if the imported library was already initialized elsewhere. + // An import in the main namespace should create a global variable, even if the imported library was already + // initialized elsewhere. String ftl = "<#import 'lib3ImportsLib1.ftl' as lib3>${lib1Cnt} ${.main.lib1???c} ${.globals.lib1???c}, " + "<#import 'lib1.ftl' as lib1>${lib1Cnt} ${.main.lib1???c} ${.globals.lib1???c}"; - assertOutput(ftl, "1 false false, 1 true false"); - // Activate bugfix: - getConfiguration().setIncompatibleImprovements(Configuration.VERSION_2_3_24); assertOutput(ftl, "1 false false, 1 true true"); } http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/8ba7883e/src/test/java/org/apache/freemarker/core/ast/IteratorIssuesTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/freemarker/core/ast/IteratorIssuesTest.java b/src/test/java/org/apache/freemarker/core/ast/IteratorIssuesTest.java index 0dd8b01..10b774f 100644 --- a/src/test/java/org/apache/freemarker/core/ast/IteratorIssuesTest.java +++ b/src/test/java/org/apache/freemarker/core/ast/IteratorIssuesTest.java @@ -38,81 +38,35 @@ public class IteratorIssuesTest extends TemplateTest { private static final String FTL_LIST_AND_HAS_CONTENT = "<#list it as i>${i}${it?hasContent?then('+', '-')}</#list>"; - private static final String OUT_LIST_AND_HAS_CONTENT_BW_WRONG = "a+b+c+"; private static final String OUT_LIST_AND_HAS_CONTENT_BW_GOOD = "a+b+c-"; @Test - public void testHasContentAndListDOW230() throws Exception { - addToDataModel("it", getDOW230().wrap(getAbcIt())); + public void testHasContentAndListDOW() throws Exception { + addToDataModel("it", getDOW300().wrap(getAbcIt())); assertOutput(FTL_HAS_CONTENT_AND_LIST, OUT_HAS_CONTENT_AND_LIST_ABC); - addToDataModel("it", getDOW230().wrap(getEmptyIt())); + addToDataModel("it", getDOW300().wrap(getEmptyIt())); assertOutput(FTL_HAS_CONTENT_AND_LIST, OUT_HAS_CONTENT_AND_LIST_EMPTY); } @Test - public void testHasContentAndListDOW2323() throws Exception { - addToDataModel("it", getDOW2323().wrap(getAbcIt())); + public void testHasContentAndListBW() throws Exception { + addToDataModel("it", getBW300().wrap(getAbcIt())); assertOutput(FTL_HAS_CONTENT_AND_LIST, OUT_HAS_CONTENT_AND_LIST_ABC); - addToDataModel("it", getDOW2323().wrap(getEmptyIt())); - assertOutput(FTL_HAS_CONTENT_AND_LIST, OUT_HAS_CONTENT_AND_LIST_EMPTY); - } - - @Test - public void testHasContentAndListBW230() throws Exception { - addToDataModel("it", getBW230().wrap(getAbcIt())); - assertOutput(FTL_HAS_CONTENT_AND_LIST, OUT_HAS_CONTENT_AND_LIST_ABC); - - addToDataModel("it", getBW230().wrap(getEmptyIt())); - assertOutput(FTL_HAS_CONTENT_AND_LIST, ""); - } - - @Test - public void testHasContentAndListBW2323() throws Exception { - addToDataModel("it", getBW2323().wrap(getAbcIt())); - assertOutput(FTL_HAS_CONTENT_AND_LIST, OUT_HAS_CONTENT_AND_LIST_ABC); - - addToDataModel("it", getBW230().wrap(getEmptyIt())); - assertOutput(FTL_HAS_CONTENT_AND_LIST, ""); - } - - @Test - public void testHasContentAndListBW2324() throws Exception { - addToDataModel("it", getBW2324().wrap(getAbcIt())); - assertOutput(FTL_HAS_CONTENT_AND_LIST, OUT_HAS_CONTENT_AND_LIST_ABC); - - addToDataModel("it", getBW2324().wrap(getEmptyIt())); + addToDataModel("it", getBW300().wrap(getEmptyIt())); assertOutput(FTL_HAS_CONTENT_AND_LIST, OUT_HAS_CONTENT_AND_LIST_EMPTY); } @Test - public void testListAndHasContentDOW230() throws Exception { - addToDataModel("it", getDOW230().wrap(getAbcIt())); + public void testListAndHasContentDOW() throws Exception { + addToDataModel("it", getDOW300().wrap(getAbcIt())); assertErrorContains(FTL_LIST_AND_HAS_CONTENT, "can be listed only once"); } @Test - public void testListAndHasContentDOW2323() throws Exception { - addToDataModel("it", getDOW2323().wrap(getAbcIt())); - assertErrorContains(FTL_LIST_AND_HAS_CONTENT, "can be listed only once"); - } - - @Test - public void testListAndHasContentBW230() throws Exception { - addToDataModel("it", getBW230().wrap(getAbcIt())); - assertOutput(FTL_LIST_AND_HAS_CONTENT, OUT_LIST_AND_HAS_CONTENT_BW_WRONG); - } - - @Test - public void testListAndHasContentBW2323() throws Exception { - addToDataModel("it", getBW2323().wrap(getAbcIt())); - assertOutput(FTL_LIST_AND_HAS_CONTENT, OUT_LIST_AND_HAS_CONTENT_BW_WRONG); - } - - @Test - public void testListAndHasContentBW2324() throws Exception { - addToDataModel("it", getBW2324().wrap(getAbcIt())); + public void testListAndHasContentBW() throws Exception { + addToDataModel("it", getBW300().wrap(getAbcIt())); assertOutput(FTL_LIST_AND_HAS_CONTENT, OUT_LIST_AND_HAS_CONTENT_BW_GOOD); } @@ -124,24 +78,12 @@ public class IteratorIssuesTest extends TemplateTest { return Arrays.asList(new String[] { }).iterator(); } - private DefaultObjectWrapper getDOW230() { - return new DefaultObjectWrapperBuilder(Configuration.VERSION_2_3_0).build(); - } - - private DefaultObjectWrapper getDOW2323() { - return new DefaultObjectWrapperBuilder(Configuration.VERSION_2_3_23).build(); - } - - private BeansWrapper getBW230() { - return new BeansWrapperBuilder(Configuration.VERSION_2_3_0).build(); - } - - private BeansWrapper getBW2323() { - return new BeansWrapperBuilder(Configuration.VERSION_2_3_23).build(); + private DefaultObjectWrapper getDOW300() { + return new DefaultObjectWrapperBuilder(Configuration.VERSION_3_0_0).build(); } - private BeansWrapper getBW2324() { - return new BeansWrapperBuilder(Configuration.VERSION_2_3_24).build(); + private BeansWrapper getBW300() { + return new BeansWrapperBuilder(Configuration.VERSION_3_0_0).build(); } } http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/8ba7883e/src/test/java/org/apache/freemarker/core/ast/NumberFormatTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/freemarker/core/ast/NumberFormatTest.java b/src/test/java/org/apache/freemarker/core/ast/NumberFormatTest.java index 3699d83..12da0cd 100644 --- a/src/test/java/org/apache/freemarker/core/ast/NumberFormatTest.java +++ b/src/test/java/org/apache/freemarker/core/ast/NumberFormatTest.java @@ -18,8 +18,11 @@ */ package org.apache.freemarker.core.ast; -import static org.hamcrest.Matchers.*; -import static org.junit.Assert.*; +import static org.hamcrest.Matchers.instanceOf; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotSame; +import static org.junit.Assert.assertSame; +import static org.junit.Assert.assertThat; import java.io.IOException; import java.math.BigDecimal; @@ -31,12 +34,6 @@ import java.util.Map; import org.apache.freemarker.core.Configuration; import org.apache.freemarker.core.Template; import org.apache.freemarker.core.TemplateException; -import org.apache.freemarker.core.ast.AliasTemplateNumberFormatFactory; -import org.apache.freemarker.core.ast.Environment; -import org.apache.freemarker.core.ast.TemplateConfiguration; -import org.apache.freemarker.core.ast.TemplateNumberFormat; -import org.apache.freemarker.core.ast.TemplateNumberFormatFactory; -import org.apache.freemarker.core.ast.UndefinedCustomFormatException; import org.apache.freemarker.core.model.TemplateDirectiveBody; import org.apache.freemarker.core.model.TemplateDirectiveModel; import org.apache.freemarker.core.model.TemplateModel; @@ -57,7 +54,6 @@ public class NumberFormatTest extends TemplateTest { @Before public void setup() { Configuration cfg = getConfiguration(); - cfg.setIncompatibleImprovements(Configuration.VERSION_2_3_24); cfg.setLocale(Locale.US); cfg.setCustomNumberFormats(ImmutableMap.of( @@ -216,22 +212,17 @@ public class NumberFormatTest extends TemplateTest { } @Test - public void testIcIAndEscaping() throws Exception { + public void testAtPrefix() throws Exception { Configuration cfg = getConfiguration(); - testIcIAndEscapingWhenCustFormsAccepted(cfg); - cfg.setIncompatibleImprovements(Configuration.VERSION_2_3_23); - testIcIAndEscapingWhenCustFormsAccepted(cfg); - - cfg.setCustomNumberFormats(Collections.<String, TemplateNumberFormatFactory>emptyMap()); cfg.setNumberFormat("@hex"); - assertOutput("${10}", "@hex10"); + assertOutput("${10}", "a"); cfg.setNumberFormat("'@'0"); assertOutput("${10}", "@10"); cfg.setNumberFormat("@@0"); assertOutput("${10}", "@@10"); - cfg.setIncompatibleImprovements(Configuration.VERSION_2_3_24); + cfg.setCustomNumberFormats(Collections.<String, TemplateNumberFormatFactory>emptyMap()); cfg.setNumberFormat("@hex"); assertErrorContains("${10}", "custom", "\"hex\""); cfg.setNumberFormat("'@'0"); @@ -240,15 +231,6 @@ public class NumberFormatTest extends TemplateTest { assertOutput("${10}", "@@10"); } - protected void testIcIAndEscapingWhenCustFormsAccepted(Configuration cfg) throws IOException, TemplateException { - cfg.setNumberFormat("@hex"); - assertOutput("${10}", "a"); - cfg.setNumberFormat("'@'0"); - assertOutput("${10}", "@10"); - cfg.setNumberFormat("@@0"); - assertOutput("${10}", "@@10"); - } - @Test public void testAlieses() throws Exception { Configuration cfg = getConfiguration(); http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/8ba7883e/src/test/java/org/apache/freemarker/core/ast/ObjectBuilderSettingsTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/freemarker/core/ast/ObjectBuilderSettingsTest.java b/src/test/java/org/apache/freemarker/core/ast/ObjectBuilderSettingsTest.java index 14d6a33..c041623 100644 --- a/src/test/java/org/apache/freemarker/core/ast/ObjectBuilderSettingsTest.java +++ b/src/test/java/org/apache/freemarker/core/ast/ObjectBuilderSettingsTest.java @@ -376,9 +376,9 @@ public class ObjectBuilderSettingsTest { @Test public void beansWrapperTest() throws Exception { BeansWrapper bw = (BeansWrapper) _ObjectBuilderSettingEvaluator.eval( - "BeansWrapper(2.3.21, simpleMapWrapper=true, exposeFields=true)", + "BeansWrapper(3.0.0, simpleMapWrapper=true, exposeFields=true)", ObjectWrapper.class, false, _SettingEvaluationEnvironment.getCurrent()); - assertEquals(Configuration.VERSION_2_3_21, bw.getIncompatibleImprovements()); + assertEquals(Configuration.VERSION_3_0_0, bw.getIncompatibleImprovements()); assertTrue(bw.isSimpleMapWrapper()); assertTrue(bw.isExposeFields()); } @@ -386,19 +386,20 @@ public class ObjectBuilderSettingsTest { @Test public void defaultObjectWrapperTest() throws Exception { DefaultObjectWrapper bw = (DefaultObjectWrapper) _ObjectBuilderSettingEvaluator.eval( - "DefaultObjectWrapper(2.3.21)", + "DefaultObjectWrapper(3.0.0)", ObjectWrapper.class, false, _SettingEvaluationEnvironment.getCurrent()); - assertEquals(Configuration.VERSION_2_3_21, bw.getIncompatibleImprovements()); + assertEquals(Configuration.VERSION_3_0_0, bw.getIncompatibleImprovements()); assertFalse(bw.isExposeFields()); } @Test public void configurationPropertiesTest() throws TemplateException { - final Configuration cfg = new Configuration(); + final Configuration cfg = new Configuration(Configuration.getVersion()); { Properties props = new Properties(); - props.setProperty(Configurable.OBJECT_WRAPPER_KEY, "org.apache.freemarker.core.model.impl.beans.BeansWrapper(2.3.21)"); + props.setProperty(Configurable.OBJECT_WRAPPER_KEY, + "org.apache.freemarker.core.model.impl.beans.BeansWrapper(3.0.0)"); props.setProperty(Configurable.ARITHMETIC_ENGINE_KEY, "org.apache.freemarker.core.ast.ObjectBuilderSettingsTest$DummyArithmeticEngine"); props.setProperty(Configurable.TEMPLATE_EXCEPTION_HANDLER_KEY, @@ -413,7 +414,8 @@ public class ObjectBuilderSettingsTest { cfg.setSettings(props); assertEquals(BeansWrapper.class, cfg.getObjectWrapper().getClass()); assertTrue(((WriteProtectable) cfg.getObjectWrapper()).isWriteProtected()); - assertEquals(Configuration.VERSION_2_3_21, ((BeansWrapper) cfg.getObjectWrapper()).getIncompatibleImprovements()); + assertEquals( + Configuration.VERSION_3_0_0, ((BeansWrapper) cfg.getObjectWrapper()).getIncompatibleImprovements()); assertEquals(DummyArithmeticEngine.class, cfg.getArithmeticEngine().getClass()); assertEquals(DummyTemplateExceptionHandler.class, cfg.getTemplateExceptionHandler().getClass()); assertEquals(DummyCacheStorage.class, cfg.getCacheStorage().getClass()); @@ -438,7 +440,8 @@ public class ObjectBuilderSettingsTest { assertTrue(((WriteProtectable) cfg.getObjectWrapper()).isWriteProtected()); assertEquals(1, ((DummyArithmeticEngine) cfg.getArithmeticEngine()).getX()); assertEquals(1, ((DummyTemplateExceptionHandler) cfg.getTemplateExceptionHandler()).getX()); - assertEquals(Configuration.VERSION_2_3_0, ((BeansWrapper) cfg.getObjectWrapper()).getIncompatibleImprovements()); + assertEquals(Configuration.VERSION_3_0_0, + ((BeansWrapper) cfg.getObjectWrapper()).getIncompatibleImprovements()); assertEquals(500, ((MruCacheStorage) cfg.getCacheStorage()).getSoftSizeLimit()); assertEquals(TemplateClassResolver.ALLOWS_NOTHING_RESOLVER, cfg.getNewBuiltinClassResolver()); assertEquals("utf-8", cfg.getDefaultEncoding()); @@ -454,33 +457,41 @@ public class ObjectBuilderSettingsTest { assertSame(ArithmeticEngine.BIGDECIMAL_ENGINE, cfg.getArithmeticEngine()); assertSame(TemplateExceptionHandler.RETHROW_HANDLER, cfg.getTemplateExceptionHandler()); assertTrue(((WriteProtectable) cfg.getObjectWrapper()).isWriteProtected()); - assertEquals(Configuration.VERSION_2_3_0, ((BeansWrapper) cfg.getObjectWrapper()).getIncompatibleImprovements()); + assertEquals(Configuration.VERSION_3_0_0, + ((BeansWrapper) cfg.getObjectWrapper()).getIncompatibleImprovements()); } { Properties props = new Properties(); - props.setProperty(Configurable.OBJECT_WRAPPER_KEY, "org.apache.freemarker.core.model.impl.beans.BeansWrapper"); + props.setProperty( + Configurable.OBJECT_WRAPPER_KEY, + "org.apache.freemarker.core.model.impl.beans.BeansWrapper"); cfg.setSettings(props); assertEquals(BeansWrapper.class, cfg.getObjectWrapper().getClass()); assertFalse(((WriteProtectable) cfg.getObjectWrapper()).isWriteProtected()); - assertEquals(Configuration.VERSION_2_3_0, ((BeansWrapper) cfg.getObjectWrapper()).getIncompatibleImprovements()); + assertEquals(Configuration.VERSION_3_0_0, + ((BeansWrapper) cfg.getObjectWrapper()).getIncompatibleImprovements()); } { Properties props = new Properties(); - props.setProperty(Configurable.OBJECT_WRAPPER_KEY, "DefaultObjectWrapper(2.3.19)"); + props.setProperty(Configurable.OBJECT_WRAPPER_KEY, "DefaultObjectWrapper(3.0.0)"); cfg.setSettings(props); assertEquals(DefaultObjectWrapper.class, cfg.getObjectWrapper().getClass()); assertTrue(((WriteProtectable) cfg.getObjectWrapper()).isWriteProtected()); - assertEquals(Configuration.VERSION_2_3_0, ((BeansWrapper) cfg.getObjectWrapper()).getIncompatibleImprovements()); + assertEquals( + Configuration.VERSION_3_0_0, + ((BeansWrapper) cfg.getObjectWrapper()).getIncompatibleImprovements()); } } @Test - public void timeZoneTest() throws _ObjectBuilderSettingEvaluationException, ClassNotFoundException, InstantiationException, IllegalAccessException { + public void timeZoneTest() throws _ObjectBuilderSettingEvaluationException, ClassNotFoundException, + InstantiationException, IllegalAccessException { for (String timeZoneId : new String[] { "GMT+01", "GMT", "UTC" }) { TestBean8 result = (TestBean8) _ObjectBuilderSettingEvaluator.eval( - "org.apache.freemarker.core.ast.ObjectBuilderSettingsTest$TestBean8(timeZone=TimeZone('" + timeZoneId + "'))", + "org.apache.freemarker.core.ast.ObjectBuilderSettingsTest$TestBean8(timeZone=TimeZone('" + + timeZoneId + "'))", TestBean8.class, false, new _SettingEvaluationEnvironment()); assertEquals(TimeZone.getTimeZone(timeZoneId), result.getTimeZone()); } http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/8ba7883e/src/test/java/org/apache/freemarker/core/ast/OutputFormatTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/freemarker/core/ast/OutputFormatTest.java b/src/test/java/org/apache/freemarker/core/ast/OutputFormatTest.java index 74401ac..18d3ca0 100644 --- a/src/test/java/org/apache/freemarker/core/ast/OutputFormatTest.java +++ b/src/test/java/org/apache/freemarker/core/ast/OutputFormatTest.java @@ -18,7 +18,10 @@ */ package org.apache.freemarker.core.ast; -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertSame; +import static org.junit.Assert.assertTrue; import java.io.IOException; import java.io.StringWriter; @@ -28,16 +31,6 @@ import java.util.Collections; import org.apache.freemarker.core.Configuration; import org.apache.freemarker.core.Template; import org.apache.freemarker.core.TemplateException; -import org.apache.freemarker.core.Version; -import org.apache.freemarker.core.ast.HTMLOutputFormat; -import org.apache.freemarker.core.ast.InvalidReferenceException; -import org.apache.freemarker.core.ast.OutputFormat; -import org.apache.freemarker.core.ast.ParseException; -import org.apache.freemarker.core.ast.PlainTextOutputFormat; -import org.apache.freemarker.core.ast.RTFOutputFormat; -import org.apache.freemarker.core.ast.TemplateConfiguration; -import org.apache.freemarker.core.ast.UndefinedOutputFormat; -import org.apache.freemarker.core.ast.XMLOutputFormat; import org.apache.freemarker.core.model.TemplateModelException; import org.apache.freemarker.core.templateresolver.ConditionalTemplateConfigurationFactory; import org.apache.freemarker.core.templateresolver.FileNameGlobMatcher; @@ -100,7 +93,7 @@ public class OutputFormatTest extends TemplateTest { addTemplate("tWithHeader.ftlx", "<#ftl outputFormat='HTML'>" + commonContent); Configuration cfg = getConfiguration(); - for (int setupNumber = 1; setupNumber <= 5; setupNumber++) { + for (int setupNumber = 1; setupNumber <= 3; setupNumber++) { final OutputFormat cfgOutputFormat; final OutputFormat ftlhOutputFormat; final OutputFormat ftlxOutputFormat; @@ -131,18 +124,6 @@ public class OutputFormatTest extends TemplateTest { ftlhOutputFormat = HTMLOutputFormat.INSTANCE; // can't be overidden ftlxOutputFormat = XMLOutputFormat.INSTANCE; break; - case 4: - cfg.setIncompatibleImprovements(Configuration.VERSION_2_3_23); - cfgOutputFormat = UndefinedOutputFormat.INSTANCE; - ftlhOutputFormat = XMLOutputFormat.INSTANCE; // now gets overidden - ftlxOutputFormat = UndefinedOutputFormat.INSTANCE; - break; - case 5: - cfg.setTemplateConfigurations(null); - cfgOutputFormat = UndefinedOutputFormat.INSTANCE; - ftlhOutputFormat = UndefinedOutputFormat.INSTANCE; - ftlxOutputFormat = UndefinedOutputFormat.INSTANCE; - break; default: throw new AssertionError(); } @@ -210,7 +191,7 @@ public class OutputFormatTest extends TemplateTest { cfg.setTemplateConfigurations(null); cfg.unsetOutputFormat(); - cfg.setIncompatibleImprovements(Configuration.VERSION_2_3_23); // Extensions has no effect + cfg.setRecognizeStandardFileExtensions(false); assertErrorContainsForNamed("t.ftlx", UndefinedOutputFormat.INSTANCE.getName()); cfg.setOutputFormat(HTMLOutputFormat.INSTANCE); assertOutputForNamed("t.ftlx", "' ' '"); @@ -229,7 +210,6 @@ public class OutputFormatTest extends TemplateTest { cfg.setTemplateConfigurations(null); cfg.unsetOutputFormat(); - cfg.setIncompatibleImprovements(Configuration.VERSION_2_3_24); cfg.setTemplateConfigurations(tcfHTML); assertOutputForNamed("t.ftlx", "' ' '"); // Can't override it cfg.setRecognizeStandardFileExtensions(false); @@ -261,15 +241,6 @@ public class OutputFormatTest extends TemplateTest { t.process(null, out); assertEquals("'", out.toString()); } - - cfg.setIncompatibleImprovements(Configuration.VERSION_2_3_23); - { - Template t = new Template("foo.ftlx", commonFTL, cfg); - assertSame(UndefinedOutputFormat.INSTANCE, t.getOutputFormat()); - StringWriter out = new StringWriter(); - t.process(null, out); - assertEquals("'", out.toString()); - } } @Test @@ -907,21 +878,19 @@ public class OutputFormatTest extends TemplateTest { @Test public void testBannedBIsWhenAutoEscaping() throws Exception { for (String biName : new String[] { "html", "xhtml", "rtf", "xml" }) { - for (Version ici : new Version[] { Configuration.VERSION_2_3_0, Configuration.VERSION_2_3_24 }) { - getConfiguration().setIncompatibleImprovements(ici); - - String commonFTL = "${'x'?" + biName + "}"; - assertOutput(commonFTL, "x"); - assertErrorContains("<#ftl outputFormat='HTML'>" + commonFTL, - "?" + biName, "HTML", "double-escaping"); - assertErrorContains("<#ftl outputFormat='HTML'>${'${\"x\"?" + biName + "}'}", - "?" + biName, "HTML", "double-escaping"); - assertOutput("<#ftl outputFormat='plainText'>" + commonFTL, "x"); - assertOutput("<#ftl outputFormat='HTML' autoEsc=false>" + commonFTL, "x"); - assertOutput("<#ftl outputFormat='HTML'><#noAutoEsc>" + commonFTL + "</#noAutoEsc>", "x"); - assertOutput("<#ftl outputFormat='HTML'><#outputFormat 'plainText'>" + commonFTL + "</#outputFormat>", - "x"); - } + getConfiguration().setIncompatibleImprovements(Configuration.VERSION_3_0_0); + + String commonFTL = "${'x'?" + biName + "}"; + assertOutput(commonFTL, "x"); + assertErrorContains("<#ftl outputFormat='HTML'>" + commonFTL, + "?" + biName, "HTML", "double-escaping"); + assertErrorContains("<#ftl outputFormat='HTML'>${'${\"x\"?" + biName + "}'}", + "?" + biName, "HTML", "double-escaping"); + assertOutput("<#ftl outputFormat='plainText'>" + commonFTL, "x"); + assertOutput("<#ftl outputFormat='HTML' autoEsc=false>" + commonFTL, "x"); + assertOutput("<#ftl outputFormat='HTML'><#noAutoEsc>" + commonFTL + "</#noAutoEsc>", "x"); + assertOutput("<#ftl outputFormat='HTML'><#outputFormat 'plainText'>" + commonFTL + "</#outputFormat>", + "x"); } } @@ -1033,7 +1002,7 @@ public class OutputFormatTest extends TemplateTest { @Override protected Configuration createConfiguration() throws TemplateModelException { - Configuration cfg = new Configuration(Configuration.VERSION_2_3_24); + Configuration cfg = new Configuration(Configuration.VERSION_3_0_0); TemplateConfiguration xmlTC = new TemplateConfiguration(); xmlTC.setOutputFormat(XMLOutputFormat.INSTANCE); http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/8ba7883e/src/test/java/org/apache/freemarker/core/ast/ParsingErrorMessagesTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/freemarker/core/ast/ParsingErrorMessagesTest.java b/src/test/java/org/apache/freemarker/core/ast/ParsingErrorMessagesTest.java index 916ca6b..a46b768 100644 --- a/src/test/java/org/apache/freemarker/core/ast/ParsingErrorMessagesTest.java +++ b/src/test/java/org/apache/freemarker/core/ast/ParsingErrorMessagesTest.java @@ -19,19 +19,18 @@ package org.apache.freemarker.core.ast; -import static org.junit.Assert.*; +import static org.junit.Assert.fail; import java.io.IOException; import org.apache.freemarker.core.Configuration; import org.apache.freemarker.core.Template; -import org.apache.freemarker.core.ast.ParseException; import org.apache.freemarker.core.util._StringUtil; import org.junit.Test; public class ParsingErrorMessagesTest { - private Configuration cfg = new Configuration(Configuration.VERSION_2_3_21); + private Configuration cfg = new Configuration(Configuration.VERSION_3_0_0); { cfg.setTagSyntax(Configuration.AUTO_DETECT_TAG_SYNTAX); } http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/8ba7883e/src/test/java/org/apache/freemarker/core/ast/SQLTimeZoneTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/freemarker/core/ast/SQLTimeZoneTest.java b/src/test/java/org/apache/freemarker/core/ast/SQLTimeZoneTest.java index 0b15523..e8525ff 100644 --- a/src/test/java/org/apache/freemarker/core/ast/SQLTimeZoneTest.java +++ b/src/test/java/org/apache/freemarker/core/ast/SQLTimeZoneTest.java @@ -19,7 +19,8 @@ package org.apache.freemarker.core.ast; -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; import java.sql.Time; import java.sql.Timestamp; @@ -337,7 +338,7 @@ public class SQLTimeZoneTest extends TemplateTest { @Override protected Configuration createConfiguration() { - Configuration cfg = new Configuration(Configuration.VERSION_2_3_21); + Configuration cfg = new Configuration(Configuration.VERSION_3_0_0); cfg.setLocale(Locale.US); cfg.setDateFormat("yyyy-MM-dd"); cfg.setTimeFormat("HH:mm:ss"); http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/8ba7883e/src/test/java/org/apache/freemarker/core/ast/SpecialVariableTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/freemarker/core/ast/SpecialVariableTest.java b/src/test/java/org/apache/freemarker/core/ast/SpecialVariableTest.java index 828725f..b3fb79c 100644 --- a/src/test/java/org/apache/freemarker/core/ast/SpecialVariableTest.java +++ b/src/test/java/org/apache/freemarker/core/ast/SpecialVariableTest.java @@ -19,15 +19,11 @@ package org.apache.freemarker.core.ast; -import static org.hamcrest.Matchers.*; -import static org.junit.Assert.*; +import static org.hamcrest.Matchers.greaterThan; +import static org.junit.Assert.assertThat; import org.apache.freemarker.core.Configuration; import org.apache.freemarker.core.Version; -import org.apache.freemarker.core.ast.BuiltinVariable; -import org.apache.freemarker.core.ast.HTMLOutputFormat; -import org.apache.freemarker.core.ast.PlainTextOutputFormat; -import org.apache.freemarker.core.ast.UndefinedOutputFormat; import org.apache.freemarker.test.TemplateTest; import org.junit.Test; @@ -56,7 +52,7 @@ public class SpecialVariableTest extends TemplateTest { "${.incompatibleImprovements}", getConfiguration().getIncompatibleImprovements().toString()); - getConfiguration().setIncompatibleImprovements(new Version(2, 3, 23)); + getConfiguration().setIncompatibleImprovements(new Version(3, 0, 0)); assertOutput( "${.incompatible_improvements}", getConfiguration().getIncompatibleImprovements().toString()); http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/8ba7883e/src/test/java/org/apache/freemarker/core/ast/StringLiteralInterpolationTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/freemarker/core/ast/StringLiteralInterpolationTest.java b/src/test/java/org/apache/freemarker/core/ast/StringLiteralInterpolationTest.java index 00e29f2..37dbc0f 100644 --- a/src/test/java/org/apache/freemarker/core/ast/StringLiteralInterpolationTest.java +++ b/src/test/java/org/apache/freemarker/core/ast/StringLiteralInterpolationTest.java @@ -23,8 +23,6 @@ import java.util.Collections; import org.apache.freemarker.core.Configuration; import org.apache.freemarker.core.TemplateException; -import org.apache.freemarker.core.ast.InvalidReferenceException; -import org.apache.freemarker.core.ast.RTFOutputFormat; import org.apache.freemarker.test.TemplateTest; import org.junit.Test; @@ -89,6 +87,8 @@ public class StringLiteralInterpolationTest extends TemplateTest { assertOutput("<#escape x as x?html><#assign x = '&'>${x} ${'${x}'}</#escape> ${x}", "& & &"); } + // We couldn't test this on 3.0.0, as nothing was fixed there with IcI yet + /*- @Test public void iciInheritanceBugFixed() throws Exception { // Broken behavior emulated: @@ -99,6 +99,7 @@ public class StringLiteralInterpolationTest extends TemplateTest { getConfiguration().setIncompatibleImprovements(Configuration.VERSION_2_3_24); assertOutput("${'&\\''?html} ${\"${'&\\\\\\''?html}\"}", "&' &'"); } + */ @Test public void markup() throws IOException, TemplateException { http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/8ba7883e/src/test/java/org/apache/freemarker/core/ast/TabSizeTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/freemarker/core/ast/TabSizeTest.java b/src/test/java/org/apache/freemarker/core/ast/TabSizeTest.java index b42215c..ea33054 100644 --- a/src/test/java/org/apache/freemarker/core/ast/TabSizeTest.java +++ b/src/test/java/org/apache/freemarker/core/ast/TabSizeTest.java @@ -18,14 +18,14 @@ */ package org.apache.freemarker.core.ast; -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; import java.io.IOException; import org.apache.freemarker.core.Configuration; import org.apache.freemarker.core.Template; import org.apache.freemarker.core.TemplateNotFoundException; -import org.apache.freemarker.core.ast.ParseException; import org.apache.freemarker.core.templateresolver.MalformedTemplateNameException; import org.apache.freemarker.test.TemplateTest; import org.junit.Test; @@ -35,7 +35,6 @@ public class TabSizeTest extends TemplateTest { @Override protected Configuration createConfiguration() throws Exception { Configuration cfg = super.createConfiguration(); - cfg.setIncompatibleImprovements(Configuration.VERSION_2_3_22); return cfg; } http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/8ba7883e/src/test/java/org/apache/freemarker/core/ast/TagSyntaxVariationsTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/freemarker/core/ast/TagSyntaxVariationsTest.java b/src/test/java/org/apache/freemarker/core/ast/TagSyntaxVariationsTest.java index bb1b1aa..2f0e1d9 100644 --- a/src/test/java/org/apache/freemarker/core/ast/TagSyntaxVariationsTest.java +++ b/src/test/java/org/apache/freemarker/core/ast/TagSyntaxVariationsTest.java @@ -26,7 +26,6 @@ import java.io.StringWriter; import org.apache.freemarker.core.Configuration; import org.apache.freemarker.core.Template; import org.apache.freemarker.core.TemplateException; -import org.apache.freemarker.core.ast.ParseException; import org.apache.freemarker.core.util._StringUtil; import junit.framework.TestCase; @@ -63,13 +62,7 @@ public class TagSyntaxVariationsTest extends TestCase { public final void test() throws TemplateException, IOException { - Configuration cfgBuggy = new Configuration(); - // Default on 2.3.x: cfgBuggy.setEmulate23ParserBugs(true); - // Default on 2.3.x: cfgBuggy.setTagSyntax(Configuration.ANGLE_BRACKET_TAG_SYNTAX); - - Configuration cfgFixed = new Configuration(); - cfgFixed.setIncompatibleImprovements(Configuration.VERSION_2_3_19); - // Default on 2.3.x: cfgFixed.setTagSyntax(Configuration.ANGLE_BRACKET_TAG_SYNTAX); + Configuration cfg = new Configuration(Configuration.VERSION_3_0_0); // Permutations for (int ifOrAssign = 0; ifOrAssign < 2; ifOrAssign++) { @@ -79,10 +72,7 @@ public class TagSyntaxVariationsTest extends TestCase { // Permutations for (int angOrSqu = 0; angOrSqu < 2; angOrSqu++) { - cfgBuggy.setTagSyntax(angOrSqu == 0 - ? Configuration.ANGLE_BRACKET_TAG_SYNTAX - : Configuration.SQUARE_BRACKET_TAG_SYNTAX); - cfgFixed.setTagSyntax(angOrSqu == 0 + cfg.setTagSyntax(angOrSqu == 0 ? Configuration.ANGLE_BRACKET_TAG_SYNTAX : Configuration.SQUARE_BRACKET_TAG_SYNTAX); @@ -92,10 +82,7 @@ public class TagSyntaxVariationsTest extends TestCase { String wrong_xxx = angOrSqu == 0 ? WRONG_ANG : WRONG_SQU; String wrongc_xxx = angOrSqu == 0 ? WRONGC_ANG : WRONGC_SQU; - test(cfgBuggy, - dir_xxx + cust_xxx, - dir_out + CUST_OUT); - test(cfgFixed, + test(cfg, dir_xxx + cust_xxx, dir_out + CUST_OUT); @@ -103,61 +90,33 @@ public class TagSyntaxVariationsTest extends TestCase { for (int wrongOrWrongc = 0; wrongOrWrongc < 2; wrongOrWrongc++) { String wrongx_xxx = wrongOrWrongc == 0 ? wrong_xxx : wrongc_xxx; - // Bug: initial unknown # tags are treated as static text - test(cfgBuggy, - wrongx_xxx + dir_xxx, - wrongx_xxx + dir_out); - test(cfgFixed, + test(cfg, wrongx_xxx + dir_xxx, null); - // Bug: same as above - test(cfgBuggy, - wrongx_xxx + wrongx_xxx + dir_xxx, - wrongx_xxx + wrongx_xxx + dir_out); - - test(cfgBuggy, - dir_xxx + wrongx_xxx, - null); - test(cfgFixed, + test(cfg, dir_xxx + wrongx_xxx, null); - test(cfgBuggy, - hdr_xxx + wrongx_xxx, - null); - test(cfgFixed, + test(cfg, hdr_xxx + wrongx_xxx, null); - test(cfgBuggy, - cust_xxx + wrongx_xxx + dir_xxx, - null); - test(cfgFixed, + test(cfg, cust_xxx + wrongx_xxx + dir_xxx, null); } // for wrongc } // for squ - cfgBuggy.setTagSyntax(Configuration.AUTO_DETECT_TAG_SYNTAX); - cfgFixed.setTagSyntax(Configuration.AUTO_DETECT_TAG_SYNTAX); + cfg.setTagSyntax(Configuration.AUTO_DETECT_TAG_SYNTAX); for (int perm = 0; perm < 4; perm++) { // All 4 permutations String wrong_xxx = (perm & 1) == 0 ? WRONG_ANG : WRONG_SQU; String dir_xxx = (perm & 2) == 0 ? dir_ang : dir_squ; - // Bug: Auto-detection ignores unknown # tags - test(cfgBuggy, - wrong_xxx + dir_xxx, - wrong_xxx + dir_out); - test(cfgFixed, + test(cfg, wrong_xxx + dir_xxx, null); - - // Bug: same as above - test(cfgBuggy, - wrong_xxx + wrong_xxx + dir_xxx, - wrong_xxx + wrong_xxx + dir_out); } // for perm // Permutations @@ -168,38 +127,23 @@ public class TagSyntaxVariationsTest extends TestCase { String dir_xxx = angOrSquStart == 0 ? dir_ang : dir_squ; String dir_yyy = angOrSquStart != 0 ? dir_ang : dir_squ; - test(cfgBuggy, - cust_xxx + wrong_yyy + dir_xxx, - CUST_OUT + wrong_yyy + dir_out); - test(cfgFixed, + test(cfg, cust_xxx + wrong_yyy + dir_xxx, CUST_OUT + wrong_yyy + dir_out); - test(cfgBuggy, - hdr_xxx + wrong_yyy + dir_xxx, - wrong_yyy + dir_out); - test(cfgFixed, + test(cfg, hdr_xxx + wrong_yyy + dir_xxx, wrong_yyy + dir_out); - test(cfgBuggy, - cust_xxx + wrong_yyy + dir_yyy, - CUST_OUT + wrong_yyy + dir_yyy); - test(cfgFixed, + test(cfg, cust_xxx + wrong_yyy + dir_yyy, CUST_OUT + wrong_yyy + dir_yyy); - test(cfgBuggy, - hdr_xxx + wrong_yyy + dir_yyy, - wrong_yyy + dir_yyy); - test(cfgFixed, + test(cfg, hdr_xxx + wrong_yyy + dir_yyy, wrong_yyy + dir_yyy); - test(cfgBuggy, - dir_xxx + wrong_yyy + dir_yyy, - dir_out + wrong_yyy + dir_yyy); - test(cfgFixed, + test(cfg, dir_xxx + wrong_yyy + dir_yyy, dir_out + wrong_yyy + dir_yyy); } // for squStart http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/8ba7883e/src/test/java/org/apache/freemarker/core/ast/TemplatGetEncodingTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/freemarker/core/ast/TemplatGetEncodingTest.java b/src/test/java/org/apache/freemarker/core/ast/TemplatGetEncodingTest.java index af001c9..e2af001 100644 --- a/src/test/java/org/apache/freemarker/core/ast/TemplatGetEncodingTest.java +++ b/src/test/java/org/apache/freemarker/core/ast/TemplatGetEncodingTest.java @@ -29,7 +29,6 @@ import java.nio.charset.StandardCharsets; import org.apache.freemarker.core.Configuration; import org.apache.freemarker.core.Template; import org.apache.freemarker.core.TemplateNotFoundException; -import org.apache.freemarker.core.ast.ParseException; import org.apache.freemarker.core.templateresolver.MalformedTemplateNameException; import org.apache.freemarker.core.templateresolver.impl.ByteArrayTemplateLoader; import org.apache.freemarker.core.templateresolver.impl.StrongCacheStorage; @@ -39,7 +38,7 @@ public class TemplatGetEncodingTest { @Test public void test() throws TemplateNotFoundException, MalformedTemplateNameException, ParseException, IOException { - Configuration cfg = new Configuration(Configuration.VERSION_2_3_22); + Configuration cfg = new Configuration(Configuration.VERSION_3_0_0); { cfg.setDefaultEncoding("ISO-8859-2"); ByteArrayTemplateLoader tl = new ByteArrayTemplateLoader(); http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/8ba7883e/src/test/java/org/apache/freemarker/core/ast/TemplateConfigurationTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/freemarker/core/ast/TemplateConfigurationTest.java b/src/test/java/org/apache/freemarker/core/ast/TemplateConfigurationTest.java index 2e41f21..6e222fc 100644 --- a/src/test/java/org/apache/freemarker/core/ast/TemplateConfigurationTest.java +++ b/src/test/java/org/apache/freemarker/core/ast/TemplateConfigurationTest.java @@ -103,7 +103,7 @@ public class TemplateConfigurationTest { } } - private static final Version ICI = Configuration.VERSION_2_3_22; + private static final Version ICI = Configuration.VERSION_3_0_0; private static final Configuration DEFAULT_CFG = new Configuration(ICI); static { @@ -168,7 +168,7 @@ public class TemplateConfigurationTest { SETTING_ASSIGNMENTS.put("dateFormat", "yyyy-#DDD"); SETTING_ASSIGNMENTS.put("dateTimeFormat", "yyyy-#DDD-@HH:mm"); SETTING_ASSIGNMENTS.put("locale", NON_DEFAULT_LOCALE); - SETTING_ASSIGNMENTS.put("logTemplateExceptions", false); + SETTING_ASSIGNMENTS.put("logTemplateExceptions", true); SETTING_ASSIGNMENTS.put("newBuiltinClassResolver", TemplateClassResolver.ALLOWS_NOTHING_RESOLVER); SETTING_ASSIGNMENTS.put("numberFormat", "0.0000"); SETTING_ASSIGNMENTS.put("objectWrapper", new SimpleObjectWrapper(ICI)); @@ -190,7 +190,7 @@ public class TemplateConfigurationTest { SETTING_ASSIGNMENTS.put("strictSyntaxMode", false); SETTING_ASSIGNMENTS.put("autoEscapingPolicy", Configuration.DISABLE_AUTO_ESCAPING_POLICY); SETTING_ASSIGNMENTS.put("outputFormat", HTMLOutputFormat.INSTANCE); - SETTING_ASSIGNMENTS.put("recognizeStandardFileExtensions", true); + SETTING_ASSIGNMENTS.put("recognizeStandardFileExtensions", false); SETTING_ASSIGNMENTS.put("tabSize", 1); SETTING_ASSIGNMENTS.put("lazyImports", Boolean.TRUE); SETTING_ASSIGNMENTS.put("lazyAutoImports", Boolean.FALSE); @@ -489,7 +489,7 @@ public class TemplateConfigurationTest { @Test public void applyOrder() throws Exception { - Configuration cfg = new Configuration(Configuration.VERSION_2_3_25); + Configuration cfg = new Configuration(Configuration.VERSION_3_0_0); Template t = new Template(null, "", cfg); { @@ -552,7 +552,7 @@ public class TemplateConfigurationTest { @Test public void testConfigureCustomAttributes() throws Exception { - Configuration cfg = new Configuration(Configuration.VERSION_2_3_22); + Configuration cfg = new Configuration(Configuration.VERSION_3_0_0); cfg.setCustomAttribute("k1", "c"); cfg.setCustomAttribute("k2", "c"); cfg.setCustomAttribute("k3", "c"); @@ -648,24 +648,26 @@ public class TemplateConfigurationTest { { TemplateConfiguration tc = new TemplateConfiguration(); + /* Can't test this now, as the only valid value is 3.0.0. [FM3.0.1] tc.setParentConfiguration(new Configuration(new Version(2, 3, 0))); assertOutputWithoutAndWithTC(tc, "<#foo>", null, "<#foo>"); + */ testedProps.add(Configuration.INCOMPATIBLE_IMPROVEMENTS_KEY_CAMEL_CASE); } { TemplateConfiguration tc = new TemplateConfiguration(); - tc.setParentConfiguration(new Configuration(new Version(2, 3, 0))); - tc.setRecognizeStandardFileExtensions(true); - assertOutputWithoutAndWithTC(tc, "${.outputFormat}", - UndefinedOutputFormat.INSTANCE.getName(), HTMLOutputFormat.INSTANCE.getName()); + tc.setParentConfiguration(DEFAULT_CFG); + tc.setRecognizeStandardFileExtensions(false); + assertOutputWithoutAndWithTC(tc, "adhoc.ftlh", "${.outputFormat}", + HTMLOutputFormat.INSTANCE.getName(), UndefinedOutputFormat.INSTANCE.getName()); testedProps.add(Configuration.RECOGNIZE_STANDARD_FILE_EXTENSIONS_KEY_CAMEL_CASE); } { TemplateConfiguration tc = new TemplateConfiguration(); tc.setLogTemplateExceptions(false); - tc.setParentConfiguration(new Configuration(new Version(2, 3, 22))); + tc.setParentConfiguration(DEFAULT_CFG); tc.setTabSize(3); assertOutputWithoutAndWithTC(tc, "<#attempt><@'\\t$\\{1+}'?interpret/><#recover>" @@ -679,40 +681,6 @@ public class TemplateConfigurationTest { } @Test - public void testConfigureParserTooLowIcI() throws Exception { - Configuration cfgWithTooLowIcI = new Configuration(Configuration.VERSION_2_3_21); - for (PropertyDescriptor propDesc : getTemplateConfigurationSettingPropDescs(true, false)) { - TemplateConfiguration tc = new TemplateConfiguration(); - - String propName = propDesc.getName(); - Object value = SETTING_ASSIGNMENTS.get(propName); - propDesc.getWriteMethod().invoke(tc, value); - - boolean shouldFail; - if (CONFIGURABLE_PROP_NAMES.contains(propName)) { - shouldFail = true; - } else if (PARSER_PROP_NAMES.contains(propName)) { - shouldFail = false; - } else { - fail("Uncategorized property: " + propName); - return; - } - - try { - tc.setParentConfiguration(cfgWithTooLowIcI); - if (shouldFail) { - fail("Should fail with property: " + propName); - } - } catch (IllegalStateException e) { - if (!shouldFail) { - throw e; - } - assertThat(e.getMessage(), containsString("2.3.22")); - } - } - } - - @Test public void testArithmeticEngine() throws TemplateException, IOException { TemplateConfiguration tc = new TemplateConfiguration(); tc.setParentConfiguration(DEFAULT_CFG); @@ -850,19 +818,29 @@ public class TemplateConfigurationTest { tc.apply(t); } + + private void assertOutputWithoutAndWithTC( + TemplateConfiguration tc, String ftl, String expectedDefaultOutput, + String expectedConfiguredOutput) throws TemplateException, IOException { + assertOutputWithoutAndWithTC(tc, null, ftl, expectedDefaultOutput, expectedConfiguredOutput); + } - private void assertOutputWithoutAndWithTC(TemplateConfiguration tc, String ftl, String expectedDefaultOutput, + private void assertOutputWithoutAndWithTC( + TemplateConfiguration tc, String templateName, String ftl, String expectedDefaultOutput, String expectedConfiguredOutput) throws TemplateException, IOException { - assertOutput(null, ftl, expectedDefaultOutput); - assertOutput(tc, ftl, expectedConfiguredOutput); + if (templateName == null) { + templateName = "adhoc.ftl"; + } + assertOutput(null, templateName, ftl, expectedDefaultOutput); + assertOutput(tc, templateName, ftl, expectedConfiguredOutput); } - private void assertOutput(TemplateConfiguration tc, String ftl, String expectedConfiguredOutput) + private void assertOutput(TemplateConfiguration tc, String templateName, String ftl, String expectedConfiguredOutput) throws TemplateException, IOException { StringWriter sw = new StringWriter(); try { Configuration cfg = tc != null ? tc.getParentConfiguration() : DEFAULT_CFG; - Template t = new Template("adhoc.ftlh", null, new StringReader(ftl), cfg, tc, null); + Template t = new Template(templateName, null, new StringReader(ftl), cfg, tc, null); if (tc != null) { tc.apply(t); } http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/8ba7883e/src/test/java/org/apache/freemarker/core/ast/TemplateConfigurationWithTemplateResolverTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/freemarker/core/ast/TemplateConfigurationWithTemplateResolverTest.java b/src/test/java/org/apache/freemarker/core/ast/TemplateConfigurationWithTemplateResolverTest.java index f6e1df9..0319fab 100644 --- a/src/test/java/org/apache/freemarker/core/ast/TemplateConfigurationWithTemplateResolverTest.java +++ b/src/test/java/org/apache/freemarker/core/ast/TemplateConfigurationWithTemplateResolverTest.java @@ -18,7 +18,8 @@ */ package org.apache.freemarker.core.ast; -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; import java.io.IOException; import java.io.StringWriter; @@ -28,8 +29,6 @@ import java.util.Locale; import org.apache.freemarker.core.Configuration; import org.apache.freemarker.core.Template; import org.apache.freemarker.core.TemplateException; -import org.apache.freemarker.core.ast.CustomAttribute; -import org.apache.freemarker.core.ast.TemplateConfiguration; import org.apache.freemarker.core.templateresolver.ConditionalTemplateConfigurationFactory; import org.apache.freemarker.core.templateresolver.FileNameGlobMatcher; import org.apache.freemarker.core.templateresolver.FirstMatchTemplateConfigurationFactory; @@ -112,7 +111,7 @@ public class TemplateConfigurationWithTemplateResolverTest { @Test public void testLocale() throws Exception { - Configuration cfg = new Configuration(Configuration.VERSION_2_3_23); + Configuration cfg = new Configuration(Configuration.VERSION_3_0_0); cfg.setLocale(Locale.US); StringTemplateLoader tl = new StringTemplateLoader(); @@ -153,7 +152,7 @@ public class TemplateConfigurationWithTemplateResolverTest { @Test public void testPlainText() throws Exception { Configuration cfg = createCommonEncodingTesterConfig(); - cfg.setIncompatibleImprovements(Configuration.VERSION_2_3_22); + cfg.setIncompatibleImprovements(Configuration.VERSION_3_0_0); TemplateConfiguration tcDE = new TemplateConfiguration(); tcDE.setLocale(Locale.GERMANY); @@ -195,7 +194,7 @@ public class TemplateConfigurationWithTemplateResolverTest { @Test public void testConfigurableSettings() throws Exception { - Configuration cfg = new Configuration(Configuration.VERSION_2_3_22); + Configuration cfg = new Configuration(Configuration.VERSION_3_0_0); cfg.setLocale(Locale.US); TemplateConfiguration tcFR = new TemplateConfiguration(); @@ -228,7 +227,7 @@ public class TemplateConfigurationWithTemplateResolverTest { @Test public void testCustomAttributes() throws Exception { - Configuration cfg = new Configuration(Configuration.VERSION_2_3_22); + Configuration cfg = new Configuration(Configuration.VERSION_3_0_0); TemplateConfiguration tc1 = new TemplateConfiguration(); tc1.setCustomAttribute("a1", "a1tc1"); @@ -297,7 +296,7 @@ public class TemplateConfigurationWithTemplateResolverTest { } private Configuration createCommonEncodingTesterConfig() throws UnsupportedEncodingException { - Configuration cfg = new Configuration(Configuration.VERSION_2_3_0); + Configuration cfg = new Configuration(Configuration.VERSION_3_0_0); cfg.setDefaultEncoding("iso-8859-1"); cfg.setLocale(Locale.US); http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/8ba7883e/src/test/java/org/apache/freemarker/core/ast/TemplateLevelSettings.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/freemarker/core/ast/TemplateLevelSettings.java b/src/test/java/org/apache/freemarker/core/ast/TemplateLevelSettings.java index 7794041..b651f41 100644 --- a/src/test/java/org/apache/freemarker/core/ast/TemplateLevelSettings.java +++ b/src/test/java/org/apache/freemarker/core/ast/TemplateLevelSettings.java @@ -19,7 +19,7 @@ package org.apache.freemarker.core.ast; -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; import java.io.IOException; import java.io.StringWriter; @@ -57,33 +57,26 @@ public class TemplateLevelSettings { @Test public void test() throws IOException, TemplateException { assertOutputs( - "M[inc:INC]MM[impM1:M{M}M[impM2:M{IMP}M]M]M[incM:M{M}M]M", "M[inc:M]MM[impM1:M{M}M[impM2:M{M}M]M]M[incM:M{M}M]M", "M,m", "INC,inc", "IMP,imp"); assertOutputs( - "C[inc:INC]CC[impM1:C{C}C[impM2:C{IMP}C]C]C[incM:C{C}C]C", "C[inc:C]CC[impM1:C{C}C[impM2:C{C}C]C]C[incM:C{C}C]C", null, "INC,inc", "IMP,imp"); assertOutputs( - "M[inc:C]MM[impM1:M{M}M[impM2:M{IMP}M]M]M[incM:M{M}M]M", "M[inc:M]MM[impM1:M{M}M[impM2:M{M}M]M]M[incM:M{M}M]M", "M,m", null, "IMP,imp"); assertOutputs( - "M[inc:INC]MM[impM1:M{M}M[impM2:M{C}M]M]M[incM:M{M}M]M", "M[inc:M]MM[impM1:M{M}M[impM2:M{M}M]M]M[incM:M{M}M]M", "M,m", "INC,inc", null); } private void assertOutputs( - String legacyOutput, String fixedOutput, + String expectedOutput, String mainBoolFmt, String incBoolFmt, String impBoolFtm) throws IOException, TemplateException { assertEquals( - legacyOutput, - renderWith(Configuration.VERSION_2_3_21, mainBoolFmt, incBoolFmt, impBoolFtm)); - assertEquals( - fixedOutput, - renderWith(Configuration.VERSION_2_3_22, mainBoolFmt, incBoolFmt, impBoolFtm)); + expectedOutput, + renderWith(Configuration.VERSION_3_0_0, mainBoolFmt, incBoolFmt, impBoolFtm)); } private String renderWith(Version version, String mainBoolFmt, String incBoolFmt, String impBoolFtm) http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/8ba7883e/src/test/java/org/apache/freemarker/core/ast/TemplateNameSpecialVariablesTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/freemarker/core/ast/TemplateNameSpecialVariablesTest.java b/src/test/java/org/apache/freemarker/core/ast/TemplateNameSpecialVariablesTest.java index 49b7ca8..d5575aa 100644 --- a/src/test/java/org/apache/freemarker/core/ast/TemplateNameSpecialVariablesTest.java +++ b/src/test/java/org/apache/freemarker/core/ast/TemplateNameSpecialVariablesTest.java @@ -23,7 +23,6 @@ import java.io.IOException; import org.apache.freemarker.core.Configuration; import org.apache.freemarker.core.Template; import org.apache.freemarker.core.TemplateException; -import org.apache.freemarker.core.Version; import org.apache.freemarker.core.templateresolver.TemplateLoader; import org.apache.freemarker.core.templateresolver.impl.StringTemplateLoader; import org.apache.freemarker.core.util._StringUtil; @@ -33,9 +32,6 @@ import org.junit.Test; public class TemplateNameSpecialVariablesTest extends TemplateTest { - private static final Version[] BREAK_POINT_VERSIONS = new Version[] { - Configuration.VERSION_2_3_0, Configuration.VERSION_2_3_22, Configuration.VERSION_2_3_23 }; - private static TemplateLoader createTemplateLoader(String specVar) { StringTemplateLoader tl = new StringTemplateLoader(); tl.putTemplate("main.ftl", @@ -84,67 +80,18 @@ public class TemplateNameSpecialVariablesTest extends TemplateTest { = "t=${.templateName}, ct=${.currentTemplateName!'-'}, mt=${.mainTemplateName!'-'}"; @Test - public void testTemplateName230() throws IOException, TemplateException { - getConfiguration().setTemplateLoader(createTemplateLoader(".templateName")); - getConfiguration().setIncompatibleImprovements(Configuration.VERSION_2_3_0); - assertMainFtlOutput(false); - } - - /** This IcI version was buggy. */ - @Test - public void testTemplateName2322() throws IOException, TemplateException { - getConfiguration().setTemplateLoader(createTemplateLoader(".templateName")); - getConfiguration().setIncompatibleImprovements(Configuration.VERSION_2_3_22); - assertMainFtlOutput(true); - } - - @Test - public void testTemplateName2323() throws IOException, TemplateException { + public void testTemplateName() throws IOException, TemplateException { getConfiguration().setTemplateLoader(createTemplateLoader(".templateName")); - getConfiguration().setIncompatibleImprovements(Configuration.VERSION_2_3_23); assertMainFtlOutput(false); } @Test public void testMainTemplateName() throws IOException, TemplateException { getConfiguration().setTemplateLoader(createTemplateLoader(".mainTemplateName")); - for (Version ici : BREAK_POINT_VERSIONS) { - getConfiguration().setIncompatibleImprovements(ici); - assertMainFtlOutput(true); - } + assertMainFtlOutput(true); } - @Test - public void testCurrentTemplateName() throws IOException, TemplateException { - getConfiguration().setTemplateLoader(createTemplateLoader(".currentTemplateName")); - for (Version ici : BREAK_POINT_VERSIONS) { - getConfiguration().setIncompatibleImprovements(ici); - assertOutputForNamed("main.ftl", - "In main: main.ftl\n" - + "In imp: imp.ftl\n" - + "In main: main.ftl\n" - + "imp.ftl\n" - + "{main.ftl}\n" - + "In imp call imp:\n" - + "imp.ftl\n" - + "{imp.ftl}\n" - + "After: imp.ftl\n" - + "In main: main.ftl\n" - + "In inc: inc.ftl\n" - + "In inc call imp:\n" - + "imp.ftl\n" - + "{inc.ftl}\n" - + "In main: main.ftl\n" - + "inc.ftl\n" - + "{main.ftl}\n" - + "In inc call imp:\n" - + "imp.ftl\n" - + "{inc.ftl}\n" - + "In main: main.ftl\n"); - } - } - - protected void assertMainFtlOutput(boolean allMain) throws IOException, TemplateException { + private void assertMainFtlOutput(boolean allMain) throws IOException, TemplateException { String expected = "In main: main.ftl\n" + "In imp: imp.ftl\n" @@ -174,6 +121,33 @@ public class TemplateNameSpecialVariablesTest extends TemplateTest { assertOutputForNamed("main.ftl", expected); } + @Test + public void testCurrentTemplateName() throws IOException, TemplateException { + getConfiguration().setTemplateLoader(createTemplateLoader(".currentTemplateName")); + assertOutputForNamed("main.ftl", + "In main: main.ftl\n" + + "In imp: imp.ftl\n" + + "In main: main.ftl\n" + + "imp.ftl\n" + + "{main.ftl}\n" + + "In imp call imp:\n" + + "imp.ftl\n" + + "{imp.ftl}\n" + + "After: imp.ftl\n" + + "In main: main.ftl\n" + + "In inc: inc.ftl\n" + + "In inc call imp:\n" + + "imp.ftl\n" + + "{inc.ftl}\n" + + "In main: main.ftl\n" + + "inc.ftl\n" + + "{main.ftl}\n" + + "In inc call imp:\n" + + "imp.ftl\n" + + "{inc.ftl}\n" + + "In main: main.ftl\n"); + } + @Before public void setup() { Configuration cfg = getConfiguration(); http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/8ba7883e/src/test/java/org/apache/freemarker/core/ast/TheadInterruptingSupportTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/freemarker/core/ast/TheadInterruptingSupportTest.java b/src/test/java/org/apache/freemarker/core/ast/TheadInterruptingSupportTest.java index d6b8a4e..8b5a8b7 100644 --- a/src/test/java/org/apache/freemarker/core/ast/TheadInterruptingSupportTest.java +++ b/src/test/java/org/apache/freemarker/core/ast/TheadInterruptingSupportTest.java @@ -19,7 +19,7 @@ package org.apache.freemarker.core.ast; -import static org.junit.Assert.*; +import static org.junit.Assert.assertTrue; import java.io.IOException; import java.util.Map; @@ -41,7 +41,7 @@ public class TheadInterruptingSupportTest { private static final Logger LOG = LoggerFactory.getLogger(TheadInterruptingSupportTest.class); private static final int TEMPLATE_INTERRUPTION_TIMEOUT = 5000; - private final Configuration cfg = new Configuration(Configuration.VERSION_2_3_22); + private final Configuration cfg = new Configuration(Configuration.VERSION_3_0_0); @Test public void test() throws IOException, InterruptedException { http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/8ba7883e/src/test/java/org/apache/freemarker/core/ast/UnclosedCommentTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/freemarker/core/ast/UnclosedCommentTest.java b/src/test/java/org/apache/freemarker/core/ast/UnclosedCommentTest.java index 4126fc0..afa1de1 100644 --- a/src/test/java/org/apache/freemarker/core/ast/UnclosedCommentTest.java +++ b/src/test/java/org/apache/freemarker/core/ast/UnclosedCommentTest.java @@ -28,40 +28,17 @@ import org.junit.Test; public class UnclosedCommentTest extends TemplateTest { - private static final String UNCLOSED_COMMENT_0 = "foo<#--"; - private static final String UNCLOSED_COMMENT_1 = "foo<#-- "; - private static final String UNCLOSED_COMMENT_2 = "foo<#--bar"; - private static final String UNCLOSED_COMMENT_3 = "foo\n<#--\n"; - - private static final String UNCLOSED_NOPARSE_0 = "foo<#noparse>"; - private static final String UNCLOSED_NOPARSE_1 = "foo<#noparse> "; - private static final String UNCLOSED_NOPARSE_2 = "foo<#noparse>bar"; - private static final String UNCLOSED_NOPARSE_3 = "foo\n<#noparse>\n"; - - @Test - public void testLegacyBehavior() throws IOException, TemplateException { - setConfiguration(new Configuration(Configuration.VERSION_2_3_20)); - assertErrorContains(UNCLOSED_COMMENT_0, "end of file"); - assertOutput(UNCLOSED_COMMENT_1, "foo"); - assertOutput(UNCLOSED_COMMENT_2, "foo"); - assertOutput(UNCLOSED_COMMENT_3, "foo\n"); - assertErrorContains(UNCLOSED_NOPARSE_0, "end of file"); - assertOutput(UNCLOSED_NOPARSE_1, "foo"); - assertOutput(UNCLOSED_NOPARSE_2, "foo"); - assertOutput(UNCLOSED_NOPARSE_3, "foo\n"); - } - @Test - public void testFixedBehavior() throws IOException, TemplateException { - setConfiguration(new Configuration(Configuration.VERSION_2_3_21)); - assertErrorContains(UNCLOSED_COMMENT_0, "end of file"); // Not too good... - assertErrorContains(UNCLOSED_COMMENT_1, "Unclosed", "<#--"); - assertErrorContains(UNCLOSED_COMMENT_2, "Unclosed", "<#--"); - assertErrorContains(UNCLOSED_COMMENT_3, "Unclosed", "<#--"); - assertErrorContains(UNCLOSED_NOPARSE_0, "end of file"); // Not too good... - assertErrorContains(UNCLOSED_NOPARSE_1, "Unclosed", "#noparse"); - assertErrorContains(UNCLOSED_NOPARSE_2, "Unclosed", "#noparse"); - assertErrorContains(UNCLOSED_NOPARSE_3, "Unclosed", "#noparse"); + public void test() throws IOException, TemplateException { + setConfiguration(new Configuration(Configuration.VERSION_3_0_0)); + assertErrorContains("foo<#--", "end of file"); // Not too good... + assertErrorContains("foo<#-- ", "Unclosed", "<#--"); + assertErrorContains("foo<#--bar", "Unclosed", "<#--"); + assertErrorContains("foo\n<#--\n", "Unclosed", "<#--"); + assertErrorContains("foo<#noparse>", "end of file"); // Not too good... + assertErrorContains("foo<#noparse> ", "Unclosed", "#noparse"); + assertErrorContains("foo<#noparse>bar", "Unclosed", "#noparse"); + assertErrorContains("foo\n<#noparse>\n", "Unclosed", "#noparse"); } } http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/8ba7883e/src/test/java/org/apache/freemarker/core/ast/WhitespaceStrippingTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/freemarker/core/ast/WhitespaceStrippingTest.java b/src/test/java/org/apache/freemarker/core/ast/WhitespaceStrippingTest.java index 0f587db..f09bf84 100644 --- a/src/test/java/org/apache/freemarker/core/ast/WhitespaceStrippingTest.java +++ b/src/test/java/org/apache/freemarker/core/ast/WhitespaceStrippingTest.java @@ -28,8 +28,9 @@ import org.junit.Test; public class WhitespaceStrippingTest extends TemplateTest { - private final Configuration cfgStripWS = new Configuration(Configuration.VERSION_2_3_21); - private final Configuration cfgNoStripWS = new Configuration(Configuration.VERSION_2_3_21); + private final Configuration cfgStripWS = new Configuration(Configuration.VERSION_3_0_0); + + private final Configuration cfgNoStripWS = new Configuration(Configuration.VERSION_3_0_0); { cfgNoStripWS.setWhitespaceStripping(false); }
