2 * Created on 29.02.2004
4 * To change the template for this generated file go to
5 * Window - Preferences - Java - Code Generation - Code and Comments
7 package net.sourceforge.phpeclipse.phpeditor.php.test;
9 import java.io.PrintWriter;
10 import java.io.StringWriter;
11 import java.util.Locale;
13 import net.sourceforge.phpdt.core.compiler.IProblem;
14 import net.sourceforge.phpdt.core.tests.util.AbstractCompilerTest;
15 import net.sourceforge.phpdt.core.tests.util.Util;
16 import net.sourceforge.phpdt.internal.compiler.CompilationResult;
17 import net.sourceforge.phpdt.internal.compiler.DefaultErrorHandlingPolicies;
18 import net.sourceforge.phpdt.internal.compiler.batch.CompilationUnit;
19 import net.sourceforge.phpdt.internal.compiler.env.ICompilationUnit;
20 import net.sourceforge.phpdt.internal.compiler.parser.UnitParser;
21 import net.sourceforge.phpdt.internal.compiler.problem.DefaultProblem;
22 import net.sourceforge.phpdt.internal.compiler.problem.DefaultProblemFactory;
23 import net.sourceforge.phpdt.internal.compiler.problem.ProblemReporter;
24 import net.sourceforge.phpeclipse.internal.compiler.ast.CompilationUnitDeclaration;
29 * To change the template for this generated type comment go to
30 * Window - Preferences - Java - Code Generation - Code and Comments
32 public class DualParseSyntaxErrorTest extends AbstractCompilerTest {
33 public static boolean optimizeStringLiterals = false;
35 public DualParseSyntaxErrorTest(String testName){
38 public void checkParse(
40 String expectedSyntaxErrorDiagnosis) {
46 DefaultErrorHandlingPolicies.proceedWithAllProblems(),
47 //new CompilerOptions(getCompilerOptions()),
48 new DefaultProblemFactory(Locale.getDefault())));
50 ICompilationUnit sourceUnit = new CompilationUnit(source, "", null);
51 CompilationResult compilationResult = new CompilationResult(sourceUnit, 0, 0, 0);
53 CompilationUnitDeclaration computedUnit = parser.dietParse(sourceUnit, compilationResult, true);
54 // if (computedUnit.types != null) {
55 // for (int i = computedUnit.types.size(); --i >= 0;){
56 // ((TypeDeclaration)computedUnit.types.get(i)).parseMethod(parser, computedUnit);
60 StringBuffer buffer = new StringBuffer(100);
61 if (compilationResult.hasProblems() || compilationResult.hasTasks()) {
62 IProblem[] problems = compilationResult.getAllProblems();
63 int count = problems.length;
65 char[] unitSource = compilationResult.compilationUnit.getContents();
66 for (int i = 0; i < count; i++) {
67 if (problems[i] != null) {
68 if (problemCount == 0)
69 buffer.append("----------\n");
71 buffer.append(problemCount + (problems[i].isError() ? ". ERROR" : ". WARNING"));
72 buffer.append(" in " + new String(problems[i].getOriginatingFileName()).replace('/', '\\'));
74 buffer.append(((DefaultProblem)problems[i]).errorReportSource(unitSource));
76 buffer.append(problems[i].getMessage());
78 } catch (Exception e) {
79 StringWriter stringWriter = new StringWriter();
80 e.printStackTrace(new PrintWriter(stringWriter));
81 buffer.append(stringWriter.getBuffer());
83 buffer.append("----------\n");
87 String computedSyntaxErrorDiagnosis = buffer.toString();
88 if(!expectedSyntaxErrorDiagnosis.equals(computedSyntaxErrorDiagnosis)) {
89 System.out.println(Util.displayString(computedSyntaxErrorDiagnosis));
92 "Invalid syntax error diagnosis",
93 expectedSyntaxErrorDiagnosis,
94 computedSyntaxErrorDiagnosis);
96 public void test01() {
98 "final class test {\n" +
100 "private function f1() {\n" +
103 "public function f2() {\n" +
109 String expectedSyntaxErrorDiagnosis =
112 String testName = "<test01>";
115 expectedSyntaxErrorDiagnosis);
118 public void test02() {
126 String expectedSyntaxErrorDiagnosis =
129 String testName = "<test02>";
132 expectedSyntaxErrorDiagnosis);
136 public void test97() {
139 " function &fetchRow($result, $fetchmode = DB_FETCHMODE_DEFAULT, $rownum=null) \n"+
144 String expectedSyntaxErrorDiagnosis =
149 expectedSyntaxErrorDiagnosis);
152 public void test98() {
154 "if(!$result = mysql_query($sql)) return(array());\n";
156 String expectedSyntaxErrorDiagnosis =
161 expectedSyntaxErrorDiagnosis);
165 public void test99() {
169 " function &fetchRow($result, $fetchmode = DB_FETCHMODE_DEFAULT, $rownum=null) \n"+
174 String expectedSyntaxErrorDiagnosis =
179 expectedSyntaxErrorDiagnosis);