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

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

Issue 667043003: Port regexp tests from V8 to Dart. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 1 month 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 | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file.
4
5 import 'util.dart';
6 import 'package:expect/expect.dart';
7
8 void main() {
9 description("This page tests handling of parentheses subexpressions.");
10
11 var regexp1 = new RegExp(r"(a|A)(b|B)");
12 shouldBe(regexp1.firstMatch('abc'), ['ab','a','b']);
13
14 var regexp2 = new RegExp(r"(a((b)|c|d))e");
15 shouldBe(regexp2.firstMatch('abacadabe'), ['abe','ab','b','b']);
16
17 var regexp3 = new RegExp(r"(a(b|(c)|d))e");
18 shouldBe(regexp3.firstMatch('abacadabe'), ['abe','ab','b',null]);
19
20 var regexp4 = new RegExp(r"(a(b|c|(d)))e");
21 shouldBe(regexp4.firstMatch('abacadabe'), ['abe','ab','b',null]);
22
23 var regexp5 = new RegExp(r"(a((b)|(c)|(d)))e");
24 shouldBe(regexp5.firstMatch('abacadabe'), ['abe','ab','b','b',null,null]);
25
26 var regexp6 = new RegExp(r"(a((b)|(c)|(d)))");
27 shouldBe(regexp6.firstMatch('abcde'), ['ab','ab','b','b',null,null]);
28
29 var regexp7 = new RegExp(r"(a(b)??)??c");
30 shouldBe(regexp7.firstMatch('abc'), ['abc','ab','b']);
31
32 var regexp8 = new RegExp(r"(a|(e|q))(x|y)");
33 shouldBe(regexp8.firstMatch('bcaddxqy') , ['qy','q','q','y']);
34
35 var regexp9 = new RegExp(r"((t|b)?|a)$");
36 shouldBe(regexp9.firstMatch('asdfjejgsdflaksdfjkeljghkjea'), ['a','a',null]);
37
38 var regexp10 = new RegExp(r"(?:h|e?(?:t|b)?|a?(?:t|b)?)(?:$)");
39 shouldBe(regexp10.firstMatch('asdfjejgsdflaksdfjkeljghat'), ['at']);
40
41 var regexp11 = new RegExp(r"([Jj]ava([Ss]cript)?)\sis\s(fun\w*)");
42 shouldBeNull(regexp11.firstMatch('Developing with JavaScript is dangerous, do not try it without assistance'));
43
44 var regexp12 = new RegExp(r"(?:(.+), )?(.+), (..) to (?:(.+), )?(.+), (..)");
45 shouldBe(regexp12.firstMatch('Seattle, WA to Buckley, WA'), ['Seattle, WA to B uckley, WA', null, 'Seattle', 'WA', null, 'Buckley', 'WA']);
46
47 var regexp13 = new RegExp(r"(A)?(A.*)");
48 shouldBe(regexp13.firstMatch('zxcasd;fl\ ^AaaAAaaaf;lrlrzs'), ['AaaAAaaaf;lrlr zs',null,'AaaAAaaaf;lrlrzs']);
49
50 var regexp14 = new RegExp(r"(a)|(b)");
51 shouldBe(regexp14.firstMatch('b'), ['b',null,'b']);
52
53 var regexp15 = new RegExp(r"^(?!(ab)de|x)(abd)(f)");
54 shouldBe(regexp15.firstMatch('abdf'), ['abdf',null,'abd','f']);
55
56 var regexp16 = new RegExp(r"(a|A)(b|B)");
57 shouldBe(regexp16.firstMatch('abc'), ['ab','a','b']);
58
59 var regexp17 = new RegExp(r"(a|d|q|)x", caseSensitive: false);
60 shouldBe(regexp17.firstMatch('bcaDxqy'), ['Dx','D']);
61
62 var regexp18 = new RegExp(r"^.*?(:|$)");
63 shouldBe(regexp18.firstMatch('Hello: World'), ['Hello:',':']);
64
65 var regexp19 = new RegExp(r"(ab|^.{0,2})bar");
66 shouldBe(regexp19.firstMatch('barrel'), ['bar','']);
67
68 var regexp20 = new RegExp(r"(?:(?!foo)...|^.{0,2})bar(.*)");
69 shouldBe(regexp20.firstMatch('barrel'), ['barrel','rel']);
70 shouldBe(regexp20.firstMatch('2barrel'), ['2barrel','rel']);
71
72 var regexp21 = new RegExp(r"([a-g](b|B)|xyz)");
73 shouldBe(regexp21.firstMatch('abc'), ['ab','ab','b']);
74
75 var regexp22 = new RegExp(r"(?:^|;)\s*abc=([^;]*)");
76 shouldBeNull(regexp22.firstMatch('abcdlskfgjdslkfg'));
77
78 var regexp23 = new RegExp("\"[^<\"]*\"|'[^<']*'");
79 shouldBe(regexp23.firstMatch('<html xmlns=\"http://www.w3.org/1999/xhtml\"'),
80 ['\"http://www.w3.org/1999/xhtml\"']);
81
82 var regexp24 = new RegExp(r"^(?:(?=abc)\w{3}:|\d\d)$");
83 shouldBeNull(regexp24.firstMatch('123'));
84
85 var regexp25 = new RegExp(r"^\s*(\*|[\w\-]+)(\b|$)?");
86 shouldBe(regexp25.firstMatch('this is a test'), ['this','this',null]);
87 shouldBeNull(regexp25.firstMatch('!this is a test'));
88
89 var regexp26 = new RegExp(r"a(b)(a*)|aaa");
90 shouldBe(regexp26.firstMatch('aaa'), ['aaa',null,null]);
91
92 var regexp27 = new RegExp(
93 "^" +
94 "(?:" +
95 "([^:/?#]+):" + /* scheme */
96 ")?" +
97 "(?:" +
98 "(//)" + /* authorityRoot */
99 "(" + /* authority */
100 "(?:" +
101 "(" + /* userInfo */
102 "([^:@]*)" + /* user */
103 ":?" +
104 "([^:@]*)" + /* password */
105 ")?" +
106 "@" +
107 ")?" +
108 "([^:/?#]*)" + /* domain */
109 "(?::(\\d*))?" + /* port */
110 ")" +
111 ")?" +
112 "([^?#]*)" + /*path*/
113 "(?:\\?([^#]*))?" + /* queryString */
114 "(?:#(.*))?" /*fragment */
115 );
116 shouldBe(regexp27.firstMatch('file:///Users/Someone/Desktop/HelloWorld/index.h tml'), ['file:///Users/Someone/Desktop/HelloWorld/index.html','file','//','',nul l,null,null,'',null,'/Users/Someone/Desktop/HelloWorld/index.html',null,null]);
117
118 var regexp28 = new RegExp(
119 "^" +
120 "(?:" +
121 "([^:/?#]+):" + /* scheme */
122 ")?" +
123 "(?:" +
124 "(//)" + /* authorityRoot */
125 "(" + /* authority */
126 "(" + /* userInfo */
127 "([^:@]*)" + /* user */
128 ":?" +
129 "([^:@]*)" + /* password */
130 ")?" +
131 "@" +
132 ")" +
133 ")?"
134 );
135 shouldBe(regexp28.firstMatch('file:///Users/Someone/Desktop/HelloWorld/index.h tml'), ['file:','file',null,null,null,null,null]);
136
137 var regexp29 = new RegExp(r'^\s*((\[[^\]]+\])|(u?)("[^"]+"))\s*');
138 shouldBeNull(regexp29.firstMatch('Committer:'));
139
140 var regexp30 = new RegExp(r'^\s*((\[[^\]]+\])|m(u?)("[^"]+"))\s*');
141 shouldBeNull(regexp30.firstMatch('Committer:'));
142
143 var regexp31 = new RegExp(r'^\s*(m(\[[^\]]+\])|m(u?)("[^"]+"))\s*');
144 shouldBeNull(regexp31.firstMatch('Committer:'));
145
146 var regexp32 = new RegExp(r'\s*(m(\[[^\]]+\])|m(u?)("[^"]+"))\s*');
147 shouldBeNull(regexp32.firstMatch('Committer:'));
148
149 var regexp33 = new RegExp('^(?:(?:(a)(xyz|[^>"\'\s]*)?)|(/?>)|.[^\w\s>]*)');
150 shouldBe(regexp33.firstMatch('> <head>'), ['>',null,null,'>']);
151
152 var regexp34 = new RegExp(r"(?:^|\b)btn-\S+");
153 shouldBeNull(regexp34.firstMatch('xyz123'));
154 shouldBe(regexp34.firstMatch('btn-abc'),['btn-abc']);
155 shouldBeNull(regexp34.firstMatch('btn- abc'));
156 shouldBeNull(regexp34.firstMatch('XXbtn-abc'));
157 shouldBe(regexp34.firstMatch('XX btn-abc'),['btn-abc']);
158
159 var regexp35 = new RegExp(r"^((a|b)(x|xxx)|)$");
160 shouldBe(regexp35.firstMatch('ax'), ['ax','ax','a','x']);
161 shouldBeNull(regexp35.firstMatch('axx'));
162 shouldBe(regexp35.firstMatch('axxx'), ['axxx','axxx','a','xxx']);
163 shouldBe(regexp35.firstMatch('bx'), ['bx','bx','b','x']);
164 shouldBeNull(regexp35.firstMatch('bxx'));
165 shouldBe(regexp35.firstMatch('bxxx'), ['bxxx','bxxx','b','xxx']);
166
167 var regexp36 = new RegExp(r"^((\/|\.|\-)(\d\d|\d\d\d\d)|)$");
168 shouldBe(regexp36.firstMatch('/2011'), ['/2011','/2011','/','2011']);
169 shouldBe(regexp36.firstMatch('/11'), ['/11','/11','/','11']);
170 shouldBeNull(regexp36.firstMatch('/123'));
171
172 var regexp37 = new RegExp(r"^([1][0-2]|[0]\d|\d)(\/|\.|\-)([0-2]\d|[3][0-1]|\d )((\/|\.|\-)(\d\d|\d\d\d\d)|)$");
173 shouldBe(regexp37.firstMatch('7/4/1776'), ['7/4/1776','7','/','4','/1776','/', '1776']);
174 shouldBe(regexp37.firstMatch('07-04-1776'), ['07-04-1776','07','-','04','-1776 ','-','1776']);
175
176 var regexp38 = new RegExp(r"^(z|(x|xx)|b|)$");
177 shouldBe(regexp38.firstMatch('xx'), ['xx','xx','xx']);
178 shouldBe(regexp38.firstMatch('b'), ['b','b',null]);
179 shouldBe(regexp38.firstMatch('z'), ['z','z',null]);
180 shouldBe(regexp38.firstMatch(''), ['','',null]);
181
182 var regexp39 = new RegExp(r"(8|((?=P)))?");
183 shouldBe(regexp39.firstMatch(''), ['',null,null]);
184 shouldBe(regexp39.firstMatch('8'), ['8','8',null]);
185 shouldBe(regexp39.firstMatch('zP'), ['',null,null]);
186
187 var regexp40 = new RegExp(r"((8)|((?=P){4}))?()");
188 shouldBe(regexp40.firstMatch(''), ['',null,null,null,'']);
189 shouldBe(regexp40.firstMatch('8'), ['8','8','8',null,'']);
190 shouldBe(regexp40.firstMatch('zPz'), ['',null,null,null,'']);
191 shouldBe(regexp40.firstMatch('zPPz'), ['',null,null,null,'']);
192 shouldBe(regexp40.firstMatch('zPPPz'), ['',null,null,null,'']);
193 shouldBe(regexp40.firstMatch('zPPPPz'), ['',null,null,null,'']);
194
195 var regexp41 = new RegExp(r"(([\w\-]+:\/\/?|www[.])[^\s()<>]+(?:([\w\d]+)|([^\ [:punct:\]\s()<>\W]|\/)))");
196 shouldBe(regexp41.firstMatch('Here is a link: http://www.acme.com/our_products /index.html. That is all we want!'),
197 ['http://www.acme.com/our_products/index.html','http://www.acme.com/our_pr oducts/index.html','http://','l',null]);
198
199 var regexp42 = new RegExp(r"((?:(4)?))?");
200 shouldBe(regexp42.firstMatch(''), ['',null,null]);
201 shouldBe(regexp42.firstMatch('4'), ['4','4','4']);
202 shouldBe(regexp42.firstMatch('4321'), ['4','4','4']);
203
204 shouldBeTrue(new RegExp(r"(?!(?=r{0}){2,})|((z)?)?", caseSensitive: false).has Match(''));
205
206 var regexp43 = new RegExp(r"(?!(?:\1+s))");
207 shouldBe(regexp43.firstMatch('SSS'), ['']);
208
209 var regexp44 = new RegExp(r"(?!(?:\3+(s+?)))");
210 shouldBe(regexp44.firstMatch('SSS'), ['',null]);
211
212 var regexp45 = new RegExp(r"((?!(?:|)v{2,}|))");
213 shouldBeNull(regexp45.firstMatch('vt'));
214
215 var regexp46 = new RegExp(r"(w)(?:5{3}|())|pk");
216 shouldBeNull(regexp46.firstMatch('5'));
217 shouldBe(regexp46.firstMatch('pk'), ['pk',null,null]);
218 shouldBe(regexp46.firstMatch('Xw555'), ['w555','w',null]);
219 shouldBe(regexp46.firstMatch('Xw55pk5'), ['w','w','']);
220
221 var regexp47 = new RegExp(r"(.*?)(?:(?:\?(.*?)?)?)(?:(?:#)?)$");
222 shouldBe(regexp47.firstMatch('/www.acme.com/this/is/a/path/file.txt'),
223 ['/www.acme.com/this/is/a/path/file.txt','/www.acme.com/this/is/a/path/f ile.txt',null]);
224
225 var regexp48 = new RegExp(r"^(?:(\w+):\/*([\w\.\-\d]+)(?::(\d+)|)(?=(?:\/|$))| )(?:$|\/?(.*?)(?:\?(.*?)?|)(?:#(.*)|)$)");
226 shouldBe(regexp48.firstMatch('http://www.acme.com/this/is/a/path/file.txt'),
227 ['http://www.acme.com/this/is/a/path/file.txt','http','www.acme.com',null, 'this/is/a/path/file.txt',null,null]);
228
229 var regexp49 = new RegExp(r"(?:([^:]*?)(?:(?:\?(.*?)?)?)(?:(?:#)?)$)|(?:^(?:(\ w+):\/*([\w\.\-\d]+)(?::(\d+)|)(?=(?:\/|$))|)(?:$|\/?(.*?)(?:\?(.*?)?|)(?:#(.*)| )$))");
230 shouldBe(regexp49.firstMatch('http://www.acme.com/this/is/a/path/file.txt'),
231 ['http://www.acme.com/this/is/a/path/file.txt',null,null,'http','www.acme. com',null,'this/is/a/path/file.txt',null,null]);
232
233 var regexp50 = new RegExp(r"((a)b{28,}c|d)x");
234 shouldBeNull(regexp50.firstMatch('((a)b{28,}c|d)x'));
235 shouldBe(regexp50.firstMatch('abbbbbbbbbbbbbbbbbbbbbbbbbbbbcx'), ['abbbbbbbbbb bbbbbbbbbbbbbbbbbbcx', 'abbbbbbbbbbbbbbbbbbbbbbbbbbbbc', 'a']);
236 shouldBe(regexp50.firstMatch('dx'), ['dx', 'd', null]);
237
238 var s = "((.\s{-}).{28,}\P{Yi}?{,30}\|.)\x9e{-,}\P{Any}";
239 var regexp51 = new RegExp(s);
240 shouldBeNull(regexp51.firstMatch('abc'));
241 shouldBe(regexp51.firstMatch(s), [')\x9e{-,}P{Any}',')',null]);
242
243 var regexp52 = new RegExp(r"(Rob)|(Bob)|(Robert)|(Bobby)");
244 shouldBe(regexp52.firstMatch('Hi Bob'), ['Bob',null,'Bob',null,null]);
245
246 // Test cases discovered by fuzzing that crashed the compiler.
247 var regexp53 = new RegExp(r"(?=(?:(?:(gB)|(?!cs|<))((?=(?!v6){0,})))|(?=#)+?)" , multiLine: true);
248 shouldBe(regexp53.firstMatch('#'), ['',null,'']);
249 var regexp54 = new RegExp(r"((?:(?:()|(?!))((?=(?!))))|())", multiLine: true);
250 shouldBe(regexp54.firstMatch('#'), ['','',null,null,'']);
251 var regexp55 = new RegExp(r"(?:(?:(?:a?|(?:))((?:)))|a?)", multiLine: true);
252 shouldBe(regexp55.firstMatch('#'), ['','']);
253
254 // Test evaluation order of empty subpattern alternatives.
255 var regexp56 = new RegExp(r"(|a)");
256 shouldBe(regexp56.firstMatch('a'), ['','']);
257 var regexp57 = new RegExp(r"(a|)");
258 shouldBe(regexp57.firstMatch('a'), ['a','a']);
259
260 // Tests that non-greedy repeat quantified parentheses will backtrack through multiple frames of subpattern matches.
261 var regexp58 = new RegExp(r"a|b(?:[^b])*?c");
262 shouldBe(regexp58.firstMatch('badbc'), ['a']);
263 var regexp59 = new RegExp(r"(X(?:.(?!X))*?Y)|(Y(?:.(?!Y))*?Z)");
264 Expect.listEquals(regexp59.allMatches('Y aaa X Match1 Y aaa Y Match2 Z')
265 .map((m) => m.group(0))
266 .toList(),
267 ['X Match1 Y','Y Match2 Z']);
268 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698