OLD | NEW |
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 18 matching lines...) Expand all Loading... |
29 test('should pass signaled errors to .done', () { | 29 test('should pass signaled errors to .done', () { |
30 expect(errorGroup.done, throwsFormatException); | 30 expect(errorGroup.done, throwsFormatException); |
31 errorGroup.signalError(new FormatException()); | 31 errorGroup.signalError(new FormatException()); |
32 }); | 32 }); |
33 | 33 |
34 test("shouldn't allow additional futures or streams once an error has been " | 34 test("shouldn't allow additional futures or streams once an error has been " |
35 "signaled", () { | 35 "signaled", () { |
36 expect(errorGroup.done, throwsFormatException); | 36 expect(errorGroup.done, throwsFormatException); |
37 errorGroup.signalError(new FormatException()); | 37 errorGroup.signalError(new FormatException()); |
38 | 38 |
39 expect(() => errorGroup.registerFuture(new Future.immediate(null)), | 39 expect(() => errorGroup.registerFuture(new Future.value()), |
40 throwsStateError); | 40 throwsStateError); |
41 expect(() => errorGroup.registerStream(new StreamController().stream), | 41 expect(() => errorGroup.registerStream(new StreamController().stream), |
42 throwsStateError); | 42 throwsStateError); |
43 }); | 43 }); |
44 }); | 44 }); |
45 | 45 |
46 group('with a single future', () { | 46 group('with a single future', () { |
47 Completer completer; | 47 Completer completer; |
48 Future future; | 48 Future future; |
49 | 49 |
50 setUp(() { | 50 setUp(() { |
51 errorGroup = new ErrorGroup(); | 51 errorGroup = new ErrorGroup(); |
52 completer = new Completer(); | 52 completer = new Completer(); |
53 future = errorGroup.registerFuture(completer.future); | 53 future = errorGroup.registerFuture(completer.future); |
54 }); | 54 }); |
55 | 55 |
56 test('should pass through a value from the future', () { | 56 test('should pass through a value from the future', () { |
57 expect(future, completion(equals('value'))); | 57 expect(future, completion(equals('value'))); |
58 expect(errorGroup.done, completes); | 58 expect(errorGroup.done, completes); |
59 completer.complete('value'); | 59 completer.complete('value'); |
60 }); | 60 }); |
61 | 61 |
62 test("shouldn't allow additional futures or streams once .done has " | 62 test("shouldn't allow additional futures or streams once .done has " |
63 "been called", () { | 63 "been called", () { |
64 completer.complete('value'); | 64 completer.complete('value'); |
65 | 65 |
66 expect(() => errorGroup.registerFuture(new Future.immediate(null)), | 66 expect(() => errorGroup.registerFuture(new Future.value()), |
67 throwsStateError); | 67 throwsStateError); |
68 expect(() => errorGroup.registerStream(new StreamController().stream), | 68 expect(() => errorGroup.registerStream(new StreamController().stream), |
69 throwsStateError); | 69 throwsStateError); |
70 }); | 70 }); |
71 | 71 |
72 test('should pass through an exception from the future if it has a ' | 72 test('should pass through an exception from the future if it has a ' |
73 'listener', () { | 73 'listener', () { |
74 expect(future, throwsFormatException); | 74 expect(future, throwsFormatException); |
75 // errorGroup shouldn't top-level the exception | 75 // errorGroup shouldn't top-level the exception |
76 completer.completeError(new FormatException()); | 76 completer.completeError(new FormatException()); |
(...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
420 expect(stream.toList(), completion(equals(['value1', 'value2']))); | 420 expect(stream.toList(), completion(equals(['value1', 'value2']))); |
421 controller..add('value1')..add('value2')..close(); | 421 controller..add('value1')..add('value2')..close(); |
422 | 422 |
423 expect(stream.toList().then((_) { | 423 expect(stream.toList().then((_) { |
424 // shouldn't cause a top-level exception | 424 // shouldn't cause a top-level exception |
425 completer.completeError(new FormatException()); | 425 completer.completeError(new FormatException()); |
426 }), completes); | 426 }), completes); |
427 }); | 427 }); |
428 }); | 428 }); |
429 } | 429 } |
OLD | NEW |