Debian Codegraph @

rhino/testsrc/tests/ecma_3/RegExp/regress-188206.js

raw symbols SCIP
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5
6 /*
7 *
8 * Date: 21 January 2003
9 * SUMMARY: Invalid use of regexp quantifiers should generate SyntaxErrors
10 *
11 * See http://bugzilla.mozilla.org/show_bug.cgi?id=188206
12 * and http://bugzilla.mozilla.org/show_bug.cgi?id=85721#c48 etc.
13 * and http://bugzilla.mozilla.org/show_bug.cgi?id=190685
14 * and http://bugzilla.mozilla.org/show_bug.cgi?id=197451
15 */
16 //-----------------------------------------------------------------------------
17 var gTestfile = 'regress-188206.js';
18 var UBound = 0;
19 var BUGNUMBER = 188206;
20 var summary = 'Invalid use of regexp quantifiers should generate SyntaxErrors';
21 var TEST_PASSED = 'SyntaxError';
22 var TEST_FAILED = 'Generated an error, but NOT a SyntaxError!';
23 var TEST_FAILED_BADLY = 'Did not generate ANY error!!!';
24 var CHECK_PASSED = 'Should not generate an error';
25 var CHECK_FAILED = 'Generated an error!';
26 var status = '';
27 var statusitems = [];
28 var actual = '';
29 var actualvalues = [];
30 var expect= '';
31 var expectedvalues = [];
32
33
34 /*
35 * All the following are invalid uses of regexp quantifiers and
36 * should generate SyntaxErrors. That's what we're testing for.
37 *
38 * To allow the test to compile and run, we have to hide the errors
39 * inside eval strings, and check they are caught at run-time -
40 *
41 */
42 status = inSection(1);
43 testThis(' /a**/ ');
44
45 status = inSection(2);
46 testThis(' /a***/ ');
47
48 status = inSection(3);
49 testThis(' /a++/ ');
50
51 status = inSection(4);
52 testThis(' /a+++/ ');
53
54 /*
55 * The ? quantifier, unlike * or +, may appear twice in succession.
56 * Thus we need at least three in a row to provoke a SyntaxError -
57 */
58
59 status = inSection(5);
60 testThis(' /a???/ ');
61
62 status = inSection(6);
63 testThis(' /a????/ ');
64
65
66 /*
67 * Now do some weird things on the left side of the regexps -
68 */
69 status = inSection(9);
70 testThis(' /+a/ ');
71
72 status = inSection(10);
73 testThis(' /++a/ ');
74
75 status = inSection(11);
76 testThis(' /?a/ ');
77
78 status = inSection(12);
79 testThis(' /??a/ ');
80
81
82 /*
83 * Misusing the {DecmalDigits} quantifier - according to BOTH ECMA and Perl.
84 *
85 * Just as with the * and + quantifiers above, can't have two {DecmalDigits}
86 * quantifiers in succession - it's a SyntaxError.
87 */
88 status = inSection(28);
89 testThis(' /x{1}{1}/ ');
90
91 status = inSection(29);
92 testThis(' /x{1,}{1}/ ');
93
94 status = inSection(30);
95 testThis(' /x{1,2}{1}/ ');
96
97 status = inSection(31);
98 testThis(' /x{1}{1,}/ ');
99
100 status = inSection(32);
101 testThis(' /x{1,}{1,}/ ');
102
103 status = inSection(33);
104 testThis(' /x{1,2}{1,}/ ');
105
106 status = inSection(34);
107 testThis(' /x{1}{1,2}/ ');
108
109 status = inSection(35);
110 testThis(' /x{1,}{1,2}/ ');
111
112 status = inSection(36);
113 testThis(' /x{1,2}{1,2}/ ');
114
115
116
117 //-----------------------------------------------------------------------------
118 test();
119 //-----------------------------------------------------------------------------
120
121
122
123 /*
124 * Invalid syntax should generate a SyntaxError
125 */
126 function testThis(sInvalidSyntax)
127 {
128 expect = TEST_PASSED;
129 actual = TEST_FAILED_BADLY;
130
131 try
132 {
133 eval(sInvalidSyntax);
134 }
135 catch(e)
136 {
137 if (e instanceof SyntaxError)
138 actual = TEST_PASSED;
139 else
140 actual = TEST_FAILED;
141 }
142
143 statusitems[UBound] = status;
144 expectedvalues[UBound] = expect;
145 actualvalues[UBound] = actual;
146 UBound++;
147 }
148
149
150 /*
151 * Allowed syntax shouldn't generate any errors
152 */
153 function checkThis(sAllowedSyntax)
154 {
155 expect = CHECK_PASSED;
156 actual = CHECK_PASSED;
157
158 try
159 {
160 eval(sAllowedSyntax);
161 }
162 catch(e)
163 {
164 actual = CHECK_FAILED;
165 }
166
167 statusitems[UBound] = status;
168 expectedvalues[UBound] = expect;
169 actualvalues[UBound] = actual;
170 UBound++;
171 }
172
173
174 function test()
175 {
176 enterFunc('test');
177 printBugNumber(BUGNUMBER);
178 printStatus(summary);
179
180 for (var i=0; i<UBound; i++)
181 {
182 reportCompare(expectedvalues[i], actualvalues[i], statusitems[i]);
183 }
184
185 exitFunc ('test');
186 }