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

Unified Diff: tests/language/reg_exp_test.dart

Issue 460613002: Add optional start index to Pattern.allMatches. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Add extra test. Created 6 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 side-by-side diff with in-line comments
Download patch
Index: tests/language/reg_exp_test.dart
diff --git a/tests/language/reg_exp_test.dart b/tests/language/reg_exp_test.dart
index c51663c3b63bb6224dc9c1b3305637ebc87529af..cde9112c492afc1d50e4d00632a272fc45cf368b 100644
--- a/tests/language/reg_exp_test.dart
+++ b/tests/language/reg_exp_test.dart
@@ -21,6 +21,26 @@ void main() {
Expect.listEquals(["", "a", "", "", "a", ""],
exp.allMatches(str).map((x)=>x[0]).toList());
+ // Check that allMatches works with optional start index.
+ exp = new RegExp("as{2}");
+ str = "assassin";
+ Expect.equals(2, exp.allMatches(str).length);
+ Expect.equals(2, exp.allMatches(str, 0).length);
+ Expect.equals(1, exp.allMatches(str, 1).length);
+ Expect.equals(0, exp.allMatches(str, 4).length);
+ Expect.equals(0, exp.allMatches(str, str.length).length);
+ Expect.throws(() => exp.allMatches(str, -1));
+ Expect.throws(() => exp.allMatches(str, str.length + 1));
+
+ exp = new RegExp(".*");
+ Expect.equals("", exp.allMatches(str, str.length).single[0]);
+
+ // The "^" must only match at the beginning of the string.
+ // Using a start-index doesn't change where the string starts.
+ exp = new RegExp("^ass");
+ Expect.equals(1, exp.allMatches(str, 0).length);
+ Expect.equals(0, exp.allMatches(str, 3).length);
+
// Regression test for http://dartbug.com/2980
exp = new RegExp("^", multiLine: true); // Any zero-length match will work.
str = "foo\nbar\nbaz";

Powered by Google App Engine
This is Rietveld 408576698