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

Side by Side Diff: tests/language/regex/indexof_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
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 CheckMatch(re, str, matches) {
10 assertEquals(matches.length > 0, re.hasMatch(str));
11 var result = re.allMatches(str).toList();
12 if (matches.length > 0) {
13 assertEquals(matches.length, result.length);
14 var lastExpected;
15 var lastFrom;
16 var lastLength;
17 for (var idx = 0; idx < matches.length; idx++) {
18 var from = matches[idx][0];
19 var length = matches[idx][1];
20 var expected = str.substring(from, from + length);
21 var name = "$str[$from..${from+length}]";
22 assertEquals(expected, result[idx].group(0), name);
23 }
24 } else {
25 assertTrue(result.isEmpty);
26 }
27 }
28
29 CheckMatch(new RegExp(r"abc"), "xxxabcxxxabcxxx", [[3, 3], [9, 3]]);
30 CheckMatch(new RegExp(r"abc"), "abcabcabc", [[0, 3], [3, 3], [6, 3]]);
31 CheckMatch(new RegExp(r"aba"), "ababababa", [[0, 3], [4, 3]]);
32 CheckMatch(new RegExp(r"foo"), "ofooofoooofofooofo", [[1, 3], [5, 3], [12, 3]] );
33 CheckMatch(new RegExp(r"foobarbaz"), "xx", []);
34 CheckMatch(new RegExp(r"abc"), "abababa", []);
35
36 assertEquals("xxxdefxxxdefxxx", "xxxabcxxxabcxxx".replaceAll(new RegExp(r"abc" ), "def"));
37 assertEquals("o-o-oofo-ofo", "ofooofoooofofooofo".replaceAll(new RegExp(r"foo" ), "-"));
38 assertEquals("deded", "deded".replaceAll(new RegExp(r"x"), "-"));
39 assertEquals("-a-b-c-d-e-f-", "abcdef".replaceAll(new RegExp(""), "-"));
40
41 CheckMatch(new RegExp(r"a(.)"), "xyzzyabxyzzyacxyzzy", [[5, 2], [12, 2]]);
42
43 CheckMatch(new RegExp(r"a|(?:)"), "aba", [[0, 1], [1, 0], [2, 1], [3, 0]]);
44 CheckMatch(new RegExp(r"a|(?:)"), "baba", [[0, 0], [1, 1], [2, 0], [3, 1], [4, 0]]);
45 CheckMatch(new RegExp(r"a|(?:)"), "bab", [[0, 0], [1, 1], [2, 0], [3, 0]]);
46 }
OLDNEW
« no previous file with comments | « tests/language/regex/global_test.dart ('k') | tests/language/regex/invalid-range-in-class_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698