dplayx: Code to forward player creation
[wine/gsoc_dplay.git] / dlls / jscript / tests / regexp.js
bloba839adba9e09e7dc075b98cf7a8df790a492f5ff
1 /*
2  * Copyright 2008 Jacek Caban for CodeWeavers
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
17  */
20 var m, re, b;
22 re = /a+/;
23 ok(re.lastIndex === 0, "re.lastIndex = " + re.lastIndex);
25 m = re.exec(" aabaaa");
26 ok(re.lastIndex === 3, "re.lastIndex = " + re.lastIndex);
27 ok(m.index === 1, "m.index = " + m.index);
28 ok(m.input === " aabaaa", "m.input = " + m.input);
29 ok(m.length === 1, "m.length = " + m.length);
30 ok(m[0] === "aa", "m[0] = " + m[0]);
32 m = re.exec(" aabaaa");
33 ok(re.lastIndex === 3, "re.lastIndex = " + re.lastIndex);
34 ok(m.index === 1, "m.index = " + m.index);
35 ok(m.input === " aabaaa", "m.input = " + m.input);
36 ok(m.length === 1, "m.length = " + m.length);
37 ok(m[0] === "aa", "m[0] = " + m[0]);
39 re = /a+/g;
40 ok(re.lastIndex === 0, "re.lastIndex = " + re.lastIndex);
42 m = re.exec(" aabaaa");
43 ok(re.lastIndex === 3, "re.lastIndex = " + re.lastIndex);
44 ok(m.index === 1, "m.index = " + m.index);
45 ok(m.input === " aabaaa", "m.input = " + m.input);
46 ok(m.length === 1, "m.length = " + m.length);
47 ok(m[0] === "aa", "m[0] = " + m[0]);
49 m = re.exec(" aabaaa");
50 ok(re.lastIndex === 7, "re.lastIndex = " + re.lastIndex);
51 ok(m.index === 4, "m.index = " + m.index);
52 ok(m.input === " aabaaa", "m.input = " + m.input);
53 ok(m.length === 1, "m.length = " + m.length);
54 ok(m[0] === "aaa", "m[0] = " + m[0]);
56 m = re.exec(" aabaaa");
57 ok(re.lastIndex === 0, "re.lastIndex = " + re.lastIndex);
58 ok(m === null, "m is not null");
60 re.exec("               a");
61 ok(re.lastIndex === 16, "re.lastIndex = " + re.lastIndex);
63 m = re.exec(" a");
64 ok(m === null, "m is not null");
65 ok(re.lastIndex === 0, "re.lastIndex = " + re.lastIndex);
67 m = re.exec(" a");
68 ok(re.lastIndex === 2, "re.lastIndex = " + re.lastIndex);
70 m = re.exec();
71 ok(m === null, "m is not null");
72 ok(re.lastIndex === 0, "re.lastIndex = " + re.lastIndex);
74 b = re.test("  a ");
75 ok(b === true, "re.test('  a ') returned " + b);
76 ok(re.lastIndex === 3, "re.lastIndex = " + re.lastIndex);
78 b = re.test(" a ");
79 ok(b === false, "re.test(' a ') returned " + b);
80 ok(re.lastIndex === 0, "re.lastIndex = " + re.lastIndex);
82 re = /\[([^\[]+)\]/g;
83 m = re.exec(" [test]  ");
84 ok(re.lastIndex === 7, "re.lastIndex = " + re.lastIndex);
85 ok(m.index === 1, "m.index = " + m.index);
86 ok(m.input === " [test]  ", "m.input = " + m.input);
87 ok(m.length === 2, "m.length = " + m.length);
88 ok(m[0] === "[test]", "m[0] = " + m[0]);
89 ok(m[1] === "test", "m[1] = " + m[1]);
91 b = /a*/.test();
92 ok(b === true, "/a*/.test() returned " + b);
94 m = "abcabc".match(/ca/);
95 ok(typeof(m) === "object", "typeof m is not object");
96 ok(m.length === 1, "m.length is not 1");
97 ok(m["0"] === "ca", "m[0] is not \"ca\"");
99 m = "abcabc".match(/ab/);
100 ok(typeof(m) === "object", "typeof m is not object");
101 ok(m.length === 1, "m.length is not 1");
102 ok(m["0"] === "ab", "m[0] is not \"ab\"");
104 m = "abcabc".match(/ab/g);
105 ok(typeof(m) === "object", "typeof m is not object");
106 ok(m.length === 2, "m.length is not 2");
107 ok(m["0"] === "ab", "m[0] is not \"ab\"");
108 ok(m["1"] === "ab", "m[1] is not \"ab\"");
110 m = "abcabc".match(/Ab/g);
111 ok(typeof(m) === "object", "typeof m is not object");
112 ok(m === null, "m is not null");
114 m = "abcabc".match(/Ab/gi);
115 ok(typeof(m) === "object", "typeof m is not object");
116 ok(m.length === 2, "m.length is not 2");
117 ok(m["0"] === "ab", "m[0] is not \"ab\"");
118 ok(m["1"] === "ab", "m[1] is not \"ab\"");
120 m = "aaabcabc".match(/a+b/g);
121 ok(typeof(m) === "object", "typeof m is not object");
122 ok(m.length === 2, "m.length is not 2");
123 ok(m["0"] === "aaab", "m[0] is not \"ab\"");
124 ok(m["1"] === "ab", "m[1] is not \"ab\"");
126 m = "aaa\\\\cabc".match(/\\/g);
127 ok(typeof(m) === "object", "typeof m is not object");
128 ok(m.length === 2, "m.length is not 2");
129 ok(m["0"] === "\\", "m[0] is not \"\\\"");
130 ok(m["1"] === "\\", "m[1] is not \"\\\"");
132 m = "abcabc".match(new RegExp("ab"));
133 ok(typeof(m) === "object", "typeof m is not object");
134 ok(m.length === 1, "m.length is not 1");
135 ok(m["0"] === "ab", "m[0] is not \"ab\"");
137 m = "abcabc".match(new RegExp("ab","g"));
138 ok(typeof(m) === "object", "typeof m is not object");
139 ok(m.length === 2, "m.length is not 2");
140 ok(m["0"] === "ab", "m[0] is not \"ab\"");
141 ok(m["1"] === "ab", "m[1] is not \"ab\"");
143 m = "abcabc".match(new RegExp(/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\"");
149 m = "abcabc".match(new RegExp("ab","g", "test"));
150 ok(typeof(m) === "object", "typeof m is not object");
151 ok(m.length === 2, "m.length is not 2");
152 ok(m["0"] === "ab", "m[0] is not \"ab\"");
153 ok(m["1"] === "ab", "m[1] is not \"ab\"");
155 m = "abcabcg".match("ab", "g");
156 ok(typeof(m) === "object", "typeof m is not object");
157 ok(m.length === 1, "m.length is not 1");
158 ok(m["0"] === "ab", "m[0] is not \"ab\"");
160 m = "abcabc".match();
161 ok(m === null, "m is not null");
163 r = "- [test] -".replace(/\[([^\[]+)\]/g, "success");
164 ok(r === "- success -", "r = " + r + " expected '- success -'");
166 r = "[test] [test]".replace(/\[([^\[]+)\]/g, "aa");
167 ok(r === "aa aa", "r = " + r + "aa aa");
169 r = "[test] [test]".replace(/\[([^\[]+)\]/, "aa");
170 ok(r === "aa [test]", "r = " + r + " expected 'aa [test]'");
172 r = "- [test] -".replace(/\[([^\[]+)\]/g);
173 ok(r === "- undefined -", "r = " + r + " expected '- undefined -'");
175 r = "- [test] -".replace(/\[([^\[]+)\]/g, true);
176 ok(r === "- true -", "r = " + r + " expected '- true -'");
178 r = "- [test] -".replace(/\[([^\[]+)\]/g, true, "test");
179 ok(r === "- true -", "r = " + r + " expected '- true -'");
181 var tmp = 0;
183 function replaceFunc1(m, off, str) {
184     ok(arguments.length === 3, "arguments.length = " + arguments.length);
186     switch(tmp) {
187     case 0:
188         ok(m === "[test1]", "m = " + m + " expected [test1]");
189         ok(off === 0, "off = " + off + " expected 0");
190         break;
191     case 1:
192         ok(m === "[test2]", "m = " + m + " expected [test2]");
193         ok(off === 8, "off = " + off + " expected 8");
194         break;
195     default:
196         ok(false, "unexpected call");
197     }
199     ok(str === "[test1] [test2]", "str = " + arguments[3]);
200     return "r" + tmp++;
203 r = "[test1] [test2]".replace(/\[[^\[]+\]/g, replaceFunc1);
204 ok(r === "r0 r1", "r = " + r + " expected 'r0 r1'");
206 tmp = 0;
208 function replaceFunc2(m, subm, off, str) {
209     ok(arguments.length === 4, "arguments.length = " + arguments.length);
211     switch(tmp) {
212     case 0:
213         ok(subm === "test1", "subm = " + subm);
214         ok(m === "[test1]", "m = " + m + " expected [test1]");
215         ok(off === 0, "off = " + off + " expected 0");
216         break;
217     case 1:
218         ok(subm === "test2", "subm = " + subm);
219         ok(m === "[test2]", "m = " + m + " expected [test2]");
220         ok(off === 8, "off = " + off + " expected 8");
221         break;
222     default:
223         ok(false, "unexpected call");
224     }
226     ok(str === "[test1] [test2]", "str = " + arguments[3]);
227     return "r" + tmp++;
230 r = "[test1] [test2]".replace(/\[([^\[]+)\]/g, replaceFunc2);
231 ok(r === "r0 r1", "r = '" + r + "' expected 'r0 r1'");
233 r = "$1,$2".replace(/(\$(\d))/g, "$$1-$1$2");
234 ok(r === "$1-$11,$1-$22", "r = '" + r + "' expected '$1-$11,$1-$22'");
236 r = "abc &1 123".replace(/(\&(\d))/g, "$&");
237 ok(r === "abc &1 123", "r = '" + r + "' expected 'abc &1 123'");
239 r = "abc &1 123".replace(/(\&(\d))/g, "$'");
240 ok(r === "abc  123 123", "r = '" + r + "' expected 'abc  123 123'");
242 r = "abc &1 123".replace(/(\&(\d))/g, "$`");
243 ok(r === "abc abc  123", "r = '" + r + "' expected 'abc abc  123'");
245 r = "abc &1 123".replace(/(\&(\d))/g, "$3");
246 ok(r === "abc $3 123", "r = '" + r + "' expected 'abc $3 123'");
248 r = "abc &1 123".replace(/(\&(\d))/g, "$");
249 ok(r === "abc $ 123", "r = '" + r + "' expected 'abc $ 123'");
251 r = "abc &1 123".replace(/(\&(\d))/g, "$a");
252 ok(r === "abc $a 123", "r = '" + r + "' expected 'abc $a 123'");
254 r = "abc &1 123".replace(/(\&(\d))/g, "$11");
255 ok(r === "abc &11 123", "r = '" + r + "' expected 'abc &11 123'");
257 r = "abc &1 123".replace(/(\&(\d))/g, "$0");
258 ok(r === "abc $0 123", "r = '" + r + "' expected 'abc $0 123'");
260 r = "1 2 3".replace("2", "$&");
261 ok(r === "1 $& 3", "r = '" + r + "' expected '1 $& 3'");
263 r = "1 2 3".replace("2", "$'");
264 ok(r === "1 $' 3", "r = '" + r + "' expected '1 $' 3'");
266 r = "1,,2,3".split(/,+/g);
267 ok(r.length === 3, "r.length = " + r.length);
268 ok(r[0] === "1", "r[0] = " + r[0]);
269 ok(r[1] === "2", "r[1] = " + r[1]);
270 ok(r[2] === "3", "r[2] = " + r[2]);
272 r = "1,,2,3".split(/,+/);
273 ok(r.length === 3, "r.length = " + r.length);
274 ok(r[0] === "1", "r[0] = " + r[0]);
275 ok(r[1] === "2", "r[1] = " + r[1]);
276 ok(r[2] === "3", "r[2] = " + r[2]);
278 r = "1,,2,".split(/,+/);
279 ok(r.length === 2, "r.length = " + r.length);
280 ok(r[0] === "1", "r[0] = " + r[0]);
281 ok(r[1] === "2", "r[1] = " + r[1]);
283 re = /abc[^d]/g;
284 ok(re.source === "abc[^d]", "re.source = '" + re.source + "', expected 'abc[^d]'");
286 re = /a\bc[^d]/g;
287 ok(re.source === "a\\bc[^d]", "re.source = '" + re.source + "', expected 'a\\bc[^d]'");
289 reportSuccess();