2 * Created on 28.04.2003
5 package net.sourceforge.phpeclipse.phpeditor.php.test;
9 import junit.framework.TestCase;
10 import net.sourceforge.phpdt.core.JavaCore;
11 import net.sourceforge.phpdt.internal.corext.codemanipulation.StubUtility;
12 import net.sourceforge.phpdt.internal.corext.util.Strings;
13 import net.sourceforge.phpdt.internal.formatter.CodeFormatter;
14 import net.sourceforge.phpdt.internal.ui.preferences.CodeFormatterPreferencePage;
16 import org.eclipse.jface.text.IDocument;
19 * Testcase for the PHP CodeFormatter
20 * @author Stefan Langer
21 * @version $Revision: 1.2 $
23 public class PHPFormatterTest extends TestCase {
24 private CodeFormatter fFormatter;
25 private IDocument fDocument;
26 private String fInitialIndentation;
29 * @see junit.framework.TestCase#setUp()
31 protected void setUp() throws Exception {
32 Map options = JavaCore.getOptions();
33 fFormatter = new CodeFormatter(options);
34 fDocument = new DummyDocument();
37 public void testFormatter1() {
38 System.out.println("----- testFormatter1 -----");
40 String text = "<?php\n" + "function test()\n" + "{echo 'Test!';}\n" + "?>";
43 String lineDelimiter = StubUtility.getLineDelimiterFor(fDocument);
46 if (fInitialIndentation != null) {
47 indent = Strings.computeIndent(fInitialIndentation, CodeFormatterPreferencePage.getTabSize());
49 String formatedString = fFormatter.format(text, indent, null, lineDelimiter);
51 String testResult = "<?php function test() {" + lineDelimiter + "\techo 'Test!';" + lineDelimiter + "}" + lineDelimiter + "?>";
53 junit.framework.Assert.assertEquals(formatedString, testResult);
56 public void testFormatter2() {
58 System.out.println("----- testFormatter2 -----");
59 String text = "<?php\n" + "if ( ${ $feldname }== $modellvar) $i=0;\n" + "?>";
62 String lineDelimiter = StubUtility.getLineDelimiterFor(fDocument);
65 if (fInitialIndentation != null) {
66 indent = Strings.computeIndent(fInitialIndentation, CodeFormatterPreferencePage.getTabSize());
68 String formatedString = fFormatter.format(text, indent, null, lineDelimiter);
70 String testResult = "<?php " + "if (${ $feldname } == $modellvar)" + lineDelimiter + "\t$i = 0;" + lineDelimiter + "?>";
72 junit.framework.Assert.assertEquals(formatedString, testResult);