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

Unified Diff: pkg/matcher/lib/src/core_matchers.dart

Issue 763783003: Add isNotEmpty to core_matchers. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Style fixes Created 6 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | pkg/matcher/test/core_matchers_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/matcher/lib/src/core_matchers.dart
diff --git a/pkg/matcher/lib/src/core_matchers.dart b/pkg/matcher/lib/src/core_matchers.dart
index c3c996d908f27b76033061e179bd73530abe8e45..64a7a8b131df1d63d7395e35b7a631d081b1d3db 100644
--- a/pkg/matcher/lib/src/core_matchers.dart
+++ b/pkg/matcher/lib/src/core_matchers.dart
@@ -9,23 +9,32 @@ import 'interfaces.dart';
import 'util.dart';
/// Returns a matcher that matches empty strings, maps or iterables
-/// (including collections).
+/// (including collections) using the isEmpty property.
const Matcher isEmpty = const _Empty();
class _Empty extends Matcher {
const _Empty();
bool matches(item, Map matchState) {
- if (item is Map || item is Iterable) {
- return item.isEmpty;
- } else if (item is String) {
- return item.length == 0;
- } else {
- return false;
- }
+ return (item is Map || item is Iterable || item is String) && item.isEmpty;
}
Description describe(Description description) => description.add('empty');
}
+/// Returns a matcher that matches non-empty strings, maps or iterables
+/// (including collections) using the isNotEmpty property.
+const Matcher isNotEmpty = const _NotEmpty();
+
+class _NotEmpty extends Matcher {
+ const _NotEmpty();
+
+ bool matches(item, Map matchState) {
+ return (item is Map || item is Iterable || item is String) &&
+ item.isNotEmpty;
+ }
+
+ Description describe(Description description) => description.add('non-empty');
+}
+
/// A matcher that matches any null value.
const Matcher isNull = const _IsNull();
« no previous file with comments | « no previous file | pkg/matcher/test/core_matchers_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698