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 //-----------------------------------------------------------------------------
53 var BUGNUMBER = 228087;
54 var summary = 'Testing regexps with unescaped braces';
56 var statusmessages = new Array();
58 var patterns = new Array();
60 var strings = new Array();
62 var actualmatches = new Array();
63 var expectedmatch = '';
64 var expectedmatches = new Array();
68 string = 'foo {1} foo {2} foo';
70 // try an example with the braces escaped
71 status = inSection(1);
74 pattern = new RegExp('\{1.*\}', 'g');
75 actualmatch = string.match(pattern);
82 expectedmatch = Array('{1} foo {2}');
85 // just like Section 1, without the braces being escaped
86 status = inSection(2);
89 pattern = new RegExp('{1.*}', 'g');
90 actualmatch = string.match(pattern);
97 expectedmatch = Array('{1} foo {2}');
100 // try an example with the braces escaped
101 status = inSection(3);
104 pattern = new RegExp('\{1[.!\}]*\}', 'g');
105 actualmatch = string.match(pattern);
112 expectedmatch = Array('{1}');
115 // just like Section 3, without the braces being escaped
116 status = inSection(4);
119 pattern = new RegExp('{1[.!}]*}', 'g');
120 actualmatch = string.match(pattern);
127 expectedmatch = Array('{1}');
131 string = 'abccccc{3 }c{ 3}c{3, }c{3 ,}c{3 ,4}c{3, 4}c{3,4 }de';
133 // use braces in a normal quantifier construct
134 status = inSection(5);
137 pattern = new RegExp('c{3}');
138 actualmatch = string.match(pattern);
145 expectedmatch = Array('ccc');
148 // now disrupt the quantifer - the braces should now be interpreted literally
149 status = inSection(6);
152 pattern = new RegExp('c{3 }');
153 actualmatch = string.match(pattern);
160 expectedmatch = Array('c{3 }');
163 status = inSection(7);
166 pattern = new RegExp('c{3.}');
167 actualmatch = string.match(pattern);
174 expectedmatch = Array('c{3 }');
177 status = inSection(8);
180 // need to escape the \ in \s since
181 // this has been converted to a constructor call
182 // instead of a literal regexp
183 pattern = new RegExp('c{3\\s}');
184 actualmatch = string.match(pattern);
191 expectedmatch = Array('c{3 }');
194 status = inSection(9);
197 pattern = new RegExp('c{3[ ]}');
198 actualmatch = string.match(pattern);
205 expectedmatch = Array('c{3 }');
208 status = inSection(10);
211 pattern = new RegExp('c{ 3}');
212 actualmatch = string.match(pattern);
219 expectedmatch = Array('c{ 3}');
222 // using braces in a normal quantifier construct again
223 status = inSection(11);
226 pattern = new RegExp('c{3,}');
227 actualmatch = string.match(pattern);
234 expectedmatch = Array('ccccc');
237 // now disrupt it - the braces should now be interpreted literally
238 status = inSection(12);
241 pattern = new RegExp('c{3, }');
242 actualmatch = string.match(pattern);
249 expectedmatch = Array('c{3, }');
252 status = inSection(13);
255 pattern = new RegExp('c{3 ,}');
256 actualmatch = string.match(pattern);
263 expectedmatch = Array('c{3 ,}');
266 // using braces in a normal quantifier construct again
267 status = inSection(14);
270 pattern = new RegExp('c{3,4}');
271 actualmatch = string.match(pattern);
278 expectedmatch = Array('cccc');
281 // now disrupt it - the braces should now be interpreted literally
282 status = inSection(15);
285 pattern = new RegExp('c{3 ,4}');
286 actualmatch = string.match(pattern);
293 expectedmatch = Array('c{3 ,4}');
296 status = inSection(16);
299 pattern = new RegExp('c{3, 4}');
300 actualmatch = string.match(pattern);
307 expectedmatch = Array('c{3, 4}');
310 status = inSection(17);
313 pattern = new RegExp('c{3,4 }');
314 actualmatch = string.match(pattern);
321 expectedmatch = Array('c{3,4 }');
327 //-------------------------------------------------------------------------------------------------
329 //-------------------------------------------------------------------------------------------------
335 statusmessages[i] = status;
336 patterns[i] = pattern;
338 actualmatches[i] = actualmatch;
339 expectedmatches[i] = expectedmatch;
347 printBugNumber(BUGNUMBER);
348 printStatus (summary);
349 testRegExp(statusmessages, patterns, strings, actualmatches, expectedmatches);