View | Details | Raw Unified | Return to bug 40255 | Differences between
and this patch

Collapse All | Expand All

(-)Ant (+32 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2004 John-Mason P. Shackelford and others.
3
 * All rights reserved. This program and the accompanying materials 
4
 * are made available under the terms of the Common Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/cpl-v10.html
7
 * 
8
 * Contributors:
9
 *     John-Mason P. Shackelford - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.ant.tests.ui.editor.formatter;
12
13
import org.eclipse.ant.tests.ui.testplugin.ProjectCreationDecorator;
14
15
import junit.framework.Test;
16
import junit.framework.TestSuite;
17
18
/**
19
 * 
20
 */
21
public class AntEditorFormatterTests {
22
	public static Test suite() {
23
		TestSuite suite = new TestSuite(
24
				"Ant Editor Formatter TestSuite");
25
		//$JUnit-BEGIN$
26
		suite.addTestSuite(ProjectCreationDecorator.class);
27
		suite.addTestSuite(FormattingPreferencesTest.class);
28
		suite.addTestSuite(NonParsingXMLFormatterTest.class);
29
		//$JUnit-END$
30
		return suite;
31
	}
32
}
(-)Ant (+70 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2004 John-Mason P. Shackelford and others.
3
 * All rights reserved. This program and the accompanying materials 
4
 * are made available under the terms of the Common Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/cpl-v10.html
7
 * 
8
 * Contributors:
9
 *     John-Mason P. Shackelford - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.ant.tests.ui.editor.formatter;
12
13
import org.eclipse.ant.internal.ui.editor.formatter.FormattingPreferences;
14
import org.eclipse.ant.tests.ui.testplugin.AbstractAntUITest;
15
16
17
/**
18
 * @author shacj
19
 *
20
 * To change the template for this generated type comment go to
21
 * Window - Preferences - Java - Code Generation - Code and Comments
22
 */
23
public class FormattingPreferencesTest extends AbstractAntUITest {
24
25
    /**
26
     * @param name
27
     */
28
    public FormattingPreferencesTest(String name) {
29
        super(name);
30
    }
31
32
    public final void testGetCanonicalIndent() {
33
     
34
        FormattingPreferences prefs;
35
        
36
        // test spaces 
37
        prefs = new FormattingPreferences(){
38
            public int getTabWidth() {                
39
                return 3;
40
            }
41
            public boolean useSpacesInsteadOfTabs() {
42
                return true;
43
            }
44
        };        
45
        assertEquals("   ",prefs.getCanonicalIndent());
46
        
47
        // ensure the value is not hard coded
48
        prefs = new FormattingPreferences(){
49
            public int getTabWidth() {                
50
                return 7;
51
            }
52
            public boolean useSpacesInsteadOfTabs() {
53
                return true;
54
            }
55
        };        
56
        assertEquals("       ",prefs.getCanonicalIndent());
57
        
58
        // use tab character
59
        prefs = new FormattingPreferences(){
60
            public int getTabWidth() {                
61
                return 7;
62
            }
63
            public boolean useSpacesInsteadOfTabs() {
64
                return false;
65
            }
66
        };        
67
        assertEquals("\t",prefs.getCanonicalIndent());
68
    }
69
70
}
(-)Ant (+103 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2004 John-Mason P. Shackelford and others.
3
 * All rights reserved. This program and the accompanying materials 
4
 * are made available under the terms of the Common Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/cpl-v10.html
7
 * 
8
 * Contributors:
9
 *     John-Mason P. Shackelford - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.ant.tests.ui.editor.formatter;
12
13
import org.eclipse.ant.internal.ui.editor.formatter.FormattingPreferences;
14
import org.eclipse.ant.internal.ui.editor.formatter.NonParsingXMLFormatter;
15
import org.eclipse.ant.tests.ui.testplugin.AbstractAntUITest;
16
17
/**
18
 *  
19
 */
20
public class NonParsingXMLFormatterTest extends AbstractAntUITest {
21
22
    /**
23
     * @param name
24
     */
25
    public NonParsingXMLFormatterTest(String name) {
26
        super(name);
27
    }
28
29
    /**
30
     * General Test 
31
     */
32
    public final void testFormat01() throws Exception {
33
        FormattingPreferences prefs = new FormattingPreferences(){
34
            public int getTabWidth() {                
35
                return 3;
36
            }
37
            public boolean stripBlankLines() {
38
                return false;
39
            }
40
            public boolean useSpacesInsteadOfTabs() {
41
                return true;
42
            }
43
        };
44
        simpleTest("formatTest_source01.xml","formatTest_target01.xml",prefs);        
45
    }
46
47
    /**
48
     * Insure that tab width is not hard coded
49
     */
50
    public final void testFormat02() throws Exception {
51
        FormattingPreferences prefs = new FormattingPreferences(){
52
            public int getTabWidth() {                
53
                return 7;
54
            }
55
            public boolean stripBlankLines() {
56
                return false;
57
            }
58
            public boolean useSpacesInsteadOfTabs() {
59
                return true;
60
            }
61
        };
62
        simpleTest("formatTest_source01.xml","formatTest_target02.xml",prefs);        
63
    }
64
65
    
66
    /**
67
     * Test with tab characters instead of spaces.
68
     */
69
    public final void testFormat03() throws Exception {
70
        FormattingPreferences prefs = new FormattingPreferences(){
71
            public int getTabWidth() {                
72
                return 3;
73
            }
74
            public boolean stripBlankLines() {
75
                return false;
76
            }
77
            public boolean useSpacesInsteadOfTabs() {
78
                return false;
79
            }
80
        };
81
        simpleTest("formatTest_source01.xml","formatTest_target03.xml",prefs);        
82
    }
83
    
84
    
85
    /**
86
     * @param sourceFileName - file to format
87
     * @param targetFileName - the source file after a properly executed format
88
     * @param prefs - given the included preference instructions
89
     * @throws Exception
90
     */
91
    private void simpleTest(String sourceFileName, String targetFileName,
92
            FormattingPreferences prefs) throws Exception {
93
        
94
        NonParsingXMLFormatter xmlFormatter = new NonParsingXMLFormatter();
95
        xmlFormatter.setText(getFileContentAsString(getBuildFile(sourceFileName)));
96
        xmlFormatter.setFormattingPreferences(prefs);
97
        
98
        String result = xmlFormatter.format();
99
        String expectedResult = getFileContentAsString(getBuildFile(targetFileName));
100
        
101
        assertEquals(expectedResult, result);
102
    }
103
}
(-)testbuildfiles/formatTest_source01.xml (+14 lines)
Added Link Here
1
<project default="formatTest">
2
3
<!-- = = = = = = --><!-- formatTest  --><!-- = = = = = = --><target name="formatTest" depends="init" description="--> test target one"><!-- hello world --><greeting /></target>
4
5
<!-- - - - - - - -->
6
<!-- init        -->
7
<!-- - - - - - - -->
8
<target name="init">
9
  <property name="greeting" value="hi" />
10
  <presetdef name="greeting"><echo>${greeting}</echo>
11
</presetdef>
12
   </target>
13
14
</project>
(-)testbuildfiles/formatTest_target01.xml (+21 lines)
Added Link Here
1
<project default="formatTest">
2
3
   <!-- = = = = = = -->
4
   <!-- formatTest  -->
5
   <!-- = = = = = = -->
6
   <target name="formatTest" depends="init" description="--> test target one">
7
      <!-- hello world -->
8
      <greeting />
9
   </target>
10
11
   <!-- - - - - - - -->
12
   <!-- init        -->
13
   <!-- - - - - - - -->
14
   <target name="init">
15
      <property name="greeting" value="hi" />
16
      <presetdef name="greeting">
17
         <echo>${greeting}</echo>
18
      </presetdef>
19
   </target>
20
21
</project>
(-)testbuildfiles/formatTest_target02.xml (+21 lines)
Added Link Here
1
<project default="formatTest">
2
3
       <!-- = = = = = = -->
4
       <!-- formatTest  -->
5
       <!-- = = = = = = -->
6
       <target name="formatTest" depends="init" description="--> test target one">
7
              <!-- hello world -->
8
              <greeting />
9
       </target>
10
11
       <!-- - - - - - - -->
12
       <!-- init        -->
13
       <!-- - - - - - - -->
14
       <target name="init">
15
              <property name="greeting" value="hi" />
16
              <presetdef name="greeting">
17
                     <echo>${greeting}</echo>
18
              </presetdef>
19
       </target>
20
21
</project>
(-)testbuildfiles/formatTest_target03.xml (+21 lines)
Added Link Here
1
<project default="formatTest">
2
3
	<!-- = = = = = = -->
4
	<!-- formatTest  -->
5
	<!-- = = = = = = -->
6
	<target name="formatTest" depends="init" description="--> test target one">
7
		<!-- hello world -->
8
		<greeting />
9
	</target>
10
11
	<!-- - - - - - - -->
12
	<!-- init        -->
13
	<!-- - - - - - - -->
14
	<target name="init">
15
		<property name="greeting" value="hi" />
16
		<presetdef name="greeting">
17
			<echo>${greeting}</echo>
18
		</presetdef>
19
	</target>
20
21
</project>

Return to bug 40255