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

Side by Side Diff: pkg/mock/lib/src/result_matcher.dart

Issue 278613003: pkg/mock: fixes for v0.11 (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: status file fix for mismatched version constraints Created 6 years, 7 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 | Annotate | Revision Log
« no previous file with comments | « pkg/mock/lib/src/mock.dart ('k') | pkg/mock/lib/src/result_set_matcher.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 mock.result_matcher; 5 library mock.result_matcher;
6 6
7 import 'package:matcher/matcher.dart'; 7 import 'package:matcher/matcher.dart';
8 8
9 import 'action.dart'; 9 import 'action.dart';
10 import 'log_entry.dart'; 10 import 'log_entry.dart';
11 11
12 /** 12 /**
13 * [_ResultMatcher]s are used to make assertions about the results 13 * [_ResultMatcher]s are used to make assertions about the results
14 * of method calls. These can be used as optional parameters to [getLogs]. 14 * of method calls. These can be used as optional parameters to [getLogs].
15 */ 15 */
16 class _ResultMatcher extends Matcher { 16 class _ResultMatcher extends Matcher {
17 final Action action; 17 final Action action;
18 final Matcher value; 18 final Matcher value;
19 19
20 const _ResultMatcher(this.action, this.value); 20 const _ResultMatcher(this.action, this.value);
21 21
22 bool matches(item, Map matchState) { 22 bool matches(item, Map matchState) {
23 if (item is! LogEntry) { 23 if (item is! LogEntry) {
24 return false; 24 return false;
25 } 25 }
26 // normalize the action; _PROXY is like _RETURN. 26 // normalize the action; _PROXY is like _RETURN.
27 Action eaction = item.action; 27 Action eaction = item.action;
28 if (eaction == Action.PROXY) { 28 if (eaction == Action.PROXY) {
29 eaction = Action.RETURN; 29 eaction = Action.RETURN;
30 } 30 }
31 return (eaction == action && value.matches(item.value, matchState)); 31 return (eaction == action && value.matches(item.value, matchState));
32 } 32 }
33 33
34 Description describe(Description description) { 34 Description describe(Description description) {
35 description.add(' to '); 35 description.add(' to ');
36 if (action == Action.RETURN || action == Action.PROXY) 36 if (action == Action.RETURN || action == Action.PROXY) {
37 description.add('return '); 37 description.add('return ');
38 else 38 } else {
39 description.add('throw '); 39 description.add('throw ');
40 }
40 return description.addDescriptionOf(value); 41 return description.addDescriptionOf(value);
41 } 42 }
42 43
43 Description describeMismatch(item, Description mismatchDescription, 44 Description describeMismatch(item, Description mismatchDescription,
44 Map matchState, bool verbose) { 45 Map matchState, bool verbose) {
45 if (item.action == Action.RETURN || item.action == Action.PROXY) { 46 if (item.action == Action.RETURN || item.action == Action.PROXY) {
46 mismatchDescription.add('returned '); 47 mismatchDescription.add('returned ');
47 } else { 48 } else {
48 mismatchDescription.add('threw '); 49 mismatchDescription.add('threw ');
49 } 50 }
50 mismatchDescription.add(item.value); 51 mismatchDescription.add(item.value);
51 return mismatchDescription; 52 return mismatchDescription;
52 } 53 }
53 } 54 }
54 55
55 /** 56 /**
56 *[returning] matches log entries where the call to a method returned 57 *[returning] matches log entries where the call to a method returned
57 * a value that matched [value]. 58 * a value that matched [value].
58 */ 59 */
59 Matcher returning(value) => 60 Matcher returning(value) =>
60 new _ResultMatcher(Action.RETURN, wrapMatcher(value)); 61 new _ResultMatcher(Action.RETURN, wrapMatcher(value));
61 62
62 /** 63 /**
63 *[throwing] matches log entrues where the call to a method threw 64 *[throwing] matches log entrues where the call to a method threw
64 * a value that matched [value]. 65 * a value that matched [value].
65 */ 66 */
66 Matcher throwing(value) => 67 Matcher throwing(value) =>
67 new _ResultMatcher(Action.THROW, wrapMatcher(value)); 68 new _ResultMatcher(Action.THROW, wrapMatcher(value));
OLDNEW
« no previous file with comments | « pkg/mock/lib/src/mock.dart ('k') | pkg/mock/lib/src/result_set_matcher.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698