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

Unified Diff: lib/unittest/collection_matchers.dart

Issue 10832058: Improved the way we generate mismatch descriptions. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 5 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 | lib/unittest/core_matchers.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/unittest/collection_matchers.dart
===================================================================
--- lib/unittest/collection_matchers.dart (revision 10002)
+++ lib/unittest/collection_matchers.dart (working copy)
@@ -13,12 +13,39 @@
_EveryElement(Matcher this._matcher);
- bool matches(item) {
- return item.every((e) => _matcher.matches(e));
+ bool matches(item, MatchState matchState) {
+ if (item is! Iterable) {
+ return false;
+ }
+ var i = 0;
+ for (var element in item) {
+ if (!_matcher.matches(element, matchState)) {
+ matchState.state = {
+ 'index': i,
+ 'element': element,
+ 'state': matchState.state
+ };
+ return false;
+ }
+ ++i;
+ }
+ return true;
}
Description describe(Description description) =>
description.add('every element ').addDescriptionOf(_matcher);
+
+ Description describeMismatch(item, Description mismatchDescription,
+ MatchState matchState, bool verbose) {
+ if (matchState.state != null) {
+ var index = matchState.state['index'];
+ var element = matchState.state['element'];
+ return _matcher.describeMismatch(element, mismatchDescription,
+ matchState.state['state'], verbose).add(' at position $index');
+ }
+ return super.describeMismatch(item, mismatchDescription,
+ matchState, verbose);
+ }
}
/**
@@ -32,8 +59,8 @@
_SomeElement(this._matcher);
- bool matches(item) {
- return item.some( (e) => _matcher.matches(e) );
+ bool matches(item, MatchState matchState) {
+ return item.some( (e) => _matcher.matches(e, matchState) );
}
Description describe(Description description) =>
@@ -56,16 +83,19 @@
_matcher = equals(_expected, 1);
}
- bool matches(item) => (item is Iterable) && _matcher.matches(item);
+ bool matches(item, MatchState matchState) =>
+ (item is Iterable) && _matcher.matches(item, matchState);
Description describe(Description description) =>
description.add('equals ').addDescriptionOf(_expected).add(' ordered');
- Description describeMismatch(item, Description mismatchDescription) {
+ Description describeMismatch(item, Description mismatchDescription,
+ MatchState matchState, bool verbose) {
if (item is !Iterable) {
return mismatchDescription.add('not an Iterable');
} else {
- return _matcher.describeMismatch(item, mismatchDescription);
+ return _matcher.describeMismatch(item, mismatchDescription,
+ matchState, verbose);
}
}
}
@@ -139,12 +169,13 @@
return null;
}
- bool matches(item) => (_test(item) == null);
+ bool matches(item, MatchState mismatchState) => (_test(item) == null);
Description describe(Description description) =>
description.add('equals ').addDescriptionOf(_expected).add(' unordered');
- Description describeMismatch(item, Description mismatchDescription) =>
+ Description describeMismatch(item, Description mismatchDescription,
+ MatchState matchState, bool verbose) =>
mismatchDescription.add(_test(item));
}
@@ -154,13 +185,15 @@
*/
/* abstract */ class _CollectionMatcher extends BaseMatcher {
const _CollectionMatcher();
- Description describeMismatch(item, Description mismatchDescription) {
+ Description describeMismatch(item, Description mismatchDescription,
+ MatchState matchState, bool verbose) {
if (item is !Collection) {
return mismatchDescription.
addDescriptionOf(item).
add(' not a collection');
} else {
- return super.describeMismatch(item, mismatchDescription);
+ return super.describeMismatch(item, mismatchDescription, matchState,
+ verbose);
}
}
}
« no previous file with comments | « no previous file | lib/unittest/core_matchers.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698