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

Unified Diff: lib/unittest/map_matchers.dart

Issue 10441104: New expectation functions plus convert old tests to use these. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 6 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 | « lib/unittest/interfaces.dart ('k') | lib/unittest/matcher.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/unittest/map_matchers.dart
===================================================================
--- lib/unittest/map_matchers.dart (revision 0)
+++ lib/unittest/map_matchers.dart (revision 0)
@@ -0,0 +1,52 @@
+// Copyright (c) 2012, 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.
+
+/**
+ * Returns a matcher which matches maps containing the given [value].
+ */
+Matcher containsValue(value) => new _ContainsValue(value);
+
+class _ContainsValue extends BaseMatcher {
+ final _value;
+
+ const _ContainsValue(this._value);
+
+ bool matches(item) => item.containsValue(_value);
+ Description describe(Description description) =>
+ description.add('contains value ').addDescriptionOf(_value);
+}
+
+/**
+ * Returns a matcher which matches maps containing the key-value pair
+ * with [key] => [value].
+ */
+Matcher containsPair(key, value) =>
+ new _ContainsMapping(key, wrapMatcher(value));
+
+class _ContainsMapping extends BaseMatcher {
+ final _key;
+ final Matcher _valueMatcher;
+
+ const _ContainsMapping(this._key, Matcher this._valueMatcher);
+
+ bool matches(item) =>
+ item.containsKey(_key) && _valueMatcher.matches(item[_key]);
+
+ Description describe(Description description) {
+ return description.add('contains pair ').addDescriptionOf(_key).
+ add(' => ').addDescriptionOf(_valueMatcher);
+ }
+
+ Description describeMismatch(item, Description mismatchDescription) {
+ if (!item.containsKey(_key)) {
+ return mismatchDescription.addDescriptionOf(item).
+ add("' doesn't contain key '").addDescriptionOf(_key);
+ } else {
+ return mismatchDescription.add(' contains key ').addDescriptionOf(_key).
+ add(' but with value ');
+ _valueMatcher.describeMismatch(item[_key], mismatchDescription);
+ return mismatchDescription;
+ }
+ }
+}
« no previous file with comments | « lib/unittest/interfaces.dart ('k') | lib/unittest/matcher.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698