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

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

Issue 2833073002: Stoppp using trippple consonants (Closed)
Patch Set: More spolling Created 3 years, 8 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
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("AtoBtoCDtoE", "AfromBtoCDtoE".replaceFirst("from", "to")); 9 Expect.equals("AtoBtoCDtoE", "AfromBtoCDtoE".replaceFirst("from", "to"));
10 10
11 // Test with the replaced string at the begining. 11 // Test with the replaced string at the beginning.
12 Expect.equals("toABtoCDtoE", "fromABtoCDtoE".replaceFirst("from", "to")); 12 Expect.equals("toABtoCDtoE", "fromABtoCDtoE".replaceFirst("from", "to"));
13 13
14 // Test with the replaced string at the end. 14 // Test with the replaced string at the end.
15 Expect.equals("toABtoCDtoEto", "fromABtoCDtoEto".replaceFirst("from", "to")); 15 Expect.equals("toABtoCDtoEto", "fromABtoCDtoEto".replaceFirst("from", "to"));
16 16
17 // Test when there are no occurence of the string to replace. 17 // Test when there are no occurence of the string to replace.
18 Expect.equals("ABC", "ABC".replaceFirst("from", "to")); 18 Expect.equals("ABC", "ABC".replaceFirst("from", "to"));
19 19
20 // Test when the string to change is the empty string. 20 // Test when the string to change is the empty string.
21 Expect.equals("", "".replaceFirst("from", "to")); 21 Expect.equals("", "".replaceFirst("from", "to"));
(...skipping 15 matching lines...) Expand all
37 // Test changing the empty string. 37 // Test changing the empty string.
38 Expect.equals("to", "".replaceFirst("", "to")); 38 Expect.equals("to", "".replaceFirst("", "to"));
39 39
40 // Test replacing the empty string. 40 // Test replacing the empty string.
41 Expect.equals("toAtoBtoCto", "AtoBtoCto".replaceFirst("", "to")); 41 Expect.equals("toAtoBtoCto", "AtoBtoCto".replaceFirst("", "to"));
42 42
43 // Test startIndex. 43 // Test startIndex.
44 Expect.equals( 44 Expect.equals(
45 "foo-AAA-foo-bar", "foo-bar-foo-bar".replaceFirst("bar", "AAA", 4)); 45 "foo-AAA-foo-bar", "foo-bar-foo-bar".replaceFirst("bar", "AAA", 4));
46 46
47 // Test startIndex skipping one case at the begining. 47 // Test startIndex skipping one case at the beginning.
48 Expect.equals( 48 Expect.equals(
49 "foo-bar-AAA-bar", "foo-bar-foo-bar".replaceFirst("foo", "AAA", 1)); 49 "foo-bar-AAA-bar", "foo-bar-foo-bar".replaceFirst("foo", "AAA", 1));
50 50
51 // Test startIndex skipping one case at the begining. 51 // Test startIndex skipping one case at the beginning.
52 Expect.equals( 52 Expect.equals(
53 "foo-bar-foo-AAA", "foo-bar-foo-bar".replaceFirst("bar", "AAA", 5)); 53 "foo-bar-foo-AAA", "foo-bar-foo-bar".replaceFirst("bar", "AAA", 5));
54 54
55 // Test startIndex replacing with the empty string. 55 // Test startIndex replacing with the empty string.
56 Expect.equals("foo-bar--bar", "foo-bar-foo-bar".replaceFirst("foo", "", 1)); 56 Expect.equals("foo-bar--bar", "foo-bar-foo-bar".replaceFirst("foo", "", 1));
57 57
58 // Test startIndex with a RegExp with carat 58 // Test startIndex with a RegExp with carat
59 Expect.equals("foo-bar-foo-bar", 59 Expect.equals("foo-bar-foo-bar",
60 "foo-bar-foo-bar".replaceFirst(new RegExp(r"^foo"), "", 8)); 60 "foo-bar-foo-bar".replaceFirst(new RegExp(r"^foo"), "", 8));
61 61
(...skipping 17 matching lines...) Expand all
79 () => "hello".replaceFirst("h", "X", null), (e) => e is ArgumentError); 79 () => "hello".replaceFirst("h", "X", null), (e) => e is ArgumentError);
80 80
81 // Test object startIndex 81 // Test object startIndex
82 Expect.throws(() => "hello".replaceFirst("h", "X", new Object())); 82 Expect.throws(() => "hello".replaceFirst("h", "X", new Object()));
83 83
84 // Test replaceFirstMapped. 84 // Test replaceFirstMapped.
85 85
86 Expect.equals( 86 Expect.equals(
87 "AtoBtoCDtoE", "AfromBtoCDtoE".replaceFirstMapped("from", (_) => "to")); 87 "AtoBtoCDtoE", "AfromBtoCDtoE".replaceFirstMapped("from", (_) => "to"));
88 88
89 // Test with the replaced string at the begining. 89 // Test with the replaced string at the beginning.
90 Expect.equals( 90 Expect.equals(
91 "toABtoCDtoE", "fromABtoCDtoE".replaceFirstMapped("from", (_) => "to")); 91 "toABtoCDtoE", "fromABtoCDtoE".replaceFirstMapped("from", (_) => "to"));
92 92
93 // Test with the replaced string at the end. 93 // Test with the replaced string at the end.
94 Expect.equals("toABtoCDtoEto", 94 Expect.equals("toABtoCDtoEto",
95 "fromABtoCDtoEto".replaceFirstMapped("from", (_) => "to")); 95 "fromABtoCDtoEto".replaceFirstMapped("from", (_) => "to"));
96 96
97 // Test when there are no occurence of the string to replace. 97 // Test when there are no occurence of the string to replace.
98 Expect.equals("ABC", "ABC".replaceFirstMapped("from", (_) => "to")); 98 Expect.equals("ABC", "ABC".replaceFirstMapped("from", (_) => "to"));
99 99
(...skipping 17 matching lines...) Expand all
117 // Test changing the empty string. 117 // Test changing the empty string.
118 Expect.equals("to", "".replaceFirstMapped("", (_) => "to")); 118 Expect.equals("to", "".replaceFirstMapped("", (_) => "to"));
119 119
120 // Test replacing the empty string. 120 // Test replacing the empty string.
121 Expect.equals("toAtoBtoCto", "AtoBtoCto".replaceFirstMapped("", (_) => "to")); 121 Expect.equals("toAtoBtoCto", "AtoBtoCto".replaceFirstMapped("", (_) => "to"));
122 122
123 // Test startIndex. 123 // Test startIndex.
124 Expect.equals("foo-AAA-foo-bar", 124 Expect.equals("foo-AAA-foo-bar",
125 "foo-bar-foo-bar".replaceFirstMapped("bar", (_) => "AAA", 4)); 125 "foo-bar-foo-bar".replaceFirstMapped("bar", (_) => "AAA", 4));
126 126
127 // Test startIndex skipping one case at the begining. 127 // Test startIndex skipping one case at the beginning.
128 Expect.equals("foo-bar-AAA-bar", 128 Expect.equals("foo-bar-AAA-bar",
129 "foo-bar-foo-bar".replaceFirstMapped("foo", (_) => "AAA", 1)); 129 "foo-bar-foo-bar".replaceFirstMapped("foo", (_) => "AAA", 1));
130 130
131 // Test startIndex skipping one case at the begining. 131 // Test startIndex skipping one case at the beginning.
132 Expect.equals("foo-bar-foo-AAA", 132 Expect.equals("foo-bar-foo-AAA",
133 "foo-bar-foo-bar".replaceFirstMapped("bar", (_) => "AAA", 5)); 133 "foo-bar-foo-bar".replaceFirstMapped("bar", (_) => "AAA", 5));
134 134
135 // Test startIndex replacing with the empty string. 135 // Test startIndex replacing with the empty string.
136 Expect.equals("foo-bar--bar", 136 Expect.equals("foo-bar--bar",
137 "foo-bar-foo-bar".replaceFirstMapped("foo", (_) => "", 1)); 137 "foo-bar-foo-bar".replaceFirstMapped("foo", (_) => "", 1));
138 138
139 // Test startIndex with a RegExp with carat 139 // Test startIndex with a RegExp with carat
140 Expect.equals("foo-bar-foo-bar", 140 Expect.equals("foo-bar-foo-bar",
141 "foo-bar-foo-bar".replaceFirstMapped(new RegExp(r"^foo"), (_) => "", 8)); 141 "foo-bar-foo-bar".replaceFirstMapped(new RegExp(r"^foo"), (_) => "", 8));
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
218 Expect.throws(() => string.replaceRange(0, 0, ["x"])); 218 Expect.throws(() => string.replaceRange(0, 0, ["x"]));
219 Expect.throws(() => string.replaceRange(-1, 0, "x")); 219 Expect.throws(() => string.replaceRange(-1, 0, "x"));
220 Expect.throws(() => string.replaceRange(0, string.length + 1, "x")); 220 Expect.throws(() => string.replaceRange(0, string.length + 1, "x"));
221 } 221 }
222 } 222 }
223 223
224 // Fails to return a String on toString, throws if converted by "$naughty". 224 // Fails to return a String on toString, throws if converted by "$naughty".
225 class Naughty { 225 class Naughty {
226 toString() => this; 226 toString() => this;
227 } 227 }
OLDNEW
« no previous file with comments | « tests/corelib_strong/string_replace_all_test.dart ('k') | tests/corelib_strong/string_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698