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
.lastIndex
== 3, "m.lastIndex = " + m
.lastIndex
);
54 ok(m
.input
=== " aabaaa", "m.input = " + m
.input
);
55 ok(m
.length
=== 1, "m.length = " + m
.length
);
56 ok(m
[0] === "aa", "m[0] = " + m
[0]);
58 m
= re
.exec(" aabaaa");
59 ok(re
.lastIndex
=== 7, "re.lastIndex = " + re
.lastIndex
);
60 ok(m
.index
=== 4, "m.index = " + m
.index
);
61 ok(m
.input
=== " aabaaa", "m.input = " + m
.input
);
62 ok(m
.length
=== 1, "m.length = " + m
.length
);
63 ok(m
[0] === "aaa", "m[0] = " + m
[0]);
65 m
= re
.exec(" aabaaa");
66 ok(re
.lastIndex
=== 0, "re.lastIndex = " + re
.lastIndex
);
67 ok(m
=== null, "m is not null");
70 ok(re
.lastIndex
=== 16, "re.lastIndex = " + re
.lastIndex
);
71 ok(RegExp
.leftContext
=== " ",
72 "RegExp.leftContext = " + RegExp
.leftContext
);
73 ok(RegExp
.rightContext
=== "", "RegExp.rightContext = " + RegExp
.rightContext
);
76 ok(m
=== null, "m is not null");
77 ok(re
.lastIndex
=== 0, "re.lastIndex = " + re
.lastIndex
);
80 ok(re
.lastIndex
=== 2, "re.lastIndex = " + re
.lastIndex
);
83 ok(m
=== null, "m is not null");
84 ok(re
.lastIndex
=== 0, "re.lastIndex = " + re
.lastIndex
);
86 m
= /(a|b)+|(c)/.exec("aa");
87 ok(m
[0] === "aa", "m[0] = " + m
[0]);
88 ok(m
[1] === "a", "m[1] = " + m
[1]);
89 ok(m
[2] === "", "m[2] = " + m
[2]);
92 ok(b
=== true, "re.test(' a ') returned " + b
);
93 ok(re
.lastIndex
=== 3, "re.lastIndex = " + re
.lastIndex
);
94 ok(RegExp
.leftContext
=== " ", "RegExp.leftContext = " + RegExp
.leftContext
);
95 ok(RegExp
.rightContext
=== " ", "RegExp.rightContext = " + RegExp
.rightContext
);
98 ok(b
=== false, "re.test(' a ') returned " + b
);
99 ok(re
.lastIndex
=== 0, "re.lastIndex = " + re
.lastIndex
);
100 ok(RegExp
.leftContext
=== " ", "RegExp.leftContext = " + RegExp
.leftContext
);
101 ok(RegExp
.rightContext
=== " ", "RegExp.rightContext = " + RegExp
.rightContext
);
103 re
= /\[([^\[]+)\]/g;
104 m
= re
.exec(" [test] ");
105 ok(re
.lastIndex
=== 7, "re.lastIndex = " + re
.lastIndex
);
106 ok(m
.index
=== 1, "m.index = " + m
.index
);
107 ok(m
.input
=== " [test] ", "m.input = " + m
.input
);
108 ok(m
.length
=== 2, "m.length = " + m
.length
);
109 ok(m
[0] === "[test]", "m[0] = " + m
[0]);
110 ok(m
[1] === "test", "m[1] = " + m
[1]);
113 ok(b
=== true, "/a*/.test() returned " + b
);
114 ok(RegExp
.leftContext
=== "", "RegExp.leftContext = " + RegExp
.leftContext
);
115 ok(RegExp
.rightContext
=== "undefined", "RegExp.rightContext = " + RegExp
.rightContext
);
118 ok(b
=== true, "/f/.test() returned " + b
);
119 ok(RegExp
.leftContext
=== "unde", "RegExp.leftContext = " + RegExp
.leftContext
);
120 ok(RegExp
.rightContext
=== "ined", "RegExp.rightContext = " + RegExp
.rightContext
);
123 ok(b
=== false, "/abc/.test() returned " + b
);
124 ok(RegExp
.leftContext
=== "unde", "RegExp.leftContext = " + RegExp
.leftContext
);
125 ok(RegExp
.rightContext
=== "ined", "RegExp.rightContext = " + RegExp
.rightContext
);
127 m
= "abcabc".match(re
= /ca/);
128 ok(typeof(m
) === "object", "typeof m is not object");
129 ok(m
.length
=== 1, "m.length is not 1");
130 ok(m
["0"] === "ca", "m[0] is not \"ca\"");
131 ok(m
.constructor === Array
, "unexpected m.constructor");
132 ok(re
.lastIndex
=== 4, "re.lastIndex = " + re
.lastIndex
);
133 ok(RegExp
.leftContext
=== "ab", "RegExp.leftContext = " + RegExp
.leftContext
);
134 ok(RegExp
.rightContext
=== "bc", "RegExp.rightContext = " + RegExp
.rightContext
);
136 m
= "abcabc".match(/ab/);
137 ok(typeof(m
) === "object", "typeof m is not object");
138 ok(m
.length
=== 1, "m.length is not 1");
139 ok(m
["0"] === "ab", "m[0] is not \"ab\"");
140 ok(RegExp
.leftContext
=== "", "RegExp.leftContext = " + RegExp
.leftContext
);
141 ok(RegExp
.rightContext
=== "cabc", "RegExp.rightContext = " + RegExp
.rightContext
);
143 m
= "abcabc".match(/ab/g);
144 ok(typeof(m
) === "object", "typeof m is not object");
145 ok(m
.length
=== 2, "m.length is not 2");
146 ok(m
["0"] === "ab", "m[0] is not \"ab\"");
147 ok(m
["1"] === "ab", "m[1] is not \"ab\"");
148 /* ok(m.input === "abcabc", "m.input = " + m.input); */
150 m
= "abcabc".match(/Ab/g);
151 ok(typeof(m
) === "object", "typeof m is not object");
152 ok(m
=== null, "m is not null");
154 m
= "abcabc".match(/Ab/gi);
155 ok(typeof(m
) === "object", "typeof m is not object");
156 ok(m
.length
=== 2, "m.length is not 2");
157 ok(m
["0"] === "ab", "m[0] is not \"ab\"");
158 ok(m
["1"] === "ab", "m[1] is not \"ab\"");
159 ok(RegExp
.leftContext
=== "abc", "RegExp.leftContext = " + RegExp
.leftContext
);
160 ok(RegExp
.rightContext
=== "c", "RegExp.rightContext = " + RegExp
.rightContext
);
162 m
= "aaabcabc".match(/a+b/g);
163 ok(typeof(m
) === "object", "typeof m is not object");
164 ok(m
.length
=== 2, "m.length is not 2");
165 ok(m
["0"] === "aaab", "m[0] is not \"ab\"");
166 ok(m
["1"] === "ab", "m[1] is not \"ab\"");
168 m
= "aaa\\\\cabc".match(/\\/g
);
169 ok(typeof(m
) === "object", "typeof m is not object");
170 ok(m
.length
=== 2, "m.length is not 2");
171 ok(m
["0"] === "\\", "m[0] is not \"\\\"");
172 ok(m
["1"] === "\\", "m[1] is not \"\\\"");
174 m
= "abcabc".match(new RegExp("ab"));
175 ok(typeof(m
) === "object", "typeof m is not object");
176 ok(m
.length
=== 1, "m.length is not 1");
177 ok(m
["0"] === "ab", "m[0] is not \"ab\"");
179 m
= "abcabc".match(new RegExp("ab","g"));
180 ok(typeof(m
) === "object", "typeof m is not object");
181 ok(m
.length
=== 2, "m.length is not 2");
182 ok(m
["0"] === "ab", "m[0] is not \"ab\"");
183 ok(m
["1"] === "ab", "m[1] is not \"ab\"");
184 ok(RegExp
.leftContext
=== "abc", "RegExp.leftContext = " + RegExp
.leftContext
);
185 ok(RegExp
.rightContext
=== "c", "RegExp.rightContext = " + RegExp
.rightContext
);
187 m
= "abcabc".match(new RegExp(/ab/g));
188 ok(typeof(m
) === "object", "typeof m is not object");
189 ok(m
.length
=== 2, "m.length is not 2");
190 ok(m
["0"] === "ab", "m[0] is not \"ab\"");
191 ok(m
["1"] === "ab", "m[1] is not \"ab\"");
193 m
= "abcabc".match(new RegExp("ab","g", "test"));
194 ok(typeof(m
) === "object", "typeof m is not object");
195 ok(m
.length
=== 2, "m.length is not 2");
196 ok(m
["0"] === "ab", "m[0] is not \"ab\"");
197 ok(m
["1"] === "ab", "m[1] is not \"ab\"");
198 ok(m
.index
=== 3, "m.index = " + m
.index
);
199 ok(m
.input
=== "abcabc", "m.input = " + m
.input
);
200 ok(m
.lastIndex
=== 5, "m.lastIndex = " + m
.lastIndex
);
202 m
= "abcabcg".match("ab", "g");
203 ok(typeof(m
) === "object", "typeof m is not object");
204 ok(m
.length
=== 1, "m.length is not 1");
205 ok(m
["0"] === "ab", "m[0] is not \"ab\"");
206 ok(RegExp
.leftContext
=== "", "RegExp.leftContext = " + RegExp
.leftContext
);
207 ok(RegExp
.rightContext
=== "cabcg", "RegExp.rightContext = " + RegExp
.rightContext
);
209 m
= "abcabc".match();
210 ok(m
=== null, "m is not null");
211 ok(RegExp
.leftContext
=== "", "RegExp.leftContext = " + RegExp
.leftContext
);
212 ok(RegExp
.rightContext
=== "cabcg", "RegExp.rightContext = " + RegExp
.rightContext
);
214 m
= "abcabc".match(/(a)(b)cabc/);
215 ok(typeof(m
) === "object", "typeof m is not object");
216 ok(m
.length
=== 3, "m.length is not 3");
217 ok(m
[0] === "abcabc", "m[0] is not \"abc\"");
218 ok(m
[1] === "a", "m[1] is not \"a\"");
219 ok(m
[2] === "b", "m[2] is not \"b\"");
223 m
= "abcabc".match(re
);
224 ok(typeof(m
) === "object", "typeof m is not object");
225 ok(m
.length
=== 2, "m.length = " + m
.length
+ "expected 3");
226 ok(m
[0] === "abcabc", "m[0] is not \"abc\"");
227 ok(m
[1] === "a", "m[1] is not \"a\"");
228 ok(re
.lastIndex
=== 6, "re.lastIndex = " + re
.lastIndex
);
232 m
= "abcabcxxx".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(m
.input
=== "abcabcxxx", "m.input = " + m
.input
);
238 ok(re
.lastIndex
=== 6, "re.lastIndex = " + re
.lastIndex
);
240 r
= "- [test] -".replace(re
= /\[([^\[]+)\]/g, "success");
241 ok(r
=== "- success -", "r = " + r
+ " expected '- success -'");
242 ok(re
.lastIndex
=== 8, "re.lastIndex = " + re
.lastIndex
);
243 ok(RegExp
.leftContext
=== "- ", "RegExp.leftContext = " + RegExp
.leftContext
);
244 ok(RegExp
.rightContext
=== " -", "RegExp.rightContext = " + RegExp
.rightContext
);
246 r
= "[test] [test]".replace(/\[([^\[]+)\]/g, "aa");
247 ok(r
=== "aa aa", "r = " + r
+ "aa aa");
248 ok(RegExp
.leftContext
=== "[test] ",
249 "RegExp.leftContext = " + RegExp
.leftContext
);
250 ok(RegExp
.rightContext
=== "",
251 "RegExp.rightContext = " + RegExp
.rightContext
);
253 r
= "[test] [test]".replace(/\[([^\[]+)\]/, "aa");
254 ok(r
=== "aa [test]", "r = " + r
+ " expected 'aa [test]'");
256 r
= "- [test] -".replace(/\[([^\[]+)\]/g);
257 ok(r
=== "- undefined -", "r = " + r
+ " expected '- undefined -'");
259 r
= "- [test] -".replace(/\[([^\[]+)\]/g, true);
260 ok(r
=== "- true -", "r = " + r
+ " expected '- true -'");
262 r
= "- [test] -".replace(/\[([^\[]+)\]/g, true, "test");
263 ok(r
=== "- true -", "r = " + r
+ " expected '- true -'");
264 ok(RegExp
.leftContext
=== "- ", "RegExp.leftContext = " + RegExp
.leftContext
);
265 ok(RegExp
.rightContext
=== " -", "RegExp.rightContext = " + RegExp
.rightContext
);
269 function replaceFunc1(m
, off
, str
) {
270 ok(arguments
.length
=== 3, "arguments.length = " + arguments
.length
);
274 ok(m
=== "[test1]", "m = " + m
+ " expected [test1]");
275 ok(off
=== 0, "off = " + off
+ " expected 0");
276 ok(RegExp
.leftContext
=== "- ",
277 "RegExp.leftContext = " + RegExp
.leftContext
);
278 ok(RegExp
.rightContext
=== " -",
279 "RegExp.rightContext = " + RegExp
.rightContext
);
282 ok(m
=== "[test2]", "m = " + m
+ " expected [test2]");
283 ok(off
=== 8, "off = " + off
+ " expected 8");
284 ok(RegExp
.leftContext
=== "- ",
285 "RegExp.leftContext = " + RegExp
.leftContext
);
286 ok(RegExp
.rightContext
=== " -",
287 "RegExp.rightContext = " + RegExp
.rightContext
);
290 ok(false, "unexpected call");
293 ok(str
=== "[test1] [test2]", "str = " + arguments
[3]);
297 r
= "[test1] [test2]".replace(/\[[^\[]+\]/g, replaceFunc1
);
298 ok(r
=== "r0 r1", "r = " + r
+ " expected 'r0 r1'");
299 ok(RegExp
.leftContext
=== "[test1] ", "RegExp.leftContext = " + RegExp
.leftContext
);
300 ok(RegExp
.rightContext
=== "", "RegExp.rightContext = " + RegExp
.rightContext
);
304 function replaceFunc2(m
, subm
, off
, str
) {
305 ok(arguments
.length
=== 4, "arguments.length = " + arguments
.length
);
309 ok(subm
=== "test1", "subm = " + subm
);
310 ok(m
=== "[test1]", "m = " + m
+ " expected [test1]");
311 ok(off
=== 0, "off = " + off
+ " expected 0");
314 ok(subm
=== "test2", "subm = " + subm
);
315 ok(m
=== "[test2]", "m = " + m
+ " expected [test2]");
316 ok(off
=== 8, "off = " + off
+ " expected 8");
319 ok(false, "unexpected call");
322 ok(str
=== "[test1] [test2]", "str = " + arguments
[3]);
326 r
= "[test1] [test2]".replace(/\[([^\[]+)\]/g, replaceFunc2
);
327 ok(r
=== "r0 r1", "r = '" + r
+ "' expected 'r0 r1'");
329 r
= "$1,$2".replace(/(\$(\d))/g, "$$1-$1$2");
330 ok(r
=== "$1-$11,$1-$22", "r = '" + r
+ "' expected '$1-$11,$1-$22'");
331 ok(RegExp
.leftContext
=== "$1,", "RegExp.leftContext = " + RegExp
.leftContext
);
332 ok(RegExp
.rightContext
=== "", "RegExp.rightContext = " + RegExp
.rightContext
);
334 r
= "abc &1 123".replace(/(\&(\d))/g, "$&");
335 ok(r
=== "abc &1 123", "r = '" + r
+ "' expected 'abc &1 123'");
336 ok(RegExp
.leftContext
=== "abc ", "RegExp.leftContext = " + RegExp
.leftContext
);
337 ok(RegExp
.rightContext
=== " 123", "RegExp.rightContext = " + RegExp
.rightContext
);
339 r
= "abc &1 123".replace(/(\&(\d))/g, "$'");
340 ok(r
=== "abc 123 123", "r = '" + r
+ "' expected 'abc 123 123'");
342 r
= "abc &1 123".replace(/(\&(\d))/g, "$`");
343 ok(r
=== "abc abc 123", "r = '" + r
+ "' expected 'abc abc 123'");
345 r
= "abc &1 123".replace(/(\&(\d))/g, "$3");
346 ok(r
=== "abc $3 123", "r = '" + r
+ "' expected 'abc $3 123'");
348 r
= "abc &1 123".replace(/(\&(\d))/g, "$");
349 ok(r
=== "abc $ 123", "r = '" + r
+ "' expected 'abc $ 123'");
351 r
= "abc &1 123".replace(/(\&(\d))/g, "$a");
352 ok(r
=== "abc $a 123", "r = '" + r
+ "' expected 'abc $a 123'");
354 r
= "abc &1 123".replace(/(\&(\d))/g, "$11");
355 ok(r
=== "abc &11 123", "r = '" + r
+ "' expected 'abc &11 123'");
357 r
= "abc &1 123".replace(/(\&(\d))/g, "$0");
358 ok(r
=== "abc $0 123", "r = '" + r
+ "' expected 'abc $0 123'");
361 r
= "1 2 3".replace("2", "$&");
362 ok(r
=== "1 $& 3", "r = '" + r
+ "' expected '1 $& 3'");
363 ok(RegExp
.leftContext
=== "", "RegExp.leftContext = " + RegExp
.leftContext
);
364 ok(RegExp
.rightContext
=== "", "RegExp.rightContext = " + RegExp
.rightContext
);
366 r
= "1 2 3".replace("2", "$'");
367 ok(r
=== "1 $' 3", "r = '" + r
+ "' expected '1 $' 3'");
369 r
= "1,,2,3".split(/,+/g);
370 ok(r
.length
=== 3, "r.length = " + r
.length
);
371 ok(r
[0] === "1", "r[0] = " + r
[0]);
372 ok(r
[1] === "2", "r[1] = " + r
[1]);
373 ok(r
[2] === "3", "r[2] = " + r
[2]);
374 ok(RegExp
.leftContext
=== "1,,2", "RegExp.leftContext = " + RegExp
.leftContext
);
375 ok(RegExp
.rightContext
=== "3", "RegExp.rightContext = " + RegExp
.rightContext
);
377 r
= "1,,2,3".split(/,+/);
378 ok(r
.length
=== 3, "r.length = " + r
.length
);
379 ok(r
[0] === "1", "r[0] = " + r
[0]);
380 ok(r
[1] === "2", "r[1] = " + r
[1]);
381 ok(r
[2] === "3", "r[2] = " + r
[2]);
383 r
= "1,,2,".split(/,+/);
384 ok(r
.length
=== 2, "r.length = " + r
.length
);
385 ok(r
[0] === "1", "r[0] = " + r
[0]);
386 ok(r
[1] === "2", "r[1] = " + r
[1]);
389 r
= "1,,2,".split(re
);
390 ok(r
.length
=== 2, "r.length = " + r
.length
);
391 ok(r
[0] === "1", "r[0] = " + r
[0]);
392 ok(r
[1] === "2", "r[1] = " + r
[1]);
393 ok(re
.lastIndex
=== 5, "re.lastIndex = " + re
.lastIndex
);
396 r
= "1,,2,".split(re
);
397 ok(r
.length
=== 2, "r.length = " + r
.length
);
398 ok(r
[0] === "1", "r[0] = " + r
[0]);
399 ok(r
[1] === "2", "r[1] = " + r
[1]);
400 ok(re
.lastIndex
=== 5, "re.lastIndex = " + re
.lastIndex
);
402 r
= "1 12 \t3".split(re
= /\s+/).join(";");
403 ok(r
=== "1;12;3", "r = " + r
);
404 ok(re
.lastIndex
=== 6, "re.lastIndex = " + re
.lastIndex
);
406 r
= "123".split(re
= /\s+/).join(";");
407 ok(r
=== "123", "r = " + r
);
408 ok(re
.lastIndex
=== 0, "re.lastIndex = " + re
.lastIndex
);
410 /* another standard violation */
411 r
= "1 12 \t3".split(re
= /(\s)+/g).join(";");
412 ok(r
=== "1;12;3", "r = " + r
);
413 ok(re
.lastIndex
=== 6, "re.lastIndex = " + re
.lastIndex
);
414 ok(RegExp
.leftContext
=== "1 12", "RegExp.leftContext = " + RegExp
.leftContext
);
415 ok(RegExp
.rightContext
=== "3", "RegExp.rightContext = " + RegExp
.rightContext
);
419 r
= "1,,2,".split(re
);
420 ok(r
.length
=== 2, "r.length = " + r
.length
);
421 ok(r
[0] === "1", "r[0] = " + r
[0]);
422 ok(r
[1] === "2", "r[1] = " + r
[1]);
423 ok(re
.lastIndex
=== 5, "re.lastIndex = " + re
.lastIndex
);
426 ok(re
.source
=== "abc[^d]", "re.source = '" + re
.source
+ "', expected 'abc[^d]'");
429 ok(re
.source
=== "a\\bc[^d]", "re.source = '" + re
.source
+ "', expected 'a\\bc[^d]'");
432 ok(re
=== RegExp(re
), "re !== RegExp(re)");
434 re
= RegExp("abc[^d]", "g");
435 ok(re
.source
=== "abc[^d]", "re.source = '" + re
.source
+ "', expected 'abc[^d]'");
438 ok(re
=== RegExp(re
, undefined), "re !== RegExp(re, undefined)");
441 ok(re
=== RegExp(re
, undefined, 1), "re !== RegExp(re, undefined, 1)");
444 ok(re
.lastIndex
=== 0, "re.lastIndex = " + re
.lastIndex
+ " expected 0");
447 ok(re
.lastIndex
=== 2, "re.lastIndex = " + re
.lastIndex
+ " expected 2");
448 ok(m
.index
=== 1, "m.index = " + m
.index
+ " expected 1");
449 ok(RegExp
.leftContext
=== " ", "RegExp.leftContext = " + RegExp
.leftContext
);
450 ok(RegExp
.rightContext
=== " ", "RegExp.rightContext = " + RegExp
.rightContext
);
453 ok(re
.lastIndex
=== 0, "re.lastIndex = " + re
.lastIndex
+ " expected 0");
454 ok(m
=== null, "m = " + m
+ " expected null");
457 m
= re
.exec(" a a ");
458 ok(re
.lastIndex
=== 4, "re.lastIndex = " + re
.lastIndex
+ " expected 4");
459 ok(m
.index
=== 3, "m.index = " + m
.index
+ " expected 3");
462 ok(re
.lastIndex
=== "2", "re.lastIndex = " + re
.lastIndex
+ " expected '2'");
463 m
= re
.exec(" a a ");
464 ok(re
.lastIndex
=== 4, "re.lastIndex = " + re
.lastIndex
+ " expected 4");
465 ok(m
.index
=== 3, "m.index = " + m
.index
+ " expected 3");
468 var obj
= new Object();
469 obj
.valueOf = function() { return li
; };
472 ok(re
.lastIndex
=== obj
, "re.lastIndex = " + re
.lastIndex
+ " expected obj");
474 m
= re
.exec(" a a ");
475 ok(re
.lastIndex
=== 2, "re.lastIndex = " + re
.lastIndex
+ " expected 2");
476 ok(m
.index
=== 1, "m.index = " + m
.index
+ " expected 1");
479 re
.lastIndex
= "test";
480 ok(re
.lastIndex
=== "test", "re.lastIndex = " + re
.lastIndex
+ " expected 'test'");
481 m
= re
.exec(" a a ");
482 ok(re
.lastIndex
=== 2 || re
.lastIndex
=== 0, "re.lastIndex = " + re
.lastIndex
+ " expected 2 or 0");
483 if(re
.lastIndex
!= 0)
484 ok(m
.index
=== 1, "m.index = " + m
.index
+ " expected 1");
486 ok(m
=== null, "m = " + m
+ " expected null");
490 ok(re
.lastIndex
=== 3.9, "re.lastIndex = " + re
.lastIndex
+ " expected 3.9");
491 m
= re
.exec(" a a ");
492 ok(re
.lastIndex
=== 4, "re.lastIndex = " + re
.lastIndex
+ " expected 4");
493 ok(m
.index
=== 3, "m.index = " + m
.index
+ " expected 3");
495 obj
.valueOf = function() { throw 0; }
497 ok(re
.lastIndex
=== obj
, "unexpected re.lastIndex");
498 m
= re
.exec(" a a ");
499 ok(re
.lastIndex
=== 2, "re.lastIndex = " + re
.lastIndex
+ " expected 2");
500 ok(m
.index
=== 1, "m.index = " + m
.index
+ " expected 1");
503 ok(re
.lastIndex
=== -3, "re.lastIndex = " + re
.lastIndex
+ " expected -3");
504 m
= re
.exec(" a a ");
505 ok(re
.lastIndex
=== 0, "re.lastIndex = " + re
.lastIndex
+ " expected 0");
506 ok(m
=== null, "m = " + m
+ " expected null");
509 ok(re
.lastIndex
=== -1, "re.lastIndex = " + re
.lastIndex
+ " expected -1");
511 ok(re
.lastIndex
=== 0, "re.lastIndex = " + re
.lastIndex
+ " expected 0");
512 ok(m
=== null, "m = " + m
+ " expected null");
516 ok(re
.lastIndex
=== -3, "re.lastIndex = " + re
.lastIndex
+ " expected -3");
517 m
= re
.exec(" a a ");
518 ok(re
.lastIndex
=== 2, "re.lastIndex = " + re
.lastIndex
+ " expected 0");
519 ok(m
.index
=== 1, "m = " + m
+ " expected 1");
520 ok(RegExp
.leftContext
=== " ", "RegExp.leftContext = " + RegExp
.leftContext
);
521 ok(RegExp
.rightContext
=== " a ", "RegExp.rightContext = " + RegExp
.rightContext
);
524 ok(re
.lastIndex
=== -1, "re.lastIndex = " + re
.lastIndex
+ " expected -1");
526 ok(re
.lastIndex
=== 0, "re.lastIndex = " + re
.lastIndex
+ " expected 0");
527 ok(m
=== null, "m = " + m
+ " expected null");
530 i
= 'baacd'.search(re
);
531 ok(i
=== 1, "'baacd'.search(re) = " + i
);
532 ok(re
.lastIndex
=== 3, "re.lastIndex = " + re
.lastIndex
);
533 ok(RegExp
.leftContext
=== "b", "RegExp.leftContext = " + RegExp
.leftContext
);
534 ok(RegExp
.rightContext
=== "cd", "RegExp.rightContext = " + RegExp
.rightContext
);
537 i
= 'baacdaa'.search(re
);
538 ok(i
=== 1, "'baacd'.search(re) = " + i
);
539 ok(re
.lastIndex
=== 3, "re.lastIndex = " + re
.lastIndex
);
542 i
= 'baacd'.search(re
);
543 ok(i
=== 1, "'baacd'.search(re) = " + i
);
544 ok(re
.lastIndex
=== 3, "re.lastIndex = " + re
.lastIndex
);
547 i
= 'baacdaa'.search(re
);
548 ok(i
=== 1, "'baacd'.search(re) = " + i
);
549 ok(re
.lastIndex
=== 3, "re.lastIndex = " + re
.lastIndex
);
550 ok(RegExp
.leftContext
=== "b", "RegExp.leftContext = " + RegExp
.leftContext
);
551 ok(RegExp
.rightContext
=== "cdaa", "RegExp.rightContext = " + RegExp
.rightContext
);
555 i
= 'abc'.search(re
);
556 ok(i
=== -1, "'abc'.search(/d/g) = " + i
);
557 ok(re
.lastIndex
=== 0, "re.lastIndex = " + re
.lastIndex
);
558 ok(RegExp
.leftContext
=== "b", "RegExp.leftContext = " + RegExp
.leftContext
);
559 ok(RegExp
.rightContext
=== "cdaa", "RegExp.rightContext = " + RegExp
.rightContext
);
561 i
= 'abcdde'.search(/[df]/);
562 ok(i
=== 3, "'abc'.search(/[df]/) = " + i
);
564 i
= 'abcdde'.search(/[df]/, "a");
565 ok(i
=== 3, "'abc'.search(/[df]/) = " + i
);
567 i
= 'abcdde'.search("[df]");
568 ok(i
=== 3, "'abc'.search(/d*/) = " + i
);
571 toString: function() { return "abc"; }
573 i
= String
.prototype.search
.call(obj
, "b");
574 ok(i
=== 1, "String.prototype.seatch.apply(obj, 'b') = " + i
);
576 i
= " undefined ".search();
577 ok(i
=== null, "' undefined '.search() = " + i
);