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(RegExp.leftContext === " ", "RegExp.leftContext = " + RegExp.leftContext);
45 ok(RegExp.rightContext === "baaa", "RegExp.rightContext = " + RegExp.rightContext);
47 m = /^[^<]*(<(.|\s)+>)[^>]*$|^#(\w+)$/.exec(
48 "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
49 ok(m === null, "m is not null");
52 ok(re.lastIndex === 0, "re.lastIndex = " + re.lastIndex);
54 m = re.exec(" aabaaa");
55 ok(re.lastIndex === 3, "re.lastIndex = " + re.lastIndex);
56 ok(m.index === 1, "m.index = " + m.index);
57 ok(m.lastIndex == 3, "m.lastIndex = " + m.lastIndex);
58 ok(m.input === " aabaaa", "m.input = " + m.input);
59 ok(m.length === 1, "m.length = " + m.length);
60 ok(m[0] === "aa", "m[0] = " + m[0]);
62 m = re.exec(" aabaaa");
63 ok(re.lastIndex === 7, "re.lastIndex = " + re.lastIndex);
64 ok(m.index === 4, "m.index = " + m.index);
65 ok(m.input === " aabaaa", "m.input = " + m.input);
66 ok(m.length === 1, "m.length = " + m.length);
67 ok(m[0] === "aaa", "m[0] = " + m[0]);
69 m = re.exec(" aabaaa");
70 ok(re.lastIndex === 0, "re.lastIndex = " + re.lastIndex);
71 ok(m === null, "m is not null");
74 ok(re.lastIndex === 16, "re.lastIndex = " + re.lastIndex);
75 ok(RegExp.leftContext === " ",
76 "RegExp.leftContext = " + RegExp.leftContext);
77 ok(RegExp.rightContext === "", "RegExp.rightContext = " + RegExp.rightContext);
80 ok(m === null, "m is not null");
81 ok(re.lastIndex === 0, "re.lastIndex = " + re.lastIndex);
84 ok(re.lastIndex === 2, "re.lastIndex = " + re.lastIndex);
87 ok(m === null, "m is not null");
88 ok(re.lastIndex === 0, "re.lastIndex = " + re.lastIndex);
90 m = /(a|b)+|(c)/.exec("aa");
91 ok(m[0] === "aa", "m[0] = " + m[0]);
92 ok(m[1] === "a", "m[1] = " + m[1]);
93 ok(m[2] === "", "m[2] = " + m[2]);
96 ok(b === true, "re.test(' a ') returned " + b);
97 ok(re.lastIndex === 3, "re.lastIndex = " + re.lastIndex);
98 ok(RegExp.leftContext === " ", "RegExp.leftContext = " + RegExp.leftContext);
99 ok(RegExp.rightContext === " ", "RegExp.rightContext = " + RegExp.rightContext);
102 ok(b === false, "re.test(' a ') returned " + b);
103 ok(re.lastIndex === 0, "re.lastIndex = " + re.lastIndex);
104 ok(RegExp.leftContext === " ", "RegExp.leftContext = " + RegExp.leftContext);
105 ok(RegExp.rightContext === " ", "RegExp.rightContext = " + RegExp.rightContext);
107 re = /\[([^\[]+)\]/g;
108 m = re.exec(" [test] ");
109 ok(re.lastIndex === 7, "re.lastIndex = " + re.lastIndex);
110 ok(m.index === 1, "m.index = " + m.index);
111 ok(m.input === " [test] ", "m.input = " + m.input);
112 ok(m.length === 2, "m.length = " + m.length);
113 ok(m[0] === "[test]", "m[0] = " + m[0]);
114 ok(m[1] === "test", "m[1] = " + m[1]);
117 ok(b === true, "/a*/.test() returned " + b);
118 ok(RegExp.leftContext === "", "RegExp.leftContext = " + RegExp.leftContext);
119 ok(RegExp.rightContext === "undefined", "RegExp.rightContext = " + RegExp.rightContext);
122 ok(b === true, "/f/.test() returned " + b);
123 ok(RegExp.leftContext === "unde", "RegExp.leftContext = " + RegExp.leftContext);
124 ok(RegExp.rightContext === "ined", "RegExp.rightContext = " + RegExp.rightContext);
127 ok(b === false, "/abc/.test() returned " + b);
128 ok(RegExp.leftContext === "unde", "RegExp.leftContext = " + RegExp.leftContext);
129 ok(RegExp.rightContext === "ined", "RegExp.rightContext = " + RegExp.rightContext);
131 m = "abcabc".match(re = /ca/);
132 ok(typeof(m) === "object", "typeof m is not object");
133 ok(m.length === 1, "m.length is not 1");
134 ok(m["0"] === "ca", "m[0] is not \"ca\"");
135 ok(m.constructor === Array, "unexpected m.constructor");
136 ok(re.lastIndex === 4, "re.lastIndex = " + re.lastIndex);
137 ok(RegExp.leftContext === "ab", "RegExp.leftContext = " + RegExp.leftContext);
138 ok(RegExp.rightContext === "bc", "RegExp.rightContext = " + RegExp.rightContext);
140 m = "abcabc".match(/ab/);
141 ok(typeof(m) === "object", "typeof m is not object");
142 ok(m.length === 1, "m.length is not 1");
143 ok(m["0"] === "ab", "m[0] is not \"ab\"");
144 ok(RegExp.leftContext === "", "RegExp.leftContext = " + RegExp.leftContext);
145 ok(RegExp.rightContext === "cabc", "RegExp.rightContext = " + RegExp.rightContext);
147 m = "abcabc".match(/ab/g);
148 ok(typeof(m) === "object", "typeof m is not object");
149 ok(m.length === 2, "m.length is not 2");
150 ok(m["0"] === "ab", "m[0] is not \"ab\"");
151 ok(m["1"] === "ab", "m[1] is not \"ab\"");
152 /* ok(m.input === "abcabc", "m.input = " + m.input); */
154 m = "abcabc".match(/Ab/g);
155 ok(typeof(m) === "object", "typeof m is not object");
156 ok(m === null, "m is not null");
158 m = "abcabc".match(/Ab/gi);
159 ok(typeof(m) === "object", "typeof m is not object");
160 ok(m.length === 2, "m.length is not 2");
161 ok(m["0"] === "ab", "m[0] is not \"ab\"");
162 ok(m["1"] === "ab", "m[1] is not \"ab\"");
163 ok(RegExp.leftContext === "abc", "RegExp.leftContext = " + RegExp.leftContext);
164 ok(RegExp.rightContext === "c", "RegExp.rightContext = " + RegExp.rightContext);
166 m = "aaabcabc".match(/a+b/g);
167 ok(typeof(m) === "object", "typeof m is not object");
168 ok(m.length === 2, "m.length is not 2");
169 ok(m["0"] === "aaab", "m[0] is not \"ab\"");
170 ok(m["1"] === "ab", "m[1] is not \"ab\"");
172 m = "aaa\\\\cabc".match(/\\/g);
173 ok(typeof(m) === "object", "typeof m is not object");
174 ok(m.length === 2, "m.length is not 2");
175 ok(m["0"] === "\\", "m[0] is not \"\\\"");
176 ok(m["1"] === "\\", "m[1] is not \"\\\"");
178 m = "abcabc".match(new RegExp("ab"));
179 ok(typeof(m) === "object", "typeof m is not object");
180 ok(m.length === 1, "m.length is not 1");
181 ok(m["0"] === "ab", "m[0] is not \"ab\"");
183 m = "abcabc".match(new RegExp("ab","g"));
184 ok(typeof(m) === "object", "typeof m is not object");
185 ok(m.length === 2, "m.length is not 2");
186 ok(m["0"] === "ab", "m[0] is not \"ab\"");
187 ok(m["1"] === "ab", "m[1] is not \"ab\"");
188 ok(RegExp.leftContext === "abc", "RegExp.leftContext = " + RegExp.leftContext);
189 ok(RegExp.rightContext === "c", "RegExp.rightContext = " + RegExp.rightContext);
191 m = "abcabc".match(new RegExp(/ab/g));
192 ok(typeof(m) === "object", "typeof m is not object");
193 ok(m.length === 2, "m.length is not 2");
194 ok(m["0"] === "ab", "m[0] is not \"ab\"");
195 ok(m["1"] === "ab", "m[1] is not \"ab\"");
197 m = "abcabc".match(new RegExp("ab","g", "test"));
198 ok(typeof(m) === "object", "typeof m is not object");
199 ok(m.length === 2, "m.length is not 2");
200 ok(m["0"] === "ab", "m[0] is not \"ab\"");
201 ok(m["1"] === "ab", "m[1] is not \"ab\"");
202 ok(m.index === 3, "m.index = " + m.index);
203 ok(m.input === "abcabc", "m.input = " + m.input);
204 ok(m.lastIndex === 5, "m.lastIndex = " + m.lastIndex);
206 m = "abcabcg".match("ab", "g");
207 ok(typeof(m) === "object", "typeof m is not object");
208 ok(m.length === 1, "m.length is not 1");
209 ok(m["0"] === "ab", "m[0] is not \"ab\"");
210 ok(RegExp.leftContext === "", "RegExp.leftContext = " + RegExp.leftContext);
211 ok(RegExp.rightContext === "cabcg", "RegExp.rightContext = " + RegExp.rightContext);
213 m = "abcabc".match();
214 ok(m === null, "m is not null");
215 ok(RegExp.leftContext === "", "RegExp.leftContext = " + RegExp.leftContext);
216 ok(RegExp.rightContext === "cabcg", "RegExp.rightContext = " + RegExp.rightContext);
218 m = "abcabc".match(/(a)(b)cabc/);
219 ok(typeof(m) === "object", "typeof m is not object");
220 ok(m.length === 3, "m.length is not 3");
221 ok(m[0] === "abcabc", "m[0] is not \"abc\"");
222 ok(m[1] === "a", "m[1] is not \"a\"");
223 ok(m[2] === "b", "m[2] is not \"b\"");
227 m = "abcabc".match(re);
228 ok(typeof(m) === "object", "typeof m is not object");
229 ok(m.length === 2, "m.length = " + m.length + "expected 3");
230 ok(m[0] === "abcabc", "m[0] is not \"abc\"");
231 ok(m[1] === "a", "m[1] is not \"a\"");
232 ok(re.lastIndex === 6, "re.lastIndex = " + re.lastIndex);
236 m = "abcabcxxx".match(re);
237 ok(typeof(m) === "object", "typeof m is not object");
238 ok(m.length === 2, "m.length = " + m.length + "expected 3");
239 ok(m[0] === "abcabc", "m[0] is not \"abc\"");
240 ok(m[1] === "a", "m[1] is not \"a\"");
241 ok(m.input === "abcabcxxx", "m.input = " + m.input);
242 ok(re.lastIndex === 6, "re.lastIndex = " + re.lastIndex);
244 r = "- [test] -".replace(re = /\[([^\[]+)\]/g, "success");
245 ok(r === "- success -", "r = " + r + " expected '- success -'");
246 ok(re.lastIndex === 8, "re.lastIndex = " + re.lastIndex);
247 ok(RegExp.leftContext === "- ", "RegExp.leftContext = " + RegExp.leftContext);
248 ok(RegExp.rightContext === " -", "RegExp.rightContext = " + RegExp.rightContext);
250 r = "[test] [test]".replace(/\[([^\[]+)\]/g, "aa");
251 ok(r === "aa aa", "r = " + r + "aa aa");
252 ok(RegExp.leftContext === "[test] ",
253 "RegExp.leftContext = " + RegExp.leftContext);
254 ok(RegExp.rightContext === "",
255 "RegExp.rightContext = " + RegExp.rightContext);
257 r = "[test] [test]".replace(/\[([^\[]+)\]/, "aa");
258 ok(r === "aa [test]", "r = " + r + " expected 'aa [test]'");
260 r = "- [test] -".replace(/\[([^\[]+)\]/g);
261 ok(r === "- undefined -", "r = " + r + " expected '- undefined -'");
263 r = "- [test] -".replace(/\[([^\[]+)\]/g, true);
264 ok(r === "- true -", "r = " + r + " expected '- true -'");
266 r = "- [test] -".replace(/\[([^\[]+)\]/g, true, "test");
267 ok(r === "- true -", "r = " + r + " expected '- true -'");
268 ok(RegExp.leftContext === "- ", "RegExp.leftContext = " + RegExp.leftContext);
269 ok(RegExp.rightContext === " -", "RegExp.rightContext = " + RegExp.rightContext);
273 function replaceFunc1(m, off, str) {
274 ok(arguments.length === 3, "arguments.length = " + arguments.length);
278 ok(m === "[test1]", "m = " + m + " expected [test1]");
279 ok(off === 0, "off = " + off + " expected 0");
280 ok(RegExp.leftContext === "- ",
281 "RegExp.leftContext = " + RegExp.leftContext);
282 ok(RegExp.rightContext === " -",
283 "RegExp.rightContext = " + RegExp.rightContext);
286 ok(m === "[test2]", "m = " + m + " expected [test2]");
287 ok(off === 8, "off = " + off + " expected 8");
288 ok(RegExp.leftContext === "- ",
289 "RegExp.leftContext = " + RegExp.leftContext);
290 ok(RegExp.rightContext === " -",
291 "RegExp.rightContext = " + RegExp.rightContext);
294 ok(false, "unexpected call");
297 ok(str === "[test1] [test2]", "str = " + arguments[3]);
301 r = "[test1] [test2]".replace(/\[[^\[]+\]/g, replaceFunc1);
302 ok(r === "r0 r1", "r = " + r + " expected 'r0 r1'");
303 ok(RegExp.leftContext === "[test1] ", "RegExp.leftContext = " + RegExp.leftContext);
304 ok(RegExp.rightContext === "", "RegExp.rightContext = " + RegExp.rightContext);
308 function replaceFunc2(m, subm, off, str) {
309 ok(arguments.length === 4, "arguments.length = " + arguments.length);
313 ok(subm === "test1", "subm = " + subm);
314 ok(m === "[test1]", "m = " + m + " expected [test1]");
315 ok(off === 0, "off = " + off + " expected 0");
318 ok(subm === "test2", "subm = " + subm);
319 ok(m === "[test2]", "m = " + m + " expected [test2]");
320 ok(off === 8, "off = " + off + " expected 8");
323 ok(false, "unexpected call");
326 ok(str === "[test1] [test2]", "str = " + arguments[3]);
330 r = "[test1] [test2]".replace(/\[([^\[]+)\]/g, replaceFunc2);
331 ok(r === "r0 r1", "r = '" + r + "' expected 'r0 r1'");
333 r = "$1,$2".replace(/(\$(\d))/g, "$$1-$1$2");
334 ok(r === "$1-$11,$1-$22", "r = '" + r + "' expected '$1-$11,$1-$22'");
335 ok(RegExp.leftContext === "$1,", "RegExp.leftContext = " + RegExp.leftContext);
336 ok(RegExp.rightContext === "", "RegExp.rightContext = " + RegExp.rightContext);
338 r = "abc &1 123".replace(/(\&(\d))/g, "$&");
339 ok(r === "abc &1 123", "r = '" + r + "' expected 'abc &1 123'");
340 ok(RegExp.leftContext === "abc ", "RegExp.leftContext = " + RegExp.leftContext);
341 ok(RegExp.rightContext === " 123", "RegExp.rightContext = " + RegExp.rightContext);
343 r = "abc &1 123".replace(/(\&(\d))/g, "$'");
344 ok(r === "abc 123 123", "r = '" + r + "' expected 'abc 123 123'");
346 r = "abc &1 123".replace(/(\&(\d))/g, "$`");
347 ok(r === "abc abc 123", "r = '" + r + "' expected 'abc abc 123'");
349 r = "abc &1 123".replace(/(\&(\d))/g, "$3");
350 ok(r === "abc $3 123", "r = '" + r + "' expected 'abc $3 123'");
352 r = "abc &1 123".replace(/(\&(\d))/g, "$");
353 ok(r === "abc $ 123", "r = '" + r + "' expected 'abc $ 123'");
355 r = "abc &1 123".replace(/(\&(\d))/g, "$a");
356 ok(r === "abc $a 123", "r = '" + r + "' expected 'abc $a 123'");
358 r = "abc &1 123".replace(/(\&(\d))/g, "$11");
359 ok(r === "abc &11 123", "r = '" + r + "' expected 'abc &11 123'");
361 r = "abc &1 123".replace(/(\&(\d))/g, "$0");
362 ok(r === "abc $0 123", "r = '" + r + "' expected 'abc $0 123'");
365 r = "1 2 3".replace("2", "$&");
366 ok(r === "1 $& 3", "r = '" + r + "' expected '1 $& 3'");
367 ok(RegExp.leftContext === "", "RegExp.leftContext = " + RegExp.leftContext);
368 ok(RegExp.rightContext === "", "RegExp.rightContext = " + RegExp.rightContext);
370 r = "1 2 3".replace("2", "$'");
371 ok(r === "1 $' 3", "r = '" + r + "' expected '1 $' 3'");
373 r = "1,,2,3".split(/,+/g);
374 ok(r.length === 3, "r.length = " + r.length);
375 ok(r[0] === "1", "r[0] = " + r[0]);
376 ok(r[1] === "2", "r[1] = " + r[1]);
377 ok(r[2] === "3", "r[2] = " + r[2]);
378 ok(RegExp.leftContext === "1,,2", "RegExp.leftContext = " + RegExp.leftContext);
379 ok(RegExp.rightContext === "3", "RegExp.rightContext = " + RegExp.rightContext);
381 r = "1,,2,3".split(/,+/);
382 ok(r.length === 3, "r.length = " + r.length);
383 ok(r[0] === "1", "r[0] = " + r[0]);
384 ok(r[1] === "2", "r[1] = " + r[1]);
385 ok(r[2] === "3", "r[2] = " + r[2]);
387 r = "1,,2,".split(/,+/);
388 ok(r.length === 2, "r.length = " + r.length);
389 ok(r[0] === "1", "r[0] = " + r[0]);
390 ok(r[1] === "2", "r[1] = " + r[1]);
393 r = "1,,2,".split(re);
394 ok(r.length === 2, "r.length = " + r.length);
395 ok(r[0] === "1", "r[0] = " + r[0]);
396 ok(r[1] === "2", "r[1] = " + r[1]);
397 ok(re.lastIndex === 5, "re.lastIndex = " + re.lastIndex);
400 r = "1,,2,".split(re);
401 ok(r.length === 2, "r.length = " + r.length);
402 ok(r[0] === "1", "r[0] = " + r[0]);
403 ok(r[1] === "2", "r[1] = " + r[1]);
404 ok(re.lastIndex === 5, "re.lastIndex = " + re.lastIndex);
406 r = "1 12 \t3".split(re = /\s+/).join(";");
407 ok(r === "1;12;3", "r = " + r);
408 ok(re.lastIndex === 6, "re.lastIndex = " + re.lastIndex);
410 r = "123".split(re = /\s+/).join(";");
411 ok(r === "123", "r = " + r);
412 ok(re.lastIndex === 0, "re.lastIndex = " + re.lastIndex);
414 /* another standard violation */
415 r = "1 12 \t3".split(re = /(\s)+/g).join(";");
416 ok(r === "1;12;3", "r = " + r);
417 ok(re.lastIndex === 6, "re.lastIndex = " + re.lastIndex);
418 ok(RegExp.leftContext === "1 12", "RegExp.leftContext = " + RegExp.leftContext);
419 ok(RegExp.rightContext === "3", "RegExp.rightContext = " + RegExp.rightContext);
423 r = "1,,2,".split(re);
424 ok(r.length === 2, "r.length = " + r.length);
425 ok(r[0] === "1", "r[0] = " + r[0]);
426 ok(r[1] === "2", "r[1] = " + r[1]);
427 ok(re.lastIndex === 5, "re.lastIndex = " + re.lastIndex);
430 ok(re.source === "abc[^d]", "re.source = '" + re.source + "', expected 'abc[^d]'");
433 ok(re.source === "a\\bc[^d]", "re.source = '" + re.source + "', expected 'a\\bc[^d]'");
436 ok(re === RegExp(re), "re !== RegExp(re)");
438 re = RegExp("abc[^d]", "g");
439 ok(re.source === "abc[^d]", "re.source = '" + re.source + "', expected 'abc[^d]'");
442 ok(re === RegExp(re, undefined), "re !== RegExp(re, undefined)");
445 ok(re === RegExp(re, undefined, 1), "re !== RegExp(re, undefined, 1)");
448 ok(re.lastIndex === 0, "re.lastIndex = " + re.lastIndex + " expected 0");
451 ok(re.lastIndex === 2, "re.lastIndex = " + re.lastIndex + " expected 2");
452 ok(m.index === 1, "m.index = " + m.index + " expected 1");
453 ok(RegExp.leftContext === " ", "RegExp.leftContext = " + RegExp.leftContext);
454 ok(RegExp.rightContext === " ", "RegExp.rightContext = " + RegExp.rightContext);
457 ok(re.lastIndex === 0, "re.lastIndex = " + re.lastIndex + " expected 0");
458 ok(m === null, "m = " + m + " expected null");
461 m = re.exec(" a a ");
462 ok(re.lastIndex === 4, "re.lastIndex = " + re.lastIndex + " expected 4");
463 ok(m.index === 3, "m.index = " + m.index + " expected 3");
466 ok(re.lastIndex === "2", "re.lastIndex = " + re.lastIndex + " expected '2'");
467 m = re.exec(" a a ");
468 ok(re.lastIndex === 4, "re.lastIndex = " + re.lastIndex + " expected 4");
469 ok(m.index === 3, "m.index = " + m.index + " expected 3");
472 var obj = new Object();
473 obj.valueOf = function() { return li; };
476 ok(re.lastIndex === obj, "re.lastIndex = " + re.lastIndex + " expected obj");
478 m = re.exec(" a a ");
479 ok(re.lastIndex === 2, "re.lastIndex = " + re.lastIndex + " expected 2");
480 ok(m.index === 1, "m.index = " + m.index + " expected 1");
483 re.lastIndex = "test";
484 ok(re.lastIndex === "test", "re.lastIndex = " + re.lastIndex + " expected 'test'");
485 m = re.exec(" a a ");
486 ok(re.lastIndex === 2 || re.lastIndex === 0, "re.lastIndex = " + re.lastIndex + " expected 2 or 0");
487 if(re.lastIndex != 0)
488 ok(m.index === 1, "m.index = " + m.index + " expected 1");
490 ok(m === null, "m = " + m + " expected null");
494 ok(re.lastIndex === 3.9, "re.lastIndex = " + re.lastIndex + " expected 3.9");
495 m = re.exec(" a a ");
496 ok(re.lastIndex === 4, "re.lastIndex = " + re.lastIndex + " expected 4");
497 ok(m.index === 3, "m.index = " + m.index + " expected 3");
499 obj.valueOf = function() { throw 0; }
501 ok(re.lastIndex === obj, "unexpected re.lastIndex");
502 m = re.exec(" a a ");
503 ok(re.lastIndex === 2, "re.lastIndex = " + re.lastIndex + " expected 2");
504 ok(m.index === 1, "m.index = " + m.index + " expected 1");
507 ok(re.lastIndex === -3, "re.lastIndex = " + re.lastIndex + " expected -3");
508 m = re.exec(" a a ");
509 ok(re.lastIndex === 0, "re.lastIndex = " + re.lastIndex + " expected 0");
510 ok(m === null, "m = " + m + " expected null");
513 ok(re.lastIndex === -1, "re.lastIndex = " + re.lastIndex + " expected -1");
515 ok(re.lastIndex === 0, "re.lastIndex = " + re.lastIndex + " expected 0");
516 ok(m === null, "m = " + m + " expected null");
520 ok(re.lastIndex === -3, "re.lastIndex = " + re.lastIndex + " expected -3");
521 m = re.exec(" a a ");
522 ok(re.lastIndex === 2, "re.lastIndex = " + re.lastIndex + " expected 0");
523 ok(m.index === 1, "m = " + m + " expected 1");
524 ok(RegExp.leftContext === " ", "RegExp.leftContext = " + RegExp.leftContext);
525 ok(RegExp.rightContext === " a ", "RegExp.rightContext = " + RegExp.rightContext);
528 ok(re.lastIndex === -1, "re.lastIndex = " + re.lastIndex + " expected -1");
530 ok(re.lastIndex === 0, "re.lastIndex = " + re.lastIndex + " expected 0");
531 ok(m === null, "m = " + m + " expected null");
534 i = 'baacd'.search(re);
535 ok(i === 1, "'baacd'.search(re) = " + i);
536 ok(re.lastIndex === 3, "re.lastIndex = " + re.lastIndex);
537 ok(RegExp.leftContext === "b", "RegExp.leftContext = " + RegExp.leftContext);
538 ok(RegExp.rightContext === "cd", "RegExp.rightContext = " + RegExp.rightContext);
541 i = 'baacdaa'.search(re);
542 ok(i === 1, "'baacd'.search(re) = " + i);
543 ok(re.lastIndex === 3, "re.lastIndex = " + re.lastIndex);
546 i = 'baacd'.search(re);
547 ok(i === 1, "'baacd'.search(re) = " + i);
548 ok(re.lastIndex === 3, "re.lastIndex = " + re.lastIndex);
551 i = 'baacdaa'.search(re);
552 ok(i === 1, "'baacd'.search(re) = " + i);
553 ok(re.lastIndex === 3, "re.lastIndex = " + re.lastIndex);
554 ok(RegExp.leftContext === "b", "RegExp.leftContext = " + RegExp.leftContext);
555 ok(RegExp.rightContext === "cdaa", "RegExp.rightContext = " + RegExp.rightContext);
559 i = 'abc'.search(re);
560 ok(i === -1, "'abc'.search(/d/g) = " + i);
561 ok(re.lastIndex === 0, "re.lastIndex = " + re.lastIndex);
562 ok(RegExp.leftContext === "b", "RegExp.leftContext = " + RegExp.leftContext);
563 ok(RegExp.rightContext === "cdaa", "RegExp.rightContext = " + RegExp.rightContext);
565 i = 'abcdde'.search(/[df]/);
566 ok(i === 3, "'abc'.search(/[df]/) = " + i);
568 i = 'abcdde'.search(/[df]/, "a");
569 ok(i === 3, "'abc'.search(/[df]/) = " + i);
571 i = 'abcdde'.search("[df]");
572 ok(i === 3, "'abc'.search(/d*/) = " + i);
575 toString: function() { return "abc"; }
577 i = String.prototype.search.call(obj, "b");
578 ok(i === 1, "String.prototype.seatch.apply(obj, 'b') = " + i);
580 i = " undefined ".search();
581 ok(i === null, "' undefined '.search() = " + i);
583 tmp = "=)".replace(/=/, "?");
584 ok(tmp === "?)", "'=)'.replace(/=/, '?') = " + tmp);
586 tmp = " ".replace(/^\s*|\s*$/g, "y");
587 ok(tmp === "yy", '" ".replace(/^\s*|\s*$/g, "y") = ' + tmp);
589 tmp = "xxx".replace(/^\s*|\s*$/g, "");
590 ok(tmp === "xxx", '"xxx".replace(/^\s*|\s*$/g, "y") = ' + tmp);
592 tmp = "xxx".replace(/^\s*|\s*$/g, "y");
593 ok(tmp === "yxxxy", '"xxx".replace(/^\s*|\s*$/g, "y") = ' + tmp);
595 tmp = "x/y".replace(/[/]/, "*");
596 ok(tmp === "x*y", '"x/y".replace(/[/]/, "*") = ' + tmp);
598 tmp = "x/y".replace(/[xy/]/g, "*");
599 ok(tmp === "***", '"x/y".replace(/[xy/]/, "*") = ' + tmp);