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 part of matcher; | 5 part of matcher; |
| 6 | 6 |
| 7 /** | 7 /** |
| 8 * Returns a matcher that matches empty strings, maps or collections. | 8 * Returns a matcher that matches empty strings, maps or collections. |
| 9 */ | 9 */ |
| 10 const Matcher isEmpty = const _Empty(); | 10 const Matcher isEmpty = const _Empty(); |
| 11 | 11 |
| 12 class _Empty extends BaseMatcher { | 12 class _Empty extends BaseMatcher { |
| 13 const _Empty(); | 13 const _Empty(); |
| 14 bool matches(item, MatchState matchState) { | 14 bool matches(item, MatchState matchState) { |
| 15 if (item is Map || item is Collection) { | 15 if (item is Map || item is Iterable) { |
| 16 return item.isEmpty; | 16 return item.isEmpty; |
| 17 } else if (item is String) { | 17 } else if (item is String) { |
| 18 return item.length == 0; | 18 return item.length == 0; |
| 19 } else { | 19 } else { |
| 20 return false; | 20 return false; |
| 21 } | 21 } |
| 22 } | 22 } |
| 23 Description describe(Description description) => | 23 Description describe(Description description) => |
| 24 description.add('empty'); | 24 description.add('empty'); |
| 25 } | 25 } |
| (...skipping 554 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 580 | 580 |
| 581 class _Contains extends BaseMatcher { | 581 class _Contains extends BaseMatcher { |
| 582 | 582 |
| 583 final _expected; | 583 final _expected; |
| 584 | 584 |
| 585 const _Contains(this._expected); | 585 const _Contains(this._expected); |
| 586 | 586 |
| 587 bool matches(item, MatchState matchState) { | 587 bool matches(item, MatchState matchState) { |
| 588 if (item is String) { | 588 if (item is String) { |
| 589 return item.indexOf(_expected) >= 0; | 589 return item.indexOf(_expected) >= 0; |
| 590 } else if (item is Collection) { | 590 } else if (item is Iterable) { |
| 591 if (_expected is Matcher) { | 591 if (_expected is Matcher) { |
| 592 return item.any((e) => _expected.matches(e, matchState)); | 592 return item.any((e) => _expected.matches(e, matchState)); |
| 593 } else { | 593 } else { |
| 594 return item.any((e) => e == _expected); | 594 return item.contains(_expected); |
|
butlermatt
2013/02/07 15:30:28
I changed this to contains(), to allow Iterables t
| |
| 595 } | 595 } |
| 596 } else if (item is Map) { | 596 } else if (item is Map) { |
| 597 return item.containsKey(_expected); | 597 return item.containsKey(_expected); |
| 598 } | 598 } |
| 599 return false; | 599 return false; |
| 600 } | 600 } |
| 601 | 601 |
| 602 Description describe(Description description) => | 602 Description describe(Description description) => |
| 603 description.add('contains ').addDescriptionOf(_expected); | 603 description.add('contains ').addDescriptionOf(_expected); |
| 604 } | 604 } |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 695 description.add(_featureDescription).add(' ').addDescriptionOf(_matcher); | 695 description.add(_featureDescription).add(' ').addDescriptionOf(_matcher); |
| 696 | 696 |
| 697 Description describeMismatch(item, Description mismatchDescription, | 697 Description describeMismatch(item, Description mismatchDescription, |
| 698 MatchState matchState, bool verbose) { | 698 MatchState matchState, bool verbose) { |
| 699 mismatchDescription.add(_featureName).add(' '); | 699 mismatchDescription.add(_featureName).add(' '); |
| 700 _matcher.describeMismatch(matchState.state['feature'], mismatchDescription, | 700 _matcher.describeMismatch(matchState.state['feature'], mismatchDescription, |
| 701 matchState.state['innerState'], verbose); | 701 matchState.state['innerState'], verbose); |
| 702 return mismatchDescription; | 702 return mismatchDescription; |
| 703 } | 703 } |
| 704 } | 704 } |
| OLD | NEW |