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 | 5 |
6 /** | 6 /** |
7 * Returns a matcher that matches empty strings, maps or collections. | 7 * Returns a matcher that matches empty strings, maps or collections. |
8 */ | 8 */ |
9 const Matcher isEmpty = const _Empty(); | 9 const Matcher isEmpty = const _Empty(); |
10 | 10 |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
95 | 95 |
96 String _compareIterables(expected, actual, matcher, depth) { | 96 String _compareIterables(expected, actual, matcher, depth) { |
97 if (actual is !Iterable) { | 97 if (actual is !Iterable) { |
98 return 'is not Iterable'; | 98 return 'is not Iterable'; |
99 } | 99 } |
100 var expectedIterator = expected.iterator(); | 100 var expectedIterator = expected.iterator(); |
101 var actualIterator = actual.iterator(); | 101 var actualIterator = actual.iterator(); |
102 var position = 0; | 102 var position = 0; |
103 String reason = null; | 103 String reason = null; |
104 while (reason == null) { | 104 while (reason == null) { |
105 if (expectedIterator.hasNext()) { | 105 if (expectedIterator.hasNext) { |
106 if (actualIterator.hasNext()) { | 106 if (actualIterator.hasNext) { |
107 Description r = matcher(expectedIterator.next(), | 107 Description r = matcher(expectedIterator.next(), |
108 actualIterator.next(), | 108 actualIterator.next(), |
109 'mismatch at position ${position}', | 109 'mismatch at position ${position}', |
110 depth); | 110 depth); |
111 if (r != null) reason = r.toString(); | 111 if (r != null) reason = r.toString(); |
112 ++position; | 112 ++position; |
113 } else { | 113 } else { |
114 reason = 'shorter than expected'; | 114 reason = 'shorter than expected'; |
115 } | 115 } |
116 } else if (actualIterator.hasNext()) { | 116 } else if (actualIterator.hasNext) { |
117 reason = 'longer than expected'; | 117 reason = 'longer than expected'; |
118 } else { | 118 } else { |
119 return null; | 119 return null; |
120 } | 120 } |
121 } | 121 } |
122 return reason; | 122 return reason; |
123 } | 123 } |
124 | 124 |
125 Description _recursiveMatch(expected, actual, String location, int depth) { | 125 Description _recursiveMatch(expected, actual, String location, int depth) { |
126 Description reason = null; | 126 Description reason = null; |
(...skipping 491 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
618 final _matcher; | 618 final _matcher; |
619 final String _description; | 619 final String _description; |
620 | 620 |
621 const _Predicate(this._matcher, this._description); | 621 const _Predicate(this._matcher, this._description); |
622 | 622 |
623 bool matches(item, MatchState matchState) => _matcher(item); | 623 bool matches(item, MatchState matchState) => _matcher(item); |
624 | 624 |
625 Description describe(Description description) => | 625 Description describe(Description description) => |
626 description.add(_description); | 626 description.add(_description); |
627 } | 627 } |
OLD | NEW |