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

Unified 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 side-by-side diff with in-line comments
Download patch
« 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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/mock/lib/src/result_matcher.dart
diff --git a/pkg/mock/lib/src/result_matcher.dart b/pkg/mock/lib/src/result_matcher.dart
new file mode 100644
index 0000000000000000000000000000000000000000..08f89d6c1b593757cf6194dfa02f7828fc83aeb4
--- /dev/null
+++ b/pkg/mock/lib/src/result_matcher.dart
@@ -0,0 +1,67 @@
+// 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 mock.result_matcher;
+
+import 'package:matcher/matcher.dart';
+
+import 'action.dart';
+import 'log_entry.dart';
+
+/**
+ * [_ResultMatcher]s are used to make assertions about the results
+ * of method calls. These can be used as optional parameters to [getLogs].
+ */
+class _ResultMatcher extends Matcher {
+ final Action action;
+ final Matcher value;
+
+ const _ResultMatcher(this.action, this.value);
+
+ bool matches(item, Map matchState) {
+ if (item is! LogEntry) {
+ return false;
+ }
+ // normalize the action; _PROXY is like _RETURN.
+ Action eaction = item.action;
+ if (eaction == Action.PROXY) {
+ eaction = Action.RETURN;
+ }
+ return (eaction == action && value.matches(item.value, matchState));
+ }
+
+ Description describe(Description description) {
+ description.add(' to ');
+ if (action == Action.RETURN || action == Action.PROXY)
+ description.add('return ');
+ else
+ description.add('throw ');
+ return description.addDescriptionOf(value);
+ }
+
+ Description describeMismatch(item, Description mismatchDescription,
+ Map matchState, bool verbose) {
+ if (item.action == Action.RETURN || item.action == Action.PROXY) {
+ mismatchDescription.add('returned ');
+ } else {
+ mismatchDescription.add('threw ');
+ }
+ mismatchDescription.add(item.value);
+ return mismatchDescription;
+ }
+}
+
+/**
+ *[returning] matches log entries where the call to a method returned
+ * a value that matched [value].
+ */
+Matcher returning(value) =>
+ new _ResultMatcher(Action.RETURN, wrapMatcher(value));
+
+/**
+ *[throwing] matches log entrues where the call to a method threw
+ * a value that matched [value].
+ */
+Matcher throwing(value) =>
+ new _ResultMatcher(Action.THROW, wrapMatcher(value));
« 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