OLD | NEW |
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, 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 "dart:async"; | 5 import "dart:async"; |
6 | 6 |
7 import "package:async/async.dart"; | 7 import "package:async/async.dart"; |
8 import "package:test/test.dart"; | 8 import "package:test/test.dart"; |
9 | 9 |
10 import "utils.dart"; | 10 import "utils.dart"; |
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
238 () async { | 238 () async { |
239 expect(completer.sink.done, completes); | 239 expect(completer.sink.done, completes); |
240 await flushMicrotasks(); | 240 await flushMicrotasks(); |
241 | 241 |
242 completer.setDestinationSink(new TestSink()); | 242 completer.setDestinationSink(new TestSink()); |
243 await flushMicrotasks(); | 243 await flushMicrotasks(); |
244 | 244 |
245 expect(completer.sink.close(), completes); | 245 expect(completer.sink.close(), completes); |
246 }); | 246 }); |
247 | 247 |
| 248 group("fromFuture()", () { |
| 249 test("with a successful completion", () async { |
| 250 var futureCompleter = new Completer(); |
| 251 var sink = StreamSinkCompleter.fromFuture(futureCompleter.future); |
| 252 sink.add(1); |
| 253 sink.add(2); |
| 254 sink.add(3); |
| 255 sink.close(); |
| 256 |
| 257 var testSink = new TestSink(); |
| 258 futureCompleter.complete(testSink); |
| 259 await testSink.done; |
| 260 |
| 261 expect(testSink.results[0].asValue.value, equals(1)); |
| 262 expect(testSink.results[1].asValue.value, equals(2)); |
| 263 expect(testSink.results[2].asValue.value, equals(3)); |
| 264 }); |
| 265 |
| 266 test("with an error", () async { |
| 267 var futureCompleter = new Completer(); |
| 268 var sink = StreamSinkCompleter.fromFuture(futureCompleter.future); |
| 269 expect(sink.done, throwsA("oh no")); |
| 270 futureCompleter.completeError("oh no"); |
| 271 }); |
| 272 }); |
| 273 |
| 274 group("setError()", () { |
| 275 test("produces a closed sink with the error", () { |
| 276 completer.setError("oh no"); |
| 277 expect(completer.sink.done, throwsA("oh no")); |
| 278 expect(completer.sink.close(), throwsA("oh no")); |
| 279 }); |
| 280 |
| 281 test("produces an error even if done was accessed earlier", () async { |
| 282 expect(completer.sink.done, throwsA("oh no")); |
| 283 expect(completer.sink.close(), throwsA("oh no")); |
| 284 await flushMicrotasks(); |
| 285 |
| 286 completer.setError("oh no"); |
| 287 }); |
| 288 }); |
| 289 |
248 test("doesn't allow the destination sink to be set multiple times", () { | 290 test("doesn't allow the destination sink to be set multiple times", () { |
249 completer.setDestinationSink(new TestSink()); | 291 completer.setDestinationSink(new TestSink()); |
250 expect(() => completer.setDestinationSink(new TestSink()), | 292 expect(() => completer.setDestinationSink(new TestSink()), |
251 throwsStateError); | 293 throwsStateError); |
252 expect(() => completer.setDestinationSink(new TestSink()), | 294 expect(() => completer.setDestinationSink(new TestSink()), |
253 throwsStateError); | 295 throwsStateError); |
254 }); | 296 }); |
255 } | 297 } |
OLD | NEW |