Bug 40255 - Ant formatter
diff --git a/ant/org.eclipse.ant.tests.ui/Ant Editor Tests/org/eclipse/ant/tests/ui/editor/formatter/FormattingPreferencesTest.java b/ant/org.eclipse.ant.tests.ui/Ant Editor Tests/org/eclipse/ant/tests/ui/editor/formatter/FormattingPreferencesTest.java
new file mode 100644
index 0000000..8295cfc
--- /dev/null
+++ b/ant/org.eclipse.ant.tests.ui/Ant Editor Tests/org/eclipse/ant/tests/ui/editor/formatter/FormattingPreferencesTest.java
@@ -0,0 +1,63 @@
+/*******************************************************************************
+ * Copyright (c) 2004 John-Mason P. Shackelford and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * John-Mason P. Shackelford - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.ant.tests.ui.editor.formatter;
+
+import org.eclipse.ant.internal.ui.editor.formatter.FormattingPreferences;
+import org.eclipse.ant.tests.ui.testplugin.AbstractAntUITest;
+
+public class FormattingPreferencesTest extends AbstractAntUITest {
+
+ /**
+ * @param name
+ */
+ public FormattingPreferencesTest(String name) {
+ super(name);
+ }
+
+ public final void testGetCanonicalIndent() {
+
+ FormattingPreferences prefs;
+
+ // test spaces
+ prefs = new FormattingPreferences(){
+ public int getTabWidth() {
+ return 3;
+ }
+ public boolean useSpacesInsteadOfTabs() {
+ return true;
+ }
+ };
+ assertEquals(" ",prefs.getCanonicalIndent());
+
+ // ensure the value is not hard coded
+ prefs = new FormattingPreferences(){
+ public int getTabWidth() {
+ return 7;
+ }
+ public boolean useSpacesInsteadOfTabs() {
+ return true;
+ }
+ };
+ assertEquals(" ",prefs.getCanonicalIndent());
+
+ // use tab character
+ prefs = new FormattingPreferences(){
+ public int getTabWidth() {
+ return 7;
+ }
+ public boolean useSpacesInsteadOfTabs() {
+ return false;
+ }
+ };
+ assertEquals("\t",prefs.getCanonicalIndent());
+ }
+
+}
diff --git a/ant/org.eclipse.ant.tests.ui/Ant Editor Tests/org/eclipse/ant/tests/ui/editor/formatter/NonParsingXMLFormatterTest.java b/ant/org.eclipse.ant.tests.ui/Ant Editor Tests/org/eclipse/ant/tests/ui/editor/formatter/NonParsingXMLFormatterTest.java
new file mode 100644
index 0000000..4acfab1
--- /dev/null
+++ b/ant/org.eclipse.ant.tests.ui/Ant Editor Tests/org/eclipse/ant/tests/ui/editor/formatter/NonParsingXMLFormatterTest.java
@@ -0,0 +1,103 @@
+/*******************************************************************************
+ * Copyright (c) 2004 John-Mason P. Shackelford and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * John-Mason P. Shackelford - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.ant.tests.ui.editor.formatter;
+
+import org.eclipse.ant.internal.ui.editor.formatter.FormattingPreferences;
+import org.eclipse.ant.internal.ui.editor.formatter.NonParsingXMLFormatter;
+import org.eclipse.ant.tests.ui.testplugin.AbstractAntUITest;
+
+/**
+ *
+ */
+public class NonParsingXMLFormatterTest extends AbstractAntUITest {
+
+ /**
+ * @param name
+ */
+ public NonParsingXMLFormatterTest(String name) {
+ super(name);
+ }
+
+ /**
+ * General Test
+ */
+ public final void testGeneralFormat() throws Exception {
+ FormattingPreferences prefs = new FormattingPreferences(){
+ public int getTabWidth() {
+ return 3;
+ }
+ public boolean stripBlankLines() {
+ return false;
+ }
+ public boolean useSpacesInsteadOfTabs() {
+ return true;
+ }
+ };
+ simpleTest("formatTest_source01.xml","formatTest_target01.xml",prefs);
+ }
+
+ /**
+ * Insure that tab width is not hard coded
+ */
+ public final void testTabWidth() throws Exception {
+ FormattingPreferences prefs = new FormattingPreferences(){
+ public int getTabWidth() {
+ return 7;
+ }
+ public boolean stripBlankLines() {
+ return false;
+ }
+ public boolean useSpacesInsteadOfTabs() {
+ return true;
+ }
+ };
+ simpleTest("formatTest_source01.xml","formatTest_target02.xml",prefs);
+ }
+
+
+ /**
+ * Test with tab characters instead of spaces.
+ */
+ public final void testTabsInsteadOfSpaces() throws Exception {
+ FormattingPreferences prefs = new FormattingPreferences(){
+ public int getTabWidth() {
+ return 3;
+ }
+ public boolean stripBlankLines() {
+ return false;
+ }
+ public boolean useSpacesInsteadOfTabs() {
+ return false;
+ }
+ };
+ simpleTest("formatTest_source01.xml","formatTest_target03.xml",prefs);
+ }
+
+
+ /**
+ * @param sourceFileName - file to format
+ * @param targetFileName - the source file after a properly executed format
+ * @param prefs - given the included preference instructions
+ * @throws Exception
+ */
+ private void simpleTest(String sourceFileName, String targetFileName,
+ FormattingPreferences prefs) throws Exception {
+
+ NonParsingXMLFormatter xmlFormatter = new NonParsingXMLFormatter();
+ xmlFormatter.setText(getFileContentAsString(getBuildFile(sourceFileName)));
+ xmlFormatter.setFormattingPreferences(prefs);
+
+ String result = xmlFormatter.format();
+ String expectedResult = getFileContentAsString(getBuildFile(targetFileName));
+
+ assertEquals(expectedResult, result);
+ }
+}
diff --git a/ant/org.eclipse.ant.tests.ui/test plugin/org/eclipse/ant/tests/ui/testplugin/AntUITests.java b/ant/org.eclipse.ant.tests.ui/test plugin/org/eclipse/ant/tests/ui/testplugin/AntUITests.java
index f63d8d2..da49a48 100644
--- a/ant/org.eclipse.ant.tests.ui/test plugin/org/eclipse/ant/tests/ui/testplugin/AntUITests.java
+++ b/ant/org.eclipse.ant.tests.ui/test plugin/org/eclipse/ant/tests/ui/testplugin/AntUITests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2002, 2003 GEBIT Gesellschaft fuer EDV-Beratung
+ * Copyright (c) 2002, 2004 GEBIT Gesellschaft fuer EDV-Beratung
* und Informatik-Technologien mbH,
* Berlin, Duesseldorf, Frankfurt (Germany) and others.
* All rights reserved. This program and the accompanying materials
@@ -21,12 +21,13 @@
import org.eclipse.ant.tests.ui.editor.AntEditorContentOutlineTests;
import org.eclipse.ant.tests.ui.editor.CodeCompletionTest;
import org.eclipse.ant.tests.ui.editor.TaskDescriptionProviderTest;
+import org.eclipse.ant.tests.ui.editor.formatter.FormattingPreferencesTest;
+import org.eclipse.ant.tests.ui.editor.formatter.NonParsingXMLFormatterTest;
import org.eclipse.ant.tests.ui.externaltools.MigrationTests;
import org.eclipse.ant.tests.ui.separateVM.SeparateVMTests;
/**
* Test suite for the Ant UI
- *
*/
public class AntUITests extends TestSuite {
@@ -41,6 +42,8 @@
suite.addTest(new TestSuite(TaskDescriptionProviderTest.class));
suite.addTest(new TestSuite(AntEditorContentOutlineTests.class));
suite.addTest(new TestSuite(MigrationTests.class));
+ suite.addTest(new TestSuite(FormattingPreferencesTest.class));
+ suite.addTest(new TestSuite(NonParsingXMLFormatterTest.class));
return suite;
}
}
diff --git a/ant/org.eclipse.ant.tests.ui/testbuildfiles/formatTest_source01.xml b/ant/org.eclipse.ant.tests.ui/testbuildfiles/formatTest_source01.xml
new file mode 100644
index 0000000..be1ff78
--- /dev/null
+++ b/ant/org.eclipse.ant.tests.ui/testbuildfiles/formatTest_source01.xml
@@ -0,0 +1,14 @@
+<project default="formatTest">
+
+<!-- = = = = = = --><!-- formatTest --><!-- = = = = = = --><target name="formatTest" depends="init" description="--> test target one"><!-- hello world --><greeting /></target>
+
+<!-- - - - - - - -->
+<!-- init -->
+<!-- - - - - - - -->
+<target name="init">
+ <property name="greeting" value="hi" />
+ <presetdef name="greeting"><echo>${greeting}</echo>
+</presetdef>
+ </target>
+
+</project>
diff --git a/ant/org.eclipse.ant.tests.ui/testbuildfiles/formatTest_target01.xml b/ant/org.eclipse.ant.tests.ui/testbuildfiles/formatTest_target01.xml
new file mode 100644
index 0000000..3059228
--- /dev/null
+++ b/ant/org.eclipse.ant.tests.ui/testbuildfiles/formatTest_target01.xml
@@ -0,0 +1,21 @@
+<project default="formatTest">
+
+ <!-- = = = = = = -->
+ <!-- formatTest -->
+ <!-- = = = = = = -->
+ <target name="formatTest" depends="init" description="--> test target one">
+ <!-- hello world -->
+ <greeting />
+ </target>
+
+ <!-- - - - - - - -->
+ <!-- init -->
+ <!-- - - - - - - -->
+ <target name="init">
+ <property name="greeting" value="hi" />
+ <presetdef name="greeting">
+ <echo>${greeting}</echo>
+ </presetdef>
+ </target>
+
+</project>
diff --git a/ant/org.eclipse.ant.tests.ui/testbuildfiles/formatTest_target02.xml b/ant/org.eclipse.ant.tests.ui/testbuildfiles/formatTest_target02.xml
new file mode 100644
index 0000000..6a1ad9c
--- /dev/null
+++ b/ant/org.eclipse.ant.tests.ui/testbuildfiles/formatTest_target02.xml
@@ -0,0 +1,21 @@
+<project default="formatTest">
+
+ <!-- = = = = = = -->
+ <!-- formatTest -->
+ <!-- = = = = = = -->
+ <target name="formatTest" depends="init" description="--> test target one">
+ <!-- hello world -->
+ <greeting />
+ </target>
+
+ <!-- - - - - - - -->
+ <!-- init -->
+ <!-- - - - - - - -->
+ <target name="init">
+ <property name="greeting" value="hi" />
+ <presetdef name="greeting">
+ <echo>${greeting}</echo>
+ </presetdef>
+ </target>
+
+</project>
diff --git a/ant/org.eclipse.ant.tests.ui/testbuildfiles/formatTest_target03.xml b/ant/org.eclipse.ant.tests.ui/testbuildfiles/formatTest_target03.xml
new file mode 100644
index 0000000..89cd953
--- /dev/null
+++ b/ant/org.eclipse.ant.tests.ui/testbuildfiles/formatTest_target03.xml
@@ -0,0 +1,21 @@
+<project default="formatTest">
+
+ <!-- = = = = = = -->
+ <!-- formatTest -->
+ <!-- = = = = = = -->
+ <target name="formatTest" depends="init" description="--> test target one">
+ <!-- hello world -->
+ <greeting />
+ </target>
+
+ <!-- - - - - - - -->
+ <!-- init -->
+ <!-- - - - - - - -->
+ <target name="init">
+ <property name="greeting" value="hi" />
+ <presetdef name="greeting">
+ <echo>${greeting}</echo>
+ </presetdef>
+ </target>
+
+</project>
\ No newline at end of file