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

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

Issue 3005533002: Fix the return type of String.split in DDC to be correct (Closed)
Patch Set: Created 3 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
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 testSplit(List expect, String string, Pattern pattern) { 13 testSplit(List<String> expect, String string, Pattern pattern) {
14 String patternString; 14 String patternString;
15 if (pattern is String) { 15 if (pattern is String) {
16 patternString = '"$pattern"'; 16 patternString = '"$pattern"';
17 } else if (pattern is RegExp) { 17 } else if (pattern is RegExp) {
18 patternString = "/${pattern.pattern}/"; 18 patternString = "/${pattern.pattern}/";
19 } else { 19 } else {
20 patternString = pattern.toString(); 20 patternString = pattern.toString();
21 } 21 }
22 Expect.listEquals( 22 List actual = string.split(pattern);
23 expect, string.split(pattern), '"$string".split($patternString)'); 23
24 // Check that the list is growable/mutable
25 actual
26 ..add('42')
27 ..removeLast();
28
29 // Ensure that the correct type is reified.
30 actual = actual as List<String>;
31 Expect.throws(() {
32 actual.add(42);
33 }, (e) => e is TypeError, 'List<String>.add should not accept an int');
34
35 Expect.listEquals(expect, actual, '"$string".split($patternString)');
24 } 36 }
25 37
26 /** String patterns. */ 38 /** String patterns. */
27 void testSplitString() { 39 void testSplitString() {
28 // Normal match. 40 // Normal match.
29 testSplit(["a", "b", "c"], "a b c", " "); 41 testSplit(["a", "b", "c"], "a b c", " ");
30 testSplit(["a", "b", "c"], "adbdc", "d"); 42 testSplit(["a", "b", "c"], "adbdc", "d");
31 testSplit(["a", "b", "c"], "addbddc", "dd"); 43 testSplit(["a", "b", "c"], "addbddc", "dd");
32 // No match. 44 // No match.
33 testSplit(["abc"], "abc", " "); 45 testSplit(["abc"], "abc", " ");
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 final regexp; 138 final regexp;
127 RegExpWrap(String source) : regexp = new RegExp(source); 139 RegExpWrap(String source) : regexp = new RegExp(source);
128 Iterable<Match> allMatches(String string, [int start = 0]) => 140 Iterable<Match> allMatches(String string, [int start = 0]) =>
129 regexp.allMatches(string, start); 141 regexp.allMatches(string, start);
130 142
131 Match matchAsPrefix(String string, [int start = 0]) => 143 Match matchAsPrefix(String string, [int start = 0]) =>
132 regexp.matchAsPrefix(string, start); 144 regexp.matchAsPrefix(string, start);
133 145
134 String toString() => "Wrap(/${regexp.pattern}/)"; 146 String toString() => "Wrap(/${regexp.pattern}/)";
135 } 147 }
OLDNEW
« tests/corelib_2/corelib_2.status ('K') | « tests/corelib_2/corelib_2.status ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698