Skip to content

Commit 94f7022

Browse files
Added test setup/teardown.
Made default matcher isTrue. Made the exception matchers work with dart2js. Added isIn matcher. equals() now recurses. Review URL: https://chromiumcodereview.appspot.com//10579008 git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@8951 260f80e4-7a28-3924-810f-c04153c831b5
1 parent 5f509dc commit 94f7022

10 files changed

+525
-219
lines changed

lib/unittest/collection_matchers.dart

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -43,28 +43,32 @@ class _SomeElement extends _CollectionMatcher {
4343
/**
4444
* Returns a matcher which matches [Iterable]s that have the same
4545
* length and the same elements as [expected], and in the same order.
46+
* This is equivalent to equals but does not recurse.
4647
*/
48+
4749
Matcher orderedEquals(Iterable expected) => new _OrderedEquals(expected);
4850

4951
class _OrderedEquals extends BaseMatcher {
50-
Iterable _expected;
51-
52-
_OrderedEquals(this._expected);
52+
final Iterable _expected;
53+
Matcher _matcher;
5354

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);
5757
}
5858

59-
bool matches(item) => (_test(item) == null);
59+
bool matches(item) => (item is Iterable) && _matcher.matches(item);
6060

6161
Description describe(Description description) =>
6262
description.add('equals ').addDescriptionOf(_expected).add(' ordered');
6363

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+
}
6671
}
67-
6872
/**
6973
* Returns a matcher which matches [Iterable]s that have the same
7074
* length and the same elements as [expected], but not necessarily in
@@ -124,8 +128,11 @@ class _UnorderedEquals extends BaseMatcher {
124128
++actualPosition;
125129
}
126130
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();
129136
}
130137
++expectedPosition;
131138
}
@@ -145,8 +152,7 @@ class _UnorderedEquals extends BaseMatcher {
145152
* Collection matchers match against [Collection]s. We add this intermediate
146153
* class to give better mismatch error messages than the base Matcher class.
147154
*/
148-
149-
/*abstract*/ class _CollectionMatcher extends BaseMatcher {
155+
/* abstract */ class _CollectionMatcher extends BaseMatcher {
150156
const _CollectionMatcher();
151157
Description describeMismatch(item, Description mismatchDescription) {
152158
if (item is !Collection) {

0 commit comments

Comments
 (0)