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

Unified Diff: tests/language/reg_exp_test.dart

Issue 15709018: Proof-of-concept matchPrefix on Pattern. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Addressed other comments. Created 7 years, 6 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/corelib/string_pattern_test.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/language/reg_exp_test.dart
diff --git a/tests/language/reg_exp_test.dart b/tests/language/reg_exp_test.dart
index 26826a906b956a5f31ee254124b268321faa5b3e..c51663c3b63bb6224dc9c1b3305637ebc87529af 100644
--- a/tests/language/reg_exp_test.dart
+++ b/tests/language/reg_exp_test.dart
@@ -25,4 +25,40 @@ void main() {
exp = new RegExp("^", multiLine: true); // Any zero-length match will work.
str = "foo\nbar\nbaz";
Expect.equals(" foo\n bar\n baz", str.replaceAll(exp, " "));
+
+ exp = new RegExp(r"(\w+)");
+ Expect.isNull(exp.matchAsPrefix(" xyz ab"));
+ Expect.isNull(exp.matchAsPrefix(" xyz ab", 0));
+
+ var m = exp.matchAsPrefix(" xyz ab", 1);
+ Expect.equals("xyz", m[0]);
+ Expect.equals("xyz", m[1]);
+ Expect.equals(1, m.groupCount);
+
+ m = exp.matchAsPrefix(" xyz ab", 2);
+ Expect.equals("yz", m[0]);
+ Expect.equals("yz", m[1]);
+ Expect.equals(1, m.groupCount);
+
+ m = exp.matchAsPrefix(" xyz ab", 3);
+ Expect.equals("z", m[0]);
+ Expect.equals("z", m[1]);
+ Expect.equals(1, m.groupCount);
+
+ Expect.isNull(exp.matchAsPrefix(" xyz ab", 4));
+
+ m = exp.matchAsPrefix(" xyz ab", 5);
+ Expect.equals("ab", m[0]);
+ Expect.equals("ab", m[1]);
+ Expect.equals(1, m.groupCount);
+
+ m = exp.matchAsPrefix(" xyz ab", 6);
+ Expect.equals("b", m[0]);
+ Expect.equals("b", m[1]);
+ Expect.equals(1, m.groupCount);
+
+ Expect.isNull(exp.matchAsPrefix(" xyz ab", 7));
+
+ Expect.throws(() => exp.matchAsPrefix(" xyz ab", -1));
+ Expect.throws(() => exp.matchAsPrefix(" xyz ab", 8));
}
« no previous file with comments | « tests/corelib/string_pattern_test.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698