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

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

Issue 15755005: Change output of string equality match failures. (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 /** The objects thrown by the default failure handler. */ 7 /** The objects thrown by the default failure handler. */
8 class TestFailure { 8 class TestFailure {
9 String _message; 9 String _message;
10 10
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 String _defaultErrorFormatter(actual, Matcher matcher, String reason, 137 String _defaultErrorFormatter(actual, Matcher matcher, String reason,
138 MatchState matchState, bool verbose) { 138 MatchState matchState, bool verbose) {
139 var description = new StringDescription(); 139 var description = new StringDescription();
140 description.add('Expected: ').addDescriptionOf(matcher).add('\n'); 140 description.add('Expected: ').addDescriptionOf(matcher).add('\n');
141 141
142 var mismatchDescription = new StringDescription(); 142 var mismatchDescription = new StringDescription();
143 matcher.describeMismatch(actual, mismatchDescription, matchState, verbose); 143 matcher.describeMismatch(actual, mismatchDescription, matchState, verbose);
144 description.add(' But: ') 144 description.add(' But: ')
145 .add(mismatchDescription.toString()).add('.\n'); 145 .add(mismatchDescription.toString()).add('.\n');
146 146
147 if (!mismatchDescription.toString().startsWith("was ")) { 147 description.add('Actual: ').addDescriptionOf(actual);
148 description.add('Actual: ').addDescriptionOf(actual);
149 }
150 if (reason != null) { 148 if (reason != null) {
151 description.add(reason).add('\n'); 149 description.add(reason).add('\n');
152 } 150 }
153 return description.toString(); 151 return description.toString();
154 } 152 }
155 153
156 /** 154 /**
157 * Changes or resets to default the failure message formatter for expect(). 155 * Changes or resets to default the failure message formatter for expect().
158 * [formatter] is a reference to the new formatter; if this is omitted or 156 * [formatter] is a reference to the new formatter; if this is omitted or
159 * null then the failure formatter is reset to the default. The new 157 * null then the failure formatter is reset to the default. The new
160 * formatter is returned; this allows custom expect handlers to easily 158 * formatter is returned; this allows custom expect handlers to easily
161 * get a reference to the default formatter. 159 * get a reference to the default formatter.
162 */ 160 */
163 ErrorFormatter configureExpectFormatter([ErrorFormatter formatter = null]) { 161 ErrorFormatter configureExpectFormatter([ErrorFormatter formatter = null]) {
164 if (formatter == null) { 162 if (formatter == null) {
165 formatter = _defaultErrorFormatter; 163 formatter = _defaultErrorFormatter;
166 } 164 }
167 return _assertErrorFormatter = formatter; 165 return _assertErrorFormatter = formatter;
168 } 166 }
169 167
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698