OLD | NEW |
| (Empty) |
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 | |
3 // BSD-style license that can be found in the LICENSE file. | |
4 | |
5 class StringReplaceTest { | |
6 static testMain() { | |
7 Expect.equals( | |
8 "AtoBtoCDtoE", "AfromBtoCDtoE".replaceFirst("from", "to")); | |
9 | |
10 // Test with the replaced string at the begining. | |
11 Expect.equals( | |
12 "toABtoCDtoE", "fromABtoCDtoE".replaceFirst("from", "to")); | |
13 | |
14 // Test with the replaced string at the end. | |
15 Expect.equals( | |
16 "toABtoCDtoEto", "fromABtoCDtoEto".replaceFirst("from", "to")); | |
17 | |
18 // Test when there are no occurence of the string to replace. | |
19 Expect.equals("ABC", "ABC".replaceFirst("from", "to")); | |
20 | |
21 // Test when the string to change is the empty string. | |
22 Expect.equals("", "".replaceFirst("from", "to")); | |
23 | |
24 // Test when the string to change is a substring of the string to | |
25 // replace. | |
26 Expect.equals("fro", "fro".replaceFirst("from", "to")); | |
27 | |
28 // Test when the string to change is the replaced string. | |
29 Expect.equals("to", "from".replaceFirst("from", "to")); | |
30 | |
31 // Test when the string to change is the replacement string. | |
32 Expect.equals("to", "to".replaceFirst("from", "to")); | |
33 | |
34 // Test replacing by the empty string. | |
35 Expect.equals("", "from".replaceFirst("from", "")); | |
36 Expect.equals("AB", "AfromB".replaceFirst("from", "")); | |
37 | |
38 // Test changing the empty string. | |
39 Expect.equals("to", "".replaceFirst("", "to")); | |
40 | |
41 // Test replacing the empty string. | |
42 Expect.equals("toAtoBtoCto", "AtoBtoCto".replaceFirst("", "to")); | |
43 } | |
44 } | |
45 | |
46 main() { | |
47 StringReplaceTest.testMain(); | |
48 } | |
OLD | NEW |