| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 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. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 import 'interfaces.dart'; | 5 import 'interfaces.dart'; |
| 6 import 'util.dart'; | 6 import 'util.dart'; |
| 7 | 7 |
| 8 /// Returns a matcher which matches maps containing the given [value]. | 8 /// Returns a matcher which matches maps containing the given [value]. |
| 9 Matcher containsValue(value) => new _ContainsValue(value); | 9 Matcher containsValue(value) => new _ContainsValue(value); |
| 10 | 10 |
| 11 class _ContainsValue extends Matcher { | 11 class _ContainsValue extends Matcher { |
| 12 final _value; | 12 final _value; |
| 13 | 13 |
| 14 const _ContainsValue(this._value); | 14 const _ContainsValue(this._value); |
| 15 | 15 |
| 16 bool matches(item, Map matchState) => item.containsValue(_value); | 16 bool matches(item, Map matchState) => item.containsValue(_value); |
| 17 Description describe(Description description) => | 17 Description describe(Description description) => |
| 18 description.add('contains value ').addDescriptionOf(_value); | 18 description.add('contains value ').addDescriptionOf(_value); |
| 19 } | 19 } |
| 20 | 20 |
| 21 /// Returns a matcher which matches maps containing the key-value pair | 21 /// Returns a matcher which matches maps containing the key-value pair |
| 22 /// with [key] => [value]. | 22 /// with [key] => [value]. |
| 23 Matcher containsPair(key, value) => | 23 Matcher containsPair(key, value) => |
| 24 new _ContainsMapping(key, wrapMatcher(value)); | 24 new _ContainsMapping(key, wrapMatcher(value)); |
| 25 | 25 |
| 26 class _ContainsMapping extends Matcher { | 26 class _ContainsMapping extends Matcher { |
| 27 final _key; | 27 final _key; |
| 28 final Matcher _valueMatcher; | 28 final Matcher _valueMatcher; |
| 29 | 29 |
| 30 const _ContainsMapping(this._key, Matcher this._valueMatcher); | 30 const _ContainsMapping(this._key, this._valueMatcher); |
| 31 | 31 |
| 32 bool matches(item, Map matchState) => | 32 bool matches(item, Map matchState) => |
| 33 item.containsKey(_key) && _valueMatcher.matches(item[_key], matchState); | 33 item.containsKey(_key) && _valueMatcher.matches(item[_key], matchState); |
| 34 | 34 |
| 35 Description describe(Description description) { | 35 Description describe(Description description) { |
| 36 return description | 36 return description |
| 37 .add('contains pair ') | 37 .add('contains pair ') |
| 38 .addDescriptionOf(_key) | 38 .addDescriptionOf(_key) |
| 39 .add(' => ') | 39 .add(' => ') |
| 40 .addDescriptionOf(_valueMatcher); | 40 .addDescriptionOf(_valueMatcher); |
| 41 } | 41 } |
| 42 | 42 |
| 43 Description describeMismatch( | 43 Description describeMismatch( |
| 44 item, Description mismatchDescription, Map matchState, bool verbose) { | 44 item, Description mismatchDescription, Map matchState, bool verbose) { |
| 45 if (!item.containsKey(_key)) { | 45 if (!item.containsKey(_key)) { |
| 46 return mismatchDescription | 46 return mismatchDescription |
| 47 .add(" doesn't contain key ") | 47 .add(" doesn't contain key ") |
| 48 .addDescriptionOf(_key); | 48 .addDescriptionOf(_key); |
| 49 } else { | 49 } else { |
| 50 mismatchDescription | 50 mismatchDescription |
| 51 .add(' contains key ') | 51 .add(' contains key ') |
| 52 .addDescriptionOf(_key) | 52 .addDescriptionOf(_key) |
| 53 .add(' but with value '); | 53 .add(' but with value '); |
| 54 _valueMatcher.describeMismatch( | 54 _valueMatcher.describeMismatch( |
| 55 item[_key], mismatchDescription, matchState, verbose); | 55 item[_key], mismatchDescription, matchState, verbose); |
| 56 return mismatchDescription; | 56 return mismatchDescription; |
| 57 } | 57 } |
| 58 } | 58 } |
| 59 } | 59 } |
| OLD | NEW |