Chromium Code Reviews| 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); |
| + }); |
| +} |