| Index: test/mjsunit/regexp-capture-3.js
|
| ===================================================================
|
| --- test/mjsunit/regexp-capture-3.js (revision 11415)
|
| +++ test/mjsunit/regexp-capture-3.js (working copy)
|
| @@ -86,3 +86,71 @@
|
| for (var i = 3; i < 10; i++) {
|
| assertEquals("", RegExp['$' + i]);
|
| }
|
| +
|
| +
|
| +function Override() {
|
| + // Set the internal lastMatchInfoOverride. After calling this we do a normal
|
| + // match and verify the override was cleared and that we record the new
|
| + // captures.
|
| + "abcdabcd".replace(/(b)(c)/g, function() { });
|
| +}
|
| +
|
| +
|
| +function TestOverride(input, expect, property, re_src) {
|
| + var re = new RegExp(re_src);
|
| + var re_g = new RegExp(re_src, "g");
|
| +
|
| + function OverrideCase(fn) {
|
| + Override();
|
| + fn();
|
| + assertEquals(expect, RegExp[property]);
|
| + }
|
| +
|
| + OverrideCase(function() { return input.replace(re, "x"); });
|
| + OverrideCase(function() { return input.replace(re_g, "x"); });
|
| + OverrideCase(function() { return input.replace(re, ""); });
|
| + OverrideCase(function() { return input.replace(re_g, ""); });
|
| + OverrideCase(function() { return input.match(re); });
|
| + OverrideCase(function() { return input.match(re_g); });
|
| + OverrideCase(function() { return re.test(input); });
|
| + OverrideCase(function() { return re_g.test(input); });
|
| +}
|
| +
|
| +var input = "bar.foo baz......";
|
| +var re_str = "(ba.).*?f";
|
| +TestOverride(input, "bar", "$1", re_str);
|
| +
|
| +input = "foo bar baz";
|
| +var re_str = "bar";
|
| +TestOverride(input, "bar", "$&", re_str);
|
| +
|
| +
|
| +function no_last_match(fn) {
|
| + fn();
|
| + assertEquals("hestfisk", RegExp.$1);
|
| +}
|
| +
|
| +/(hestfisk)/.test("There's no such thing as a hestfisk!");
|
| +
|
| +no_last_match(function() { "foo".replace("f", ""); });
|
| +no_last_match(function() { "foo".replace("f", "f"); });
|
| +no_last_match(function() { "foo".split("o"); });
|
| +
|
| +var base = "In the music. In the music. ";
|
| +var cons = base + base + base + base;
|
| +no_last_match(function() { cons.replace("x", "y"); });
|
| +no_last_match(function() { cons.replace("e", "E"); });
|
| +
|
| +
|
| +// Here's one that matches once, then tries to match again, but fails.
|
| +// Verify that the last match info is from the last match, not from the
|
| +// failure that came after.
|
| +"bar.foo baz......".replace(/(ba.).*?f/g, function() { return "x";});
|
| +assertEquals("bar", RegExp.$1);
|
| +
|
| +
|
| +var a = "foo bar baz".replace(/^|bar/g, "");
|
| +assertEquals("foo baz", a);
|
| +
|
| +a = "foo bar baz".replace(/^|bar/g, "*");
|
| +assertEquals("*foo * baz", a);
|
|
|