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` |
11 * file. | 11 * file. |
12 * | 12 * |
13 * dependencies: | 13 * dependencies: |
14 * unittest: any | 14 * unittest: any |
15 * | 15 * |
16 * Then run `pub install`. | 16 * Then run `pub install`. |
17 * | 17 * |
18 * Import this into your Dart code with: | 18 * Import this into your Dart code with: |
19 * | 19 * |
20 * import 'package:unittest/mirror_matchers.dart'; | 20 * import 'package:unittest/mirror_matchers.dart'; |
21 * | 21 * |
22 * For more information, see the [unittest package on pub.dartlang.org]. | 22 * For more information, see the [unittest package on pub.dartlang.org]. |
23 * (http://pub.dartlang.org/packages/unittest). | 23 * (http://pub.dartlang.org/packages/unittest). |
24 * | 24 * |
25 * [pub]: http://pub.dartlang.org | 25 * [pub]: http://pub.dartlang.org |
26 * [pkg]: http://pub.dartlang.org/packages/mirror_matchers | 26 * [pkg]: http://pub.dartlang.org/packages/mirror_matchers |
27 */ | 27 */ |
28 library mirror_matchers; | 28 library mirror_matchers; |
29 | 29 |
30 import 'dart:async'; | |
31 import 'dart:mirrors'; | 30 import 'dart:mirrors'; |
32 import 'package:meta/meta.dart'; | |
33 | 31 |
34 import 'matcher.dart'; | 32 import 'matcher.dart'; |
35 | 33 |
36 /** | 34 /** |
37 * Returns a matcher that checks if a class instance has a property | 35 * Returns a matcher that checks if a class instance has a property |
38 * with name [name], and optionally, if that property in turn satisfies | 36 * with name [name], and optionally, if that property in turn satisfies |
39 * a [matcher]. | 37 * a [matcher]. |
40 */ | 38 */ |
41 Matcher hasProperty(String name, [matcher]) => | 39 Matcher hasProperty(String name, [matcher]) => |
42 new _HasProperty(name, matcher == null ? null : wrapMatcher(matcher)); | 40 new _HasProperty(name, matcher == null ? null : wrapMatcher(matcher)); |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
83 var innerDescription = new StringDescription(); | 81 var innerDescription = new StringDescription(); |
84 _matcher.describeMismatch(matchState['value'], innerDescription, | 82 _matcher.describeMismatch(matchState['value'], innerDescription, |
85 matchState['state'], verbose); | 83 matchState['state'], verbose); |
86 if (innerDescription.length > 0) { | 84 if (innerDescription.length > 0) { |
87 mismatchDescription.add(' which ').add(innerDescription.toString()); | 85 mismatchDescription.add(' which ').add(innerDescription.toString()); |
88 } | 86 } |
89 } | 87 } |
90 return mismatchDescription; | 88 return mismatchDescription; |
91 } | 89 } |
92 } | 90 } |
OLD | NEW |