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

Side by Side Diff: pkg/unittest/lib/mirror_matchers.dart

Issue 90973002: Revert r30650: fails in dart2js minified mode. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | pkg/unittest/test/mirror_matchers_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 var candidate = classMirror.declarations[symbol]; 52 if (!classMirror.getters.containsKey(symbol)) {
53 if (candidate == null) {
54 addStateInfo(matchState, {'reason': 'has no property named "$_name"'}); 53 addStateInfo(matchState, {'reason': 'has no property named "$_name"'});
55 return false; 54 return false;
56 } 55 }
57 bool isInstanceField = candidate is VariableMirror && !candidate.isStatic;
58 bool isInstanceGetter =
59 candidate is MethodMirror && candidate.isGetter && !candidate.isStatic;
60 if (!(isInstanceField || isInstanceGetter)) {
61 addStateInfo(matchState, {'reason':
62 'has a member named "$_name", but it is not an instance property'});
63 return false;
64 }
65 if (_matcher == null) return true; 56 if (_matcher == null) return true;
66 var result = mirror.getField(symbol); 57 var result = mirror.getField(symbol);
67 var resultMatches = _matcher.matches(result.reflectee, matchState); 58 var resultMatches = _matcher.matches(result.reflectee, matchState);
68 if (!resultMatches) { 59 if (!resultMatches) {
69 addStateInfo(matchState, {'value': result.reflectee}); 60 addStateInfo(matchState, {'value': result.reflectee});
70 } 61 }
71 return resultMatches; 62 return resultMatches;
72 } 63 }
73 64
74 Description describe(Description description) { 65 Description describe(Description description) {
(...skipping 15 matching lines...) Expand all
90 var innerDescription = new StringDescription(); 81 var innerDescription = new StringDescription();
91 _matcher.describeMismatch(matchState['value'], innerDescription, 82 _matcher.describeMismatch(matchState['value'], innerDescription,
92 matchState['state'], verbose); 83 matchState['state'], verbose);
93 if (innerDescription.length > 0) { 84 if (innerDescription.length > 0) {
94 mismatchDescription.add(' which ').add(innerDescription.toString()); 85 mismatchDescription.add(' which ').add(innerDescription.toString());
95 } 86 }
96 } 87 }
97 return mismatchDescription; 88 return mismatchDescription;
98 } 89 }
99 } 90 }
OLDNEW
« no previous file with comments | « no previous file | pkg/unittest/test/mirror_matchers_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698