blob: 4acfab18a98b00040ae22d83b1d714b3fd3955ab [file] [log] [blame]
/*******************************************************************************
* 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);
}
}