Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(140)

Side by Side Diff: pkg/unittest/lib/src/core_matchers.dart

Issue 14333023: The matcher argument to the CustomMatcher constructor no longer has to be a matcher; it will be wra… (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | pkg/unittest/test/matchers_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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, 711 const CustomMatcher(this._featureDescription, this._featureName, matcher)
712 this._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 }
OLDNEW
« no previous file with comments | « no previous file | pkg/unittest/test/matchers_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698