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