QML_RUNTIME_TESTING should be disabled by default.
[profile/ivi/qtdeclarative.git] / tests / auto / declarative / parserstress / tests / ecma_3 / extensions / regress-228087.js
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4 *
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
9 *
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
13 * License.
14 *
15 * The Original Code is JavaScript Engine testing utilities.
16 *
17 * The Initial Developer of the Original Code is
18 * Netscape Communications Corp.
19 * Portions created by the Initial Developer are Copyright (C) 2003
20 * the Initial Developer. All Rights Reserved.
21 *
22 * Contributor(s):
23 *   bex@xaotec.com, PhilSchwartau@aol.com
24 *
25 * Alternatively, the contents of this file may be used under the terms of
26 * either the GNU General Public License Version 2 or later (the "GPL"), or
27 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28 * in which case the provisions of the GPL or the LGPL are applicable instead
29 * of those above. If you wish to allow use of your version of this file only
30 * under the terms of either the GPL or the LGPL, and not to allow others to
31 * use your version of this file under the terms of the MPL, indicate your
32 * decision by deleting the provisions above and replace them with the notice
33 * and other provisions required by the GPL or the LGPL. If you do not delete
34 * the provisions above, a recipient may use your version of this file under
35 * the terms of any one of the MPL, the GPL or the LGPL.
36 *
37 * ***** END LICENSE BLOCK ***** */
38
39 /*
40  *
41  * Date:    12 December 2003
42  * SUMMARY: Testing regexps with unescaped braces
43  * See http://bugzilla.mozilla.org/show_bug.cgi?id=228087
44  *
45  * Note: unbalanced, unescaped braces are not permitted by ECMA-262 Ed.3,
46  * but we decided to follow Perl and IE and allow this for compatibility.
47  *
48  * See http://bugzilla.mozilla.org/show_bug.cgi?id=188206 and its testcase.
49  * See http://bugzilla.mozilla.org/show_bug.cgi?id=223273 and its testcase.
50  */
51 //-----------------------------------------------------------------------------
52 var gTestfile = 'regress-228087.js';
53 var i = 0;
54 var BUGNUMBER = 228087;
55 var summary = 'Testing regexps with unescaped braces';
56 var status = '';
57 var statusmessages = new Array();
58 var pattern = '';
59 var patterns = new Array();
60 var string = '';
61 var strings = new Array();
62 var actualmatch = '';
63 var actualmatches = new Array();
64 var expectedmatch = '';
65 var expectedmatches = new Array();
66 var e;
67
68
69 string = 'foo {1} foo {2} foo';
70
71 // try an example with the braces escaped
72 status = inSection(1);
73 try
74 {
75   pattern = new RegExp('\{1.*\}', 'g');
76   actualmatch = string.match(pattern);
77 }
78 catch (e)
79 {
80   pattern = 'error';
81   actualmatch = '';
82 }
83 expectedmatch = Array('{1} foo {2}');
84 addThis();
85
86 // just like Section 1, without the braces being escaped
87 status = inSection(2);
88 try
89 {
90   pattern = new RegExp('{1.*}', 'g');
91   actualmatch = string.match(pattern);
92 }
93 catch (e)
94 {
95   pattern = 'error';
96   actualmatch = '';
97 }
98 expectedmatch = Array('{1} foo {2}');
99 addThis();
100
101 // try an example with the braces escaped
102 status = inSection(3);
103 try
104 {
105   pattern = new RegExp('\{1[.!\}]*\}', 'g');
106   actualmatch = string.match(pattern);
107 }
108 catch (e)
109 {
110   pattern = 'error';
111   actualmatch = '';
112 }
113 expectedmatch = Array('{1}');
114 addThis();
115
116 // just like Section 3, without the braces being escaped
117 status = inSection(4);
118 try
119 {
120   pattern = new RegExp('{1[.!}]*}', 'g');
121   actualmatch = string.match(pattern);
122 }
123 catch (e)
124 {
125   pattern = 'error';
126   actualmatch = '';
127 }
128 expectedmatch = Array('{1}');
129 addThis();
130
131
132 string = 'abccccc{3 }c{ 3}c{3, }c{3 ,}c{3 ,4}c{3, 4}c{3,4 }de';
133
134 // use braces in a normal quantifier construct
135 status = inSection(5);
136 try
137 {
138   pattern = new RegExp('c{3}');
139   actualmatch = string.match(pattern);
140 }
141 catch (e)
142 {
143   pattern = 'error';
144   actualmatch = '';
145 }
146 expectedmatch = Array('ccc');
147 addThis();
148
149 // now disrupt the quantifer - the braces should now be interpreted literally
150 status = inSection(6);
151 try
152 {
153   pattern = new RegExp('c{3 }');
154   actualmatch = string.match(pattern);
155 }
156 catch (e)
157 {
158   pattern = 'error';
159   actualmatch = '';
160 }
161 expectedmatch = Array('c{3 }');
162 addThis();
163
164 status = inSection(7);
165 try
166 {
167   pattern = new RegExp('c{3.}');
168   actualmatch = string.match(pattern);
169 }
170 catch (e)
171 {
172   pattern = 'error';
173   actualmatch = '';
174 }
175 expectedmatch = Array('c{3 }');
176 addThis();
177
178 status = inSection(8);
179 try
180 {
181   // need to escape the \ in \s since
182   // this has been converted to a constructor call
183   // instead of a literal regexp
184   pattern = new RegExp('c{3\\s}');
185   actualmatch = string.match(pattern);
186 }
187 catch (e)
188 {
189   pattern = 'error';
190   actualmatch = '';
191 }
192 expectedmatch = Array('c{3 }');
193 addThis();
194
195 status = inSection(9);
196 try
197 {
198   pattern = new RegExp('c{3[ ]}');
199   actualmatch = string.match(pattern);
200 }
201 catch (e)
202 {
203   pattern = 'error';
204   actualmatch = '';
205 }
206 expectedmatch = Array('c{3 }');
207 addThis();
208
209 status = inSection(10);
210 try
211 {
212   pattern = new RegExp('c{ 3}');
213   actualmatch = string.match(pattern);
214 }
215 catch (e)
216 {
217   pattern = 'error';
218   actualmatch = '';
219 }
220 expectedmatch = Array('c{ 3}');
221 addThis();
222
223 // using braces in a normal quantifier construct again
224 status = inSection(11);
225 try
226 {
227   pattern = new RegExp('c{3,}');
228   actualmatch = string.match(pattern);
229 }
230 catch (e)
231 {
232   pattern = 'error';
233   actualmatch = '';
234 }
235 expectedmatch = Array('ccccc');
236 addThis();
237
238 // now disrupt it - the braces should now be interpreted literally
239 status = inSection(12);
240 try
241 {
242   pattern = new RegExp('c{3, }');
243   actualmatch = string.match(pattern);
244 }
245 catch (e)
246 {
247   pattern = 'error';
248   actualmatch = '';
249 }
250 expectedmatch = Array('c{3, }');
251 addThis();
252
253 status = inSection(13);
254 try
255 {
256   pattern = new RegExp('c{3 ,}');
257   actualmatch = string.match(pattern);
258 }
259 catch (e)
260 {
261   pattern = 'error';
262   actualmatch = '';
263 }
264 expectedmatch = Array('c{3 ,}');
265 addThis();
266
267 // using braces in a normal quantifier construct again
268 status = inSection(14);
269 try
270 {
271   pattern = new RegExp('c{3,4}');
272   actualmatch = string.match(pattern);
273 }
274 catch (e)
275 {
276   pattern = 'error';
277   actualmatch = '';
278 }
279 expectedmatch = Array('cccc');
280 addThis();
281
282 // now disrupt it - the braces should now be interpreted literally
283 status = inSection(15);
284 try
285 {
286   pattern = new RegExp('c{3 ,4}');
287   actualmatch = string.match(pattern);
288 }
289 catch (e)
290 {
291   pattern = 'error';
292   actualmatch = '';
293 }
294 expectedmatch = Array('c{3 ,4}');
295 addThis();
296
297 status = inSection(16);
298 try
299 {
300   pattern = new RegExp('c{3, 4}');
301   actualmatch = string.match(pattern);
302 }
303 catch (e)
304 {
305   pattern = 'error';
306   actualmatch = '';
307 }
308 expectedmatch = Array('c{3, 4}');
309 addThis();
310
311 status = inSection(17);
312 try
313 {
314   pattern = new RegExp('c{3,4 }');
315   actualmatch = string.match(pattern);
316 }
317 catch (e)
318 {
319   pattern = 'error';
320   actualmatch = '';
321 }
322 expectedmatch = Array('c{3,4 }');
323 addThis();
324
325
326
327
328 //-------------------------------------------------------------------------------------------------
329 test();
330 //-------------------------------------------------------------------------------------------------
331
332
333
334 function addThis()
335 {
336   statusmessages[i] = status;
337   patterns[i] = pattern;
338   strings[i] = string;
339   actualmatches[i] = actualmatch;
340   expectedmatches[i] = expectedmatch;
341   i++;
342 }
343
344
345 function test()
346 {
347   enterFunc ('test');
348   printBugNumber(BUGNUMBER);
349   printStatus (summary);
350   testRegExp(statusmessages, patterns, strings, actualmatches, expectedmatches);
351   exitFunc ('test');
352 }