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

Unified Diff: lib/src/matcher/map_matchers.dart

Issue 1135653004: pkg/(unit)test: include a copy of old matcher (Closed) Base URL: https://github.com/dart-lang/test.git@stable
Patch Set: another nit 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « lib/src/matcher/iterable_matchers.dart ('k') | lib/src/matcher/numeric_matchers.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/src/matcher/map_matchers.dart
diff --git a/lib/src/matcher/map_matchers.dart b/lib/src/matcher/map_matchers.dart
new file mode 100644
index 0000000000000000000000000000000000000000..98e89af8946c1544d533417c09416094a3eeb895
--- /dev/null
+++ b/lib/src/matcher/map_matchers.dart
@@ -0,0 +1,61 @@
+// 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.
+
+library unittest.matcher.map_matchers;
+
+import 'interfaces.dart';
+import 'util.dart';
+
+/// Returns a matcher which matches maps containing the given [value].
+Matcher containsValue(value) => new _ContainsValue(value);
+
+class _ContainsValue extends Matcher {
+ final _value;
+
+ const _ContainsValue(this._value);
+
+ bool matches(item, Map matchState) => 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 Matcher {
+ final _key;
+ final Matcher _valueMatcher;
+
+ const _ContainsMapping(this._key, Matcher this._valueMatcher);
+
+ bool matches(item, Map matchState) =>
+ item.containsKey(_key) && _valueMatcher.matches(item[_key], matchState);
+
+ Description describe(Description description) {
+ return description
+ .add('contains pair ')
+ .addDescriptionOf(_key)
+ .add(' => ')
+ .addDescriptionOf(_valueMatcher);
+ }
+
+ Description describeMismatch(
+ item, Description mismatchDescription, Map matchState, bool verbose) {
+ if (!item.containsKey(_key)) {
+ return mismatchDescription
+ .add(" doesn't contain key ")
+ .addDescriptionOf(_key);
+ } else {
+ mismatchDescription
+ .add(' contains key ')
+ .addDescriptionOf(_key)
+ .add(' but with value ');
+ _valueMatcher.describeMismatch(
+ item[_key], mismatchDescription, matchState, verbose);
+ return mismatchDescription;
+ }
+ }
+}
« no previous file with comments | « lib/src/matcher/iterable_matchers.dart ('k') | lib/src/matcher/numeric_matchers.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698