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

Side by Side Diff: tests/corelib_strong/regexp/capture-3_test.dart

Issue 2985233002: Migrated test block 19 to Dart 2.0. (Closed)
Patch Set: Migrated test block 19 to Dart 2.0. Created 3 years, 4 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 unified diff | Download patch
OLDNEW
(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(
68 r"(((.*)*)*x)Ā")); // Continuation after loop is filtered, so is loop.
69 NoHang(new RegExp(r"(((.*)*)*Ā)foo")); // Body of loop filtered.
70 NoHang(new RegExp(
71 r"Ā(((.*)*)*x)")); // Everything after a filtered character is filtered.
72 NoHang(new RegExp(
73 r"(((.*)*)*x)Ā")); // Everything before a filtered character is filtered.
74 NoHang(new RegExp(
75 r"[ćăĀ](((.*)*)*x)")); // Everything after a filtered class is filtered.
76 NoHang(new RegExp(
77 r"(((.*)*)*x)[ćăĀ]")); // Everything before a filtered class is filtered.
78 NoHang(new RegExp(r"[^\x00-\xff](((.*)*)*x)")); // After negated class.
79 NoHang(new RegExp(r"(((.*)*)*x)[^\x00-\xff]")); // Before negated class.
80 NoHang(new RegExp(r"(?!(((.*)*)*x)Ā)foo")); // Negative lookahead is filtered.
81 NoHang(new RegExp(
82 r"(?!(((.*)*)*x))Ā")); // Continuation branch of negative lookahead.
83 NoHang(new RegExp(r"(?=(((.*)*)*x)Ā)foo")); // Positive lookahead is filtered.
84 NoHang(new RegExp(
85 r"(?=(((.*)*)*x))Ā")); // Continuation branch of positive lookahead.
86 NoHang(new RegExp(
87 r"(?=Ā)(((.*)*)*x)")); // Positive lookahead also prunes continuation.
88 NoHang(new RegExp(
89 r"(æ|ø|Ā)(((.*)*)*x)")); // All branches of alternation are filtered.
90 NoHang(new RegExp(r"(a|b|(((.*)*)*x))Ā")); // 1 out of 3 branches pruned.
91 NoHang(new RegExp(
92 r"(a|(((.*)*)*x)ă|(((.*)*)*x)Ā)")); // 2 out of 3 branches pruned.
93
94 var s = "Don't prune based on a repetition of length 0";
95 assertEquals(null, firstMatch(s, new RegExp(r"å{1,1}prune")));
96 assertEquals("prune", (firstMatch(s, new RegExp(r"å{0,0}prune"))[0]));
97
98 // Some very deep regexps where FilterASCII gives up in order not to make the
99 // stack overflow.
100 var regex6 = new RegExp(r"a*\u0100*\w");
101 var input0 = "a";
102 regex6.firstMatch(input0);
103
104 var re = "\u0100*\\w";
105
106 for (var i = 0; i < 200; i++) re = "a*" + re;
107
108 var regex7 = new RegExp(re);
109 regex7.firstMatch(input0);
110
111 var regex8 = new RegExp(re, caseSensitive: false);
112 regex8.firstMatch(input0);
113
114 re = "[\u0100]*\\w";
115 for (var i = 0; i < 200; i++) re = "a*" + re;
116
117 var regex9 = new RegExp(re);
118 regex9.firstMatch(input0);
119
120 var regex10 = new RegExp(re, caseSensitive: false);
121 regex10.firstMatch(input0);
122
123 var regex11 = new RegExp(r"^(?:[^\u0000-\u0080]|[0-9a-z?,.!&\s#()])+$",
124 caseSensitive: false);
125 regex11.firstMatch(input0);
126
127 var regex12 = new RegExp(
128 r"u(\xf0{8}?\D*?|( ? !)$h??(|)*?(||)+?\6((?:\W\B|--\d-*-|)?$){0, }?|^Y( ? !1)\d+)+a");
129 regex12.firstMatch("");
130 }
OLDNEW
« no previous file with comments | « tests/corelib_strong/regexp/bol_test.dart ('k') | tests/corelib_strong/regexp/capture_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698