OLD | NEW |
---|---|
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 part of matcher; | 5 part of matcher; |
6 | 6 |
7 /** | 7 /** |
8 * Returns a matcher which matches [Iterable]s in which all elements | 8 * Returns a matcher which matches [Iterable]s in which all elements |
9 * match the given [matcher]. | 9 * match the given [matcher]. |
10 */ | 10 */ |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
51 } | 51 } |
52 mismatchDescription.add(' at index $index'); | 52 mismatchDescription.add(' at index $index'); |
53 return mismatchDescription; | 53 return mismatchDescription; |
54 } | 54 } |
55 return super.describeMismatch(item, mismatchDescription, | 55 return super.describeMismatch(item, mismatchDescription, |
56 matchState, verbose); | 56 matchState, verbose); |
57 } | 57 } |
58 } | 58 } |
59 | 59 |
60 /** | 60 /** |
61 * Deprecated form of [anyElement]. | |
62 */ | |
63 @deprecated | |
64 Matcher someElement(matcher) => new _AnyElement(wrapMatcher(matcher)); | |
65 | |
66 /** | |
61 * Returns a matcher which matches [Iterable]s in which at least one | 67 * Returns a matcher which matches [Iterable]s in which at least one |
62 * element matches the given [matcher]. | 68 * element matches the given [matcher]. |
63 */ | 69 */ |
64 Matcher someElement(matcher) => new _SomeElement(wrapMatcher(matcher)); | 70 Matcher anyElement(matcher) => new _AnyElement(wrapMatcher(matcher)); |
65 | 71 |
66 class _SomeElement extends _IterableMatcher { | 72 class _AnyElement extends _IterableMatcher { |
67 Matcher _matcher; | 73 Matcher _matcher; |
68 | 74 |
69 _SomeElement(this._matcher); | 75 _AnyElement(this._matcher); |
70 | 76 |
71 bool matches(item, Map matchState) { | 77 bool matches(item, Map matchState) { |
72 return item.any((e) => _matcher.matches(e, matchState)); | 78 return item.any((e) => _matcher.matches(e, matchState)); |
Sean Eagan
2013/07/25 16:55:15
In describe below, 'some element ' -> 'any element
gram
2013/07/25 17:07:05
I thought about that but IMO 'some element' reads
| |
73 } | 79 } |
74 | 80 |
75 Description describe(Description description) => | 81 Description describe(Description description) => |
76 description.add('some element ').addDescriptionOf(_matcher); | 82 description.add('some element ').addDescriptionOf(_matcher); |
77 } | 83 } |
78 | 84 |
79 /** | 85 /** |
80 * Returns a matcher which matches [Iterable]s that have the same | 86 * Returns a matcher which matches [Iterable]s that have the same |
81 * length and the same elements as [expected], and in the same order. | 87 * length and the same elements as [expected], and in the same order. |
82 * This is equivalent to equals but does not recurse. | 88 * This is equivalent to equals but does not recurse. |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
240 return mismatchDescription. | 246 return mismatchDescription. |
241 add('has '). | 247 add('has '). |
242 addDescriptionOf(matchState["actual"]). | 248 addDescriptionOf(matchState["actual"]). |
243 add(' which is not $_description '). | 249 add(' which is not $_description '). |
244 addDescriptionOf(matchState["expected"]). | 250 addDescriptionOf(matchState["expected"]). |
245 add(' at index ${matchState["index"]}'); | 251 add(' at index ${matchState["index"]}'); |
246 } | 252 } |
247 } | 253 } |
248 } | 254 } |
249 | 255 |
OLD | NEW |