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

Unified Diff: pkg/mock/lib/src/times_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/result_set_matcher.dart ('k') | pkg/mock/lib/src/util.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/mock/lib/src/times_matcher.dart
diff --git a/pkg/mock/lib/src/times_matcher.dart b/pkg/mock/lib/src/times_matcher.dart
new file mode 100644
index 0000000000000000000000000000000000000000..225fc9434a24f075d4403394eebfa7ad4b1cf2bb
--- /dev/null
+++ b/pkg/mock/lib/src/times_matcher.dart
@@ -0,0 +1,65 @@
+// 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.times_matcher;
+
+import 'package:matcher/matcher.dart';
+
+/**
+ * [_TimesMatcher]s are used to make assertions about the number of
+ * times a method was called.
+ */
+class _TimesMatcher extends Matcher {
+ final int min, max;
+
+ const _TimesMatcher(this.min, [this.max = -1]);
+
+ bool matches(logList, Map matchState) => logList.length >= min &&
+ (max < 0 || logList.length <= max);
+
+ Description describe(Description description) {
+ description.add('to be called ');
+ if (max < 0) {
+ description.add('at least $min');
+ } else if (max == min) {
+ description.add('$max');
+ } else if (min == 0) {
+ description.add('at most $max');
+ } else {
+ description.add('between $min and $max');
+ }
+ return description.add(' times');
+ }
+
+ Description describeMismatch(logList, Description mismatchDescription,
+ Map matchState, bool verbose) =>
+ mismatchDescription.add('was called ${logList.length} times');
+}
+
+/** [happenedExactly] matches an exact number of calls. */
+Matcher happenedExactly(count) {
+ return new _TimesMatcher(count, count);
+}
+
+/** [happenedAtLeast] matches a minimum number of calls. */
+Matcher happenedAtLeast(count) {
+ return new _TimesMatcher(count);
+}
+
+/** [happenedAtMost] matches a maximum number of calls. */
+Matcher happenedAtMost(count) {
+ return new _TimesMatcher(0, count);
+}
+
+/** [neverHappened] matches zero calls. */
+const Matcher neverHappened = const _TimesMatcher(0, 0);
+
+/** [happenedOnce] matches exactly one call. */
+const Matcher happenedOnce = const _TimesMatcher(1, 1);
+
+/** [happenedAtLeastOnce] matches one or more calls. */
+const Matcher happenedAtLeastOnce = const _TimesMatcher(1);
+
+/** [happenedAtMostOnce] matches zero or one call. */
+const Matcher happenedAtMostOnce = const _TimesMatcher(0, 1);
« no previous file with comments | « pkg/mock/lib/src/result_set_matcher.dart ('k') | pkg/mock/lib/src/util.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698