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 m
= "abcabc".match(/ca/);
23 ok(typeof(m
) === "object", "typeof m is not object");
24 ok(m
.length
=== 1, "m.length is not 1");
25 ok(m
["0"] === "ca", "m[0] is not \"ca\"");
27 m
= "abcabc".match(/ab/);
28 ok(typeof(m
) === "object", "typeof m is not object");
29 ok(m
.length
=== 1, "m.length is not 1");
30 ok(m
["0"] === "ab", "m[0] is not \"ab\"");
32 m
= "abcabc".match(/ab/g);
33 ok(typeof(m
) === "object", "typeof m is not object");
34 ok(m
.length
=== 2, "m.length is not 2");
35 ok(m
["0"] === "ab", "m[0] is not \"ab\"");
36 ok(m
["1"] === "ab", "m[1] is not \"ab\"");
38 m
= "abcabc".match(/Ab/g);
39 ok(typeof(m
) === "object", "typeof m is not object");
40 ok(m
=== null, "m is not null");
42 m
= "abcabc".match(/Ab/gi);
43 ok(typeof(m
) === "object", "typeof m is not object");
44 ok(m
.length
=== 2, "m.length is not 2");
45 ok(m
["0"] === "ab", "m[0] is not \"ab\"");
46 ok(m
["1"] === "ab", "m[1] is not \"ab\"");
48 m
= "aaabcabc".match(/a+b/g);
49 ok(typeof(m
) === "object", "typeof m is not object");
50 ok(m
.length
=== 2, "m.length is not 2");
51 ok(m
["0"] === "aaab", "m[0] is not \"ab\"");
52 ok(m
["1"] === "ab", "m[1] is not \"ab\"");
54 m
= "aaa\\\\cabc".match(/\\/g
);
55 ok(typeof(m
) === "object", "typeof m is not object");
56 ok(m
.length
=== 2, "m.length is not 2");
57 ok(m
["0"] === "\\", "m[0] is not \"\\\"");
58 ok(m
["1"] === "\\", "m[1] is not \"\\\"");
60 m
= "abcabc".match(new RegExp("ab"));
61 ok(typeof(m
) === "object", "typeof m is not object");
62 ok(m
.length
=== 1, "m.length is not 1");
63 ok(m
["0"] === "ab", "m[0] is not \"ab\"");
65 m
= "abcabc".match(new RegExp("ab","g"));
66 ok(typeof(m
) === "object", "typeof m is not object");
67 ok(m
.length
=== 2, "m.length is not 2");
68 ok(m
["0"] === "ab", "m[0] is not \"ab\"");
69 ok(m
["1"] === "ab", "m[1] is not \"ab\"");
71 m
= "abcabc".match(new RegExp(/ab/g));
72 ok(typeof(m
) === "object", "typeof m is not object");
73 ok(m
.length
=== 2, "m.length is not 2");
74 ok(m
["0"] === "ab", "m[0] is not \"ab\"");
75 ok(m
["1"] === "ab", "m[1] is not \"ab\"");
77 m
= "abcabc".match(new RegExp("ab","g", "test"));
78 ok(typeof(m
) === "object", "typeof m is not object");
79 ok(m
.length
=== 2, "m.length is not 2");
80 ok(m
["0"] === "ab", "m[0] is not \"ab\"");
81 ok(m
["1"] === "ab", "m[1] is not \"ab\"");
83 m
= "abcabcg".match("ab", "g");
84 ok(typeof(m
) === "object", "typeof m is not object");
85 ok(m
.length
=== 1, "m.length is not 1");
86 ok(m
["0"] === "ab", "m[0] is not \"ab\"");
89 ok(m
=== null, "m is not null");
91 r
= "- [test] -".replace(/\[([^\[]+)\]/g, "success");
92 ok(r
=== "- success -", "r = " + r
+ " expected '- success -'");
94 r
= "[test] [test]".replace(/\[([^\[]+)\]/g, "aa");
95 ok(r
=== "aa aa", "r = " + r
+ "aa aa");
97 r
= "[test] [test]".replace(/\[([^\[]+)\]/, "aa");
98 ok(r
=== "aa [test]", "r = " + r
+ " expected 'aa [test]'");
100 r
= "- [test] -".replace(/\[([^\[]+)\]/g);
101 ok(r
=== "- undefined -", "r = " + r
+ " expected '- undefined -'");
103 r
= "- [test] -".replace(/\[([^\[]+)\]/g, true);
104 ok(r
=== "- true -", "r = " + r
+ " expected '- true -'");
106 r
= "- [test] -".replace(/\[([^\[]+)\]/g, true, "test");
107 ok(r
=== "- true -", "r = " + r
+ " expected '- true -'");
111 function replaceFunc1(m
, off
, str
) {
112 ok(arguments
.length
=== 3, "arguments.length = " + arguments
.length
);
116 ok(m
=== "[test1]", "m = " + m
+ " expected [test1]");
117 ok(off
=== 0, "off = " + off
+ " expected 0");
120 ok(m
=== "[test2]", "m = " + m
+ " expected [test2]");
121 ok(off
=== 8, "off = " + off
+ " expected 8");
124 ok(false, "unexpected call");
127 ok(str
=== "[test1] [test2]", "str = " + arguments
[3]);
131 r
= "[test1] [test2]".replace(/\[[^\[]+\]/g, replaceFunc1
);
132 ok(r
=== "r0 r1", "r = " + r
+ " expected 'r0 r1'");
136 function replaceFunc2(m
, subm
, off
, str
) {
137 ok(arguments
.length
=== 4, "arguments.length = " + arguments
.length
);
141 ok(subm
=== "test1", "subm = " + subm
);
142 ok(m
=== "[test1]", "m = " + m
+ " expected [test1]");
143 ok(off
=== 0, "off = " + off
+ " expected 0");
146 ok(subm
=== "test2", "subm = " + subm
);
147 ok(m
=== "[test2]", "m = " + m
+ " expected [test2]");
148 ok(off
=== 8, "off = " + off
+ " expected 8");
151 ok(false, "unexpected call");
154 ok(str
=== "[test1] [test2]", "str = " + arguments
[3]);
158 r
= "[test1] [test2]".replace(/\[([^\[]+)\]/g, replaceFunc2
);
159 ok(r
=== "r0 r1", "r = '" + r
+ "' expected 'r0 r1'");
161 r
= "1,,2,3".split(/,+/g);
162 ok(r
.length
=== 3, "r.length = " + r
.length
);
163 ok(r
[0] === "1", "r[0] = " + r
[0]);
164 ok(r
[1] === "2", "r[1] = " + r
[1]);
165 ok(r
[2] === "3", "r[2] = " + r
[2]);
167 r
= "1,,2,3".split(/,+/);
168 ok(r
.length
=== 3, "r.length = " + r
.length
);
169 ok(r
[0] === "1", "r[0] = " + r
[0]);
170 ok(r
[1] === "2", "r[1] = " + r
[1]);
171 ok(r
[2] === "3", "r[2] = " + r
[2]);
173 r
= "1,,2,".split(/,+/);
174 ok(r
.length
=== 2, "r.length = " + r
.length
);
175 ok(r
[0] === "1", "r[0] = " + r
[0]);
176 ok(r
[1] === "2", "r[1] = " + r
[1]);