blob: 9e65da5e18b6e743051f66450e50a92ce2d61d83 [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 Stream<T> take(int count)
* Provides at most the first n values of this stream.
* Forwards the first n data events of this stream, and all error events,
* to the returned stream, and ends with a done event.
* If this stream produces fewer than count values before it's done,
* so will the returned stream.
* @description Checks that all error events are returned. Checks that
* the resulting stream ends with a done event.
* @author kaigorodov
*/
import "dart:async";
import "../../../Utils/async_utils.dart";
import "../../../Utils/expect.dart";
void check(int eventCount, int takeCount) {
Iterable it=new Iterable.generate(eventCount, (int index)=>index);
Stream s = new Stream.fromIterable(it).map((x) => throw new ArgumentError(x));
Stream t=s.take(takeCount);
int seenCount=0;
asyncStart();
t.listen((value){
Expect.fail("datum not expected");
},
onError: (error) {
Expect.isTrue(error is ArgumentError, error.toString());
var message=(error as ArgumentError).message;
Expect.equals(seenCount, message);
seenCount++;
},
onDone: () {
Expect.equals(eventCount, seenCount);
asyncEnd();
}
);
}
main() {
check(0,0);
check(0,1);
check(1,0);
check(1,1);
check(2,3);
}