76d4a1063f9b99d74cb2f4a06b8d6dd15f3ad86f
[phpeclipse.git] / net.sourceforge.phpeclipse.tests / src / net / sourceforge / phpeclipse / phpeditor / php / test / DualParseSyntaxErrorTest.java
1 /*
2  * Created on 29.02.2004
3  *
4  * To change the template for this generated file go to
5  * Window - Preferences - Java - Code Generation - Code and Comments
6  */
7 package net.sourceforge.phpeclipse.phpeditor.php.test;
8
9 import java.io.PrintWriter;
10 import java.io.StringWriter;
11 import java.util.Locale;
12
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
26 /**
27  * @author khartlage
28  *
29  * To change the template for this generated type comment go to
30  * Window - Preferences - Java - Code Generation - Code and Comments
31  */
32 public class DualParseSyntaxErrorTest extends AbstractCompilerTest {
33                 public static boolean optimizeStringLiterals = false;
34                 
35         public DualParseSyntaxErrorTest(String testName){
36                 super(testName);
37         }
38         
39         public void test01() {
40                 String s = 
41                         "$login =1; " +
42                         "final class test {\n" + 
43                         "\n" + 
44                         "private function f1() {\n" + 
45                         "\n" + 
46                         "}\n" + 
47                         "public function f2() {\n" + 
48                         "\n" +
49                         "  \n" + 
50                         "}  \n" + 
51                         "}";    
52
53                 String expectedSyntaxErrorDiagnosis =
54                         "";
55
56                 String testName = "<test01>";
57                 checkParsePHP(
58                         s.toCharArray(),
59                         expectedSyntaxErrorDiagnosis);
60 //                      testName);
61         }
62         public void test02() {
63                 String s = 
64                         "class test {                                                       \n"+
65                         "       function f0() \n"+
66                         "       {                                                               \n"+
67                         "       }                                                                               \n"+
68                         "}                                                                                      \n";    
69
70                 String expectedSyntaxErrorDiagnosis =
71                         "";
72
73                 String testName = "<test02>";
74                 checkParsePHP(
75                         s.toCharArray(),
76                         expectedSyntaxErrorDiagnosis);
77 //                      testName);
78         }
79         public void test03() {
80           String s = 
81         "$chars = ( isset($HTTP_GET_VARS['chars']) ) ? intval($HTTP_GET_VARS['chars']) : 200;";
82         String expectedSyntaxErrorDiagnosis =
83                 "";
84
85         checkParsePHP(
86                 s.toCharArray(),
87                 expectedSyntaxErrorDiagnosis);
88 //              testName);
89 }
90         public void test96() {
91                 String s = "$str = <<<EOD\n" + "Example of string\n"
92         + "spanning multiple lines\n" + "using heredoc syntax.\n" + "EOD;\n"
93         + "\n" + "/* More complex example, with variables. */\n"
94         + "class foo\n" + "{\n" + "    var $foo;\n" + "    var $bar;\n" + "\n"
95         + "    function foo()\n" + "    {\n" + "        $this->foo = 'Foo';\n"
96         + "        $this->bar = array('Bar1', 'Bar2', 'Bar3');\n" + "    }\n"
97         + "}\n" + "\n" + "$foo = new foo();\n" + "$name = 'MyName';\n" + "\n"
98         + "echo <<<EOT\n"
99         + "My name is \"$name\". I am printing some $foo->foo.\n"
100         + "Now, I am printing some {$foo->bar[1]}.\n"
101         + "This should print a capital 'A': \\x41\n" + "EOT;\n";
102                 String expectedSyntaxErrorDiagnosis =
103                         "";
104
105                 checkParsePHP(
106                         s.toCharArray(),
107                         expectedSyntaxErrorDiagnosis);
108 //                      testName);
109         }
110         public void test97() {
111                 String s = 
112                         "class momo {                                                       \n"+
113                         "       function &fetchRow($result, $fetchmode = DB_FETCHMODE_DEFAULT, $rownum=null) \n"+
114                         "       {                                                               \n"+
115                         "       }                                                                               \n"+
116                         "}                                                                                      \n";    
117
118                 String expectedSyntaxErrorDiagnosis =
119                         "";
120
121                 checkParsePHP(
122                         s.toCharArray(),
123                         expectedSyntaxErrorDiagnosis);
124 //                      testName);
125         }
126         public void test98() {
127                 String s = 
128                   "return(array());"+
129                         "if(!$result = mysql_query($sql)) return(array());\n";  
130
131                 String expectedSyntaxErrorDiagnosis =
132                         "";
133
134                 checkParsePHP(
135                         s.toCharArray(),
136                         expectedSyntaxErrorDiagnosis);
137 //                      testName);
138         }
139         
140         public void test99() {
141                 String s = 
142                         "class test {                                                       \n"+
143                         "   murks;                                        \n"+
144                         "       function &fetchRow($result, $fetchmode = DB_FETCHMODE_DEFAULT, $rownum=null) \n"+
145                         "       {                                                               \n"+
146                         "       }                                                                               \n"+
147                         "}                                                                                      \n";    
148
149                 String expectedSyntaxErrorDiagnosis =
150                         "----------\n" + 
151                         "1. ERROR in  (at line 1)\n" + 
152                         "       murks;                                        \n" + 
153                         "       ^^^^^\n" + 
154                         "Parser error \"\'public\' \'private\' or \'protected\' modifier expected for field declarations.\"\n" + 
155                         "----------\n" + 
156                         "2. ERROR in  (at line 1)\n" + 
157                         "       }                                                                                       \n" + 
158                         "       ^\n" + 
159                         "Parser error \"Too many closing \'}\'; end-of-file not reached.\"\n" + 
160                         "----------\n";
161
162                 checkParsePHP(
163                         s.toCharArray(),
164                         expectedSyntaxErrorDiagnosis);
165 //                      testName);
166         }
167 }