| 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 iterables | 8 * Returns a matcher that matches empty strings, maps or iterables |
| 9 * (including collections). | 9 * (including collections). |
| 10 */ | 10 */ |
| (...skipping 690 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 701 * | 701 * |
| 702 * and then use this for example like: | 702 * and then use this for example like: |
| 703 * | 703 * |
| 704 * expect(inventoryItem, new HasPrice(greaterThan(0))); | 704 * expect(inventoryItem, new HasPrice(greaterThan(0))); |
| 705 */ | 705 */ |
| 706 class CustomMatcher extends BaseMatcher { | 706 class CustomMatcher extends BaseMatcher { |
| 707 final String _featureDescription; | 707 final String _featureDescription; |
| 708 final String _featureName; | 708 final String _featureName; |
| 709 final Matcher _matcher; | 709 final Matcher _matcher; |
| 710 | 710 |
| 711 const CustomMatcher(this._featureDescription, this._featureName, matcher) | 711 CustomMatcher(this._featureDescription, this._featureName, matcher) |
| 712 : this._matcher = wrapMatcher(matcher); | 712 : this._matcher = wrapMatcher(matcher); |
| 713 | 713 |
| 714 /** Override this to extract the interesting feature.*/ | 714 /** Override this to extract the interesting feature.*/ |
| 715 featureValueOf(actual) => actual; | 715 featureValueOf(actual) => actual; |
| 716 | 716 |
| 717 bool matches(item, MatchState matchState) { | 717 bool matches(item, MatchState matchState) { |
| 718 var f = featureValueOf(item); | 718 var f = featureValueOf(item); |
| 719 if (_matcher.matches(f, matchState)) return true; | 719 if (_matcher.matches(f, matchState)) return true; |
| 720 matchState.state = { 'innerState': matchState.state, 'feature': f }; | 720 matchState.state = { 'innerState': matchState.state, 'feature': f }; |
| 721 return false; | 721 return false; |
| 722 } | 722 } |
| 723 | 723 |
| 724 Description describe(Description description) => | 724 Description describe(Description description) => |
| 725 description.add(_featureDescription).add(' ').addDescriptionOf(_matcher); | 725 description.add(_featureDescription).add(' ').addDescriptionOf(_matcher); |
| 726 | 726 |
| 727 Description describeMismatch(item, Description mismatchDescription, | 727 Description describeMismatch(item, Description mismatchDescription, |
| 728 MatchState matchState, bool verbose) { | 728 MatchState matchState, bool verbose) { |
| 729 mismatchDescription.add(_featureName).add(' '); | 729 mismatchDescription.add(_featureName).add(' '); |
| 730 _matcher.describeMismatch(matchState.state['feature'], mismatchDescription, | 730 _matcher.describeMismatch(matchState.state['feature'], mismatchDescription, |
| 731 matchState.state['innerState'], verbose); | 731 matchState.state['innerState'], verbose); |
| 732 return mismatchDescription; | 732 return mismatchDescription; |
| 733 } | 733 } |
| 734 } | 734 } |
| OLD | NEW |