Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 * The mirror matchers library provides some additional matchers that | 5 * The mirror matchers library provides some additional matchers that |
| 6 * make use of dart:mirrors. | 6 * make use of dart:mirrors. |
| 7 * | 7 * |
| 8 * ## Installing ## | 8 * ## Installing ## |
| 9 * | 9 * |
| 10 * Use [pub][] to install this package. Add the following to your `pubspec.yaml` | 10 * Use [pub][] to install this package. Add the following to your `pubspec.yaml` |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 42 class _HasProperty extends Matcher { | 42 class _HasProperty extends Matcher { |
| 43 final String _name; | 43 final String _name; |
| 44 final Matcher _matcher; | 44 final Matcher _matcher; |
| 45 | 45 |
| 46 const _HasProperty(this._name, [this._matcher]); | 46 const _HasProperty(this._name, [this._matcher]); |
| 47 | 47 |
| 48 bool matches(item, Map matchState) { | 48 bool matches(item, Map matchState) { |
| 49 var mirror = reflect(item); | 49 var mirror = reflect(item); |
| 50 var classMirror = mirror.type; | 50 var classMirror = mirror.type; |
| 51 var symbol = new Symbol(_name); | 51 var symbol = new Symbol(_name); |
| 52 if (!classMirror.getters.containsKey(symbol)) { | 52 var candidate = classMirror.declarations[symbol]; |
| 53 if (candidate == null || | |
| 54 candidate is! MethodMirror || | |
|
Siggi Cherem (dart-lang)
2013/11/25 20:28:47
shouldn't we exclude if candidate is a VariableMir
| |
| 55 !candidate.isGetter || | |
| 56 candidate.isStatic) { | |
|
rmacnak
2013/11/25 19:54:01
This last clause changes the behavior. Presumably
Siggi Cherem (dart-lang)
2013/11/25 20:28:47
Makes sense, sgtm. Could we however split this che
| |
| 53 addStateInfo(matchState, {'reason': 'has no property named "$_name"'}); | 57 addStateInfo(matchState, {'reason': 'has no property named "$_name"'}); |
| 54 return false; | 58 return false; |
| 55 } | 59 } |
| 56 if (_matcher == null) return true; | 60 if (_matcher == null) return true; |
| 57 var result = mirror.getField(symbol); | 61 var result = mirror.getField(symbol); |
| 58 var resultMatches = _matcher.matches(result.reflectee, matchState); | 62 var resultMatches = _matcher.matches(result.reflectee, matchState); |
| 59 if (!resultMatches) { | 63 if (!resultMatches) { |
| 60 addStateInfo(matchState, {'value': result.reflectee}); | 64 addStateInfo(matchState, {'value': result.reflectee}); |
| 61 } | 65 } |
| 62 return resultMatches; | 66 return resultMatches; |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 81 var innerDescription = new StringDescription(); | 85 var innerDescription = new StringDescription(); |
| 82 _matcher.describeMismatch(matchState['value'], innerDescription, | 86 _matcher.describeMismatch(matchState['value'], innerDescription, |
| 83 matchState['state'], verbose); | 87 matchState['state'], verbose); |
| 84 if (innerDescription.length > 0) { | 88 if (innerDescription.length > 0) { |
| 85 mismatchDescription.add(' which ').add(innerDescription.toString()); | 89 mismatchDescription.add(' which ').add(innerDescription.toString()); |
| 86 } | 90 } |
| 87 } | 91 } |
| 88 return mismatchDescription; | 92 return mismatchDescription; |
| 89 } | 93 } |
| 90 } | 94 } |
| OLD | NEW |