Index: pkg/scheduled_test/lib/src/stream_matcher.dart |
diff --git a/pkg/scheduled_test/lib/src/stream_matcher.dart b/pkg/scheduled_test/lib/src/stream_matcher.dart |
index f1e65dad6482c9cf73becb0a3bbff7814fa0e3f8..f92a1c425b9be9b25072ee7548b0173eac795054 100644 |
--- a/pkg/scheduled_test/lib/src/stream_matcher.dart |
+++ b/pkg/scheduled_test/lib/src/stream_matcher.dart |
@@ -82,6 +82,14 @@ StreamMatcher either(streamMatcher1, streamMatcher2) => |
/// [streamMatcher] can be a [StreamMatcher], a [Matcher], or an [Object]. |
StreamMatcher allow(streamMatcher) => new _AllowMatcher(streamMatcher); |
+/// A matcher that asserts that a stream never emits values matching |
+/// [streamMatcher]. |
+/// |
+/// This will consume the remainder of a stream. |
+/// |
+/// [streamMatcher] can be a [StreamMatcher], a [Matcher], or an [Object]. |
+StreamMatcher never(streamMatcher) => new _NeverMatcher(streamMatcher); |
+ |
/// A matcher that matches a stream that emits no more values. |
StreamMatcher get isDone => new _IsDoneMatcher(); |
@@ -279,6 +287,38 @@ class _AllowMatcher implements StreamMatcher { |
} |
} |
+/// See [never]. |
+class _NeverMatcher implements StreamMatcher { |
+ final StreamMatcher _matcher; |
+ |
+ _NeverMatcher(streamMatcher) |
+ : _matcher = new StreamMatcher.wrap(streamMatcher); |
+ |
+ Future<Description> tryMatch(ScheduledStream stream) { |
+ consumeNext() { |
+ return stream.hasNext.then((hasNext) { |
+ if (!hasNext) return new Future.value(); |
+ |
+ var fork = stream.fork(); |
+ return _matcher.tryMatch(fork).whenComplete(fork.close) |
+ .then((description) { |
+ if (description != null) { |
Bob Nystrom
2014/02/14 17:55:02
It took me a long time to figure out what's going
nweiz
2014/02/18 22:01:10
I'll do this in a follow-up CL so I can change it
|
+ return stream.next().then((_) => consumeNext()); |
+ } |
+ |
+ return new StringDescription("matched\n") |
+ .add(prefixLines(_matcher.toString(), prefix: ' ')); |
+ }); |
+ }); |
+ } |
+ |
+ return consumeNext(); |
+ } |
+ |
+ String toString() => |
+ 'never\n${prefixLines(_matcher.toString(), prefix: ' ')}'; |
+} |
+ |
/// See [isDone]. |
class _IsDoneMatcher implements StreamMatcher { |
_IsDoneMatcher(); |