]>
git.saurik.com Git - apple/javascriptcore.git/blob - tests/mozilla/ecma_3/RegExp/regress-188206.js
1 /* ***** BEGIN LICENSE BLOCK *****
2 * Version: NPL 1.1/GPL 2.0/LGPL 2.1
4 * The contents of this file are subject to the Netscape Public License
5 * Version 1.1 (the "License"); you may not use this file except in
6 * compliance with the License. You may obtain a copy of the License at
7 * http://www.mozilla.org/NPL/
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
14 * The Original Code is JavaScript Engine testing utilities.
16 * The Initial Developer of the Original Code is Netscape Communications Corp.
17 * Portions created by the Initial Developer are Copyright (C) 2003
18 * the Initial Developer. All Rights Reserved.
20 * Contributor(s): scole@planetweb.com, pschwartau@netscape.com
22 * Alternatively, the contents of this file may be used under the terms of
23 * either the GNU General Public License Version 2 or later (the "GPL"), or
24 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
25 * in which case the provisions of the GPL or the LGPL are applicable instead
26 * of those above. If you wish to allow use of your version of this file only
27 * under the terms of either the GPL or the LGPL, and not to allow others to
28 * use your version of this file under the terms of the NPL, indicate your
29 * decision by deleting the provisions above and replace them with the notice
30 * and other provisions required by the GPL or the LGPL. If you do not delete
31 * the provisions above, a recipient may use your version of this file under
32 * the terms of any one of the NPL, the GPL or the LGPL.
34 * ***** END LICENSE BLOCK *****
37 * Date: 21 January 2003
38 * SUMMARY: Invalid use of regexp quantifiers should generate SyntaxErrors
40 * See http://bugzilla.mozilla.org/show_bug.cgi?id=188206
41 * and http://bugzilla.mozilla.org/show_bug.cgi?id=85721#c48 etc.
42 * and http://bugzilla.mozilla.org/show_bug.cgi?id=190685
43 * and http://bugzilla.mozilla.org/show_bug.cgi?id=197451
45 //-----------------------------------------------------------------------------
48 var summary
= 'Invalid use of regexp quantifiers should generate SyntaxErrors';
49 var TEST_PASSED
= 'SyntaxError';
50 var TEST_FAILED
= 'Generated an error, but NOT a SyntaxError!';
51 var TEST_FAILED_BADLY
= 'Did not generate ANY error!!!';
52 var CHECK_PASSED
= 'Should not generate an error';
53 var CHECK_FAILED
= 'Generated an error!';
57 var actualvalues
= [];
59 var expectedvalues
= [];
63 * All the following are invalid uses of regexp quantifiers and
64 * should generate SyntaxErrors. That's what we're testing for.
66 * To allow the test to compile and run, we have to hide the errors
67 * inside eval strings, and check they are caught at run-time -
70 status
= inSection(1);
73 status
= inSection(2);
76 status
= inSection(3);
79 status
= inSection(4);
83 * The ? quantifier, unlike * or +, may appear twice in succession.
84 * Thus we need at least three in a row to provoke a SyntaxError -
87 status
= inSection(5);
90 status
= inSection(6);
91 testThis(' /a????/ ');
95 * Now do some weird things on the left side of the regexps -
97 status
= inSection(7);
100 status
= inSection(8);
103 status
= inSection(9);
106 status
= inSection(10);
109 status
= inSection(11);
112 status
= inSection(12);
117 * Misusing the {DecmalDigits} quantifier - according to ECMA,
118 * but not according to Perl.
120 * ECMA-262 Edition 3 prohibits the use of unescaped braces in
121 * regexp patterns, unless they form part of a quantifier.
123 * Hovever, Perl does not prohibit this. If not used as part
124 * of a quantifer, Perl treats braces literally.
126 * We decided to follow Perl on this for backward compatibility.
127 * See http://bugzilla.mozilla.org/show_bug.cgi?id=190685.
129 * Therefore NONE of the following ECMA violations should generate
130 * a SyntaxError. Note we use checkThis() instead of testThis().
132 status
= inSection(13);
133 checkThis(' /a*{/ ');
135 status
= inSection(14);
136 checkThis(' /a{}/ ');
138 status
= inSection(15);
141 status
= inSection(16);
144 status
= inSection(17);
145 checkThis(' /x{abc}/ ');
147 status
= inSection(18);
148 checkThis(' /{{0}/ ');
150 status
= inSection(19);
151 checkThis(' /{{1}/ ');
153 status
= inSection(20);
154 checkThis(' /x{{0}/ ');
156 status
= inSection(21);
157 checkThis(' /x{{1}/ ');
159 status
= inSection(22);
160 checkThis(' /x{{0}}/ ');
162 status
= inSection(23);
163 checkThis(' /x{{1}}/ ');
165 status
= inSection(24);
166 checkThis(' /x{{0}}/ ');
168 status
= inSection(25);
169 checkThis(' /x{{1}}/ ');
171 status
= inSection(26);
172 checkThis(' /x{{0}}/ ');
174 status
= inSection(27);
175 checkThis(' /x{{1}}/ ');
179 * Misusing the {DecmalDigits} quantifier - according to BOTH ECMA and Perl.
181 * Just as with the * and + quantifiers above, can't have two {DecmalDigits}
182 * quantifiers in succession - it's a SyntaxError.
184 status
= inSection(28);
185 testThis(' /x{1}{1}/ ');
187 status
= inSection(29);
188 testThis(' /x{1,}{1}/ ');
190 status
= inSection(30);
191 testThis(' /x{1,2}{1}/ ');
193 status
= inSection(31);
194 testThis(' /x{1}{1,}/ ');
196 status
= inSection(32);
197 testThis(' /x{1,}{1,}/ ');
199 status
= inSection(33);
200 testThis(' /x{1,2}{1,}/ ');
202 status
= inSection(34);
203 testThis(' /x{1}{1,2}/ ');
205 status
= inSection(35);
206 testThis(' /x{1,}{1,2}/ ');
208 status
= inSection(36);
209 testThis(' /x{1,2}{1,2}/ ');
213 //-----------------------------------------------------------------------------
215 //-----------------------------------------------------------------------------
220 * Invalid syntax should generate a SyntaxError
222 function testThis(sInvalidSyntax
)
224 expect
= TEST_PASSED
;
225 actual
= TEST_FAILED_BADLY
;
229 eval(sInvalidSyntax
);
233 if (e
instanceof SyntaxError
)
234 actual
= TEST_PASSED
;
236 actual
= TEST_FAILED
;
239 statusitems
[UBound
] = status
;
240 expectedvalues
[UBound
] = expect
;
241 actualvalues
[UBound
] = actual
;
247 * Allowed syntax shouldn't generate any errors
249 function checkThis(sAllowedSyntax
)
251 expect
= CHECK_PASSED
;
252 actual
= CHECK_PASSED
;
256 eval(sAllowedSyntax
);
260 actual
= CHECK_FAILED
;
263 statusitems
[UBound
] = status
;
264 expectedvalues
[UBound
] = expect
;
265 actualvalues
[UBound
] = actual
;
274 printStatus(summary
);
276 for (var i
=0; i
<UBound
; i
++)
278 reportCompare(expectedvalues
[i
], actualvalues
[i
], statusitems
[i
]);