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

Side by Side Diff: tests/language/regex/capture-3_test.dart

Issue 539153002: Port and integrate the irregexp engine from V8 (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Addressed Ivan's comments. Created 6 years, 2 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 | Annotate | Revision Log
« no previous file with comments | « tests/language/regex/bol_test.dart ('k') | tests/language/regex/capture_test.dart » ('j') | 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. 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 dynamic oneMatch(re) {
10 assertEquals("acd", "abcd".replaceAll(re, ""));
11 }
12
13 oneMatch(new RegExp(r"b"));
14 oneMatch(new RegExp(r"b"));
15
16 assertEquals("acdacd", "abcdabcd".replaceAll(new RegExp(r"b"), ""));
17
18 dynamic captureMatch(re) {
19 var match = firstMatch("abcd", re);
20 assertEquals("b", match.group(1));
21 assertEquals("c", match.group(2));
22 }
23
24 captureMatch(new RegExp(r"(b)(c)"));
25 captureMatch(new RegExp(r"(b)(c)"));
26
27 // A test that initially does a zero width match, but later does a non-zero
28 // width match.
29 var a = "foo bar baz".replaceAll(new RegExp(r"^|bar"), "");
30 assertEquals("foo baz", a);
31
32 a = "foo bar baz".replaceAll(new RegExp(r"^|bar"), "*");
33 assertEquals("*foo * baz", a);
34
35 // We test FilterASCII using regexps that will backtrack forever. Since
36 // a regexp with a non-ASCII character in it can never match an ASCII
37 // string we can test that the relevant node is removed by verifying that
38 // there is no hang.
39 dynamic NoHang(re) {
40 firstMatch("This is an ASCII string that could take forever", re);
41 }
42
43 NoHang(new RegExp(r"(((.*)*)*x)Ā")); // Continuation after loop is filtered, so is loop.
44 NoHang(new RegExp(r"(((.*)*)*Ā)foo")); // Body of loop filtered.
45 NoHang(new RegExp(r"Ā(((.*)*)*x)")); // Everything after a filtered characte r is filtered.
46 NoHang(new RegExp(r"(((.*)*)*x)Ā")); // Everything before a filtered charact er is filtered.
47 NoHang(new RegExp(r"[ćăĀ](((.*)*)*x)")); // Everything after a filtered clas s is filtered.
48 NoHang(new RegExp(r"(((.*)*)*x)[ćăĀ]")); // Everything before a filtered cla ss is filtered.
49 NoHang(new RegExp(r"[^\x00-\xff](((.*)*)*x)")); // After negated class.
50 NoHang(new RegExp(r"(((.*)*)*x)[^\x00-\xff]")); // Before negated class.
51 NoHang(new RegExp(r"(?!(((.*)*)*x)Ā)foo")); // Negative lookahead is filtered .
52 NoHang(new RegExp(r"(?!(((.*)*)*x))Ā")); // Continuation branch of negative l ookahead.
53 NoHang(new RegExp(r"(?=(((.*)*)*x)Ā)foo")); // Positive lookahead is filtered .
54 NoHang(new RegExp(r"(?=(((.*)*)*x))Ā")); // Continuation branch of positive l ookahead.
55 NoHang(new RegExp(r"(?=Ā)(((.*)*)*x)")); // Positive lookahead also prunes co ntinuation.
56 NoHang(new RegExp(r"(æ|ø|Ā)(((.*)*)*x)")); // All branches of alternation are filtered.
57 NoHang(new RegExp(r"(a|b|(((.*)*)*x))Ā")); // 1 out of 3 branches pruned.
58 NoHang(new RegExp(r"(a|(((.*)*)*x)ă|(((.*)*)*x)Ā)")); // 2 out of 3 branches pruned.
59
60 var s = "Don't prune based on a repetition of length 0";
61 assertEquals(null, firstMatch(s, new RegExp(r"å{1,1}prune")));
62 assertEquals("prune", (firstMatch(s, new RegExp(r"å{0,0}prune"))[0]));
63
64 // Some very deep regexps where FilterASCII gives up in order not to make the
65 // stack overflow.
66 var regex6 = new RegExp(r"a*\u0100*\w");
67 var input0 = "a";
68 regex6.firstMatch(input0);
69
70 var re = "\u0100*\\w";
71
72 for (var i = 0; i < 200; i++) re = "a*" + re;
73
74 var regex7 = new RegExp(re);
75 regex7.firstMatch(input0);
76
77 var regex8 = new RegExp(re, caseSensitive: false);
78 regex8.firstMatch(input0);
79
80 re = "[\u0100]*\\w";
81 for (var i = 0; i < 200; i++) re = "a*" + re;
82
83 var regex9 = new RegExp(re);
84 regex9.firstMatch(input0);
85
86 var regex10 = new RegExp(re, caseSensitive: false);
87 regex10.firstMatch(input0);
88
89 var regex11 = new RegExp(r"^(?:[^\u0000-\u0080]|[0-9a-z?,.!&\s#()])+$", caseSe nsitive: false);
90 regex11.firstMatch(input0);
91
92 var regex12 = new RegExp(r"u(\xf0{8}?\D*?|( ? !)$h??(|)*?(||)+?\6((?:\W\B|--\d -*-|)?$){0, }?|^Y( ? !1)\d+)+a");
93 regex12.firstMatch("");
94 }
OLDNEW
« no previous file with comments | « tests/language/regex/bol_test.dart ('k') | tests/language/regex/capture_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698