From: khartlage Date: Fri, 23 May 2003 18:37:59 +0000 (+0000) Subject: Added new CodeFormatter JUnit test X-Git-Url: http://git.phpeclipse.com Added new CodeFormatter JUnit test --- diff --git a/net.sourceforge.phpeclipse.tests/src/net/sourceforge/phpeclipse/phpeditor/php/test/DummyDocument.java b/net.sourceforge.phpeclipse.tests/src/net/sourceforge/phpeclipse/phpeditor/php/test/DummyDocument.java index 19ba311..b758fa9 100644 --- a/net.sourceforge.phpeclipse.tests/src/net/sourceforge/phpeclipse/phpeditor/php/test/DummyDocument.java +++ b/net.sourceforge.phpeclipse.tests/src/net/sourceforge/phpeclipse/phpeditor/php/test/DummyDocument.java @@ -10,9 +10,9 @@ import org.eclipse.jface.text.*; * Mockobject for Testing. * * @author Stefan Langer - * @version $Revision: 1.1 $ + * @version $Revision: 1.2 $ */ -public class DummyDocument implements IDocument +public class DummyDocument extends Document // implements IDocument { private char[] fTextBuffer; /* (non-Javadoc) @@ -105,10 +105,10 @@ public class DummyDocument implements IDocument /* (non-Javadoc) * @see org.eclipse.jface.text.IDocument#addPositionCategory(java.lang.String) */ - public void addPositionCategory(String category) - { - throw new UnsupportedOperationException("Not implemented!"); - } +// public void addPositionCategory(String category) +// { +// throw new UnsupportedOperationException("Not implemented!"); +// } /* (non-Javadoc) * @see org.eclipse.jface.text.IDocument#removePositionCategory(java.lang.String) @@ -130,10 +130,10 @@ public class DummyDocument implements IDocument /* (non-Javadoc) * @see org.eclipse.jface.text.IDocument#containsPositionCategory(java.lang.String) */ - public boolean containsPositionCategory(String category) - { - throw new UnsupportedOperationException("Not implemented!"); - } +// public boolean containsPositionCategory(String category) +// { +// throw new UnsupportedOperationException("Not implemented!"); +// } /* (non-Javadoc) * @see org.eclipse.jface.text.IDocument#addPosition(org.eclipse.jface.text.Position) @@ -198,10 +198,10 @@ public class DummyDocument implements IDocument /* (non-Javadoc) * @see org.eclipse.jface.text.IDocument#addPositionUpdater(org.eclipse.jface.text.IPositionUpdater) */ - public void addPositionUpdater(IPositionUpdater updater) - { - throw new UnsupportedOperationException("Not implemented!"); - } +// public void addPositionUpdater(IPositionUpdater updater) +// { +// throw new UnsupportedOperationException("Not implemented!"); +// } /* (non-Javadoc) * @see org.eclipse.jface.text.IDocument#removePositionUpdater(org.eclipse.jface.text.IPositionUpdater) @@ -214,10 +214,10 @@ public class DummyDocument implements IDocument /* (non-Javadoc) * @see org.eclipse.jface.text.IDocument#insertPositionUpdater(org.eclipse.jface.text.IPositionUpdater, int) */ - public void insertPositionUpdater(IPositionUpdater updater, int index) - { - throw new UnsupportedOperationException("Not implemented!"); - } +// public void insertPositionUpdater(IPositionUpdater updater, int index) +// { +// throw new UnsupportedOperationException("Not implemented!"); +// } /* (non-Javadoc) * @see org.eclipse.jface.text.IDocument#getPositionUpdaters() @@ -361,18 +361,18 @@ public class DummyDocument implements IDocument /* (non-Javadoc) * @see org.eclipse.jface.text.IDocument#getLegalLineDelimiters() */ - public String[] getLegalLineDelimiters() - { - throw new UnsupportedOperationException("Not implemented!"); - } +// public String[] getLegalLineDelimiters() +// { +// throw new UnsupportedOperationException("Not implemented!"); +// } /* (non-Javadoc) * @see org.eclipse.jface.text.IDocument#getLineDelimiter(int) */ - public String getLineDelimiter(int line) throws BadLocationException - { - throw new UnsupportedOperationException("Not implemented!"); - } +// public String getLineDelimiter(int line) throws BadLocationException +// { +// throw new UnsupportedOperationException("Not implemented!"); +// } /* (non-Javadoc) * @see org.eclipse.jface.text.IDocument#search(int, java.lang.String, boolean, boolean, boolean) diff --git a/net.sourceforge.phpeclipse.tests/src/net/sourceforge/phpeclipse/phpeditor/php/test/PHPFormatterTest.java b/net.sourceforge.phpeclipse.tests/src/net/sourceforge/phpeclipse/phpeditor/php/test/PHPFormatterTest.java new file mode 100644 index 0000000..11e7ed1 --- /dev/null +++ b/net.sourceforge.phpeclipse.tests/src/net/sourceforge/phpeclipse/phpeditor/php/test/PHPFormatterTest.java @@ -0,0 +1,74 @@ +/* + * Created on 28.04.2003 + * + */ +package net.sourceforge.phpeclipse.phpeditor.php.test; + +import java.util.Map; + +import junit.framework.TestCase; +import net.sourceforge.phpdt.internal.corext.codemanipulation.StubUtility; +import net.sourceforge.phpdt.internal.corext.util.Strings; +import net.sourceforge.phpdt.internal.formatter.CodeFormatter; +import net.sourceforge.phpdt.internal.ui.preferences.CodeFormatterPreferencePage; +import net.sourceforge.phpeclipse.PHPCore; + +import org.eclipse.jface.text.IDocument; + +/** + * Testcase for the PHP CodeFormatter + * @author Stefan Langer + * @version $Revision: 1.1 $ + */ +public class PHPFormatterTest extends TestCase { + private CodeFormatter fFormatter; + private IDocument fDocument; + private String fInitialIndentation; + + /* (non-Javadoc) + * @see junit.framework.TestCase#setUp() + */ + protected void setUp() throws Exception { + Map options = PHPCore.getOptions(); + fFormatter = new CodeFormatter(options); + fDocument = new DummyDocument(); + } + + public void testFormatter1() { + System.out.println("----- testFormatter1 -----"); + + String text = ""; + fDocument.set(text); + + String lineDelimiter = StubUtility.getLineDelimiterFor(fDocument); + + int indent = 0; + if (fInitialIndentation != null) { + indent = Strings.computeIndent(fInitialIndentation, CodeFormatterPreferencePage.getTabSize()); + } + String formatedString = fFormatter.format(text, indent, null, lineDelimiter); + + String testResult = ""; + + junit.framework.Assert.assertEquals(formatedString, testResult); + } + + public void testFormatter2() { + // bug 741752 + System.out.println("----- testFormatter2 -----"); + String text = ""; + fDocument.set(text); + + String lineDelimiter = StubUtility.getLineDelimiterFor(fDocument); + + int indent = 0; + if (fInitialIndentation != null) { + indent = Strings.computeIndent(fInitialIndentation, CodeFormatterPreferencePage.getTabSize()); + } + String formatedString = fFormatter.format(text, indent, null, lineDelimiter); + + String testResult = ""; + + junit.framework.Assert.assertEquals(formatedString, testResult); + } +}