Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(37)

Unified Diff: test/mjsunit/regexp-capture-3.js

Issue 10174017: Regexp: Remove nodes from the regexp that cannot match because (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: Created 8 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/jsregexp.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/mjsunit/regexp-capture-3.js
===================================================================
--- test/mjsunit/regexp-capture-3.js (revision 11428)
+++ test/mjsunit/regexp-capture-3.js (working copy)
@@ -154,3 +154,34 @@
a = "foo bar baz".replace(/^|bar/g, "*");
assertEquals("*foo * baz", a);
+
+// We test FilterASCII using regexps that will backtrack forever. Since
+// a regexp with a non-ASCII character in it can never match an ASCII
+// string we can test that the relevant node is removed by verifying that
+// there is no hang.
+function NoHang(re) {
+ print(re);
+ "This is an ASCII string that could take forever".match(re);
+}
+
+
+NoHang(/(((.*)*)*x)å/); // Continuation after loop is filtered, so is loop.
+NoHang(/(((.*)*)*å)foo/); // Body of loop filtered.
+NoHang(/å(((.*)*)*x)/); // Everything after a filtered character is filtered.
+NoHang(/(((.*)*)*x)å/); // Everything before a filtered character is filtered.
+NoHang(/[æøå](((.*)*)*x)/); // Everything after a filtered class is filtered.
+NoHang(/(((.*)*)*x)[æøå]/); // Everything before a filtered class is filtered.
+NoHang(/[^\x00-\x7f](((.*)*)*x)/); // After negated class.
+NoHang(/(((.*)*)*x)[^\x00-\x7f]/); // Before negated class.
+NoHang(/(?!(((.*)*)*x)å)foo/); // Negative lookahead is filtered.
+NoHang(/(?!(((.*)*)*x))å/); // Continuation branch of negative lookahead.
+NoHang(/(?=(((.*)*)*x)å)foo/); // Positive lookahead is filtered.
+NoHang(/(?=(((.*)*)*x))å/); // Continuation branch of positive lookahead.
+NoHang(/(?=å)(((.*)*)*x)/); // Positive lookahead also prunes continuation.
+NoHang(/(æ|ø|å)(((.*)*)*x)/); // All branches of alternation are filtered.
+NoHang(/(a|b|(((.*)*)*x))å/); // 1 out of 3 branches pruned.
+NoHang(/(a|(((.*)*)*x)ø|(((.*)*)*x)å)/); // 2 out of 3 branches pruned.
+
+var s = "Don't prune based on a repetition of length 0";
+assertEquals(null, s.match(/å{1,1}prune/));
+assertEquals("prune", (s.match(/å{0,0}prune/)[0]));
« no previous file with comments | « src/jsregexp.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698