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

Unified Diff: lib/src/prints_matcher.dart

Issue 867133002: pkg/matcher: refactor with unittest v0.12 work (Closed) Base URL: https://github.com/dart-lang/matcher.git@master
Patch Set: cl nits Created 5 years, 10 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 | « lib/src/future_matchers.dart ('k') | lib/src/throws_matcher.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/src/prints_matcher.dart
diff --git a/lib/src/prints_matcher.dart b/lib/src/prints_matcher.dart
deleted file mode 100644
index be6abe36833e331d9e94b60d5cabf1e616004648..0000000000000000000000000000000000000000
--- a/lib/src/prints_matcher.dart
+++ /dev/null
@@ -1,73 +0,0 @@
-// Copyright (c) 2014, 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.
-
-library matcher.prints_matcher;
-
-import 'dart:async';
-
-import 'description.dart';
-import 'expect.dart';
-import 'interfaces.dart';
-import 'future_matchers.dart';
-import 'util.dart';
-
-/// Matches a [Function] that prints text that matches [matcher].
-///
-/// [matcher] may be a String or a [Matcher].
-///
-/// If the function this runs against returns a [Future], all text printed by
-/// the function (using [Zone] scoping) until that Future completes is matched.
-///
-/// This only tracks text printed using the [print] function.
-Matcher prints(matcher) => new _Prints(wrapMatcher(matcher));
-
-class _Prints extends Matcher {
- final Matcher _matcher;
-
- _Prints(this._matcher);
-
- bool matches(item, Map matchState) {
- if (item is! Function) return false;
-
- var buffer = new StringBuffer();
- var result = runZoned(item,
- zoneSpecification: new ZoneSpecification(print: (_, __, ____, line) {
- buffer.writeln(line);
- }));
-
- if (result is! Future) {
- var actual = buffer.toString();
- matchState['prints.actual'] = actual;
- return _matcher.matches(actual, matchState);
- }
-
- return completes.matches(result.then(wrapAsync((_) {
- expect(buffer.toString(), _matcher);
- }, 'prints')), matchState);
- }
-
- Description describe(Description description) =>
- description.add('prints ').addDescriptionOf(_matcher);
-
- Description describeMismatch(
- item, Description description, Map matchState, bool verbose) {
- var actual = matchState.remove('prints.actual');
- if (actual == null) return description;
- if (actual.isEmpty) return description.add("printed nothing.");
-
- description.add('printed ').addDescriptionOf(actual);
-
- // Create a new description for the matcher because at least
- // [_StringEqualsMatcher] replaces the previous contents of the description.
- var innerMismatch = _matcher
- .describeMismatch(actual, new StringDescription(), matchState, verbose)
- .toString();
-
- if (innerMismatch.isNotEmpty) {
- description.add('\n Which: ').add(innerMismatch.toString());
- }
-
- return description;
- }
-}
« no previous file with comments | « lib/src/future_matchers.dart ('k') | lib/src/throws_matcher.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698