1 /* ***** BEGIN LICENSE BLOCK *****
2 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
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/
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
17 * Netscape Communications Corp.
18 * Portions created by the Initial Developer are Copyright (C) 2003
19 * the Initial Developer. All Rights Reserved.
22 * scole@planetweb.com, pschwartau@netscape.com
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.
36 * ***** END LICENSE BLOCK *****
39 * Date: 21 January 2003
40 * SUMMARY: Invalid use of regexp quantifiers should generate SyntaxErrors
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
47 //-----------------------------------------------------------------------------
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!';
59 var actualvalues = [];
61 var expectedvalues = [];
65 * All the following are invalid uses of regexp quantifiers and
66 * should generate SyntaxErrors. That's what we're testing for.
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 -
72 status = inSection(1);
75 status = inSection(2);
78 status = inSection(3);
81 status = inSection(4);
85 * The ? quantifier, unlike * or +, may appear twice in succession.
86 * Thus we need at least three in a row to provoke a SyntaxError -
89 status = inSection(5);
92 status = inSection(6);
93 testThis(' /a????/ ');
97 * Now do some weird things on the left side of the regexps -
99 status = inSection(7);
102 status = inSection(8);
105 status = inSection(9);
108 status = inSection(10);
111 status = inSection(11);
114 status = inSection(12);
119 * Misusing the {DecmalDigits} quantifier - according to ECMA,
120 * but not according to Perl.
122 * ECMA-262 Edition 3 prohibits the use of unescaped braces in
123 * regexp patterns, unless they form part of a quantifier.
125 * Hovever, Perl does not prohibit this. If not used as part
126 * of a quantifer, Perl treats braces literally.
128 * We decided to follow Perl on this for backward compatibility.
129 * See http://bugzilla.mozilla.org/show_bug.cgi?id=190685.
131 * Therefore NONE of the following ECMA violations should generate
132 * a SyntaxError. Note we use checkThis() instead of testThis().
134 status = inSection(13);
135 checkThis(' /a*{/ ');
137 status = inSection(14);
138 checkThis(' /a{}/ ');
140 status = inSection(15);
143 status = inSection(16);
146 status = inSection(17);
147 checkThis(' /x{abc}/ ');
149 status = inSection(18);
150 checkThis(' /{{0}/ ');
152 status = inSection(19);
153 checkThis(' /{{1}/ ');
155 status = inSection(20);
156 checkThis(' /x{{0}/ ');
158 status = inSection(21);
159 checkThis(' /x{{1}/ ');
161 status = inSection(22);
162 checkThis(' /x{{0}}/ ');
164 status = inSection(23);
165 checkThis(' /x{{1}}/ ');
167 status = inSection(24);
168 checkThis(' /x{{0}}/ ');
170 status = inSection(25);
171 checkThis(' /x{{1}}/ ');
173 status = inSection(26);
174 checkThis(' /x{{0}}/ ');
176 status = inSection(27);
177 checkThis(' /x{{1}}/ ');
181 * Misusing the {DecmalDigits} quantifier - according to BOTH ECMA and Perl.
183 * Just as with the * and + quantifiers above, can't have two {DecmalDigits}
184 * quantifiers in succession - it's a SyntaxError.
186 status = inSection(28);
187 testThis(' /x{1}{1}/ ');
189 status = inSection(29);
190 testThis(' /x{1,}{1}/ ');
192 status = inSection(30);
193 testThis(' /x{1,2}{1}/ ');
195 status = inSection(31);
196 testThis(' /x{1}{1,}/ ');
198 status = inSection(32);
199 testThis(' /x{1,}{1,}/ ');
201 status = inSection(33);
202 testThis(' /x{1,2}{1,}/ ');
204 status = inSection(34);
205 testThis(' /x{1}{1,2}/ ');
207 status = inSection(35);
208 testThis(' /x{1,}{1,2}/ ');
210 status = inSection(36);
211 testThis(' /x{1,2}{1,2}/ ');
215 //-----------------------------------------------------------------------------
217 //-----------------------------------------------------------------------------
222 * Invalid syntax should generate a SyntaxError
224 function testThis(sInvalidSyntax)
226 expect = TEST_PASSED;
227 actual = TEST_FAILED_BADLY;
231 eval(sInvalidSyntax);
235 if (e instanceof SyntaxError)
236 actual = TEST_PASSED;
238 actual = TEST_FAILED;
241 statusitems[UBound] = status;
242 expectedvalues[UBound] = expect;
243 actualvalues[UBound] = actual;
249 * Allowed syntax shouldn't generate any errors
251 function checkThis(sAllowedSyntax)
253 expect = CHECK_PASSED;
254 actual = CHECK_PASSED;
258 eval(sAllowedSyntax);
262 actual = CHECK_FAILED;
265 statusitems[UBound] = status;
266 expectedvalues[UBound] = expect;
267 actualvalues[UBound] = actual;
276 printStatus(summary);
278 for (var i=0; i<UBound; i++)
280 reportCompare(expectedvalues[i], actualvalues[i], statusitems[i]);