[ADVAPI32_WINETEST] Revert service.c changes from 3c1b7834e1 to avoid testbot hangs...
[reactos.git] / modules / rostests / winetests / jscript / regexp.js
1 /*
2 * Copyright 2008 Jacek Caban for CodeWeavers
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
17 */
18
19
20 var m, re, b, i, obj;
21
22 ok(RegExp.leftContext === "", "RegExp.leftContext = " + RegExp.leftContext);
23 RegExp.leftContext = "abc";
24 ok(RegExp.leftContext === "", "RegExp.leftContext = " + RegExp.leftContext);
25
26 re = /a+/;
27 ok(re.lastIndex === 0, "re.lastIndex = " + re.lastIndex);
28
29 m = re.exec(" aabaaa");
30 ok(re.lastIndex === 3, "re.lastIndex = " + re.lastIndex);
31 ok(m.index === 1, "m.index = " + m.index);
32 ok(m.input === " aabaaa", "m.input = " + m.input);
33 ok(m.length === 1, "m.length = " + m.length);
34 ok(m[0] === "aa", "m[0] = " + m[0]);
35 ok(RegExp.leftContext === " ", "RegExp.leftContext = " + RegExp.leftContext);
36 ok(RegExp.rightContext === "baaa", "RegExp.rightContext = " + RegExp.rightContext);
37
38 m = re.exec(" aabaaa");
39 ok(re.lastIndex === 3, "re.lastIndex = " + re.lastIndex);
40 ok(m.index === 1, "m.index = " + m.index);
41 ok(m.input === " aabaaa", "m.input = " + m.input);
42 ok(m.length === 1, "m.length = " + m.length);
43 ok(m[0] === "aa", "m[0] = " + m[0]);
44 ok(m.propertyIsEnumerable("0"), "m.0 is not enumerable");
45 ok(m.propertyIsEnumerable("input"), "m.input is not enumerable");
46 ok(m.propertyIsEnumerable("index"), "m.index is not enumerable");
47 ok(m.propertyIsEnumerable("lastIndex"), "m.lastIndex is not enumerable");
48 ok(m.propertyIsEnumerable("length") === false, "m.length is not enumerable");
49 ok(RegExp.leftContext === " ", "RegExp.leftContext = " + RegExp.leftContext);
50 ok(RegExp.rightContext === "baaa", "RegExp.rightContext = " + RegExp.rightContext);
51
52 m = /^[^<]*(<(.|\s)+>)[^>]*$|^#(\w+)$/.exec(
53 "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
54 ok(m === null, "m is not null");
55
56 re = /a+/g;
57 ok(re.lastIndex === 0, "re.lastIndex = " + re.lastIndex);
58
59 m = re.exec(" aabaaa");
60 ok(re.lastIndex === 3, "re.lastIndex = " + re.lastIndex);
61 ok(m.index === 1, "m.index = " + m.index);
62 ok(m.lastIndex == 3, "m.lastIndex = " + m.lastIndex);
63 ok(m.input === " aabaaa", "m.input = " + m.input);
64 ok(m.length === 1, "m.length = " + m.length);
65 ok(m[0] === "aa", "m[0] = " + m[0]);
66
67 m = re.exec(" aabaaa");
68 ok(re.lastIndex === 7, "re.lastIndex = " + re.lastIndex);
69 ok(m.index === 4, "m.index = " + m.index);
70 ok(m.input === " aabaaa", "m.input = " + m.input);
71 ok(m.length === 1, "m.length = " + m.length);
72 ok(m[0] === "aaa", "m[0] = " + m[0]);
73
74 m = re.exec(" aabaaa");
75 ok(re.lastIndex === 0, "re.lastIndex = " + re.lastIndex);
76 ok(m === null, "m is not null");
77
78 re.exec(" a");
79 ok(re.lastIndex === 16, "re.lastIndex = " + re.lastIndex);
80 ok(RegExp.leftContext === " ",
81 "RegExp.leftContext = " + RegExp.leftContext);
82 ok(RegExp.rightContext === "", "RegExp.rightContext = " + RegExp.rightContext);
83
84 m = re.exec(" a");
85 ok(m === null, "m is not null");
86 ok(re.lastIndex === 0, "re.lastIndex = " + re.lastIndex);
87
88 m = re.exec(" a");
89 ok(re.lastIndex === 2, "re.lastIndex = " + re.lastIndex);
90
91 m = re.exec();
92 ok(m === null, "m is not null");
93 ok(re.lastIndex === 0, "re.lastIndex = " + re.lastIndex);
94
95 m = /(a|b)+|(c)/.exec("aa");
96 ok(m[0] === "aa", "m[0] = " + m[0]);
97 ok(m[1] === "a", "m[1] = " + m[1]);
98 ok(m[2] === "", "m[2] = " + m[2]);
99
100 b = re.test(" a ");
101 ok(b === true, "re.test(' a ') returned " + b);
102 ok(re.lastIndex === 3, "re.lastIndex = " + re.lastIndex);
103 ok(RegExp.leftContext === " ", "RegExp.leftContext = " + RegExp.leftContext);
104 ok(RegExp.rightContext === " ", "RegExp.rightContext = " + RegExp.rightContext);
105
106 b = re.test(" a ");
107 ok(b === false, "re.test(' a ') returned " + b);
108 ok(re.lastIndex === 0, "re.lastIndex = " + re.lastIndex);
109 ok(RegExp.leftContext === " ", "RegExp.leftContext = " + RegExp.leftContext);
110 ok(RegExp.rightContext === " ", "RegExp.rightContext = " + RegExp.rightContext);
111
112 re = /\[([^\[]+)\]/g;
113 m = re.exec(" [test] ");
114 ok(re.lastIndex === 7, "re.lastIndex = " + re.lastIndex);
115 ok(m.index === 1, "m.index = " + m.index);
116 ok(m.input === " [test] ", "m.input = " + m.input);
117 ok(m.length === 2, "m.length = " + m.length);
118 ok(m[0] === "[test]", "m[0] = " + m[0]);
119 ok(m[1] === "test", "m[1] = " + m[1]);
120
121 b = /a*/.test();
122 ok(b === true, "/a*/.test() returned " + b);
123 ok(RegExp.leftContext === "", "RegExp.leftContext = " + RegExp.leftContext);
124 ok(RegExp.rightContext === "undefined", "RegExp.rightContext = " + RegExp.rightContext);
125
126 b = /f/.test();
127 ok(b === true, "/f/.test() returned " + b);
128 ok(RegExp.leftContext === "unde", "RegExp.leftContext = " + RegExp.leftContext);
129 ok(RegExp.rightContext === "ined", "RegExp.rightContext = " + RegExp.rightContext);
130
131 b = /abc/.test();
132 ok(b === false, "/abc/.test() returned " + b);
133 ok(RegExp.leftContext === "unde", "RegExp.leftContext = " + RegExp.leftContext);
134 ok(RegExp.rightContext === "ined", "RegExp.rightContext = " + RegExp.rightContext);
135
136 m = "abcabc".match(re = /ca/);
137 ok(typeof(m) === "object", "typeof m is not object");
138 ok(m.length === 1, "m.length is not 1");
139 ok(m["0"] === "ca", "m[0] is not \"ca\"");
140 ok(m.constructor === Array, "unexpected m.constructor");
141 ok(re.lastIndex === 4, "re.lastIndex = " + re.lastIndex);
142 ok(RegExp.leftContext === "ab", "RegExp.leftContext = " + RegExp.leftContext);
143 ok(RegExp.rightContext === "bc", "RegExp.rightContext = " + RegExp.rightContext);
144
145 m = "abcabc".match(/ab/);
146 ok(typeof(m) === "object", "typeof m is not object");
147 ok(m.length === 1, "m.length is not 1");
148 ok(m["0"] === "ab", "m[0] is not \"ab\"");
149 ok(RegExp.leftContext === "", "RegExp.leftContext = " + RegExp.leftContext);
150 ok(RegExp.rightContext === "cabc", "RegExp.rightContext = " + RegExp.rightContext);
151
152 m = "abcabc".match(/ab/g);
153 ok(typeof(m) === "object", "typeof m is not object");
154 ok(m.length === 2, "m.length is not 2");
155 ok(m["0"] === "ab", "m[0] is not \"ab\"");
156 ok(m["1"] === "ab", "m[1] is not \"ab\"");
157 /* ok(m.input === "abcabc", "m.input = " + m.input); */
158
159 m = "abcabc".match(/Ab/g);
160 ok(typeof(m) === "object", "typeof m is not object");
161 ok(m === null, "m is not null");
162
163 m = "abcabc".match(/Ab/gi);
164 ok(typeof(m) === "object", "typeof m is not object");
165 ok(m.length === 2, "m.length is not 2");
166 ok(m["0"] === "ab", "m[0] is not \"ab\"");
167 ok(m["1"] === "ab", "m[1] is not \"ab\"");
168 ok(RegExp.leftContext === "abc", "RegExp.leftContext = " + RegExp.leftContext);
169 ok(RegExp.rightContext === "c", "RegExp.rightContext = " + RegExp.rightContext);
170
171 m = "aaabcabc".match(/a+b/g);
172 ok(typeof(m) === "object", "typeof m is not object");
173 ok(m.length === 2, "m.length is not 2");
174 ok(m["0"] === "aaab", "m[0] is not \"ab\"");
175 ok(m["1"] === "ab", "m[1] is not \"ab\"");
176
177 m = "aaa\\\\cabc".match(/\\/g);
178 ok(typeof(m) === "object", "typeof m is not object");
179 ok(m.length === 2, "m.length is not 2");
180 ok(m["0"] === "\\", "m[0] is not \"\\\"");
181 ok(m["1"] === "\\", "m[1] is not \"\\\"");
182
183 m = "abcabc".match(new RegExp("ab"));
184 ok(typeof(m) === "object", "typeof m is not object");
185 ok(m.length === 1, "m.length is not 1");
186 ok(m["0"] === "ab", "m[0] is not \"ab\"");
187
188 m = "abcabc".match(new RegExp("ab","g"));
189 ok(typeof(m) === "object", "typeof m is not object");
190 ok(m.length === 2, "m.length is not 2");
191 ok(m["0"] === "ab", "m[0] is not \"ab\"");
192 ok(m["1"] === "ab", "m[1] is not \"ab\"");
193 ok(RegExp.leftContext === "abc", "RegExp.leftContext = " + RegExp.leftContext);
194 ok(RegExp.rightContext === "c", "RegExp.rightContext = " + RegExp.rightContext);
195
196 m = "abcabc".match(new RegExp(/ab/g));
197 ok(typeof(m) === "object", "typeof m is not object");
198 ok(m.length === 2, "m.length is not 2");
199 ok(m["0"] === "ab", "m[0] is not \"ab\"");
200 ok(m["1"] === "ab", "m[1] is not \"ab\"");
201
202 m = "abcabc".match(new RegExp("ab","g", "test"));
203 ok(typeof(m) === "object", "typeof m is not object");
204 ok(m.length === 2, "m.length is not 2");
205 ok(m["0"] === "ab", "m[0] is not \"ab\"");
206 ok(m["1"] === "ab", "m[1] is not \"ab\"");
207 ok(m.index === 3, "m.index = " + m.index);
208 ok(m.input === "abcabc", "m.input = " + m.input);
209 ok(m.lastIndex === 5, "m.lastIndex = " + m.lastIndex);
210
211 m = "abcabcg".match("ab", "g");
212 ok(typeof(m) === "object", "typeof m is not object");
213 ok(m.length === 1, "m.length is not 1");
214 ok(m["0"] === "ab", "m[0] is not \"ab\"");
215 ok(RegExp.leftContext === "", "RegExp.leftContext = " + RegExp.leftContext);
216 ok(RegExp.rightContext === "cabcg", "RegExp.rightContext = " + RegExp.rightContext);
217
218 m = "abcabc".match();
219 ok(m === null, "m is not null");
220 ok(RegExp.leftContext === "", "RegExp.leftContext = " + RegExp.leftContext);
221 ok(RegExp.rightContext === "cabcg", "RegExp.rightContext = " + RegExp.rightContext);
222
223 m = "abcabc".match(/(a)(b)cabc/);
224 ok(typeof(m) === "object", "typeof m is not object");
225 ok(m.length === 3, "m.length is not 3");
226 ok(m[0] === "abcabc", "m[0] is not \"abc\"");
227 ok(m[1] === "a", "m[1] is not \"a\"");
228 ok(m[2] === "b", "m[2] is not \"b\"");
229
230 re = /(a)bcabc/;
231 re.lastIndex = -3;
232 m = "abcabc".match(re);
233 ok(typeof(m) === "object", "typeof m is not object");
234 ok(m.length === 2, "m.length = " + m.length + "expected 3");
235 ok(m[0] === "abcabc", "m[0] is not \"abc\"");
236 ok(m[1] === "a", "m[1] is not \"a\"");
237 ok(re.lastIndex === 6, "re.lastIndex = " + re.lastIndex);
238
239 re = /(a)bcabc/;
240 re.lastIndex = 2;
241 m = "abcabcxxx".match(re);
242 ok(typeof(m) === "object", "typeof m is not object");
243 ok(m.length === 2, "m.length = " + m.length + "expected 3");
244 ok(m[0] === "abcabc", "m[0] is not \"abc\"");
245 ok(m[1] === "a", "m[1] is not \"a\"");
246 ok(m.input === "abcabcxxx", "m.input = " + m.input);
247 ok(re.lastIndex === 6, "re.lastIndex = " + re.lastIndex);
248
249 r = "- [test] -".replace(re = /\[([^\[]+)\]/g, "success");
250 ok(r === "- success -", "r = " + r + " expected '- success -'");
251 ok(re.lastIndex === 8, "re.lastIndex = " + re.lastIndex);
252 ok(RegExp.leftContext === "- ", "RegExp.leftContext = " + RegExp.leftContext);
253 ok(RegExp.rightContext === " -", "RegExp.rightContext = " + RegExp.rightContext);
254
255 r = "[test] [test]".replace(/\[([^\[]+)\]/g, "aa");
256 ok(r === "aa aa", "r = " + r + "aa aa");
257 ok(RegExp.leftContext === "[test] ",
258 "RegExp.leftContext = " + RegExp.leftContext);
259 ok(RegExp.rightContext === "",
260 "RegExp.rightContext = " + RegExp.rightContext);
261
262 r = "[test] [test]".replace(/\[([^\[]+)\]/, "aa");
263 ok(r === "aa [test]", "r = " + r + " expected 'aa [test]'");
264
265 r = "- [test] -".replace(/\[([^\[]+)\]/g);
266 ok(r === "- undefined -", "r = " + r + " expected '- undefined -'");
267
268 r = "- [test] -".replace(/\[([^\[]+)\]/g, true);
269 ok(r === "- true -", "r = " + r + " expected '- true -'");
270
271 r = "- [test] -".replace(/\[([^\[]+)\]/g, true, "test");
272 ok(r === "- true -", "r = " + r + " expected '- true -'");
273 ok(RegExp.leftContext === "- ", "RegExp.leftContext = " + RegExp.leftContext);
274 ok(RegExp.rightContext === " -", "RegExp.rightContext = " + RegExp.rightContext);
275
276 var tmp = 0;
277
278 function replaceFunc1(m, off, str) {
279 ok(arguments.length === 3, "arguments.length = " + arguments.length);
280
281 switch(tmp) {
282 case 0:
283 ok(m === "[test1]", "m = " + m + " expected [test1]");
284 ok(off === 0, "off = " + off + " expected 0");
285 ok(RegExp.leftContext === "- ",
286 "RegExp.leftContext = " + RegExp.leftContext);
287 ok(RegExp.rightContext === " -",
288 "RegExp.rightContext = " + RegExp.rightContext);
289 break;
290 case 1:
291 ok(m === "[test2]", "m = " + m + " expected [test2]");
292 ok(off === 8, "off = " + off + " expected 8");
293 ok(RegExp.leftContext === "- ",
294 "RegExp.leftContext = " + RegExp.leftContext);
295 ok(RegExp.rightContext === " -",
296 "RegExp.rightContext = " + RegExp.rightContext);
297 break;
298 default:
299 ok(false, "unexpected call");
300 }
301
302 ok(str === "[test1] [test2]", "str = " + arguments[3]);
303 return "r" + tmp++;
304 }
305
306 r = "[test1] [test2]".replace(/\[[^\[]+\]/g, replaceFunc1);
307 ok(r === "r0 r1", "r = " + r + " expected 'r0 r1'");
308 ok(RegExp.leftContext === "[test1] ", "RegExp.leftContext = " + RegExp.leftContext);
309 ok(RegExp.rightContext === "", "RegExp.rightContext = " + RegExp.rightContext);
310
311 tmp = 0;
312
313 function replaceFunc2(m, subm, off, str) {
314 ok(arguments.length === 4, "arguments.length = " + arguments.length);
315
316 switch(tmp) {
317 case 0:
318 ok(subm === "test1", "subm = " + subm);
319 ok(m === "[test1]", "m = " + m + " expected [test1]");
320 ok(off === 0, "off = " + off + " expected 0");
321 break;
322 case 1:
323 ok(subm === "test2", "subm = " + subm);
324 ok(m === "[test2]", "m = " + m + " expected [test2]");
325 ok(off === 8, "off = " + off + " expected 8");
326 break;
327 default:
328 ok(false, "unexpected call");
329 }
330
331 ok(str === "[test1] [test2]", "str = " + arguments[3]);
332 return "r" + tmp++;
333 }
334
335 r = "[test1] [test2]".replace(/\[([^\[]+)\]/g, replaceFunc2);
336 ok(r === "r0 r1", "r = '" + r + "' expected 'r0 r1'");
337
338 r = "$1,$2".replace(/(\$(\d))/g, "$$1-$1$2");
339 ok(r === "$1-$11,$1-$22", "r = '" + r + "' expected '$1-$11,$1-$22'");
340 ok(RegExp.leftContext === "$1,", "RegExp.leftContext = " + RegExp.leftContext);
341 ok(RegExp.rightContext === "", "RegExp.rightContext = " + RegExp.rightContext);
342
343 r = "abc &1 123".replace(/(\&(\d))/g, "$&");
344 ok(r === "abc &1 123", "r = '" + r + "' expected 'abc &1 123'");
345 ok(RegExp.leftContext === "abc ", "RegExp.leftContext = " + RegExp.leftContext);
346 ok(RegExp.rightContext === " 123", "RegExp.rightContext = " + RegExp.rightContext);
347
348 r = "abc &1 123".replace(/(\&(\d))/g, "$'");
349 ok(r === "abc 123 123", "r = '" + r + "' expected 'abc 123 123'");
350
351 r = "abc &1 123".replace(/(\&(\d))/g, "$`");
352 ok(r === "abc abc 123", "r = '" + r + "' expected 'abc abc 123'");
353
354 r = "abc &1 123".replace(/(\&(\d))/g, "$3");
355 ok(r === "abc $3 123", "r = '" + r + "' expected 'abc $3 123'");
356
357 r = "abc &1 123".replace(/(\&(\d))/g, "$");
358 ok(r === "abc $ 123", "r = '" + r + "' expected 'abc $ 123'");
359
360 r = "abc &1 123".replace(/(\&(\d))/g, "$a");
361 ok(r === "abc $a 123", "r = '" + r + "' expected 'abc $a 123'");
362
363 r = "abc &1 123".replace(/(\&(\d))/g, "$11");
364 ok(r === "abc &11 123", "r = '" + r + "' expected 'abc &11 123'");
365
366 r = "abc &1 123".replace(/(\&(\d))/g, "$0");
367 ok(r === "abc $0 123", "r = '" + r + "' expected 'abc $0 123'");
368
369 /a/.test("a");
370 r = "1 2 3".replace("2", "$&");
371 ok(r === "1 $& 3", "r = '" + r + "' expected '1 $& 3'");
372 ok(RegExp.leftContext === "", "RegExp.leftContext = " + RegExp.leftContext);
373 ok(RegExp.rightContext === "", "RegExp.rightContext = " + RegExp.rightContext);
374
375 r = "1 2 3".replace("2", "$'");
376 ok(r === "1 $' 3", "r = '" + r + "' expected '1 $' 3'");
377
378 r = "1,,2,3".split(/,+/g);
379 ok(r.length === 3, "r.length = " + r.length);
380 ok(r[0] === "1", "r[0] = " + r[0]);
381 ok(r[1] === "2", "r[1] = " + r[1]);
382 ok(r[2] === "3", "r[2] = " + r[2]);
383 ok(RegExp.leftContext === "1,,2", "RegExp.leftContext = " + RegExp.leftContext);
384 ok(RegExp.rightContext === "3", "RegExp.rightContext = " + RegExp.rightContext);
385
386 r = "1,,2,3".split(/,+/g, 2);
387 ok(r.length === 2, "r.length = " + r.length);
388 ok(r[0] === "1", "r[0] = " + r[0]);
389 ok(r[1] === "2", "r[1] = " + r[1]);
390 ok(RegExp.leftContext === "1,,2", "RegExp.leftContext = " + RegExp.leftContext);
391 ok(RegExp.rightContext === "3", "RegExp.rightContext = " + RegExp.rightContext);
392
393 r = "1,,2,3".split(/,+/g, 1);
394 ok(r.length === 1, "r.length = " + r.length);
395 ok(r[0] === "1", "r[0] = " + r[0]);
396 ok(RegExp.leftContext === "1", "RegExp.leftContext = " + RegExp.leftContext);
397 ok(RegExp.rightContext === "2,3", "RegExp.rightContext = " + RegExp.rightContext);
398
399 r = "1,,2,3".split(/,+/);
400 ok(r.length === 3, "r.length = " + r.length);
401 ok(r[0] === "1", "r[0] = " + r[0]);
402 ok(r[1] === "2", "r[1] = " + r[1]);
403 ok(r[2] === "3", "r[2] = " + r[2]);
404
405 r = "1,,2,".split(/,+/);
406 ok(r.length === 2, "r.length = " + r.length);
407 ok(r[0] === "1", "r[0] = " + r[0]);
408 ok(r[1] === "2", "r[1] = " + r[1]);
409
410 re = /,+/;
411 r = "1,,2,".split(re);
412 ok(r.length === 2, "r.length = " + r.length);
413 ok(r[0] === "1", "r[0] = " + r[0]);
414 ok(r[1] === "2", "r[1] = " + r[1]);
415 ok(re.lastIndex === 5, "re.lastIndex = " + re.lastIndex);
416
417 re = /,+/g;
418 r = "1,,2,".split(re);
419 ok(r.length === 2, "r.length = " + r.length);
420 ok(r[0] === "1", "r[0] = " + r[0]);
421 ok(r[1] === "2", "r[1] = " + r[1]);
422 ok(re.lastIndex === 5, "re.lastIndex = " + re.lastIndex);
423
424 r = "1 12 \t3".split(re = /\s+/).join(";");
425 ok(r === "1;12;3", "r = " + r);
426 ok(re.lastIndex === 6, "re.lastIndex = " + re.lastIndex);
427
428 r = "123".split(re = /\s+/).join(";");
429 ok(r === "123", "r = " + r);
430 ok(re.lastIndex === 0, "re.lastIndex = " + re.lastIndex);
431
432 r = "1ab2aab3".split(/(a+)b/);
433 ok(r.length === 3, "r.length = " + r.length);
434 ok(r[0] === "1", "r[0] = " + r[0]);
435 ok(r[1] === "2", "r[1] = " + r[1]);
436 ok(r[2] === "3", "r[2] = " + r[2]);
437
438 r = "A<B>bold</B>and<CODE>coded</CODE>".split(/<(\/)?([^<>]+)>/) ;
439 ok(r.length === 4, "r.length = " + r.length);
440
441 /* another standard violation */
442 r = "1 12 \t3".split(re = /(\s)+/g).join(";");
443 ok(r === "1;12;3", "r = " + r);
444 ok(re.lastIndex === 6, "re.lastIndex = " + re.lastIndex);
445 ok(RegExp.leftContext === "1 12", "RegExp.leftContext = " + RegExp.leftContext);
446 ok(RegExp.rightContext === "3", "RegExp.rightContext = " + RegExp.rightContext);
447
448 re = /,+/;
449 re.lastIndex = 4;
450 r = "1,,2,".split(re);
451 ok(r.length === 2, "r.length = " + r.length);
452 ok(r[0] === "1", "r[0] = " + r[0]);
453 ok(r[1] === "2", "r[1] = " + r[1]);
454 ok(re.lastIndex === 5, "re.lastIndex = " + re.lastIndex);
455
456 re = /abc[^d]/g;
457 ok(re.source === "abc[^d]", "re.source = '" + re.source + "', expected 'abc[^d]'");
458
459 re = /a\bc[^d]/g;
460 ok(re.source === "a\\bc[^d]", "re.source = '" + re.source + "', expected 'a\\bc[^d]'");
461
462 re = /abc/;
463 ok(re === RegExp(re), "re !== RegExp(re)");
464
465 re = RegExp("abc[^d]", "g");
466 ok(re.source === "abc[^d]", "re.source = '" + re.source + "', expected 'abc[^d]'");
467
468 re = /abc/;
469 ok(re === RegExp(re, undefined), "re !== RegExp(re, undefined)");
470
471 re = /abc/;
472 ok(re === RegExp(re, undefined, 1), "re !== RegExp(re, undefined, 1)");
473
474 re = /a/g;
475 ok(re.lastIndex === 0, "re.lastIndex = " + re.lastIndex + " expected 0");
476
477 m = re.exec(" a ");
478 ok(re.lastIndex === 2, "re.lastIndex = " + re.lastIndex + " expected 2");
479 ok(m.index === 1, "m.index = " + m.index + " expected 1");
480 ok(RegExp.leftContext === " ", "RegExp.leftContext = " + RegExp.leftContext);
481 ok(RegExp.rightContext === " ", "RegExp.rightContext = " + RegExp.rightContext);
482
483 m = re.exec(" a ");
484 ok(re.lastIndex === 0, "re.lastIndex = " + re.lastIndex + " expected 0");
485 ok(m === null, "m = " + m + " expected null");
486
487 re.lastIndex = 2;
488 m = re.exec(" a a ");
489 ok(re.lastIndex === 4, "re.lastIndex = " + re.lastIndex + " expected 4");
490 ok(m.index === 3, "m.index = " + m.index + " expected 3");
491
492 re.lastIndex = "2";
493 ok(re.lastIndex === "2", "re.lastIndex = " + re.lastIndex + " expected '2'");
494 m = re.exec(" a a ");
495 ok(re.lastIndex === 4, "re.lastIndex = " + re.lastIndex + " expected 4");
496 ok(m.index === 3, "m.index = " + m.index + " expected 3");
497
498 var li = 0;
499 var obj = new Object();
500 obj.valueOf = function() { return li; };
501
502 re.lastIndex = obj;
503 ok(re.lastIndex === obj, "re.lastIndex = " + re.lastIndex + " expected obj");
504 li = 2;
505 m = re.exec(" a a ");
506 ok(re.lastIndex === 2, "re.lastIndex = " + re.lastIndex + " expected 2");
507 ok(m.index === 1, "m.index = " + m.index + " expected 1");
508
509 re.lastIndex = 3;
510 re.lastIndex = "test";
511 ok(re.lastIndex === "test", "re.lastIndex = " + re.lastIndex + " expected 'test'");
512 m = re.exec(" a a ");
513 ok(re.lastIndex === 2 || re.lastIndex === 0, "re.lastIndex = " + re.lastIndex + " expected 2 or 0");
514 if(re.lastIndex != 0)
515 ok(m.index === 1, "m.index = " + m.index + " expected 1");
516 else
517 ok(m === null, "m = " + m + " expected null");
518
519 re.lastIndex = 0;
520 re.lastIndex = 3.9;
521 ok(re.lastIndex === 3.9, "re.lastIndex = " + re.lastIndex + " expected 3.9");
522 m = re.exec(" a a ");
523 ok(re.lastIndex === 4, "re.lastIndex = " + re.lastIndex + " expected 4");
524 ok(m.index === 3, "m.index = " + m.index + " expected 3");
525
526 obj.valueOf = function() { throw 0; }
527 re.lastIndex = obj;
528 ok(re.lastIndex === obj, "unexpected re.lastIndex");
529 m = re.exec(" a a ");
530 ok(re.lastIndex === 2, "re.lastIndex = " + re.lastIndex + " expected 2");
531 ok(m.index === 1, "m.index = " + m.index + " expected 1");
532
533 re.lastIndex = -3;
534 ok(re.lastIndex === -3, "re.lastIndex = " + re.lastIndex + " expected -3");
535 m = re.exec(" a a ");
536 ok(re.lastIndex === 0, "re.lastIndex = " + re.lastIndex + " expected 0");
537 ok(m === null, "m = " + m + " expected null");
538
539 re.lastIndex = -1;
540 ok(re.lastIndex === -1, "re.lastIndex = " + re.lastIndex + " expected -1");
541 m = re.exec(" ");
542 ok(re.lastIndex === 0, "re.lastIndex = " + re.lastIndex + " expected 0");
543 ok(m === null, "m = " + m + " expected null");
544
545 re = /a/;
546 re.lastIndex = -3;
547 ok(re.lastIndex === -3, "re.lastIndex = " + re.lastIndex + " expected -3");
548 m = re.exec(" a a ");
549 ok(re.lastIndex === 2, "re.lastIndex = " + re.lastIndex + " expected 0");
550 ok(m.index === 1, "m = " + m + " expected 1");
551 ok(RegExp.leftContext === " ", "RegExp.leftContext = " + RegExp.leftContext);
552 ok(RegExp.rightContext === " a ", "RegExp.rightContext = " + RegExp.rightContext);
553
554 re.lastIndex = -1;
555 ok(re.lastIndex === -1, "re.lastIndex = " + re.lastIndex + " expected -1");
556 m = re.exec(" ");
557 ok(re.lastIndex === 0, "re.lastIndex = " + re.lastIndex + " expected 0");
558 ok(m === null, "m = " + m + " expected null");
559
560 re = /aa/g;
561 i = 'baacd'.search(re);
562 ok(i === 1, "'baacd'.search(re) = " + i);
563 ok(re.lastIndex === 3, "re.lastIndex = " + re.lastIndex);
564 ok(RegExp.leftContext === "b", "RegExp.leftContext = " + RegExp.leftContext);
565 ok(RegExp.rightContext === "cd", "RegExp.rightContext = " + RegExp.rightContext);
566
567 re.lastIndex = 2;
568 i = 'baacdaa'.search(re);
569 ok(i === 1, "'baacd'.search(re) = " + i);
570 ok(re.lastIndex === 3, "re.lastIndex = " + re.lastIndex);
571
572 re = /aa/;
573 i = 'baacd'.search(re);
574 ok(i === 1, "'baacd'.search(re) = " + i);
575 ok(re.lastIndex === 3, "re.lastIndex = " + re.lastIndex);
576
577 re.lastIndex = 2;
578 i = 'baacdaa'.search(re);
579 ok(i === 1, "'baacd'.search(re) = " + i);
580 ok(re.lastIndex === 3, "re.lastIndex = " + re.lastIndex);
581 ok(RegExp.leftContext === "b", "RegExp.leftContext = " + RegExp.leftContext);
582 ok(RegExp.rightContext === "cdaa", "RegExp.rightContext = " + RegExp.rightContext);
583
584 re = /d/g;
585 re.lastIndex = 1;
586 i = 'abc'.search(re);
587 ok(i === -1, "'abc'.search(/d/g) = " + i);
588 ok(re.lastIndex === 0, "re.lastIndex = " + re.lastIndex);
589 ok(RegExp.leftContext === "b", "RegExp.leftContext = " + RegExp.leftContext);
590 ok(RegExp.rightContext === "cdaa", "RegExp.rightContext = " + RegExp.rightContext);
591
592 i = 'abcdde'.search(/[df]/);
593 ok(i === 3, "'abc'.search(/[df]/) = " + i);
594
595 i = 'abcdde'.search(/[df]/, "a");
596 ok(i === 3, "'abc'.search(/[df]/) = " + i);
597
598 i = 'abcdde'.search("[df]");
599 ok(i === 3, "'abc'.search(/d*/) = " + i);
600
601 obj = {
602 toString: function() { return "abc"; }
603 };
604 i = String.prototype.search.call(obj, "b");
605 ok(i === 1, "String.prototype.seatch.apply(obj, 'b') = " + i);
606
607 i = " undefined ".search();
608 ok(i === null, "' undefined '.search() = " + i);
609
610 tmp = "=)".replace(/=/, "?");
611 ok(tmp === "?)", "'=)'.replace(/=/, '?') = " + tmp);
612
613 tmp = " ".replace(/^\s*|\s*$/g, "y");
614 ok(tmp === "yy", '" ".replace(/^\s*|\s*$/g, "y") = ' + tmp);
615
616 tmp = "xxx".replace(/^\s*|\s*$/g, "");
617 ok(tmp === "xxx", '"xxx".replace(/^\s*|\s*$/g, "y") = ' + tmp);
618
619 tmp = "xxx".replace(/^\s*|\s*$/g, "y");
620 ok(tmp === "yxxxy", '"xxx".replace(/^\s*|\s*$/g, "y") = ' + tmp);
621
622 tmp = "x/y".replace(/[/]/, "*");
623 ok(tmp === "x*y", '"x/y".replace(/[/]/, "*") = ' + tmp);
624
625 tmp = "x/y".replace(/[xy/]/g, "*");
626 ok(tmp === "***", '"x/y".replace(/[xy/]/, "*") = ' + tmp);
627
628 /(b)/.exec("abc");
629 ok(RegExp.$1 === "b", "RegExp.$1 = " + RegExp.$1);
630 ok("$2" in RegExp, "RegExp.$2 doesn't exist");
631 ok(RegExp.$2 === "", "RegExp.$2 = " + RegExp.$2);
632 ok(RegExp.$9 === "", "RegExp.$9 = " + RegExp.$9);
633 ok(!("$10" in RegExp), "RegExp.$10 exists");
634
635 /(b)(b)(b)(b)(b)(b)(b)(b)(b)(b)(b)/.exec("abbbbbbbbbbbc");
636 ok(RegExp.$1 === "b", "RegExp.$1 = " + RegExp.$1);
637 ok(RegExp.$2 === "b", "[2] RegExp.$2 = " + RegExp.$2);
638 ok(RegExp.$9 === "b", "RegExp.$9 = " + RegExp.$9);
639 ok(!("$10" in RegExp), "RegExp.$10 exists");
640
641 /(b)/.exec("abc");
642 ok(RegExp.$1 === "b", "RegExp.$1 = " + RegExp.$1);
643 ok("$2" in RegExp, "RegExp.$2 doesn't exist");
644 ok(RegExp.$2 === "", "RegExp.$2 = " + RegExp.$2);
645 ok(RegExp.$9 === "", "RegExp.$9 = " + RegExp.$9);
646 ok(!("$10" in RegExp), "RegExp.$10 exists");
647
648 RegExp.$1 = "a";
649 ok(RegExp.$1 === "b", "RegExp.$1 = " + RegExp.$1);
650
651 ok(/abc/.toString() === "/abc/", "/abc/.toString() = " + /abc/.toString());
652 ok(/\//.toString() === "/\\//", "/\//.toString() = " + /\//.toString());
653 tmp = new RegExp("abc/");
654 ok(tmp.toString() === "/abc//", "(new RegExp(\"abc/\")).toString() = " + tmp.toString());
655 ok(/abc/g.toString() === "/abc/g", "/abc/g.toString() = " + /abc/g.toString());
656 ok(/abc/i.toString() === "/abc/i", "/abc/i.toString() = " + /abc/i.toString());
657 ok(/abc/ig.toString() === "/abc/ig", "/abc/ig.toString() = " + /abc/ig.toString());
658 ok(/abc/mgi.toString() === "/abc/igm", "/abc/mgi.toString() = " + /abc/mgi.toString());
659 tmp = new RegExp("abc/", "mgi");
660 ok(tmp.toString() === "/abc//igm", "(new RegExp(\"abc/\")).toString() = " + tmp.toString());
661 ok(/abc/.toString(1, false, "3") === "/abc/", "/abc/.toString(1, false, \"3\") = " + /abc/.toString());
662
663 re = /x/;
664 ok(re.ignoreCase === false, "re.ignoreCase = " + re.ignoreCase);
665 ok(re.multiline === false, "re.multiline = " + re.multiline);
666 ok(re.global === false, "re.global = " + re.global);
667 re = /x/i;
668 ok(re.ignoreCase === true, "re.ignoreCase = " + re.ignoreCase);
669 ok(re.multiline === false, "re.multiline = " + re.multiline);
670 ok(re.global === false, "re.global = " + re.global);
671 re = new RegExp("xxx", "gi");
672 ok(re.ignoreCase === true, "re.ignoreCase = " + re.ignoreCase);
673 ok(re.multiline === false, "re.multiline = " + re.multiline);
674 ok(re.global === true, "re.global = " + re.global);
675 re = /x/mg;
676 ok(re.ignoreCase === false, "re.ignoreCase = " + re.ignoreCase);
677 ok(re.multiline === true, "re.multiline = " + re.multiline);
678 ok(re.global === true, "re.global = " + re.global);
679
680 reportSuccess();