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() {
100 String expectedSyntaxErrorDiagnosis =
103 String testName = "<test01>";
106 expectedSyntaxErrorDiagnosis);
109 public void test02() {
117 String expectedSyntaxErrorDiagnosis =
120 String testName = "<test02>";
123 expectedSyntaxErrorDiagnosis);
127 public void test97() {
130 " function &fetchRow($result, $fetchmode = DB_FETCHMODE_DEFAULT, $rownum=null) \n"+
135 String expectedSyntaxErrorDiagnosis =
137 "1. ERROR in <test1> (at line 1)\n" +
138 " class class { \n" +
140 "Parse error \"Don\'t use keyword for class declaration [class].\"\n" +
142 "2. ERROR in <test1> (at line 1)\n" +
143 " class class { \n" +
145 "Parse error \"Class name expected after keyword \'class\'.\"\n" +
150 expectedSyntaxErrorDiagnosis);
153 public void test98() {
155 "if(!$result = mysql_query($sql)) return(array());\n";
157 String expectedSyntaxErrorDiagnosis =
162 expectedSyntaxErrorDiagnosis);
166 public void test99() {
170 " function &fetchRow($result, $fetchmode = DB_FETCHMODE_DEFAULT, $rownum=null) \n"+
175 String expectedSyntaxErrorDiagnosis =
180 expectedSyntaxErrorDiagnosis);