Index: test/mjsunit/regexp-static.js |
=================================================================== |
--- test/mjsunit/regexp-static.js (revision 1481) |
+++ test/mjsunit/regexp-static.js (working copy) |
@@ -132,3 +132,25 @@ |
re = /(.)/g; |
function f() { return RegExp.$1; }; |
assertEquals('abcd', 'abcd'.replace(re, f)); |
+ |
+// lastParen where the last parenthesis didn't match. |
+assertEquals("foo,", /foo(?:a(x))?/.exec("foobx"), "lastParen setup"); |
+assertEquals("", RegExp.lastParen, "lastParen"); |
+ |
+// The same test for $1 to $9. |
+for (var i = 1; i <= 9; i++) { |
+ var haystack = "foo"; |
+ var re_text = "^foo"; |
+ for (var j = 0; j < i - 1; j++) { |
+ haystack += "x"; |
+ re_text += "(x)"; |
+ } |
+ re_text += "(?:a(x))?"; |
+ haystack += "bx"; |
+ var re = new RegExp(re_text); |
+ assertTrue(re.test(haystack), "$" + i + " setup"); |
+ for (var j = 1; j < i - 1; j++) { |
+ assertEquals("x", RegExp['$' + j], "$" + j + " in $" + i + " setup"); |
+ } |
+ assertEquals("", RegExp['$' + (i)], "$" + i); |
+} |