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 |
} |