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

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

Issue 2771453003: Format all tests. (Closed)
Patch Set: Format files 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 testSplitString(); 8 testSplitString();
9 testSplitRegExp(); 9 testSplitRegExp();
10 testSplitPattern(); 10 testSplitPattern();
11 } 11 }
12 12
13
14 testSplit(List expect, String string, Pattern pattern) { 13 testSplit(List expect, String string, Pattern pattern) {
15 String patternString; 14 String patternString;
16 if (pattern is String) { 15 if (pattern is String) {
17 patternString = '"$pattern"'; 16 patternString = '"$pattern"';
18 } else if (pattern is RegExp) { 17 } else if (pattern is RegExp) {
19 patternString = "/${pattern.pattern}/"; 18 patternString = "/${pattern.pattern}/";
20 } else { 19 } else {
21 patternString = pattern.toString(); 20 patternString = pattern.toString();
22 } 21 }
23 Expect.listEquals(expect, string.split(pattern), 22 Expect.listEquals(
24 '"$string".split($patternString)'); 23 expect, string.split(pattern), '"$string".split($patternString)');
25 } 24 }
26 25
27 /** String patterns. */ 26 /** String patterns. */
28 void testSplitString() { 27 void testSplitString() {
29 // Normal match. 28 // Normal match.
30 testSplit(["a", "b", "c"], "a b c", " "); 29 testSplit(["a", "b", "c"], "a b c", " ");
31 testSplit(["a", "b", "c"], "adbdc", "d"); 30 testSplit(["a", "b", "c"], "adbdc", "d");
32 testSplit(["a", "b", "c"], "addbddc", "dd"); 31 testSplit(["a", "b", "c"], "addbddc", "dd");
33 // No match. 32 // No match.
34 testSplit(["abc"], "abc", " "); 33 testSplit(["abc"], "abc", " ");
35 testSplit(["a"], "a", "b"); 34 testSplit(["a"], "a", "b");
36 testSplit([""], "", "b"); 35 testSplit([""], "", "b");
37 // Empty match matches everywhere except start/end. 36 // Empty match matches everywhere except start/end.
38 testSplit(["a", "b", "c"], "abc", ""); 37 testSplit(["a", "b", "c"], "abc", "");
39 // All empty parts. 38 // All empty parts.
40 testSplit(["", "", "", "", ""], "aaaa", "a"); 39 testSplit(["", "", "", "", ""], "aaaa", "a");
41 testSplit(["", "", "", "", ""], " ", " "); 40 testSplit(["", "", "", "", ""], " ", " ");
42 testSplit(["", ""], "a", "a"); 41 testSplit(["", ""], "a", "a");
43 // No overlapping matches. Match as early as possible. 42 // No overlapping matches. Match as early as possible.
44 testSplit(["", "", "", "a"], "aaaaaaa", "aa"); 43 testSplit(["", "", "", "a"], "aaaaaaa", "aa");
45 // Cannot split the empty string. 44 // Cannot split the empty string.
46 testSplit([], "", ""); // Match. 45 testSplit([], "", ""); // Match.
47 testSplit([""], "", "a"); // No match. 46 testSplit([""], "", "a"); // No match.
48 } 47 }
49 48
50 /** RegExp patterns. */ 49 /** RegExp patterns. */
51 void testSplitRegExp() { 50 void testSplitRegExp() {
52 testSplitWithRegExp((s) => new RegExp(s)); 51 testSplitWithRegExp((s) => new RegExp(s));
53 } 52 }
54 53
55 /** Non-String, non-RegExp patterns. */ 54 /** Non-String, non-RegExp patterns. */
56 void testSplitPattern() { 55 void testSplitPattern() {
57 testSplitWithRegExp((s) => new RegExpWrap(s)); 56 testSplitWithRegExp((s) => new RegExpWrap(s));
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
127 final regexp; 126 final regexp;
128 RegExpWrap(String source) : regexp = new RegExp(source); 127 RegExpWrap(String source) : regexp = new RegExp(source);
129 Iterable<Match> allMatches(String string, [int start = 0]) => 128 Iterable<Match> allMatches(String string, [int start = 0]) =>
130 regexp.allMatches(string, start); 129 regexp.allMatches(string, start);
131 130
132 Match matchAsPrefix(String string, [int start = 0]) => 131 Match matchAsPrefix(String string, [int start = 0]) =>
133 regexp.matchAsPrefix(string, start); 132 regexp.matchAsPrefix(string, start);
134 133
135 String toString() => "Wrap(/${regexp.pattern}/)"; 134 String toString() => "Wrap(/${regexp.pattern}/)";
136 } 135 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698