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). |
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 if (item is Map || item is Iterable) { |
19 return item.isEmpty; | 19 return item.isEmpty; |
20 } else if (item is String) { | 20 } else if (item is String) { |
Lasse Reichstein Nielsen
2014/11/27 15:22:46
Consider merging String into the previous "if"-con
dskloet
2014/11/27 15:27:53
It could just be:
return (item is Map || item is
blackhc
2014/11/28 16:12:29
Done.
| |
21 return item.length == 0; | 21 return item.length == 0; |
22 } else { | 22 } else { |
23 return false; | 23 return false; |
24 } | 24 } |
25 } | 25 } |
26 Description describe(Description description) => description.add('empty'); | 26 Description describe(Description description) => description.add('empty'); |
27 } | 27 } |
28 | 28 |
29 /// Returns a matcher that matches non-empty strings, maps or iterables | |
30 // (including collections). | |
Lasse Reichstein Nielsen
2014/11/27 15:22:46
Second line isn't part of dartdoc-comment.
Docume
blackhc
2014/11/28 16:12:29
Done.
| |
31 const Matcher isNotEmpty = const _NotEmpty(); | |
32 | |
33 class _NotEmpty extends Matcher { | |
34 const _NotEmpty(); | |
35 bool matches(item, Map matchState) { | |
36 if (item is Map || item is Iterable || item is String) { | |
dskloet
2014/11/27 15:27:53
return (item is Map || item is Iterable || item is
blackhc
2014/11/28 16:12:29
Done.
| |
37 return item.isNotEmpty; | |
38 } else { | |
39 return false; | |
40 } | |
41 } | |
42 Description describe(Description description) => description.add('non-empty'); | |
43 } | |
44 | |
29 /// A matcher that matches any null value. | 45 /// A matcher that matches any null value. |
30 const Matcher isNull = const _IsNull(); | 46 const Matcher isNull = const _IsNull(); |
31 | 47 |
32 /// A matcher that matches any non-null value. | 48 /// A matcher that matches any non-null value. |
33 const Matcher isNotNull = const _IsNotNull(); | 49 const Matcher isNotNull = const _IsNotNull(); |
34 | 50 |
35 class _IsNull extends Matcher { | 51 class _IsNull extends Matcher { |
36 const _IsNull(); | 52 const _IsNull(); |
37 bool matches(item, Map matchState) => item == null; | 53 bool matches(item, Map matchState) => item == null; |
38 Description describe(Description description) => description.add('null'); | 54 Description describe(Description description) => description.add('null'); |
(...skipping 600 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
639 addDescriptionOf(matchState['feature']); | 655 addDescriptionOf(matchState['feature']); |
640 var innerDescription = new StringDescription(); | 656 var innerDescription = new StringDescription(); |
641 _matcher.describeMismatch(matchState['feature'], innerDescription, | 657 _matcher.describeMismatch(matchState['feature'], innerDescription, |
642 matchState['state'], verbose); | 658 matchState['state'], verbose); |
643 if (innerDescription.length > 0) { | 659 if (innerDescription.length > 0) { |
644 mismatchDescription.add(' which ').add(innerDescription.toString()); | 660 mismatchDescription.add(' which ').add(innerDescription.toString()); |
645 } | 661 } |
646 return mismatchDescription; | 662 return mismatchDescription; |
647 } | 663 } |
648 } | 664 } |
OLD | NEW |