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);
48 ok(re.lastIndex === 0, "re.lastIndex = " + re.lastIndex);
50 m = re.exec(" aabaaa");
51 ok(re.lastIndex === 3, "re.lastIndex = " + re.lastIndex);
52 ok(m.index === 1, "m.index = " + m.index);
53 ok(m.input === " aabaaa", "m.input = " + m.input);
54 ok(m.length === 1, "m.length = " + m.length);
55 ok(m[0] === "aa", "m[0] = " + m[0]);
57 m = re.exec(" aabaaa");
58 ok(re.lastIndex === 7, "re.lastIndex = " + re.lastIndex);
59 ok(m.index === 4, "m.index = " + m.index);
60 ok(m.input === " aabaaa", "m.input = " + m.input);
61 ok(m.length === 1, "m.length = " + m.length);
62 ok(m[0] === "aaa", "m[0] = " + m[0]);
64 m = re.exec(" aabaaa");
65 ok(re.lastIndex === 0, "re.lastIndex = " + re.lastIndex);
66 ok(m === null, "m is not null");
69 ok(re.lastIndex === 16, "re.lastIndex = " + re.lastIndex);
70 ok(RegExp.leftContext === " ",
71 "RegExp.leftContext = " + RegExp.leftContext);
72 ok(RegExp.rightContext === "", "RegExp.rightContext = " + RegExp.rightContext);
75 ok(m === null, "m is not null");
76 ok(re.lastIndex === 0, "re.lastIndex = " + re.lastIndex);
79 ok(re.lastIndex === 2, "re.lastIndex = " + re.lastIndex);
82 ok(m === null, "m is not null");
83 ok(re.lastIndex === 0, "re.lastIndex = " + re.lastIndex);
85 m = /(a|b)+|(c)/.exec("aa");
86 ok(m[0] === "aa", "m[0] = " + m[0]);
87 ok(m[1] === "a", "m[1] = " + m[1]);
88 ok(m[2] === "", "m[2] = " + m[2]);
91 ok(b === true, "re.test(' a ') returned " + b);
92 ok(re.lastIndex === 3, "re.lastIndex = " + re.lastIndex);
93 ok(RegExp.leftContext === " ", "RegExp.leftContext = " + RegExp.leftContext);
94 ok(RegExp.rightContext === " ", "RegExp.rightContext = " + RegExp.rightContext);
97 ok(b === false, "re.test(' a ') returned " + b);
98 ok(re.lastIndex === 0, "re.lastIndex = " + re.lastIndex);
99 ok(RegExp.leftContext === " ", "RegExp.leftContext = " + RegExp.leftContext);
100 ok(RegExp.rightContext === " ", "RegExp.rightContext = " + RegExp.rightContext);
102 re = /\[([^\[]+)\]/g;
103 m = re.exec(" [test] ");
104 ok(re.lastIndex === 7, "re.lastIndex = " + re.lastIndex);
105 ok(m.index === 1, "m.index = " + m.index);
106 ok(m.input === " [test] ", "m.input = " + m.input);
107 ok(m.length === 2, "m.length = " + m.length);
108 ok(m[0] === "[test]", "m[0] = " + m[0]);
109 ok(m[1] === "test", "m[1] = " + m[1]);
112 ok(b === true, "/a*/.test() returned " + b);
113 ok(RegExp.leftContext === "", "RegExp.leftContext = " + RegExp.leftContext);
114 ok(RegExp.rightContext === "undefined", "RegExp.rightContext = " + RegExp.rightContext);
117 ok(b === true, "/f/.test() returned " + b);
118 ok(RegExp.leftContext === "unde", "RegExp.leftContext = " + RegExp.leftContext);
119 ok(RegExp.rightContext === "ined", "RegExp.rightContext = " + RegExp.rightContext);
122 ok(b === false, "/abc/.test() returned " + b);
123 ok(RegExp.leftContext === "unde", "RegExp.leftContext = " + RegExp.leftContext);
124 ok(RegExp.rightContext === "ined", "RegExp.rightContext = " + RegExp.rightContext);
126 m = "abcabc".match(re = /ca/);
127 ok(typeof(m) === "object", "typeof m is not object");
128 ok(m.length === 1, "m.length is not 1");
129 ok(m["0"] === "ca", "m[0] is not \"ca\"");
130 ok(m.constructor === Array, "unexpected m.constructor");
131 ok(re.lastIndex === 4, "re.lastIndex = " + re.lastIndex);
132 ok(RegExp.leftContext === "ab", "RegExp.leftContext = " + RegExp.leftContext);
133 ok(RegExp.rightContext === "bc", "RegExp.rightContext = " + RegExp.rightContext);
135 m = "abcabc".match(/ab/);
136 ok(typeof(m) === "object", "typeof m is not object");
137 ok(m.length === 1, "m.length is not 1");
138 ok(m["0"] === "ab", "m[0] is not \"ab\"");
139 ok(RegExp.leftContext === "", "RegExp.leftContext = " + RegExp.leftContext);
140 ok(RegExp.rightContext === "cabc", "RegExp.rightContext = " + RegExp.rightContext);
142 m = "abcabc".match(/ab/g);
143 ok(typeof(m) === "object", "typeof m is not object");
144 ok(m.length === 2, "m.length is not 2");
145 ok(m["0"] === "ab", "m[0] is not \"ab\"");
146 ok(m["1"] === "ab", "m[1] is not \"ab\"");
147 /* ok(m.input === "abcabc", "m.input = " + m.input); */
149 m = "abcabc".match(/Ab/g);
150 ok(typeof(m) === "object", "typeof m is not object");
151 ok(m === null, "m is not null");
153 m = "abcabc".match(/Ab/gi);
154 ok(typeof(m) === "object", "typeof m is not object");
155 ok(m.length === 2, "m.length is not 2");
156 ok(m["0"] === "ab", "m[0] is not \"ab\"");
157 ok(m["1"] === "ab", "m[1] is not \"ab\"");
158 ok(RegExp.leftContext === "abc", "RegExp.leftContext = " + RegExp.leftContext);
159 ok(RegExp.rightContext === "c", "RegExp.rightContext = " + RegExp.rightContext);
161 m = "aaabcabc".match(/a+b/g);
162 ok(typeof(m) === "object", "typeof m is not object");
163 ok(m.length === 2, "m.length is not 2");
164 ok(m["0"] === "aaab", "m[0] is not \"ab\"");
165 ok(m["1"] === "ab", "m[1] is not \"ab\"");
167 m = "aaa\\\\cabc".match(/\\/g);
168 ok(typeof(m) === "object", "typeof m is not object");
169 ok(m.length === 2, "m.length is not 2");
170 ok(m["0"] === "\\", "m[0] is not \"\\\"");
171 ok(m["1"] === "\\", "m[1] is not \"\\\"");
173 m = "abcabc".match(new RegExp("ab"));
174 ok(typeof(m) === "object", "typeof m is not object");
175 ok(m.length === 1, "m.length is not 1");
176 ok(m["0"] === "ab", "m[0] is not \"ab\"");
178 m = "abcabc".match(new RegExp("ab","g"));
179 ok(typeof(m) === "object", "typeof m is not object");
180 ok(m.length === 2, "m.length is not 2");
181 ok(m["0"] === "ab", "m[0] is not \"ab\"");
182 ok(m["1"] === "ab", "m[1] is not \"ab\"");
183 ok(RegExp.leftContext === "abc", "RegExp.leftContext = " + RegExp.leftContext);
184 ok(RegExp.rightContext === "c", "RegExp.rightContext = " + RegExp.rightContext);
186 m = "abcabc".match(new RegExp(/ab/g));
187 ok(typeof(m) === "object", "typeof m is not object");
188 ok(m.length === 2, "m.length is not 2");
189 ok(m["0"] === "ab", "m[0] is not \"ab\"");
190 ok(m["1"] === "ab", "m[1] is not \"ab\"");
192 m = "abcabc".match(new RegExp("ab","g", "test"));
193 ok(typeof(m) === "object", "typeof m is not object");
194 ok(m.length === 2, "m.length is not 2");
195 ok(m["0"] === "ab", "m[0] is not \"ab\"");
196 ok(m["1"] === "ab", "m[1] is not \"ab\"");
198 m = "abcabcg".match("ab", "g");
199 ok(typeof(m) === "object", "typeof m is not object");
200 ok(m.length === 1, "m.length is not 1");
201 ok(m["0"] === "ab", "m[0] is not \"ab\"");
202 ok(RegExp.leftContext === "", "RegExp.leftContext = " + RegExp.leftContext);
203 ok(RegExp.rightContext === "cabcg", "RegExp.rightContext = " + RegExp.rightContext);
205 m = "abcabc".match();
206 ok(m === null, "m is not null");
207 ok(RegExp.leftContext === "", "RegExp.leftContext = " + RegExp.leftContext);
208 ok(RegExp.rightContext === "cabcg", "RegExp.rightContext = " + RegExp.rightContext);
210 m = "abcabc".match(/(a)(b)cabc/);
211 ok(typeof(m) === "object", "typeof m is not object");
212 ok(m.length === 3, "m.length is not 3");
213 ok(m[0] === "abcabc", "m[0] is not \"abc\"");
214 ok(m[1] === "a", "m[1] is not \"a\"");
215 ok(m[2] === "b", "m[2] is not \"b\"");
219 m = "abcabc".match(re);
220 ok(typeof(m) === "object", "typeof m is not object");
221 ok(m.length === 2, "m.length = " + m.length + "expected 3");
222 ok(m[0] === "abcabc", "m[0] is not \"abc\"");
223 ok(m[1] === "a", "m[1] is not \"a\"");
224 ok(re.lastIndex === 6, "re.lastIndex = " + re.lastIndex);
228 m = "abcabcxxx".match(re);
229 ok(typeof(m) === "object", "typeof m is not object");
230 ok(m.length === 2, "m.length = " + m.length + "expected 3");
231 ok(m[0] === "abcabc", "m[0] is not \"abc\"");
232 ok(m[1] === "a", "m[1] is not \"a\"");
233 ok(m.input === "abcabcxxx", "m.input = " + m.input);
234 ok(re.lastIndex === 6, "re.lastIndex = " + re.lastIndex);
236 r = "- [test] -".replace(re = /\[([^\[]+)\]/g, "success");
237 ok(r === "- success -", "r = " + r + " expected '- success -'");
238 ok(re.lastIndex === 8, "re.lastIndex = " + re.lastIndex);
239 ok(RegExp.leftContext === "- ", "RegExp.leftContext = " + RegExp.leftContext);
240 ok(RegExp.rightContext === " -", "RegExp.rightContext = " + RegExp.rightContext);
242 r = "[test] [test]".replace(/\[([^\[]+)\]/g, "aa");
243 ok(r === "aa aa", "r = " + r + "aa aa");
244 ok(RegExp.leftContext === "[test] ",
245 "RegExp.leftContext = " + RegExp.leftContext);
246 ok(RegExp.rightContext === "",
247 "RegExp.rightContext = " + RegExp.rightContext);
249 r = "[test] [test]".replace(/\[([^\[]+)\]/, "aa");
250 ok(r === "aa [test]", "r = " + r + " expected 'aa [test]'");
252 r = "- [test] -".replace(/\[([^\[]+)\]/g);
253 ok(r === "- undefined -", "r = " + r + " expected '- undefined -'");
255 r = "- [test] -".replace(/\[([^\[]+)\]/g, true);
256 ok(r === "- true -", "r = " + r + " expected '- true -'");
258 r = "- [test] -".replace(/\[([^\[]+)\]/g, true, "test");
259 ok(r === "- true -", "r = " + r + " expected '- true -'");
260 ok(RegExp.leftContext === "- ", "RegExp.leftContext = " + RegExp.leftContext);
261 ok(RegExp.rightContext === " -", "RegExp.rightContext = " + RegExp.rightContext);
265 function replaceFunc1(m, off, str) {
266 ok(arguments.length === 3, "arguments.length = " + arguments.length);
270 ok(m === "[test1]", "m = " + m + " expected [test1]");
271 ok(off === 0, "off = " + off + " expected 0");
272 ok(RegExp.leftContext === "- ",
273 "RegExp.leftContext = " + RegExp.leftContext);
274 ok(RegExp.rightContext === " -",
275 "RegExp.rightContext = " + RegExp.rightContext);
278 ok(m === "[test2]", "m = " + m + " expected [test2]");
279 ok(off === 8, "off = " + off + " expected 8");
280 ok(RegExp.leftContext === "- ",
281 "RegExp.leftContext = " + RegExp.leftContext);
282 ok(RegExp.rightContext === " -",
283 "RegExp.rightContext = " + RegExp.rightContext);
286 ok(false, "unexpected call");
289 ok(str === "[test1] [test2]", "str = " + arguments[3]);
293 r = "[test1] [test2]".replace(/\[[^\[]+\]/g, replaceFunc1);
294 ok(r === "r0 r1", "r = " + r + " expected 'r0 r1'");
295 ok(RegExp.leftContext === "[test1] ", "RegExp.leftContext = " + RegExp.leftContext);
296 ok(RegExp.rightContext === "", "RegExp.rightContext = " + RegExp.rightContext);
300 function replaceFunc2(m, subm, off, str) {
301 ok(arguments.length === 4, "arguments.length = " + arguments.length);
305 ok(subm === "test1", "subm = " + subm);
306 ok(m === "[test1]", "m = " + m + " expected [test1]");
307 ok(off === 0, "off = " + off + " expected 0");
310 ok(subm === "test2", "subm = " + subm);
311 ok(m === "[test2]", "m = " + m + " expected [test2]");
312 ok(off === 8, "off = " + off + " expected 8");
315 ok(false, "unexpected call");
318 ok(str === "[test1] [test2]", "str = " + arguments[3]);
322 r = "[test1] [test2]".replace(/\[([^\[]+)\]/g, replaceFunc2);
323 ok(r === "r0 r1", "r = '" + r + "' expected 'r0 r1'");
325 r = "$1,$2".replace(/(\$(\d))/g, "$$1-$1$2");
326 ok(r === "$1-$11,$1-$22", "r = '" + r + "' expected '$1-$11,$1-$22'");
327 ok(RegExp.leftContext === "$1,", "RegExp.leftContext = " + RegExp.leftContext);
328 ok(RegExp.rightContext === "", "RegExp.rightContext = " + RegExp.rightContext);
330 r = "abc &1 123".replace(/(\&(\d))/g, "$&");
331 ok(r === "abc &1 123", "r = '" + r + "' expected 'abc &1 123'");
332 ok(RegExp.leftContext === "abc ", "RegExp.leftContext = " + RegExp.leftContext);
333 ok(RegExp.rightContext === " 123", "RegExp.rightContext = " + RegExp.rightContext);
335 r = "abc &1 123".replace(/(\&(\d))/g, "$'");
336 ok(r === "abc 123 123", "r = '" + r + "' expected 'abc 123 123'");
338 r = "abc &1 123".replace(/(\&(\d))/g, "$`");
339 ok(r === "abc abc 123", "r = '" + r + "' expected 'abc abc 123'");
341 r = "abc &1 123".replace(/(\&(\d))/g, "$3");
342 ok(r === "abc $3 123", "r = '" + r + "' expected 'abc $3 123'");
344 r = "abc &1 123".replace(/(\&(\d))/g, "$");
345 ok(r === "abc $ 123", "r = '" + r + "' expected 'abc $ 123'");
347 r = "abc &1 123".replace(/(\&(\d))/g, "$a");
348 ok(r === "abc $a 123", "r = '" + r + "' expected 'abc $a 123'");
350 r = "abc &1 123".replace(/(\&(\d))/g, "$11");
351 ok(r === "abc &11 123", "r = '" + r + "' expected 'abc &11 123'");
353 r = "abc &1 123".replace(/(\&(\d))/g, "$0");
354 ok(r === "abc $0 123", "r = '" + r + "' expected 'abc $0 123'");
357 r = "1 2 3".replace("2", "$&");
358 ok(r === "1 $& 3", "r = '" + r + "' expected '1 $& 3'");
359 ok(RegExp.leftContext === "", "RegExp.leftContext = " + RegExp.leftContext);
360 ok(RegExp.rightContext === "", "RegExp.rightContext = " + RegExp.rightContext);
362 r = "1 2 3".replace("2", "$'");
363 ok(r === "1 $' 3", "r = '" + r + "' expected '1 $' 3'");
365 r = "1,,2,3".split(/,+/g);
366 ok(r.length === 3, "r.length = " + r.length);
367 ok(r[0] === "1", "r[0] = " + r[0]);
368 ok(r[1] === "2", "r[1] = " + r[1]);
369 ok(r[2] === "3", "r[2] = " + r[2]);
370 ok(RegExp.leftContext === "1,,2", "RegExp.leftContext = " + RegExp.leftContext);
371 ok(RegExp.rightContext === "3", "RegExp.rightContext = " + RegExp.rightContext);
373 r = "1,,2,3".split(/,+/);
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]);
379 r = "1,,2,".split(/,+/);
380 ok(r.length === 2, "r.length = " + r.length);
381 ok(r[0] === "1", "r[0] = " + r[0]);
382 ok(r[1] === "2", "r[1] = " + r[1]);
385 r = "1,,2,".split(re);
386 ok(r.length === 2, "r.length = " + r.length);
387 ok(r[0] === "1", "r[0] = " + r[0]);
388 ok(r[1] === "2", "r[1] = " + r[1]);
389 ok(re.lastIndex === 5, "re.lastIndex = " + re.lastIndex);
392 r = "1,,2,".split(re);
393 ok(r.length === 2, "r.length = " + r.length);
394 ok(r[0] === "1", "r[0] = " + r[0]);
395 ok(r[1] === "2", "r[1] = " + r[1]);
396 ok(re.lastIndex === 5, "re.lastIndex = " + re.lastIndex);
398 r = "1 12 \t3".split(re = /\s+/).join(";");
399 ok(r === "1;12;3", "r = " + r);
400 ok(re.lastIndex === 6, "re.lastIndex = " + re.lastIndex);
402 r = "123".split(re = /\s+/).join(";");
403 ok(r === "123", "r = " + r);
404 ok(re.lastIndex === 0, "re.lastIndex = " + re.lastIndex);
406 /* another standard violation */
407 r = "1 12 \t3".split(re = /(\s)+/g).join(";");
408 ok(r === "1;12;3", "r = " + r);
409 ok(re.lastIndex === 6, "re.lastIndex = " + re.lastIndex);
410 ok(RegExp.leftContext === "1 12", "RegExp.leftContext = " + RegExp.leftContext);
411 ok(RegExp.rightContext === "3", "RegExp.rightContext = " + RegExp.rightContext);
415 r = "1,,2,".split(re);
416 ok(r.length === 2, "r.length = " + r.length);
417 ok(r[0] === "1", "r[0] = " + r[0]);
418 ok(r[1] === "2", "r[1] = " + r[1]);
419 ok(re.lastIndex === 5, "re.lastIndex = " + re.lastIndex);
422 ok(re.source === "abc[^d]", "re.source = '" + re.source + "', expected 'abc[^d]'");
425 ok(re.source === "a\\bc[^d]", "re.source = '" + re.source + "', expected 'a\\bc[^d]'");
428 ok(re === RegExp(re), "re !== RegExp(re)");
430 re = RegExp("abc[^d]", "g");
431 ok(re.source === "abc[^d]", "re.source = '" + re.source + "', expected 'abc[^d]'");
434 ok(re === RegExp(re, undefined), "re !== RegExp(re, undefined)");
437 ok(re === RegExp(re, undefined, 1), "re !== RegExp(re, undefined, 1)");
440 ok(re.lastIndex === 0, "re.lastIndex = " + re.lastIndex + " expected 0");
443 ok(re.lastIndex === 2, "re.lastIndex = " + re.lastIndex + " expected 2");
444 ok(m.index === 1, "m.index = " + m.index + " expected 1");
445 ok(RegExp.leftContext === " ", "RegExp.leftContext = " + RegExp.leftContext);
446 ok(RegExp.rightContext === " ", "RegExp.rightContext = " + RegExp.rightContext);
449 ok(re.lastIndex === 0, "re.lastIndex = " + re.lastIndex + " expected 0");
450 ok(m === null, "m = " + m + " expected null");
453 m = re.exec(" a a ");
454 ok(re.lastIndex === 4, "re.lastIndex = " + re.lastIndex + " expected 4");
455 ok(m.index === 3, "m.index = " + m.index + " expected 3");
458 ok(re.lastIndex === "2", "re.lastIndex = " + re.lastIndex + " expected '2'");
459 m = re.exec(" a a ");
460 ok(re.lastIndex === 4, "re.lastIndex = " + re.lastIndex + " expected 4");
461 ok(m.index === 3, "m.index = " + m.index + " expected 3");
464 var obj = new Object();
465 obj.valueOf = function() { return li; };
468 ok(re.lastIndex === obj, "re.lastIndex = " + re.lastIndex + " expected obj");
470 m = re.exec(" a a ");
471 ok(re.lastIndex === 2, "re.lastIndex = " + re.lastIndex + " expected 2");
472 ok(m.index === 1, "m.index = " + m.index + " expected 1");
475 re.lastIndex = "test";
476 ok(re.lastIndex === "test", "re.lastIndex = " + re.lastIndex + " expected 'test'");
477 m = re.exec(" a a ");
478 ok(re.lastIndex === 2 || re.lastIndex === 0, "re.lastIndex = " + re.lastIndex + " expected 2 or 0");
479 if(re.lastIndex != 0)
480 ok(m.index === 1, "m.index = " + m.index + " expected 1");
482 ok(m === null, "m = " + m + " expected null");
486 ok(re.lastIndex === 3.9, "re.lastIndex = " + re.lastIndex + " expected 3.9");
487 m = re.exec(" a a ");
488 ok(re.lastIndex === 4, "re.lastIndex = " + re.lastIndex + " expected 4");
489 ok(m.index === 3, "m.index = " + m.index + " expected 3");
491 obj.valueOf = function() { throw 0; }
493 ok(re.lastIndex === obj, "unexpected re.lastIndex");
494 m = re.exec(" a a ");
495 ok(re.lastIndex === 2, "re.lastIndex = " + re.lastIndex + " expected 2");
496 ok(m.index === 1, "m.index = " + m.index + " expected 1");
499 ok(re.lastIndex === -3, "re.lastIndex = " + re.lastIndex + " expected -3");
500 m = re.exec(" a a ");
501 ok(re.lastIndex === 0, "re.lastIndex = " + re.lastIndex + " expected 0");
502 ok(m === null, "m = " + m + " expected null");
505 ok(re.lastIndex === -1, "re.lastIndex = " + re.lastIndex + " expected -1");
507 ok(re.lastIndex === 0, "re.lastIndex = " + re.lastIndex + " expected 0");
508 ok(m === null, "m = " + m + " expected null");
512 ok(re.lastIndex === -3, "re.lastIndex = " + re.lastIndex + " expected -3");
513 m = re.exec(" a a ");
514 ok(re.lastIndex === 2, "re.lastIndex = " + re.lastIndex + " expected 0");
515 ok(m.index === 1, "m = " + m + " expected 1");
516 ok(RegExp.leftContext === " ", "RegExp.leftContext = " + RegExp.leftContext);
517 ok(RegExp.rightContext === " a ", "RegExp.rightContext = " + RegExp.rightContext);
520 ok(re.lastIndex === -1, "re.lastIndex = " + re.lastIndex + " expected -1");
522 ok(re.lastIndex === 0, "re.lastIndex = " + re.lastIndex + " expected 0");
523 ok(m === null, "m = " + m + " expected null");
526 i = 'baacd'.search(re);
527 ok(i === 1, "'baacd'.search(re) = " + i);
528 ok(re.lastIndex === 3, "re.lastIndex = " + re.lastIndex);
529 ok(RegExp.leftContext === "b", "RegExp.leftContext = " + RegExp.leftContext);
530 ok(RegExp.rightContext === "cd", "RegExp.rightContext = " + RegExp.rightContext);
533 i = 'baacdaa'.search(re);
534 ok(i === 1, "'baacd'.search(re) = " + i);
535 ok(re.lastIndex === 3, "re.lastIndex = " + re.lastIndex);
538 i = 'baacd'.search(re);
539 ok(i === 1, "'baacd'.search(re) = " + i);
540 ok(re.lastIndex === 3, "re.lastIndex = " + re.lastIndex);
543 i = 'baacdaa'.search(re);
544 ok(i === 1, "'baacd'.search(re) = " + i);
545 ok(re.lastIndex === 3, "re.lastIndex = " + re.lastIndex);
546 ok(RegExp.leftContext === "b", "RegExp.leftContext = " + RegExp.leftContext);
547 ok(RegExp.rightContext === "cdaa", "RegExp.rightContext = " + RegExp.rightContext);
551 i = 'abc'.search(re);
552 ok(i === -1, "'abc'.search(/d/g) = " + i);
553 ok(re.lastIndex === 0, "re.lastIndex = " + re.lastIndex);
554 ok(RegExp.leftContext === "b", "RegExp.leftContext = " + RegExp.leftContext);
555 ok(RegExp.rightContext === "cdaa", "RegExp.rightContext = " + RegExp.rightContext);
557 i = 'abcdde'.search(/[df]/);
558 ok(i === 3, "'abc'.search(/[df]/) = " + i);
560 i = 'abcdde'.search(/[df]/, "a");
561 ok(i === 3, "'abc'.search(/[df]/) = " + i);
563 i = 'abcdde'.search("[df]");
564 ok(i === 3, "'abc'.search(/d*/) = " + i);
567 toString: function() { return "abc"; }
569 i = String.prototype.search.call(obj, "b");
570 ok(i === 1, "String.prototype.seatch.apply(obj, 'b') = " + i);
572 i = " undefined ".search();
573 ok(i === null, "' undefined '.search() = " + i);