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

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: Code review changes Created 6 years, 1 month 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
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..5e477f48a56d8010b607a1f49825aedcf148eda6 100644
--- a/pkg/matcher/lib/src/core_matchers.dart
+++ b/pkg/matcher/lib/src/core_matchers.dart
@@ -9,23 +9,30 @@ 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) {
nweiz 2014/12/01 22:18:07 Nit: empty lines between members. The existing co
blackhc 2014/12/03 10:07:17 Done.
+ 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/iterable_matchers_test.dart » ('j') | pkg/matcher/test/matchers_unminified_test.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698