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

Side by Side Diff: tests/lib/async/futures_test.dart

Issue 14070010: Refactor Future constructors. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Added co19 issue number. Created 7 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 | Annotate | Revision Log
« no previous file with comments | « tests/lib/async/future_test.dart ('k') | tests/lib/async/slow_consumer2_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 library futures_test; 5 library futures_test;
6 import "package:expect/expect.dart"; 6 import "package:expect/expect.dart";
7 import 'dart:async'; 7 import 'dart:async';
8 import 'dart:isolate'; 8 import 'dart:isolate';
9 9
10 Future testWaitEmpty() { 10 Future testWaitEmpty() {
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 Future testForEachEmpty() { 77 Future testForEachEmpty() {
78 return Future.forEach([], (_) { 78 return Future.forEach([], (_) {
79 throw 'should not be called'; 79 throw 'should not be called';
80 }); 80 });
81 } 81 }
82 82
83 Future testForEach() { 83 Future testForEach() {
84 var seen = <int>[]; 84 var seen = <int>[];
85 return Future.forEach([1, 2, 3, 4, 5], (n) { 85 return Future.forEach([1, 2, 3, 4, 5], (n) {
86 seen.add(n); 86 seen.add(n);
87 return new Future.immediate(null); 87 return new Future.value();
88 }).then((_) => Expect.listEquals([1, 2, 3, 4, 5], seen)); 88 }).then((_) => Expect.listEquals([1, 2, 3, 4, 5], seen));
89 } 89 }
90 90
91 Future testForEachWithException() { 91 Future testForEachWithException() {
92 var seen = <int>[]; 92 var seen = <int>[];
93 return Future.forEach([1, 2, 3, 4, 5], (n) { 93 return Future.forEach([1, 2, 3, 4, 5], (n) {
94 if (n == 4) throw 'correct exception'; 94 if (n == 4) throw 'correct exception';
95 seen.add(n); 95 seen.add(n);
96 return new Future.immediate(null); 96 return new Future.value();
97 }).then((_) { 97 }).then((_) {
98 throw 'incorrect exception'; 98 throw 'incorrect exception';
99 }).catchError((error) { 99 }).catchError((error) {
100 Expect.equals('correct exception', error); 100 Expect.equals('correct exception', error);
101 }); 101 });
102 } 102 }
103 103
104 main() { 104 main() {
105 List<Future> futures = new List<Future>(); 105 List<Future> futures = new List<Future>();
106 106
107 futures.add(testWaitEmpty()); 107 futures.add(testWaitEmpty());
108 futures.add(testCompleteAfterWait()); 108 futures.add(testCompleteAfterWait());
109 futures.add(testCompleteBeforeWait()); 109 futures.add(testCompleteBeforeWait());
110 futures.add(testWaitWithMultipleValues()); 110 futures.add(testWaitWithMultipleValues());
111 futures.add(testWaitWithSingleError()); 111 futures.add(testWaitWithSingleError());
112 futures.add(testWaitWithMultipleErrors()); 112 futures.add(testWaitWithMultipleErrors());
113 futures.add(testForEachEmpty()); 113 futures.add(testForEachEmpty());
114 futures.add(testForEach()); 114 futures.add(testForEach());
115 futures.add(testForEachWithException()); 115 futures.add(testForEachWithException());
116 116
117 // Use a receive port for blocking the test. 117 // Use a receive port for blocking the test.
118 // Note that if the test fails, the program will not end. 118 // Note that if the test fails, the program will not end.
119 ReceivePort port = new ReceivePort(); 119 ReceivePort port = new ReceivePort();
120 Future.wait(futures).then((List list) { 120 Future.wait(futures).then((List list) {
121 Expect.equals(9, list.length); 121 Expect.equals(9, list.length);
122 port.close(); 122 port.close();
123 }); 123 });
124 } 124 }
OLDNEW
« no previous file with comments | « tests/lib/async/future_test.dart ('k') | tests/lib/async/slow_consumer2_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698