OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
147 // failure that came after. | 147 // failure that came after. |
148 "bar.foo baz......".replace(/(ba.).*?f/g, function() { return "x";}); | 148 "bar.foo baz......".replace(/(ba.).*?f/g, function() { return "x";}); |
149 assertEquals("bar", RegExp.$1); | 149 assertEquals("bar", RegExp.$1); |
150 | 150 |
151 | 151 |
152 var a = "foo bar baz".replace(/^|bar/g, ""); | 152 var a = "foo bar baz".replace(/^|bar/g, ""); |
153 assertEquals("foo baz", a); | 153 assertEquals("foo baz", a); |
154 | 154 |
155 a = "foo bar baz".replace(/^|bar/g, "*"); | 155 a = "foo bar baz".replace(/^|bar/g, "*"); |
156 assertEquals("*foo * baz", a); | 156 assertEquals("*foo * baz", a); |
| 157 |
| 158 // We test FilterASCII using regexps that will backtrack forever. Since |
| 159 // a regexp with a non-ASCII character in it can never match an ASCII |
| 160 // string we can test that the relevant node is removed by verifying that |
| 161 // there is no hang. |
| 162 function NoHang(re) { |
| 163 print(re); |
| 164 "This is an ASCII string that could take forever".match(re); |
| 165 } |
| 166 |
| 167 |
| 168 NoHang(/(((.*)*)*x)å/); // Continuation after loop is filtered, so is loop. |
| 169 NoHang(/(((.*)*)*å)foo/); // Body of loop filtered. |
| 170 NoHang(/å(((.*)*)*x)/); // Everything after a filtered character is filtered. |
| 171 NoHang(/(((.*)*)*x)å/); // Everything before a filtered character is filtered. |
| 172 NoHang(/[æøå](((.*)*)*x)/); // Everything after a filtered class is filtered. |
| 173 NoHang(/(((.*)*)*x)[æøå]/); // Everything before a filtered class is filtered. |
| 174 NoHang(/[^\x00-\x7f](((.*)*)*x)/); // After negated class. |
| 175 NoHang(/(((.*)*)*x)[^\x00-\x7f]/); // Before negated class. |
| 176 NoHang(/(?!(((.*)*)*x)å)foo/); // Negative lookahead is filtered. |
| 177 NoHang(/(?!(((.*)*)*x))å/); // Continuation branch of negative lookahead. |
| 178 NoHang(/(?=(((.*)*)*x)å)foo/); // Positive lookahead is filtered. |
| 179 NoHang(/(?=(((.*)*)*x))å/); // Continuation branch of positive lookahead. |
| 180 NoHang(/(?=å)(((.*)*)*x)/); // Positive lookahead also prunes continuation. |
| 181 NoHang(/(æ|ø|å)(((.*)*)*x)/); // All branches of alternation are filtered. |
| 182 NoHang(/(a|b|(((.*)*)*x))å/); // 1 out of 3 branches pruned. |
| 183 NoHang(/(a|(((.*)*)*x)ø|(((.*)*)*x)å)/); // 2 out of 3 branches pruned. |
| 184 |
| 185 var s = "Don't prune based on a repetition of length 0"; |
| 186 assertEquals(null, s.match(/å{1,1}prune/)); |
| 187 assertEquals("prune", (s.match(/å{0,0}prune/)[0])); |
OLD | NEW |