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

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: Little fixes 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
« 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 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 startIndex with a RegExp with carat
63 Expect.equals(
64 "foo-bar-foo-bar",
65 "foo-bar-foo-bar".replaceFirst(new RegExp(r"^foo"), "", 8));
66
67 // Test startIndex with a RegExp
68 Expect.equals(
69 "aaa{3}X{3}", "aaa{3}aaa{3}".replaceFirst(new RegExp(r"a{3}"), "X", 1));
70
71 // Test startIndex with regexp-looking String
72 Expect.equals(
73 "aaa{3}aaX", "aaa{3}aaa{3}".replaceFirst("a{3}", "X", 3));
74
75 // Test negative startIndex
76 Expect.throws(
77 () => "hello".replaceFirst("h", "X", -1), (e) => e is RangeError);
78
79 // Test startIndex too large
80 Expect.throws(
81 () => "hello".replaceFirst("h", "X", 6), (e) => e is RangeError);
82
83 // Test null startIndex
84 Expect.throws(
85 () => "hello".replaceFirst("h", "X", null), (e) => e is ArgumentError);
86
87 // Test object startIndex
88 Expect.throws(
89 () => "hello".replaceFirst("h", "X", new Object()));
45 } 90 }
46 } 91 }
47 92
48 main() { 93 main() {
49 StringReplaceTest.testMain(); 94 StringReplaceTest.testMain();
50 } 95 }
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