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

Unified Diff: lib/unittest/collection_matchers.dart

Issue 10579008: Added test setup/teardown. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 6 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 8913)
+++ lib/unittest/collection_matchers.dart (working copy)
@@ -43,28 +43,32 @@
/**
* Returns a matcher which matches [Iterable]s that have the same
* length and the same elements as [expected], and in the same order.
+ * This is equivalent to equals but does not recurse.
*/
+
Matcher orderedEquals(Iterable expected) => new _OrderedEquals(expected);
class _OrderedEquals extends BaseMatcher {
- Iterable _expected;
+ final Iterable _expected;
+ Matcher _matcher;
- _OrderedEquals(this._expected);
-
- String _test(item) {
- return _compareIterables(_expected, item,
- (expected, actual, location) => expected == actual? null : location);
+ _OrderedEquals(this._expected) {
+ _matcher = equals(_expected, 1);
}
- bool matches(item) => (_test(item) == null);
+ bool matches(item) => (item is Iterable) && _matcher.matches(item);
Description describe(Description description) =>
description.add('equals ').addDescriptionOf(_expected).add(' ordered');
- Description describeMismatch(item, Description mismatchDescription) =>
- mismatchDescription.add(_test(item));
+ Description describeMismatch(item, Description mismatchDescription) {
+ if (item is !Iterable) {
+ return mismatchDescription.add('not an Iterable');
+ } else {
+ return _matcher.describeMismatch(item, mismatchDescription);
+ }
+ }
}
-
/**
* Returns a matcher which matches [Iterable]s that have the same
* length and the same elements as [expected], but not necessarily in
@@ -124,8 +128,11 @@
++actualPosition;
}
if (!gotMatch) {
- return 'has no match for element ${expectedElement} '
- 'at position ${expectedPosition}';
+ Description reason = new StringDescription();
+ reason.add('has no match for element ').
+ addDescriptionOf(expectedElement).
+ add(' at position ${expectedPosition}');
+ return reason.toString();
}
++expectedPosition;
}
@@ -145,8 +152,7 @@
* Collection matchers match against [Collection]s. We add this intermediate
* class to give better mismatch error messages than the base Matcher class.
*/
-
-/*abstract*/ class _CollectionMatcher extends BaseMatcher {
+/* abstract */ class _CollectionMatcher extends BaseMatcher {
const _CollectionMatcher();
Description describeMismatch(item, Description mismatchDescription) {
if (item is !Collection) {
« 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