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

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

Issue 12224053: Updated contains and isEmpty matches to use iterables. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Update doc-comments Created 7 years, 10 months 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/unittest/test/matchers_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/unittest/lib/src/core_matchers.dart
diff --git a/pkg/unittest/lib/src/core_matchers.dart b/pkg/unittest/lib/src/core_matchers.dart
index 449990b0b1518710fb892a4e00bfe0dfc361cfb8..aef79b244fc551d5e464f6711b8cd360efc24c57 100644
--- a/pkg/unittest/lib/src/core_matchers.dart
+++ b/pkg/unittest/lib/src/core_matchers.dart
@@ -5,14 +5,15 @@
part of matcher;
/**
- * Returns a matcher that matches empty strings, maps or collections.
+ * Returns a matcher that matches empty strings, maps or iterables
+ * (including collections).
*/
const Matcher isEmpty = const _Empty();
class _Empty extends BaseMatcher {
const _Empty();
bool matches(item, MatchState matchState) {
- if (item is Map || item is Collection) {
+ if (item is Map || item is Iterable) {
return item.isEmpty;
} else if (item is String) {
return item.length == 0;
@@ -572,9 +573,10 @@ class _HasLength extends BaseMatcher {
/**
* Returns a matcher that matches if the match argument contains
* the expected value. For [String]s this means substring matching;
- * for [Map]s is means the map has the key, and for [Collection]s it
- * means the collection has a matching element. In the case of collections,
- * [expected] can itself be a matcher.
+ * for [Map]s is means the map has the key, and for [Iterable]s
gram 2013/02/07 17:35:23 While you're at it can you correct the comment? "i
butlermatt 2013/02/07 17:50:15 Done.
+ * (including [Collection]s) it means the iterable has a matching
+ * element. In the case of iterables, [expected] can itself be a
+ * matcher.
*/
Matcher contains(expected) => new _Contains(expected);
@@ -587,11 +589,11 @@ class _Contains extends BaseMatcher {
bool matches(item, MatchState matchState) {
if (item is String) {
return item.indexOf(_expected) >= 0;
- } else if (item is Collection) {
+ } else if (item is Iterable) {
if (_expected is Matcher) {
return item.any((e) => _expected.matches(e, matchState));
} else {
- return item.any((e) => e == _expected);
+ return item.contains(_expected);
}
} else if (item is Map) {
return item.containsKey(_expected);
« no previous file with comments | « no previous file | pkg/unittest/test/matchers_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698