Chromium Code Reviews| 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 final Matcher isEmpty = const _Empty(); | 9 final Matcher isEmpty = const _Empty(); |
| 10 | 10 |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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 reason = 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(); | |
|
srdjan
2012/06/21 00:07:33
Why guard it (r != null)?
(null).toString() shoul
| |
| 111 ++position; | 112 ++position; |
| 112 } else { | 113 } else { |
| 113 reason = 'shorter than expected'; | 114 reason = 'shorter than expected'; |
| 114 } | 115 } |
| 115 } else if (actualIterator.hasNext()) { | 116 } else if (actualIterator.hasNext()) { |
| 116 reason = 'longer than expected'; | 117 reason = 'longer than expected'; |
| 117 } else { | 118 } else { |
| 118 return null; | 119 return null; |
| 119 } | 120 } |
| 120 } | 121 } |
| (...skipping 459 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 580 final _matcher; | 581 final _matcher; |
| 581 final String _description; | 582 final String _description; |
| 582 | 583 |
| 583 const _Predicate(this._matcher, this._description); | 584 const _Predicate(this._matcher, this._description); |
| 584 | 585 |
| 585 bool matches(item) => _matcher(item); | 586 bool matches(item) => _matcher(item); |
| 586 | 587 |
| 587 Description describe(Description description) => | 588 Description describe(Description description) => |
| 588 description.add(_description); | 589 description.add(_description); |
| 589 } | 590 } |
| OLD | NEW |