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

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

Issue 14600029: Add pretty-printing to unittest and more thoroughly print values. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Code review changes. Created 7 years, 7 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 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 return _assertFailureHandler; 130 return _assertFailureHandler;
131 } 131 }
132 132
133 // The error message formatter for failed asserts. 133 // The error message formatter for failed asserts.
134 ErrorFormatter _assertErrorFormatter = null; 134 ErrorFormatter _assertErrorFormatter = null;
135 135
136 // The default error formatter implementation. 136 // The default error formatter implementation.
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). 140 description.add('Expected: ').addDescriptionOf(matcher).add('\n');
141 add('\n but: '); 141
142 matcher.describeMismatch(actual, description, matchState, verbose); 142 var mismatchDescription = new StringDescription();
143 description.add('.\n'); 143 matcher.describeMismatch(actual, mismatchDescription, matchState, verbose);
144 if (verbose) { 144 description.add(' But: ')
145 if (actual is Iterable) { 145 .add(mismatchDescription.toString()).add('.\n');
146 description.add('Actual: ').addDescriptionOf(actual).add('\n'); 146
147 } else if (actual is Map) { 147 if (!mismatchDescription.toString().startsWith("was ")) {
148 description.add('Actual: '); 148 description.add('Actual: ').addDescriptionOf(actual);
149 var count = 25;
150 for (var k in actual.keys) {
151 if (count == 0) {
152 description.add('...\n');
153 break;
154 }
155 description.addDescriptionOf(k);
156 description.add(' : ');
157 description.addDescriptionOf(actual[k]);
158 description.add('\n');
159 --count;
160 }
161 }
162 } 149 }
163 if (reason != null) { 150 if (reason != null) {
164 description.add(reason).add('\n'); 151 description.add(reason).add('\n');
165 } 152 }
166 return description.toString(); 153 return description.toString();
167 } 154 }
168 155
169 /** 156 /**
170 * Changes or resets to default the failure message formatter for expect(). 157 * Changes or resets to default the failure message formatter for expect().
171 * [formatter] is a reference to the new formatter; if this is omitted or 158 * [formatter] is a reference to the new formatter; if this is omitted or
172 * null then the failure formatter is reset to the default. The new 159 * null then the failure formatter is reset to the default. The new
173 * formatter is returned; this allows custom expect handlers to easily 160 * formatter is returned; this allows custom expect handlers to easily
174 * get a reference to the default formatter. 161 * get a reference to the default formatter.
175 */ 162 */
176 ErrorFormatter configureExpectFormatter([ErrorFormatter formatter = null]) { 163 ErrorFormatter configureExpectFormatter([ErrorFormatter formatter = null]) {
177 if (formatter == null) { 164 if (formatter == null) {
178 formatter = _defaultErrorFormatter; 165 formatter = _defaultErrorFormatter;
179 } 166 }
180 return _assertErrorFormatter = formatter; 167 return _assertErrorFormatter = formatter;
181 } 168 }
182 169
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698