OLD | NEW |
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 /** | 5 /// The mirror matchers library provides some additional matchers that |
6 * The mirror matchers library provides some additional matchers that | 6 /// make use of `dart:mirrors`. |
7 * make use of `dart:mirrors`. | |
8 */ | |
9 library matcher.mirror_matchers; | 7 library matcher.mirror_matchers; |
10 | 8 |
11 import 'dart:mirrors'; | 9 import 'dart:mirrors'; |
12 | 10 |
13 import 'matcher.dart'; | 11 import 'matcher.dart'; |
14 | 12 |
15 /** | 13 /// Returns a matcher that checks if a class instance has a property |
16 * Returns a matcher that checks if a class instance has a property | 14 /// with name [name], and optionally, if that property in turn satisfies |
17 * with name [name], and optionally, if that property in turn satisfies | 15 /// a [matcher]. |
18 * a [matcher]. | |
19 */ | |
20 Matcher hasProperty(String name, [matcher]) => | 16 Matcher hasProperty(String name, [matcher]) => |
21 new _HasProperty(name, matcher == null ? null : wrapMatcher(matcher)); | 17 new _HasProperty(name, matcher == null ? null : wrapMatcher(matcher)); |
22 | 18 |
23 class _HasProperty extends Matcher { | 19 class _HasProperty extends Matcher { |
24 final String _name; | 20 final String _name; |
25 final Matcher _matcher; | 21 final Matcher _matcher; |
26 | 22 |
27 const _HasProperty(this._name, [this._matcher]); | 23 const _HasProperty(this._name, [this._matcher]); |
28 | 24 |
29 bool matches(item, Map matchState) { | 25 bool matches(item, Map matchState) { |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
71 var innerDescription = new StringDescription(); | 67 var innerDescription = new StringDescription(); |
72 _matcher.describeMismatch(matchState['value'], innerDescription, | 68 _matcher.describeMismatch(matchState['value'], innerDescription, |
73 matchState['state'], verbose); | 69 matchState['state'], verbose); |
74 if (innerDescription.length > 0) { | 70 if (innerDescription.length > 0) { |
75 mismatchDescription.add(' which ').add(innerDescription.toString()); | 71 mismatchDescription.add(' which ').add(innerDescription.toString()); |
76 } | 72 } |
77 } | 73 } |
78 return mismatchDescription; | 74 return mismatchDescription; |
79 } | 75 } |
80 } | 76 } |
OLD | NEW |