@@ -43,28 +43,32 @@ class _SomeElement extends _CollectionMatcher {
43
43
/**
44
44
* Returns a matcher which matches [Iterable] s that have the same
45
45
* length and the same elements as [expected] , and in the same order.
46
+ * This is equivalent to equals but does not recurse.
46
47
*/
48
+
47
49
Matcher orderedEquals (Iterable expected) => new _OrderedEquals (expected);
48
50
49
51
class _OrderedEquals extends BaseMatcher {
50
- Iterable _expected;
51
-
52
- _OrderedEquals (this ._expected);
52
+ final Iterable _expected;
53
+ Matcher _matcher;
53
54
54
- String _test (item) {
55
- return _compareIterables (_expected, item,
56
- (expected, actual, location) => expected == actual? null : location);
55
+ _OrderedEquals (this ._expected) {
56
+ _matcher = equals (_expected, 1 );
57
57
}
58
58
59
- bool matches (item) => (_test ( item) == null );
59
+ bool matches (item) => (item is Iterable ) && _matcher. matches (item );
60
60
61
61
Description describe (Description description) =>
62
62
description.add ('equals ' ).addDescriptionOf (_expected).add (' ordered' );
63
63
64
- Description describeMismatch (item, Description mismatchDescription) =>
65
- mismatchDescription.add (_test (item));
64
+ Description describeMismatch (item, Description mismatchDescription) {
65
+ if (item is ! Iterable ) {
66
+ return mismatchDescription.add ('not an Iterable' );
67
+ } else {
68
+ return _matcher.describeMismatch (item, mismatchDescription);
69
+ }
70
+ }
66
71
}
67
-
68
72
/**
69
73
* Returns a matcher which matches [Iterable] s that have the same
70
74
* length and the same elements as [expected] , but not necessarily in
@@ -124,8 +128,11 @@ class _UnorderedEquals extends BaseMatcher {
124
128
++ actualPosition;
125
129
}
126
130
if (! gotMatch) {
127
- return 'has no match for element ${expectedElement } '
128
- 'at position ${expectedPosition }' ;
131
+ Description reason = new StringDescription ();
132
+ reason.add ('has no match for element ' ).
133
+ addDescriptionOf (expectedElement).
134
+ add (' at position ${expectedPosition }' );
135
+ return reason.toString ();
129
136
}
130
137
++ expectedPosition;
131
138
}
@@ -145,8 +152,7 @@ class _UnorderedEquals extends BaseMatcher {
145
152
* Collection matchers match against [Collection] s. We add this intermediate
146
153
* class to give better mismatch error messages than the base Matcher class.
147
154
*/
148
-
149
- /*abstract*/ class _CollectionMatcher extends BaseMatcher {
155
+ /* abstract */ class _CollectionMatcher extends BaseMatcher {
150
156
const _CollectionMatcher ();
151
157
Description describeMismatch (item, Description mismatchDescription) {
152
158
if (item is ! Collection ) {
0 commit comments