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

Side by Side Diff: tests/corelib/string_replace_test.dart

Issue 462463003: Add optional startIndex to String.replaceFirst (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: 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 unified diff | Download patch | Annotate | Revision Log
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 class StringReplaceTest { 7 class StringReplaceTest {
8 static testMain() { 8 static testMain() {
9 Expect.equals( 9 Expect.equals(
10 "AtoBtoCDtoE", "AfromBtoCDtoE".replaceFirst("from", "to")); 10 "AtoBtoCDtoE", "AfromBtoCDtoE".replaceFirst("from", "to"));
(...skipping 24 matching lines...) Expand all
35 35
36 // Test replacing by the empty string. 36 // Test replacing by the empty string.
37 Expect.equals("", "from".replaceFirst("from", "")); 37 Expect.equals("", "from".replaceFirst("from", ""));
38 Expect.equals("AB", "AfromB".replaceFirst("from", "")); 38 Expect.equals("AB", "AfromB".replaceFirst("from", ""));
39 39
40 // Test changing the empty string. 40 // Test changing the empty string.
41 Expect.equals("to", "".replaceFirst("", "to")); 41 Expect.equals("to", "".replaceFirst("", "to"));
42 42
43 // Test replacing the empty string. 43 // Test replacing the empty string.
44 Expect.equals("toAtoBtoCto", "AtoBtoCto".replaceFirst("", "to")); 44 Expect.equals("toAtoBtoCto", "AtoBtoCto".replaceFirst("", "to"));
45
46 // Test startIndex.
47 Expect.equals(
48 "foo-AAA-foo-bar", "foo-bar-foo-bar".replaceFirst("bar", "AAA", 4));
49
50 // Test startIndex skipping one case at the begining.
51 Expect.equals(
52 "foo-bar-AAA-bar", "foo-bar-foo-bar".replaceFirst("foo", "AAA", 1));
53
54 // Test startIndex skipping one case at the begining.
55 Expect.equals(
56 "foo-bar-foo-AAA", "foo-bar-foo-bar".replaceFirst("bar", "AAA", 5));
57
58 // Test startIndex replacing with the empty string.
59 Expect.equals(
60 "foo-bar--bar", "foo-bar-foo-bar".replaceFirst("foo", "", 1));
61
62 // Test negative startIndex
Bill Hesse 2014/08/11 07:47:47 Add tests for null and object as startIndex.
srawlins 2014/08/14 00:42:45 Done.
63 Expect.throws(
64 () => "hello".replaceFirst("h", "X", -1), (e) => e is RangeError);
65
66 // Test startIndex too large
67 Expect.throws(
68 () => "hello".replaceFirst("h", "X", 6), (e) => e is RangeError);
45 } 69 }
46 } 70 }
Lasse Reichstein Nielsen 2014/08/13 08:35:09 Test with regexps too, and with strings that conta
srawlins 2014/08/14 00:42:45 Done.
47 71
48 main() { 72 main() {
49 StringReplaceTest.testMain(); 73 StringReplaceTest.testMain();
50 } 74 }
OLDNEW
« sdk/lib/_internal/lib/string_helper.dart ('K') | « sdk/lib/core/string.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698