Chromium Code Reviews| 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 bool matches(item, Map matchState) { | |
|
nweiz
2014/12/01 22:18:07
Nit: empty lines between members.
The existing co
blackhc
2014/12/03 10:07:17
Done.
| |
| 30 return (item is Map || item is Iterable || item is String) && | |
| 31 item.isNotEmpty; | |
| 32 } | |
| 33 Description describe(Description description) => description.add('non-empty'); | |
| 34 } | |
| 35 | |
| 29 /// A matcher that matches any null value. | 36 /// A matcher that matches any null value. |
| 30 const Matcher isNull = const _IsNull(); | 37 const Matcher isNull = const _IsNull(); |
| 31 | 38 |
| 32 /// A matcher that matches any non-null value. | 39 /// A matcher that matches any non-null value. |
| 33 const Matcher isNotNull = const _IsNotNull(); | 40 const Matcher isNotNull = const _IsNotNull(); |
| 34 | 41 |
| 35 class _IsNull extends Matcher { | 42 class _IsNull extends Matcher { |
| 36 const _IsNull(); | 43 const _IsNull(); |
| 37 bool matches(item, Map matchState) => item == null; | 44 bool matches(item, Map matchState) => item == null; |
| 38 Description describe(Description description) => description.add('null'); | 45 Description describe(Description description) => description.add('null'); |
| (...skipping 600 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 639 addDescriptionOf(matchState['feature']); | 646 addDescriptionOf(matchState['feature']); |
| 640 var innerDescription = new StringDescription(); | 647 var innerDescription = new StringDescription(); |
| 641 _matcher.describeMismatch(matchState['feature'], innerDescription, | 648 _matcher.describeMismatch(matchState['feature'], innerDescription, |
| 642 matchState['state'], verbose); | 649 matchState['state'], verbose); |
| 643 if (innerDescription.length > 0) { | 650 if (innerDescription.length > 0) { |
| 644 mismatchDescription.add(' which ').add(innerDescription.toString()); | 651 mismatchDescription.add(' which ').add(innerDescription.toString()); |
| 645 } | 652 } |
| 646 return mismatchDescription; | 653 return mismatchDescription; |
| 647 } | 654 } |
| 648 } | 655 } |
| OLD | NEW |