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

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

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