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

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

Issue 12193016: Added an example of the use of predicate. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 10 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 | no next file » | 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 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();
(...skipping 614 matching lines...) Expand 10 before | Expand all | Expand 10 after
625 } 625 }
626 return false; 626 return false;
627 } 627 }
628 628
629 Description describe(Description description) => 629 Description describe(Description description) =>
630 description.add('is in ').addDescriptionOf(_expected); 630 description.add('is in ').addDescriptionOf(_expected);
631 } 631 }
632 632
633 /** 633 /**
634 * Returns a matcher that uses an arbitrary function that returns 634 * Returns a matcher that uses an arbitrary function that returns
635 * true or false for the actual value. 635 * true or false for the actual value. For example:
636 *
637 * expect(v, predicate((x) => ((x % 2) == 0), "is even"))
636 */ 638 */
637 Matcher predicate(f, [description ='satisfies function']) => 639 Matcher predicate(Function f, [description ='satisfies function']) =>
638 new _Predicate(f, description); 640 new _Predicate(f, description);
639 641
640 class _Predicate extends BaseMatcher { 642 class _Predicate extends BaseMatcher {
641 643
642 final _matcher; 644 final Function _matcher;
643 final String _description; 645 final String _description;
644 646
645 const _Predicate(this._matcher, this._description); 647 const _Predicate(this._matcher, this._description);
646 648
647 bool matches(item, MatchState matchState) => _matcher(item); 649 bool matches(item, MatchState matchState) => _matcher(item);
648 650
649 Description describe(Description description) => 651 Description describe(Description description) =>
650 description.add(_description); 652 description.add(_description);
651 } 653 }
652 654
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
693 description.add(_featureDescription).add(' ').addDescriptionOf(_matcher); 695 description.add(_featureDescription).add(' ').addDescriptionOf(_matcher);
694 696
695 Description describeMismatch(item, Description mismatchDescription, 697 Description describeMismatch(item, Description mismatchDescription,
696 MatchState matchState, bool verbose) { 698 MatchState matchState, bool verbose) {
697 mismatchDescription.add(_featureName).add(' '); 699 mismatchDescription.add(_featureName).add(' ');
698 _matcher.describeMismatch(matchState.state['feature'], mismatchDescription, 700 _matcher.describeMismatch(matchState.state['feature'], mismatchDescription,
699 matchState.state['innerState'], verbose); 701 matchState.state['innerState'], verbose);
700 return mismatchDescription; 702 return mismatchDescription;
701 } 703 }
702 } 704 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698