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

Side by Side Diff: lib/src/prints_matcher.dart

Issue 840133003: matcher: fixed status file, formatting, tweaks to readme (Closed) Base URL: https://github.com/dart-lang/matcher.git@master
Patch Set: nits Created 5 years, 11 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 unified diff | Download patch
« no previous file with comments | « lib/src/pretty_print.dart ('k') | lib/src/string_matchers.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 library matcher.prints_matcher; 5 library matcher.prints_matcher;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 8
9 import 'description.dart'; 9 import 'description.dart';
10 import 'expect.dart'; 10 import 'expect.dart';
(...skipping 13 matching lines...) Expand all
24 24
25 class _Prints extends Matcher { 25 class _Prints extends Matcher {
26 final Matcher _matcher; 26 final Matcher _matcher;
27 27
28 _Prints(this._matcher); 28 _Prints(this._matcher);
29 29
30 bool matches(item, Map matchState) { 30 bool matches(item, Map matchState) {
31 if (item is! Function) return false; 31 if (item is! Function) return false;
32 32
33 var buffer = new StringBuffer(); 33 var buffer = new StringBuffer();
34 var result = runZoned(item, zoneSpecification: 34 var result = runZoned(item,
35 new ZoneSpecification(print: (_, __, ____, line) { 35 zoneSpecification: new ZoneSpecification(print: (_, __, ____, line) {
36 buffer.writeln(line); 36 buffer.writeln(line);
37 })); 37 }));
38 38
39 if (result is! Future) { 39 if (result is! Future) {
40 var actual = buffer.toString(); 40 var actual = buffer.toString();
41 matchState['prints.actual'] = actual; 41 matchState['prints.actual'] = actual;
42 return _matcher.matches(actual, matchState); 42 return _matcher.matches(actual, matchState);
43 } 43 }
44 44
45 return completes.matches(result.then(wrapAsync((_) { 45 return completes.matches(result.then(wrapAsync((_) {
46 expect(buffer.toString(), _matcher); 46 expect(buffer.toString(), _matcher);
47 }, 'prints')), matchState); 47 }, 'prints')), matchState);
48 } 48 }
49 49
50 Description describe(Description description) => 50 Description describe(Description description) =>
51 description.add('prints ').addDescriptionOf(_matcher); 51 description.add('prints ').addDescriptionOf(_matcher);
52 52
53 Description describeMismatch(item, Description description, Map matchState, 53 Description describeMismatch(
54 bool verbose) { 54 item, Description description, Map matchState, bool verbose) {
55 var actual = matchState.remove('prints.actual'); 55 var actual = matchState.remove('prints.actual');
56 if (actual == null) return description; 56 if (actual == null) return description;
57 if (actual.isEmpty) return description.add("printed nothing."); 57 if (actual.isEmpty) return description.add("printed nothing.");
58 58
59 description.add('printed ').addDescriptionOf(actual); 59 description.add('printed ').addDescriptionOf(actual);
60 60
61 // Create a new description for the matcher because at least 61 // Create a new description for the matcher because at least
62 // [_StringEqualsMatcher] replaces the previous contents of the description. 62 // [_StringEqualsMatcher] replaces the previous contents of the description.
63 var innerMismatch = _matcher.describeMismatch( 63 var innerMismatch = _matcher
64 actual, new StringDescription(), matchState, verbose).toString(); 64 .describeMismatch(actual, new StringDescription(), matchState, verbose)
65 .toString();
65 66
66 if (innerMismatch.isNotEmpty) { 67 if (innerMismatch.isNotEmpty) {
67 description.add('\n Which: ').add(innerMismatch.toString()); 68 description.add('\n Which: ').add(innerMismatch.toString());
68 } 69 }
69 70
70 return description; 71 return description;
71 } 72 }
72 } 73 }
OLDNEW
« no previous file with comments | « lib/src/pretty_print.dart ('k') | lib/src/string_matchers.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698