• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// Copyright JS Foundation and other contributors, http://js.foundation
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15var result = /\0/.exec("\u0000");
16assert (result !== null);
17assert (result[0] === "\u0000");
18
19result = /\0/u.exec("\u0000");
20assert (result !== null);
21assert (result[0] === "\u0000");
22
23result = /\000/.exec("\u0000");
24assert (result !== null);
25assert (result[0] === "\u0000");
26
27try {
28  new RegExp("\\000", 'u').exec("\u0000");
29  assert (false);
30} catch (e) {
31  assert (e instanceof SyntaxError);
32}
33
34result = /\0000/.exec("\u0000\u0030");
35assert (result !== null);
36assert (result[0] === "\u0000\u0030");
37
38result = /\377/.exec("\u00ff");
39assert (result !== null);
40assert (result[0] === "\u00ff");
41
42try {
43  new RegExp("\\377", 'u').exec("\u00ff");
44  assert (false);
45} catch (e) {
46  assert (e instanceof SyntaxError);
47}
48
49result = /\3777/.exec("\u00ff\u0037");
50assert (result !== null);
51assert (result[0] === "\u00ff\u0037");
52
53try {
54  new RegExp("\\3777", 'u').exec("\u00ff\u0037");
55  assert (false);
56} catch (e) {
57  assert (e instanceof SyntaxError);
58}
59
60result = /\400/.exec("\u0020\u0030");
61assert (result !== null);
62assert (result[0] === "\u0020\u0030");
63
64try {
65  new RegExp("\\400", 'u').exec("\u0020\u0030");
66  assert (false);
67} catch (e) {
68  assert (e instanceof SyntaxError);
69}
70
71result = /(\1)/.exec("\u0001");
72assert (result !== null);
73assert (result[0].length === 0);
74
75result = /(\1)/u.exec("\u0001");
76assert (result !== null);
77assert (result[0].length === 0);
78
79result = /(\2)/.exec("\u0002");
80assert (result !== null);
81assert (result[0] === '\u0002');
82
83try {
84  new RegExp("(\\2)", 'u').exec("\u0002");
85  assert (false);
86} catch (e) {
87  assert (e instanceof SyntaxError);
88}
89
90result = /\8/.exec("\u0038");
91assert (result !== null);
92assert (result[0] === '8');
93
94result = /\99/.exec("\u0039\u0039");
95assert (result !== null);
96assert (result[0] === "99");
97
98// CharClassEscape
99assert (/\d+/.exec("123")[0] === "123");
100assert (/\D+/.exec("abc")[0] === "abc");
101assert (/\s+/.exec("   ")[0] === "   ");
102assert (/\S+/.exec("abc")[0] === "abc");
103assert (/\w+/.exec("abc")[0] === "abc");
104assert (/\W+/.exec("|||")[0] === "|||");
105assert (/\d+/u.exec("123")[0] === "123");
106assert (/\D+/u.exec("abc")[0] === "abc");
107assert (/\s+/u.exec("   ")[0] === "   ");
108assert (/\S+/u.exec("abc")[0] === "abc");
109assert (/\w+/u.exec("abc")[0] === "abc");
110assert (/\W+/u.exec("|||")[0] === "|||");
111
112assert (/\d+/u.exec("\u{10CAF}") === null);
113assert (/\D+/u.exec("\u{10CAF}")[0] === "\u{10CAF}");
114assert (/\s+/u.exec("\u{10CAF}") === null);
115assert (/\S+/u.exec("\u{10CAF}")[0] === "\u{10CAF}");
116assert (/\w+/u.exec("\u{10CAF}") === null);
117assert (/\W+/u.exec("\u{10CAF}")[0] === "\u{10CAF}");
118
119result = /\xz/.exec("xz");
120assert (result !== null);
121assert (result[0] === "xz");
122
123try {
124  new RegExp("\\xz", "u").exec("xz");
125  assert (false);
126} catch (e) {
127  assert (e instanceof SyntaxError);
128}
129
130result = /\c/.exec("\\c");
131assert (result !== null);
132assert (result[0] === "\\c");
133
134try {
135  new RegExp("\\c", 'u').exec("\\c")
136  assert (false);
137} catch (e) {
138  assert (e instanceof SyntaxError);
139}
140
141result = /\c1/.exec("\\c1");
142assert (result !== null);
143assert (result[0] === "\\c1");
144
145try {
146  new RegExp("\\c1", 'u').exec("\\c1");
147  assert (false);
148} catch (e) {
149  assert (e instanceof SyntaxError);
150}
151
152try {
153  new RegExp("^+");
154  assert (false);
155} catch (e) {
156  assert (e instanceof SyntaxError);
157}
158
159try {
160  new RegExp("$+");
161  assert (false);
162} catch (e) {
163  assert (e instanceof SyntaxError);
164}
165
166try {
167  new RegExp("\\b+");
168  assert (false);
169} catch (e) {
170  assert (e instanceof SyntaxError);
171}
172
173try {
174  new RegExp("\\B+");
175  assert (false);
176} catch (e) {
177  assert (e instanceof SyntaxError);
178}
179
180assert (/[\b]/.exec("\u0008")[0] === "\u0008");
181assert (/[\b]/u.exec("\u0008")[0] === "\u0008");
182assert (/[\B]/.exec("\u0042")[0] === "\u0042");
183
184try {
185  new RegExp ("[\\B]", 'u').exec("\u0042");
186  assert (false);
187} catch (e) {
188  assert (e instanceof SyntaxError);
189}
190
191assert (/[\c1]/.exec("\u0011")[0] === "\u0011");
192assert (/[\c_]/.exec("\u001f")[0] === "\u001f");
193assert (/[\c]/.exec("\\")[0] === "\\");
194assert (/[\c]/.exec("c")[0] === "c");
195
196try {
197  new RegExp("[\\c1]", 'u');
198  assert (false);
199} catch (e) {
200  assert (e instanceof SyntaxError);
201}
202
203try {
204  new RegExp("[\\c]", 'u');
205  assert (false);
206} catch (e) {
207  assert (e instanceof SyntaxError);
208}
209
210try {
211  new RegExp("[\\c_]", 'u');
212  assert (false);
213} catch (e) {
214  assert (e instanceof SyntaxError);
215}
216
217assert (/{{1,2}/.exec("{{")[0] === "{{");
218
219try {
220  new RegExp("{{1,2}", 'u').exec("{{");
221  assert (false);
222} catch (e) {
223  assert (e instanceof SyntaxError);
224}
225
226assert (/a{1,2/.exec("a{1,2")[0] === "a{1,2");
227
228try {
229  new RegExp("a{1,2", 'u').exec("a{1,2");
230  assert (false);
231} catch (e) {
232  assert (e instanceof SyntaxError);
233}
234
235assert (/\u017f/i.exec("s") === null);
236assert (/\u017f/ui.exec("s")[0] === "s");
237
238assert (/��/.exec("��")[0] === "��");
239assert (/��/u.exec("��")[0] === "��");
240assert (/��*?/.exec("��")[0] === "\ud803");
241assert (/��*?/u.exec("��")[0] === "");
242assert (/��+/.exec("������")[0] === "��");
243assert (/��+/u.exec("������")[0] === "������");
244
245assert (/\ud803\udc96*?/.exec("��")[0] === '\ud803');
246assert (/\ud803\udc96*?/u.exec("��")[0] === '');
247assert (/\ud803\udc96+/.exec("������")[0] === '��');
248assert (/\ud803\udc96+/u.exec("������")[0] === '������');
249
250assert (/.*����/u.exec("������������")[0] === '������������');
251
252assert (/[\u{10000}]/.exec("\u{10000}") === null);
253assert (/[\u{10000}]/.exec("{")[0] === "{");
254assert (/[^\u{10000}]/.exec("\u{10000}")[0] === "\ud800");
255assert (/[^\u{10000}]/.exec("{") === null);
256
257assert (/[\uffff]/.exec("\uffff")[0] === "\uffff");
258assert (/[^\uffff]/.exec("\uffff") === null);
259
260assert (/[\u{10000}]/u.exec("\u{10000}")[0] === "\u{10000}");
261assert (/[\u{10000}]/u.exec("{") === null);
262assert (/[^\u{10000}]/u.exec("\u{10000}") === null);
263assert (/[^\u{10000}]/u.exec("{")[0] === "{");
264
265assert (/[\uffff]/u.exec("\uffff")[0] === "\uffff");
266assert (/[^\uffff]/u.exec("\uffff") === null);
267
268assert (/a{4294967296,4294967297}/.exec("aaaa") === null);
269assert (/a{4294967294,4294967295}/.exec("aaaa") === null);
270assert (/a{0000000000000000001,0000000000000000002}/u.exec("aaaa")[0] === 'aa');
271assert (/(\4294967297)/.exec("\4294967297")[0] === "\4294967297");
272assert (/(\1)/u.exec("aaaa")[0] === "");
273
274try {
275  new RegExp("a{4294967295,4294967294}", '');
276  assert (false);
277} catch (e) {
278  assert (e instanceof SyntaxError);
279}
280
281assert (/[\d-\s]/.exec("-")[0] === "-");
282assert (/[0-\s]/.exec("-")[0] === "-");
283assert (/[\d-0]/.exec("-")[0] === "-");
284
285try {
286  new RegExp("[\\d-\\s]", 'u').exec("-");
287  assert (false);
288} catch (e) {
289  assert (e instanceof SyntaxError);
290}
291
292try {
293  new RegExp("[0-\\s]", 'u').exec("-");
294  assert (false);
295} catch (e) {
296  assert (e instanceof SyntaxError);
297}
298
299try {
300  new RegExp("[\\d-0]", 'u').exec("-");
301  assert (false);
302} catch (e) {
303  assert (e instanceof SyntaxError);
304}
305
306assert (/[-]/.exec("-")[0] === "-");
307assert (/[-]/u.exec("-")[0] === "-");
308assert (/[--]/.exec("-")[0] === "-");
309assert (/[--]/u.exec("-")[0] === "-");
310
311assert (/}/.exec("}")[0] === "}");
312assert (/\}/u.exec("}")[0] === "}");
313
314try {
315  new RegExp("}", 'u').exec("}");
316  assert (false);
317} catch (e) {
318  assert (e instanceof SyntaxError);
319}
320
321assert (/]/.exec("]")[0] === "]");
322assert (/\]/u.exec("]")[0] === "]");
323
324try {
325  new RegExp("]", 'u').exec("]");
326  assert (false);
327} catch (e) {
328  assert (e instanceof SyntaxError);
329}
330
331assert (/(?=)*/.exec("")[0] === "");
332assert (/(?=)+/.exec("")[0] === "");
333assert (/(?=){1,2}/.exec("")[0] === "");
334
335try {
336  new RegExp("(?=)*", 'u');
337  assert (false);
338} catch (e) {
339  assert (e instanceof SyntaxError);
340}
341
342try {
343  new RegExp("(?=)+", 'u');
344  assert (false);
345} catch (e) {
346  assert (e instanceof SyntaxError);
347}
348
349try {
350  new RegExp("(?=){1,2}", 'u');
351  assert (false);
352} catch (e) {
353  assert (e instanceof SyntaxError);
354}
355
356try {
357  new RegExp("(?=){2,1}", '');
358  assert (false);
359} catch (e) {
360  assert (e instanceof SyntaxError);
361}
362