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

Unified 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 side-by-side diff with in-line comments
Download patch
« 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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/language/regex/indexof_test.dart
diff --git a/tests/language/regex/indexof_test.dart b/tests/language/regex/indexof_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..f8f0e3c9d46dc037ec112523cc9bd31c52cb99d0
--- /dev/null
+++ b/tests/language/regex/indexof_test.dart
@@ -0,0 +1,46 @@
+// Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+import 'util.dart';
+import 'package:expect/expect.dart';
+
+void main() {
+ dynamic CheckMatch(re, str, matches) {
+ assertEquals(matches.length > 0, re.hasMatch(str));
+ var result = re.allMatches(str).toList();
+ if (matches.length > 0) {
+ assertEquals(matches.length, result.length);
+ var lastExpected;
+ var lastFrom;
+ var lastLength;
+ for (var idx = 0; idx < matches.length; idx++) {
+ var from = matches[idx][0];
+ var length = matches[idx][1];
+ var expected = str.substring(from, from + length);
+ var name = "$str[$from..${from+length}]";
+ assertEquals(expected, result[idx].group(0), name);
+ }
+ } else {
+ assertTrue(result.isEmpty);
+ }
+ }
+
+ CheckMatch(new RegExp(r"abc"), "xxxabcxxxabcxxx", [[3, 3], [9, 3]]);
+ CheckMatch(new RegExp(r"abc"), "abcabcabc", [[0, 3], [3, 3], [6, 3]]);
+ CheckMatch(new RegExp(r"aba"), "ababababa", [[0, 3], [4, 3]]);
+ CheckMatch(new RegExp(r"foo"), "ofooofoooofofooofo", [[1, 3], [5, 3], [12, 3]]);
+ CheckMatch(new RegExp(r"foobarbaz"), "xx", []);
+ CheckMatch(new RegExp(r"abc"), "abababa", []);
+
+ assertEquals("xxxdefxxxdefxxx", "xxxabcxxxabcxxx".replaceAll(new RegExp(r"abc"), "def"));
+ assertEquals("o-o-oofo-ofo", "ofooofoooofofooofo".replaceAll(new RegExp(r"foo"), "-"));
+ assertEquals("deded", "deded".replaceAll(new RegExp(r"x"), "-"));
+ assertEquals("-a-b-c-d-e-f-", "abcdef".replaceAll(new RegExp(""), "-"));
+
+ CheckMatch(new RegExp(r"a(.)"), "xyzzyabxyzzyacxyzzy", [[5, 2], [12, 2]]);
+
+ CheckMatch(new RegExp(r"a|(?:)"), "aba", [[0, 1], [1, 0], [2, 1], [3, 0]]);
+ CheckMatch(new RegExp(r"a|(?:)"), "baba", [[0, 0], [1, 1], [2, 0], [3, 1], [4, 0]]);
+ CheckMatch(new RegExp(r"a|(?:)"), "bab", [[0, 0], [1, 1], [2, 0], [3, 0]]);
+}
« 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