OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 testReplaceAll() { | 7 testReplaceAll() { |
8 Expect.equals("aXXcaXXdae", "abcabdae".replaceAll("b", "XX")); | 8 Expect.equals("aXXcaXXdae", "abcabdae".replaceAll("b", "XX")); |
9 | 9 |
10 // Test with the replaced string at the begining. | 10 // Test with the replaced string at the beginning. |
11 Expect.equals("XXbcXXbdXXe", "abcabdae".replaceAll("a", "XX")); | 11 Expect.equals("XXbcXXbdXXe", "abcabdae".replaceAll("a", "XX")); |
12 | 12 |
13 // Test with the replaced string at the end. | 13 // Test with the replaced string at the end. |
14 Expect.equals("abcabdaXX", "abcabdae".replaceAll("e", "XX")); | 14 Expect.equals("abcabdaXX", "abcabdae".replaceAll("e", "XX")); |
15 | 15 |
16 // Test when there are no occurence of the string to replace. | 16 // Test when there are no occurence of the string to replace. |
17 Expect.equals("abcabdae", "abcabdae".replaceAll("f", "XX")); | 17 Expect.equals("abcabdae", "abcabdae".replaceAll("f", "XX")); |
18 | 18 |
19 // Test when the string to change is the empty string. | 19 // Test when the string to change is the empty string. |
20 Expect.equals("", "".replaceAll("from", "to")); | 20 Expect.equals("", "".replaceAll("from", "to")); |
(...skipping 29 matching lines...) Expand all Loading... |
50 Expect.equals(r"$$", "..".replaceAll(".", r"$")); | 50 Expect.equals(r"$$", "..".replaceAll(".", r"$")); |
51 Expect.equals(r"[$$$$]", "[..]".replaceAll(".", r"$$")); | 51 Expect.equals(r"[$$$$]", "[..]".replaceAll(".", r"$$")); |
52 Expect.equals(r"[$]", "[..]".replaceAll("..", r"$")); | 52 Expect.equals(r"[$]", "[..]".replaceAll("..", r"$")); |
53 Expect.equals(r"$$", r"\\".replaceAll(r"\", r"$")); | 53 Expect.equals(r"$$", r"\\".replaceAll(r"\", r"$")); |
54 } | 54 } |
55 | 55 |
56 testReplaceAllMapped() { | 56 testReplaceAllMapped() { |
57 String mark(Match m) => "[${m[0]}]"; | 57 String mark(Match m) => "[${m[0]}]"; |
58 Expect.equals("a[b]ca[b]dae", "abcabdae".replaceAllMapped("b", mark)); | 58 Expect.equals("a[b]ca[b]dae", "abcabdae".replaceAllMapped("b", mark)); |
59 | 59 |
60 // Test with the replaced string at the begining. | 60 // Test with the replaced string at the beginning. |
61 Expect.equals("[a]bc[a]bd[a]e", "abcabdae".replaceAllMapped("a", mark)); | 61 Expect.equals("[a]bc[a]bd[a]e", "abcabdae".replaceAllMapped("a", mark)); |
62 | 62 |
63 // Test with the replaced string at the end. | 63 // Test with the replaced string at the end. |
64 Expect.equals("abcabda[e]", "abcabdae".replaceAllMapped("e", mark)); | 64 Expect.equals("abcabda[e]", "abcabdae".replaceAllMapped("e", mark)); |
65 | 65 |
66 // Test when there are no occurence of the string to replace. | 66 // Test when there are no occurence of the string to replace. |
67 Expect.equals("abcabdae", "abcabdae".replaceAllMapped("f", mark)); | 67 Expect.equals("abcabdae", "abcabdae".replaceAllMapped("f", mark)); |
68 | 68 |
69 // Test when the string to change is the empty string. | 69 // Test when the string to change is the empty string. |
70 Expect.equals("", "".replaceAllMapped("from", mark)); | 70 Expect.equals("", "".replaceAllMapped("from", mark)); |
(...skipping 16 matching lines...) Expand all Loading... |
87 Expect.equals("[]A[]B[]C[]", "ABC".replaceAllMapped("", mark)); | 87 Expect.equals("[]A[]B[]C[]", "ABC".replaceAllMapped("", mark)); |
88 } | 88 } |
89 | 89 |
90 testSplitMapJoin() { | 90 testSplitMapJoin() { |
91 String mark(Match m) => "[${m[0]}]"; | 91 String mark(Match m) => "[${m[0]}]"; |
92 String wrap(String s) => "<${s}>"; | 92 String wrap(String s) => "<${s}>"; |
93 | 93 |
94 Expect.equals("<a>[b]<ca>[b]<dae>", | 94 Expect.equals("<a>[b]<ca>[b]<dae>", |
95 "abcabdae".splitMapJoin("b", onMatch: mark, onNonMatch: wrap)); | 95 "abcabdae".splitMapJoin("b", onMatch: mark, onNonMatch: wrap)); |
96 | 96 |
97 // Test with the replaced string at the begining. | 97 // Test with the replaced string at the beginning. |
98 Expect.equals("<>[a]<bc>[a]<bd>[a]<e>", | 98 Expect.equals("<>[a]<bc>[a]<bd>[a]<e>", |
99 "abcabdae".splitMapJoin("a", onMatch: mark, onNonMatch: wrap)); | 99 "abcabdae".splitMapJoin("a", onMatch: mark, onNonMatch: wrap)); |
100 | 100 |
101 // Test with the replaced string at the end. | 101 // Test with the replaced string at the end. |
102 Expect.equals("<abcabda>[e]<>", | 102 Expect.equals("<abcabda>[e]<>", |
103 "abcabdae".splitMapJoin("e", onMatch: mark, onNonMatch: wrap)); | 103 "abcabdae".splitMapJoin("e", onMatch: mark, onNonMatch: wrap)); |
104 | 104 |
105 // Test when there are no occurence of the string to replace. | 105 // Test when there are no occurence of the string to replace. |
106 Expect.equals("<abcabdae>", | 106 Expect.equals("<abcabdae>", |
107 "abcabdae".splitMapJoin("f", onMatch: mark, onNonMatch: wrap)); | 107 "abcabdae".splitMapJoin("f", onMatch: mark, onNonMatch: wrap)); |
(...skipping 23 matching lines...) Expand all Loading... |
131 // Test with only onNonMatch | 131 // Test with only onNonMatch |
132 Expect.equals( | 132 Expect.equals( |
133 "<>a<bc>a<bd>a<e>", "abcabdae".splitMapJoin("a", onNonMatch: wrap)); | 133 "<>a<bc>a<bd>a<e>", "abcabdae".splitMapJoin("a", onNonMatch: wrap)); |
134 } | 134 } |
135 | 135 |
136 main() { | 136 main() { |
137 testReplaceAll(); | 137 testReplaceAll(); |
138 testReplaceAllMapped(); | 138 testReplaceAllMapped(); |
139 testSplitMapJoin(); | 139 testSplitMapJoin(); |
140 } | 140 } |
OLD | NEW |