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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « sdk/lib/core/string.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 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. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 import "package:expect/expect.dart"; 5 import "package:expect/expect.dart";
6 6
7 main() { 7 main() {
8 // Test replaceFirst. 8 // Test replaceFirst.
9 Expect.equals( 9 Expect.equals(
10 "AtoBtoCDtoE", "AfromBtoCDtoE".replaceFirst("from", "to")); 10 "AtoBtoCDtoE", "AfromBtoCDtoE".replaceFirst("from", "to"));
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
203 Expect.equals("foo-$o", "foo-bar".replaceFirstMapped("bar", 203 Expect.equals("foo-$o", "foo-bar".replaceFirstMapped("bar",
204 (v) { return o; })); 204 (v) { return o; }));
205 205
206 Expect.equals("foo-42", "foo-bar".replaceFirstMapped("bar", 206 Expect.equals("foo-42", "foo-bar".replaceFirstMapped("bar",
207 (v) { return 42; })); 207 (v) { return 42; }));
208 208
209 // Test replacement returning object throwing on string-conversion. 209 // Test replacement returning object throwing on string-conversion.
210 var n = new Naughty(); 210 var n = new Naughty();
211 Expect.throws( 211 Expect.throws(
212 () => "foo-bar".replaceFirstMapped("bar", (v) { return n; })); 212 () => "foo-bar".replaceFirstMapped("bar", (v) { return n; }));
213
214 for (var string in ["", "x", "foo", "x\u2000z"]) {
215 for (var replacement in ["", "foo", string]) {
216 for (int start = 0; start <= string.length; start++) {
217 var expect;
218 for (int end = start; end <= string.length; end++) {
219 expect = string.substring(0, start) +
220 replacement +
221 string.substring(end);
222 Expect.equals(expect, string.replaceRange(start, end, replacement),
223 '"$string"[$start:$end]="$replacement"');
224 }
225 // Reuse expect from "end == string.length" case when omitting end.
226 Expect.equals(expect, string.replaceRange(start, null, replacement),
227 '"$string"[$start:]="$replacement"');
228 }
229 }
230 Expect.throws(() => string.replaceRange(0, 0, null));
231 Expect.throws(() => string.replaceRange(0, 0, 42));
232 Expect.throws(() => string.replaceRange(0, 0, ["x"]));
233 Expect.throws(() => string.replaceRange(-1, 0, "x"));
234 Expect.throws(() => string.replaceRange(0, string.length + 1, "x"));
235 }
213 } 236 }
214 237
215 // Fails to return a String on toString, throws if converted by "$naughty". 238 // Fails to return a String on toString, throws if converted by "$naughty".
216 class Naughty { 239 class Naughty {
217 toString() => this; 240 toString() => this;
218 } 241 }
OLDNEW
« 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