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

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

Issue 233243007: pkg/mock: restructure library layout (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 8 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 return description.addDescriptionOf(value);
41 }
42
43 Description describeMismatch(item, Description mismatchDescription,
44 Map matchState, bool verbose) {
45 if (item.action == Action.RETURN || item.action == Action.PROXY) {
46 mismatchDescription.add('returned ');
47 } else {
48 mismatchDescription.add('threw ');
49 }
50 mismatchDescription.add(item.value);
51 return mismatchDescription;
52 }
53 }
54
55 /**
56 *[returning] matches log entries where the call to a method returned
57 * a value that matched [value].
58 */
59 Matcher returning(value) =>
60 new _ResultMatcher(Action.RETURN, wrapMatcher(value));
61
62 /**
63 *[throwing] matches log entrues where the call to a method threw
64 * a value that matched [value].
65 */
66 Matcher throwing(value) =>
67 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