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

Side by Side Diff: tests/corelib/src/RegExpAllMatchesTest.dart

Issue 9114021: Added method map to Collection interface and all its implementations (except classes generated fr... (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 11 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 | Annotate | Revision Log
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 // Dart test program for RegExp.allMatches. 5 // Dart test program for RegExp.allMatches.
6 6
7 class RegExpAllMatchesTest { 7 class RegExpAllMatchesTest {
8 static testIterator() { 8 static testIterator() {
9 var matches = new RegExp("foo").allMatches("foo foo"); 9 var matches = new RegExp("foo").allMatches("foo foo");
10 Iterator it = matches.iterator(); 10 Iterator it = matches.iterator();
(...skipping 20 matching lines...) Expand all
31 31
32 static testForEach() { 32 static testForEach() {
33 var matches = new RegExp("foo").allMatches("foo foo"); 33 var matches = new RegExp("foo").allMatches("foo foo");
34 var str = ""; 34 var str = "";
35 matches.forEach((Match m) { 35 matches.forEach((Match m) {
36 str += m.group(0); 36 str += m.group(0);
37 }); 37 });
38 Expect.equals("foofoo", str); 38 Expect.equals("foofoo", str);
39 } 39 }
40 40
41 static testMap() {
42 var matches = new RegExp("foo?").allMatches("foo fo foo fo");
43 var mapped = matches.map((Match m) {
sra1 2012/01/05 22:46:49 nit. could use matches.map((Match m) => m.group(0
44 return m.group(0) + "bar";
45 });
46 Expect.equals(4, mapped.length);
47 var str = "";
48 for (String s in mapped) {
49 str += s;
50 }
51 Expect.equals("foobarfobarfoobarfobar", str);
52 }
53
41 static testFilter() { 54 static testFilter() {
42 var matches = new RegExp("foo?").allMatches("foo fo foo fo"); 55 var matches = new RegExp("foo?").allMatches("foo fo foo fo");
43 var filtered = matches.filter((Match m) { 56 var filtered = matches.filter((Match m) {
44 return m.group(0) == 'foo'; 57 return m.group(0) == 'foo';
45 }); 58 });
46 Expect.equals(2, filtered.length); 59 Expect.equals(2, filtered.length);
47 var str = ""; 60 var str = "";
48 for (Match m in filtered) { 61 for (Match m in filtered) {
49 str += m.group(0); 62 str += m.group(0);
50 } 63 }
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 static testGetCount() { 97 static testGetCount() {
85 var matches = new RegExp("foo?").allMatches("foo fo foo fo"); 98 var matches = new RegExp("foo?").allMatches("foo fo foo fo");
86 Expect.equals(4, matches.length); 99 Expect.equals(4, matches.length);
87 matches = new RegExp("fooo").allMatches("foo fo foo fo"); 100 matches = new RegExp("fooo").allMatches("foo fo foo fo");
88 Expect.equals(0, matches.length); 101 Expect.equals(0, matches.length);
89 } 102 }
90 103
91 static testMain() { 104 static testMain() {
92 testIterator(); 105 testIterator();
93 testForEach(); 106 testForEach();
107 testMap();
94 testFilter(); 108 testFilter();
95 testEvery(); 109 testEvery();
96 testSome(); 110 testSome();
97 testIsEmpty(); 111 testIsEmpty();
98 testGetCount(); 112 testGetCount();
99 } 113 }
100 } 114 }
101 115
102 main() { 116 main() {
103 RegExpAllMatchesTest.testMain(); 117 RegExpAllMatchesTest.testMain();
104 } 118 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698