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

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

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

Powered by Google App Engine
This is Rietveld 408576698