* roottypes.cs: Rename from tree.cs.
[mono.git] / mcs / class / Microsoft.JScript / Test / Mozilla / ecma_3 / RegExp / regress-188206.js
1 /* ***** BEGIN LICENSE BLOCK *****
2  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
3  *
4  * The contents of this file are subject to the Mozilla Public License Version
5  * 1.1 (the "License"); you may not use this file except in compliance with
6  * the License. You may obtain a copy of the License at
7  * http://www.mozilla.org/MPL/
8  *
9  * Software distributed under the License is distributed on an "AS IS" basis,
10  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
11  * for the specific language governing rights and limitations under the
12  * License.
13  *
14  * The Original Code is JavaScript Engine testing utilities.
15  *
16  * The Initial Developer of the Original Code is
17  * Netscape Communications Corp.
18  * Portions created by the Initial Developer are Copyright (C) 2003
19  * the Initial Developer. All Rights Reserved.
20  *
21  * Contributor(s):
22  *   scole@planetweb.com, pschwartau@netscape.com
23  *
24  * Alternatively, the contents of this file may be used under the terms of
25  * either the GNU General Public License Version 2 or later (the "GPL"), or
26  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27  * in which case the provisions of the GPL or the LGPL are applicable instead
28  * of those above. If you wish to allow use of your version of this file only
29  * under the terms of either the GPL or the LGPL, and not to allow others to
30  * use your version of this file under the terms of the MPL, indicate your
31  * decision by deleting the provisions above and replace them with the notice
32  * and other provisions required by the GPL or the LGPL. If you do not delete
33  * the provisions above, a recipient may use your version of this file under
34  * the terms of any one of the MPL, the GPL or the LGPL.
35  *
36  * ***** END LICENSE BLOCK *****
37  *
38  *
39  * Date:    21 January 2003
40  * SUMMARY: Invalid use of regexp quantifiers should generate SyntaxErrors
41  *
42  * See http://bugzilla.mozilla.org/show_bug.cgi?id=188206
43  * and http://bugzilla.mozilla.org/show_bug.cgi?id=85721#c48 etc.
44  * and http://bugzilla.mozilla.org/show_bug.cgi?id=190685
45  * and http://bugzilla.mozilla.org/show_bug.cgi?id=197451
46  */
47 //-----------------------------------------------------------------------------
48 var UBound = 0;
49 var bug = 188206;
50 var summary = 'Invalid use of regexp quantifiers should generate SyntaxErrors';
51 var TEST_PASSED = 'SyntaxError';
52 var TEST_FAILED = 'Generated an error, but NOT a SyntaxError!';
53 var TEST_FAILED_BADLY = 'Did not generate ANY error!!!';
54 var CHECK_PASSED = 'Should not generate an error';
55 var CHECK_FAILED = 'Generated an error!';
56 var status = '';
57 var statusitems = [];
58 var actual = '';
59 var actualvalues = [];
60 var expect= '';
61 var expectedvalues = [];
62
63
64 /*
65  * All the following are invalid uses of regexp quantifiers and
66  * should generate SyntaxErrors. That's what we're testing for.
67  *
68  * To allow the test to compile and run, we have to hide the errors
69  * inside eval strings, and check they are caught at run-time -
70  *
71  */
72 status = inSection(1);
73 testThis(' /a**/ ');
74
75 status = inSection(2);
76 testThis(' /a***/ ');
77
78 status = inSection(3);
79 testThis(' /a++/ ');
80
81 status = inSection(4);
82 testThis(' /a+++/ ');
83
84 /*
85  * The ? quantifier, unlike * or +, may appear twice in succession.
86  * Thus we need at least three in a row to provoke a SyntaxError -
87  */
88
89 status = inSection(5);
90 testThis(' /a???/ ');
91
92 status = inSection(6);
93 testThis(' /a????/ ');
94
95
96 /*
97  * Now do some weird things on the left side of the regexps -
98  */
99 status = inSection(7);
100 testThis(' /*a/ ');
101
102 status = inSection(8);
103 testThis(' /**a/ ');
104
105 status = inSection(9);
106 testThis(' /+a/ ');
107
108 status = inSection(10);
109 testThis(' /++a/ ');
110
111 status = inSection(11);
112 testThis(' /?a/ ');
113
114 status = inSection(12);
115 testThis(' /??a/ ');
116
117
118 /*
119  * Misusing the {DecmalDigits} quantifier - according to ECMA,
120  * but not according to Perl.
121  *
122  * ECMA-262 Edition 3 prohibits the use of unescaped braces in
123  * regexp patterns, unless they form part of a quantifier.
124  *
125  * Hovever, Perl does not prohibit this. If not used as part
126  * of a quantifer, Perl treats braces literally.
127  *
128  * We decided to follow Perl on this for backward compatibility.
129  * See http://bugzilla.mozilla.org/show_bug.cgi?id=190685.
130  *
131  * Therefore NONE of the following ECMA violations should generate
132  * a SyntaxError. Note we use checkThis() instead of testThis().
133  */
134 status = inSection(13);
135 checkThis(' /a*{/ ');
136
137 status = inSection(14);
138 checkThis(' /a{}/ ');
139
140 status = inSection(15);
141 checkThis(' /{a/ ');
142
143 status = inSection(16);
144 checkThis(' /}a/ ');
145
146 status = inSection(17);
147 checkThis(' /x{abc}/ ');
148
149 status = inSection(18);
150 checkThis(' /{{0}/ ');
151
152 status = inSection(19);
153 checkThis(' /{{1}/ ');
154
155 status = inSection(20);
156 checkThis(' /x{{0}/ ');
157
158 status = inSection(21);
159 checkThis(' /x{{1}/ ');
160
161 status = inSection(22);
162 checkThis(' /x{{0}}/ ');
163
164 status = inSection(23);
165 checkThis(' /x{{1}}/ ');
166
167 status = inSection(24);
168 checkThis(' /x{{0}}/ ');
169
170 status = inSection(25);
171 checkThis(' /x{{1}}/ ');
172
173 status = inSection(26);
174 checkThis(' /x{{0}}/ ');
175
176 status = inSection(27);
177 checkThis(' /x{{1}}/ ');
178
179
180 /*
181  * Misusing the {DecmalDigits} quantifier - according to BOTH ECMA and Perl.
182  *
183  * Just as with the * and + quantifiers above, can't have two {DecmalDigits}
184  * quantifiers in succession - it's a SyntaxError.
185  */
186 status = inSection(28);
187 testThis(' /x{1}{1}/ ');
188
189 status = inSection(29);
190 testThis(' /x{1,}{1}/ ');
191
192 status = inSection(30);
193 testThis(' /x{1,2}{1}/ ');
194
195 status = inSection(31);
196 testThis(' /x{1}{1,}/ ');
197
198 status = inSection(32);
199 testThis(' /x{1,}{1,}/ ');
200
201 status = inSection(33);
202 testThis(' /x{1,2}{1,}/ ');
203
204 status = inSection(34);
205 testThis(' /x{1}{1,2}/ ');
206
207 status = inSection(35);
208 testThis(' /x{1,}{1,2}/ ');
209
210 status = inSection(36);
211 testThis(' /x{1,2}{1,2}/ ');
212
213
214
215 //-----------------------------------------------------------------------------
216 test();
217 //-----------------------------------------------------------------------------
218
219
220
221 /*
222  * Invalid syntax should generate a SyntaxError
223  */
224 function testThis(sInvalidSyntax)
225 {
226   expect = TEST_PASSED;
227   actual = TEST_FAILED_BADLY;
228
229   try
230   {
231     eval(sInvalidSyntax);
232   }
233   catch(e)
234   {
235     if (e instanceof SyntaxError)
236       actual = TEST_PASSED;
237     else
238       actual = TEST_FAILED;
239   }
240
241   statusitems[UBound] = status;
242   expectedvalues[UBound] = expect;
243   actualvalues[UBound] = actual;
244   UBound++;
245 }
246
247
248 /*
249  * Allowed syntax shouldn't generate any errors
250  */
251 function checkThis(sAllowedSyntax)
252 {
253   expect = CHECK_PASSED;
254   actual = CHECK_PASSED;
255
256   try
257   {
258     eval(sAllowedSyntax);
259   }
260   catch(e)
261   {
262     actual = CHECK_FAILED;
263   }
264
265   statusitems[UBound] = status;
266   expectedvalues[UBound] = expect;
267   actualvalues[UBound] = actual;
268   UBound++;
269 }
270
271
272 function test()
273 {
274   enterFunc('test');
275   printBugNumber(bug);
276   printStatus(summary);
277
278   for (var i=0; i<UBound; i++)
279   {
280     reportCompare(expectedvalues[i], actualvalues[i], statusitems[i]);
281   }
282
283   exitFunc ('test');
284 }