misc
[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 net.sourceforge.phpdt.core.tests.util.AbstractCompilerTest;
10
11 public class DualParseSyntaxErrorTest extends AbstractCompilerTest {
12                 public static boolean optimizeStringLiterals = false;
13                 
14         public DualParseSyntaxErrorTest(String testName){
15                 super(testName);
16         }
17         
18         public void test01() {
19                 String s = 
20                         "$login =1; " +
21                         "final class test {\n" + 
22                         "\n" + 
23                         "private function f1() {\n" + 
24                         "\n" + 
25                         "}\n" + 
26                         "public function f2() {\n" + 
27                         "\n" +
28                         "  \n" + 
29                         "}  \n" + 
30                         "}";    
31
32                 String expectedSyntaxErrorDiagnosis =
33                         "";
34
35                 String testName = "<test01>";
36                 checkParsePHP(
37                         s.toCharArray(),
38                         expectedSyntaxErrorDiagnosis);
39 //                      testName);
40         }
41         public void test02() {
42                 String s = 
43                         "class test {                                                       \n"+
44                         "       function f0() \n"+
45                         "       {                                                               \n"+
46                         "       }                                                                               \n"+
47                         "}                                                                                      \n";    
48
49                 String expectedSyntaxErrorDiagnosis =
50                         "";
51
52                 String testName = "<test02>";
53                 checkParsePHP(
54                         s.toCharArray(),
55                         expectedSyntaxErrorDiagnosis);
56 //                      testName);
57         }
58         public void test03() {
59           String s = 
60         "$chars = ( isset($HTTP_GET_VARS['chars']) ) ? intval($HTTP_GET_VARS['chars']) : 200;";
61         String expectedSyntaxErrorDiagnosis =
62                 "";
63
64         checkParsePHP(
65                 s.toCharArray(),
66                 expectedSyntaxErrorDiagnosis);
67 //              testName);
68 }
69         public void test96() {
70                 String s = "$str = <<<EOD\n" + "Example of string\n"
71         + "spanning multiple lines\n" + "using heredoc syntax.\n" + "EOD;\n"
72         + "\n" + "/* More complex example, with variables. */\n"
73         + "class foo\n" + "{\n" + "    var $foo;\n" + "    var $bar;\n" + "\n"
74         + "    function foo()\n" + "    {\n" + "        $this->foo = 'Foo';\n"
75         + "        $this->bar = array('Bar1', 'Bar2', 'Bar3');\n" + "    }\n"
76         + "}\n" + "\n" + "$foo = new foo();\n" + "$name = 'MyName';\n" + "\n"
77         + "echo <<<EOT\n"
78         + "My name is \"$name\". I am printing some $foo->foo.\n"
79         + "Now, I am printing some {$foo->bar[1]}.\n"
80         + "This should print a capital 'A': \\x41\n" + "EOT;\n";
81                 String expectedSyntaxErrorDiagnosis =
82                         "";
83
84                 checkParsePHP(
85                         s.toCharArray(),
86                         expectedSyntaxErrorDiagnosis);
87 //                      testName);
88         }
89         public void test97() {
90                 String s = 
91                         "class momo {                                                       \n"+
92                         "       function &fetchRow($result, $fetchmode = DB_FETCHMODE_DEFAULT, $rownum=null) \n"+
93                         "       {                                                               \n"+
94                         "       }                                                                               \n"+
95                         "}                                                                                      \n";    
96
97                 String expectedSyntaxErrorDiagnosis =
98                         "";
99
100                 checkParsePHP(
101                         s.toCharArray(),
102                         expectedSyntaxErrorDiagnosis);
103 //                      testName);
104         }
105         public void test98() {
106                 String s = 
107                   "return(array());"+
108                         "if(!$result = mysql_query($sql)) return(array());\n";  
109
110                 String expectedSyntaxErrorDiagnosis =
111                         "";
112
113                 checkParsePHP(
114                         s.toCharArray(),
115                         expectedSyntaxErrorDiagnosis);
116 //                      testName);
117         }
118         
119         public void test99() {
120                 String s = 
121                         "class test {                                                       \n"+
122                         "   murks;                                        \n"+
123                         "       function &fetchRow($result, $fetchmode = DB_FETCHMODE_DEFAULT, $rownum=null) \n"+
124                         "       {                                                               \n"+
125                         "       }                                                                               \n"+
126                         "}                                                                                      \n";    
127
128                 String expectedSyntaxErrorDiagnosis =
129                         "----------\n" + 
130                         "1. ERROR in  (at line 1)\n" + 
131                         "       murks;                                        \n" + 
132                         "       ^^^^^\n" + 
133                         "Parser error \"\'public\' \'private\' or \'protected\' modifier expected for field declarations.\"\n" + 
134                         "----------\n" + 
135                         "2. ERROR in  (at line 1)\n" + 
136                         "       }                                                                                       \n" + 
137                         "       ^\n" + 
138                         "Parser error \"Too many closing \'}\'; end-of-file not reached.\"\n" + 
139                         "----------\n";
140
141                 checkParsePHP(
142                         s.toCharArray(),
143                         expectedSyntaxErrorDiagnosis);
144 //                      testName);
145         }
146 }