Chromium Code Reviews| Index: lib/unittest/collection_matchers.dart |
| =================================================================== |
| --- lib/unittest/collection_matchers.dart (revision 8828) |
| +++ lib/unittest/collection_matchers.dart (working copy) |
| @@ -43,28 +43,37 @@ |
| /** |
| * 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; |
| + Matcher _matcher; |
|
Bob Nystrom
2012/06/19 23:38:33
Can you make these final?
gram
2012/06/20 17:44:14
_expected yes, _matcher no
|
| - _OrderedEquals(this._expected); |
| + _OrderedEquals(this._expected) { |
| + _matcher = equals(_expected, 1); |
| + } |
| - String _test(item) { |
| - return _compareIterables(_expected, item, |
| - (expected, actual, location) => expected == actual? null : location); |
| + bool matches(item) { |
|
Bob Nystrom
2012/06/19 23:38:33
=> (item is Iterable) && _matcher.matches(item);
gram
2012/06/20 17:44:14
Done.
|
| + if (item is !Iterable) { |
| + return false; |
| + } |
| + return _matcher.matches(item); |
| } |
| - bool matches(item) => (_test(item) == null); |
| - |
| 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 +133,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 +157,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) { |