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

Unified Diff: tests/corelib/string_replace_test.dart

Issue 949753005: Add String.replaceRange and use it in replaceFirst{,Mapped}. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address comments. Created 5 years, 10 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 | « sdk/lib/core/string.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/corelib/string_replace_test.dart
diff --git a/tests/corelib/string_replace_test.dart b/tests/corelib/string_replace_test.dart
index b8486ae0363e37df4c6f5b4888bea4c9db6a3d2a..3e53efd32ccb015328ef923aba84a824335f319b 100644
--- a/tests/corelib/string_replace_test.dart
+++ b/tests/corelib/string_replace_test.dart
@@ -210,6 +210,29 @@ main() {
var n = new Naughty();
Expect.throws(
() => "foo-bar".replaceFirstMapped("bar", (v) { return n; }));
+
+ for (var string in ["", "x", "foo", "x\u2000z"]) {
+ for (var replacement in ["", "foo", string]) {
+ for (int start = 0; start <= string.length; start++) {
+ var expect;
+ for (int end = start; end <= string.length; end++) {
+ expect = string.substring(0, start) +
+ replacement +
+ string.substring(end);
+ Expect.equals(expect, string.replaceRange(start, end, replacement),
+ '"$string"[$start:$end]="$replacement"');
+ }
+ // Reuse expect from "end == string.length" case when omitting end.
+ Expect.equals(expect, string.replaceRange(start, null, replacement),
+ '"$string"[$start:]="$replacement"');
+ }
+ }
+ Expect.throws(() => string.replaceRange(0, 0, null));
+ Expect.throws(() => string.replaceRange(0, 0, 42));
+ Expect.throws(() => string.replaceRange(0, 0, ["x"]));
+ Expect.throws(() => string.replaceRange(-1, 0, "x"));
+ Expect.throws(() => string.replaceRange(0, string.length + 1, "x"));
+ }
}
// Fails to return a String on toString, throws if converted by "$naughty".
« no previous file with comments | « sdk/lib/core/string.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698