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
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/
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
15 * The Original Code is JavaScript Engine testing utilities.
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.
23 * bex@xaotec.com, PhilSchwartau@aol.com
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.
37 * ***** END LICENSE BLOCK ***** */
41 * Date: 12 December 2003
42 * SUMMARY: Testing regexps with unescaped braces
43 * See http://bugzilla.mozilla.org/show_bug.cgi?id=228087
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.
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.
51 //-----------------------------------------------------------------------------
52 var gTestfile = 'regress-228087.js';
54 var BUGNUMBER = 228087;
55 var summary = 'Testing regexps with unescaped braces';
57 var statusmessages = new Array();
59 var patterns = new Array();
61 var strings = new Array();
63 var actualmatches = new Array();
64 var expectedmatch = '';
65 var expectedmatches = new Array();
69 string = 'foo {1} foo {2} foo';
71 // try an example with the braces escaped
72 status = inSection(1);
75 pattern = new RegExp('\{1.*\}', 'g');
76 actualmatch = string.match(pattern);
83 expectedmatch = Array('{1} foo {2}');
86 // just like Section 1, without the braces being escaped
87 status = inSection(2);
90 pattern = new RegExp('{1.*}', 'g');
91 actualmatch = string.match(pattern);
98 expectedmatch = Array('{1} foo {2}');
101 // try an example with the braces escaped
102 status = inSection(3);
105 pattern = new RegExp('\{1[.!\}]*\}', 'g');
106 actualmatch = string.match(pattern);
113 expectedmatch = Array('{1}');
116 // just like Section 3, without the braces being escaped
117 status = inSection(4);
120 pattern = new RegExp('{1[.!}]*}', 'g');
121 actualmatch = string.match(pattern);
128 expectedmatch = Array('{1}');
132 string = 'abccccc{3 }c{ 3}c{3, }c{3 ,}c{3 ,4}c{3, 4}c{3,4 }de';
134 // use braces in a normal quantifier construct
135 status = inSection(5);
138 pattern = new RegExp('c{3}');
139 actualmatch = string.match(pattern);
146 expectedmatch = Array('ccc');
149 // now disrupt the quantifer - the braces should now be interpreted literally
150 status = inSection(6);
153 pattern = new RegExp('c{3 }');
154 actualmatch = string.match(pattern);
161 expectedmatch = Array('c{3 }');
164 status = inSection(7);
167 pattern = new RegExp('c{3.}');
168 actualmatch = string.match(pattern);
175 expectedmatch = Array('c{3 }');
178 status = inSection(8);
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);
192 expectedmatch = Array('c{3 }');
195 status = inSection(9);
198 pattern = new RegExp('c{3[ ]}');
199 actualmatch = string.match(pattern);
206 expectedmatch = Array('c{3 }');
209 status = inSection(10);
212 pattern = new RegExp('c{ 3}');
213 actualmatch = string.match(pattern);
220 expectedmatch = Array('c{ 3}');
223 // using braces in a normal quantifier construct again
224 status = inSection(11);
227 pattern = new RegExp('c{3,}');
228 actualmatch = string.match(pattern);
235 expectedmatch = Array('ccccc');
238 // now disrupt it - the braces should now be interpreted literally
239 status = inSection(12);
242 pattern = new RegExp('c{3, }');
243 actualmatch = string.match(pattern);
250 expectedmatch = Array('c{3, }');
253 status = inSection(13);
256 pattern = new RegExp('c{3 ,}');
257 actualmatch = string.match(pattern);
264 expectedmatch = Array('c{3 ,}');
267 // using braces in a normal quantifier construct again
268 status = inSection(14);
271 pattern = new RegExp('c{3,4}');
272 actualmatch = string.match(pattern);
279 expectedmatch = Array('cccc');
282 // now disrupt it - the braces should now be interpreted literally
283 status = inSection(15);
286 pattern = new RegExp('c{3 ,4}');
287 actualmatch = string.match(pattern);
294 expectedmatch = Array('c{3 ,4}');
297 status = inSection(16);
300 pattern = new RegExp('c{3, 4}');
301 actualmatch = string.match(pattern);
308 expectedmatch = Array('c{3, 4}');
311 status = inSection(17);
314 pattern = new RegExp('c{3,4 }');
315 actualmatch = string.match(pattern);
322 expectedmatch = Array('c{3,4 }');
328 //-------------------------------------------------------------------------------------------------
330 //-------------------------------------------------------------------------------------------------
336 statusmessages[i] = status;
337 patterns[i] = pattern;
339 actualmatches[i] = actualmatch;
340 expectedmatches[i] = expectedmatch;
348 printBugNumber(BUGNUMBER);
349 printStatus (summary);
350 testRegExp(statusmessages, patterns, strings, actualmatches, expectedmatches);