misc parser changes
[phpeclipse.git] / net.sourceforge.phpeclipse.tests / src / net / sourceforge / phpeclipse / phpeditor / php / test / DualParseSyntaxErrorTest.java
index 09830f3..76d4a10 100644 (file)
@@ -35,66 +35,10 @@ public class DualParseSyntaxErrorTest extends AbstractCompilerTest {
        public DualParseSyntaxErrorTest(String testName){
                super(testName);
        }
-       public void checkParse(
-               char[] source, 
-               String expectedSyntaxErrorDiagnosis) {
-//             String testName) {
-
-               UnitParser parser = 
-                       new UnitParser(
-                               new ProblemReporter(
-                                       DefaultErrorHandlingPolicies.proceedWithAllProblems(), 
-                                       //new CompilerOptions(getCompilerOptions()), 
-                                       new DefaultProblemFactory(Locale.getDefault())));
-
-               ICompilationUnit sourceUnit = new CompilationUnit(source, "", null);
-               CompilationResult compilationResult = new CompilationResult(sourceUnit, 0, 0, 0);       
-               
-               CompilationUnitDeclaration computedUnit = parser.dietParse(sourceUnit, compilationResult, true);
-//             if (computedUnit.types != null) {
-//                     for (int i = computedUnit.types.size(); --i >= 0;){
-//                             ((TypeDeclaration)computedUnit.types.get(i)).parseMethod(parser, computedUnit);
-//                     }
-//             }
-
-               StringBuffer buffer = new StringBuffer(100);
-               if (compilationResult.hasProblems() || compilationResult.hasTasks()) {
-                       IProblem[] problems = compilationResult.getAllProblems();
-                       int count = problems.length;
-                       int problemCount = 0;
-                       char[] unitSource = compilationResult.compilationUnit.getContents();
-                       for (int i = 0; i < count; i++) { 
-                               if (problems[i] != null) {
-                                       if (problemCount == 0)
-                                               buffer.append("----------\n");
-                                       problemCount++;
-                                       buffer.append(problemCount + (problems[i].isError() ? ". ERROR" : ". WARNING"));
-                                       buffer.append(" in " + new String(problems[i].getOriginatingFileName()).replace('/', '\\'));
-                                       try {
-                                               buffer.append(((DefaultProblem)problems[i]).errorReportSource(unitSource));
-                                               buffer.append("\n");
-                                               buffer.append(problems[i].getMessage());
-                                               buffer.append("\n");
-                                       } catch (Exception e) {
-                                               StringWriter stringWriter = new StringWriter();
-                                               e.printStackTrace(new PrintWriter(stringWriter));
-                                               buffer.append(stringWriter.getBuffer());
-                                       }
-                                       buffer.append("----------\n");
-                               }
-                       }
-               }
-               String computedSyntaxErrorDiagnosis = buffer.toString();
-               if(!expectedSyntaxErrorDiagnosis.equals(computedSyntaxErrorDiagnosis)) {
-                       System.out.println(Util.displayString(computedSyntaxErrorDiagnosis));
-               }
-               assertEquals(
-                       "Invalid syntax error diagnosis",
-                       expectedSyntaxErrorDiagnosis,
-                       computedSyntaxErrorDiagnosis);
-       }
+       
        public void test01() {
                String s = 
+                       "$login =1; " +
                        "final class test {\n" + 
                        "\n" + 
                        "private function f1() {\n" + 
@@ -110,7 +54,7 @@ public class DualParseSyntaxErrorTest extends AbstractCompilerTest {
                        "";
 
                String testName = "<test01>";
-               checkParse(
+               checkParsePHP(
                        s.toCharArray(),
                        expectedSyntaxErrorDiagnosis);
 //                     testName);
@@ -127,12 +71,42 @@ public class DualParseSyntaxErrorTest extends AbstractCompilerTest {
                        "";
 
                String testName = "<test02>";
-               checkParse(
+               checkParsePHP(
+                       s.toCharArray(),
+                       expectedSyntaxErrorDiagnosis);
+//                     testName);
+       }
+       public void test03() {
+         String s = 
+       "$chars = ( isset($HTTP_GET_VARS['chars']) ) ? intval($HTTP_GET_VARS['chars']) : 200;";
+       String expectedSyntaxErrorDiagnosis =
+               "";
+
+       checkParsePHP(
+               s.toCharArray(),
+               expectedSyntaxErrorDiagnosis);
+//             testName);
+}
+       public void test96() {
+               String s = "$str = <<<EOD\n" + "Example of string\n"
+        + "spanning multiple lines\n" + "using heredoc syntax.\n" + "EOD;\n"
+        + "\n" + "/* More complex example, with variables. */\n"
+        + "class foo\n" + "{\n" + "    var $foo;\n" + "    var $bar;\n" + "\n"
+        + "    function foo()\n" + "    {\n" + "        $this->foo = 'Foo';\n"
+        + "        $this->bar = array('Bar1', 'Bar2', 'Bar3');\n" + "    }\n"
+        + "}\n" + "\n" + "$foo = new foo();\n" + "$name = 'MyName';\n" + "\n"
+        + "echo <<<EOT\n"
+        + "My name is \"$name\". I am printing some $foo->foo.\n"
+        + "Now, I am printing some {$foo->bar[1]}.\n"
+        + "This should print a capital 'A': \\x41\n" + "EOT;\n";
+               String expectedSyntaxErrorDiagnosis =
+                       "";
+
+               checkParsePHP(
                        s.toCharArray(),
                        expectedSyntaxErrorDiagnosis);
 //                     testName);
        }
-       
        public void test97() {
                String s = 
                        "class momo {                                                       \n"+
@@ -144,19 +118,20 @@ public class DualParseSyntaxErrorTest extends AbstractCompilerTest {
                String expectedSyntaxErrorDiagnosis =
                        "";
 
-               checkParse(
+               checkParsePHP(
                        s.toCharArray(),
                        expectedSyntaxErrorDiagnosis);
 //                     testName);
        }
        public void test98() {
                String s = 
+                 "return(array());"+
                        "if(!$result = mysql_query($sql)) return(array());\n";  
 
                String expectedSyntaxErrorDiagnosis =
                        "";
 
-               checkParse(
+               checkParsePHP(
                        s.toCharArray(),
                        expectedSyntaxErrorDiagnosis);
 //                     testName);
@@ -172,9 +147,19 @@ public class DualParseSyntaxErrorTest extends AbstractCompilerTest {
                        "}                                                                                      \n";    
 
                String expectedSyntaxErrorDiagnosis =
-                       "";
-
-               checkParse(
+                       "----------\n" + 
+                       "1. ERROR in  (at line 1)\n" + 
+                       "       murks;                                        \n" + 
+                       "       ^^^^^\n" + 
+                       "Parser error \"\'public\' \'private\' or \'protected\' modifier expected for field declarations.\"\n" + 
+                       "----------\n" + 
+                       "2. ERROR in  (at line 1)\n" + 
+                       "       }                                                                                       \n" + 
+                       "       ^\n" + 
+                       "Parser error \"Too many closing \'}\'; end-of-file not reached.\"\n" + 
+                       "----------\n";
+
+               checkParsePHP(
                        s.toCharArray(),
                        expectedSyntaxErrorDiagnosis);
 //                     testName);