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

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

Issue 14367005: Improved error messages for type mismatches. (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
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 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
170 } 170 }
171 } 171 }
172 } 172 }
173 } 173 }
174 } else { 174 } else {
175 reason = new StringDescription(); 175 reason = new StringDescription();
176 var eType = typeName(expected); 176 var eType = typeName(expected);
177 var aType = typeName(actual); 177 var aType = typeName(actual);
178 var includeTypes = eType != aType; 178 var includeTypes = eType != aType;
179 // If we have recursed, show the expected value too; if not, 179 // If we have recursed, show the expected value too; if not,
180 // expect() will show it for us. As expect will not show type 180 // expect() will show it for us.
181 // mismatches at the top level we handle those here too. 181 if (depth > 0) {
182 if (includeTypes || depth > 1) {
183 reason.add('expected '); 182 reason.add('expected ');
184 if (includeTypes) { 183 if (includeTypes) {
185 reason.add(eType).add(':'); 184 reason.add(eType).add(':');
186 } 185 }
187 reason.addDescriptionOf(expected).add(' but '); 186 reason.addDescriptionOf(expected).add(' but ');
188 } 187 }
189 reason.add('was '); 188 reason.add('was ');
190 if (includeTypes) { 189 if (includeTypes) {
191 reason.add(aType).add(':'); 190 reason.add(aType).add(':');
192 } 191 }
193 reason.addDescriptionOf(actual); 192 reason.addDescriptionOf(actual);
193 if (includeTypes && depth == 0) {
194 reason.add(' (not type ').add(eType).add(')');
195 }
194 } 196 }
195 } 197 }
196 if (reason != null && location.length > 0) { 198 if (reason != null && location.length > 0) {
197 reason.add(' ').add(location); 199 reason.add(' ').add(location);
198 } 200 }
199 return reason; 201 return reason;
200 } 202 }
201 203
202 String typeName(x) { 204 String typeName(x) {
203 // dart2js blows up on some objects (e.g. window.navigator). 205 // dart2js blows up on some objects (e.g. window.navigator).
(...skipping 519 matching lines...) Expand 10 before | Expand all | Expand 10 after
723 description.add(_featureDescription).add(' ').addDescriptionOf(_matcher); 725 description.add(_featureDescription).add(' ').addDescriptionOf(_matcher);
724 726
725 Description describeMismatch(item, Description mismatchDescription, 727 Description describeMismatch(item, Description mismatchDescription,
726 MatchState matchState, bool verbose) { 728 MatchState matchState, bool verbose) {
727 mismatchDescription.add(_featureName).add(' '); 729 mismatchDescription.add(_featureName).add(' ');
728 _matcher.describeMismatch(matchState.state['feature'], mismatchDescription, 730 _matcher.describeMismatch(matchState.state['feature'], mismatchDescription,
729 matchState.state['innerState'], verbose); 731 matchState.state['innerState'], verbose);
730 return mismatchDescription; 732 return mismatchDescription;
731 } 733 }
732 } 734 }
OLDNEW
« no previous file with comments | « no previous file | pkg/unittest/test/matchers_test.dart » ('j') | pkg/unittest/test/matchers_test.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698