Index: pkg/scheduled_test/lib/src/utils.dart |
diff --git a/pkg/scheduled_test/lib/src/utils.dart b/pkg/scheduled_test/lib/src/utils.dart |
index b5e086e4c11b38c34d64e255f8fe590bf28d004a..e36863d19bba0f1de8c428e72be965986ebcc0b9 100644 |
--- a/pkg/scheduled_test/lib/src/utils.dart |
+++ b/pkg/scheduled_test/lib/src/utils.dart |
@@ -24,3 +24,39 @@ Future pumpEventQueue([int times=200]) { |
if (times == 0) return new Future.immediate(null); |
return new Future.immediate(null).then((_) => pumpEventQueue(times - 1)); |
} |
+ |
+/// Returns whether [iterable1] has the same elements in the same order as |
+/// [iterable2]. The elements are compared using `==`. |
+bool orderedIterableEquals(Iterable iterable1, Iterable iterable2) { |
+ var iter1 = iterable1.iterator; |
+ var iter2 = iterable2.iterator; |
+ |
+ while (true) { |
+ var hasNext1 = iter1.moveNext(); |
+ var hasNext2 = iter2.moveNext(); |
+ if (hasNext1 != hasNext2) return false; |
+ if (!hasNext1) return true; |
+ if (iter1.current != iter2.current) return false; |
+ } |
+} |
+ |
+// TODO(nweiz): remove this when issue 8731 is fixed. |
+/// Returns a [Stream] that will immediately emit [error] and then close. |
+Stream errorStream(error) => new Future.immediateError(error).asStream(); |
+ |
+/// Returns a buffered stream that will emit the same values as the stream |
+/// returned by [future] once [future] completes. If [future] completes to an |
+/// error, the return value will emit that error and then close. |
+Stream futureStream(Future<Stream> future) { |
+ var controller = new StreamController(); |
+ future.then((stream) { |
+ stream.listen( |
+ controller.add, |
+ onError: (error) => controller.signalError(error), |
+ onDone: controller.close); |
+ }).catchError((e) { |
+ controller.signalError(e); |
+ controller.close(); |
+ }); |
+ return controller.stream; |
+} |