30683bdc79
Also increment pkg/async version to fix broken first upload. Review URL: https://codereview.chromium.org//94013005 git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@31322 260f80e4-7a28-3924-810f-c04153c831b5
95 lines
2.6 KiB
Dart
95 lines
2.6 KiB
Dart
// 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) {
|
|
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 current/moveNext during move", () {
|
|
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);
|
|
});
|
|
}
|