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

Unified Diff: tests/lib/async/stream_iterator_test.dart

Issue 99463005: Update stream iterator doc and add test. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « sdk/lib/async/stream_impl.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/lib/async/stream_iterator_test.dart
diff --git a/tests/lib/async/stream_iterator_test.dart b/tests/lib/async/stream_iterator_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..a044094db945e9a523a9265a6ee9b25c597471d2
--- /dev/null
+++ b/tests/lib/async/stream_iterator_test.dart
@@ -0,0 +1,94 @@
+// Copyright (c) 2013, 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.
+
+import "dart:async";
+import "package:unittest/unittest.dart";
+
+main() {
+ test("stream iterator basic", () {
+ StreamController c = new StreamController();
+ Stream s = c.stream;
+ StreamIterator i = new StreamIterator(s);
+ i.moveNext().then(expectAsync1((bool b) {
+ expect(b, isTrue);
+ expect(42, i.current);
+ return i.moveNext();
+ })).then(expectAsync1((bool b) {
+ expect(b, isTrue);
+ expect(37, i.current);
+ return i.moveNext();
+ })).then(expectAsync1((bool b) {
+ expect(b, isFalse);
+ }));
+ c.add(42);
+ c.add(37);
+ c.close();
+ });
+
+ test("stream iterator prefilled", () {
+ StreamController c = new StreamController();
+ c.add(42);
+ c.add(37);
+ c.close();
+ Stream s = c.stream;
+ StreamIterator i = new StreamIterator(s);
+ i.moveNext().then(expectAsync1((bool b) {
+ expect(b, isTrue);
+ expect(42, i.current);
+ return i.moveNext();
+ })).then(expectAsync1((bool b) {
+ expect(b, isTrue);
+ expect(37, i.current);
+ return i.moveNext();
+ })).then(expectAsync1((bool b) {
+ expect(b, isFalse);
+ }));
+ });
+
+ test("stream iterator error", () {
+ StreamController c = new StreamController();
+ Stream s = c.stream;
+ StreamIterator i = new StreamIterator(s);
+ i.moveNext().then(expectAsync1((bool b) {
+ expect(b, isTrue);
+ expect(42, i.current);
+ return i.moveNext();
+ })).then((bool b) {
+ Expect.fail("Result not expected");
+ }, onError: expectAsync1((e) {
+ expect("BAD", e);
+ return i.moveNext();
+ })).then(expectAsync1((bool b) {
+ expect(b, isFalse);
+ }));
+ c.add(42);
+ c.addError("BAD");
+ c.add(37);
+ c.close();
+ });
+
+ test("stream iterator read badly", () {
Søren Gjesse 2013/12/19 15:28:35 Why is this test called "read badly"?
Lasse Reichstein Nielsen 2013/12/19 15:30:17 Short for "read current at a time when you shouldn
+ StreamController c = new StreamController();
+ Stream s = c.stream;
+ StreamIterator i = new StreamIterator(s);
+ i.moveNext().then(expectAsync1((bool b) {
+ expect(b, isTrue);
+ expect(42, i.current);
+ new Timer(const Duration(milliseconds:100), expectAsync0(() {
+ expect(i.current, null);
+ expect(() { i.moveNext(); }, throws);
+ c.add(37);
+ c.close();
+ }));
+ return i.moveNext();
+ })).then(expectAsync1((bool b) {
+ expect(b, isTrue);
+ expect(37, i.current);
+ return i.moveNext();
+ })).then(expectAsync1((bool b) {
+ expect(b, isFalse);
+ }));
+ c.add(42);
+ });
+}
« no previous file with comments | « sdk/lib/async/stream_impl.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698