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

Side by Side Diff: sdk/lib/_internal/pub/test/error_group_test.dart

Issue 14753009: Make StreamSubscription be the active part of a stream. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address comments. Created 7 years, 6 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 | « sdk/lib/_internal/pub/lib/src/error_group.dart ('k') | sdk/lib/async/stream.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) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, 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 error_group_test; 5 library error_group_test;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 8
9 import 'package:unittest/unittest.dart'; 9 import 'package:unittest/unittest.dart';
10 10
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
203 StreamController controller; 203 StreamController controller;
204 Stream stream; 204 Stream stream;
205 205
206 setUp(() { 206 setUp(() {
207 errorGroup = new ErrorGroup(); 207 errorGroup = new ErrorGroup();
208 controller = new StreamController(); 208 controller = new StreamController();
209 stream = errorGroup.registerStream(controller.stream.asBroadcastStream()); 209 stream = errorGroup.registerStream(controller.stream.asBroadcastStream());
210 }); 210 });
211 211
212 test('should pass through values from the stream', () { 212 test('should pass through values from the stream', () {
213 expect(stream.elementAt(0), completion(equals(1))); 213 StreamIterator iter = new StreamIterator(stream);
214 expect(stream.elementAt(1), completion(equals(2))); 214 iter.moveNext().then((hasNext) {
215 expect(hasNext, isTrue);
216 expect(iter.current, equals(1));
217 iter.moveNext().then((hasNext) {
218 expect(hasNext, isTrue);
219 expect(iter.current, equals(2));
220 expect(iter.moveNext(), completion(isFalse));
221 });
222 });
215 expect(errorGroup.done, completes); 223 expect(errorGroup.done, completes);
216 224
217 controller..add(1)..add(2)..close(); 225 controller..add(1)..add(2)..close();
218 }); 226 });
219 227
220 test('should pass through an error from the stream if it has a ' 228 test('should pass through an error from the stream if it has a '
221 'listener', () { 229 'listener', () {
222 expect(stream.first, throwsFormatException); 230 expect(stream.first, throwsFormatException);
223 // errorGroup shouldn't top-level the exception 231 // errorGroup shouldn't top-level the exception
224 controller.addError(new FormatException()); 232 controller.addError(new FormatException());
225 }); 233 });
226 234
227 test('should notify the error group of an exception from the stream even ' 235 test('should notify the error group of an exception from the stream even '
228 'if it has a listener', () { 236 'if it has a listener', () {
229 expect(stream.first, throwsFormatException); 237 expect(stream.first, throwsFormatException);
230 expect(errorGroup.done, throwsFormatException); 238 expect(errorGroup.done, throwsFormatException);
231 controller.addError(new FormatException()); 239 controller.addError(new FormatException());
232 }); 240 });
233 241
234 test('should pass a signaled exception to the stream if it has a listener ' 242 test('should pass a signaled exception to the stream if it has a listener '
235 'and should unsubscribe that stream', () { 243 'and should unsubscribe that stream', () {
244 // errorGroup shouldn't top-level the exception
236 expect(stream.first, throwsFormatException); 245 expect(stream.first, throwsFormatException);
237 // errorGroup shouldn't top-level the exception
238 errorGroup.signalError(new FormatException()); 246 errorGroup.signalError(new FormatException());
239 247
240 expect(stream.first.catchError((_) { 248 expect(new Future(() {
241 controller.add('value'); 249 controller.add('value');
242 return stream.isEmpty; 250 }), completes);
243 }), completion(isTrue));
244 }); 251 });
245 252
246 test('should notify the error group of a signaled exception even if the ' 253 test('should notify the error group of a signaled exception even if the '
247 'stream has a listener', () { 254 'stream has a listener', () {
248 expect(stream.first, throwsFormatException); 255 expect(stream.first, throwsFormatException);
249 expect(errorGroup.done, throwsFormatException); 256 expect(errorGroup.done, throwsFormatException);
250 errorGroup.signalError(new FormatException()); 257 errorGroup.signalError(new FormatException());
251 }); 258 });
252 259
253 test("should see one value and complete .done when the stream is done even " 260 test("should see one value and complete .done when the stream is done even "
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
338 expect(stream1.toList(), completion(equals(['value1.1', 'value1.2']))); 345 expect(stream1.toList(), completion(equals(['value1.1', 'value1.2'])));
339 expect(stream2.toList(), completion(equals(['value2.1', 'value2.2']))); 346 expect(stream2.toList(), completion(equals(['value2.1', 'value2.2'])));
340 expect(errorGroup.done, completes); 347 expect(errorGroup.done, completes);
341 348
342 controller1..add('value1.1')..add('value1.2')..close(); 349 controller1..add('value1.1')..add('value1.2')..close();
343 controller2..add('value2.1')..add('value2.2')..close(); 350 controller2..add('value2.1')..add('value2.2')..close();
344 }); 351 });
345 352
346 test("shouldn't throw a top-level exception if a stream receives an error " 353 test("shouldn't throw a top-level exception if a stream receives an error "
347 "after the other listened stream completes", () { 354 "after the other listened stream completes", () {
348 expect(stream1.toList(), completion(equals(['value1', 'value2']))); 355 var signal = new Completer();
356 expect(stream1.toList().whenComplete(signal.complete),
357 completion(equals(['value1', 'value2'])));
349 controller1..add('value1')..add('value2')..close(); 358 controller1..add('value1')..add('value2')..close();
350 359
351 expect(stream1.toList().then((_) { 360 expect(signal.future.then((_) {
352 // shouldn't cause a top-level exception 361 // shouldn't cause a top-level exception
353 controller2.addError(new FormatException()); 362 controller2.addError(new FormatException());
354 }), completes); 363 }), completes);
355 }); 364 });
356 365
357 test("shouldn't throw a top-level exception if an error is signaled after " 366 test("shouldn't throw a top-level exception if an error is signaled after "
358 "one listened stream completes", () { 367 "one listened stream completes", () {
359 expect(stream1.toList(), completion(equals(['value1', 'value2']))); 368 var signal = new Completer();
369 expect(stream1.toList().whenComplete(signal.complete),
370 completion(equals(['value1', 'value2'])));
360 controller1..add('value1')..add('value2')..close(); 371 controller1..add('value1')..add('value2')..close();
361 372
362 expect(stream1.toList().then((_) { 373 expect(signal.future.then((_) {
363 // shouldn't cause a top-level exception 374 // shouldn't cause a top-level exception
364 errorGroup.signalError(new FormatException()); 375 errorGroup.signalError(new FormatException());
365 }), completes); 376 }), completes);
366 }); 377 });
367 }); 378 });
368 379
369 group('with a stream and a future', () { 380 group('with a stream and a future', () {
370 StreamController controller; 381 StreamController controller;
371 Stream stream; 382 Stream stream;
372 Completer completer; 383 Completer completer;
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
412 completer.complete('value'); 423 completer.complete('value');
413 424
414 expect(future.then((_) { 425 expect(future.then((_) {
415 // shouldn't cause a top-level exception 426 // shouldn't cause a top-level exception
416 controller.addError(new FormatException()); 427 controller.addError(new FormatException());
417 }), completes); 428 }), completes);
418 }); 429 });
419 430
420 test("shouldn't throw a top-level exception if the future receives an " 431 test("shouldn't throw a top-level exception if the future receives an "
421 "error after the listened stream completes", () { 432 "error after the listened stream completes", () {
422 expect(stream.toList(), completion(equals(['value1', 'value2']))); 433 var signal = new Completer();
434 expect(stream.toList().whenComplete(signal.complete),
435 completion(equals(['value1', 'value2'])));
423 controller..add('value1')..add('value2')..close(); 436 controller..add('value1')..add('value2')..close();
424 437
425 expect(stream.toList().then((_) { 438 expect(signal.future.then((_) {
426 // shouldn't cause a top-level exception 439 // shouldn't cause a top-level exception
427 completer.completeError(new FormatException()); 440 completer.completeError(new FormatException());
428 }), completes); 441 }), completes);
429 }); 442 });
430 }); 443 });
431 } 444 }
OLDNEW
« no previous file with comments | « sdk/lib/_internal/pub/lib/src/error_group.dart ('k') | sdk/lib/async/stream.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698