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

Side by Side Diff: lib/unittest/operator_matchers.dart

Issue 10832058: Improved the way we generate mismatch descriptions. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 4 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 | « lib/unittest/numeric_matchers.dart ('k') | lib/unittest/string_matchers.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 /** 5 /**
6 * This returns a matcher that inverts [matcher] to its logical negation. 6 * This returns a matcher that inverts [matcher] to its logical negation.
7 */ 7 */
8 Matcher isNot(matcher) => new _IsNot(wrapMatcher(matcher)); 8 Matcher isNot(matcher) => new _IsNot(wrapMatcher(matcher));
9 9
10 class _IsNot extends BaseMatcher { 10 class _IsNot extends BaseMatcher {
11 final Matcher _matcher; 11 final Matcher _matcher;
12 12
13 const _IsNot(Matcher this._matcher); 13 const _IsNot(Matcher this._matcher);
14 14
15 bool matches(item) => !_matcher.matches(item); 15 bool matches(item, MatchState matchState) =>
16 !_matcher.matches(item, matchState);
16 17
17 Description describe(Description description) => 18 Description describe(Description description) =>
18 description.add('not ').addDescriptionOf(_matcher); 19 description.add('not ').addDescriptionOf(_matcher);
19 } 20 }
20 21
21 /** 22 /**
22 * This returns a matcher that matches if all of the matchers passed as 23 * This returns a matcher that matches if all of the matchers passed as
23 * arguments (up to 7) match. Instead of passing the matchers separately 24 * arguments (up to 7) match. Instead of passing the matchers separately
24 * they can be passed as a single List argument. 25 * they can be passed as a single List argument.
25 * Any argument that is not a matcher is implicitly wrapped in a 26 * Any argument that is not a matcher is implicitly wrapped in a
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 } 69 }
69 return new _AllOf(matchers); 70 return new _AllOf(matchers);
70 } 71 }
71 } 72 }
72 73
73 class _AllOf extends BaseMatcher { 74 class _AllOf extends BaseMatcher {
74 final Iterable<Matcher> _matchers; 75 final Iterable<Matcher> _matchers;
75 76
76 const _AllOf(this._matchers); 77 const _AllOf(this._matchers);
77 78
78 bool matches(item) { 79 bool matches(item, MatchState matchState) {
79 for (var matcher in _matchers) { 80 for (var matcher in _matchers) {
80 if (!matcher.matches(item)) { 81 if (!matcher.matches(item, matchState)) {
82 matchState.state = {
83 'matcher': matcher,
84 'state': matchState.state
85 };
81 return false; 86 return false;
82 } 87 }
83 } 88 }
84 return true; 89 return true;
85 } 90 }
86 91
87 Description describeMismatch(item, Description mismatchDescription) { 92 Description describeMismatch(item, Description mismatchDescription,
88 for (var matcher in _matchers) { 93 MatchState matchState, bool verbose) {
89 if (!matcher.matches(item)) { 94 var matcher = matchState.state['matcher'];
90 mismatchDescription.addDescriptionOf(matcher).add(' '); 95 mismatchDescription.addDescriptionOf(matcher).add(' ');
91 matcher.describeMismatch(item, mismatchDescription); 96 matcher.describeMismatch(item, mismatchDescription,
92 break; 97 matchState.state['state'], verbose);
93 }
94 }
95 return mismatchDescription; 98 return mismatchDescription;
96 } 99 }
97 100
98 Description describe(Description description) => 101 Description describe(Description description) =>
99 description.addAll('(', ' and ', ')', _matchers); 102 description.addAll('(', ' and ', ')', _matchers);
100 } 103 }
101 104
102 /** 105 /**
103 * Matches if any of the given matchers evaluate to true. The 106 * Matches if any of the given matchers evaluate to true. The
104 * arguments can be a set of matchers as separate parameters 107 * arguments can be a set of matchers as separate parameters
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 } 157 }
155 return new _AnyOf(matchers); 158 return new _AnyOf(matchers);
156 } 159 }
157 } 160 }
158 161
159 class _AnyOf extends BaseMatcher { 162 class _AnyOf extends BaseMatcher {
160 final Iterable<Matcher> _matchers; 163 final Iterable<Matcher> _matchers;
161 164
162 const _AnyOf(this._matchers); 165 const _AnyOf(this._matchers);
163 166
164 bool matches(item) { 167 bool matches(item, MatchState matchState) {
165 for (var matcher in _matchers) { 168 for (var matcher in _matchers) {
166 if (matcher.matches(item)) { 169 if (matcher.matches(item, matchState)) {
167 return true; 170 return true;
168 } 171 }
169 } 172 }
170 return false; 173 return false;
171 } 174 }
172 175
173 Description describe(Description description) => 176 Description describe(Description description) =>
174 description.addAll('(', ' or ', ')', _matchers); 177 description.addAll('(', ' or ', ')', _matchers);
175 } 178 }
176 179
OLDNEW
« no previous file with comments | « lib/unittest/numeric_matchers.dart ('k') | lib/unittest/string_matchers.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698