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

Unified Diff: tests/standalone/io/io_sink_test.dart

Issue 52263005: Add IOSink:flush(). (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 2 months 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/io/stdio.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/standalone/io/io_sink_test.dart
diff --git a/tests/standalone/io/io_sink_test.dart b/tests/standalone/io/io_sink_test.dart
index de830442e394cb7a0494d9df4e47933af4d04913..6c0be44d59b28559060674bb1a40f6f45beb3e7a 100644
--- a/tests/standalone/io/io_sink_test.dart
+++ b/tests/standalone/io/io_sink_test.dart
@@ -3,40 +3,43 @@
// BSD-style license that can be found in the LICENSE file.
import "package:expect/expect.dart";
+import "package:async_helper/async_helper.dart";
import "dart:async";
import "dart:io";
-import "dart:isolate";
class TestConsumer implements StreamConsumer {
final List expected;
final List received = [];
- var closePort;
-
int addStreamCount = 0;
int expcetedAddStreamCount;
+ bool expectClose;
TestConsumer(this.expected,
- {close: true,
+ {this.expectClose: true,
this.expcetedAddStreamCount: -1}) {
- if (close) closePort = new ReceivePort();
+ if (expectClose) asyncStart();
}
Future addStream(Stream stream) {
addStreamCount++;
- return stream.fold(
- received,
- (list, value) {
- list.addAll(value);
- return list;
- })
- .then((_) {});
+ var sub = stream
+ .listen((v) {
+ received.addAll(v);
+ });
+ sub.pause();
+ scheduleMicrotask(sub.resume);
+ return sub.asFuture();
+ }
+
+ void matches(List list) {
+ Expect.listEquals(list, received);
}
Future close() {
return new Future.value()
.then((_) {
- if (closePort != null) closePort.close();
+ if (expectClose) asyncEnd();
Expect.listEquals(expected, received);
if (expcetedAddStreamCount >= 0) {
Expect.equals(expcetedAddStreamCount, addStreamCount);
@@ -62,6 +65,23 @@ void testAddClose() {
sink.close();
}
+
+void testAddFlush() {
+ var consumer = new TestConsumer([0, 1, 2]);
+ var sink = new IOSink(consumer);
+ sink.add([0]);
+ sink.flush().then((s) {
+ consumer.matches([0]);
+ s.add([1]);
+ s.add([2]);
+ s.flush().then((s) {
+ consumer.matches([0, 1, 2]);
+ s.close();
+ });
+ });
+}
+
+
void testAddStreamClose() {
{
var sink = new IOSink(new TestConsumer([0]));
@@ -104,6 +124,7 @@ void testAddStreamAddClose() {
void main() {
testClose();
testAddClose();
+ testAddFlush();
testAddStreamClose();
testAddStreamAddClose();
}
« no previous file with comments | « sdk/lib/io/stdio.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698