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

Side by Side Diff: tests/corelib_strong/regexp/parentheses_test.dart

Issue 2989843002: Migrated test block 21 to Dart 2.0. (Closed)
Patch Set: Migrated test block 20 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
« no previous file with comments | « tests/corelib_strong/regexp/overflow_test.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2014, the Dart project authors. All rights reserved.
2 // Copyright 2013 the V8 project authors. All rights reserved.
3 // Copyright (C) 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved.
4 //
5 // Redistribution and use in source and binary forms, with or without
6 // modification, are permitted provided that the following conditions
7 // are met:
8 // 1. Redistributions of source code must retain the above copyright
9 // notice, this list of conditions and the following disclaimer.
10 // 2. Redistributions in binary form must reproduce the above copyright
11 // notice, this list of conditions and the following disclaimer in the
12 // documentation and/or other materials provided with the distribution.
13 //
14 // THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND AN Y
15 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
16 // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
17 // DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR AN Y
18 // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
19 // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
20 // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND O N
21 // ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
23 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24
25 import 'v8_regexp_utils.dart';
26 import 'package:expect/expect.dart';
27
28 void main() {
29 description("This page tests handling of parentheses subexpressions.");
30
31 var regexp1 = new RegExp(r"(a|A)(b|B)");
32 shouldBe(regexp1.firstMatch('abc'), ['ab', 'a', 'b']);
33
34 var regexp2 = new RegExp(r"(a((b)|c|d))e");
35 shouldBe(regexp2.firstMatch('abacadabe'), ['abe', 'ab', 'b', 'b']);
36
37 var regexp3 = new RegExp(r"(a(b|(c)|d))e");
38 shouldBe(regexp3.firstMatch('abacadabe'), ['abe', 'ab', 'b', null]);
39
40 var regexp4 = new RegExp(r"(a(b|c|(d)))e");
41 shouldBe(regexp4.firstMatch('abacadabe'), ['abe', 'ab', 'b', null]);
42
43 var regexp5 = new RegExp(r"(a((b)|(c)|(d)))e");
44 shouldBe(
45 regexp5.firstMatch('abacadabe'), ['abe', 'ab', 'b', 'b', null, null]);
46
47 var regexp6 = new RegExp(r"(a((b)|(c)|(d)))");
48 shouldBe(regexp6.firstMatch('abcde'), ['ab', 'ab', 'b', 'b', null, null]);
49
50 var regexp7 = new RegExp(r"(a(b)??)??c");
51 shouldBe(regexp7.firstMatch('abc'), ['abc', 'ab', 'b']);
52
53 var regexp8 = new RegExp(r"(a|(e|q))(x|y)");
54 shouldBe(regexp8.firstMatch('bcaddxqy'), ['qy', 'q', 'q', 'y']);
55
56 var regexp9 = new RegExp(r"((t|b)?|a)$");
57 shouldBe(
58 regexp9.firstMatch('asdfjejgsdflaksdfjkeljghkjea'), ['a', 'a', null]);
59
60 var regexp10 = new RegExp(r"(?:h|e?(?:t|b)?|a?(?:t|b)?)(?:$)");
61 shouldBe(regexp10.firstMatch('asdfjejgsdflaksdfjkeljghat'), ['at']);
62
63 var regexp11 = new RegExp(r"([Jj]ava([Ss]cript)?)\sis\s(fun\w*)");
64 shouldBeNull(regexp11.firstMatch(
65 'Developing with JavaScript is dangerous, do not try it without assistance '));
66
67 var regexp12 = new RegExp(r"(?:(.+), )?(.+), (..) to (?:(.+), )?(.+), (..)");
68 shouldBe(regexp12.firstMatch('Seattle, WA to Buckley, WA'), [
69 'Seattle, WA to Buckley, WA',
70 null,
71 'Seattle',
72 'WA',
73 null,
74 'Buckley',
75 'WA'
76 ]);
77
78 var regexp13 = new RegExp(r"(A)?(A.*)");
79 shouldBe(regexp13.firstMatch('zxcasd;fl\ ^AaaAAaaaf;lrlrzs'),
80 ['AaaAAaaaf;lrlrzs', null, 'AaaAAaaaf;lrlrzs']);
81
82 var regexp14 = new RegExp(r"(a)|(b)");
83 shouldBe(regexp14.firstMatch('b'), ['b', null, 'b']);
84
85 var regexp15 = new RegExp(r"^(?!(ab)de|x)(abd)(f)");
86 shouldBe(regexp15.firstMatch('abdf'), ['abdf', null, 'abd', 'f']);
87
88 var regexp16 = new RegExp(r"(a|A)(b|B)");
89 shouldBe(regexp16.firstMatch('abc'), ['ab', 'a', 'b']);
90
91 var regexp17 = new RegExp(r"(a|d|q|)x", caseSensitive: false);
92 shouldBe(regexp17.firstMatch('bcaDxqy'), ['Dx', 'D']);
93
94 var regexp18 = new RegExp(r"^.*?(:|$)");
95 shouldBe(regexp18.firstMatch('Hello: World'), ['Hello:', ':']);
96
97 var regexp19 = new RegExp(r"(ab|^.{0,2})bar");
98 shouldBe(regexp19.firstMatch('barrel'), ['bar', '']);
99
100 var regexp20 = new RegExp(r"(?:(?!foo)...|^.{0,2})bar(.*)");
101 shouldBe(regexp20.firstMatch('barrel'), ['barrel', 'rel']);
102 shouldBe(regexp20.firstMatch('2barrel'), ['2barrel', 'rel']);
103
104 var regexp21 = new RegExp(r"([a-g](b|B)|xyz)");
105 shouldBe(regexp21.firstMatch('abc'), ['ab', 'ab', 'b']);
106
107 var regexp22 = new RegExp(r"(?:^|;)\s*abc=([^;]*)");
108 shouldBeNull(regexp22.firstMatch('abcdlskfgjdslkfg'));
109
110 var regexp23 = new RegExp("\"[^<\"]*\"|'[^<']*'");
111 shouldBe(regexp23.firstMatch('<html xmlns=\"http://www.w3.org/1999/xhtml\"'),
112 ['\"http://www.w3.org/1999/xhtml\"']);
113
114 var regexp24 = new RegExp(r"^(?:(?=abc)\w{3}:|\d\d)$");
115 shouldBeNull(regexp24.firstMatch('123'));
116
117 var regexp25 = new RegExp(r"^\s*(\*|[\w\-]+)(\b|$)?");
118 shouldBe(regexp25.firstMatch('this is a test'), ['this', 'this', null]);
119 shouldBeNull(regexp25.firstMatch('!this is a test'));
120
121 var regexp26 = new RegExp(r"a(b)(a*)|aaa");
122 shouldBe(regexp26.firstMatch('aaa'), ['aaa', null, null]);
123
124 var regexp27 = new RegExp("^" +
125 "(?:" +
126 "([^:/?#]+):" + /* scheme */
127 ")?" +
128 "(?:" +
129 "(//)" + /* authorityRoot */
130 "(" + /* authority */
131 "(?:" +
132 "(" + /* userInfo */
133 "([^:@]*)" + /* user */
134 ":?" +
135 "([^:@]*)" + /* password */
136 ")?" +
137 "@" +
138 ")?" +
139 "([^:/?#]*)" + /* domain */
140 "(?::(\\d*))?" + /* port */
141 ")" +
142 ")?" +
143 "([^?#]*)" + /*path*/
144 "(?:\\?([^#]*))?" + /* queryString */
145 "(?:#(.*))?" /*fragment */
146 );
147 shouldBe(
148 regexp27
149 .firstMatch('file:///Users/Someone/Desktop/HelloWorld/index.html'),
150 [
151 'file:///Users/Someone/Desktop/HelloWorld/index.html',
152 'file',
153 '//',
154 '',
155 null,
156 null,
157 null,
158 '',
159 null,
160 '/Users/Someone/Desktop/HelloWorld/index.html',
161 null,
162 null
163 ]);
164
165 var regexp28 = new RegExp("^" +
166 "(?:" +
167 "([^:/?#]+):" + /* scheme */
168 ")?" +
169 "(?:" +
170 "(//)" + /* authorityRoot */
171 "(" + /* authority */
172 "(" + /* userInfo */
173 "([^:@]*)" + /* user */
174 ":?" +
175 "([^:@]*)" + /* password */
176 ")?" +
177 "@" +
178 ")" +
179 ")?");
180 shouldBe(
181 regexp28
182 .firstMatch('file:///Users/Someone/Desktop/HelloWorld/index.html'),
183 ['file:', 'file', null, null, null, null, null]);
184
185 var regexp29 = new RegExp(r'^\s*((\[[^\]]+\])|(u?)("[^"]+"))\s*');
186 shouldBeNull(regexp29.firstMatch('Committer:'));
187
188 var regexp30 = new RegExp(r'^\s*((\[[^\]]+\])|m(u?)("[^"]+"))\s*');
189 shouldBeNull(regexp30.firstMatch('Committer:'));
190
191 var regexp31 = new RegExp(r'^\s*(m(\[[^\]]+\])|m(u?)("[^"]+"))\s*');
192 shouldBeNull(regexp31.firstMatch('Committer:'));
193
194 var regexp32 = new RegExp(r'\s*(m(\[[^\]]+\])|m(u?)("[^"]+"))\s*');
195 shouldBeNull(regexp32.firstMatch('Committer:'));
196
197 var regexp33 = new RegExp('^(?:(?:(a)(xyz|[^>"\'\s]*)?)|(/?>)|.[^\w\s>]*)');
198 shouldBe(regexp33.firstMatch('> <head>'), ['>', null, null, '>']);
199
200 var regexp34 = new RegExp(r"(?:^|\b)btn-\S+");
201 shouldBeNull(regexp34.firstMatch('xyz123'));
202 shouldBe(regexp34.firstMatch('btn-abc'), ['btn-abc']);
203 shouldBeNull(regexp34.firstMatch('btn- abc'));
204 shouldBeNull(regexp34.firstMatch('XXbtn-abc'));
205 shouldBe(regexp34.firstMatch('XX btn-abc'), ['btn-abc']);
206
207 var regexp35 = new RegExp(r"^((a|b)(x|xxx)|)$");
208 shouldBe(regexp35.firstMatch('ax'), ['ax', 'ax', 'a', 'x']);
209 shouldBeNull(regexp35.firstMatch('axx'));
210 shouldBe(regexp35.firstMatch('axxx'), ['axxx', 'axxx', 'a', 'xxx']);
211 shouldBe(regexp35.firstMatch('bx'), ['bx', 'bx', 'b', 'x']);
212 shouldBeNull(regexp35.firstMatch('bxx'));
213 shouldBe(regexp35.firstMatch('bxxx'), ['bxxx', 'bxxx', 'b', 'xxx']);
214
215 var regexp36 = new RegExp(r"^((\/|\.|\-)(\d\d|\d\d\d\d)|)$");
216 shouldBe(regexp36.firstMatch('/2011'), ['/2011', '/2011', '/', '2011']);
217 shouldBe(regexp36.firstMatch('/11'), ['/11', '/11', '/', '11']);
218 shouldBeNull(regexp36.firstMatch('/123'));
219
220 var regexp37 = new RegExp(
221 r"^([1][0-2]|[0]\d|\d)(\/|\.|\-)([0-2]\d|[3][0-1]|\d)((\/|\.|\-)(\d\d|\d\d \d\d)|)$");
222 shouldBe(regexp37.firstMatch('7/4/1776'),
223 ['7/4/1776', '7', '/', '4', '/1776', '/', '1776']);
224 shouldBe(regexp37.firstMatch('07-04-1776'),
225 ['07-04-1776', '07', '-', '04', '-1776', '-', '1776']);
226
227 var regexp38 = new RegExp(r"^(z|(x|xx)|b|)$");
228 shouldBe(regexp38.firstMatch('xx'), ['xx', 'xx', 'xx']);
229 shouldBe(regexp38.firstMatch('b'), ['b', 'b', null]);
230 shouldBe(regexp38.firstMatch('z'), ['z', 'z', null]);
231 shouldBe(regexp38.firstMatch(''), ['', '', null]);
232
233 var regexp39 = new RegExp(r"(8|((?=P)))?");
234 shouldBe(regexp39.firstMatch(''), ['', null, null]);
235 shouldBe(regexp39.firstMatch('8'), ['8', '8', null]);
236 shouldBe(regexp39.firstMatch('zP'), ['', null, null]);
237
238 var regexp40 = new RegExp(r"((8)|((?=P){4}))?()");
239 shouldBe(regexp40.firstMatch(''), ['', null, null, null, '']);
240 shouldBe(regexp40.firstMatch('8'), ['8', '8', '8', null, '']);
241 shouldBe(regexp40.firstMatch('zPz'), ['', null, null, null, '']);
242 shouldBe(regexp40.firstMatch('zPPz'), ['', null, null, null, '']);
243 shouldBe(regexp40.firstMatch('zPPPz'), ['', null, null, null, '']);
244 shouldBe(regexp40.firstMatch('zPPPPz'), ['', null, null, null, '']);
245
246 var regexp41 = new RegExp(
247 r"(([\w\-]+:\/\/?|www[.])[^\s()<>]+(?:([\w\d]+)|([^\[:punct:\]\s()<>\W]|\/ )))");
248 shouldBe(
249 regexp41.firstMatch(
250 'Here is a link: http://www.acme.com/our_products/index.html. That is all we want!'),
251 [
252 'http://www.acme.com/our_products/index.html',
253 'http://www.acme.com/our_products/index.html',
254 'http://',
255 'l',
256 null
257 ]);
258
259 var regexp42 = new RegExp(r"((?:(4)?))?");
260 shouldBe(regexp42.firstMatch(''), ['', null, null]);
261 shouldBe(regexp42.firstMatch('4'), ['4', '4', '4']);
262 shouldBe(regexp42.firstMatch('4321'), ['4', '4', '4']);
263
264 shouldBeTrue(new RegExp(r"(?!(?=r{0}){2,})|((z)?)?", caseSensitive: false)
265 .hasMatch(''));
266
267 var regexp43 = new RegExp(r"(?!(?:\1+s))");
268 shouldBe(regexp43.firstMatch('SSS'), ['']);
269
270 var regexp44 = new RegExp(r"(?!(?:\3+(s+?)))");
271 shouldBe(regexp44.firstMatch('SSS'), ['', null]);
272
273 var regexp45 = new RegExp(r"((?!(?:|)v{2,}|))");
274 shouldBeNull(regexp45.firstMatch('vt'));
275
276 var regexp46 = new RegExp(r"(w)(?:5{3}|())|pk");
277 shouldBeNull(regexp46.firstMatch('5'));
278 shouldBe(regexp46.firstMatch('pk'), ['pk', null, null]);
279 shouldBe(regexp46.firstMatch('Xw555'), ['w555', 'w', null]);
280 shouldBe(regexp46.firstMatch('Xw55pk5'), ['w', 'w', '']);
281
282 var regexp47 = new RegExp(r"(.*?)(?:(?:\?(.*?)?)?)(?:(?:#)?)$");
283 shouldBe(regexp47.firstMatch('/www.acme.com/this/is/a/path/file.txt'), [
284 '/www.acme.com/this/is/a/path/file.txt',
285 '/www.acme.com/this/is/a/path/file.txt',
286 null
287 ]);
288
289 var regexp48 = new RegExp(
290 r"^(?:(\w+):\/*([\w\.\-\d]+)(?::(\d+)|)(?=(?:\/|$))|)(?:$|\/?(.*?)(?:\?(.* ?)?|)(?:#(.*)|)$)");
291 shouldBe(regexp48.firstMatch('http://www.acme.com/this/is/a/path/file.txt'), [
292 'http://www.acme.com/this/is/a/path/file.txt',
293 'http',
294 'www.acme.com',
295 null,
296 'this/is/a/path/file.txt',
297 null,
298 null
299 ]);
300
301 var regexp49 = new RegExp(
302 r"(?:([^:]*?)(?:(?:\?(.*?)?)?)(?:(?:#)?)$)|(?:^(?:(\w+):\/*([\w\.\-\d]+)(? ::(\d+)|)(?=(?:\/|$))|)(?:$|\/?(.*?)(?:\?(.*?)?|)(?:#(.*)|)$))");
303 shouldBe(regexp49.firstMatch('http://www.acme.com/this/is/a/path/file.txt'), [
304 'http://www.acme.com/this/is/a/path/file.txt',
305 null,
306 null,
307 'http',
308 'www.acme.com',
309 null,
310 'this/is/a/path/file.txt',
311 null,
312 null
313 ]);
314
315 var regexp50 = new RegExp(r"((a)b{28,}c|d)x");
316 shouldBeNull(regexp50.firstMatch('((a)b{28,}c|d)x'));
317 shouldBe(regexp50.firstMatch('abbbbbbbbbbbbbbbbbbbbbbbbbbbbcx'), [
318 'abbbbbbbbbbbbbbbbbbbbbbbbbbbbcx',
319 'abbbbbbbbbbbbbbbbbbbbbbbbbbbbc',
320 'a'
321 ]);
322 shouldBe(regexp50.firstMatch('dx'), ['dx', 'd', null]);
323
324 var s = "((.\s{-}).{28,}\P{Yi}?{,30}\|.)\x9e{-,}\P{Any}";
325 var regexp51 = new RegExp(s);
326 shouldBeNull(regexp51.firstMatch('abc'));
327 shouldBe(regexp51.firstMatch(s), [')\x9e{-,}P{Any}', ')', null]);
328
329 var regexp52 = new RegExp(r"(Rob)|(Bob)|(Robert)|(Bobby)");
330 shouldBe(regexp52.firstMatch('Hi Bob'), ['Bob', null, 'Bob', null, null]);
331
332 // Test cases discovered by fuzzing that crashed the compiler.
333 var regexp53 = new RegExp(
334 r"(?=(?:(?:(gB)|(?!cs|<))((?=(?!v6){0,})))|(?=#)+?)",
335 multiLine: true);
336 shouldBe(regexp53.firstMatch('#'), ['', null, '']);
337 var regexp54 = new RegExp(r"((?:(?:()|(?!))((?=(?!))))|())", multiLine: true);
338 shouldBe(regexp54.firstMatch('#'), ['', '', null, null, '']);
339 var regexp55 = new RegExp(r"(?:(?:(?:a?|(?:))((?:)))|a?)", multiLine: true);
340 shouldBe(regexp55.firstMatch('#'), ['', '']);
341
342 // Test evaluation order of empty subpattern alternatives.
343 var regexp56 = new RegExp(r"(|a)");
344 shouldBe(regexp56.firstMatch('a'), ['', '']);
345 var regexp57 = new RegExp(r"(a|)");
346 shouldBe(regexp57.firstMatch('a'), ['a', 'a']);
347
348 // Tests that non-greedy repeat quantified parentheses will backtrack through multiple frames of subpattern matches.
349 var regexp58 = new RegExp(r"a|b(?:[^b])*?c");
350 shouldBe(regexp58.firstMatch('badbc'), ['a']);
351 var regexp59 = new RegExp(r"(X(?:.(?!X))*?Y)|(Y(?:.(?!Y))*?Z)");
352 Expect.listEquals(
353 regexp59
354 .allMatches('Y aaa X Match1 Y aaa Y Match2 Z')
355 .map((m) => m.group(0))
356 .toList(),
357 ['X Match1 Y', 'Y Match2 Z']);
358 }
OLDNEW
« no previous file with comments | « tests/corelib_strong/regexp/overflow_test.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698