blob: a584effd3a383d439ddcb1200b61e441c24f466a [file] [log] [blame]
// Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
/// @assertion abstract Future addStream(Stream<S> stream)
/// Consumes the elements of stream.
/// Listens on stream and does something for each event.
/// The consumer may stop listening after an error, or it may consume all the
/// errors and only stop at a done event.
/// @description Checks that addStream() can be followed by add(), addError()
/// or close() when future is completed.
/// @author ilya
import "dart:async";
import "../../../Utils/expect.dart";
listen(stream, expectedData, expectedErrors) {
var actualData = [];
var actualErrors = [];
asyncStart();
stream.listen((x) {
actualData.add(x);
}, onError: (x) {
actualErrors.add(x);
}, onDone: () {
Expect.listEquals(expectedData, actualData);
Expect.listEquals(expectedErrors, actualErrors);
asyncEnd();
});
}
main() {
var from = new Stream.fromIterable([5, 6]);
var c = new StreamController();
var sink = c.sink;
listen(c.stream, [5, 6, 1, 3], [2, 4]);
asyncStart();
sink.addStream(from).then((_) {
sink.add(1);
sink.addError(2);
sink.add(3);
sink.addError(4);
sink.close();
asyncEnd();
});
}