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 library matcher.core_matchers; | 5 library matcher.core_matchers; |
6 | 6 |
7 import 'description.dart'; | 7 import 'description.dart'; |
8 import 'interfaces.dart'; | 8 import 'interfaces.dart'; |
9 import 'util.dart'; | 9 import 'util.dart'; |
10 | 10 |
11 /// Returns a matcher that matches empty strings, maps or iterables | 11 /// Returns a matcher that matches empty strings, maps or iterables |
12 /// (including collections). | 12 /// (including collections) using the isEmpty property. |
13 const Matcher isEmpty = const _Empty(); | 13 const Matcher isEmpty = const _Empty(); |
14 | 14 |
15 class _Empty extends Matcher { | 15 class _Empty extends Matcher { |
16 const _Empty(); | 16 const _Empty(); |
17 bool matches(item, Map matchState) { | 17 bool matches(item, Map matchState) { |
18 if (item is Map || item is Iterable) { | 18 return (item is Map || item is Iterable || item is String) && item.isEmpty; |
19 return item.isEmpty; | |
20 } else if (item is String) { | |
21 return item.length == 0; | |
22 } else { | |
23 return false; | |
24 } | |
25 } | 19 } |
26 Description describe(Description description) => description.add('empty'); | 20 Description describe(Description description) => description.add('empty'); |
27 } | 21 } |
28 | 22 |
| 23 /// Returns a matcher that matches non-empty strings, maps or iterables |
| 24 /// (including collections) using the isNotEmpty property. |
| 25 const Matcher isNotEmpty = const _NotEmpty(); |
| 26 |
| 27 class _NotEmpty extends Matcher { |
| 28 const _NotEmpty(); |
| 29 |
| 30 bool matches(item, Map matchState) { |
| 31 return (item is Map || item is Iterable || item is String) && |
| 32 item.isNotEmpty; |
| 33 } |
| 34 |
| 35 Description describe(Description description) => description.add('non-empty'); |
| 36 } |
| 37 |
29 /// A matcher that matches any null value. | 38 /// A matcher that matches any null value. |
30 const Matcher isNull = const _IsNull(); | 39 const Matcher isNull = const _IsNull(); |
31 | 40 |
32 /// A matcher that matches any non-null value. | 41 /// A matcher that matches any non-null value. |
33 const Matcher isNotNull = const _IsNotNull(); | 42 const Matcher isNotNull = const _IsNotNull(); |
34 | 43 |
35 class _IsNull extends Matcher { | 44 class _IsNull extends Matcher { |
36 const _IsNull(); | 45 const _IsNull(); |
37 bool matches(item, Map matchState) => item == null; | 46 bool matches(item, Map matchState) => item == null; |
38 Description describe(Description description) => description.add('null'); | 47 Description describe(Description description) => description.add('null'); |
(...skipping 600 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
639 addDescriptionOf(matchState['feature']); | 648 addDescriptionOf(matchState['feature']); |
640 var innerDescription = new StringDescription(); | 649 var innerDescription = new StringDescription(); |
641 _matcher.describeMismatch(matchState['feature'], innerDescription, | 650 _matcher.describeMismatch(matchState['feature'], innerDescription, |
642 matchState['state'], verbose); | 651 matchState['state'], verbose); |
643 if (innerDescription.length > 0) { | 652 if (innerDescription.length > 0) { |
644 mismatchDescription.add(' which ').add(innerDescription.toString()); | 653 mismatchDescription.add(' which ').add(innerDescription.toString()); |
645 } | 654 } |
646 return mismatchDescription; | 655 return mismatchDescription; |
647 } | 656 } |
648 } | 657 } |
OLD | NEW |