| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2014, the Dart project authors. All rights reserved. | |
| 2 // Copyright 2009 the V8 project authors. All rights reserved. | |
| 3 // Redistribution and use in source and binary forms, with or without | |
| 4 // modification, are permitted provided that the following conditions are | |
| 5 // met: | |
| 6 // | |
| 7 // * Redistributions of source code must retain the above copyright | |
| 8 // notice, this list of conditions and the following disclaimer. | |
| 9 // * Redistributions in binary form must reproduce the above | |
| 10 // copyright notice, this list of conditions and the following | |
| 11 // disclaimer in the documentation and/or other materials provided | |
| 12 // with the distribution. | |
| 13 // * Neither the name of Google Inc. nor the names of its | |
| 14 // contributors may be used to endorse or promote products derived | |
| 15 // from this software without specific prior written permission. | |
| 16 // | |
| 17 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
| 18 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
| 19 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
| 20 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
| 21 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
| 22 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
| 23 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
| 24 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
| 25 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
| 26 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
| 27 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
| 28 | |
| 29 import 'v8_regexp_utils.dart'; | |
| 30 import 'package:expect/expect.dart'; | |
| 31 | |
| 32 void main() { | |
| 33 dynamic oneMatch(re) { | |
| 34 assertEquals("acd", "abcd".replaceAll(re, "")); | |
| 35 } | |
| 36 | |
| 37 oneMatch(new RegExp(r"b")); | |
| 38 oneMatch(new RegExp(r"b")); | |
| 39 | |
| 40 assertEquals("acdacd", "abcdabcd".replaceAll(new RegExp(r"b"), "")); | |
| 41 | |
| 42 dynamic captureMatch(re) { | |
| 43 var match = firstMatch("abcd", re); | |
| 44 assertEquals("b", match.group(1)); | |
| 45 assertEquals("c", match.group(2)); | |
| 46 } | |
| 47 | |
| 48 captureMatch(new RegExp(r"(b)(c)")); | |
| 49 captureMatch(new RegExp(r"(b)(c)")); | |
| 50 | |
| 51 // A test that initially does a zero width match, but later does a non-zero | |
| 52 // width match. | |
| 53 var a = "foo bar baz".replaceAll(new RegExp(r"^|bar"), ""); | |
| 54 assertEquals("foo baz", a); | |
| 55 | |
| 56 a = "foo bar baz".replaceAll(new RegExp(r"^|bar"), "*"); | |
| 57 assertEquals("*foo * baz", a); | |
| 58 | |
| 59 // We test FilterASCII using regexps that will backtrack forever. Since | |
| 60 // a regexp with a non-ASCII character in it can never match an ASCII | |
| 61 // string we can test that the relevant node is removed by verifying that | |
| 62 // there is no hang. | |
| 63 dynamic NoHang(re) { | |
| 64 firstMatch("This is an ASCII string that could take forever", re); | |
| 65 } | |
| 66 | |
| 67 NoHang(new RegExp(r"(((.*)*)*x)Ā")); // Continuation after loop is filtered,
so is loop. | |
| 68 NoHang(new RegExp(r"(((.*)*)*Ā)foo")); // Body of loop filtered. | |
| 69 NoHang(new RegExp(r"Ā(((.*)*)*x)")); // Everything after a filtered characte
r is filtered. | |
| 70 NoHang(new RegExp(r"(((.*)*)*x)Ā")); // Everything before a filtered charact
er is filtered. | |
| 71 NoHang(new RegExp(r"[ćăĀ](((.*)*)*x)")); // Everything after a filtered clas
s is filtered. | |
| 72 NoHang(new RegExp(r"(((.*)*)*x)[ćăĀ]")); // Everything before a filtered cla
ss is filtered. | |
| 73 NoHang(new RegExp(r"[^\x00-\xff](((.*)*)*x)")); // After negated class. | |
| 74 NoHang(new RegExp(r"(((.*)*)*x)[^\x00-\xff]")); // Before negated class. | |
| 75 NoHang(new RegExp(r"(?!(((.*)*)*x)Ā)foo")); // Negative lookahead is filtered
. | |
| 76 NoHang(new RegExp(r"(?!(((.*)*)*x))Ā")); // Continuation branch of negative l
ookahead. | |
| 77 NoHang(new RegExp(r"(?=(((.*)*)*x)Ā)foo")); // Positive lookahead is filtered
. | |
| 78 NoHang(new RegExp(r"(?=(((.*)*)*x))Ā")); // Continuation branch of positive l
ookahead. | |
| 79 NoHang(new RegExp(r"(?=Ā)(((.*)*)*x)")); // Positive lookahead also prunes co
ntinuation. | |
| 80 NoHang(new RegExp(r"(æ|ø|Ā)(((.*)*)*x)")); // All branches of alternation are
filtered. | |
| 81 NoHang(new RegExp(r"(a|b|(((.*)*)*x))Ā")); // 1 out of 3 branches pruned. | |
| 82 NoHang(new RegExp(r"(a|(((.*)*)*x)ă|(((.*)*)*x)Ā)")); // 2 out of 3 branches
pruned. | |
| 83 | |
| 84 var s = "Don't prune based on a repetition of length 0"; | |
| 85 assertEquals(null, firstMatch(s, new RegExp(r"å{1,1}prune"))); | |
| 86 assertEquals("prune", (firstMatch(s, new RegExp(r"å{0,0}prune"))[0])); | |
| 87 | |
| 88 // Some very deep regexps where FilterASCII gives up in order not to make the | |
| 89 // stack overflow. | |
| 90 var regex6 = new RegExp(r"a*\u0100*\w"); | |
| 91 var input0 = "a"; | |
| 92 regex6.firstMatch(input0); | |
| 93 | |
| 94 var re = "\u0100*\\w"; | |
| 95 | |
| 96 for (var i = 0; i < 200; i++) re = "a*" + re; | |
| 97 | |
| 98 var regex7 = new RegExp(re); | |
| 99 regex7.firstMatch(input0); | |
| 100 | |
| 101 var regex8 = new RegExp(re, caseSensitive: false); | |
| 102 regex8.firstMatch(input0); | |
| 103 | |
| 104 re = "[\u0100]*\\w"; | |
| 105 for (var i = 0; i < 200; i++) re = "a*" + re; | |
| 106 | |
| 107 var regex9 = new RegExp(re); | |
| 108 regex9.firstMatch(input0); | |
| 109 | |
| 110 var regex10 = new RegExp(re, caseSensitive: false); | |
| 111 regex10.firstMatch(input0); | |
| 112 | |
| 113 var regex11 = new RegExp(r"^(?:[^\u0000-\u0080]|[0-9a-z?,.!&\s#()])+$", caseSe
nsitive: false); | |
| 114 regex11.firstMatch(input0); | |
| 115 | |
| 116 var regex12 = new RegExp(r"u(\xf0{8}?\D*?|( ? !)$h??(|)*?(||)+?\6((?:\W\B|--\d
-*-|)?$){0, }?|^Y( ? !1)\d+)+a"); | |
| 117 regex12.firstMatch(""); | |
| 118 } | |
| OLD | NEW |