2 * Copyright 2008 Jacek Caban for CodeWeavers
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.
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.
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
22 ok(RegExp.leftContext === "", "RegExp.leftContext = " + RegExp.leftContext);
23 RegExp.leftContext = "abc";
24 ok(RegExp.leftContext === "", "RegExp.leftContext = " + RegExp.leftContext);
27 ok(re.lastIndex === 0, "re.lastIndex = " + re.lastIndex);
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);
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);
52 m = /^[^<]*(<(.|\s)+>)[^>]*$|^#(\w+)$/.exec(
53 "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
54 ok(m === null, "m is not null");
57 ok(re.lastIndex === 0, "re.lastIndex = " + re.lastIndex);
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]);
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]);
74 m = re.exec(" aabaaa");
75 ok(re.lastIndex === 0, "re.lastIndex = " + re.lastIndex);
76 ok(m === null, "m is not null");
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);
85 ok(m === null, "m is not null");
86 ok(re.lastIndex === 0, "re.lastIndex = " + re.lastIndex);
89 ok(re.lastIndex === 2, "re.lastIndex = " + re.lastIndex);
92 ok(m === null, "m is not null");
93 ok(re.lastIndex === 0, "re.lastIndex = " + re.lastIndex);
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]);
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);
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);
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]);
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);
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);
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);
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);
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);
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); */
159 m = "abcabc".match(/Ab/g);
160 ok(typeof(m) === "object", "typeof m is not object");
161 ok(m === null, "m is not null");
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);
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\"");
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 \"\\\"");
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\"");
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);
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\"");
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);
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);
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);
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\"");
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);
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);
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);
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);
262 r = "[test] [test]".replace(/\[([^\[]+)\]/, "aa");
263 ok(r === "aa [test]", "r = " + r + " expected 'aa [test]'");
265 r = "- [test] -".replace(/\[([^\[]+)\]/g);
266 ok(r === "- undefined -", "r = " + r + " expected '- undefined -'");
268 r = "- [test] -".replace(/\[([^\[]+)\]/g, true);
269 ok(r === "- true -", "r = " + r + " expected '- true -'");
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);
278 function replaceFunc1(m, off, str) {
279 ok(arguments.length === 3, "arguments.length = " + arguments.length);
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);
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);
299 ok(false, "unexpected call");
302 ok(str === "[test1] [test2]", "str = " + arguments[3]);
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);
313 function replaceFunc2(m, subm, off, str) {
314 ok(arguments.length === 4, "arguments.length = " + arguments.length);
318 ok(subm === "test1", "subm = " + subm);
319 ok(m === "[test1]", "m = " + m + " expected [test1]");
320 ok(off === 0, "off = " + off + " expected 0");
323 ok(subm === "test2", "subm = " + subm);
324 ok(m === "[test2]", "m = " + m + " expected [test2]");
325 ok(off === 8, "off = " + off + " expected 8");
328 ok(false, "unexpected call");
331 ok(str === "[test1] [test2]", "str = " + arguments[3]);
335 r = "[test1] [test2]".replace(/\[([^\[]+)\]/g, replaceFunc2);
336 ok(r === "r0 r1", "r = '" + r + "' expected 'r0 r1'");
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);
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);
348 r = "abc &1 123".replace(/(\&(\d))/g, "$'");
349 ok(r === "abc 123 123", "r = '" + r + "' expected 'abc 123 123'");
351 r = "abc &1 123".replace(/(\&(\d))/g, "$`");
352 ok(r === "abc abc 123", "r = '" + r + "' expected 'abc abc 123'");
354 r = "abc &1 123".replace(/(\&(\d))/g, "$3");
355 ok(r === "abc $3 123", "r = '" + r + "' expected 'abc $3 123'");
357 r = "abc &1 123".replace(/(\&(\d))/g, "$");
358 ok(r === "abc $ 123", "r = '" + r + "' expected 'abc $ 123'");
360 r = "abc &1 123".replace(/(\&(\d))/g, "$a");
361 ok(r === "abc $a 123", "r = '" + r + "' expected 'abc $a 123'");
363 r = "abc &1 123".replace(/(\&(\d))/g, "$11");
364 ok(r === "abc &11 123", "r = '" + r + "' expected 'abc &11 123'");
366 r = "abc &1 123".replace(/(\&(\d))/g, "$0");
367 ok(r === "abc $0 123", "r = '" + r + "' expected 'abc $0 123'");
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);
375 r = "1 2 3".replace("2", "$'");
376 ok(r === "1 $' 3", "r = '" + r + "' expected '1 $' 3'");
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);
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);
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);
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]);
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]);
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);
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);
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);
428 r = "123".split(re = /\s+/).join(";");
429 ok(r === "123", "r = " + r);
430 ok(re.lastIndex === 0, "re.lastIndex = " + re.lastIndex);
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]);
438 r = "A<B>bold</B>and<CODE>coded</CODE>".split(/<(\/)?([^<>]+)>/) ;
439 ok(r.length === 4, "r.length = " + r.length);
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);
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);
457 ok(re.source === "abc[^d]", "re.source = '" + re.source + "', expected 'abc[^d]'");
460 ok(re.source === "a\\bc[^d]", "re.source = '" + re.source + "', expected 'a\\bc[^d]'");
463 ok(re === RegExp(re), "re !== RegExp(re)");
465 re = RegExp("abc[^d]", "g");
466 ok(re.source === "abc[^d]", "re.source = '" + re.source + "', expected 'abc[^d]'");
469 ok(re === RegExp(re, undefined), "re !== RegExp(re, undefined)");
472 ok(re === RegExp(re, undefined, 1), "re !== RegExp(re, undefined, 1)");
475 ok(re.lastIndex === 0, "re.lastIndex = " + re.lastIndex + " expected 0");
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);
484 ok(re.lastIndex === 0, "re.lastIndex = " + re.lastIndex + " expected 0");
485 ok(m === null, "m = " + m + " expected null");
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");
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");
499 var obj = new Object();
500 obj.valueOf = function() { return li; };
503 ok(re.lastIndex === obj, "re.lastIndex = " + re.lastIndex + " expected obj");
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");
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");
517 ok(m === null, "m = " + m + " expected null");
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");
526 obj.valueOf = function() { throw 0; }
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");
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");
540 ok(re.lastIndex === -1, "re.lastIndex = " + re.lastIndex + " expected -1");
542 ok(re.lastIndex === 0, "re.lastIndex = " + re.lastIndex + " expected 0");
543 ok(m === null, "m = " + m + " expected null");
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);
555 ok(re.lastIndex === -1, "re.lastIndex = " + re.lastIndex + " expected -1");
557 ok(re.lastIndex === 0, "re.lastIndex = " + re.lastIndex + " expected 0");
558 ok(m === null, "m = " + m + " expected null");
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);
568 i = 'baacdaa'.search(re);
569 ok(i === 1, "'baacd'.search(re) = " + i);
570 ok(re.lastIndex === 3, "re.lastIndex = " + re.lastIndex);
573 i = 'baacd'.search(re);
574 ok(i === 1, "'baacd'.search(re) = " + i);
575 ok(re.lastIndex === 3, "re.lastIndex = " + re.lastIndex);
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);
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);
592 i = 'abcdde'.search(/[df]/);
593 ok(i === 3, "'abc'.search(/[df]/) = " + i);
595 i = 'abcdde'.search(/[df]/, "a");
596 ok(i === 3, "'abc'.search(/[df]/) = " + i);
598 i = 'abcdde'.search("[df]");
599 ok(i === 3, "'abc'.search(/d*/) = " + i);
602 toString: function() { return "abc"; }
604 i = String.prototype.search.call(obj, "b");
605 ok(i === 1, "String.prototype.seatch.apply(obj, 'b') = " + i);
607 i = " undefined ".search();
608 ok(i === null, "' undefined '.search() = " + i);
610 tmp = "=)".replace(/=/, "?");
611 ok(tmp === "?)", "'=)'.replace(/=/, '?') = " + tmp);
613 tmp = " ".replace(/^\s*|\s*$/g, "y");
614 ok(tmp === "yy", '" ".replace(/^\s*|\s*$/g, "y") = ' + tmp);
616 tmp = "xxx".replace(/^\s*|\s*$/g, "");
617 ok(tmp === "xxx", '"xxx".replace(/^\s*|\s*$/g, "y") = ' + tmp);
619 tmp = "xxx".replace(/^\s*|\s*$/g, "y");
620 ok(tmp === "yxxxy", '"xxx".replace(/^\s*|\s*$/g, "y") = ' + tmp);
622 tmp = "x/y".replace(/[/]/, "*");
623 ok(tmp === "x*y", '"x/y".replace(/[/]/, "*") = ' + tmp);
625 tmp = "x/y".replace(/[xy/]/g, "*");
626 ok(tmp === "***", '"x/y".replace(/[xy/]/, "*") = ' + tmp);
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");
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");
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");
649 ok(RegExp.$1 === "b", "RegExp.$1 = " + RegExp.$1);