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;
25 import net.sourceforge.phpeclipse.internal.compiler.ast.TypeDeclaration;
30 * To change the template for this generated type comment go to
31 * Window - Preferences - Java - Code Generation - Code and Comments
33 public class DualParseSyntaxErrorTest extends AbstractCompilerTest {
34 public static boolean optimizeStringLiterals = false;
36 public DualParseSyntaxErrorTest(String testName){
39 public void checkParse(
41 String expectedSyntaxErrorDiagnosis,
47 DefaultErrorHandlingPolicies.proceedWithAllProblems(),
48 //new CompilerOptions(getCompilerOptions()),
49 new DefaultProblemFactory(Locale.getDefault())));
51 ICompilationUnit sourceUnit = new CompilationUnit(source, testName, null);
52 CompilationResult compilationResult = new CompilationResult(sourceUnit, 0, 0, 0);
54 CompilationUnitDeclaration computedUnit = parser.dietParse(sourceUnit, compilationResult, true);
55 // if (computedUnit.types != null) {
56 // for (int i = computedUnit.types.size(); --i >= 0;){
57 // ((TypeDeclaration)computedUnit.types.get(i)).parseMethod(parser, computedUnit);
61 StringBuffer buffer = new StringBuffer(100);
62 if (compilationResult.hasProblems() || compilationResult.hasTasks()) {
63 IProblem[] problems = compilationResult.getAllProblems();
64 int count = problems.length;
66 char[] unitSource = compilationResult.compilationUnit.getContents();
67 for (int i = 0; i < count; i++) {
68 if (problems[i] != null) {
69 if (problemCount == 0)
70 buffer.append("----------\n");
72 buffer.append(problemCount + (problems[i].isError() ? ". ERROR" : ". WARNING"));
73 buffer.append(" in " + new String(problems[i].getOriginatingFileName()).replace('/', '\\'));
75 buffer.append(((DefaultProblem)problems[i]).errorReportSource(unitSource));
77 buffer.append(problems[i].getMessage());
79 } catch (Exception e) {
80 StringWriter stringWriter = new StringWriter();
81 e.printStackTrace(new PrintWriter(stringWriter));
82 buffer.append(stringWriter.getBuffer());
84 buffer.append("----------\n");
88 String computedSyntaxErrorDiagnosis = buffer.toString();
89 if(!expectedSyntaxErrorDiagnosis.equals(computedSyntaxErrorDiagnosis)) {
90 System.out.println(Util.displayString(computedSyntaxErrorDiagnosis));
93 "Invalid syntax error diagnosis" + testName,
94 expectedSyntaxErrorDiagnosis,
95 computedSyntaxErrorDiagnosis);
98 public void test01() {
101 " function &fetchRow($result, $fetchmode = DB_FETCHMODE_DEFAULT, $rownum=null) \n"+
106 String expectedSyntaxErrorDiagnosis =
108 "1. ERROR in <test1> (at line 1)\n" +
109 " class class { \n" +
111 "Parse error \"Don\'t use keyword for class declaration [class].\"\n" +
113 "2. ERROR in <test1> (at line 1)\n" +
114 " class class { \n" +
116 "Parse error \"Class name expected after keyword \'class\'.\"\n" +
119 String testName = "<test1>";
122 expectedSyntaxErrorDiagnosis,
126 public void test02() {
128 "if(!$result = mysql_query($sql)) return(array());\n";
130 String expectedSyntaxErrorDiagnosis =
133 String testName = "<test2>";
136 expectedSyntaxErrorDiagnosis,
140 public void test03() {
144 " function &fetchRow($result, $fetchmode = DB_FETCHMODE_DEFAULT, $rownum=null) \n"+
149 String expectedSyntaxErrorDiagnosis =
152 String testName = "<test3>";
155 expectedSyntaxErrorDiagnosis,